2 Samba Unix/Linux SMB client library
3 Distributed SMB/CIFS Server Management Utility
4 Copyright (C) 2004,2009 Guenther Deschner (gd@samba.org)
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "utils/net.h"
21 #include "../librpc/gen_ndr/cli_spoolss.h"
22 #include "rpc_client/cli_spoolss.h"
23 #include "rpc_client/init_spoolss.h"
24 #include "nt_printing.h"
26 #include "registry/reg_objects.h"
27 #include "../libcli/security/security.h"
29 /* support itanium as well */
30 static const struct print_architecture_table_node archi_table[]= {
32 {"Windows 4.0", "WIN40", 0 },
33 {"Windows NT x86", "W32X86", 2 },
34 {"Windows NT x86", "W32X86", 3 },
35 {"Windows NT R4000", "W32MIPS", 2 },
36 {"Windows NT Alpha_AXP", "W32ALPHA", 2 },
37 {"Windows NT PowerPC", "W32PPC", 2 },
38 {"Windows IA64", "IA64", 3 },
39 {"Windows x64", "x64", 3 },
45 * This display-printdriver-functions was borrowed from rpcclient/cmd_spoolss.c.
46 * It is here for debugging purpose and should be removed later on.
49 /****************************************************************************
50 Printer info level 3 display function.
51 ****************************************************************************/
53 static void display_print_driver3(struct spoolss_DriverInfo3 *r)
61 printf(_("Printer Driver Info 3:\n"));
62 printf(_("\tVersion: [%x]\n"), r->version);
63 printf(_("\tDriver Name: [%s]\n"), r->driver_name);
64 printf(_("\tArchitecture: [%s]\n"), r->architecture);
65 printf(_("\tDriver Path: [%s]\n"), r->driver_path);
66 printf(_("\tDatafile: [%s]\n"), r->data_file);
67 printf(_("\tConfigfile: [%s]\n\n"), r->config_file);
68 printf(_("\tHelpfile: [%s]\n\n"), r->help_file);
70 for (i=0; r->dependent_files[i] != NULL; i++) {
71 printf(_("\tDependentfiles: [%s]\n"), r->dependent_files[i]);
76 printf(_("\tMonitorname: [%s]\n"), r->monitor_name);
77 printf(_("\tDefaultdatatype: [%s]\n\n"), r->default_datatype);
80 static void display_reg_value(const char *subkey, struct regval_blob *value)
85 switch(regval_type(value)) {
87 d_printf(_("\t[%s:%s]: REG_DWORD: 0x%08x\n"), subkey,
88 regval_name(value), *((uint32_t *) regval_data_p(value)));
92 blob = data_blob_const(regval_data_p(value), regval_size(value));
93 pull_reg_sz(talloc_tos(), &blob, &text);
97 d_printf(_("\t[%s:%s]: REG_SZ: %s\n"), subkey, regval_name(value),
102 d_printf(_("\t[%s:%s]: REG_BINARY: unknown length value not "
104 subkey, regval_name(value));
110 blob = data_blob_const(regval_data_p(value), regval_size(value));
112 if (!pull_reg_multi_sz(NULL, &blob, &values)) {
113 d_printf("pull_reg_multi_sz failed\n");
117 printf("%s: REG_MULTI_SZ: \n", regval_name(value));
118 for (i=0; values[i] != NULL; i++) {
119 d_printf("%s\n", values[i]);
126 d_printf(_("\t%s: unknown type %d\n"), regval_name(value),
133 * Copies ACLs, DOS-attributes and timestamps from one
134 * file or directory from one connected share to another connected share
136 * @param c A net_context structure
137 * @param mem_ctx A talloc-context
138 * @param cli_share_src A connected cli_state
139 * @param cli_share_dst A connected cli_state
140 * @param src_file The source file-name
141 * @param dst_file The destination file-name
142 * @param copy_acls Whether to copy acls
143 * @param copy_attrs Whether to copy DOS attributes
144 * @param copy_timestamps Whether to preserve timestamps
145 * @param is_file Whether this file is a file or a dir
147 * @return Normal NTSTATUS return.
150 NTSTATUS net_copy_fileattr(struct net_context *c,
152 struct cli_state *cli_share_src,
153 struct cli_state *cli_share_dst,
154 const char *src_name, const char *dst_name,
155 bool copy_acls, bool copy_attrs,
156 bool copy_timestamps, bool is_file)
158 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
159 uint16_t fnum_src = 0;
160 uint16_t fnum_dst = 0;
161 struct security_descriptor *sd = NULL;
163 time_t f_atime, f_ctime, f_mtime;
166 if (!copy_timestamps && !copy_acls && !copy_attrs)
169 /* open file/dir on the originating server */
171 DEBUGADD(3,("opening %s %s on originating server\n",
172 is_file?"file":"dir", src_name));
174 if (!NT_STATUS_IS_OK(cli_ntcreate(cli_share_src, src_name, 0, READ_CONTROL_ACCESS, 0,
175 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum_src))) {
176 DEBUGADD(0,("cannot open %s %s on originating server %s\n",
177 is_file?"file":"dir", src_name, cli_errstr(cli_share_src)));
178 nt_status = cli_nt_error(cli_share_src);
185 /* get the security descriptor */
186 sd = cli_query_secdesc(cli_share_src, fnum_src, mem_ctx);
188 DEBUG(0,("failed to get security descriptor: %s\n",
189 cli_errstr(cli_share_src)));
190 nt_status = cli_nt_error(cli_share_src);
194 if (c->opt_verbose && DEBUGLEVEL >= 3)
195 display_sec_desc(sd);
199 if (copy_attrs || copy_timestamps) {
201 /* get file attributes */
202 if (!NT_STATUS_IS_OK(cli_getattrE(cli_share_src, fnum_src, &attr, NULL,
203 &f_ctime, &f_atime, &f_mtime))) {
204 DEBUG(0,("failed to get file-attrs: %s\n",
205 cli_errstr(cli_share_src)));
206 nt_status = cli_nt_error(cli_share_src);
212 /* open the file/dir on the destination server */
214 if (!NT_STATUS_IS_OK(cli_ntcreate(cli_share_dst, dst_name, 0, WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS, 0,
215 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum_dst))) {
216 DEBUG(0,("failed to open %s on the destination server: %s: %s\n",
217 is_file?"file":"dir", dst_name, cli_errstr(cli_share_dst)));
218 nt_status = cli_nt_error(cli_share_dst);
222 if (copy_timestamps) {
225 if (!NT_STATUS_IS_OK(cli_setattrE(cli_share_dst, fnum_dst, f_ctime, f_atime, f_mtime))) {
226 DEBUG(0,("failed to set file-attrs (timestamps): %s\n",
227 cli_errstr(cli_share_dst)));
228 nt_status = cli_nt_error(cli_share_dst);
236 if (!cli_set_secdesc(cli_share_dst, fnum_dst, sd)) {
237 DEBUG(0,("could not set secdesc on %s: %s\n",
238 dst_name, cli_errstr(cli_share_dst)));
239 nt_status = cli_nt_error(cli_share_dst);
247 if (!NT_STATUS_IS_OK(cli_setatr(cli_share_dst, dst_name, attr, 0))) {
248 DEBUG(0,("failed to set file-attrs: %s\n",
249 cli_errstr(cli_share_dst)));
250 nt_status = cli_nt_error(cli_share_dst);
258 if (!NT_STATUS_IS_OK(cli_close(cli_share_src, fnum_src))) {
260 _("could not close %s on originating server: %s\n"),
261 is_file?"file":"dir", cli_errstr(cli_share_src));
262 nt_status = cli_nt_error(cli_share_src);
266 if (!NT_STATUS_IS_OK(cli_close(cli_share_dst, fnum_dst))) {
268 _("could not close %s on destination server: %s\n"),
269 is_file?"file":"dir", cli_errstr(cli_share_dst));
270 nt_status = cli_nt_error(cli_share_dst);
275 nt_status = NT_STATUS_OK;
281 cli_close(cli_share_src, fnum_src);
284 cli_close(cli_share_dst, fnum_dst);
290 * Copy a file or directory from a connected share to another connected share
292 * @param c A net_context structure
293 * @param mem_ctx A talloc-context
294 * @param cli_share_src A connected cli_state
295 * @param cli_share_dst A connected cli_state
296 * @param src_file The source file-name
297 * @param dst_file The destination file-name
298 * @param copy_acls Whether to copy acls
299 * @param copy_attrs Whether to copy DOS attributes
300 * @param copy_timestamps Whether to preserve timestamps
301 * @param is_file Whether this file is a file or a dir
303 * @return Normal NTSTATUS return.
306 NTSTATUS net_copy_file(struct net_context *c,
308 struct cli_state *cli_share_src,
309 struct cli_state *cli_share_dst,
310 const char *src_name, const char *dst_name,
311 bool copy_acls, bool copy_attrs,
312 bool copy_timestamps, bool is_file)
314 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
315 uint16_t fnum_src = 0;
316 uint16_t fnum_dst = 0;
317 static int io_bufsize = 64512;
318 int read_size = io_bufsize;
323 if (!src_name || !dst_name)
326 if (cli_share_src == NULL || cli_share_dst == NULL)
329 /* open on the originating server */
330 DEBUGADD(3,("opening %s %s on originating server\n",
331 is_file ? "file":"dir", src_name));
333 nt_status = cli_open(cli_share_src, src_name, O_RDONLY, DENY_NONE, &fnum_src);
335 nt_status = cli_ntcreate(cli_share_src, src_name, 0, READ_CONTROL_ACCESS, 0,
336 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum_src);
338 if (!NT_STATUS_IS_OK(nt_status)) {
339 DEBUGADD(0,("cannot open %s %s on originating server %s\n",
340 is_file ? "file":"dir",
341 src_name, cli_errstr(cli_share_src)));
348 /* open file on the destination server */
349 DEBUGADD(3,("opening file %s on destination server\n", dst_name));
350 nt_status = cli_open(cli_share_dst, dst_name,
351 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE, &fnum_dst);
353 if (!NT_STATUS_IS_OK(nt_status)) {
354 DEBUGADD(1,("cannot create file %s on destination server: %s\n",
355 dst_name, cli_errstr(cli_share_dst)));
359 /* allocate memory */
360 if (!(data = (char *)SMB_MALLOC(read_size))) {
361 d_fprintf(stderr, _("malloc fail for size %d\n"),
363 nt_status = NT_STATUS_NO_MEMORY;
370 if (c->opt_verbose) {
372 d_printf(_("copying [\\\\%s\\%s%s] => [\\\\%s\\%s%s] "
373 "%s ACLs and %s DOS Attributes %s\n"),
374 cli_share_src->desthost, cli_share_src->share, src_name,
375 cli_share_dst->desthost, cli_share_dst->share, dst_name,
376 copy_acls ? _("with") : _("without"),
377 copy_attrs ? _("with") : _("without"),
378 copy_timestamps ? _("(preserving timestamps)") : "" );
386 n = cli_read(cli_share_src, fnum_src, data, nread,
392 ret = cli_write(cli_share_dst, fnum_dst, 0, data,
396 d_fprintf(stderr, _("Error writing file: %s\n"),
397 cli_errstr(cli_share_dst));
398 nt_status = cli_nt_error(cli_share_dst);
406 if (!is_file && !NT_STATUS_IS_OK(cli_chkpath(cli_share_dst, dst_name))) {
409 DEBUGADD(3,("creating dir %s on the destination server\n",
412 if (!NT_STATUS_IS_OK(cli_mkdir(cli_share_dst, dst_name))) {
413 DEBUG(0,("cannot create directory %s: %s\n",
414 dst_name, cli_errstr(cli_share_dst)));
415 nt_status = NT_STATUS_NO_SUCH_FILE;
418 if (!NT_STATUS_IS_OK(cli_chkpath(cli_share_dst, dst_name))) {
420 _("cannot check for directory %s: %s\n"),
421 dst_name, cli_errstr(cli_share_dst));
428 if (!NT_STATUS_IS_OK(cli_close(cli_share_src, fnum_src))) {
430 _("could not close file on originating server: %s\n"),
431 cli_errstr(cli_share_src));
432 nt_status = cli_nt_error(cli_share_src);
436 if (is_file && !NT_STATUS_IS_OK(cli_close(cli_share_dst, fnum_dst))) {
438 _("could not close file on destination server: %s\n"),
439 cli_errstr(cli_share_dst));
440 nt_status = cli_nt_error(cli_share_dst);
444 /* possibly we have to copy some file-attributes / acls / sd */
445 nt_status = net_copy_fileattr(c, mem_ctx, cli_share_src, cli_share_dst,
446 src_name, dst_name, copy_acls,
447 copy_attrs, copy_timestamps, is_file);
448 if (!NT_STATUS_IS_OK(nt_status))
452 nt_status = NT_STATUS_OK;
458 cli_close(cli_share_src, fnum_src);
461 cli_close(cli_share_dst, fnum_dst);
469 * Copy a driverfile from on connected share to another connected share
470 * This silently assumes that a driver-file is picked up from
472 * \\src_server\print$\{arch}\{version}\file
476 * \\dst_server\print$\{arch}\file
478 * to be added via setdriver-calls later.
479 * @param c A net_context structure
480 * @param mem_ctx A talloc-context
481 * @param cli_share_src A cli_state connected to source print$-share
482 * @param cli_share_dst A cli_state connected to destination print$-share
483 * @param file The file-name to be copied
484 * @param short_archi The name of the driver-architecture (short form)
486 * @return Normal NTSTATUS return.
489 static NTSTATUS net_copy_driverfile(struct net_context *c,
491 struct cli_state *cli_share_src,
492 struct cli_state *cli_share_dst,
493 const char *file, const char *short_archi) {
498 char *version = NULL;
499 char *filename = NULL;
506 /* scroll through the file until we have the part
507 beyond archi_table.short_archi */
509 while (next_token_talloc(mem_ctx, &p, &tok, "\\")) {
510 if (strequal(tok, short_archi)) {
511 next_token_talloc(mem_ctx, &p, &version, "\\");
512 next_token_talloc(mem_ctx, &p, &filename, "\\");
516 if (version == NULL || filename == NULL) {
517 return NT_STATUS_UNSUCCESSFUL;
520 /* build source file name */
521 src_name = talloc_asprintf(mem_ctx, "\\%s\\%s\\%s",
522 short_archi, version, filename);
523 if (src_name == NULL) {
524 return NT_STATUS_NO_MEMORY;
527 /* create destination file name */
528 dst_name = talloc_asprintf(mem_ctx, "\\%s\\%s", short_archi, filename);
529 if (dst_name == NULL) {
530 return NT_STATUS_NO_MEMORY;
534 /* finally copy the file */
535 return net_copy_file(c, mem_ctx, cli_share_src, cli_share_dst,
536 src_name, dst_name, false, false, false, true);
540 * Check for existing Architecture directory on a given server
542 * @param cli_share A cli_state connected to a print$-share
543 * @param short_archi The Architecture for the print-driver
545 * @return Normal NTSTATUS return.
548 static NTSTATUS check_arch_dir(struct cli_state *cli_share, const char *short_archi)
551 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
554 if (asprintf(&dir, "\\%s", short_archi) < 0) {
555 return NT_STATUS_NO_MEMORY;
558 DEBUG(10,("creating print-driver dir for architecture: %s\n",
561 if (!NT_STATUS_IS_OK(cli_mkdir(cli_share, dir))) {
562 DEBUG(1,("cannot create directory %s: %s\n",
563 dir, cli_errstr(cli_share)));
564 nt_status = NT_STATUS_NO_SUCH_FILE;
567 if (!NT_STATUS_IS_OK(cli_chkpath(cli_share, dir))) {
568 d_fprintf(stderr, _("cannot check %s: %s\n"),
569 dir, cli_errstr(cli_share));
573 nt_status = NT_STATUS_OK;
581 * Copy a print-driver (level 3) from one connected print$-share to another
582 * connected print$-share
584 * @param c A net_context structure
585 * @param mem_ctx A talloc-context
586 * @param cli_share_src A cli_state connected to a print$-share
587 * @param cli_share_dst A cli_state connected to a print$-share
588 * @param short_archi The Architecture for the print-driver
589 * @param i1 The DRIVER_INFO_3-struct
591 * @return Normal NTSTATUS return.
594 static NTSTATUS copy_print_driver_3(struct net_context *c,
596 struct cli_state *cli_share_src,
597 struct cli_state *cli_share_dst,
598 const char *short_archi,
599 struct spoolss_DriverInfo3 *r)
601 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
609 d_printf(_("copying driver: [%s], for architecture: [%s], "
611 r->driver_name, short_archi, r->version);
613 nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst,
614 r->driver_path, short_archi);
615 if (!NT_STATUS_IS_OK(nt_status))
618 nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst,
619 r->data_file, short_archi);
620 if (!NT_STATUS_IS_OK(nt_status))
623 nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst,
624 r->config_file, short_archi);
625 if (!NT_STATUS_IS_OK(nt_status))
628 nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst,
629 r->help_file, short_archi);
630 if (!NT_STATUS_IS_OK(nt_status))
633 for (i=0; r->dependent_files[i] != NULL; i++) {
635 nt_status = net_copy_driverfile(c, mem_ctx,
636 cli_share_src, cli_share_dst,
637 r->dependent_files[i], short_archi);
638 if (!NT_STATUS_IS_OK(nt_status)) {
647 * net_spoolss-functions
648 * =====================
650 * the net_spoolss-functions aim to simplify spoolss-client-functions
651 * required during the migration-process wrt buffer-sizes, returned
654 * this greatly reduces the complexitiy of the migrate-functions.
658 static bool net_spoolss_enum_printers(struct rpc_pipe_client *pipe_hnd,
663 uint32_t *num_printers,
664 union spoolss_PrinterInfo **info)
670 result = rpccli_spoolss_enumprinters(pipe_hnd, mem_ctx,
677 if (!W_ERROR_IS_OK(result)) {
678 printf(_("cannot enum printers: %s\n"), win_errstr(result));
685 static bool net_spoolss_open_printer_ex(struct rpc_pipe_client *pipe_hnd,
687 const char *printername,
688 uint32_t access_required,
689 const char *username,
690 struct policy_handle *hnd)
693 fstring printername2;
695 fstrcpy(printername2, pipe_hnd->srv_name_slash);
696 fstrcat(printername2, "\\");
697 fstrcat(printername2, printername);
699 DEBUG(10,("connecting to: %s as %s for %s and access: %x\n",
700 pipe_hnd->srv_name_slash, username, printername2, access_required));
703 result = rpccli_spoolss_openprinter_ex(pipe_hnd, mem_ctx,
708 /* be more verbose */
709 if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) {
711 _("no access to printer [%s] on [%s] for user [%s] "
713 printername2, pipe_hnd->srv_name_slash, username);
717 if (!W_ERROR_IS_OK(result)) {
718 d_fprintf(stderr,_("cannot open printer %s on server %s: %s\n"),
719 printername2, pipe_hnd->srv_name_slash, win_errstr(result));
723 DEBUG(2,("got printer handle for printer: %s, server: %s\n",
724 printername2, pipe_hnd->srv_name_slash));
729 static bool net_spoolss_getprinter(struct rpc_pipe_client *pipe_hnd,
731 struct policy_handle *hnd,
733 union spoolss_PrinterInfo *info)
737 /* getprinter call */
738 result = rpccli_spoolss_getprinter(pipe_hnd, mem_ctx,
743 if (!W_ERROR_IS_OK(result)) {
744 printf(_("cannot get printer-info: %s\n"), win_errstr(result));
751 static bool net_spoolss_setprinter(struct rpc_pipe_client *pipe_hnd,
753 struct policy_handle *hnd,
755 union spoolss_PrinterInfo *info)
759 struct spoolss_SetPrinterInfoCtr info_ctr;
760 struct spoolss_SetPrinterInfo2 info2;
761 struct spoolss_DevmodeContainer devmode_ctr;
762 struct sec_desc_buf secdesc_ctr;
764 ZERO_STRUCT(devmode_ctr);
765 ZERO_STRUCT(secdesc_ctr);
767 /* setprinter call */
769 info_ctr.level = level;
772 info_ctr.info.info0 = (struct spoolss_SetPrinterInfo0 *)
773 (void *)&info->info0;
776 info_ctr.info.info1 = (struct spoolss_SetPrinterInfo1 *)
777 (void *)&info->info1;
780 spoolss_printerinfo2_to_setprinterinfo2(&info->info2, &info2);
781 info_ctr.info.info2 = &info2;
784 info_ctr.info.info3 = (struct spoolss_SetPrinterInfo3 *)
785 (void *)&info->info3;
788 info_ctr.info.info4 = (struct spoolss_SetPrinterInfo4 *)
789 (void *)&info->info4;
792 info_ctr.info.info5 = (struct spoolss_SetPrinterInfo5 *)
793 (void *)&info->info5;
796 info_ctr.info.info6 = (struct spoolss_SetPrinterInfo6 *)
797 (void *)&info->info6;
800 info_ctr.info.info7 = (struct spoolss_SetPrinterInfo7 *)
801 (void *)&info->info7;
805 info_ctr.info.info8 = (struct spoolss_SetPrinterInfo8 *)
806 (void *)&info->info8;
809 info_ctr.info.info9 = (struct spoolss_SetPrinterInfo9 *)
810 (void *)&info->info9;
817 status = rpccli_spoolss_SetPrinter(pipe_hnd, mem_ctx,
825 if (!W_ERROR_IS_OK(result)) {
826 printf(_("cannot set printer-info: %s\n"), win_errstr(result));
834 static bool net_spoolss_setprinterdata(struct rpc_pipe_client *pipe_hnd,
836 struct policy_handle *hnd,
837 const char *value_name,
838 enum winreg_Type type,
845 /* setprinterdata call */
846 status = rpccli_spoolss_SetPrinterData(pipe_hnd, mem_ctx,
854 if (!W_ERROR_IS_OK(result)) {
855 printf (_("unable to set printerdata: %s\n"),
864 static bool net_spoolss_enumprinterkey(struct rpc_pipe_client *pipe_hnd,
866 struct policy_handle *hnd,
868 const char ***keylist)
872 /* enumprinterkey call */
873 result = rpccli_spoolss_enumprinterkey(pipe_hnd, mem_ctx, hnd, keyname, keylist, 0);
875 if (!W_ERROR_IS_OK(result)) {
876 printf(_("enumprinterkey failed: %s\n"), win_errstr(result));
883 static bool net_spoolss_enumprinterdataex(struct rpc_pipe_client *pipe_hnd,
886 struct policy_handle *hnd,
889 struct spoolss_PrinterEnumValues **info)
893 /* enumprinterdataex call */
894 result = rpccli_spoolss_enumprinterdataex(pipe_hnd, mem_ctx,
901 if (!W_ERROR_IS_OK(result)) {
902 printf(_("enumprinterdataex failed: %s\n"), win_errstr(result));
910 static bool net_spoolss_setprinterdataex(struct rpc_pipe_client *pipe_hnd,
912 struct policy_handle *hnd,
914 struct regval_blob *value)
919 /* setprinterdataex call */
920 status = rpccli_spoolss_SetPrinterDataEx(pipe_hnd, mem_ctx,
925 regval_data_p(value),
929 if (!W_ERROR_IS_OK(result)) {
930 printf(_("could not set printerdataex: %s\n"),
938 static bool net_spoolss_enumforms(struct rpc_pipe_client *pipe_hnd,
940 struct policy_handle *hnd,
943 union spoolss_FormInfo **forms)
948 result = rpccli_spoolss_enumforms(pipe_hnd, mem_ctx,
954 if (!W_ERROR_IS_OK(result)) {
955 printf(_("could not enum forms: %s\n"), win_errstr(result));
962 static bool net_spoolss_enumprinterdrivers (struct rpc_pipe_client *pipe_hnd,
964 uint32_t level, const char *env,
966 union spoolss_DriverInfo **info)
970 /* enumprinterdrivers call */
971 result = rpccli_spoolss_enumprinterdrivers(pipe_hnd, mem_ctx,
972 pipe_hnd->srv_name_slash,
978 if (!W_ERROR_IS_OK(result)) {
979 if (W_ERROR_V(result) != W_ERROR_V(WERR_INVALID_ENVIRONMENT)) {
980 printf(_("cannot enum drivers for environment %s: %s\n"), env,
984 printf(_("Server does not support environment [%s]\n"),
992 static bool net_spoolss_getprinterdriver(struct rpc_pipe_client *pipe_hnd,
994 struct policy_handle *hnd, uint32_t level,
995 const char *env, int version,
996 union spoolss_DriverInfo *info)
999 uint32_t server_major_version;
1000 uint32_t server_minor_version;
1002 /* getprinterdriver call */
1003 result = rpccli_spoolss_getprinterdriver2(pipe_hnd, mem_ctx,
1011 &server_major_version,
1012 &server_minor_version);
1013 if (!W_ERROR_IS_OK(result)) {
1014 DEBUG(1,("cannot get driver (for architecture: %s): %s\n",
1015 env, win_errstr(result)));
1016 if (W_ERROR_V(result) != W_ERROR_V(WERR_UNKNOWN_PRINTER_DRIVER) &&
1017 W_ERROR_V(result) != W_ERROR_V(WERR_INVALID_ENVIRONMENT)) {
1018 printf(_("cannot get driver: %s\n"),
1019 win_errstr(result));
1028 static bool net_spoolss_addprinterdriver(struct rpc_pipe_client *pipe_hnd,
1029 TALLOC_CTX *mem_ctx, uint32_t level,
1030 union spoolss_DriverInfo *info)
1034 struct spoolss_AddDriverInfoCtr info_ctr;
1036 info_ctr.level = level;
1040 info_ctr.info.info2 = (struct spoolss_AddDriverInfo2 *)
1041 (void *)&info->info2;
1044 info_ctr.info.info3 = (struct spoolss_AddDriverInfo3 *)
1045 (void *)&info->info3;
1048 printf(_("unsupported info level: %d\n"), level);
1052 /* addprinterdriver call */
1053 status = rpccli_spoolss_AddPrinterDriver(pipe_hnd, mem_ctx,
1054 pipe_hnd->srv_name_slash,
1057 /* be more verbose */
1058 if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) {
1059 printf(_("You are not allowed to add drivers\n"));
1062 if (!W_ERROR_IS_OK(result)) {
1063 printf(_("cannot add driver: %s\n"), win_errstr(result));
1071 * abstraction function to get uint32_t num_printers and PRINTER_INFO_CTR ctr
1072 * for a single printer or for all printers depending on argc/argv
1075 static bool get_printer_info(struct rpc_pipe_client *pipe_hnd,
1076 TALLOC_CTX *mem_ctx,
1080 uint32_t *num_printers,
1081 union spoolss_PrinterInfo **info_p)
1083 struct policy_handle hnd;
1085 /* no arguments given, enumerate all printers */
1088 if (!net_spoolss_enum_printers(pipe_hnd, mem_ctx, NULL,
1089 PRINTER_ENUM_LOCAL|PRINTER_ENUM_SHARED,
1090 level, num_printers, info_p))
1096 /* argument given, get a single printer by name */
1097 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, argv[0],
1098 MAXIMUM_ALLOWED_ACCESS,
1099 pipe_hnd->auth->user_name,
1103 *info_p = talloc_zero(mem_ctx, union spoolss_PrinterInfo);
1104 if (*info_p == NULL) {
1108 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, *info_p)) {
1109 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1113 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1118 DEBUG(3,("got %d printers\n", *num_printers));
1125 * List print-queues (including local printers that are not shared)
1127 * All parameters are provided by the run_rpc_command function, except for
1128 * argc, argv which are passed through.
1130 * @param c A net_context structure
1131 * @param domain_sid The domain sid aquired from the remote server
1132 * @param cli A cli_state connected to the server.
1133 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1134 * @param argc Standard main() style argc
1135 * @param argv Standard main() style argv. Initial components are already
1138 * @return Normal NTSTATUS return.
1141 NTSTATUS rpc_printer_list_internals(struct net_context *c,
1142 const struct dom_sid *domain_sid,
1143 const char *domain_name,
1144 struct cli_state *cli,
1145 struct rpc_pipe_client *pipe_hnd,
1146 TALLOC_CTX *mem_ctx,
1150 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1151 uint32_t i, num_printers;
1153 const char *printername, *sharename;
1154 union spoolss_PrinterInfo *info;
1156 printf("listing printers\n");
1158 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &info))
1161 for (i = 0; i < num_printers; i++) {
1163 /* do some initialization */
1164 printername = info[i].info2.printername;
1165 sharename = info[i].info2.sharename;
1167 if (printername && sharename) {
1168 d_printf(_("printer %d: %s, shared as: %s\n"),
1169 i+1, printername, sharename);
1173 return NT_STATUS_OK;
1177 * List printer-drivers from a server
1179 * All parameters are provided by the run_rpc_command function, except for
1180 * argc, argv which are passed through.
1182 * @param c A net_context structure
1183 * @param domain_sid The domain sid aquired from the remote server
1184 * @param cli A cli_state connected to the server.
1185 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1186 * @param argc Standard main() style argc
1187 * @param argv Standard main() style argv. Initial components are already
1190 * @return Normal NTSTATUS return.
1193 NTSTATUS rpc_printer_driver_list_internals(struct net_context *c,
1194 const struct dom_sid *domain_sid,
1195 const char *domain_name,
1196 struct cli_state *cli,
1197 struct rpc_pipe_client *pipe_hnd,
1198 TALLOC_CTX *mem_ctx,
1202 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1205 union spoolss_DriverInfo *info;
1208 printf(_("listing printer-drivers\n"));
1210 for (i=0; archi_table[i].long_archi!=NULL; i++) {
1212 uint32_t num_drivers;
1214 /* enum remote drivers */
1215 if (!net_spoolss_enumprinterdrivers(pipe_hnd, mem_ctx, level,
1216 archi_table[i].long_archi,
1217 &num_drivers, &info)) {
1218 nt_status = NT_STATUS_UNSUCCESSFUL;
1222 if (num_drivers == 0) {
1223 d_printf(_("no drivers found on server for "
1224 "architecture: [%s].\n"),
1225 archi_table[i].long_archi);
1229 d_printf(_("got %d printer-drivers for architecture: [%s]\n"),
1230 num_drivers, archi_table[i].long_archi);
1233 /* do something for all drivers for architecture */
1234 for (d = 0; d < num_drivers; d++) {
1235 display_print_driver3(&info[d].info3);
1239 nt_status = NT_STATUS_OK;
1247 * Publish print-queues with args-wrapper
1249 * @param cli A cli_state connected to the server.
1250 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1251 * @param argc Standard main() style argc
1252 * @param argv Standard main() style argv. Initial components are already
1256 * @return Normal NTSTATUS return.
1259 static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_hnd,
1260 TALLOC_CTX *mem_ctx,
1265 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1266 uint32_t i, num_printers;
1268 const char *printername, *sharename;
1269 union spoolss_PrinterInfo *info_enum;
1270 union spoolss_PrinterInfo info;
1271 struct spoolss_SetPrinterInfoCtr info_ctr;
1272 struct spoolss_DevmodeContainer devmode_ctr;
1273 struct sec_desc_buf secdesc_ctr;
1274 struct policy_handle hnd;
1276 const char *action_str;
1278 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_enum))
1281 for (i = 0; i < num_printers; i++) {
1283 /* do some initialization */
1284 printername = info_enum[i].info2.printername;
1285 sharename = info_enum[i].info2.sharename;
1286 if (!printername || !sharename) {
1290 /* open printer handle */
1291 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1292 PRINTER_ALL_ACCESS, pipe_hnd->auth->user_name, &hnd))
1295 /* check for existing dst printer */
1296 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info))
1299 /* check action and set string */
1301 case DSPRINT_PUBLISH:
1302 action_str = N_("published");
1304 case DSPRINT_UPDATE:
1305 action_str = N_("updated");
1307 case DSPRINT_UNPUBLISH:
1308 action_str = N_("unpublished");
1311 action_str = N_("unknown action");
1312 printf(_("unkown action: %d\n"), action);
1316 info.info7.action = action;
1318 info_ctr.info.info7 = (struct spoolss_SetPrinterInfo7 *)
1319 (void *)&info.info7;
1321 ZERO_STRUCT(devmode_ctr);
1322 ZERO_STRUCT(secdesc_ctr);
1324 nt_status = rpccli_spoolss_SetPrinter(pipe_hnd, mem_ctx,
1332 if (!W_ERROR_IS_OK(result) && !W_ERROR_EQUAL(result, WERR_IO_PENDING)) {
1333 if ((action == DSPRINT_UPDATE) && W_ERROR_EQUAL(result, W_ERROR(0x80070002))) {
1334 printf(_("printer not published yet\n"));
1336 printf(_("cannot set printer-info: %s\n"),
1337 win_errstr(result));
1342 printf(_("successfully %s printer %s in Active Directory\n"),
1343 action_str, sharename);
1346 nt_status = NT_STATUS_OK;
1349 if (is_valid_policy_hnd(&hnd))
1350 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1355 NTSTATUS rpc_printer_publish_publish_internals(struct net_context *c,
1356 const struct dom_sid *domain_sid,
1357 const char *domain_name,
1358 struct cli_state *cli,
1359 struct rpc_pipe_client *pipe_hnd,
1360 TALLOC_CTX *mem_ctx,
1364 return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, DSPRINT_PUBLISH);
1367 NTSTATUS rpc_printer_publish_unpublish_internals(struct net_context *c,
1368 const struct dom_sid *domain_sid,
1369 const char *domain_name,
1370 struct cli_state *cli,
1371 struct rpc_pipe_client *pipe_hnd,
1372 TALLOC_CTX *mem_ctx,
1376 return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, DSPRINT_UNPUBLISH);
1379 NTSTATUS rpc_printer_publish_update_internals(struct net_context *c,
1380 const struct dom_sid *domain_sid,
1381 const char *domain_name,
1382 struct cli_state *cli,
1383 struct rpc_pipe_client *pipe_hnd,
1384 TALLOC_CTX *mem_ctx,
1388 return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, DSPRINT_UPDATE);
1392 * List print-queues w.r.t. their publishing state
1394 * All parameters are provided by the run_rpc_command function, except for
1395 * argc, argv which are passed through.
1397 * @param c A net_context structure
1398 * @param domain_sid The domain sid aquired from the remote server
1399 * @param cli A cli_state connected to the server.
1400 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1401 * @param argc Standard main() style argc
1402 * @param argv Standard main() style argv. Initial components are already
1405 * @return Normal NTSTATUS return.
1408 NTSTATUS rpc_printer_publish_list_internals(struct net_context *c,
1409 const struct dom_sid *domain_sid,
1410 const char *domain_name,
1411 struct cli_state *cli,
1412 struct rpc_pipe_client *pipe_hnd,
1413 TALLOC_CTX *mem_ctx,
1417 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1418 uint32_t i, num_printers;
1420 const char *printername, *sharename;
1421 union spoolss_PrinterInfo *info_enum;
1422 union spoolss_PrinterInfo info;
1423 struct policy_handle hnd;
1426 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_enum))
1429 for (i = 0; i < num_printers; i++) {
1431 /* do some initialization */
1432 printername = info_enum[i].info2.printername;
1433 sharename = info_enum[i].info2.sharename;
1435 if (!printername || !sharename) {
1439 /* open printer handle */
1440 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1441 PRINTER_ALL_ACCESS, cli->user_name, &hnd))
1444 /* check for existing dst printer */
1445 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info))
1448 if (!info.info7.guid) {
1451 state = info.info7.action;
1453 case DSPRINT_PUBLISH:
1454 printf(_("printer [%s] is published"),
1457 printf(_(", guid: %s"),info.info7.guid);
1460 case DSPRINT_UNPUBLISH:
1461 printf(_("printer [%s] is unpublished\n"),
1464 case DSPRINT_UPDATE:
1465 printf(_("printer [%s] is currently updating\n"),
1469 printf(_("unkown state: %d\n"), state);
1474 nt_status = NT_STATUS_OK;
1477 if (is_valid_policy_hnd(&hnd))
1478 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1484 * Migrate Printer-ACLs from a source server to the destination server
1486 * All parameters are provided by the run_rpc_command function, except for
1487 * argc, argv which are passed through.
1489 * @param c A net_context structure
1490 * @param domain_sid The domain sid aquired from the remote server
1491 * @param cli A cli_state connected to the server.
1492 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1493 * @param argc Standard main() style argc
1494 * @param argv Standard main() style argv. Initial components are already
1497 * @return Normal NTSTATUS return.
1500 NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c,
1501 const struct dom_sid *domain_sid,
1502 const char *domain_name,
1503 struct cli_state *cli,
1504 struct rpc_pipe_client *pipe_hnd,
1505 TALLOC_CTX *mem_ctx,
1509 /* TODO: what now, info2 or info3 ?
1510 convince jerry that we should add clientside setacls level 3 at least
1512 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1514 uint32_t num_printers;
1516 const char *printername, *sharename;
1517 struct rpc_pipe_client *pipe_hnd_dst = NULL;
1518 struct policy_handle hnd_src, hnd_dst;
1519 union spoolss_PrinterInfo *info_enum;
1520 struct cli_state *cli_dst = NULL;
1521 union spoolss_PrinterInfo info_src, info_dst;
1523 DEBUG(3,("copying printer ACLs\n"));
1525 /* connect destination PI_SPOOLSS */
1526 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
1527 &ndr_table_spoolss.syntax_id);
1528 if (!NT_STATUS_IS_OK(nt_status))
1532 /* enum source printers */
1533 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &info_enum)) {
1534 nt_status = NT_STATUS_UNSUCCESSFUL;
1538 if (!num_printers) {
1539 printf (_("no printers found on server.\n"));
1540 nt_status = NT_STATUS_OK;
1544 /* do something for all printers */
1545 for (i = 0; i < num_printers; i++) {
1547 /* do some initialization */
1548 printername = info_enum[i].info2.printername;
1549 sharename = info_enum[i].info2.sharename;
1551 if (!printername || !sharename) {
1552 nt_status = NT_STATUS_UNSUCCESSFUL;
1556 /* we can reset NT_STATUS here because we do not
1557 get any real NT_STATUS-codes anymore from now on */
1558 nt_status = NT_STATUS_UNSUCCESSFUL;
1560 d_printf(_("migrating printer ACLs for: [%s] / [%s]\n"),
1561 printername, sharename);
1563 /* according to msdn you have specify these access-rights
1564 to see the security descriptor
1565 - READ_CONTROL (DACL)
1566 - ACCESS_SYSTEM_SECURITY (SACL)
1569 /* open src printer handle */
1570 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1571 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
1574 /* open dst printer handle */
1575 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
1576 PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst))
1579 /* check for existing dst printer */
1580 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst))
1583 /* check for existing src printer */
1584 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, 3, &info_src))
1587 /* Copy Security Descriptor */
1589 /* copy secdesc (info level 2) */
1590 info_dst.info2.devmode = NULL;
1591 info_dst.info2.secdesc = dup_sec_desc(mem_ctx, info_src.info3.secdesc);
1594 display_sec_desc(info_dst.info2.secdesc);
1596 if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst))
1599 DEBUGADD(1,("\tSetPrinter of SECDESC succeeded\n"));
1602 /* close printer handles here */
1603 if (is_valid_policy_hnd(&hnd_src)) {
1604 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1607 if (is_valid_policy_hnd(&hnd_dst)) {
1608 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1613 nt_status = NT_STATUS_OK;
1617 if (is_valid_policy_hnd(&hnd_src)) {
1618 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1621 if (is_valid_policy_hnd(&hnd_dst)) {
1622 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1626 cli_shutdown(cli_dst);
1632 * Migrate printer-forms from a src server to the dst server
1634 * All parameters are provided by the run_rpc_command function, except for
1635 * argc, argv which are passed through.
1637 * @param c A net_context structure
1638 * @param domain_sid The domain sid aquired from the remote server
1639 * @param cli A cli_state connected to the server.
1640 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1641 * @param argc Standard main() style argc
1642 * @param argv Standard main() style argv. Initial components are already
1645 * @return Normal NTSTATUS return.
1648 NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c,
1649 const struct dom_sid *domain_sid,
1650 const char *domain_name,
1651 struct cli_state *cli,
1652 struct rpc_pipe_client *pipe_hnd,
1653 TALLOC_CTX *mem_ctx,
1657 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1660 uint32_t num_printers;
1662 const char *printername, *sharename;
1663 struct rpc_pipe_client *pipe_hnd_dst = NULL;
1664 struct policy_handle hnd_src, hnd_dst;
1665 union spoolss_PrinterInfo *info_enum;
1666 union spoolss_PrinterInfo info_dst;
1668 union spoolss_FormInfo *forms;
1669 struct cli_state *cli_dst = NULL;
1671 DEBUG(3,("copying forms\n"));
1673 /* connect destination PI_SPOOLSS */
1674 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
1675 &ndr_table_spoolss.syntax_id);
1676 if (!NT_STATUS_IS_OK(nt_status))
1679 /* enum src printers */
1680 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_enum)) {
1681 nt_status = NT_STATUS_UNSUCCESSFUL;
1685 if (!num_printers) {
1686 printf (_("no printers found on server.\n"));
1687 nt_status = NT_STATUS_OK;
1691 /* do something for all printers */
1692 for (i = 0; i < num_printers; i++) {
1694 /* do some initialization */
1695 printername = info_enum[i].info2.printername;
1696 sharename = info_enum[i].info2.sharename;
1698 if (!printername || !sharename) {
1699 nt_status = NT_STATUS_UNSUCCESSFUL;
1702 /* we can reset NT_STATUS here because we do not
1703 get any real NT_STATUS-codes anymore from now on */
1704 nt_status = NT_STATUS_UNSUCCESSFUL;
1706 d_printf(_("migrating printer forms for: [%s] / [%s]\n"),
1707 printername, sharename);
1710 /* open src printer handle */
1711 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1712 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
1715 /* open dst printer handle */
1716 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
1717 PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst))
1720 /* check for existing dst printer */
1721 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst))
1724 /* finally migrate forms */
1725 if (!net_spoolss_enumforms(pipe_hnd, mem_ctx, &hnd_src, level, &num_forms, &forms))
1728 DEBUG(1,("got %d forms for printer\n", num_forms));
1731 for (f = 0; f < num_forms; f++) {
1733 union spoolss_AddFormInfo info;
1736 /* only migrate FORM_PRINTER types, according to jerry
1737 FORM_BUILTIN-types are hard-coded in samba */
1738 if (forms[f].info1.flags != SPOOLSS_FORM_PRINTER)
1742 d_printf(_("\tmigrating form # %d [%s] of type "
1744 f, forms[f].info1.form_name,
1745 forms[f].info1.flags);
1747 info.info1 = (struct spoolss_AddFormInfo1 *)
1748 (void *)&forms[f].info1;
1750 /* FIXME: there might be something wrong with samba's
1752 status = rpccli_spoolss_AddForm(pipe_hnd_dst, mem_ctx,
1757 if (!W_ERROR_IS_OK(result)) {
1758 d_printf(_("\tAddForm form %d: [%s] refused.\n"),
1759 f, forms[f].info1.form_name);
1763 DEBUGADD(1,("\tAddForm of [%s] succeeded\n",
1764 forms[f].info1.form_name));
1768 /* close printer handles here */
1769 if (is_valid_policy_hnd(&hnd_src)) {
1770 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1773 if (is_valid_policy_hnd(&hnd_dst)) {
1774 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1778 nt_status = NT_STATUS_OK;
1782 if (is_valid_policy_hnd(&hnd_src))
1783 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1785 if (is_valid_policy_hnd(&hnd_dst))
1786 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1789 cli_shutdown(cli_dst);
1795 * Migrate printer-drivers from a src server to the dst server
1797 * All parameters are provided by the run_rpc_command function, except for
1798 * argc, argv which are passed through.
1800 * @param c A net_context structure
1801 * @param domain_sid The domain sid aquired from the remote server
1802 * @param cli A cli_state connected to the server.
1803 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1804 * @param argc Standard main() style argc
1805 * @param argv Standard main() style argv. Initial components are already
1808 * @return Normal NTSTATUS return.
1811 NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c,
1812 const struct dom_sid *domain_sid,
1813 const char *domain_name,
1814 struct cli_state *cli,
1815 struct rpc_pipe_client *pipe_hnd,
1816 TALLOC_CTX *mem_ctx,
1820 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1822 uint32_t num_printers;
1824 const char *printername, *sharename;
1825 bool got_src_driver_share = false;
1826 bool got_dst_driver_share = false;
1827 struct rpc_pipe_client *pipe_hnd_dst = NULL;
1828 struct policy_handle hnd_src, hnd_dst;
1829 union spoolss_DriverInfo drv_info_src;
1830 union spoolss_PrinterInfo *info_enum;
1831 union spoolss_PrinterInfo info_dst;
1832 struct cli_state *cli_dst = NULL;
1833 struct cli_state *cli_share_src = NULL;
1834 struct cli_state *cli_share_dst = NULL;
1835 const char *drivername = NULL;
1837 DEBUG(3,("copying printer-drivers\n"));
1839 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
1840 &ndr_table_spoolss.syntax_id);
1841 if (!NT_STATUS_IS_OK(nt_status))
1844 /* open print$-share on the src server */
1845 nt_status = connect_to_service(c, &cli_share_src, &cli->dest_ss,
1846 cli->desthost, "print$", "A:");
1847 if (!NT_STATUS_IS_OK(nt_status))
1850 got_src_driver_share = true;
1853 /* open print$-share on the dst server */
1854 nt_status = connect_to_service(c, &cli_share_dst, &cli_dst->dest_ss,
1855 cli_dst->desthost, "print$", "A:");
1856 if (!NT_STATUS_IS_OK(nt_status))
1859 got_dst_driver_share = true;
1862 /* enum src printers */
1863 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_enum)) {
1864 nt_status = NT_STATUS_UNSUCCESSFUL;
1868 if (num_printers == 0) {
1869 printf (_("no printers found on server.\n"));
1870 nt_status = NT_STATUS_OK;
1875 /* do something for all printers */
1876 for (p = 0; p < num_printers; p++) {
1878 /* do some initialization */
1879 printername = info_enum[p].info2.printername;
1880 sharename = info_enum[p].info2.sharename;
1882 if (!printername || !sharename) {
1883 nt_status = NT_STATUS_UNSUCCESSFUL;
1887 /* we can reset NT_STATUS here because we do not
1888 get any real NT_STATUS-codes anymore from now on */
1889 nt_status = NT_STATUS_UNSUCCESSFUL;
1891 d_printf(_("migrating printer driver for: [%s] / [%s]\n"),
1892 printername, sharename);
1894 /* open dst printer handle */
1895 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
1896 PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst))
1899 /* check for existing dst printer */
1900 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst))
1904 /* open src printer handle */
1905 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1906 MAXIMUM_ALLOWED_ACCESS,
1907 pipe_hnd->auth->user_name,
1911 /* in a first step call getdriver for each shared printer (per arch)
1912 to get a list of all files that have to be copied */
1914 for (i=0; archi_table[i].long_archi!=NULL; i++) {
1917 if (!net_spoolss_getprinterdriver(pipe_hnd, mem_ctx, &hnd_src,
1918 level, archi_table[i].long_archi,
1919 archi_table[i].version, &drv_info_src))
1922 drivername = drv_info_src.info3.driver_name;
1925 display_print_driver3(&drv_info_src.info3);
1927 /* check arch dir */
1928 nt_status = check_arch_dir(cli_share_dst, archi_table[i].short_archi);
1929 if (!NT_STATUS_IS_OK(nt_status))
1933 /* copy driver-files */
1934 nt_status = copy_print_driver_3(c, mem_ctx, cli_share_src, cli_share_dst,
1935 archi_table[i].short_archi,
1936 &drv_info_src.info3);
1937 if (!NT_STATUS_IS_OK(nt_status))
1942 if (!net_spoolss_addprinterdriver(pipe_hnd_dst, mem_ctx, level, &drv_info_src)) {
1943 nt_status = NT_STATUS_UNSUCCESSFUL;
1947 DEBUGADD(1,("Sucessfully added driver [%s] for printer [%s]\n",
1948 drivername, printername));
1952 if (!drivername || strlen(drivername) == 0) {
1953 DEBUGADD(1,("Did not get driver for printer %s\n",
1959 info_dst.info2.drivername = drivername;
1961 if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst)) {
1962 nt_status = NT_STATUS_UNSUCCESSFUL;
1966 DEBUGADD(1,("Sucessfully set driver %s for printer %s\n",
1967 drivername, printername));
1970 if (is_valid_policy_hnd(&hnd_dst)) {
1971 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1975 if (is_valid_policy_hnd(&hnd_src)) {
1976 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1980 nt_status = NT_STATUS_OK;
1984 if (is_valid_policy_hnd(&hnd_src))
1985 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1987 if (is_valid_policy_hnd(&hnd_dst))
1988 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1991 cli_shutdown(cli_dst);
1994 if (got_src_driver_share)
1995 cli_shutdown(cli_share_src);
1997 if (got_dst_driver_share)
1998 cli_shutdown(cli_share_dst);
2005 * Migrate printer-queues from a src to the dst server
2006 * (requires a working "addprinter command" to be installed for the local smbd)
2008 * All parameters are provided by the run_rpc_command function, except for
2009 * argc, argv which are passed through.
2011 * @param c A net_context structure
2012 * @param domain_sid The domain sid aquired from the remote server
2013 * @param cli A cli_state connected to the server.
2014 * @param mem_ctx Talloc context, destoyed on compleation of the function.
2015 * @param argc Standard main() style argc
2016 * @param argv Standard main() style argv. Initial components are already
2019 * @return Normal NTSTATUS return.
2022 NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c,
2023 const struct dom_sid *domain_sid,
2024 const char *domain_name,
2025 struct cli_state *cli,
2026 struct rpc_pipe_client *pipe_hnd,
2027 TALLOC_CTX *mem_ctx,
2032 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
2033 uint32_t i = 0, num_printers;
2035 union spoolss_PrinterInfo info_dst, info_src;
2036 union spoolss_PrinterInfo *info_enum;
2037 struct cli_state *cli_dst = NULL;
2038 struct policy_handle hnd_dst, hnd_src;
2039 const char *printername, *sharename;
2040 struct rpc_pipe_client *pipe_hnd_dst = NULL;
2041 struct spoolss_SetPrinterInfoCtr info_ctr;
2043 DEBUG(3,("copying printers\n"));
2045 /* connect destination PI_SPOOLSS */
2046 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
2047 &ndr_table_spoolss.syntax_id);
2048 if (!NT_STATUS_IS_OK(nt_status))
2052 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &info_enum)) {
2053 nt_status = NT_STATUS_UNSUCCESSFUL;
2057 if (!num_printers) {
2058 printf (_("no printers found on server.\n"));
2059 nt_status = NT_STATUS_OK;
2063 /* do something for all printers */
2064 for (i = 0; i < num_printers; i++) {
2066 struct spoolss_SetPrinterInfo2 info2;
2068 /* do some initialization */
2069 printername = info_enum[i].info2.printername;
2070 sharename = info_enum[i].info2.sharename;
2072 if (!printername || !sharename) {
2073 nt_status = NT_STATUS_UNSUCCESSFUL;
2076 /* we can reset NT_STATUS here because we do not
2077 get any real NT_STATUS-codes anymore from now on */
2078 nt_status = NT_STATUS_UNSUCCESSFUL;
2080 d_printf(_("migrating printer queue for: [%s] / [%s]\n"),
2081 printername, sharename);
2083 /* open dst printer handle */
2084 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
2085 PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) {
2087 DEBUG(1,("could not open printer: %s\n", sharename));
2090 /* check for existing dst printer */
2091 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst)) {
2092 printf (_("could not get printer, creating printer.\n"));
2094 DEBUG(1,("printer already exists: %s\n", sharename));
2095 /* close printer handle here - dst only, not got src yet. */
2096 if (is_valid_policy_hnd(&hnd_dst)) {
2097 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2102 /* now get again src printer ctr via getprinter,
2103 we first need a handle for that */
2105 /* open src printer handle */
2106 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
2107 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
2110 /* getprinter on the src server */
2111 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, level, &info_src))
2114 /* copy each src printer to a dst printer 1:1,
2115 maybe some values have to be changed though */
2116 d_printf(_("creating printer: %s\n"), printername);
2118 info_ctr.level = level;
2119 spoolss_printerinfo2_to_setprinterinfo2(&info_src.info2, &info2);
2120 info_ctr.info.info2 = &info2;
2122 result = rpccli_spoolss_addprinterex(pipe_hnd_dst,
2126 if (W_ERROR_IS_OK(result))
2127 d_printf (_("printer [%s] successfully added.\n"),
2129 else if (W_ERROR_V(result) == W_ERROR_V(WERR_PRINTER_ALREADY_EXISTS))
2130 d_fprintf (stderr, _("printer [%s] already exists.\n"),
2133 d_fprintf (stderr, _("could not create printer [%s]\n"),
2138 /* close printer handles here */
2139 if (is_valid_policy_hnd(&hnd_src)) {
2140 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2143 if (is_valid_policy_hnd(&hnd_dst)) {
2144 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2148 nt_status = NT_STATUS_OK;
2151 if (is_valid_policy_hnd(&hnd_src))
2152 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2154 if (is_valid_policy_hnd(&hnd_dst))
2155 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2158 cli_shutdown(cli_dst);
2164 * Migrate Printer-Settings from a src server to the dst server
2165 * (for this to work, printers and drivers already have to be migrated earlier)
2167 * All parameters are provided by the run_rpc_command function, except for
2168 * argc, argv which are passed through.
2170 * @param c A net_context structure
2171 * @param domain_sid The domain sid aquired from the remote server
2172 * @param cli A cli_state connected to the server.
2173 * @param mem_ctx Talloc context, destoyed on compleation of the function.
2174 * @param argc Standard main() style argc
2175 * @param argv Standard main() style argv. Initial components are already
2178 * @return Normal NTSTATUS return.
2181 NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
2182 const struct dom_sid *domain_sid,
2183 const char *domain_name,
2184 struct cli_state *cli,
2185 struct rpc_pipe_client *pipe_hnd,
2186 TALLOC_CTX *mem_ctx,
2191 /* FIXME: Here the nightmare begins */
2194 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
2195 uint32_t i = 0, p = 0, j = 0;
2196 uint32_t num_printers;
2198 const char *printername, *sharename;
2199 struct rpc_pipe_client *pipe_hnd_dst = NULL;
2200 struct policy_handle hnd_src, hnd_dst;
2201 union spoolss_PrinterInfo *info_enum;
2202 union spoolss_PrinterInfo info_dst_publish;
2203 union spoolss_PrinterInfo info_dst;
2204 struct cli_state *cli_dst = NULL;
2205 char *devicename = NULL, *unc_name = NULL, *url = NULL;
2206 const char *longname;
2207 const char **keylist = NULL;
2210 ZERO_STRUCT(info_dst_publish);
2212 DEBUG(3,("copying printer settings\n"));
2214 /* connect destination PI_SPOOLSS */
2215 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
2216 &ndr_table_spoolss.syntax_id);
2217 if (!NT_STATUS_IS_OK(nt_status))
2220 /* enum src printers */
2221 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &info_enum)) {
2222 nt_status = NT_STATUS_UNSUCCESSFUL;
2226 if (!num_printers) {
2227 printf (_("no printers found on server.\n"));
2228 nt_status = NT_STATUS_OK;
2233 /* needed for dns-strings in regkeys */
2234 longname = get_mydnsfullname();
2236 nt_status = NT_STATUS_UNSUCCESSFUL;
2240 /* do something for all printers */
2241 for (i = 0; i < num_printers; i++) {
2243 uint32_t value_offered = 0, value_needed;
2244 uint32_t data_offered = 0, data_needed;
2245 enum winreg_Type type;
2246 uint8_t *buffer = NULL;
2247 const char *value_name = NULL;
2249 /* do some initialization */
2250 printername = info_enum[i].info2.printername;
2251 sharename = info_enum[i].info2.sharename;
2253 if (!printername || !sharename) {
2254 nt_status = NT_STATUS_UNSUCCESSFUL;
2257 /* we can reset NT_STATUS here because we do not
2258 get any real NT_STATUS-codes anymore from now on */
2259 nt_status = NT_STATUS_UNSUCCESSFUL;
2261 d_printf(_("migrating printer settings for: [%s] / [%s]\n"),
2262 printername, sharename);
2265 /* open src printer handle */
2266 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
2267 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
2270 /* open dst printer handle */
2271 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
2272 PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst))
2275 /* check for existing dst printer */
2276 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst,
2281 /* STEP 1: COPY DEVICE-MODE and other
2282 PRINTER_INFO_2-attributes
2285 info_dst.info2 = info_enum[i].info2;
2287 /* why is the port always disconnected when the printer
2288 is correctly installed (incl. driver ???) */
2289 info_dst.info2.portname = SAMBA_PRINTER_PORT_NAME;
2291 /* check if printer is published */
2292 if (info_enum[i].info2.attributes & PRINTER_ATTRIBUTE_PUBLISHED) {
2294 /* check for existing dst printer */
2295 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 7, &info_dst_publish))
2298 info_dst_publish.info7.action = DSPRINT_PUBLISH;
2300 /* ignore false from setprinter due to WERR_IO_PENDING */
2301 net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 7, &info_dst_publish);
2303 DEBUG(3,("republished printer\n"));
2306 if (info_enum[i].info2.devmode != NULL) {
2308 /* copy devmode (info level 2) */
2309 info_dst.info2.devmode = info_enum[i].info2.devmode;
2311 /* do not copy security descriptor (we have another
2312 * command for that) */
2313 info_dst.info2.secdesc = NULL;
2316 info_dst.info2.devmode.devicename =
2317 talloc_asprintf(mem_ctx, "\\\\%s\\%s",
2318 longname, printername);
2319 if (!info_dst.info2.devmode.devicename) {
2320 nt_status = NT_STATUS_NO_MEMORY;
2324 if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst,
2328 DEBUGADD(1,("\tSetPrinter of DEVICEMODE succeeded\n"));
2331 /* STEP 2: COPY REGISTRY VALUES */
2333 /* please keep in mind that samba parse_spools gives horribly
2334 crippled results when used to rpccli_spoolss_enumprinterdataex
2335 a win2k3-server. (Bugzilla #1851)
2336 FIXME: IIRC I've seen it too on a win2k-server
2339 /* enumerate data on src handle */
2340 nt_status = rpccli_spoolss_EnumPrinterData(pipe_hnd, mem_ctx,
2352 data_offered = data_needed;
2353 value_offered = value_needed;
2354 buffer = talloc_zero_array(mem_ctx, uint8_t, data_needed);
2355 value_name = talloc_zero_array(mem_ctx, char, value_needed);
2357 /* loop for all printerdata of "PrinterDriverData" */
2358 while (NT_STATUS_IS_OK(nt_status) && W_ERROR_IS_OK(result)) {
2360 nt_status = rpccli_spoolss_EnumPrinterData(pipe_hnd, mem_ctx,
2371 /* loop for all reg_keys */
2372 if (NT_STATUS_IS_OK(nt_status) && W_ERROR_IS_OK(result)) {
2375 if (c->opt_verbose) {
2376 struct regval_blob *v;
2378 v = regval_compose(talloc_tos(),
2384 nt_status = NT_STATUS_NO_MEMORY;
2388 display_reg_value(SPOOL_PRINTERDATA_KEY, v);
2393 if (!net_spoolss_setprinterdata(pipe_hnd_dst, mem_ctx,
2394 &hnd_dst, value_name,
2395 type, buffer, data_offered))
2398 DEBUGADD(1,("\tSetPrinterData of [%s] succeeded\n",
2403 /* STEP 3: COPY SUBKEY VALUES */
2405 /* here we need to enum all printer_keys and then work
2406 on the result with enum_printer_key_ex. nt4 does not
2407 respond to enumprinterkey, win2k does, so continue
2408 in case of an error */
2410 if (!net_spoolss_enumprinterkey(pipe_hnd, mem_ctx, &hnd_src, "", &keylist)) {
2411 printf(_("got no key-data\n"));
2416 /* work on a list of printer keys
2417 each key has to be enumerated to get all required
2418 information. information is then set via setprinterdataex-calls */
2420 if (keylist == NULL)
2423 for (i=0; keylist && keylist[i] != NULL; i++) {
2425 const char *subkey = keylist[i];
2427 struct spoolss_PrinterEnumValues *info;
2429 /* enumerate all src subkeys */
2430 if (!net_spoolss_enumprinterdataex(pipe_hnd, mem_ctx, 0,
2436 for (j=0; j < count; j++) {
2438 struct regval_blob *value;
2443 /* although samba replies with sane data in most cases we
2444 should try to avoid writing wrong registry data */
2446 if (strequal(info[j].value_name, SPOOL_REG_PORTNAME) ||
2447 strequal(info[j].value_name, SPOOL_REG_UNCNAME) ||
2448 strequal(info[j].value_name, SPOOL_REG_URL) ||
2449 strequal(info[j].value_name, SPOOL_REG_SHORTSERVERNAME) ||
2450 strequal(info[j].value_name, SPOOL_REG_SERVERNAME)) {
2452 if (strequal(info[j].value_name, SPOOL_REG_PORTNAME)) {
2454 /* although windows uses a multi-sz, we use a sz */
2455 push_reg_sz(mem_ctx, &blob, SAMBA_PRINTER_PORT_NAME);
2458 if (strequal(info[j].value_name, SPOOL_REG_UNCNAME)) {
2460 if (asprintf(&unc_name, "\\\\%s\\%s", longname, sharename) < 0) {
2461 nt_status = NT_STATUS_NO_MEMORY;
2464 push_reg_sz(mem_ctx, &blob, unc_name);
2467 if (strequal(info[j].value_name, SPOOL_REG_URL)) {
2472 /* FIXME: should we really do that ??? */
2473 if (asprintf(&url, "http://%s:631/printers/%s", longname, sharename) < 0) {
2474 nt_status = NT_STATUS_NO_MEMORY;
2477 push_reg_sz(mem_ctx, NULL, &blob, url);
2478 fstrcpy(value.valuename, SPOOL_REG_URL);
2482 if (strequal(info[j].value_name, SPOOL_REG_SERVERNAME)) {
2484 push_reg_sz(mem_ctx, &blob, longname);
2487 if (strequal(info[j].value_name, SPOOL_REG_SHORTSERVERNAME)) {
2489 push_reg_sz(mem_ctx, &blob, global_myname());
2492 value = regval_compose(talloc_tos(),
2495 blob.length == 0 ? NULL : blob.data,
2497 if (value == NULL) {
2498 nt_status = NT_STATUS_NO_MEMORY;
2503 display_reg_value(subkey, value);
2505 /* here we have to set all subkeys on the dst server */
2506 if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst,
2516 struct regval_blob *v;
2518 v = regval_compose(talloc_tos(),
2522 info[j].data->length);
2524 nt_status = NT_STATUS_NO_MEMORY;
2528 if (c->opt_verbose) {
2529 display_reg_value(subkey, v);
2532 /* here we have to set all subkeys on the dst server */
2533 if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst,
2541 DEBUGADD(1,("\tSetPrinterDataEx of key [%s\\%s] succeeded\n",
2542 subkey, info[j].value_name));
2547 TALLOC_FREE(keylist);
2549 /* close printer handles here */
2550 if (is_valid_policy_hnd(&hnd_src)) {
2551 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2554 if (is_valid_policy_hnd(&hnd_dst)) {
2555 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2560 nt_status = NT_STATUS_OK;
2563 SAFE_FREE(devicename);
2565 SAFE_FREE(unc_name);
2567 if (is_valid_policy_hnd(&hnd_src))
2568 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2570 if (is_valid_policy_hnd(&hnd_dst))
2571 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2574 cli_shutdown(cli_dst);