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 PRINTER_DRIVER_CTR *ctr)
986 /* enumprinterdrivers call */
987 result = rpccli_spoolss_enumprinterdrivers(
988 pipe_hnd, mem_ctx, level,
989 env, num_drivers, ctr);
991 if (!W_ERROR_IS_OK(result)) {
992 printf("cannot enum drivers: %s\n", win_errstr(result));
999 static bool net_spoolss_getprinterdriver(struct rpc_pipe_client *pipe_hnd,
1000 TALLOC_CTX *mem_ctx,
1001 POLICY_HND *hnd, uint32 level,
1002 const char *env, int version,
1003 union spoolss_DriverInfo *info)
1006 uint32_t server_major_version;
1007 uint32_t server_minor_version;
1009 /* getprinterdriver call */
1010 result = rpccli_spoolss_getprinterdriver2(pipe_hnd, mem_ctx,
1018 &server_major_version,
1019 &server_minor_version);
1020 if (!W_ERROR_IS_OK(result)) {
1021 DEBUG(1,("cannot get driver (for architecture: %s): %s\n",
1022 env, win_errstr(result)));
1023 if (W_ERROR_V(result) != W_ERROR_V(WERR_UNKNOWN_PRINTER_DRIVER) &&
1024 W_ERROR_V(result) != W_ERROR_V(WERR_INVALID_ENVIRONMENT)) {
1025 printf("cannot get driver: %s\n", win_errstr(result));
1034 static bool net_spoolss_addprinterdriver(struct rpc_pipe_client *pipe_hnd,
1035 TALLOC_CTX *mem_ctx, uint32 level,
1036 union spoolss_DriverInfo *info)
1040 struct spoolss_AddDriverInfoCtr info_ctr;
1042 info_ctr.level = level;
1046 info_ctr.info.info2 = (struct spoolss_AddDriverInfo2 *)&info->info2;
1049 info_ctr.info.info3 = (struct spoolss_AddDriverInfo3 *)&info->info3;
1052 printf("unsupported info level: %d\n", level);
1056 /* addprinterdriver call */
1057 status = rpccli_spoolss_AddPrinterDriver(pipe_hnd, mem_ctx,
1058 pipe_hnd->srv_name_slash,
1061 /* be more verbose */
1062 if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) {
1063 printf("You are not allowed to add drivers\n");
1066 if (!W_ERROR_IS_OK(result)) {
1067 printf("cannot add driver: %s\n", win_errstr(result));
1075 * abstraction function to get uint32 num_printers and PRINTER_INFO_CTR ctr
1076 * for a single printer or for all printers depending on argc/argv
1079 static bool get_printer_info(struct rpc_pipe_client *pipe_hnd,
1080 TALLOC_CTX *mem_ctx,
1084 uint32 *num_printers,
1085 PRINTER_INFO_CTR *ctr)
1089 union spoolss_PrinterInfo info;
1091 /* no arguments given, enumerate all printers */
1094 if (!net_spoolss_enum_printers(pipe_hnd, mem_ctx, NULL,
1095 PRINTER_ENUM_LOCAL|PRINTER_ENUM_SHARED,
1096 level, num_printers, ctr))
1105 /* argument given, get a single printer by name */
1106 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, argv[0],
1107 MAXIMUM_ALLOWED_ACCESS,
1108 pipe_hnd->auth->user_name,
1112 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info)) {
1113 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1117 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1122 DEBUG(3,("got %d printers\n", *num_printers));
1129 * List print-queues (including local printers that are not shared)
1131 * All parameters are provided by the run_rpc_command function, except for
1132 * argc, argv which are passed through.
1134 * @param c A net_context structure
1135 * @param domain_sid The domain sid aquired from the remote server
1136 * @param cli A cli_state connected to the server.
1137 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1138 * @param argc Standard main() style argc
1139 * @param argv Standard main() style argv. Initial components are already
1142 * @return Normal NTSTATUS return.
1145 NTSTATUS rpc_printer_list_internals(struct net_context *c,
1146 const DOM_SID *domain_sid,
1147 const char *domain_name,
1148 struct cli_state *cli,
1149 struct rpc_pipe_client *pipe_hnd,
1150 TALLOC_CTX *mem_ctx,
1154 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1155 uint32 i, num_printers;
1157 char *printername, *sharename;
1158 PRINTER_INFO_CTR ctr;
1160 printf("listing printers\n");
1162 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr))
1165 for (i = 0; i < num_printers; i++) {
1166 /* do some initialization */
1167 rpcstr_pull_talloc(mem_ctx,
1169 ctr.printers_2[i].printername.buffer,
1172 rpcstr_pull_talloc(mem_ctx,
1174 ctr.printers_2[i].sharename.buffer,
1178 if (printername && sharename) {
1179 d_printf("printer %d: %s, shared as: %s\n",
1180 i+1, printername, sharename);
1184 return NT_STATUS_OK;
1188 * List printer-drivers from a server
1190 * All parameters are provided by the run_rpc_command function, except for
1191 * argc, argv which are passed through.
1193 * @param c A net_context structure
1194 * @param domain_sid The domain sid aquired from the remote server
1195 * @param cli A cli_state connected to the server.
1196 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1197 * @param argc Standard main() style argc
1198 * @param argv Standard main() style argv. Initial components are already
1201 * @return Normal NTSTATUS return.
1204 NTSTATUS rpc_printer_driver_list_internals(struct net_context *c,
1205 const DOM_SID *domain_sid,
1206 const char *domain_name,
1207 struct cli_state *cli,
1208 struct rpc_pipe_client *pipe_hnd,
1209 TALLOC_CTX *mem_ctx,
1213 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1216 PRINTER_DRIVER_CTR drv_ctr_enum;
1219 ZERO_STRUCT(drv_ctr_enum);
1221 printf("listing printer-drivers\n");
1223 for (i=0; archi_table[i].long_archi!=NULL; i++) {
1227 /* enum remote drivers */
1228 if (!net_spoolss_enumprinterdrivers(pipe_hnd, mem_ctx, level,
1229 archi_table[i].long_archi,
1230 &num_drivers, &drv_ctr_enum)) {
1231 nt_status = NT_STATUS_UNSUCCESSFUL;
1235 if (num_drivers == 0) {
1236 d_printf ("no drivers found on server for architecture: [%s].\n",
1237 archi_table[i].long_archi);
1241 d_printf("got %d printer-drivers for architecture: [%s]\n",
1242 num_drivers, archi_table[i].long_archi);
1245 /* do something for all drivers for architecture */
1246 for (d = 0; d < num_drivers; d++) {
1247 display_print_driver_3(&(drv_ctr_enum.info3[d]));
1251 nt_status = NT_STATUS_OK;
1259 * Publish print-queues with args-wrapper
1261 * @param cli A cli_state connected to the server.
1262 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1263 * @param argc Standard main() style argc
1264 * @param argv Standard main() style argv. Initial components are already
1268 * @return Normal NTSTATUS return.
1271 static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_hnd,
1272 TALLOC_CTX *mem_ctx,
1277 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1278 uint32 i, num_printers;
1280 char *printername, *sharename;
1281 PRINTER_INFO_CTR ctr;
1282 union spoolss_PrinterInfo info;
1283 struct spoolss_SetPrinterInfoCtr info_ctr;
1284 struct spoolss_DevmodeContainer devmode_ctr;
1285 struct sec_desc_buf secdesc_ctr;
1288 const char *action_str;
1290 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr))
1293 for (i = 0; i < num_printers; i++) {
1294 /* do some initialization */
1295 rpcstr_pull_talloc(mem_ctx,
1297 ctr.printers_2[i].printername.buffer,
1300 rpcstr_pull_talloc(mem_ctx,
1302 ctr.printers_2[i].sharename.buffer,
1305 if (!printername || !sharename) {
1309 /* open printer handle */
1310 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1311 PRINTER_ALL_ACCESS, pipe_hnd->auth->user_name, &hnd))
1314 /* check for existing dst printer */
1315 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info))
1318 /* check action and set string */
1320 case DSPRINT_PUBLISH:
1321 action_str = "published";
1323 case DSPRINT_UPDATE:
1324 action_str = "updated";
1326 case DSPRINT_UNPUBLISH:
1327 action_str = "unpublished";
1330 action_str = "unknown action";
1331 printf("unkown action: %d\n", action);
1335 info.info7.action = action;
1337 info_ctr.info.info7 = (struct spoolss_SetPrinterInfo7 *)&info.info7;
1339 ZERO_STRUCT(devmode_ctr);
1340 ZERO_STRUCT(secdesc_ctr);
1342 nt_status = rpccli_spoolss_SetPrinter(pipe_hnd, mem_ctx,
1350 if (!W_ERROR_IS_OK(result) && (W_ERROR_V(result) != W_ERROR_V(WERR_IO_PENDING))) {
1351 printf("cannot set printer-info: %s\n", win_errstr(result));
1355 printf("successfully %s printer %s in Active Directory\n", action_str, sharename);
1358 nt_status = NT_STATUS_OK;
1361 if (is_valid_policy_hnd(&hnd))
1362 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1367 NTSTATUS rpc_printer_publish_publish_internals(struct net_context *c,
1368 const 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_PUBLISH);
1379 NTSTATUS rpc_printer_publish_unpublish_internals(struct net_context *c,
1380 const 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_UNPUBLISH);
1391 NTSTATUS rpc_printer_publish_update_internals(struct net_context *c,
1392 const DOM_SID *domain_sid,
1393 const char *domain_name,
1394 struct cli_state *cli,
1395 struct rpc_pipe_client *pipe_hnd,
1396 TALLOC_CTX *mem_ctx,
1400 return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, DSPRINT_UPDATE);
1404 * List print-queues w.r.t. their publishing state
1406 * All parameters are provided by the run_rpc_command function, except for
1407 * argc, argv which are passed through.
1409 * @param c A net_context structure
1410 * @param domain_sid The domain sid aquired from the remote server
1411 * @param cli A cli_state connected to the server.
1412 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1413 * @param argc Standard main() style argc
1414 * @param argv Standard main() style argv. Initial components are already
1417 * @return Normal NTSTATUS return.
1420 NTSTATUS rpc_printer_publish_list_internals(struct net_context *c,
1421 const DOM_SID *domain_sid,
1422 const char *domain_name,
1423 struct cli_state *cli,
1424 struct rpc_pipe_client *pipe_hnd,
1425 TALLOC_CTX *mem_ctx,
1429 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1430 uint32 i, num_printers;
1432 char *printername, *sharename;
1433 PRINTER_INFO_CTR ctr, ctr_pub;
1434 union spoolss_PrinterInfo info;
1438 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr))
1441 for (i = 0; i < num_printers; i++) {
1442 ZERO_STRUCT(ctr_pub);
1444 /* do some initialization */
1445 rpcstr_pull_talloc(mem_ctx,
1447 ctr.printers_2[i].printername.buffer,
1450 rpcstr_pull_talloc(mem_ctx,
1452 ctr.printers_2[i].sharename.buffer,
1455 if (!printername || !sharename) {
1459 /* open printer handle */
1460 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1461 PRINTER_ALL_ACCESS, cli->user_name, &hnd))
1464 /* check for existing dst printer */
1465 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info))
1468 if (!info.info7.guid) {
1471 state = info.info7.action;
1473 case DSPRINT_PUBLISH:
1474 printf("printer [%s] is published", sharename);
1476 printf(", guid: %s", info.info7.guid);
1479 case DSPRINT_UNPUBLISH:
1480 printf("printer [%s] is unpublished\n", sharename);
1482 case DSPRINT_UPDATE:
1483 printf("printer [%s] is currently updating\n", sharename);
1486 printf("unkown state: %d\n", state);
1491 nt_status = NT_STATUS_OK;
1494 if (is_valid_policy_hnd(&hnd))
1495 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1501 * Migrate Printer-ACLs from a source server to the destination server
1503 * All parameters are provided by the run_rpc_command function, except for
1504 * argc, argv which are passed through.
1506 * @param c A net_context structure
1507 * @param domain_sid The domain sid aquired from the remote server
1508 * @param cli A cli_state connected to the server.
1509 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1510 * @param argc Standard main() style argc
1511 * @param argv Standard main() style argv. Initial components are already
1514 * @return Normal NTSTATUS return.
1517 NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c,
1518 const DOM_SID *domain_sid,
1519 const char *domain_name,
1520 struct cli_state *cli,
1521 struct rpc_pipe_client *pipe_hnd,
1522 TALLOC_CTX *mem_ctx,
1526 /* TODO: what now, info2 or info3 ?
1527 convince jerry that we should add clientside setacls level 3 at least
1529 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1531 uint32 num_printers;
1533 char *printername, *sharename;
1534 struct rpc_pipe_client *pipe_hnd_dst = NULL;
1535 POLICY_HND hnd_src, hnd_dst;
1536 PRINTER_INFO_CTR ctr_src, ctr_enum;
1537 struct cli_state *cli_dst = NULL;
1538 union spoolss_PrinterInfo info_src, info_dst;
1540 ZERO_STRUCT(ctr_src);
1542 DEBUG(3,("copying printer ACLs\n"));
1544 /* connect destination PI_SPOOLSS */
1545 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
1547 if (!NT_STATUS_IS_OK(nt_status))
1551 /* enum source printers */
1552 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) {
1553 nt_status = NT_STATUS_UNSUCCESSFUL;
1557 if (!num_printers) {
1558 printf ("no printers found on server.\n");
1559 nt_status = NT_STATUS_OK;
1563 /* do something for all printers */
1564 for (i = 0; i < num_printers; i++) {
1565 /* do some initialization */
1566 rpcstr_pull_talloc(mem_ctx,
1568 ctr_enum.printers_2[i].printername.buffer,
1571 rpcstr_pull_talloc(mem_ctx,
1573 ctr_enum.printers_2[i].sharename.buffer,
1576 if (!printername || !sharename) {
1577 nt_status = NT_STATUS_UNSUCCESSFUL;
1581 /* we can reset NT_STATUS here because we do not
1582 get any real NT_STATUS-codes anymore from now on */
1583 nt_status = NT_STATUS_UNSUCCESSFUL;
1585 d_printf("migrating printer ACLs for: [%s] / [%s]\n",
1586 printername, sharename);
1588 /* according to msdn you have specify these access-rights
1589 to see the security descriptor
1590 - READ_CONTROL (DACL)
1591 - ACCESS_SYSTEM_SECURITY (SACL)
1594 /* open src printer handle */
1595 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1596 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
1599 /* open dst printer handle */
1600 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
1601 PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst))
1604 /* check for existing dst printer */
1605 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst))
1608 /* check for existing src printer */
1609 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, 3, &info_src))
1612 /* Copy Security Descriptor */
1614 /* copy secdesc (info level 2) */
1615 info_dst.info2.devmode = NULL;
1616 info_dst.info2.secdesc = dup_sec_desc(mem_ctx, info_src.info3.secdesc);
1619 display_sec_desc(info_dst.info2.secdesc);
1621 if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst))
1624 DEBUGADD(1,("\tSetPrinter of SECDESC succeeded\n"));
1627 /* close printer handles here */
1628 if (is_valid_policy_hnd(&hnd_src)) {
1629 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1632 if (is_valid_policy_hnd(&hnd_dst)) {
1633 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1638 nt_status = NT_STATUS_OK;
1642 if (is_valid_policy_hnd(&hnd_src)) {
1643 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1646 if (is_valid_policy_hnd(&hnd_dst)) {
1647 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1651 cli_shutdown(cli_dst);
1657 * Migrate printer-forms from a src server to the dst server
1659 * All parameters are provided by the run_rpc_command function, except for
1660 * argc, argv which are passed through.
1662 * @param c A net_context structure
1663 * @param domain_sid The domain sid aquired from the remote server
1664 * @param cli A cli_state connected to the server.
1665 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1666 * @param argc Standard main() style argc
1667 * @param argv Standard main() style argv. Initial components are already
1670 * @return Normal NTSTATUS return.
1673 NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c,
1674 const DOM_SID *domain_sid,
1675 const char *domain_name,
1676 struct cli_state *cli,
1677 struct rpc_pipe_client *pipe_hnd,
1678 TALLOC_CTX *mem_ctx,
1682 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1685 uint32 num_printers;
1687 char *printername, *sharename;
1688 struct rpc_pipe_client *pipe_hnd_dst = NULL;
1689 POLICY_HND hnd_src, hnd_dst;
1690 PRINTER_INFO_CTR ctr_enum;
1691 union spoolss_PrinterInfo info_dst;
1693 union spoolss_FormInfo *forms;
1694 struct cli_state *cli_dst = NULL;
1696 ZERO_STRUCT(ctr_enum);
1698 DEBUG(3,("copying forms\n"));
1700 /* connect destination PI_SPOOLSS */
1701 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
1703 if (!NT_STATUS_IS_OK(nt_status))
1706 /* enum src printers */
1707 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr_enum)) {
1708 nt_status = NT_STATUS_UNSUCCESSFUL;
1712 if (!num_printers) {
1713 printf ("no printers found on server.\n");
1714 nt_status = NT_STATUS_OK;
1718 /* do something for all printers */
1719 for (i = 0; i < num_printers; i++) {
1720 /* do some initialization */
1721 rpcstr_pull_talloc(mem_ctx,
1723 ctr_enum.printers_2[i].printername.buffer,
1726 rpcstr_pull_talloc(mem_ctx,
1728 ctr_enum.printers_2[i].sharename.buffer,
1731 if (!printername || !sharename) {
1732 nt_status = NT_STATUS_UNSUCCESSFUL;
1735 /* we can reset NT_STATUS here because we do not
1736 get any real NT_STATUS-codes anymore from now on */
1737 nt_status = NT_STATUS_UNSUCCESSFUL;
1739 d_printf("migrating printer forms for: [%s] / [%s]\n",
1740 printername, sharename);
1743 /* open src printer handle */
1744 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1745 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
1748 /* open dst printer handle */
1749 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
1750 PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst))
1753 /* check for existing dst printer */
1754 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst))
1757 /* finally migrate forms */
1758 if (!net_spoolss_enumforms(pipe_hnd, mem_ctx, &hnd_src, level, &num_forms, &forms))
1761 DEBUG(1,("got %d forms for printer\n", num_forms));
1764 for (f = 0; f < num_forms; f++) {
1766 union spoolss_AddFormInfo info;
1769 /* only migrate FORM_PRINTER types, according to jerry
1770 FORM_BUILTIN-types are hard-coded in samba */
1771 if (forms[f].info1.flags != SPOOLSS_FORM_PRINTER)
1775 d_printf("\tmigrating form # %d [%s] of type [%d]\n",
1776 f, forms[f].info1.form_name,
1777 forms[f].info1.flags);
1779 info.info1 = (struct spoolss_AddFormInfo1 *)&forms[f].info1;
1781 /* FIXME: there might be something wrong with samba's
1783 status = rpccli_spoolss_AddForm(pipe_hnd_dst, mem_ctx,
1788 if (!W_ERROR_IS_OK(result)) {
1789 d_printf("\tAddForm form %d: [%s] refused.\n",
1790 f, forms[f].info1.form_name);
1794 DEBUGADD(1,("\tAddForm of [%s] succeeded\n",
1795 forms[f].info1.form_name));
1799 /* close printer handles here */
1800 if (is_valid_policy_hnd(&hnd_src)) {
1801 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1804 if (is_valid_policy_hnd(&hnd_dst)) {
1805 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1809 nt_status = NT_STATUS_OK;
1813 if (is_valid_policy_hnd(&hnd_src))
1814 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1816 if (is_valid_policy_hnd(&hnd_dst))
1817 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1820 cli_shutdown(cli_dst);
1826 * Migrate printer-drivers from a src server to the dst server
1828 * All parameters are provided by the run_rpc_command function, except for
1829 * argc, argv which are passed through.
1831 * @param c A net_context structure
1832 * @param domain_sid The domain sid aquired from the remote server
1833 * @param cli A cli_state connected to the server.
1834 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1835 * @param argc Standard main() style argc
1836 * @param argv Standard main() style argv. Initial components are already
1839 * @return Normal NTSTATUS return.
1842 NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c,
1843 const DOM_SID *domain_sid,
1844 const char *domain_name,
1845 struct cli_state *cli,
1846 struct rpc_pipe_client *pipe_hnd,
1847 TALLOC_CTX *mem_ctx,
1851 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1853 uint32 num_printers;
1855 char *printername, *sharename;
1856 bool got_src_driver_share = false;
1857 bool got_dst_driver_share = false;
1858 struct rpc_pipe_client *pipe_hnd_dst = NULL;
1859 POLICY_HND hnd_src, hnd_dst;
1860 union spoolss_DriverInfo drv_info_src;
1861 PRINTER_INFO_CTR info_ctr_enum, info_ctr_dst;
1862 union spoolss_PrinterInfo info_dst;
1863 struct cli_state *cli_dst = NULL;
1864 struct cli_state *cli_share_src = NULL;
1865 struct cli_state *cli_share_dst = NULL;
1866 const char *drivername = NULL;
1868 ZERO_STRUCT(info_ctr_enum);
1869 ZERO_STRUCT(info_ctr_dst);
1871 DEBUG(3,("copying printer-drivers\n"));
1873 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
1875 if (!NT_STATUS_IS_OK(nt_status))
1878 /* open print$-share on the src server */
1879 nt_status = connect_to_service(c, &cli_share_src, &cli->dest_ss,
1880 cli->desthost, "print$", "A:");
1881 if (!NT_STATUS_IS_OK(nt_status))
1884 got_src_driver_share = true;
1887 /* open print$-share on the dst server */
1888 nt_status = connect_to_service(c, &cli_share_dst, &cli_dst->dest_ss,
1889 cli_dst->desthost, "print$", "A:");
1890 if (!NT_STATUS_IS_OK(nt_status))
1893 got_dst_driver_share = true;
1896 /* enum src printers */
1897 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_ctr_enum)) {
1898 nt_status = NT_STATUS_UNSUCCESSFUL;
1902 if (num_printers == 0) {
1903 printf ("no printers found on server.\n");
1904 nt_status = NT_STATUS_OK;
1909 /* do something for all printers */
1910 for (p = 0; p < num_printers; p++) {
1911 /* do some initialization */
1912 rpcstr_pull_talloc(mem_ctx,
1914 info_ctr_enum.printers_2[p].printername.buffer,
1917 rpcstr_pull_talloc(mem_ctx,
1919 info_ctr_enum.printers_2[p].sharename.buffer,
1922 if (!printername || !sharename) {
1923 nt_status = NT_STATUS_UNSUCCESSFUL;
1927 /* we can reset NT_STATUS here because we do not
1928 get any real NT_STATUS-codes anymore from now on */
1929 nt_status = NT_STATUS_UNSUCCESSFUL;
1931 d_printf("migrating printer driver for: [%s] / [%s]\n",
1932 printername, sharename);
1934 /* open dst printer handle */
1935 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
1936 PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst))
1939 /* check for existing dst printer */
1940 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst))
1944 /* open src printer handle */
1945 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1946 MAXIMUM_ALLOWED_ACCESS,
1947 pipe_hnd->auth->user_name,
1951 /* in a first step call getdriver for each shared printer (per arch)
1952 to get a list of all files that have to be copied */
1954 for (i=0; archi_table[i].long_archi!=NULL; i++) {
1957 if (!net_spoolss_getprinterdriver(pipe_hnd, mem_ctx, &hnd_src,
1958 level, archi_table[i].long_archi,
1959 archi_table[i].version, &drv_info_src))
1962 drivername = drv_info_src.info3.driver_name;
1965 display_print_driver3(&drv_info_src.info3);
1967 /* check arch dir */
1968 nt_status = check_arch_dir(cli_share_dst, archi_table[i].short_archi);
1969 if (!NT_STATUS_IS_OK(nt_status))
1973 /* copy driver-files */
1974 nt_status = copy_print_driver_3(c, mem_ctx, cli_share_src, cli_share_dst,
1975 archi_table[i].short_archi,
1976 &drv_info_src.info3);
1977 if (!NT_STATUS_IS_OK(nt_status))
1982 if (!net_spoolss_addprinterdriver(pipe_hnd_dst, mem_ctx, level, &drv_info_src)) {
1983 nt_status = NT_STATUS_UNSUCCESSFUL;
1987 DEBUGADD(1,("Sucessfully added driver [%s] for printer [%s]\n",
1988 drivername, printername));
1992 if (strlen(drivername) == 0) {
1993 DEBUGADD(1,("Did not get driver for printer %s\n",
1999 info_dst.info2.drivername = drivername;
2001 if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst)) {
2002 nt_status = NT_STATUS_UNSUCCESSFUL;
2006 DEBUGADD(1,("Sucessfully set driver %s for printer %s\n",
2007 drivername, printername));
2010 if (is_valid_policy_hnd(&hnd_dst)) {
2011 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2015 if (is_valid_policy_hnd(&hnd_src)) {
2016 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2020 nt_status = NT_STATUS_OK;
2024 if (is_valid_policy_hnd(&hnd_src))
2025 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2027 if (is_valid_policy_hnd(&hnd_dst))
2028 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2031 cli_shutdown(cli_dst);
2034 if (got_src_driver_share)
2035 cli_shutdown(cli_share_src);
2037 if (got_dst_driver_share)
2038 cli_shutdown(cli_share_dst);
2045 * Migrate printer-queues from a src to the dst server
2046 * (requires a working "addprinter command" to be installed for the local smbd)
2048 * All parameters are provided by the run_rpc_command function, except for
2049 * argc, argv which are passed through.
2051 * @param c A net_context structure
2052 * @param domain_sid The domain sid aquired from the remote server
2053 * @param cli A cli_state connected to the server.
2054 * @param mem_ctx Talloc context, destoyed on compleation of the function.
2055 * @param argc Standard main() style argc
2056 * @param argv Standard main() style argv. Initial components are already
2059 * @return Normal NTSTATUS return.
2062 NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c,
2063 const DOM_SID *domain_sid,
2064 const char *domain_name,
2065 struct cli_state *cli,
2066 struct rpc_pipe_client *pipe_hnd,
2067 TALLOC_CTX *mem_ctx,
2072 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
2073 uint32 i = 0, num_printers;
2075 PRINTER_INFO_CTR ctr_enum;
2076 union spoolss_PrinterInfo info_dst, info_src;
2077 struct cli_state *cli_dst = NULL;
2078 POLICY_HND hnd_dst, hnd_src;
2079 char *printername, *sharename;
2080 struct rpc_pipe_client *pipe_hnd_dst = NULL;
2081 struct spoolss_SetPrinterInfoCtr info_ctr;
2083 DEBUG(3,("copying printers\n"));
2085 /* connect destination PI_SPOOLSS */
2086 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
2088 if (!NT_STATUS_IS_OK(nt_status))
2092 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) {
2093 nt_status = NT_STATUS_UNSUCCESSFUL;
2097 if (!num_printers) {
2098 printf ("no printers found on server.\n");
2099 nt_status = NT_STATUS_OK;
2103 /* do something for all printers */
2104 for (i = 0; i < num_printers; i++) {
2105 /* do some initialization */
2106 rpcstr_pull_talloc(mem_ctx,
2108 ctr_enum.printers_2[i].printername.buffer,
2111 rpcstr_pull_talloc(mem_ctx,
2113 ctr_enum.printers_2[i].sharename.buffer,
2116 if (!printername || !sharename) {
2117 nt_status = NT_STATUS_UNSUCCESSFUL;
2120 /* we can reset NT_STATUS here because we do not
2121 get any real NT_STATUS-codes anymore from now on */
2122 nt_status = NT_STATUS_UNSUCCESSFUL;
2124 d_printf("migrating printer queue for: [%s] / [%s]\n",
2125 printername, sharename);
2127 /* open dst printer handle */
2128 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
2129 PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) {
2131 DEBUG(1,("could not open printer: %s\n", sharename));
2134 /* check for existing dst printer */
2135 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst)) {
2136 printf ("could not get printer, creating printer.\n");
2138 DEBUG(1,("printer already exists: %s\n", sharename));
2139 /* close printer handle here - dst only, not got src yet. */
2140 if (is_valid_policy_hnd(&hnd_dst)) {
2141 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2146 /* now get again src printer ctr via getprinter,
2147 we first need a handle for that */
2149 /* open src printer handle */
2150 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
2151 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
2154 /* getprinter on the src server */
2155 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, level, &info_src))
2158 /* copy each src printer to a dst printer 1:1,
2159 maybe some values have to be changed though */
2160 d_printf("creating printer: %s\n", printername);
2162 info_ctr.level = level;
2163 info_ctr.info.info2 = (struct spoolss_SetPrinterInfo2 *)&info_src.info2;
2165 result = rpccli_spoolss_addprinterex(pipe_hnd_dst,
2169 if (W_ERROR_IS_OK(result))
2170 d_printf ("printer [%s] successfully added.\n", printername);
2171 else if (W_ERROR_V(result) == W_ERROR_V(WERR_PRINTER_ALREADY_EXISTS))
2172 d_fprintf (stderr, "printer [%s] already exists.\n", printername);
2174 d_fprintf (stderr, "could not create printer [%s]\n", printername);
2178 /* close printer handles here */
2179 if (is_valid_policy_hnd(&hnd_src)) {
2180 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2183 if (is_valid_policy_hnd(&hnd_dst)) {
2184 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2188 nt_status = NT_STATUS_OK;
2191 if (is_valid_policy_hnd(&hnd_src))
2192 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2194 if (is_valid_policy_hnd(&hnd_dst))
2195 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2198 cli_shutdown(cli_dst);
2204 * Migrate Printer-Settings from a src server to the dst server
2205 * (for this to work, printers and drivers already have to be migrated earlier)
2207 * All parameters are provided by the run_rpc_command function, except for
2208 * argc, argv which are passed through.
2210 * @param c A net_context structure
2211 * @param domain_sid The domain sid aquired from the remote server
2212 * @param cli A cli_state connected to the server.
2213 * @param mem_ctx Talloc context, destoyed on compleation of the function.
2214 * @param argc Standard main() style argc
2215 * @param argv Standard main() style argv. Initial components are already
2218 * @return Normal NTSTATUS return.
2221 NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
2222 const DOM_SID *domain_sid,
2223 const char *domain_name,
2224 struct cli_state *cli,
2225 struct rpc_pipe_client *pipe_hnd,
2226 TALLOC_CTX *mem_ctx,
2231 /* FIXME: Here the nightmare begins */
2234 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
2235 uint32 i = 0, p = 0, j = 0;
2236 uint32 num_printers, val_needed, data_needed;
2238 char *printername, *sharename;
2239 struct rpc_pipe_client *pipe_hnd_dst = NULL;
2240 POLICY_HND hnd_src, hnd_dst;
2241 PRINTER_INFO_CTR ctr_enum;
2242 union spoolss_PrinterInfo info_dst_publish, info_dst;
2243 REGVAL_CTR *reg_ctr;
2244 struct cli_state *cli_dst = NULL;
2245 char *devicename = NULL, *unc_name = NULL, *url = NULL;
2246 const char *longname;
2248 uint16 *keylist = NULL, *curkey;
2250 ZERO_STRUCT(ctr_enum);
2252 ZERO_STRUCT(info_dst_publish);
2254 DEBUG(3,("copying printer settings\n"));
2256 /* connect destination PI_SPOOLSS */
2257 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
2259 if (!NT_STATUS_IS_OK(nt_status))
2262 /* enum src printers */
2263 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) {
2264 nt_status = NT_STATUS_UNSUCCESSFUL;
2268 if (!num_printers) {
2269 printf ("no printers found on server.\n");
2270 nt_status = NT_STATUS_OK;
2275 /* needed for dns-strings in regkeys */
2276 longname = get_mydnsfullname();
2278 nt_status = NT_STATUS_UNSUCCESSFUL;
2282 /* do something for all printers */
2283 for (i = 0; i < num_printers; i++) {
2284 /* do some initialization */
2285 rpcstr_pull_talloc(mem_ctx,
2287 ctr_enum.printers_2[i].printername.buffer,
2290 rpcstr_pull_talloc(mem_ctx,
2292 ctr_enum.printers_2[i].sharename.buffer,
2295 if (!printername || !sharename) {
2296 nt_status = NT_STATUS_UNSUCCESSFUL;
2299 /* we can reset NT_STATUS here because we do not
2300 get any real NT_STATUS-codes anymore from now on */
2301 nt_status = NT_STATUS_UNSUCCESSFUL;
2303 d_printf("migrating printer settings for: [%s] / [%s]\n",
2304 printername, sharename);
2307 /* open src printer handle */
2308 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
2309 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
2312 /* open dst printer handle */
2313 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
2314 PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst))
2317 /* check for existing dst printer */
2318 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst,
2322 #if 0 /* FIXME GD */
2324 /* STEP 1: COPY DEVICE-MODE and other
2325 PRINTER_INFO_2-attributes
2328 info_dst.info2 = &ctr_enum.printers_2[i];
2330 /* why is the port always disconnected when the printer
2331 is correctly installed (incl. driver ???) */
2332 info_dst.info2.portname = SAMBA_PRINTER_PORT_NAME;
2334 /* check if printer is published */
2335 if (ctr_enum.printers_2[i].attributes & PRINTER_ATTRIBUTE_PUBLISHED) {
2337 /* check for existing dst printer */
2338 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 7, &info_dst_publish))
2341 info_dst_publish.info7.action = DSPRINT_PUBLISH;
2343 /* ignore false from setprinter due to WERR_IO_PENDING */
2344 net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 7, &info_dst_publish);
2346 DEBUG(3,("republished printer\n"));
2349 if (ctr_enum.printers_2[i].devmode != NULL) {
2351 /* copy devmode (info level 2) */
2352 info_dst.info2.devmode = (DEVICEMODE *)
2353 TALLOC_MEMDUP(mem_ctx,
2354 ctr_enum.printers_2[i].devmode,
2355 sizeof(DEVICEMODE));
2357 /* do not copy security descriptor (we have another
2358 * command for that) */
2359 info_dst.info2.secdesc = NULL;
2362 if (asprintf(&devicename, "\\\\%s\\%s", longname,
2364 nt_status = NT_STATUS_NO_MEMORY;
2368 init_unistr(&ctr_dst.printers_2->devmode->devicename,
2371 if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst,
2375 DEBUGADD(1,("\tSetPrinter of DEVICEMODE succeeded\n"));
2378 /* STEP 2: COPY REGISTRY VALUES */
2380 /* please keep in mind that samba parse_spools gives horribly
2381 crippled results when used to rpccli_spoolss_enumprinterdataex
2382 a win2k3-server. (Bugzilla #1851)
2383 FIXME: IIRC I've seen it too on a win2k-server
2386 /* enumerate data on src handle */
2387 result = rpccli_spoolss_enumprinterdata(pipe_hnd, mem_ctx, &hnd_src, p, 0, 0,
2388 &val_needed, &data_needed, NULL);
2390 /* loop for all printerdata of "PrinterDriverData" */
2391 while (W_ERROR_IS_OK(result)) {
2393 REGISTRY_VALUE value;
2395 result = rpccli_spoolss_enumprinterdata(
2396 pipe_hnd, mem_ctx, &hnd_src, p++, val_needed,
2397 data_needed, 0, 0, &value);
2399 /* loop for all reg_keys */
2400 if (W_ERROR_IS_OK(result)) {
2404 display_reg_value(SPOOL_PRINTERDATA_KEY, value);
2407 if (!net_spoolss_setprinterdata(pipe_hnd_dst, mem_ctx,
2411 DEBUGADD(1,("\tSetPrinterData of [%s] succeeded\n",
2416 /* STEP 3: COPY SUBKEY VALUES */
2418 /* here we need to enum all printer_keys and then work
2419 on the result with enum_printer_key_ex. nt4 does not
2420 respond to enumprinterkey, win2k does, so continue
2421 in case of an error */
2423 if (!net_spoolss_enumprinterkey(pipe_hnd, mem_ctx, &hnd_src, "", &keylist)) {
2424 printf("got no key-data\n");
2429 /* work on a list of printer keys
2430 each key has to be enumerated to get all required
2431 information. information is then set via setprinterdataex-calls */
2433 if (keylist == NULL)
2437 while (*curkey != 0) {
2439 rpcstr_pull_talloc(mem_ctx,
2445 return NT_STATUS_NO_MEMORY;
2448 curkey += strlen(subkey) + 1;
2450 if ( !(reg_ctr = TALLOC_ZERO_P( mem_ctx, REGVAL_CTR )) )
2451 return NT_STATUS_NO_MEMORY;
2453 /* enumerate all src subkeys */
2454 if (!net_spoolss_enumprinterdataex(pipe_hnd, mem_ctx, 0,
2459 for (j=0; j < reg_ctr->num_values; j++) {
2461 REGISTRY_VALUE value;
2464 /* although samba replies with sane data in most cases we
2465 should try to avoid writing wrong registry data */
2467 if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_PORTNAME) ||
2468 strequal(reg_ctr->values[j]->valuename, SPOOL_REG_UNCNAME) ||
2469 strequal(reg_ctr->values[j]->valuename, SPOOL_REG_URL) ||
2470 strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SHORTSERVERNAME) ||
2471 strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SERVERNAME)) {
2473 if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_PORTNAME)) {
2475 /* although windows uses a multi-sz, we use a sz */
2476 init_unistr2(&data, SAMBA_PRINTER_PORT_NAME, UNI_STR_TERMINATE);
2477 fstrcpy(value.valuename, SPOOL_REG_PORTNAME);
2480 if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_UNCNAME)) {
2482 if (asprintf(&unc_name, "\\\\%s\\%s", longname, sharename) < 0) {
2483 nt_status = NT_STATUS_NO_MEMORY;
2486 init_unistr2(&data, unc_name, UNI_STR_TERMINATE);
2487 fstrcpy(value.valuename, SPOOL_REG_UNCNAME);
2490 if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_URL)) {
2495 /* FIXME: should we really do that ??? */
2496 if (asprintf(&url, "http://%s:631/printers/%s", longname, sharename) < 0) {
2497 nt_status = NT_STATUS_NO_MEMORY;
2500 init_unistr2(&data, url, UNI_STR_TERMINATE);
2501 fstrcpy(value.valuename, SPOOL_REG_URL);
2505 if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SERVERNAME)) {
2507 init_unistr2(&data, longname, UNI_STR_TERMINATE);
2508 fstrcpy(value.valuename, SPOOL_REG_SERVERNAME);
2511 if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SHORTSERVERNAME)) {
2513 init_unistr2(&data, global_myname(), UNI_STR_TERMINATE);
2514 fstrcpy(value.valuename, SPOOL_REG_SHORTSERVERNAME);
2517 value.type = REG_SZ;
2518 value.size = data.uni_str_len * 2;
2520 value.data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, data.buffer, value.size);
2522 value.data_p = NULL;
2526 display_reg_value(subkey, value);
2528 /* here we have to set all subkeys on the dst server */
2529 if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst,
2536 display_reg_value(subkey, *(reg_ctr->values[j]));
2538 /* here we have to set all subkeys on the dst server */
2539 if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst,
2540 subkey, reg_ctr->values[j]))
2545 DEBUGADD(1,("\tSetPrinterDataEx of key [%s\\%s] succeeded\n",
2546 subkey, reg_ctr->values[j]->valuename));
2550 TALLOC_FREE( reg_ctr );
2555 /* close printer handles here */
2556 if (is_valid_policy_hnd(&hnd_src)) {
2557 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2560 if (is_valid_policy_hnd(&hnd_dst)) {
2561 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2566 nt_status = NT_STATUS_OK;
2569 SAFE_FREE(devicename);
2571 SAFE_FREE(unc_name);
2573 if (is_valid_policy_hnd(&hnd_src))
2574 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2576 if (is_valid_policy_hnd(&hnd_dst))
2577 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2580 cli_shutdown(cli_dst);