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,
964 result = rpccli_spoolss_enumforms(pipe_hnd, mem_ctx, hnd, level, num_forms, forms);
966 if (!W_ERROR_IS_OK(result)) {
967 printf("could not enum forms: %s\n", win_errstr(result));
974 static bool net_spoolss_enumprinterdrivers (struct rpc_pipe_client *pipe_hnd,
976 uint32 level, const char *env,
978 PRINTER_DRIVER_CTR *ctr)
982 /* enumprinterdrivers call */
983 result = rpccli_spoolss_enumprinterdrivers(
984 pipe_hnd, mem_ctx, level,
985 env, num_drivers, ctr);
987 if (!W_ERROR_IS_OK(result)) {
988 printf("cannot enum drivers: %s\n", win_errstr(result));
995 static bool net_spoolss_getprinterdriver(struct rpc_pipe_client *pipe_hnd,
997 POLICY_HND *hnd, uint32 level,
998 const char *env, int version,
999 union spoolss_DriverInfo *info)
1002 uint32_t server_major_version;
1003 uint32_t server_minor_version;
1005 /* getprinterdriver call */
1006 result = rpccli_spoolss_getprinterdriver2(pipe_hnd, mem_ctx,
1014 &server_major_version,
1015 &server_minor_version);
1016 if (!W_ERROR_IS_OK(result)) {
1017 DEBUG(1,("cannot get driver (for architecture: %s): %s\n",
1018 env, win_errstr(result)));
1019 if (W_ERROR_V(result) != W_ERROR_V(WERR_UNKNOWN_PRINTER_DRIVER) &&
1020 W_ERROR_V(result) != W_ERROR_V(WERR_INVALID_ENVIRONMENT)) {
1021 printf("cannot get driver: %s\n", win_errstr(result));
1030 static bool net_spoolss_addprinterdriver(struct rpc_pipe_client *pipe_hnd,
1031 TALLOC_CTX *mem_ctx, uint32 level,
1032 union spoolss_DriverInfo *info)
1036 struct spoolss_AddDriverInfoCtr info_ctr;
1038 info_ctr.level = level;
1042 info_ctr.info.info2 = (struct spoolss_AddDriverInfo2 *)&info->info2;
1045 info_ctr.info.info3 = (struct spoolss_AddDriverInfo3 *)&info->info3;
1048 printf("unsupported info level: %d\n", level);
1052 /* addprinterdriver call */
1053 status = rpccli_spoolss_AddPrinterDriver(pipe_hnd, mem_ctx,
1054 pipe_hnd->srv_name_slash,
1057 /* be more verbose */
1058 if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) {
1059 printf("You are not allowed to add drivers\n");
1062 if (!W_ERROR_IS_OK(result)) {
1063 printf("cannot add driver: %s\n", win_errstr(result));
1071 * abstraction function to get uint32 num_printers and PRINTER_INFO_CTR ctr
1072 * for a single printer or for all printers depending on argc/argv
1075 static bool get_printer_info(struct rpc_pipe_client *pipe_hnd,
1076 TALLOC_CTX *mem_ctx,
1080 uint32 *num_printers,
1081 PRINTER_INFO_CTR *ctr)
1085 union spoolss_PrinterInfo info;
1087 /* no arguments given, enumerate all printers */
1090 if (!net_spoolss_enum_printers(pipe_hnd, mem_ctx, NULL,
1091 PRINTER_ENUM_LOCAL|PRINTER_ENUM_SHARED,
1092 level, num_printers, ctr))
1101 /* argument given, get a single printer by name */
1102 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, argv[0],
1103 MAXIMUM_ALLOWED_ACCESS,
1104 pipe_hnd->auth->user_name,
1108 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info)) {
1109 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1113 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1118 DEBUG(3,("got %d printers\n", *num_printers));
1125 * List print-queues (including local printers that are not shared)
1127 * All parameters are provided by the run_rpc_command function, except for
1128 * argc, argv which are passed through.
1130 * @param c A net_context structure
1131 * @param domain_sid The domain sid aquired from the remote server
1132 * @param cli A cli_state connected to the server.
1133 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1134 * @param argc Standard main() style argc
1135 * @param argv Standard main() style argv. Initial components are already
1138 * @return Normal NTSTATUS return.
1141 NTSTATUS rpc_printer_list_internals(struct net_context *c,
1142 const DOM_SID *domain_sid,
1143 const char *domain_name,
1144 struct cli_state *cli,
1145 struct rpc_pipe_client *pipe_hnd,
1146 TALLOC_CTX *mem_ctx,
1150 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1151 uint32 i, num_printers;
1153 char *printername, *sharename;
1154 PRINTER_INFO_CTR ctr;
1156 printf("listing printers\n");
1158 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr))
1161 for (i = 0; i < num_printers; i++) {
1162 /* do some initialization */
1163 rpcstr_pull_talloc(mem_ctx,
1165 ctr.printers_2[i].printername.buffer,
1168 rpcstr_pull_talloc(mem_ctx,
1170 ctr.printers_2[i].sharename.buffer,
1174 if (printername && sharename) {
1175 d_printf("printer %d: %s, shared as: %s\n",
1176 i+1, printername, sharename);
1180 return NT_STATUS_OK;
1184 * List printer-drivers from a server
1186 * All parameters are provided by the run_rpc_command function, except for
1187 * argc, argv which are passed through.
1189 * @param c A net_context structure
1190 * @param domain_sid The domain sid aquired from the remote server
1191 * @param cli A cli_state connected to the server.
1192 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1193 * @param argc Standard main() style argc
1194 * @param argv Standard main() style argv. Initial components are already
1197 * @return Normal NTSTATUS return.
1200 NTSTATUS rpc_printer_driver_list_internals(struct net_context *c,
1201 const DOM_SID *domain_sid,
1202 const char *domain_name,
1203 struct cli_state *cli,
1204 struct rpc_pipe_client *pipe_hnd,
1205 TALLOC_CTX *mem_ctx,
1209 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1212 PRINTER_DRIVER_CTR drv_ctr_enum;
1215 ZERO_STRUCT(drv_ctr_enum);
1217 printf("listing printer-drivers\n");
1219 for (i=0; archi_table[i].long_archi!=NULL; i++) {
1223 /* enum remote drivers */
1224 if (!net_spoolss_enumprinterdrivers(pipe_hnd, mem_ctx, level,
1225 archi_table[i].long_archi,
1226 &num_drivers, &drv_ctr_enum)) {
1227 nt_status = NT_STATUS_UNSUCCESSFUL;
1231 if (num_drivers == 0) {
1232 d_printf ("no drivers found on server for architecture: [%s].\n",
1233 archi_table[i].long_archi);
1237 d_printf("got %d printer-drivers for architecture: [%s]\n",
1238 num_drivers, archi_table[i].long_archi);
1241 /* do something for all drivers for architecture */
1242 for (d = 0; d < num_drivers; d++) {
1243 display_print_driver_3(&(drv_ctr_enum.info3[d]));
1247 nt_status = NT_STATUS_OK;
1255 * Publish print-queues with args-wrapper
1257 * @param cli A cli_state connected to the server.
1258 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1259 * @param argc Standard main() style argc
1260 * @param argv Standard main() style argv. Initial components are already
1264 * @return Normal NTSTATUS return.
1267 static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_hnd,
1268 TALLOC_CTX *mem_ctx,
1273 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1274 uint32 i, num_printers;
1276 char *printername, *sharename;
1277 PRINTER_INFO_CTR ctr;
1278 union spoolss_PrinterInfo info;
1279 struct spoolss_SetPrinterInfoCtr info_ctr;
1280 struct spoolss_DevmodeContainer devmode_ctr;
1281 struct sec_desc_buf secdesc_ctr;
1284 const char *action_str;
1286 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr))
1289 for (i = 0; i < num_printers; i++) {
1290 /* do some initialization */
1291 rpcstr_pull_talloc(mem_ctx,
1293 ctr.printers_2[i].printername.buffer,
1296 rpcstr_pull_talloc(mem_ctx,
1298 ctr.printers_2[i].sharename.buffer,
1301 if (!printername || !sharename) {
1305 /* open printer handle */
1306 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1307 PRINTER_ALL_ACCESS, pipe_hnd->auth->user_name, &hnd))
1310 /* check for existing dst printer */
1311 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info))
1314 /* check action and set string */
1316 case DSPRINT_PUBLISH:
1317 action_str = "published";
1319 case DSPRINT_UPDATE:
1320 action_str = "updated";
1322 case DSPRINT_UNPUBLISH:
1323 action_str = "unpublished";
1326 action_str = "unknown action";
1327 printf("unkown action: %d\n", action);
1331 info.info7.action = action;
1333 info_ctr.info.info7 = (struct spoolss_SetPrinterInfo7 *)&info.info7;
1335 ZERO_STRUCT(devmode_ctr);
1336 ZERO_STRUCT(secdesc_ctr);
1338 nt_status = rpccli_spoolss_SetPrinter(pipe_hnd, mem_ctx,
1346 if (!W_ERROR_IS_OK(result) && (W_ERROR_V(result) != W_ERROR_V(WERR_IO_PENDING))) {
1347 printf("cannot set printer-info: %s\n", win_errstr(result));
1351 printf("successfully %s printer %s in Active Directory\n", action_str, sharename);
1354 nt_status = NT_STATUS_OK;
1357 if (is_valid_policy_hnd(&hnd))
1358 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1363 NTSTATUS rpc_printer_publish_publish_internals(struct net_context *c,
1364 const DOM_SID *domain_sid,
1365 const char *domain_name,
1366 struct cli_state *cli,
1367 struct rpc_pipe_client *pipe_hnd,
1368 TALLOC_CTX *mem_ctx,
1372 return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, DSPRINT_PUBLISH);
1375 NTSTATUS rpc_printer_publish_unpublish_internals(struct net_context *c,
1376 const DOM_SID *domain_sid,
1377 const char *domain_name,
1378 struct cli_state *cli,
1379 struct rpc_pipe_client *pipe_hnd,
1380 TALLOC_CTX *mem_ctx,
1384 return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, DSPRINT_UNPUBLISH);
1387 NTSTATUS rpc_printer_publish_update_internals(struct net_context *c,
1388 const DOM_SID *domain_sid,
1389 const char *domain_name,
1390 struct cli_state *cli,
1391 struct rpc_pipe_client *pipe_hnd,
1392 TALLOC_CTX *mem_ctx,
1396 return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, DSPRINT_UPDATE);
1400 * List print-queues w.r.t. their publishing state
1402 * All parameters are provided by the run_rpc_command function, except for
1403 * argc, argv which are passed through.
1405 * @param c A net_context structure
1406 * @param domain_sid The domain sid aquired from the remote server
1407 * @param cli A cli_state connected to the server.
1408 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1409 * @param argc Standard main() style argc
1410 * @param argv Standard main() style argv. Initial components are already
1413 * @return Normal NTSTATUS return.
1416 NTSTATUS rpc_printer_publish_list_internals(struct net_context *c,
1417 const DOM_SID *domain_sid,
1418 const char *domain_name,
1419 struct cli_state *cli,
1420 struct rpc_pipe_client *pipe_hnd,
1421 TALLOC_CTX *mem_ctx,
1425 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1426 uint32 i, num_printers;
1428 char *printername, *sharename;
1429 PRINTER_INFO_CTR ctr, ctr_pub;
1430 union spoolss_PrinterInfo info;
1434 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr))
1437 for (i = 0; i < num_printers; i++) {
1438 ZERO_STRUCT(ctr_pub);
1440 /* do some initialization */
1441 rpcstr_pull_talloc(mem_ctx,
1443 ctr.printers_2[i].printername.buffer,
1446 rpcstr_pull_talloc(mem_ctx,
1448 ctr.printers_2[i].sharename.buffer,
1451 if (!printername || !sharename) {
1455 /* open printer handle */
1456 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1457 PRINTER_ALL_ACCESS, cli->user_name, &hnd))
1460 /* check for existing dst printer */
1461 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info))
1464 if (!info.info7.guid) {
1467 state = info.info7.action;
1469 case DSPRINT_PUBLISH:
1470 printf("printer [%s] is published", sharename);
1472 printf(", guid: %s", info.info7.guid);
1475 case DSPRINT_UNPUBLISH:
1476 printf("printer [%s] is unpublished\n", sharename);
1478 case DSPRINT_UPDATE:
1479 printf("printer [%s] is currently updating\n", sharename);
1482 printf("unkown state: %d\n", state);
1487 nt_status = NT_STATUS_OK;
1490 if (is_valid_policy_hnd(&hnd))
1491 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1497 * Migrate Printer-ACLs from a source server to the destination server
1499 * All parameters are provided by the run_rpc_command function, except for
1500 * argc, argv which are passed through.
1502 * @param c A net_context structure
1503 * @param domain_sid The domain sid aquired from the remote server
1504 * @param cli A cli_state connected to the server.
1505 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1506 * @param argc Standard main() style argc
1507 * @param argv Standard main() style argv. Initial components are already
1510 * @return Normal NTSTATUS return.
1513 NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c,
1514 const DOM_SID *domain_sid,
1515 const char *domain_name,
1516 struct cli_state *cli,
1517 struct rpc_pipe_client *pipe_hnd,
1518 TALLOC_CTX *mem_ctx,
1522 /* TODO: what now, info2 or info3 ?
1523 convince jerry that we should add clientside setacls level 3 at least
1525 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1527 uint32 num_printers;
1529 char *printername, *sharename;
1530 struct rpc_pipe_client *pipe_hnd_dst = NULL;
1531 POLICY_HND hnd_src, hnd_dst;
1532 PRINTER_INFO_CTR ctr_src, ctr_enum;
1533 struct cli_state *cli_dst = NULL;
1534 union spoolss_PrinterInfo info_src, info_dst;
1536 ZERO_STRUCT(ctr_src);
1538 DEBUG(3,("copying printer ACLs\n"));
1540 /* connect destination PI_SPOOLSS */
1541 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
1543 if (!NT_STATUS_IS_OK(nt_status))
1547 /* enum source printers */
1548 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) {
1549 nt_status = NT_STATUS_UNSUCCESSFUL;
1553 if (!num_printers) {
1554 printf ("no printers found on server.\n");
1555 nt_status = NT_STATUS_OK;
1559 /* do something for all printers */
1560 for (i = 0; i < num_printers; i++) {
1561 /* do some initialization */
1562 rpcstr_pull_talloc(mem_ctx,
1564 ctr_enum.printers_2[i].printername.buffer,
1567 rpcstr_pull_talloc(mem_ctx,
1569 ctr_enum.printers_2[i].sharename.buffer,
1572 if (!printername || !sharename) {
1573 nt_status = NT_STATUS_UNSUCCESSFUL;
1577 /* we can reset NT_STATUS here because we do not
1578 get any real NT_STATUS-codes anymore from now on */
1579 nt_status = NT_STATUS_UNSUCCESSFUL;
1581 d_printf("migrating printer ACLs for: [%s] / [%s]\n",
1582 printername, sharename);
1584 /* according to msdn you have specify these access-rights
1585 to see the security descriptor
1586 - READ_CONTROL (DACL)
1587 - ACCESS_SYSTEM_SECURITY (SACL)
1590 /* open src printer handle */
1591 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1592 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
1595 /* open dst printer handle */
1596 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
1597 PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst))
1600 /* check for existing dst printer */
1601 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst))
1604 /* check for existing src printer */
1605 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, 3, &info_src))
1608 /* Copy Security Descriptor */
1610 /* copy secdesc (info level 2) */
1611 info_dst.info2.devmode = NULL;
1612 info_dst.info2.secdesc = dup_sec_desc(mem_ctx, info_src.info3.secdesc);
1615 display_sec_desc(info_dst.info2.secdesc);
1617 if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst))
1620 DEBUGADD(1,("\tSetPrinter of SECDESC succeeded\n"));
1623 /* close printer handles here */
1624 if (is_valid_policy_hnd(&hnd_src)) {
1625 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1628 if (is_valid_policy_hnd(&hnd_dst)) {
1629 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1634 nt_status = NT_STATUS_OK;
1638 if (is_valid_policy_hnd(&hnd_src)) {
1639 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1642 if (is_valid_policy_hnd(&hnd_dst)) {
1643 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1647 cli_shutdown(cli_dst);
1653 * Migrate printer-forms from a src server to the dst server
1655 * All parameters are provided by the run_rpc_command function, except for
1656 * argc, argv which are passed through.
1658 * @param c A net_context structure
1659 * @param domain_sid The domain sid aquired from the remote server
1660 * @param cli A cli_state connected to the server.
1661 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1662 * @param argc Standard main() style argc
1663 * @param argv Standard main() style argv. Initial components are already
1666 * @return Normal NTSTATUS return.
1669 NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c,
1670 const DOM_SID *domain_sid,
1671 const char *domain_name,
1672 struct cli_state *cli,
1673 struct rpc_pipe_client *pipe_hnd,
1674 TALLOC_CTX *mem_ctx,
1678 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1681 uint32 num_printers;
1683 char *printername, *sharename;
1684 struct rpc_pipe_client *pipe_hnd_dst = NULL;
1685 POLICY_HND hnd_src, hnd_dst;
1686 PRINTER_INFO_CTR ctr_enum;
1687 union spoolss_PrinterInfo info_dst;
1690 struct cli_state *cli_dst = NULL;
1692 ZERO_STRUCT(ctr_enum);
1694 DEBUG(3,("copying forms\n"));
1696 /* connect destination PI_SPOOLSS */
1697 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
1699 if (!NT_STATUS_IS_OK(nt_status))
1702 /* enum src printers */
1703 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr_enum)) {
1704 nt_status = NT_STATUS_UNSUCCESSFUL;
1708 if (!num_printers) {
1709 printf ("no printers found on server.\n");
1710 nt_status = NT_STATUS_OK;
1714 /* do something for all printers */
1715 for (i = 0; i < num_printers; i++) {
1716 /* do some initialization */
1717 rpcstr_pull_talloc(mem_ctx,
1719 ctr_enum.printers_2[i].printername.buffer,
1722 rpcstr_pull_talloc(mem_ctx,
1724 ctr_enum.printers_2[i].sharename.buffer,
1727 if (!printername || !sharename) {
1728 nt_status = NT_STATUS_UNSUCCESSFUL;
1731 /* we can reset NT_STATUS here because we do not
1732 get any real NT_STATUS-codes anymore from now on */
1733 nt_status = NT_STATUS_UNSUCCESSFUL;
1735 d_printf("migrating printer forms for: [%s] / [%s]\n",
1736 printername, sharename);
1739 /* open src printer handle */
1740 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1741 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
1744 /* open dst printer handle */
1745 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
1746 PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst))
1749 /* check for existing dst printer */
1750 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst))
1753 /* finally migrate forms */
1754 if (!net_spoolss_enumforms(pipe_hnd, mem_ctx, &hnd_src, level, &num_forms, &forms))
1757 DEBUG(1,("got %d forms for printer\n", num_forms));
1760 for (f = 0; f < num_forms; f++) {
1762 union spoolss_AddFormInfo info;
1763 struct spoolss_AddFormInfo1 info1;
1767 /* only migrate FORM_PRINTER types, according to jerry
1768 FORM_BUILTIN-types are hard-coded in samba */
1769 if (forms[f].flag != FORM_PRINTER)
1772 if (forms[f].name.buffer)
1773 rpcstr_pull(form_name, forms[f].name.buffer,
1774 sizeof(form_name), -1, STR_TERMINATE);
1777 d_printf("\tmigrating form # %d [%s] of type [%d]\n",
1778 f, form_name, forms[f].flag);
1780 /* is there a more elegant way to do that ? */
1781 info1.flags = FORM_PRINTER;
1782 info1.size.width = forms[f].width;
1783 info1.size.height = forms[f].length;
1784 info1.area.left = forms[f].left;
1785 info1.area.top = forms[f].top;
1786 info1.area.right = forms[f].right;
1787 info1.area.bottom = forms[f].bottom;
1788 info1.form_name = form_name;
1790 info.info1 = &info1;
1792 /* FIXME: there might be something wrong with samba's
1794 status = rpccli_spoolss_AddForm(pipe_hnd_dst, mem_ctx,
1799 if (!W_ERROR_IS_OK(result)) {
1800 d_printf("\tAddForm form %d: [%s] refused.\n",
1805 DEBUGADD(1,("\tAddForm of [%s] succeeded\n", form_name));
1809 /* close printer handles here */
1810 if (is_valid_policy_hnd(&hnd_src)) {
1811 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1814 if (is_valid_policy_hnd(&hnd_dst)) {
1815 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1819 nt_status = NT_STATUS_OK;
1823 if (is_valid_policy_hnd(&hnd_src))
1824 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1826 if (is_valid_policy_hnd(&hnd_dst))
1827 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1830 cli_shutdown(cli_dst);
1836 * Migrate printer-drivers from a src server to the dst server
1838 * All parameters are provided by the run_rpc_command function, except for
1839 * argc, argv which are passed through.
1841 * @param c A net_context structure
1842 * @param domain_sid The domain sid aquired from the remote server
1843 * @param cli A cli_state connected to the server.
1844 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1845 * @param argc Standard main() style argc
1846 * @param argv Standard main() style argv. Initial components are already
1849 * @return Normal NTSTATUS return.
1852 NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c,
1853 const DOM_SID *domain_sid,
1854 const char *domain_name,
1855 struct cli_state *cli,
1856 struct rpc_pipe_client *pipe_hnd,
1857 TALLOC_CTX *mem_ctx,
1861 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1863 uint32 num_printers;
1865 char *printername, *sharename;
1866 bool got_src_driver_share = false;
1867 bool got_dst_driver_share = false;
1868 struct rpc_pipe_client *pipe_hnd_dst = NULL;
1869 POLICY_HND hnd_src, hnd_dst;
1870 union spoolss_DriverInfo drv_info_src;
1871 PRINTER_INFO_CTR info_ctr_enum, info_ctr_dst;
1872 union spoolss_PrinterInfo info_dst;
1873 struct cli_state *cli_dst = NULL;
1874 struct cli_state *cli_share_src = NULL;
1875 struct cli_state *cli_share_dst = NULL;
1876 const char *drivername = NULL;
1878 ZERO_STRUCT(info_ctr_enum);
1879 ZERO_STRUCT(info_ctr_dst);
1881 DEBUG(3,("copying printer-drivers\n"));
1883 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
1885 if (!NT_STATUS_IS_OK(nt_status))
1888 /* open print$-share on the src server */
1889 nt_status = connect_to_service(c, &cli_share_src, &cli->dest_ss,
1890 cli->desthost, "print$", "A:");
1891 if (!NT_STATUS_IS_OK(nt_status))
1894 got_src_driver_share = true;
1897 /* open print$-share on the dst server */
1898 nt_status = connect_to_service(c, &cli_share_dst, &cli_dst->dest_ss,
1899 cli_dst->desthost, "print$", "A:");
1900 if (!NT_STATUS_IS_OK(nt_status))
1903 got_dst_driver_share = true;
1906 /* enum src printers */
1907 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_ctr_enum)) {
1908 nt_status = NT_STATUS_UNSUCCESSFUL;
1912 if (num_printers == 0) {
1913 printf ("no printers found on server.\n");
1914 nt_status = NT_STATUS_OK;
1919 /* do something for all printers */
1920 for (p = 0; p < num_printers; p++) {
1921 /* do some initialization */
1922 rpcstr_pull_talloc(mem_ctx,
1924 info_ctr_enum.printers_2[p].printername.buffer,
1927 rpcstr_pull_talloc(mem_ctx,
1929 info_ctr_enum.printers_2[p].sharename.buffer,
1932 if (!printername || !sharename) {
1933 nt_status = NT_STATUS_UNSUCCESSFUL;
1937 /* we can reset NT_STATUS here because we do not
1938 get any real NT_STATUS-codes anymore from now on */
1939 nt_status = NT_STATUS_UNSUCCESSFUL;
1941 d_printf("migrating printer driver for: [%s] / [%s]\n",
1942 printername, sharename);
1944 /* open dst printer handle */
1945 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
1946 PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst))
1949 /* check for existing dst printer */
1950 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst))
1954 /* open src printer handle */
1955 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1956 MAXIMUM_ALLOWED_ACCESS,
1957 pipe_hnd->auth->user_name,
1961 /* in a first step call getdriver for each shared printer (per arch)
1962 to get a list of all files that have to be copied */
1964 for (i=0; archi_table[i].long_archi!=NULL; i++) {
1967 if (!net_spoolss_getprinterdriver(pipe_hnd, mem_ctx, &hnd_src,
1968 level, archi_table[i].long_archi,
1969 archi_table[i].version, &drv_info_src))
1972 drivername = drv_info_src.info3.driver_name;
1975 display_print_driver3(&drv_info_src.info3);
1977 /* check arch dir */
1978 nt_status = check_arch_dir(cli_share_dst, archi_table[i].short_archi);
1979 if (!NT_STATUS_IS_OK(nt_status))
1983 /* copy driver-files */
1984 nt_status = copy_print_driver_3(c, mem_ctx, cli_share_src, cli_share_dst,
1985 archi_table[i].short_archi,
1986 &drv_info_src.info3);
1987 if (!NT_STATUS_IS_OK(nt_status))
1992 if (!net_spoolss_addprinterdriver(pipe_hnd_dst, mem_ctx, level, &drv_info_src)) {
1993 nt_status = NT_STATUS_UNSUCCESSFUL;
1997 DEBUGADD(1,("Sucessfully added driver [%s] for printer [%s]\n",
1998 drivername, printername));
2002 if (strlen(drivername) == 0) {
2003 DEBUGADD(1,("Did not get driver for printer %s\n",
2009 info_dst.info2.drivername = drivername;
2011 if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst)) {
2012 nt_status = NT_STATUS_UNSUCCESSFUL;
2016 DEBUGADD(1,("Sucessfully set driver %s for printer %s\n",
2017 drivername, printername));
2020 if (is_valid_policy_hnd(&hnd_dst)) {
2021 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2025 if (is_valid_policy_hnd(&hnd_src)) {
2026 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2030 nt_status = NT_STATUS_OK;
2034 if (is_valid_policy_hnd(&hnd_src))
2035 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2037 if (is_valid_policy_hnd(&hnd_dst))
2038 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2041 cli_shutdown(cli_dst);
2044 if (got_src_driver_share)
2045 cli_shutdown(cli_share_src);
2047 if (got_dst_driver_share)
2048 cli_shutdown(cli_share_dst);
2055 * Migrate printer-queues from a src to the dst server
2056 * (requires a working "addprinter command" to be installed for the local smbd)
2058 * All parameters are provided by the run_rpc_command function, except for
2059 * argc, argv which are passed through.
2061 * @param c A net_context structure
2062 * @param domain_sid The domain sid aquired from the remote server
2063 * @param cli A cli_state connected to the server.
2064 * @param mem_ctx Talloc context, destoyed on compleation of the function.
2065 * @param argc Standard main() style argc
2066 * @param argv Standard main() style argv. Initial components are already
2069 * @return Normal NTSTATUS return.
2072 NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c,
2073 const DOM_SID *domain_sid,
2074 const char *domain_name,
2075 struct cli_state *cli,
2076 struct rpc_pipe_client *pipe_hnd,
2077 TALLOC_CTX *mem_ctx,
2082 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
2083 uint32 i = 0, num_printers;
2085 PRINTER_INFO_CTR ctr_enum;
2086 union spoolss_PrinterInfo info_dst, info_src;
2087 struct cli_state *cli_dst = NULL;
2088 POLICY_HND hnd_dst, hnd_src;
2089 char *printername, *sharename;
2090 struct rpc_pipe_client *pipe_hnd_dst = NULL;
2091 struct spoolss_SetPrinterInfoCtr info_ctr;
2093 DEBUG(3,("copying printers\n"));
2095 /* connect destination PI_SPOOLSS */
2096 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
2098 if (!NT_STATUS_IS_OK(nt_status))
2102 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) {
2103 nt_status = NT_STATUS_UNSUCCESSFUL;
2107 if (!num_printers) {
2108 printf ("no printers found on server.\n");
2109 nt_status = NT_STATUS_OK;
2113 /* do something for all printers */
2114 for (i = 0; i < num_printers; i++) {
2115 /* do some initialization */
2116 rpcstr_pull_talloc(mem_ctx,
2118 ctr_enum.printers_2[i].printername.buffer,
2121 rpcstr_pull_talloc(mem_ctx,
2123 ctr_enum.printers_2[i].sharename.buffer,
2126 if (!printername || !sharename) {
2127 nt_status = NT_STATUS_UNSUCCESSFUL;
2130 /* we can reset NT_STATUS here because we do not
2131 get any real NT_STATUS-codes anymore from now on */
2132 nt_status = NT_STATUS_UNSUCCESSFUL;
2134 d_printf("migrating printer queue for: [%s] / [%s]\n",
2135 printername, sharename);
2137 /* open dst printer handle */
2138 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
2139 PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) {
2141 DEBUG(1,("could not open printer: %s\n", sharename));
2144 /* check for existing dst printer */
2145 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst)) {
2146 printf ("could not get printer, creating printer.\n");
2148 DEBUG(1,("printer already exists: %s\n", sharename));
2149 /* close printer handle here - dst only, not got src yet. */
2150 if (is_valid_policy_hnd(&hnd_dst)) {
2151 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2156 /* now get again src printer ctr via getprinter,
2157 we first need a handle for that */
2159 /* open src printer handle */
2160 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
2161 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
2164 /* getprinter on the src server */
2165 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, level, &info_src))
2168 /* copy each src printer to a dst printer 1:1,
2169 maybe some values have to be changed though */
2170 d_printf("creating printer: %s\n", printername);
2172 info_ctr.level = level;
2173 info_ctr.info.info2 = (struct spoolss_SetPrinterInfo2 *)&info_src.info2;
2175 result = rpccli_spoolss_addprinterex(pipe_hnd_dst,
2179 if (W_ERROR_IS_OK(result))
2180 d_printf ("printer [%s] successfully added.\n", printername);
2181 else if (W_ERROR_V(result) == W_ERROR_V(WERR_PRINTER_ALREADY_EXISTS))
2182 d_fprintf (stderr, "printer [%s] already exists.\n", printername);
2184 d_fprintf (stderr, "could not create printer [%s]\n", printername);
2188 /* close printer handles here */
2189 if (is_valid_policy_hnd(&hnd_src)) {
2190 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2193 if (is_valid_policy_hnd(&hnd_dst)) {
2194 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2198 nt_status = NT_STATUS_OK;
2201 if (is_valid_policy_hnd(&hnd_src))
2202 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2204 if (is_valid_policy_hnd(&hnd_dst))
2205 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2208 cli_shutdown(cli_dst);
2214 * Migrate Printer-Settings from a src server to the dst server
2215 * (for this to work, printers and drivers already have to be migrated earlier)
2217 * All parameters are provided by the run_rpc_command function, except for
2218 * argc, argv which are passed through.
2220 * @param c A net_context structure
2221 * @param domain_sid The domain sid aquired from the remote server
2222 * @param cli A cli_state connected to the server.
2223 * @param mem_ctx Talloc context, destoyed on compleation of the function.
2224 * @param argc Standard main() style argc
2225 * @param argv Standard main() style argv. Initial components are already
2228 * @return Normal NTSTATUS return.
2231 NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
2232 const DOM_SID *domain_sid,
2233 const char *domain_name,
2234 struct cli_state *cli,
2235 struct rpc_pipe_client *pipe_hnd,
2236 TALLOC_CTX *mem_ctx,
2241 /* FIXME: Here the nightmare begins */
2244 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
2245 uint32 i = 0, p = 0, j = 0;
2246 uint32 num_printers, val_needed, data_needed;
2248 char *printername, *sharename;
2249 struct rpc_pipe_client *pipe_hnd_dst = NULL;
2250 POLICY_HND hnd_src, hnd_dst;
2251 PRINTER_INFO_CTR ctr_enum;
2252 union spoolss_PrinterInfo info_dst_publish, info_dst;
2253 REGVAL_CTR *reg_ctr;
2254 struct cli_state *cli_dst = NULL;
2255 char *devicename = NULL, *unc_name = NULL, *url = NULL;
2256 const char *longname;
2258 uint16 *keylist = NULL, *curkey;
2260 ZERO_STRUCT(ctr_enum);
2262 ZERO_STRUCT(info_dst_publish);
2264 DEBUG(3,("copying printer settings\n"));
2266 /* connect destination PI_SPOOLSS */
2267 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
2269 if (!NT_STATUS_IS_OK(nt_status))
2272 /* enum src printers */
2273 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) {
2274 nt_status = NT_STATUS_UNSUCCESSFUL;
2278 if (!num_printers) {
2279 printf ("no printers found on server.\n");
2280 nt_status = NT_STATUS_OK;
2285 /* needed for dns-strings in regkeys */
2286 longname = get_mydnsfullname();
2288 nt_status = NT_STATUS_UNSUCCESSFUL;
2292 /* do something for all printers */
2293 for (i = 0; i < num_printers; i++) {
2294 /* do some initialization */
2295 rpcstr_pull_talloc(mem_ctx,
2297 ctr_enum.printers_2[i].printername.buffer,
2300 rpcstr_pull_talloc(mem_ctx,
2302 ctr_enum.printers_2[i].sharename.buffer,
2305 if (!printername || !sharename) {
2306 nt_status = NT_STATUS_UNSUCCESSFUL;
2309 /* we can reset NT_STATUS here because we do not
2310 get any real NT_STATUS-codes anymore from now on */
2311 nt_status = NT_STATUS_UNSUCCESSFUL;
2313 d_printf("migrating printer settings for: [%s] / [%s]\n",
2314 printername, sharename);
2317 /* open src printer handle */
2318 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
2319 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
2322 /* open dst printer handle */
2323 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
2324 PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst))
2327 /* check for existing dst printer */
2328 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst,
2332 #if 0 /* FIXME GD */
2334 /* STEP 1: COPY DEVICE-MODE and other
2335 PRINTER_INFO_2-attributes
2338 info_dst.info2 = &ctr_enum.printers_2[i];
2340 /* why is the port always disconnected when the printer
2341 is correctly installed (incl. driver ???) */
2342 info_dst.info2.portname = SAMBA_PRINTER_PORT_NAME;
2344 /* check if printer is published */
2345 if (ctr_enum.printers_2[i].attributes & PRINTER_ATTRIBUTE_PUBLISHED) {
2347 /* check for existing dst printer */
2348 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 7, &info_dst_publish))
2351 info_dst_publish.info7.action = DSPRINT_PUBLISH;
2353 /* ignore false from setprinter due to WERR_IO_PENDING */
2354 net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 7, &info_dst_publish);
2356 DEBUG(3,("republished printer\n"));
2359 if (ctr_enum.printers_2[i].devmode != NULL) {
2361 /* copy devmode (info level 2) */
2362 info_dst.info2.devmode = (DEVICEMODE *)
2363 TALLOC_MEMDUP(mem_ctx,
2364 ctr_enum.printers_2[i].devmode,
2365 sizeof(DEVICEMODE));
2367 /* do not copy security descriptor (we have another
2368 * command for that) */
2369 info_dst.info2.secdesc = NULL;
2372 if (asprintf(&devicename, "\\\\%s\\%s", longname,
2374 nt_status = NT_STATUS_NO_MEMORY;
2378 init_unistr(&ctr_dst.printers_2->devmode->devicename,
2381 if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst,
2385 DEBUGADD(1,("\tSetPrinter of DEVICEMODE succeeded\n"));
2388 /* STEP 2: COPY REGISTRY VALUES */
2390 /* please keep in mind that samba parse_spools gives horribly
2391 crippled results when used to rpccli_spoolss_enumprinterdataex
2392 a win2k3-server. (Bugzilla #1851)
2393 FIXME: IIRC I've seen it too on a win2k-server
2396 /* enumerate data on src handle */
2397 result = rpccli_spoolss_enumprinterdata(pipe_hnd, mem_ctx, &hnd_src, p, 0, 0,
2398 &val_needed, &data_needed, NULL);
2400 /* loop for all printerdata of "PrinterDriverData" */
2401 while (W_ERROR_IS_OK(result)) {
2403 REGISTRY_VALUE value;
2405 result = rpccli_spoolss_enumprinterdata(
2406 pipe_hnd, mem_ctx, &hnd_src, p++, val_needed,
2407 data_needed, 0, 0, &value);
2409 /* loop for all reg_keys */
2410 if (W_ERROR_IS_OK(result)) {
2414 display_reg_value(SPOOL_PRINTERDATA_KEY, value);
2417 if (!net_spoolss_setprinterdata(pipe_hnd_dst, mem_ctx,
2421 DEBUGADD(1,("\tSetPrinterData of [%s] succeeded\n",
2426 /* STEP 3: COPY SUBKEY VALUES */
2428 /* here we need to enum all printer_keys and then work
2429 on the result with enum_printer_key_ex. nt4 does not
2430 respond to enumprinterkey, win2k does, so continue
2431 in case of an error */
2433 if (!net_spoolss_enumprinterkey(pipe_hnd, mem_ctx, &hnd_src, "", &keylist)) {
2434 printf("got no key-data\n");
2439 /* work on a list of printer keys
2440 each key has to be enumerated to get all required
2441 information. information is then set via setprinterdataex-calls */
2443 if (keylist == NULL)
2447 while (*curkey != 0) {
2449 rpcstr_pull_talloc(mem_ctx,
2455 return NT_STATUS_NO_MEMORY;
2458 curkey += strlen(subkey) + 1;
2460 if ( !(reg_ctr = TALLOC_ZERO_P( mem_ctx, REGVAL_CTR )) )
2461 return NT_STATUS_NO_MEMORY;
2463 /* enumerate all src subkeys */
2464 if (!net_spoolss_enumprinterdataex(pipe_hnd, mem_ctx, 0,
2469 for (j=0; j < reg_ctr->num_values; j++) {
2471 REGISTRY_VALUE value;
2474 /* although samba replies with sane data in most cases we
2475 should try to avoid writing wrong registry data */
2477 if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_PORTNAME) ||
2478 strequal(reg_ctr->values[j]->valuename, SPOOL_REG_UNCNAME) ||
2479 strequal(reg_ctr->values[j]->valuename, SPOOL_REG_URL) ||
2480 strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SHORTSERVERNAME) ||
2481 strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SERVERNAME)) {
2483 if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_PORTNAME)) {
2485 /* although windows uses a multi-sz, we use a sz */
2486 init_unistr2(&data, SAMBA_PRINTER_PORT_NAME, UNI_STR_TERMINATE);
2487 fstrcpy(value.valuename, SPOOL_REG_PORTNAME);
2490 if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_UNCNAME)) {
2492 if (asprintf(&unc_name, "\\\\%s\\%s", longname, sharename) < 0) {
2493 nt_status = NT_STATUS_NO_MEMORY;
2496 init_unistr2(&data, unc_name, UNI_STR_TERMINATE);
2497 fstrcpy(value.valuename, SPOOL_REG_UNCNAME);
2500 if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_URL)) {
2505 /* FIXME: should we really do that ??? */
2506 if (asprintf(&url, "http://%s:631/printers/%s", longname, sharename) < 0) {
2507 nt_status = NT_STATUS_NO_MEMORY;
2510 init_unistr2(&data, url, UNI_STR_TERMINATE);
2511 fstrcpy(value.valuename, SPOOL_REG_URL);
2515 if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SERVERNAME)) {
2517 init_unistr2(&data, longname, UNI_STR_TERMINATE);
2518 fstrcpy(value.valuename, SPOOL_REG_SERVERNAME);
2521 if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SHORTSERVERNAME)) {
2523 init_unistr2(&data, global_myname(), UNI_STR_TERMINATE);
2524 fstrcpy(value.valuename, SPOOL_REG_SHORTSERVERNAME);
2527 value.type = REG_SZ;
2528 value.size = data.uni_str_len * 2;
2530 value.data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, data.buffer, value.size);
2532 value.data_p = NULL;
2536 display_reg_value(subkey, value);
2538 /* here we have to set all subkeys on the dst server */
2539 if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst,
2546 display_reg_value(subkey, *(reg_ctr->values[j]));
2548 /* here we have to set all subkeys on the dst server */
2549 if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst,
2550 subkey, reg_ctr->values[j]))
2555 DEBUGADD(1,("\tSetPrinterDataEx of key [%s\\%s] succeeded\n",
2556 subkey, reg_ctr->values[j]->valuename));
2560 TALLOC_FREE( reg_ctr );
2565 /* close printer handles here */
2566 if (is_valid_policy_hnd(&hnd_src)) {
2567 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2570 if (is_valid_policy_hnd(&hnd_dst)) {
2571 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2576 nt_status = NT_STATUS_OK;
2579 SAFE_FREE(devicename);
2581 SAFE_FREE(unc_name);
2583 if (is_valid_policy_hnd(&hnd_src))
2584 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2586 if (is_valid_policy_hnd(&hnd_dst))
2587 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2590 cli_shutdown(cli_dst);