2 Samba Unix/Linux SMB client library
3 Distributed SMB/CIFS Server Management Utility
4 Copyright (C) 2004 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"
23 const char *long_archi;
24 const char *short_archi;
29 /* support itanium as well */
30 static const struct 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_print_driver_3(DRIVER_INFO_3 *i1)
83 fstring architecture = "";
84 fstring driverpath = "";
85 fstring datafile = "";
86 fstring configfile = "";
87 fstring helpfile = "";
88 fstring dependentfiles = "";
89 fstring monitorname = "";
90 fstring defaultdatatype = "";
98 rpcstr_pull(name, i1->name.buffer, sizeof(name), -1, STR_TERMINATE);
99 rpcstr_pull(architecture, i1->architecture.buffer, sizeof(architecture), -1, STR_TERMINATE);
100 rpcstr_pull(driverpath, i1->driverpath.buffer, sizeof(driverpath), -1, STR_TERMINATE);
101 rpcstr_pull(datafile, i1->datafile.buffer, sizeof(datafile), -1, STR_TERMINATE);
102 rpcstr_pull(configfile, i1->configfile.buffer, sizeof(configfile), -1, STR_TERMINATE);
103 rpcstr_pull(helpfile, i1->helpfile.buffer, sizeof(helpfile), -1, STR_TERMINATE);
104 rpcstr_pull(monitorname, i1->monitorname.buffer, sizeof(monitorname), -1, STR_TERMINATE);
105 rpcstr_pull(defaultdatatype, i1->defaultdatatype.buffer, sizeof(defaultdatatype), -1, STR_TERMINATE);
107 d_printf ("Printer Driver Info 3:\n");
108 d_printf ("\tVersion: [%x]\n", i1->version);
109 d_printf ("\tDriver Name: [%s]\n",name);
110 d_printf ("\tArchitecture: [%s]\n", architecture);
111 d_printf ("\tDriver Path: [%s]\n", driverpath);
112 d_printf ("\tDatafile: [%s]\n", datafile);
113 d_printf ("\tConfigfile: [%s]\n", configfile);
114 d_printf ("\tHelpfile: [%s]\n\n", helpfile);
117 rpcstr_pull(dependentfiles, i1->dependentfiles+length, sizeof(dependentfiles), -1, STR_TERMINATE);
119 length+=strlen(dependentfiles)+1;
121 if (strlen(dependentfiles) > 0) {
122 d_printf ("\tDependentfiles: [%s]\n", dependentfiles);
130 d_printf ("\tMonitorname: [%s]\n", monitorname);
131 d_printf ("\tDefaultdatatype: [%s]\n\n", defaultdatatype);
136 static void display_reg_value(const char *subkey, REGISTRY_VALUE value)
142 d_printf("\t[%s:%s]: REG_DWORD: 0x%08x\n", subkey, value.valuename,
143 *((uint32 *) value.data_p));
147 rpcstr_pull_talloc(talloc_tos(),
155 d_printf("\t[%s:%s]: REG_SZ: %s\n", subkey, value.valuename, text);
159 d_printf("\t[%s:%s]: REG_BINARY: unknown length value not displayed\n",
160 subkey, value.valuename);
164 uint32 i, num_values;
167 if (!W_ERROR_IS_OK(reg_pull_multi_sz(NULL, value.data_p,
168 value.size, &num_values,
170 d_printf("reg_pull_multi_sz failed\n");
174 for (i=0; i<num_values; i++) {
175 d_printf("%s\n", values[i]);
182 d_printf("\t%s: unknown type %d\n", value.valuename, value.type);
188 * Copies ACLs, DOS-attributes and timestamps from one
189 * file or directory from one connected share to another connected share
191 * @param c A net_context structure
192 * @param mem_ctx A talloc-context
193 * @param cli_share_src A connected cli_state
194 * @param cli_share_dst A connected cli_state
195 * @param src_file The source file-name
196 * @param dst_file The destination file-name
197 * @param copy_acls Whether to copy acls
198 * @param copy_attrs Whether to copy DOS attributes
199 * @param copy_timestamps Whether to preserve timestamps
200 * @param is_file Whether this file is a file or a dir
202 * @return Normal NTSTATUS return.
205 NTSTATUS net_copy_fileattr(struct net_context *c,
207 struct cli_state *cli_share_src,
208 struct cli_state *cli_share_dst,
209 const char *src_name, const char *dst_name,
210 bool copy_acls, bool copy_attrs,
211 bool copy_timestamps, bool is_file)
213 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
218 time_t f_atime, f_ctime, f_mtime;
221 if (!copy_timestamps && !copy_acls && !copy_attrs)
224 /* open file/dir on the originating server */
226 DEBUGADD(3,("opening %s %s on originating server\n",
227 is_file?"file":"dir", src_name));
229 fnum_src = cli_nt_create(cli_share_src, src_name, READ_CONTROL_ACCESS);
230 if (fnum_src == -1) {
231 DEBUGADD(0,("cannot open %s %s on originating server %s\n",
232 is_file?"file":"dir", src_name, cli_errstr(cli_share_src)));
233 nt_status = cli_nt_error(cli_share_src);
240 /* get the security descriptor */
241 sd = cli_query_secdesc(cli_share_src, fnum_src, mem_ctx);
243 DEBUG(0,("failed to get security descriptor: %s\n",
244 cli_errstr(cli_share_src)));
245 nt_status = cli_nt_error(cli_share_src);
249 if (c->opt_verbose && DEBUGLEVEL >= 3)
250 display_sec_desc(sd);
254 if (copy_attrs || copy_timestamps) {
256 /* get file attributes */
257 if (!cli_getattrE(cli_share_src, fnum_src, &attr, NULL,
258 &f_ctime, &f_atime, &f_mtime)) {
259 DEBUG(0,("failed to get file-attrs: %s\n",
260 cli_errstr(cli_share_src)));
261 nt_status = cli_nt_error(cli_share_src);
267 /* open the file/dir on the destination server */
269 fnum_dst = cli_nt_create(cli_share_dst, dst_name, WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS);
270 if (fnum_dst == -1) {
271 DEBUG(0,("failed to open %s on the destination server: %s: %s\n",
272 is_file?"file":"dir", dst_name, cli_errstr(cli_share_dst)));
273 nt_status = cli_nt_error(cli_share_dst);
277 if (copy_timestamps) {
280 if (!cli_setattrE(cli_share_dst, fnum_dst, f_ctime, f_atime, f_mtime)) {
281 DEBUG(0,("failed to set file-attrs (timestamps): %s\n",
282 cli_errstr(cli_share_dst)));
283 nt_status = cli_nt_error(cli_share_dst);
291 if (!cli_set_secdesc(cli_share_dst, fnum_dst, sd)) {
292 DEBUG(0,("could not set secdesc on %s: %s\n",
293 dst_name, cli_errstr(cli_share_dst)));
294 nt_status = cli_nt_error(cli_share_dst);
302 if (!cli_setatr(cli_share_dst, dst_name, attr, 0)) {
303 DEBUG(0,("failed to set file-attrs: %s\n",
304 cli_errstr(cli_share_dst)));
305 nt_status = cli_nt_error(cli_share_dst);
313 if (!cli_close(cli_share_src, fnum_src)) {
314 d_fprintf(stderr, "could not close %s on originating server: %s\n",
315 is_file?"file":"dir", cli_errstr(cli_share_src));
316 nt_status = cli_nt_error(cli_share_src);
320 if (!cli_close(cli_share_dst, fnum_dst)) {
321 d_fprintf(stderr, "could not close %s on destination server: %s\n",
322 is_file?"file":"dir", cli_errstr(cli_share_dst));
323 nt_status = cli_nt_error(cli_share_dst);
328 nt_status = NT_STATUS_OK;
334 cli_close(cli_share_src, fnum_src);
337 cli_close(cli_share_dst, fnum_dst);
343 * Copy a file or directory from a connected share to another connected share
345 * @param c A net_context structure
346 * @param mem_ctx A talloc-context
347 * @param cli_share_src A connected cli_state
348 * @param cli_share_dst A connected cli_state
349 * @param src_file The source file-name
350 * @param dst_file The destination file-name
351 * @param copy_acls Whether to copy acls
352 * @param copy_attrs Whether to copy DOS attributes
353 * @param copy_timestamps Whether to preserve timestamps
354 * @param is_file Whether this file is a file or a dir
356 * @return Normal NTSTATUS return.
359 NTSTATUS net_copy_file(struct net_context *c,
361 struct cli_state *cli_share_src,
362 struct cli_state *cli_share_dst,
363 const char *src_name, const char *dst_name,
364 bool copy_acls, bool copy_attrs,
365 bool copy_timestamps, bool is_file)
367 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
370 static int io_bufsize = 64512;
371 int read_size = io_bufsize;
376 if (!src_name || !dst_name)
379 if (cli_share_src == NULL || cli_share_dst == NULL)
382 /* open on the originating server */
383 DEBUGADD(3,("opening %s %s on originating server\n",
384 is_file ? "file":"dir", src_name));
386 fnum_src = cli_open(cli_share_src, src_name, O_RDONLY, DENY_NONE);
388 fnum_src = cli_nt_create(cli_share_src, src_name, READ_CONTROL_ACCESS);
390 if (fnum_src == -1) {
391 DEBUGADD(0,("cannot open %s %s on originating server %s\n",
392 is_file ? "file":"dir",
393 src_name, cli_errstr(cli_share_src)));
394 nt_status = cli_nt_error(cli_share_src);
401 /* open file on the destination server */
402 DEBUGADD(3,("opening file %s on destination server\n", dst_name));
403 fnum_dst = cli_open(cli_share_dst, dst_name,
404 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE);
406 if (fnum_dst == -1) {
407 DEBUGADD(1,("cannot create file %s on destination server: %s\n",
408 dst_name, cli_errstr(cli_share_dst)));
409 nt_status = cli_nt_error(cli_share_dst);
413 /* allocate memory */
414 if (!(data = (char *)SMB_MALLOC(read_size))) {
415 d_fprintf(stderr, "malloc fail for size %d\n", read_size);
416 nt_status = NT_STATUS_NO_MEMORY;
423 if (c->opt_verbose) {
425 d_printf("copying [\\\\%s\\%s%s] => [\\\\%s\\%s%s] "
426 "%s ACLs and %s DOS Attributes %s\n",
427 cli_share_src->desthost, cli_share_src->share, src_name,
428 cli_share_dst->desthost, cli_share_dst->share, dst_name,
429 copy_acls ? "with" : "without",
430 copy_attrs ? "with" : "without",
431 copy_timestamps ? "(preserving timestamps)" : "" );
439 n = cli_read(cli_share_src, fnum_src, data, nread,
445 ret = cli_write(cli_share_dst, fnum_dst, 0, data,
449 d_fprintf(stderr, "Error writing file: %s\n",
450 cli_errstr(cli_share_dst));
451 nt_status = cli_nt_error(cli_share_dst);
459 if (!is_file && !cli_chkpath(cli_share_dst, dst_name)) {
462 DEBUGADD(3,("creating dir %s on the destination server\n",
465 if (!cli_mkdir(cli_share_dst, dst_name)) {
466 DEBUG(0,("cannot create directory %s: %s\n",
467 dst_name, cli_errstr(cli_share_dst)));
468 nt_status = NT_STATUS_NO_SUCH_FILE;
471 if (!cli_chkpath(cli_share_dst, dst_name)) {
472 d_fprintf(stderr, "cannot check for directory %s: %s\n",
473 dst_name, cli_errstr(cli_share_dst));
480 if (!cli_close(cli_share_src, fnum_src)) {
481 d_fprintf(stderr, "could not close file on originating server: %s\n",
482 cli_errstr(cli_share_src));
483 nt_status = cli_nt_error(cli_share_src);
487 if (is_file && !cli_close(cli_share_dst, fnum_dst)) {
488 d_fprintf(stderr, "could not close file on destination server: %s\n",
489 cli_errstr(cli_share_dst));
490 nt_status = cli_nt_error(cli_share_dst);
494 /* possibly we have to copy some file-attributes / acls / sd */
495 nt_status = net_copy_fileattr(c, mem_ctx, cli_share_src, cli_share_dst,
496 src_name, dst_name, copy_acls,
497 copy_attrs, copy_timestamps, is_file);
498 if (!NT_STATUS_IS_OK(nt_status))
502 nt_status = NT_STATUS_OK;
508 cli_close(cli_share_src, fnum_src);
511 cli_close(cli_share_dst, fnum_dst);
519 * Copy a driverfile from on connected share to another connected share
520 * This silently assumes that a driver-file is picked up from
522 * \\src_server\print$\{arch}\{version}\file
526 * \\dst_server\print$\{arch}\file
528 * to be added via setdriver-calls later.
529 * @param c A net_context structure
530 * @param mem_ctx A talloc-context
531 * @param cli_share_src A cli_state connected to source print$-share
532 * @param cli_share_dst A cli_state connected to destination print$-share
533 * @param file The file-name to be copied
534 * @param short_archi The name of the driver-architecture (short form)
536 * @return Normal NTSTATUS return.
539 static NTSTATUS net_copy_driverfile(struct net_context *c,
541 struct cli_state *cli_share_src,
542 struct cli_state *cli_share_dst,
543 const char *file, const char *short_archi) {
545 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
557 /* scroll through the file until we have the part
558 beyond archi_table.short_archi */
560 while (next_token_talloc(mem_ctx, &p, &tok, "\\")) {
561 if (strequal(tok, short_archi)) {
562 next_token_talloc(mem_ctx, &p, &version, "\\");
563 next_token_talloc(mem_ctx, &p, &filename, "\\");
567 /* build source file name */
568 if (asprintf(&src_name, "\\%s\\%s\\%s", short_archi, version, filename) < 0 )
569 return NT_STATUS_NO_MEMORY;
572 /* create destination file name */
573 if (asprintf(&dst_name, "\\%s\\%s", short_archi, filename) < 0 )
574 return NT_STATUS_NO_MEMORY;
577 /* finally copy the file */
578 nt_status = net_copy_file(c, mem_ctx, cli_share_src, cli_share_dst,
579 src_name, dst_name, false, false, false, true);
580 if (!NT_STATUS_IS_OK(nt_status))
583 nt_status = NT_STATUS_OK;
593 * Check for existing Architecture directory on a given server
595 * @param cli_share A cli_state connected to a print$-share
596 * @param short_archi The Architecture for the print-driver
598 * @return Normal NTSTATUS return.
601 static NTSTATUS check_arch_dir(struct cli_state *cli_share, const char *short_archi)
604 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
607 if (asprintf(&dir, "\\%s", short_archi) < 0) {
608 return NT_STATUS_NO_MEMORY;
611 DEBUG(10,("creating print-driver dir for architecture: %s\n",
614 if (!cli_mkdir(cli_share, dir)) {
615 DEBUG(1,("cannot create directory %s: %s\n",
616 dir, cli_errstr(cli_share)));
617 nt_status = NT_STATUS_NO_SUCH_FILE;
620 if (!cli_chkpath(cli_share, dir)) {
621 d_fprintf(stderr, "cannot check %s: %s\n",
622 dir, cli_errstr(cli_share));
626 nt_status = NT_STATUS_OK;
634 * Copy a print-driver (level 3) from one connected print$-share to another
635 * connected print$-share
637 * @param c A net_context structure
638 * @param mem_ctx A talloc-context
639 * @param cli_share_src A cli_state connected to a print$-share
640 * @param cli_share_dst A cli_state connected to a print$-share
641 * @param short_archi The Architecture for the print-driver
642 * @param i1 The DRIVER_INFO_3-struct
644 * @return Normal NTSTATUS return.
647 static NTSTATUS copy_print_driver_3(struct net_context *c,
649 struct cli_state *cli_share_src,
650 struct cli_state *cli_share_dst,
651 const char *short_archi,
652 struct spoolss_DriverInfo3 *r)
654 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
662 d_printf("copying driver: [%s], for architecture: [%s], version: [%d]\n",
663 r->driver_name, short_archi, r->version);
665 nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst,
666 r->driver_path, short_archi);
667 if (!NT_STATUS_IS_OK(nt_status))
670 nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst,
671 r->data_file, short_archi);
672 if (!NT_STATUS_IS_OK(nt_status))
675 nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst,
676 r->config_file, short_archi);
677 if (!NT_STATUS_IS_OK(nt_status))
680 nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst,
681 r->help_file, short_archi);
682 if (!NT_STATUS_IS_OK(nt_status))
685 for (i=0; r->dependent_files[i] != NULL; i++) {
687 nt_status = net_copy_driverfile(c, mem_ctx,
688 cli_share_src, cli_share_dst,
689 r->dependent_files[i], short_archi);
690 if (!NT_STATUS_IS_OK(nt_status)) {
699 * net_spoolss-functions
700 * =====================
702 * the net_spoolss-functions aim to simplify spoolss-client-functions
703 * required during the migration-process wrt buffer-sizes, returned
706 * this greatly reduces the complexitiy of the migrate-functions.
710 static bool net_spoolss_enum_printers(struct rpc_pipe_client *pipe_hnd,
715 uint32 *num_printers,
716 PRINTER_INFO_CTR *ctr)
721 result = rpccli_spoolss_enum_printers(pipe_hnd, mem_ctx, name, flags,
722 level, num_printers, ctr);
724 if (!W_ERROR_IS_OK(result)) {
725 printf("cannot enum printers: %s\n", win_errstr(result));
732 static bool net_spoolss_open_printer_ex(struct rpc_pipe_client *pipe_hnd,
734 const char *printername,
735 uint32 access_required,
736 const char *username,
740 fstring printername2;
742 fstrcpy(printername2, pipe_hnd->srv_name_slash);
743 fstrcat(printername2, "\\");
744 fstrcat(printername2, printername);
746 DEBUG(10,("connecting to: %s as %s for %s and access: %x\n",
747 pipe_hnd->srv_name_slash, username, printername2, access_required));
750 result = rpccli_spoolss_openprinter_ex(pipe_hnd, mem_ctx,
755 /* be more verbose */
756 if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) {
757 d_fprintf(stderr, "no access to printer [%s] on [%s] for user [%s] granted\n",
758 printername2, pipe_hnd->srv_name_slash, username);
762 if (!W_ERROR_IS_OK(result)) {
763 d_fprintf(stderr, "cannot open printer %s on server %s: %s\n",
764 printername2, pipe_hnd->srv_name_slash, win_errstr(result));
768 DEBUG(2,("got printer handle for printer: %s, server: %s\n",
769 printername2, pipe_hnd->srv_name_slash));
774 static bool net_spoolss_getprinter(struct rpc_pipe_client *pipe_hnd,
778 union spoolss_PrinterInfo *info)
782 /* getprinter call */
783 result = rpccli_spoolss_getprinter(pipe_hnd, mem_ctx,
788 if (!W_ERROR_IS_OK(result)) {
789 printf("cannot get printer-info: %s\n", win_errstr(result));
796 static bool net_spoolss_setprinter(struct rpc_pipe_client *pipe_hnd,
800 union spoolss_PrinterInfo *info)
804 struct spoolss_SetPrinterInfoCtr info_ctr;
805 struct spoolss_DevmodeContainer devmode_ctr;
806 struct sec_desc_buf secdesc_ctr;
808 ZERO_STRUCT(devmode_ctr);
809 ZERO_STRUCT(secdesc_ctr);
811 /* setprinter call */
813 info_ctr.level = level;
816 info_ctr.info.info0 = (struct spoolss_SetPrinterInfo0 *)&info->info0;
819 info_ctr.info.info1 = (struct spoolss_SetPrinterInfo1 *)&info->info1;
822 info_ctr.info.info2 = (struct spoolss_SetPrinterInfo2 *)&info->info2;
825 info_ctr.info.info3 = (struct spoolss_SetPrinterInfo3 *)&info->info3;
828 info_ctr.info.info4 = (struct spoolss_SetPrinterInfo4 *)&info->info4;
831 info_ctr.info.info5 = (struct spoolss_SetPrinterInfo5 *)&info->info5;
834 info_ctr.info.info6 = (struct spoolss_SetPrinterInfo6 *)&info->info6;
837 info_ctr.info.info7 = (struct spoolss_SetPrinterInfo7 *)&info->info7;
841 info_ctr.info.info8 = (struct spoolss_SetPrinterInfo8 *)&info->info8;
844 info_ctr.info.info9 = (struct spoolss_SetPrinterInfo9 *)&info->info9;
851 status = rpccli_spoolss_SetPrinter(pipe_hnd, mem_ctx,
859 if (!W_ERROR_IS_OK(result)) {
860 printf("cannot set printer-info: %s\n", win_errstr(result));
868 static bool net_spoolss_setprinterdata(struct rpc_pipe_client *pipe_hnd,
871 REGISTRY_VALUE *value)
875 /* setprinterdata call */
876 result = rpccli_spoolss_setprinterdata(pipe_hnd, mem_ctx, hnd, value);
878 if (!W_ERROR_IS_OK(result)) {
879 printf ("unable to set printerdata: %s\n", win_errstr(result));
887 static bool net_spoolss_enumprinterkey(struct rpc_pipe_client *pipe_hnd,
895 /* enumprinterkey call */
896 result = rpccli_spoolss_enumprinterkey(pipe_hnd, mem_ctx, hnd, keyname, keylist, NULL);
898 if (!W_ERROR_IS_OK(result)) {
899 printf("enumprinterkey failed: %s\n", win_errstr(result));
906 static bool net_spoolss_enumprinterdataex(struct rpc_pipe_client *pipe_hnd,
915 /* enumprinterdataex call */
916 result = rpccli_spoolss_enumprinterdataex(pipe_hnd, mem_ctx, hnd, keyname, ctr);
918 if (!W_ERROR_IS_OK(result)) {
919 printf("enumprinterdataex failed: %s\n", win_errstr(result));
927 static bool net_spoolss_setprinterdataex(struct rpc_pipe_client *pipe_hnd,
931 REGISTRY_VALUE *value)
936 /* setprinterdataex call */
937 status = rpccli_spoolss_SetPrinterDataEx(pipe_hnd, mem_ctx,
946 if (!W_ERROR_IS_OK(result)) {
947 printf("could not set printerdataex: %s\n", win_errstr(result));
954 static bool net_spoolss_enumforms(struct rpc_pipe_client *pipe_hnd,
959 union spoolss_FormInfo **forms)
964 result = rpccli_spoolss_enumforms(pipe_hnd, mem_ctx,
970 if (!W_ERROR_IS_OK(result)) {
971 printf("could not enum forms: %s\n", win_errstr(result));
978 static bool net_spoolss_enumprinterdrivers (struct rpc_pipe_client *pipe_hnd,
980 uint32 level, const char *env,
982 union spoolss_DriverInfo **info)
986 /* enumprinterdrivers call */
987 result = rpccli_spoolss_enumprinterdrivers(pipe_hnd, mem_ctx,
988 pipe_hnd->srv_name_slash,
994 if (!W_ERROR_IS_OK(result)) {
995 printf("cannot enum drivers: %s\n", win_errstr(result));
1002 static bool net_spoolss_getprinterdriver(struct rpc_pipe_client *pipe_hnd,
1003 TALLOC_CTX *mem_ctx,
1004 POLICY_HND *hnd, uint32 level,
1005 const char *env, int version,
1006 union spoolss_DriverInfo *info)
1009 uint32_t server_major_version;
1010 uint32_t server_minor_version;
1012 /* getprinterdriver call */
1013 result = rpccli_spoolss_getprinterdriver2(pipe_hnd, mem_ctx,
1021 &server_major_version,
1022 &server_minor_version);
1023 if (!W_ERROR_IS_OK(result)) {
1024 DEBUG(1,("cannot get driver (for architecture: %s): %s\n",
1025 env, win_errstr(result)));
1026 if (W_ERROR_V(result) != W_ERROR_V(WERR_UNKNOWN_PRINTER_DRIVER) &&
1027 W_ERROR_V(result) != W_ERROR_V(WERR_INVALID_ENVIRONMENT)) {
1028 printf("cannot get driver: %s\n", win_errstr(result));
1037 static bool net_spoolss_addprinterdriver(struct rpc_pipe_client *pipe_hnd,
1038 TALLOC_CTX *mem_ctx, uint32 level,
1039 union spoolss_DriverInfo *info)
1043 struct spoolss_AddDriverInfoCtr info_ctr;
1045 info_ctr.level = level;
1049 info_ctr.info.info2 = (struct spoolss_AddDriverInfo2 *)&info->info2;
1052 info_ctr.info.info3 = (struct spoolss_AddDriverInfo3 *)&info->info3;
1055 printf("unsupported info level: %d\n", level);
1059 /* addprinterdriver call */
1060 status = rpccli_spoolss_AddPrinterDriver(pipe_hnd, mem_ctx,
1061 pipe_hnd->srv_name_slash,
1064 /* be more verbose */
1065 if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) {
1066 printf("You are not allowed to add drivers\n");
1069 if (!W_ERROR_IS_OK(result)) {
1070 printf("cannot add driver: %s\n", win_errstr(result));
1078 * abstraction function to get uint32 num_printers and PRINTER_INFO_CTR ctr
1079 * for a single printer or for all printers depending on argc/argv
1082 static bool get_printer_info(struct rpc_pipe_client *pipe_hnd,
1083 TALLOC_CTX *mem_ctx,
1087 uint32 *num_printers,
1088 PRINTER_INFO_CTR *ctr)
1092 union spoolss_PrinterInfo info;
1094 /* no arguments given, enumerate all printers */
1097 if (!net_spoolss_enum_printers(pipe_hnd, mem_ctx, NULL,
1098 PRINTER_ENUM_LOCAL|PRINTER_ENUM_SHARED,
1099 level, num_printers, ctr))
1108 /* argument given, get a single printer by name */
1109 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, argv[0],
1110 MAXIMUM_ALLOWED_ACCESS,
1111 pipe_hnd->auth->user_name,
1115 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info)) {
1116 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1120 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1125 DEBUG(3,("got %d printers\n", *num_printers));
1132 * List print-queues (including local printers that are not shared)
1134 * All parameters are provided by the run_rpc_command function, except for
1135 * argc, argv which are passed through.
1137 * @param c A net_context structure
1138 * @param domain_sid The domain sid aquired from the remote server
1139 * @param cli A cli_state connected to the server.
1140 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1141 * @param argc Standard main() style argc
1142 * @param argv Standard main() style argv. Initial components are already
1145 * @return Normal NTSTATUS return.
1148 NTSTATUS rpc_printer_list_internals(struct net_context *c,
1149 const DOM_SID *domain_sid,
1150 const char *domain_name,
1151 struct cli_state *cli,
1152 struct rpc_pipe_client *pipe_hnd,
1153 TALLOC_CTX *mem_ctx,
1157 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1158 uint32 i, num_printers;
1160 char *printername, *sharename;
1161 PRINTER_INFO_CTR ctr;
1163 printf("listing printers\n");
1165 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr))
1168 for (i = 0; i < num_printers; i++) {
1169 /* do some initialization */
1170 rpcstr_pull_talloc(mem_ctx,
1172 ctr.printers_2[i].printername.buffer,
1175 rpcstr_pull_talloc(mem_ctx,
1177 ctr.printers_2[i].sharename.buffer,
1181 if (printername && sharename) {
1182 d_printf("printer %d: %s, shared as: %s\n",
1183 i+1, printername, sharename);
1187 return NT_STATUS_OK;
1191 * List printer-drivers from a server
1193 * All parameters are provided by the run_rpc_command function, except for
1194 * argc, argv which are passed through.
1196 * @param c A net_context structure
1197 * @param domain_sid The domain sid aquired from the remote server
1198 * @param cli A cli_state connected to the server.
1199 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1200 * @param argc Standard main() style argc
1201 * @param argv Standard main() style argv. Initial components are already
1204 * @return Normal NTSTATUS return.
1207 NTSTATUS rpc_printer_driver_list_internals(struct net_context *c,
1208 const DOM_SID *domain_sid,
1209 const char *domain_name,
1210 struct cli_state *cli,
1211 struct rpc_pipe_client *pipe_hnd,
1212 TALLOC_CTX *mem_ctx,
1216 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1219 union spoolss_DriverInfo *info;
1222 printf("listing printer-drivers\n");
1224 for (i=0; archi_table[i].long_archi!=NULL; i++) {
1228 /* enum remote drivers */
1229 if (!net_spoolss_enumprinterdrivers(pipe_hnd, mem_ctx, level,
1230 archi_table[i].long_archi,
1231 &num_drivers, &info)) {
1232 nt_status = NT_STATUS_UNSUCCESSFUL;
1236 if (num_drivers == 0) {
1237 d_printf ("no drivers found on server for architecture: [%s].\n",
1238 archi_table[i].long_archi);
1242 d_printf("got %d printer-drivers for architecture: [%s]\n",
1243 num_drivers, archi_table[i].long_archi);
1246 /* do something for all drivers for architecture */
1247 for (d = 0; d < num_drivers; d++) {
1248 display_print_driver3(&info[d].info3);
1252 nt_status = NT_STATUS_OK;
1260 * Publish print-queues with args-wrapper
1262 * @param cli A cli_state connected to the server.
1263 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1264 * @param argc Standard main() style argc
1265 * @param argv Standard main() style argv. Initial components are already
1269 * @return Normal NTSTATUS return.
1272 static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_hnd,
1273 TALLOC_CTX *mem_ctx,
1278 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1279 uint32 i, num_printers;
1281 char *printername, *sharename;
1282 PRINTER_INFO_CTR ctr;
1283 union spoolss_PrinterInfo info;
1284 struct spoolss_SetPrinterInfoCtr info_ctr;
1285 struct spoolss_DevmodeContainer devmode_ctr;
1286 struct sec_desc_buf secdesc_ctr;
1289 const char *action_str;
1291 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr))
1294 for (i = 0; i < num_printers; i++) {
1295 /* do some initialization */
1296 rpcstr_pull_talloc(mem_ctx,
1298 ctr.printers_2[i].printername.buffer,
1301 rpcstr_pull_talloc(mem_ctx,
1303 ctr.printers_2[i].sharename.buffer,
1306 if (!printername || !sharename) {
1310 /* open printer handle */
1311 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1312 PRINTER_ALL_ACCESS, pipe_hnd->auth->user_name, &hnd))
1315 /* check for existing dst printer */
1316 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info))
1319 /* check action and set string */
1321 case DSPRINT_PUBLISH:
1322 action_str = "published";
1324 case DSPRINT_UPDATE:
1325 action_str = "updated";
1327 case DSPRINT_UNPUBLISH:
1328 action_str = "unpublished";
1331 action_str = "unknown action";
1332 printf("unkown action: %d\n", action);
1336 info.info7.action = action;
1338 info_ctr.info.info7 = (struct spoolss_SetPrinterInfo7 *)&info.info7;
1340 ZERO_STRUCT(devmode_ctr);
1341 ZERO_STRUCT(secdesc_ctr);
1343 nt_status = rpccli_spoolss_SetPrinter(pipe_hnd, mem_ctx,
1351 if (!W_ERROR_IS_OK(result) && (W_ERROR_V(result) != W_ERROR_V(WERR_IO_PENDING))) {
1352 printf("cannot set printer-info: %s\n", win_errstr(result));
1356 printf("successfully %s printer %s in Active Directory\n", action_str, sharename);
1359 nt_status = NT_STATUS_OK;
1362 if (is_valid_policy_hnd(&hnd))
1363 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1368 NTSTATUS rpc_printer_publish_publish_internals(struct net_context *c,
1369 const DOM_SID *domain_sid,
1370 const char *domain_name,
1371 struct cli_state *cli,
1372 struct rpc_pipe_client *pipe_hnd,
1373 TALLOC_CTX *mem_ctx,
1377 return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, DSPRINT_PUBLISH);
1380 NTSTATUS rpc_printer_publish_unpublish_internals(struct net_context *c,
1381 const DOM_SID *domain_sid,
1382 const char *domain_name,
1383 struct cli_state *cli,
1384 struct rpc_pipe_client *pipe_hnd,
1385 TALLOC_CTX *mem_ctx,
1389 return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, DSPRINT_UNPUBLISH);
1392 NTSTATUS rpc_printer_publish_update_internals(struct net_context *c,
1393 const DOM_SID *domain_sid,
1394 const char *domain_name,
1395 struct cli_state *cli,
1396 struct rpc_pipe_client *pipe_hnd,
1397 TALLOC_CTX *mem_ctx,
1401 return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, DSPRINT_UPDATE);
1405 * List print-queues w.r.t. their publishing state
1407 * All parameters are provided by the run_rpc_command function, except for
1408 * argc, argv which are passed through.
1410 * @param c A net_context structure
1411 * @param domain_sid The domain sid aquired from the remote server
1412 * @param cli A cli_state connected to the server.
1413 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1414 * @param argc Standard main() style argc
1415 * @param argv Standard main() style argv. Initial components are already
1418 * @return Normal NTSTATUS return.
1421 NTSTATUS rpc_printer_publish_list_internals(struct net_context *c,
1422 const DOM_SID *domain_sid,
1423 const char *domain_name,
1424 struct cli_state *cli,
1425 struct rpc_pipe_client *pipe_hnd,
1426 TALLOC_CTX *mem_ctx,
1430 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1431 uint32 i, num_printers;
1433 char *printername, *sharename;
1434 PRINTER_INFO_CTR ctr, ctr_pub;
1435 union spoolss_PrinterInfo info;
1439 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr))
1442 for (i = 0; i < num_printers; i++) {
1443 ZERO_STRUCT(ctr_pub);
1445 /* do some initialization */
1446 rpcstr_pull_talloc(mem_ctx,
1448 ctr.printers_2[i].printername.buffer,
1451 rpcstr_pull_talloc(mem_ctx,
1453 ctr.printers_2[i].sharename.buffer,
1456 if (!printername || !sharename) {
1460 /* open printer handle */
1461 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1462 PRINTER_ALL_ACCESS, cli->user_name, &hnd))
1465 /* check for existing dst printer */
1466 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info))
1469 if (!info.info7.guid) {
1472 state = info.info7.action;
1474 case DSPRINT_PUBLISH:
1475 printf("printer [%s] is published", sharename);
1477 printf(", guid: %s", info.info7.guid);
1480 case DSPRINT_UNPUBLISH:
1481 printf("printer [%s] is unpublished\n", sharename);
1483 case DSPRINT_UPDATE:
1484 printf("printer [%s] is currently updating\n", sharename);
1487 printf("unkown state: %d\n", state);
1492 nt_status = NT_STATUS_OK;
1495 if (is_valid_policy_hnd(&hnd))
1496 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1502 * Migrate Printer-ACLs from a source server to the destination server
1504 * All parameters are provided by the run_rpc_command function, except for
1505 * argc, argv which are passed through.
1507 * @param c A net_context structure
1508 * @param domain_sid The domain sid aquired from the remote server
1509 * @param cli A cli_state connected to the server.
1510 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1511 * @param argc Standard main() style argc
1512 * @param argv Standard main() style argv. Initial components are already
1515 * @return Normal NTSTATUS return.
1518 NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c,
1519 const DOM_SID *domain_sid,
1520 const char *domain_name,
1521 struct cli_state *cli,
1522 struct rpc_pipe_client *pipe_hnd,
1523 TALLOC_CTX *mem_ctx,
1527 /* TODO: what now, info2 or info3 ?
1528 convince jerry that we should add clientside setacls level 3 at least
1530 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1532 uint32 num_printers;
1534 char *printername, *sharename;
1535 struct rpc_pipe_client *pipe_hnd_dst = NULL;
1536 POLICY_HND hnd_src, hnd_dst;
1537 PRINTER_INFO_CTR ctr_src, ctr_enum;
1538 struct cli_state *cli_dst = NULL;
1539 union spoolss_PrinterInfo info_src, info_dst;
1541 ZERO_STRUCT(ctr_src);
1543 DEBUG(3,("copying printer ACLs\n"));
1545 /* connect destination PI_SPOOLSS */
1546 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
1548 if (!NT_STATUS_IS_OK(nt_status))
1552 /* enum source printers */
1553 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) {
1554 nt_status = NT_STATUS_UNSUCCESSFUL;
1558 if (!num_printers) {
1559 printf ("no printers found on server.\n");
1560 nt_status = NT_STATUS_OK;
1564 /* do something for all printers */
1565 for (i = 0; i < num_printers; i++) {
1566 /* do some initialization */
1567 rpcstr_pull_talloc(mem_ctx,
1569 ctr_enum.printers_2[i].printername.buffer,
1572 rpcstr_pull_talloc(mem_ctx,
1574 ctr_enum.printers_2[i].sharename.buffer,
1577 if (!printername || !sharename) {
1578 nt_status = NT_STATUS_UNSUCCESSFUL;
1582 /* we can reset NT_STATUS here because we do not
1583 get any real NT_STATUS-codes anymore from now on */
1584 nt_status = NT_STATUS_UNSUCCESSFUL;
1586 d_printf("migrating printer ACLs for: [%s] / [%s]\n",
1587 printername, sharename);
1589 /* according to msdn you have specify these access-rights
1590 to see the security descriptor
1591 - READ_CONTROL (DACL)
1592 - ACCESS_SYSTEM_SECURITY (SACL)
1595 /* open src printer handle */
1596 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1597 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
1600 /* open dst printer handle */
1601 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
1602 PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst))
1605 /* check for existing dst printer */
1606 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst))
1609 /* check for existing src printer */
1610 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, 3, &info_src))
1613 /* Copy Security Descriptor */
1615 /* copy secdesc (info level 2) */
1616 info_dst.info2.devmode = NULL;
1617 info_dst.info2.secdesc = dup_sec_desc(mem_ctx, info_src.info3.secdesc);
1620 display_sec_desc(info_dst.info2.secdesc);
1622 if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst))
1625 DEBUGADD(1,("\tSetPrinter of SECDESC succeeded\n"));
1628 /* close printer handles here */
1629 if (is_valid_policy_hnd(&hnd_src)) {
1630 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1633 if (is_valid_policy_hnd(&hnd_dst)) {
1634 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1639 nt_status = NT_STATUS_OK;
1643 if (is_valid_policy_hnd(&hnd_src)) {
1644 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1647 if (is_valid_policy_hnd(&hnd_dst)) {
1648 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1652 cli_shutdown(cli_dst);
1658 * Migrate printer-forms from a src server to the dst server
1660 * All parameters are provided by the run_rpc_command function, except for
1661 * argc, argv which are passed through.
1663 * @param c A net_context structure
1664 * @param domain_sid The domain sid aquired from the remote server
1665 * @param cli A cli_state connected to the server.
1666 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1667 * @param argc Standard main() style argc
1668 * @param argv Standard main() style argv. Initial components are already
1671 * @return Normal NTSTATUS return.
1674 NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c,
1675 const DOM_SID *domain_sid,
1676 const char *domain_name,
1677 struct cli_state *cli,
1678 struct rpc_pipe_client *pipe_hnd,
1679 TALLOC_CTX *mem_ctx,
1683 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1686 uint32 num_printers;
1688 char *printername, *sharename;
1689 struct rpc_pipe_client *pipe_hnd_dst = NULL;
1690 POLICY_HND hnd_src, hnd_dst;
1691 PRINTER_INFO_CTR ctr_enum;
1692 union spoolss_PrinterInfo info_dst;
1694 union spoolss_FormInfo *forms;
1695 struct cli_state *cli_dst = NULL;
1697 ZERO_STRUCT(ctr_enum);
1699 DEBUG(3,("copying forms\n"));
1701 /* connect destination PI_SPOOLSS */
1702 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
1704 if (!NT_STATUS_IS_OK(nt_status))
1707 /* enum src printers */
1708 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr_enum)) {
1709 nt_status = NT_STATUS_UNSUCCESSFUL;
1713 if (!num_printers) {
1714 printf ("no printers found on server.\n");
1715 nt_status = NT_STATUS_OK;
1719 /* do something for all printers */
1720 for (i = 0; i < num_printers; i++) {
1721 /* do some initialization */
1722 rpcstr_pull_talloc(mem_ctx,
1724 ctr_enum.printers_2[i].printername.buffer,
1727 rpcstr_pull_talloc(mem_ctx,
1729 ctr_enum.printers_2[i].sharename.buffer,
1732 if (!printername || !sharename) {
1733 nt_status = NT_STATUS_UNSUCCESSFUL;
1736 /* we can reset NT_STATUS here because we do not
1737 get any real NT_STATUS-codes anymore from now on */
1738 nt_status = NT_STATUS_UNSUCCESSFUL;
1740 d_printf("migrating printer forms for: [%s] / [%s]\n",
1741 printername, sharename);
1744 /* open src printer handle */
1745 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1746 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
1749 /* open dst printer handle */
1750 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
1751 PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst))
1754 /* check for existing dst printer */
1755 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst))
1758 /* finally migrate forms */
1759 if (!net_spoolss_enumforms(pipe_hnd, mem_ctx, &hnd_src, level, &num_forms, &forms))
1762 DEBUG(1,("got %d forms for printer\n", num_forms));
1765 for (f = 0; f < num_forms; f++) {
1767 union spoolss_AddFormInfo info;
1770 /* only migrate FORM_PRINTER types, according to jerry
1771 FORM_BUILTIN-types are hard-coded in samba */
1772 if (forms[f].info1.flags != SPOOLSS_FORM_PRINTER)
1776 d_printf("\tmigrating form # %d [%s] of type [%d]\n",
1777 f, forms[f].info1.form_name,
1778 forms[f].info1.flags);
1780 info.info1 = (struct spoolss_AddFormInfo1 *)&forms[f].info1;
1782 /* FIXME: there might be something wrong with samba's
1784 status = rpccli_spoolss_AddForm(pipe_hnd_dst, mem_ctx,
1789 if (!W_ERROR_IS_OK(result)) {
1790 d_printf("\tAddForm form %d: [%s] refused.\n",
1791 f, forms[f].info1.form_name);
1795 DEBUGADD(1,("\tAddForm of [%s] succeeded\n",
1796 forms[f].info1.form_name));
1800 /* close printer handles here */
1801 if (is_valid_policy_hnd(&hnd_src)) {
1802 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1805 if (is_valid_policy_hnd(&hnd_dst)) {
1806 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1810 nt_status = NT_STATUS_OK;
1814 if (is_valid_policy_hnd(&hnd_src))
1815 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1817 if (is_valid_policy_hnd(&hnd_dst))
1818 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1821 cli_shutdown(cli_dst);
1827 * Migrate printer-drivers from a src server to the dst server
1829 * All parameters are provided by the run_rpc_command function, except for
1830 * argc, argv which are passed through.
1832 * @param c A net_context structure
1833 * @param domain_sid The domain sid aquired from the remote server
1834 * @param cli A cli_state connected to the server.
1835 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1836 * @param argc Standard main() style argc
1837 * @param argv Standard main() style argv. Initial components are already
1840 * @return Normal NTSTATUS return.
1843 NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c,
1844 const DOM_SID *domain_sid,
1845 const char *domain_name,
1846 struct cli_state *cli,
1847 struct rpc_pipe_client *pipe_hnd,
1848 TALLOC_CTX *mem_ctx,
1852 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1854 uint32 num_printers;
1856 char *printername, *sharename;
1857 bool got_src_driver_share = false;
1858 bool got_dst_driver_share = false;
1859 struct rpc_pipe_client *pipe_hnd_dst = NULL;
1860 POLICY_HND hnd_src, hnd_dst;
1861 union spoolss_DriverInfo drv_info_src;
1862 PRINTER_INFO_CTR info_ctr_enum, info_ctr_dst;
1863 union spoolss_PrinterInfo info_dst;
1864 struct cli_state *cli_dst = NULL;
1865 struct cli_state *cli_share_src = NULL;
1866 struct cli_state *cli_share_dst = NULL;
1867 const char *drivername = NULL;
1869 ZERO_STRUCT(info_ctr_enum);
1870 ZERO_STRUCT(info_ctr_dst);
1872 DEBUG(3,("copying printer-drivers\n"));
1874 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
1876 if (!NT_STATUS_IS_OK(nt_status))
1879 /* open print$-share on the src server */
1880 nt_status = connect_to_service(c, &cli_share_src, &cli->dest_ss,
1881 cli->desthost, "print$", "A:");
1882 if (!NT_STATUS_IS_OK(nt_status))
1885 got_src_driver_share = true;
1888 /* open print$-share on the dst server */
1889 nt_status = connect_to_service(c, &cli_share_dst, &cli_dst->dest_ss,
1890 cli_dst->desthost, "print$", "A:");
1891 if (!NT_STATUS_IS_OK(nt_status))
1894 got_dst_driver_share = true;
1897 /* enum src printers */
1898 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_ctr_enum)) {
1899 nt_status = NT_STATUS_UNSUCCESSFUL;
1903 if (num_printers == 0) {
1904 printf ("no printers found on server.\n");
1905 nt_status = NT_STATUS_OK;
1910 /* do something for all printers */
1911 for (p = 0; p < num_printers; p++) {
1912 /* do some initialization */
1913 rpcstr_pull_talloc(mem_ctx,
1915 info_ctr_enum.printers_2[p].printername.buffer,
1918 rpcstr_pull_talloc(mem_ctx,
1920 info_ctr_enum.printers_2[p].sharename.buffer,
1923 if (!printername || !sharename) {
1924 nt_status = NT_STATUS_UNSUCCESSFUL;
1928 /* we can reset NT_STATUS here because we do not
1929 get any real NT_STATUS-codes anymore from now on */
1930 nt_status = NT_STATUS_UNSUCCESSFUL;
1932 d_printf("migrating printer driver for: [%s] / [%s]\n",
1933 printername, sharename);
1935 /* open dst printer handle */
1936 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
1937 PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst))
1940 /* check for existing dst printer */
1941 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst))
1945 /* open src printer handle */
1946 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1947 MAXIMUM_ALLOWED_ACCESS,
1948 pipe_hnd->auth->user_name,
1952 /* in a first step call getdriver for each shared printer (per arch)
1953 to get a list of all files that have to be copied */
1955 for (i=0; archi_table[i].long_archi!=NULL; i++) {
1958 if (!net_spoolss_getprinterdriver(pipe_hnd, mem_ctx, &hnd_src,
1959 level, archi_table[i].long_archi,
1960 archi_table[i].version, &drv_info_src))
1963 drivername = drv_info_src.info3.driver_name;
1966 display_print_driver3(&drv_info_src.info3);
1968 /* check arch dir */
1969 nt_status = check_arch_dir(cli_share_dst, archi_table[i].short_archi);
1970 if (!NT_STATUS_IS_OK(nt_status))
1974 /* copy driver-files */
1975 nt_status = copy_print_driver_3(c, mem_ctx, cli_share_src, cli_share_dst,
1976 archi_table[i].short_archi,
1977 &drv_info_src.info3);
1978 if (!NT_STATUS_IS_OK(nt_status))
1983 if (!net_spoolss_addprinterdriver(pipe_hnd_dst, mem_ctx, level, &drv_info_src)) {
1984 nt_status = NT_STATUS_UNSUCCESSFUL;
1988 DEBUGADD(1,("Sucessfully added driver [%s] for printer [%s]\n",
1989 drivername, printername));
1993 if (strlen(drivername) == 0) {
1994 DEBUGADD(1,("Did not get driver for printer %s\n",
2000 info_dst.info2.drivername = drivername;
2002 if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst)) {
2003 nt_status = NT_STATUS_UNSUCCESSFUL;
2007 DEBUGADD(1,("Sucessfully set driver %s for printer %s\n",
2008 drivername, printername));
2011 if (is_valid_policy_hnd(&hnd_dst)) {
2012 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2016 if (is_valid_policy_hnd(&hnd_src)) {
2017 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2021 nt_status = NT_STATUS_OK;
2025 if (is_valid_policy_hnd(&hnd_src))
2026 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2028 if (is_valid_policy_hnd(&hnd_dst))
2029 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2032 cli_shutdown(cli_dst);
2035 if (got_src_driver_share)
2036 cli_shutdown(cli_share_src);
2038 if (got_dst_driver_share)
2039 cli_shutdown(cli_share_dst);
2046 * Migrate printer-queues from a src to the dst server
2047 * (requires a working "addprinter command" to be installed for the local smbd)
2049 * All parameters are provided by the run_rpc_command function, except for
2050 * argc, argv which are passed through.
2052 * @param c A net_context structure
2053 * @param domain_sid The domain sid aquired from the remote server
2054 * @param cli A cli_state connected to the server.
2055 * @param mem_ctx Talloc context, destoyed on compleation of the function.
2056 * @param argc Standard main() style argc
2057 * @param argv Standard main() style argv. Initial components are already
2060 * @return Normal NTSTATUS return.
2063 NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c,
2064 const DOM_SID *domain_sid,
2065 const char *domain_name,
2066 struct cli_state *cli,
2067 struct rpc_pipe_client *pipe_hnd,
2068 TALLOC_CTX *mem_ctx,
2073 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
2074 uint32 i = 0, num_printers;
2076 PRINTER_INFO_CTR ctr_enum;
2077 union spoolss_PrinterInfo info_dst, info_src;
2078 struct cli_state *cli_dst = NULL;
2079 POLICY_HND hnd_dst, hnd_src;
2080 char *printername, *sharename;
2081 struct rpc_pipe_client *pipe_hnd_dst = NULL;
2082 struct spoolss_SetPrinterInfoCtr info_ctr;
2084 DEBUG(3,("copying printers\n"));
2086 /* connect destination PI_SPOOLSS */
2087 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
2089 if (!NT_STATUS_IS_OK(nt_status))
2093 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) {
2094 nt_status = NT_STATUS_UNSUCCESSFUL;
2098 if (!num_printers) {
2099 printf ("no printers found on server.\n");
2100 nt_status = NT_STATUS_OK;
2104 /* do something for all printers */
2105 for (i = 0; i < num_printers; i++) {
2106 /* do some initialization */
2107 rpcstr_pull_talloc(mem_ctx,
2109 ctr_enum.printers_2[i].printername.buffer,
2112 rpcstr_pull_talloc(mem_ctx,
2114 ctr_enum.printers_2[i].sharename.buffer,
2117 if (!printername || !sharename) {
2118 nt_status = NT_STATUS_UNSUCCESSFUL;
2121 /* we can reset NT_STATUS here because we do not
2122 get any real NT_STATUS-codes anymore from now on */
2123 nt_status = NT_STATUS_UNSUCCESSFUL;
2125 d_printf("migrating printer queue for: [%s] / [%s]\n",
2126 printername, sharename);
2128 /* open dst printer handle */
2129 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
2130 PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) {
2132 DEBUG(1,("could not open printer: %s\n", sharename));
2135 /* check for existing dst printer */
2136 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst)) {
2137 printf ("could not get printer, creating printer.\n");
2139 DEBUG(1,("printer already exists: %s\n", sharename));
2140 /* close printer handle here - dst only, not got src yet. */
2141 if (is_valid_policy_hnd(&hnd_dst)) {
2142 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2147 /* now get again src printer ctr via getprinter,
2148 we first need a handle for that */
2150 /* open src printer handle */
2151 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
2152 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
2155 /* getprinter on the src server */
2156 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, level, &info_src))
2159 /* copy each src printer to a dst printer 1:1,
2160 maybe some values have to be changed though */
2161 d_printf("creating printer: %s\n", printername);
2163 info_ctr.level = level;
2164 info_ctr.info.info2 = (struct spoolss_SetPrinterInfo2 *)&info_src.info2;
2166 result = rpccli_spoolss_addprinterex(pipe_hnd_dst,
2170 if (W_ERROR_IS_OK(result))
2171 d_printf ("printer [%s] successfully added.\n", printername);
2172 else if (W_ERROR_V(result) == W_ERROR_V(WERR_PRINTER_ALREADY_EXISTS))
2173 d_fprintf (stderr, "printer [%s] already exists.\n", printername);
2175 d_fprintf (stderr, "could not create printer [%s]\n", printername);
2179 /* close printer handles here */
2180 if (is_valid_policy_hnd(&hnd_src)) {
2181 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2184 if (is_valid_policy_hnd(&hnd_dst)) {
2185 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2189 nt_status = NT_STATUS_OK;
2192 if (is_valid_policy_hnd(&hnd_src))
2193 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2195 if (is_valid_policy_hnd(&hnd_dst))
2196 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2199 cli_shutdown(cli_dst);
2205 * Migrate Printer-Settings from a src server to the dst server
2206 * (for this to work, printers and drivers already have to be migrated earlier)
2208 * All parameters are provided by the run_rpc_command function, except for
2209 * argc, argv which are passed through.
2211 * @param c A net_context structure
2212 * @param domain_sid The domain sid aquired from the remote server
2213 * @param cli A cli_state connected to the server.
2214 * @param mem_ctx Talloc context, destoyed on compleation of the function.
2215 * @param argc Standard main() style argc
2216 * @param argv Standard main() style argv. Initial components are already
2219 * @return Normal NTSTATUS return.
2222 NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
2223 const DOM_SID *domain_sid,
2224 const char *domain_name,
2225 struct cli_state *cli,
2226 struct rpc_pipe_client *pipe_hnd,
2227 TALLOC_CTX *mem_ctx,
2232 /* FIXME: Here the nightmare begins */
2235 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
2236 uint32 i = 0, p = 0, j = 0;
2237 uint32 num_printers, val_needed, data_needed;
2239 char *printername, *sharename;
2240 struct rpc_pipe_client *pipe_hnd_dst = NULL;
2241 POLICY_HND hnd_src, hnd_dst;
2242 PRINTER_INFO_CTR ctr_enum;
2243 union spoolss_PrinterInfo info_dst_publish, info_dst;
2244 REGVAL_CTR *reg_ctr;
2245 struct cli_state *cli_dst = NULL;
2246 char *devicename = NULL, *unc_name = NULL, *url = NULL;
2247 const char *longname;
2249 uint16 *keylist = NULL, *curkey;
2251 ZERO_STRUCT(ctr_enum);
2253 ZERO_STRUCT(info_dst_publish);
2255 DEBUG(3,("copying printer settings\n"));
2257 /* connect destination PI_SPOOLSS */
2258 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
2260 if (!NT_STATUS_IS_OK(nt_status))
2263 /* enum src printers */
2264 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) {
2265 nt_status = NT_STATUS_UNSUCCESSFUL;
2269 if (!num_printers) {
2270 printf ("no printers found on server.\n");
2271 nt_status = NT_STATUS_OK;
2276 /* needed for dns-strings in regkeys */
2277 longname = get_mydnsfullname();
2279 nt_status = NT_STATUS_UNSUCCESSFUL;
2283 /* do something for all printers */
2284 for (i = 0; i < num_printers; i++) {
2285 /* do some initialization */
2286 rpcstr_pull_talloc(mem_ctx,
2288 ctr_enum.printers_2[i].printername.buffer,
2291 rpcstr_pull_talloc(mem_ctx,
2293 ctr_enum.printers_2[i].sharename.buffer,
2296 if (!printername || !sharename) {
2297 nt_status = NT_STATUS_UNSUCCESSFUL;
2300 /* we can reset NT_STATUS here because we do not
2301 get any real NT_STATUS-codes anymore from now on */
2302 nt_status = NT_STATUS_UNSUCCESSFUL;
2304 d_printf("migrating printer settings for: [%s] / [%s]\n",
2305 printername, sharename);
2308 /* open src printer handle */
2309 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
2310 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
2313 /* open dst printer handle */
2314 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
2315 PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst))
2318 /* check for existing dst printer */
2319 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst,
2323 #if 0 /* FIXME GD */
2325 /* STEP 1: COPY DEVICE-MODE and other
2326 PRINTER_INFO_2-attributes
2329 info_dst.info2 = &ctr_enum.printers_2[i];
2331 /* why is the port always disconnected when the printer
2332 is correctly installed (incl. driver ???) */
2333 info_dst.info2.portname = SAMBA_PRINTER_PORT_NAME;
2335 /* check if printer is published */
2336 if (ctr_enum.printers_2[i].attributes & PRINTER_ATTRIBUTE_PUBLISHED) {
2338 /* check for existing dst printer */
2339 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 7, &info_dst_publish))
2342 info_dst_publish.info7.action = DSPRINT_PUBLISH;
2344 /* ignore false from setprinter due to WERR_IO_PENDING */
2345 net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 7, &info_dst_publish);
2347 DEBUG(3,("republished printer\n"));
2350 if (ctr_enum.printers_2[i].devmode != NULL) {
2352 /* copy devmode (info level 2) */
2353 info_dst.info2.devmode = (DEVICEMODE *)
2354 TALLOC_MEMDUP(mem_ctx,
2355 ctr_enum.printers_2[i].devmode,
2356 sizeof(DEVICEMODE));
2358 /* do not copy security descriptor (we have another
2359 * command for that) */
2360 info_dst.info2.secdesc = NULL;
2363 if (asprintf(&devicename, "\\\\%s\\%s", longname,
2365 nt_status = NT_STATUS_NO_MEMORY;
2369 init_unistr(&ctr_dst.printers_2->devmode->devicename,
2372 if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst,
2376 DEBUGADD(1,("\tSetPrinter of DEVICEMODE succeeded\n"));
2379 /* STEP 2: COPY REGISTRY VALUES */
2381 /* please keep in mind that samba parse_spools gives horribly
2382 crippled results when used to rpccli_spoolss_enumprinterdataex
2383 a win2k3-server. (Bugzilla #1851)
2384 FIXME: IIRC I've seen it too on a win2k-server
2387 /* enumerate data on src handle */
2388 result = rpccli_spoolss_enumprinterdata(pipe_hnd, mem_ctx, &hnd_src, p, 0, 0,
2389 &val_needed, &data_needed, NULL);
2391 /* loop for all printerdata of "PrinterDriverData" */
2392 while (W_ERROR_IS_OK(result)) {
2394 REGISTRY_VALUE value;
2396 result = rpccli_spoolss_enumprinterdata(
2397 pipe_hnd, mem_ctx, &hnd_src, p++, val_needed,
2398 data_needed, 0, 0, &value);
2400 /* loop for all reg_keys */
2401 if (W_ERROR_IS_OK(result)) {
2405 display_reg_value(SPOOL_PRINTERDATA_KEY, value);
2408 if (!net_spoolss_setprinterdata(pipe_hnd_dst, mem_ctx,
2412 DEBUGADD(1,("\tSetPrinterData of [%s] succeeded\n",
2417 /* STEP 3: COPY SUBKEY VALUES */
2419 /* here we need to enum all printer_keys and then work
2420 on the result with enum_printer_key_ex. nt4 does not
2421 respond to enumprinterkey, win2k does, so continue
2422 in case of an error */
2424 if (!net_spoolss_enumprinterkey(pipe_hnd, mem_ctx, &hnd_src, "", &keylist)) {
2425 printf("got no key-data\n");
2430 /* work on a list of printer keys
2431 each key has to be enumerated to get all required
2432 information. information is then set via setprinterdataex-calls */
2434 if (keylist == NULL)
2438 while (*curkey != 0) {
2440 rpcstr_pull_talloc(mem_ctx,
2446 return NT_STATUS_NO_MEMORY;
2449 curkey += strlen(subkey) + 1;
2451 if ( !(reg_ctr = TALLOC_ZERO_P( mem_ctx, REGVAL_CTR )) )
2452 return NT_STATUS_NO_MEMORY;
2454 /* enumerate all src subkeys */
2455 if (!net_spoolss_enumprinterdataex(pipe_hnd, mem_ctx, 0,
2460 for (j=0; j < reg_ctr->num_values; j++) {
2462 REGISTRY_VALUE value;
2465 /* although samba replies with sane data in most cases we
2466 should try to avoid writing wrong registry data */
2468 if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_PORTNAME) ||
2469 strequal(reg_ctr->values[j]->valuename, SPOOL_REG_UNCNAME) ||
2470 strequal(reg_ctr->values[j]->valuename, SPOOL_REG_URL) ||
2471 strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SHORTSERVERNAME) ||
2472 strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SERVERNAME)) {
2474 if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_PORTNAME)) {
2476 /* although windows uses a multi-sz, we use a sz */
2477 init_unistr2(&data, SAMBA_PRINTER_PORT_NAME, UNI_STR_TERMINATE);
2478 fstrcpy(value.valuename, SPOOL_REG_PORTNAME);
2481 if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_UNCNAME)) {
2483 if (asprintf(&unc_name, "\\\\%s\\%s", longname, sharename) < 0) {
2484 nt_status = NT_STATUS_NO_MEMORY;
2487 init_unistr2(&data, unc_name, UNI_STR_TERMINATE);
2488 fstrcpy(value.valuename, SPOOL_REG_UNCNAME);
2491 if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_URL)) {
2496 /* FIXME: should we really do that ??? */
2497 if (asprintf(&url, "http://%s:631/printers/%s", longname, sharename) < 0) {
2498 nt_status = NT_STATUS_NO_MEMORY;
2501 init_unistr2(&data, url, UNI_STR_TERMINATE);
2502 fstrcpy(value.valuename, SPOOL_REG_URL);
2506 if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SERVERNAME)) {
2508 init_unistr2(&data, longname, UNI_STR_TERMINATE);
2509 fstrcpy(value.valuename, SPOOL_REG_SERVERNAME);
2512 if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SHORTSERVERNAME)) {
2514 init_unistr2(&data, global_myname(), UNI_STR_TERMINATE);
2515 fstrcpy(value.valuename, SPOOL_REG_SHORTSERVERNAME);
2518 value.type = REG_SZ;
2519 value.size = data.uni_str_len * 2;
2521 value.data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, data.buffer, value.size);
2523 value.data_p = NULL;
2527 display_reg_value(subkey, value);
2529 /* here we have to set all subkeys on the dst server */
2530 if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst,
2537 display_reg_value(subkey, *(reg_ctr->values[j]));
2539 /* here we have to set all subkeys on the dst server */
2540 if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst,
2541 subkey, reg_ctr->values[j]))
2546 DEBUGADD(1,("\tSetPrinterDataEx of key [%s\\%s] succeeded\n",
2547 subkey, reg_ctr->values[j]->valuename));
2551 TALLOC_FREE( reg_ctr );
2556 /* close printer handles here */
2557 if (is_valid_policy_hnd(&hnd_src)) {
2558 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2561 if (is_valid_policy_hnd(&hnd_dst)) {
2562 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2567 nt_status = NT_STATUS_OK;
2570 SAFE_FREE(devicename);
2572 SAFE_FREE(unc_name);
2574 if (is_valid_policy_hnd(&hnd_src))
2575 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2577 if (is_valid_policy_hnd(&hnd_dst))
2578 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2581 cli_shutdown(cli_dst);