2 Samba Unix/Linux SMB client library
3 Distributed SMB/CIFS Server Management Utility
4 Copyright (C) 2004,2009 Guenther Deschner (gd@samba.org)
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "utils/net.h"
22 /* support itanium as well */
23 static const struct print_architecture_table_node archi_table
[]= {
25 {"Windows 4.0", "WIN40", 0 },
26 {"Windows NT x86", "W32X86", 2 },
27 {"Windows NT x86", "W32X86", 3 },
28 {"Windows NT R4000", "W32MIPS", 2 },
29 {"Windows NT Alpha_AXP", "W32ALPHA", 2 },
30 {"Windows NT PowerPC", "W32PPC", 2 },
31 {"Windows IA64", "IA64", 3 },
32 {"Windows x64", "x64", 3 },
38 * This display-printdriver-functions was borrowed from rpcclient/cmd_spoolss.c.
39 * It is here for debugging purpose and should be removed later on.
42 /****************************************************************************
43 Printer info level 3 display function.
44 ****************************************************************************/
46 static void display_print_driver3(struct spoolss_DriverInfo3
*r
)
54 printf(_("Printer Driver Info 3:\n"));
55 printf(_("\tVersion: [%x]\n"), r
->version
);
56 printf(_("\tDriver Name: [%s]\n"), r
->driver_name
);
57 printf(_("\tArchitecture: [%s]\n"), r
->architecture
);
58 printf(_("\tDriver Path: [%s]\n"), r
->driver_path
);
59 printf(_("\tDatafile: [%s]\n"), r
->data_file
);
60 printf(_("\tConfigfile: [%s]\n\n"), r
->config_file
);
61 printf(_("\tHelpfile: [%s]\n\n"), r
->help_file
);
63 for (i
=0; r
->dependent_files
[i
] != NULL
; i
++) {
64 printf(_("\tDependentfiles: [%s]\n"), r
->dependent_files
[i
]);
69 printf(_("\tMonitorname: [%s]\n"), r
->monitor_name
);
70 printf(_("\tDefaultdatatype: [%s]\n\n"), r
->default_datatype
);
73 static void display_reg_value(const char *subkey
, struct regval_blob value
)
80 d_printf(_("\t[%s:%s]: REG_DWORD: 0x%08x\n"), subkey
,
81 value
.valuename
, *((uint32_t *) value
.data_p
));
85 blob
= data_blob_const(value
.data_p
, value
.size
);
86 pull_reg_sz(talloc_tos(), &blob
, &text
);
90 d_printf(_("\t[%s:%s]: REG_SZ: %s\n"), subkey
, value
.valuename
,
95 d_printf(_("\t[%s:%s]: REG_BINARY: unknown length value not "
97 subkey
, value
.valuename
);
103 blob
= data_blob_const(value
.data_p
, value
.size
);
105 if (!pull_reg_multi_sz(NULL
, &blob
, &values
)) {
106 d_printf("pull_reg_multi_sz failed\n");
110 printf("%s: REG_MULTI_SZ: \n", value
.valuename
);
111 for (i
=0; values
[i
] != NULL
; i
++) {
112 d_printf("%s\n", values
[i
]);
119 d_printf(_("\t%s: unknown type %d\n"), value
.valuename
,
126 * Copies ACLs, DOS-attributes and timestamps from one
127 * file or directory from one connected share to another connected share
129 * @param c A net_context structure
130 * @param mem_ctx A talloc-context
131 * @param cli_share_src A connected cli_state
132 * @param cli_share_dst A connected cli_state
133 * @param src_file The source file-name
134 * @param dst_file The destination file-name
135 * @param copy_acls Whether to copy acls
136 * @param copy_attrs Whether to copy DOS attributes
137 * @param copy_timestamps Whether to preserve timestamps
138 * @param is_file Whether this file is a file or a dir
140 * @return Normal NTSTATUS return.
143 NTSTATUS
net_copy_fileattr(struct net_context
*c
,
145 struct cli_state
*cli_share_src
,
146 struct cli_state
*cli_share_dst
,
147 const char *src_name
, const char *dst_name
,
148 bool copy_acls
, bool copy_attrs
,
149 bool copy_timestamps
, bool is_file
)
151 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
152 uint16_t fnum_src
= 0;
153 uint16_t fnum_dst
= 0;
156 time_t f_atime
, f_ctime
, f_mtime
;
159 if (!copy_timestamps
&& !copy_acls
&& !copy_attrs
)
162 /* open file/dir on the originating server */
164 DEBUGADD(3,("opening %s %s on originating server\n",
165 is_file
?"file":"dir", src_name
));
167 if (!NT_STATUS_IS_OK(cli_ntcreate(cli_share_src
, src_name
, 0, READ_CONTROL_ACCESS
, 0,
168 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0x0, 0x0, &fnum_src
))) {
169 DEBUGADD(0,("cannot open %s %s on originating server %s\n",
170 is_file
?"file":"dir", src_name
, cli_errstr(cli_share_src
)));
171 nt_status
= cli_nt_error(cli_share_src
);
178 /* get the security descriptor */
179 sd
= cli_query_secdesc(cli_share_src
, fnum_src
, mem_ctx
);
181 DEBUG(0,("failed to get security descriptor: %s\n",
182 cli_errstr(cli_share_src
)));
183 nt_status
= cli_nt_error(cli_share_src
);
187 if (c
->opt_verbose
&& DEBUGLEVEL
>= 3)
188 display_sec_desc(sd
);
192 if (copy_attrs
|| copy_timestamps
) {
194 /* get file attributes */
195 if (!NT_STATUS_IS_OK(cli_getattrE(cli_share_src
, fnum_src
, &attr
, NULL
,
196 &f_ctime
, &f_atime
, &f_mtime
))) {
197 DEBUG(0,("failed to get file-attrs: %s\n",
198 cli_errstr(cli_share_src
)));
199 nt_status
= cli_nt_error(cli_share_src
);
205 /* open the file/dir on the destination server */
207 if (!NT_STATUS_IS_OK(cli_ntcreate(cli_share_dst
, dst_name
, 0, WRITE_DAC_ACCESS
| WRITE_OWNER_ACCESS
, 0,
208 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0x0, 0x0, &fnum_dst
))) {
209 DEBUG(0,("failed to open %s on the destination server: %s: %s\n",
210 is_file
?"file":"dir", dst_name
, cli_errstr(cli_share_dst
)));
211 nt_status
= cli_nt_error(cli_share_dst
);
215 if (copy_timestamps
) {
218 if (!NT_STATUS_IS_OK(cli_setattrE(cli_share_dst
, fnum_dst
, f_ctime
, f_atime
, f_mtime
))) {
219 DEBUG(0,("failed to set file-attrs (timestamps): %s\n",
220 cli_errstr(cli_share_dst
)));
221 nt_status
= cli_nt_error(cli_share_dst
);
229 if (!cli_set_secdesc(cli_share_dst
, fnum_dst
, sd
)) {
230 DEBUG(0,("could not set secdesc on %s: %s\n",
231 dst_name
, cli_errstr(cli_share_dst
)));
232 nt_status
= cli_nt_error(cli_share_dst
);
240 if (!NT_STATUS_IS_OK(cli_setatr(cli_share_dst
, dst_name
, attr
, 0))) {
241 DEBUG(0,("failed to set file-attrs: %s\n",
242 cli_errstr(cli_share_dst
)));
243 nt_status
= cli_nt_error(cli_share_dst
);
251 if (!NT_STATUS_IS_OK(cli_close(cli_share_src
, fnum_src
))) {
253 _("could not close %s on originating server: %s\n"),
254 is_file
?"file":"dir", cli_errstr(cli_share_src
));
255 nt_status
= cli_nt_error(cli_share_src
);
259 if (!NT_STATUS_IS_OK(cli_close(cli_share_dst
, fnum_dst
))) {
261 _("could not close %s on destination server: %s\n"),
262 is_file
?"file":"dir", cli_errstr(cli_share_dst
));
263 nt_status
= cli_nt_error(cli_share_dst
);
268 nt_status
= NT_STATUS_OK
;
274 cli_close(cli_share_src
, fnum_src
);
277 cli_close(cli_share_dst
, fnum_dst
);
283 * Copy a file or directory from a connected share to another connected share
285 * @param c A net_context structure
286 * @param mem_ctx A talloc-context
287 * @param cli_share_src A connected cli_state
288 * @param cli_share_dst A connected cli_state
289 * @param src_file The source file-name
290 * @param dst_file The destination file-name
291 * @param copy_acls Whether to copy acls
292 * @param copy_attrs Whether to copy DOS attributes
293 * @param copy_timestamps Whether to preserve timestamps
294 * @param is_file Whether this file is a file or a dir
296 * @return Normal NTSTATUS return.
299 NTSTATUS
net_copy_file(struct net_context
*c
,
301 struct cli_state
*cli_share_src
,
302 struct cli_state
*cli_share_dst
,
303 const char *src_name
, const char *dst_name
,
304 bool copy_acls
, bool copy_attrs
,
305 bool copy_timestamps
, bool is_file
)
307 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
308 uint16_t fnum_src
= 0;
309 uint16_t fnum_dst
= 0;
310 static int io_bufsize
= 64512;
311 int read_size
= io_bufsize
;
316 if (!src_name
|| !dst_name
)
319 if (cli_share_src
== NULL
|| cli_share_dst
== NULL
)
322 /* open on the originating server */
323 DEBUGADD(3,("opening %s %s on originating server\n",
324 is_file
? "file":"dir", src_name
));
326 nt_status
= cli_open(cli_share_src
, src_name
, O_RDONLY
, DENY_NONE
, &fnum_src
);
328 nt_status
= cli_ntcreate(cli_share_src
, src_name
, 0, READ_CONTROL_ACCESS
, 0,
329 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0x0, 0x0, &fnum_src
);
331 if (!NT_STATUS_IS_OK(nt_status
)) {
332 DEBUGADD(0,("cannot open %s %s on originating server %s\n",
333 is_file
? "file":"dir",
334 src_name
, cli_errstr(cli_share_src
)));
341 /* open file on the destination server */
342 DEBUGADD(3,("opening file %s on destination server\n", dst_name
));
343 nt_status
= cli_open(cli_share_dst
, dst_name
,
344 O_RDWR
|O_CREAT
|O_TRUNC
, DENY_NONE
, &fnum_dst
);
346 if (!NT_STATUS_IS_OK(nt_status
)) {
347 DEBUGADD(1,("cannot create file %s on destination server: %s\n",
348 dst_name
, cli_errstr(cli_share_dst
)));
352 /* allocate memory */
353 if (!(data
= (char *)SMB_MALLOC(read_size
))) {
354 d_fprintf(stderr
, _("malloc fail for size %d\n"),
356 nt_status
= NT_STATUS_NO_MEMORY
;
363 if (c
->opt_verbose
) {
365 d_printf(_("copying [\\\\%s\\%s%s] => [\\\\%s\\%s%s] "
366 "%s ACLs and %s DOS Attributes %s\n"),
367 cli_share_src
->desthost
, cli_share_src
->share
, src_name
,
368 cli_share_dst
->desthost
, cli_share_dst
->share
, dst_name
,
369 copy_acls
? _("with") : _("without"),
370 copy_attrs
? _("with") : _("without"),
371 copy_timestamps
? _("(preserving timestamps)") : "" );
379 n
= cli_read(cli_share_src
, fnum_src
, data
, nread
,
385 ret
= cli_write(cli_share_dst
, fnum_dst
, 0, data
,
389 d_fprintf(stderr
, _("Error writing file: %s\n"),
390 cli_errstr(cli_share_dst
));
391 nt_status
= cli_nt_error(cli_share_dst
);
399 if (!is_file
&& !NT_STATUS_IS_OK(cli_chkpath(cli_share_dst
, dst_name
))) {
402 DEBUGADD(3,("creating dir %s on the destination server\n",
405 if (!NT_STATUS_IS_OK(cli_mkdir(cli_share_dst
, dst_name
))) {
406 DEBUG(0,("cannot create directory %s: %s\n",
407 dst_name
, cli_errstr(cli_share_dst
)));
408 nt_status
= NT_STATUS_NO_SUCH_FILE
;
411 if (!NT_STATUS_IS_OK(cli_chkpath(cli_share_dst
, dst_name
))) {
413 _("cannot check for directory %s: %s\n"),
414 dst_name
, cli_errstr(cli_share_dst
));
421 if (!NT_STATUS_IS_OK(cli_close(cli_share_src
, fnum_src
))) {
423 _("could not close file on originating server: %s\n"),
424 cli_errstr(cli_share_src
));
425 nt_status
= cli_nt_error(cli_share_src
);
429 if (is_file
&& !NT_STATUS_IS_OK(cli_close(cli_share_dst
, fnum_dst
))) {
431 _("could not close file on destination server: %s\n"),
432 cli_errstr(cli_share_dst
));
433 nt_status
= cli_nt_error(cli_share_dst
);
437 /* possibly we have to copy some file-attributes / acls / sd */
438 nt_status
= net_copy_fileattr(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
439 src_name
, dst_name
, copy_acls
,
440 copy_attrs
, copy_timestamps
, is_file
);
441 if (!NT_STATUS_IS_OK(nt_status
))
445 nt_status
= NT_STATUS_OK
;
451 cli_close(cli_share_src
, fnum_src
);
454 cli_close(cli_share_dst
, fnum_dst
);
462 * Copy a driverfile from on connected share to another connected share
463 * This silently assumes that a driver-file is picked up from
465 * \\src_server\print$\{arch}\{version}\file
469 * \\dst_server\print$\{arch}\file
471 * to be added via setdriver-calls later.
472 * @param c A net_context structure
473 * @param mem_ctx A talloc-context
474 * @param cli_share_src A cli_state connected to source print$-share
475 * @param cli_share_dst A cli_state connected to destination print$-share
476 * @param file The file-name to be copied
477 * @param short_archi The name of the driver-architecture (short form)
479 * @return Normal NTSTATUS return.
482 static NTSTATUS
net_copy_driverfile(struct net_context
*c
,
484 struct cli_state
*cli_share_src
,
485 struct cli_state
*cli_share_dst
,
486 const char *file
, const char *short_archi
) {
488 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
500 /* scroll through the file until we have the part
501 beyond archi_table.short_archi */
503 while (next_token_talloc(mem_ctx
, &p
, &tok
, "\\")) {
504 if (strequal(tok
, short_archi
)) {
505 next_token_talloc(mem_ctx
, &p
, &version
, "\\");
506 next_token_talloc(mem_ctx
, &p
, &filename
, "\\");
510 /* build source file name */
511 if (asprintf(&src_name
, "\\%s\\%s\\%s", short_archi
, version
, filename
) < 0 )
512 return NT_STATUS_NO_MEMORY
;
515 /* create destination file name */
516 if (asprintf(&dst_name
, "\\%s\\%s", short_archi
, filename
) < 0 )
517 return NT_STATUS_NO_MEMORY
;
520 /* finally copy the file */
521 nt_status
= net_copy_file(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
522 src_name
, dst_name
, false, false, false, true);
523 if (!NT_STATUS_IS_OK(nt_status
))
526 nt_status
= NT_STATUS_OK
;
536 * Check for existing Architecture directory on a given server
538 * @param cli_share A cli_state connected to a print$-share
539 * @param short_archi The Architecture for the print-driver
541 * @return Normal NTSTATUS return.
544 static NTSTATUS
check_arch_dir(struct cli_state
*cli_share
, const char *short_archi
)
547 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
550 if (asprintf(&dir
, "\\%s", short_archi
) < 0) {
551 return NT_STATUS_NO_MEMORY
;
554 DEBUG(10,("creating print-driver dir for architecture: %s\n",
557 if (!NT_STATUS_IS_OK(cli_mkdir(cli_share
, dir
))) {
558 DEBUG(1,("cannot create directory %s: %s\n",
559 dir
, cli_errstr(cli_share
)));
560 nt_status
= NT_STATUS_NO_SUCH_FILE
;
563 if (!NT_STATUS_IS_OK(cli_chkpath(cli_share
, dir
))) {
564 d_fprintf(stderr
, _("cannot check %s: %s\n"),
565 dir
, cli_errstr(cli_share
));
569 nt_status
= NT_STATUS_OK
;
577 * Copy a print-driver (level 3) from one connected print$-share to another
578 * connected print$-share
580 * @param c A net_context structure
581 * @param mem_ctx A talloc-context
582 * @param cli_share_src A cli_state connected to a print$-share
583 * @param cli_share_dst A cli_state connected to a print$-share
584 * @param short_archi The Architecture for the print-driver
585 * @param i1 The DRIVER_INFO_3-struct
587 * @return Normal NTSTATUS return.
590 static NTSTATUS
copy_print_driver_3(struct net_context
*c
,
592 struct cli_state
*cli_share_src
,
593 struct cli_state
*cli_share_dst
,
594 const char *short_archi
,
595 struct spoolss_DriverInfo3
*r
)
597 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
605 d_printf(_("copying driver: [%s], for architecture: [%s], "
607 r
->driver_name
, short_archi
, r
->version
);
609 nt_status
= net_copy_driverfile(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
610 r
->driver_path
, short_archi
);
611 if (!NT_STATUS_IS_OK(nt_status
))
614 nt_status
= net_copy_driverfile(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
615 r
->data_file
, short_archi
);
616 if (!NT_STATUS_IS_OK(nt_status
))
619 nt_status
= net_copy_driverfile(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
620 r
->config_file
, short_archi
);
621 if (!NT_STATUS_IS_OK(nt_status
))
624 nt_status
= net_copy_driverfile(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
625 r
->help_file
, short_archi
);
626 if (!NT_STATUS_IS_OK(nt_status
))
629 for (i
=0; r
->dependent_files
[i
] != NULL
; i
++) {
631 nt_status
= net_copy_driverfile(c
, mem_ctx
,
632 cli_share_src
, cli_share_dst
,
633 r
->dependent_files
[i
], short_archi
);
634 if (!NT_STATUS_IS_OK(nt_status
)) {
643 * net_spoolss-functions
644 * =====================
646 * the net_spoolss-functions aim to simplify spoolss-client-functions
647 * required during the migration-process wrt buffer-sizes, returned
650 * this greatly reduces the complexitiy of the migrate-functions.
654 static bool net_spoolss_enum_printers(struct rpc_pipe_client
*pipe_hnd
,
659 uint32_t *num_printers
,
660 union spoolss_PrinterInfo
**info
)
666 result
= rpccli_spoolss_enumprinters(pipe_hnd
, mem_ctx
,
673 if (!W_ERROR_IS_OK(result
)) {
674 printf(_("cannot enum printers: %s\n"), win_errstr(result
));
681 static bool net_spoolss_open_printer_ex(struct rpc_pipe_client
*pipe_hnd
,
683 const char *printername
,
684 uint32_t access_required
,
685 const char *username
,
686 struct policy_handle
*hnd
)
689 fstring printername2
;
691 fstrcpy(printername2
, pipe_hnd
->srv_name_slash
);
692 fstrcat(printername2
, "\\");
693 fstrcat(printername2
, printername
);
695 DEBUG(10,("connecting to: %s as %s for %s and access: %x\n",
696 pipe_hnd
->srv_name_slash
, username
, printername2
, access_required
));
699 result
= rpccli_spoolss_openprinter_ex(pipe_hnd
, mem_ctx
,
704 /* be more verbose */
705 if (W_ERROR_V(result
) == W_ERROR_V(WERR_ACCESS_DENIED
)) {
707 _("no access to printer [%s] on [%s] for user [%s] "
709 printername2
, pipe_hnd
->srv_name_slash
, username
);
713 if (!W_ERROR_IS_OK(result
)) {
714 d_fprintf(stderr
,_("cannot open printer %s on server %s: %s\n"),
715 printername2
, pipe_hnd
->srv_name_slash
, win_errstr(result
));
719 DEBUG(2,("got printer handle for printer: %s, server: %s\n",
720 printername2
, pipe_hnd
->srv_name_slash
));
725 static bool net_spoolss_getprinter(struct rpc_pipe_client
*pipe_hnd
,
727 struct policy_handle
*hnd
,
729 union spoolss_PrinterInfo
*info
)
733 /* getprinter call */
734 result
= rpccli_spoolss_getprinter(pipe_hnd
, mem_ctx
,
739 if (!W_ERROR_IS_OK(result
)) {
740 printf(_("cannot get printer-info: %s\n"), win_errstr(result
));
747 static bool net_spoolss_setprinter(struct rpc_pipe_client
*pipe_hnd
,
749 struct policy_handle
*hnd
,
751 union spoolss_PrinterInfo
*info
)
755 struct spoolss_SetPrinterInfoCtr info_ctr
;
756 struct spoolss_DevmodeContainer devmode_ctr
;
757 struct sec_desc_buf secdesc_ctr
;
759 ZERO_STRUCT(devmode_ctr
);
760 ZERO_STRUCT(secdesc_ctr
);
762 /* setprinter call */
764 info_ctr
.level
= level
;
767 info_ctr
.info
.info0
= (struct spoolss_SetPrinterInfo0
*)
768 (void *)&info
->info0
;
771 info_ctr
.info
.info1
= (struct spoolss_SetPrinterInfo1
*)
772 (void *)&info
->info1
;
775 info_ctr
.info
.info2
= (struct spoolss_SetPrinterInfo2
*)
776 (void *)&info
->info2
;
779 info_ctr
.info
.info3
= (struct spoolss_SetPrinterInfo3
*)
780 (void *)&info
->info3
;
783 info_ctr
.info
.info4
= (struct spoolss_SetPrinterInfo4
*)
784 (void *)&info
->info4
;
787 info_ctr
.info
.info5
= (struct spoolss_SetPrinterInfo5
*)
788 (void *)&info
->info5
;
791 info_ctr
.info
.info6
= (struct spoolss_SetPrinterInfo6
*)
792 (void *)&info
->info6
;
795 info_ctr
.info
.info7
= (struct spoolss_SetPrinterInfo7
*)
796 (void *)&info
->info7
;
800 info_ctr
.info
.info8
= (struct spoolss_SetPrinterInfo8
*)
801 (void *)&info
->info8
;
804 info_ctr
.info
.info9
= (struct spoolss_SetPrinterInfo9
*)
805 (void *)&info
->info9
;
812 status
= rpccli_spoolss_SetPrinter(pipe_hnd
, mem_ctx
,
820 if (!W_ERROR_IS_OK(result
)) {
821 printf(_("cannot set printer-info: %s\n"), win_errstr(result
));
829 static bool net_spoolss_setprinterdata(struct rpc_pipe_client
*pipe_hnd
,
831 struct policy_handle
*hnd
,
832 const char *value_name
,
833 enum winreg_Type type
,
834 union spoolss_PrinterData data
)
839 /* setprinterdata call */
840 status
= rpccli_spoolss_SetPrinterData(pipe_hnd
, mem_ctx
,
845 0, /* autocalculated */
848 if (!W_ERROR_IS_OK(result
)) {
849 printf (_("unable to set printerdata: %s\n"),
858 static bool net_spoolss_enumprinterkey(struct rpc_pipe_client
*pipe_hnd
,
860 struct policy_handle
*hnd
,
862 const char ***keylist
)
866 /* enumprinterkey call */
867 result
= rpccli_spoolss_enumprinterkey(pipe_hnd
, mem_ctx
, hnd
, keyname
, keylist
, 0);
869 if (!W_ERROR_IS_OK(result
)) {
870 printf(_("enumprinterkey failed: %s\n"), win_errstr(result
));
877 static bool net_spoolss_enumprinterdataex(struct rpc_pipe_client
*pipe_hnd
,
880 struct policy_handle
*hnd
,
883 struct spoolss_PrinterEnumValues
**info
)
887 /* enumprinterdataex call */
888 result
= rpccli_spoolss_enumprinterdataex(pipe_hnd
, mem_ctx
,
895 if (!W_ERROR_IS_OK(result
)) {
896 printf(_("enumprinterdataex failed: %s\n"), win_errstr(result
));
904 static bool net_spoolss_setprinterdataex(struct rpc_pipe_client
*pipe_hnd
,
906 struct policy_handle
*hnd
,
908 struct regval_blob
*value
)
913 /* setprinterdataex call */
914 status
= rpccli_spoolss_SetPrinterDataEx(pipe_hnd
, mem_ctx
,
923 if (!W_ERROR_IS_OK(result
)) {
924 printf(_("could not set printerdataex: %s\n"),
932 static bool net_spoolss_enumforms(struct rpc_pipe_client
*pipe_hnd
,
934 struct policy_handle
*hnd
,
937 union spoolss_FormInfo
**forms
)
942 result
= rpccli_spoolss_enumforms(pipe_hnd
, mem_ctx
,
948 if (!W_ERROR_IS_OK(result
)) {
949 printf(_("could not enum forms: %s\n"), win_errstr(result
));
956 static bool net_spoolss_enumprinterdrivers (struct rpc_pipe_client
*pipe_hnd
,
958 uint32_t level
, const char *env
,
960 union spoolss_DriverInfo
**info
)
964 /* enumprinterdrivers call */
965 result
= rpccli_spoolss_enumprinterdrivers(pipe_hnd
, mem_ctx
,
966 pipe_hnd
->srv_name_slash
,
972 if (!W_ERROR_IS_OK(result
)) {
973 printf(_("cannot enum drivers: %s\n"), win_errstr(result
));
980 static bool net_spoolss_getprinterdriver(struct rpc_pipe_client
*pipe_hnd
,
982 struct policy_handle
*hnd
, uint32_t level
,
983 const char *env
, int version
,
984 union spoolss_DriverInfo
*info
)
987 uint32_t server_major_version
;
988 uint32_t server_minor_version
;
990 /* getprinterdriver call */
991 result
= rpccli_spoolss_getprinterdriver2(pipe_hnd
, mem_ctx
,
999 &server_major_version
,
1000 &server_minor_version
);
1001 if (!W_ERROR_IS_OK(result
)) {
1002 DEBUG(1,("cannot get driver (for architecture: %s): %s\n",
1003 env
, win_errstr(result
)));
1004 if (W_ERROR_V(result
) != W_ERROR_V(WERR_UNKNOWN_PRINTER_DRIVER
) &&
1005 W_ERROR_V(result
) != W_ERROR_V(WERR_INVALID_ENVIRONMENT
)) {
1006 printf(_("cannot get driver: %s\n"),
1007 win_errstr(result
));
1016 static bool net_spoolss_addprinterdriver(struct rpc_pipe_client
*pipe_hnd
,
1017 TALLOC_CTX
*mem_ctx
, uint32_t level
,
1018 union spoolss_DriverInfo
*info
)
1022 struct spoolss_AddDriverInfoCtr info_ctr
;
1024 info_ctr
.level
= level
;
1028 info_ctr
.info
.info2
= (struct spoolss_AddDriverInfo2
*)
1029 (void *)&info
->info2
;
1032 info_ctr
.info
.info3
= (struct spoolss_AddDriverInfo3
*)
1033 (void *)&info
->info3
;
1036 printf(_("unsupported info level: %d\n"), level
);
1040 /* addprinterdriver call */
1041 status
= rpccli_spoolss_AddPrinterDriver(pipe_hnd
, mem_ctx
,
1042 pipe_hnd
->srv_name_slash
,
1045 /* be more verbose */
1046 if (W_ERROR_V(result
) == W_ERROR_V(WERR_ACCESS_DENIED
)) {
1047 printf(_("You are not allowed to add drivers\n"));
1050 if (!W_ERROR_IS_OK(result
)) {
1051 printf(_("cannot add driver: %s\n"), win_errstr(result
));
1059 * abstraction function to get uint32_t num_printers and PRINTER_INFO_CTR ctr
1060 * for a single printer or for all printers depending on argc/argv
1063 static bool get_printer_info(struct rpc_pipe_client
*pipe_hnd
,
1064 TALLOC_CTX
*mem_ctx
,
1068 uint32_t *num_printers
,
1069 union spoolss_PrinterInfo
**info_p
)
1071 struct policy_handle hnd
;
1073 /* no arguments given, enumerate all printers */
1076 if (!net_spoolss_enum_printers(pipe_hnd
, mem_ctx
, NULL
,
1077 PRINTER_ENUM_LOCAL
|PRINTER_ENUM_SHARED
,
1078 level
, num_printers
, info_p
))
1084 /* argument given, get a single printer by name */
1085 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, argv
[0],
1086 MAXIMUM_ALLOWED_ACCESS
,
1087 pipe_hnd
->auth
->user_name
,
1091 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd
, level
, *info_p
)) {
1092 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd
, NULL
);
1096 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd
, NULL
);
1101 DEBUG(3,("got %d printers\n", *num_printers
));
1108 * List print-queues (including local printers that are not shared)
1110 * All parameters are provided by the run_rpc_command function, except for
1111 * argc, argv which are passed through.
1113 * @param c A net_context structure
1114 * @param domain_sid The domain sid aquired from the remote server
1115 * @param cli A cli_state connected to the server.
1116 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1117 * @param argc Standard main() style argc
1118 * @param argv Standard main() style argv. Initial components are already
1121 * @return Normal NTSTATUS return.
1124 NTSTATUS
rpc_printer_list_internals(struct net_context
*c
,
1125 const DOM_SID
*domain_sid
,
1126 const char *domain_name
,
1127 struct cli_state
*cli
,
1128 struct rpc_pipe_client
*pipe_hnd
,
1129 TALLOC_CTX
*mem_ctx
,
1133 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1134 uint32_t i
, num_printers
;
1136 const char *printername
, *sharename
;
1137 union spoolss_PrinterInfo
*info
;
1139 printf("listing printers\n");
1141 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &info
))
1144 for (i
= 0; i
< num_printers
; i
++) {
1146 /* do some initialization */
1147 printername
= info
[i
].info2
.printername
;
1148 sharename
= info
[i
].info2
.sharename
;
1150 if (printername
&& sharename
) {
1151 d_printf(_("printer %d: %s, shared as: %s\n"),
1152 i
+1, printername
, sharename
);
1156 return NT_STATUS_OK
;
1160 * List printer-drivers from a server
1162 * All parameters are provided by the run_rpc_command function, except for
1163 * argc, argv which are passed through.
1165 * @param c A net_context structure
1166 * @param domain_sid The domain sid aquired from the remote server
1167 * @param cli A cli_state connected to the server.
1168 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1169 * @param argc Standard main() style argc
1170 * @param argv Standard main() style argv. Initial components are already
1173 * @return Normal NTSTATUS return.
1176 NTSTATUS
rpc_printer_driver_list_internals(struct net_context
*c
,
1177 const DOM_SID
*domain_sid
,
1178 const char *domain_name
,
1179 struct cli_state
*cli
,
1180 struct rpc_pipe_client
*pipe_hnd
,
1181 TALLOC_CTX
*mem_ctx
,
1185 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1188 union spoolss_DriverInfo
*info
;
1191 printf(_("listing printer-drivers\n"));
1193 for (i
=0; archi_table
[i
].long_archi
!=NULL
; i
++) {
1195 uint32_t num_drivers
;
1197 /* enum remote drivers */
1198 if (!net_spoolss_enumprinterdrivers(pipe_hnd
, mem_ctx
, level
,
1199 archi_table
[i
].long_archi
,
1200 &num_drivers
, &info
)) {
1201 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1205 if (num_drivers
== 0) {
1206 d_printf(_("no drivers found on server for "
1207 "architecture: [%s].\n"),
1208 archi_table
[i
].long_archi
);
1212 d_printf(_("got %d printer-drivers for architecture: [%s]\n"),
1213 num_drivers
, archi_table
[i
].long_archi
);
1216 /* do something for all drivers for architecture */
1217 for (d
= 0; d
< num_drivers
; d
++) {
1218 display_print_driver3(&info
[d
].info3
);
1222 nt_status
= NT_STATUS_OK
;
1230 * Publish print-queues with args-wrapper
1232 * @param cli A cli_state connected to the server.
1233 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1234 * @param argc Standard main() style argc
1235 * @param argv Standard main() style argv. Initial components are already
1239 * @return Normal NTSTATUS return.
1242 static NTSTATUS
rpc_printer_publish_internals_args(struct rpc_pipe_client
*pipe_hnd
,
1243 TALLOC_CTX
*mem_ctx
,
1248 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1249 uint32_t i
, num_printers
;
1251 const char *printername
, *sharename
;
1252 union spoolss_PrinterInfo
*info_enum
;
1253 union spoolss_PrinterInfo info
;
1254 struct spoolss_SetPrinterInfoCtr info_ctr
;
1255 struct spoolss_DevmodeContainer devmode_ctr
;
1256 struct sec_desc_buf secdesc_ctr
;
1257 struct policy_handle hnd
;
1259 const char *action_str
;
1261 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &info_enum
))
1264 for (i
= 0; i
< num_printers
; i
++) {
1266 /* do some initialization */
1267 printername
= info_enum
[i
].info2
.printername
;
1268 sharename
= info_enum
[i
].info2
.sharename
;
1269 if (!printername
|| !sharename
) {
1273 /* open printer handle */
1274 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1275 PRINTER_ALL_ACCESS
, pipe_hnd
->auth
->user_name
, &hnd
))
1278 /* check for existing dst printer */
1279 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd
, level
, &info
))
1282 /* check action and set string */
1284 case DSPRINT_PUBLISH
:
1285 action_str
= N_("published");
1287 case DSPRINT_UPDATE
:
1288 action_str
= N_("updated");
1290 case DSPRINT_UNPUBLISH
:
1291 action_str
= N_("unpublished");
1294 action_str
= N_("unknown action");
1295 printf(_("unkown action: %d\n"), action
);
1299 info
.info7
.action
= action
;
1301 info_ctr
.info
.info7
= (struct spoolss_SetPrinterInfo7
*)
1302 (void *)&info
.info7
;
1304 ZERO_STRUCT(devmode_ctr
);
1305 ZERO_STRUCT(secdesc_ctr
);
1307 nt_status
= rpccli_spoolss_SetPrinter(pipe_hnd
, mem_ctx
,
1315 if (!W_ERROR_IS_OK(result
) && (W_ERROR_V(result
) != W_ERROR_V(WERR_IO_PENDING
))) {
1316 printf(_("cannot set printer-info: %s\n"),
1317 win_errstr(result
));
1321 printf(_("successfully %s printer %s in Active Directory\n"),
1322 action_str
, sharename
);
1325 nt_status
= NT_STATUS_OK
;
1328 if (is_valid_policy_hnd(&hnd
))
1329 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd
, NULL
);
1334 NTSTATUS
rpc_printer_publish_publish_internals(struct net_context
*c
,
1335 const DOM_SID
*domain_sid
,
1336 const char *domain_name
,
1337 struct cli_state
*cli
,
1338 struct rpc_pipe_client
*pipe_hnd
,
1339 TALLOC_CTX
*mem_ctx
,
1343 return rpc_printer_publish_internals_args(pipe_hnd
, mem_ctx
, argc
, argv
, DSPRINT_PUBLISH
);
1346 NTSTATUS
rpc_printer_publish_unpublish_internals(struct net_context
*c
,
1347 const DOM_SID
*domain_sid
,
1348 const char *domain_name
,
1349 struct cli_state
*cli
,
1350 struct rpc_pipe_client
*pipe_hnd
,
1351 TALLOC_CTX
*mem_ctx
,
1355 return rpc_printer_publish_internals_args(pipe_hnd
, mem_ctx
, argc
, argv
, DSPRINT_UNPUBLISH
);
1358 NTSTATUS
rpc_printer_publish_update_internals(struct net_context
*c
,
1359 const DOM_SID
*domain_sid
,
1360 const char *domain_name
,
1361 struct cli_state
*cli
,
1362 struct rpc_pipe_client
*pipe_hnd
,
1363 TALLOC_CTX
*mem_ctx
,
1367 return rpc_printer_publish_internals_args(pipe_hnd
, mem_ctx
, argc
, argv
, DSPRINT_UPDATE
);
1371 * List print-queues w.r.t. their publishing state
1373 * All parameters are provided by the run_rpc_command function, except for
1374 * argc, argv which are passed through.
1376 * @param c A net_context structure
1377 * @param domain_sid The domain sid aquired from the remote server
1378 * @param cli A cli_state connected to the server.
1379 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1380 * @param argc Standard main() style argc
1381 * @param argv Standard main() style argv. Initial components are already
1384 * @return Normal NTSTATUS return.
1387 NTSTATUS
rpc_printer_publish_list_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 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1397 uint32_t i
, num_printers
;
1399 const char *printername
, *sharename
;
1400 union spoolss_PrinterInfo
*info_enum
;
1401 union spoolss_PrinterInfo info
;
1402 struct policy_handle hnd
;
1405 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &info_enum
))
1408 for (i
= 0; i
< num_printers
; i
++) {
1410 /* do some initialization */
1411 printername
= info_enum
[i
].info2
.printername
;
1412 sharename
= info_enum
[i
].info2
.sharename
;
1414 if (!printername
|| !sharename
) {
1418 /* open printer handle */
1419 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1420 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd
))
1423 /* check for existing dst printer */
1424 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd
, level
, &info
))
1427 if (!info
.info7
.guid
) {
1430 state
= info
.info7
.action
;
1432 case DSPRINT_PUBLISH
:
1433 printf(_("printer [%s] is published"),
1436 printf(_(", guid: %s"),info
.info7
.guid
);
1439 case DSPRINT_UNPUBLISH
:
1440 printf(_("printer [%s] is unpublished\n"),
1443 case DSPRINT_UPDATE
:
1444 printf(_("printer [%s] is currently updating\n"),
1448 printf(_("unkown state: %d\n"), state
);
1453 nt_status
= NT_STATUS_OK
;
1456 if (is_valid_policy_hnd(&hnd
))
1457 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd
, NULL
);
1463 * Migrate Printer-ACLs from a source server to the destination server
1465 * All parameters are provided by the run_rpc_command function, except for
1466 * argc, argv which are passed through.
1468 * @param c A net_context structure
1469 * @param domain_sid The domain sid aquired from the remote server
1470 * @param cli A cli_state connected to the server.
1471 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1472 * @param argc Standard main() style argc
1473 * @param argv Standard main() style argv. Initial components are already
1476 * @return Normal NTSTATUS return.
1479 NTSTATUS
rpc_printer_migrate_security_internals(struct net_context
*c
,
1480 const DOM_SID
*domain_sid
,
1481 const char *domain_name
,
1482 struct cli_state
*cli
,
1483 struct rpc_pipe_client
*pipe_hnd
,
1484 TALLOC_CTX
*mem_ctx
,
1488 /* TODO: what now, info2 or info3 ?
1489 convince jerry that we should add clientside setacls level 3 at least
1491 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1493 uint32_t num_printers
;
1495 const char *printername
, *sharename
;
1496 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
1497 struct policy_handle hnd_src
, hnd_dst
;
1498 union spoolss_PrinterInfo
*info_enum
;
1499 struct cli_state
*cli_dst
= NULL
;
1500 union spoolss_PrinterInfo info_src
, info_dst
;
1502 DEBUG(3,("copying printer ACLs\n"));
1504 /* connect destination PI_SPOOLSS */
1505 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
,
1506 &ndr_table_spoolss
.syntax_id
);
1507 if (!NT_STATUS_IS_OK(nt_status
))
1511 /* enum source printers */
1512 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &info_enum
)) {
1513 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1517 if (!num_printers
) {
1518 printf (_("no printers found on server.\n"));
1519 nt_status
= NT_STATUS_OK
;
1523 /* do something for all printers */
1524 for (i
= 0; i
< num_printers
; i
++) {
1526 /* do some initialization */
1527 printername
= info_enum
[i
].info2
.printername
;
1528 sharename
= info_enum
[i
].info2
.sharename
;
1530 if (!printername
|| !sharename
) {
1531 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1535 /* we can reset NT_STATUS here because we do not
1536 get any real NT_STATUS-codes anymore from now on */
1537 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1539 d_printf(_("migrating printer ACLs for: [%s] / [%s]\n"),
1540 printername
, sharename
);
1542 /* according to msdn you have specify these access-rights
1543 to see the security descriptor
1544 - READ_CONTROL (DACL)
1545 - ACCESS_SYSTEM_SECURITY (SACL)
1548 /* open src printer handle */
1549 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1550 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
1553 /* open dst printer handle */
1554 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
1555 PRINTER_ALL_ACCESS
, cli_dst
->user_name
, &hnd_dst
))
1558 /* check for existing dst printer */
1559 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, level
, &info_dst
))
1562 /* check for existing src printer */
1563 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd_src
, 3, &info_src
))
1566 /* Copy Security Descriptor */
1568 /* copy secdesc (info level 2) */
1569 info_dst
.info2
.devmode
= NULL
;
1570 info_dst
.info2
.secdesc
= dup_sec_desc(mem_ctx
, info_src
.info3
.secdesc
);
1573 display_sec_desc(info_dst
.info2
.secdesc
);
1575 if (!net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 2, &info_dst
))
1578 DEBUGADD(1,("\tSetPrinter of SECDESC succeeded\n"));
1581 /* close printer handles here */
1582 if (is_valid_policy_hnd(&hnd_src
)) {
1583 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
1586 if (is_valid_policy_hnd(&hnd_dst
)) {
1587 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
1592 nt_status
= NT_STATUS_OK
;
1596 if (is_valid_policy_hnd(&hnd_src
)) {
1597 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
1600 if (is_valid_policy_hnd(&hnd_dst
)) {
1601 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
1605 cli_shutdown(cli_dst
);
1611 * Migrate printer-forms from a src server to the dst server
1613 * All parameters are provided by the run_rpc_command function, except for
1614 * argc, argv which are passed through.
1616 * @param c A net_context structure
1617 * @param domain_sid The domain sid aquired from the remote server
1618 * @param cli A cli_state connected to the server.
1619 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1620 * @param argc Standard main() style argc
1621 * @param argv Standard main() style argv. Initial components are already
1624 * @return Normal NTSTATUS return.
1627 NTSTATUS
rpc_printer_migrate_forms_internals(struct net_context
*c
,
1628 const DOM_SID
*domain_sid
,
1629 const char *domain_name
,
1630 struct cli_state
*cli
,
1631 struct rpc_pipe_client
*pipe_hnd
,
1632 TALLOC_CTX
*mem_ctx
,
1636 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1639 uint32_t num_printers
;
1641 const char *printername
, *sharename
;
1642 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
1643 struct policy_handle hnd_src
, hnd_dst
;
1644 union spoolss_PrinterInfo
*info_enum
;
1645 union spoolss_PrinterInfo info_dst
;
1647 union spoolss_FormInfo
*forms
;
1648 struct cli_state
*cli_dst
= NULL
;
1650 DEBUG(3,("copying forms\n"));
1652 /* connect destination PI_SPOOLSS */
1653 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
,
1654 &ndr_table_spoolss
.syntax_id
);
1655 if (!NT_STATUS_IS_OK(nt_status
))
1658 /* enum src printers */
1659 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &info_enum
)) {
1660 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1664 if (!num_printers
) {
1665 printf (_("no printers found on server.\n"));
1666 nt_status
= NT_STATUS_OK
;
1670 /* do something for all printers */
1671 for (i
= 0; i
< num_printers
; i
++) {
1673 /* do some initialization */
1674 printername
= info_enum
[i
].info2
.printername
;
1675 sharename
= info_enum
[i
].info2
.sharename
;
1677 if (!printername
|| !sharename
) {
1678 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1681 /* we can reset NT_STATUS here because we do not
1682 get any real NT_STATUS-codes anymore from now on */
1683 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1685 d_printf(_("migrating printer forms for: [%s] / [%s]\n"),
1686 printername
, sharename
);
1689 /* open src printer handle */
1690 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1691 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
1694 /* open dst printer handle */
1695 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
1696 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd_dst
))
1699 /* check for existing dst printer */
1700 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, level
, &info_dst
))
1703 /* finally migrate forms */
1704 if (!net_spoolss_enumforms(pipe_hnd
, mem_ctx
, &hnd_src
, level
, &num_forms
, &forms
))
1707 DEBUG(1,("got %d forms for printer\n", num_forms
));
1710 for (f
= 0; f
< num_forms
; f
++) {
1712 union spoolss_AddFormInfo info
;
1715 /* only migrate FORM_PRINTER types, according to jerry
1716 FORM_BUILTIN-types are hard-coded in samba */
1717 if (forms
[f
].info1
.flags
!= SPOOLSS_FORM_PRINTER
)
1721 d_printf(_("\tmigrating form # %d [%s] of type "
1723 f
, forms
[f
].info1
.form_name
,
1724 forms
[f
].info1
.flags
);
1726 info
.info1
= (struct spoolss_AddFormInfo1
*)
1727 (void *)&forms
[f
].info1
;
1729 /* FIXME: there might be something wrong with samba's
1731 status
= rpccli_spoolss_AddForm(pipe_hnd_dst
, mem_ctx
,
1736 if (!W_ERROR_IS_OK(result
)) {
1737 d_printf(_("\tAddForm form %d: [%s] refused.\n"),
1738 f
, forms
[f
].info1
.form_name
);
1742 DEBUGADD(1,("\tAddForm of [%s] succeeded\n",
1743 forms
[f
].info1
.form_name
));
1747 /* close printer handles here */
1748 if (is_valid_policy_hnd(&hnd_src
)) {
1749 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
1752 if (is_valid_policy_hnd(&hnd_dst
)) {
1753 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
1757 nt_status
= NT_STATUS_OK
;
1761 if (is_valid_policy_hnd(&hnd_src
))
1762 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
1764 if (is_valid_policy_hnd(&hnd_dst
))
1765 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
1768 cli_shutdown(cli_dst
);
1774 * Migrate printer-drivers from a src server to the dst server
1776 * All parameters are provided by the run_rpc_command function, except for
1777 * argc, argv which are passed through.
1779 * @param c A net_context structure
1780 * @param domain_sid The domain sid aquired from the remote server
1781 * @param cli A cli_state connected to the server.
1782 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1783 * @param argc Standard main() style argc
1784 * @param argv Standard main() style argv. Initial components are already
1787 * @return Normal NTSTATUS return.
1790 NTSTATUS
rpc_printer_migrate_drivers_internals(struct net_context
*c
,
1791 const DOM_SID
*domain_sid
,
1792 const char *domain_name
,
1793 struct cli_state
*cli
,
1794 struct rpc_pipe_client
*pipe_hnd
,
1795 TALLOC_CTX
*mem_ctx
,
1799 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1801 uint32_t num_printers
;
1803 const char *printername
, *sharename
;
1804 bool got_src_driver_share
= false;
1805 bool got_dst_driver_share
= false;
1806 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
1807 struct policy_handle hnd_src
, hnd_dst
;
1808 union spoolss_DriverInfo drv_info_src
;
1809 union spoolss_PrinterInfo
*info_enum
;
1810 union spoolss_PrinterInfo info_dst
;
1811 struct cli_state
*cli_dst
= NULL
;
1812 struct cli_state
*cli_share_src
= NULL
;
1813 struct cli_state
*cli_share_dst
= NULL
;
1814 const char *drivername
= NULL
;
1816 DEBUG(3,("copying printer-drivers\n"));
1818 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
,
1819 &ndr_table_spoolss
.syntax_id
);
1820 if (!NT_STATUS_IS_OK(nt_status
))
1823 /* open print$-share on the src server */
1824 nt_status
= connect_to_service(c
, &cli_share_src
, &cli
->dest_ss
,
1825 cli
->desthost
, "print$", "A:");
1826 if (!NT_STATUS_IS_OK(nt_status
))
1829 got_src_driver_share
= true;
1832 /* open print$-share on the dst server */
1833 nt_status
= connect_to_service(c
, &cli_share_dst
, &cli_dst
->dest_ss
,
1834 cli_dst
->desthost
, "print$", "A:");
1835 if (!NT_STATUS_IS_OK(nt_status
))
1838 got_dst_driver_share
= true;
1841 /* enum src printers */
1842 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &info_enum
)) {
1843 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1847 if (num_printers
== 0) {
1848 printf (_("no printers found on server.\n"));
1849 nt_status
= NT_STATUS_OK
;
1854 /* do something for all printers */
1855 for (p
= 0; p
< num_printers
; p
++) {
1857 /* do some initialization */
1858 printername
= info_enum
[p
].info2
.printername
;
1859 sharename
= info_enum
[p
].info2
.sharename
;
1861 if (!printername
|| !sharename
) {
1862 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1866 /* we can reset NT_STATUS here because we do not
1867 get any real NT_STATUS-codes anymore from now on */
1868 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1870 d_printf(_("migrating printer driver for: [%s] / [%s]\n"),
1871 printername
, sharename
);
1873 /* open dst printer handle */
1874 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
1875 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd_dst
))
1878 /* check for existing dst printer */
1879 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 2, &info_dst
))
1883 /* open src printer handle */
1884 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1885 MAXIMUM_ALLOWED_ACCESS
,
1886 pipe_hnd
->auth
->user_name
,
1890 /* in a first step call getdriver for each shared printer (per arch)
1891 to get a list of all files that have to be copied */
1893 for (i
=0; archi_table
[i
].long_archi
!=NULL
; i
++) {
1896 if (!net_spoolss_getprinterdriver(pipe_hnd
, mem_ctx
, &hnd_src
,
1897 level
, archi_table
[i
].long_archi
,
1898 archi_table
[i
].version
, &drv_info_src
))
1901 drivername
= drv_info_src
.info3
.driver_name
;
1904 display_print_driver3(&drv_info_src
.info3
);
1906 /* check arch dir */
1907 nt_status
= check_arch_dir(cli_share_dst
, archi_table
[i
].short_archi
);
1908 if (!NT_STATUS_IS_OK(nt_status
))
1912 /* copy driver-files */
1913 nt_status
= copy_print_driver_3(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
1914 archi_table
[i
].short_archi
,
1915 &drv_info_src
.info3
);
1916 if (!NT_STATUS_IS_OK(nt_status
))
1921 if (!net_spoolss_addprinterdriver(pipe_hnd_dst
, mem_ctx
, level
, &drv_info_src
)) {
1922 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1926 DEBUGADD(1,("Sucessfully added driver [%s] for printer [%s]\n",
1927 drivername
, printername
));
1931 if (!drivername
|| strlen(drivername
) == 0) {
1932 DEBUGADD(1,("Did not get driver for printer %s\n",
1938 info_dst
.info2
.drivername
= drivername
;
1940 if (!net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 2, &info_dst
)) {
1941 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1945 DEBUGADD(1,("Sucessfully set driver %s for printer %s\n",
1946 drivername
, printername
));
1949 if (is_valid_policy_hnd(&hnd_dst
)) {
1950 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
1954 if (is_valid_policy_hnd(&hnd_src
)) {
1955 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
1959 nt_status
= NT_STATUS_OK
;
1963 if (is_valid_policy_hnd(&hnd_src
))
1964 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
1966 if (is_valid_policy_hnd(&hnd_dst
))
1967 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
1970 cli_shutdown(cli_dst
);
1973 if (got_src_driver_share
)
1974 cli_shutdown(cli_share_src
);
1976 if (got_dst_driver_share
)
1977 cli_shutdown(cli_share_dst
);
1984 * Migrate printer-queues from a src to the dst server
1985 * (requires a working "addprinter command" to be installed for the local smbd)
1987 * All parameters are provided by the run_rpc_command function, except for
1988 * argc, argv which are passed through.
1990 * @param c A net_context structure
1991 * @param domain_sid The domain sid aquired from the remote server
1992 * @param cli A cli_state connected to the server.
1993 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1994 * @param argc Standard main() style argc
1995 * @param argv Standard main() style argv. Initial components are already
1998 * @return Normal NTSTATUS return.
2001 NTSTATUS
rpc_printer_migrate_printers_internals(struct net_context
*c
,
2002 const DOM_SID
*domain_sid
,
2003 const char *domain_name
,
2004 struct cli_state
*cli
,
2005 struct rpc_pipe_client
*pipe_hnd
,
2006 TALLOC_CTX
*mem_ctx
,
2011 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
2012 uint32_t i
= 0, num_printers
;
2014 union spoolss_PrinterInfo info_dst
, info_src
;
2015 union spoolss_PrinterInfo
*info_enum
;
2016 struct cli_state
*cli_dst
= NULL
;
2017 struct policy_handle hnd_dst
, hnd_src
;
2018 const char *printername
, *sharename
;
2019 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
2020 struct spoolss_SetPrinterInfoCtr info_ctr
;
2022 DEBUG(3,("copying printers\n"));
2024 /* connect destination PI_SPOOLSS */
2025 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
,
2026 &ndr_table_spoolss
.syntax_id
);
2027 if (!NT_STATUS_IS_OK(nt_status
))
2031 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &info_enum
)) {
2032 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2036 if (!num_printers
) {
2037 printf (_("no printers found on server.\n"));
2038 nt_status
= NT_STATUS_OK
;
2042 /* do something for all printers */
2043 for (i
= 0; i
< num_printers
; i
++) {
2045 /* do some initialization */
2046 printername
= info_enum
[i
].info2
.printername
;
2047 sharename
= info_enum
[i
].info2
.sharename
;
2049 if (!printername
|| !sharename
) {
2050 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2053 /* we can reset NT_STATUS here because we do not
2054 get any real NT_STATUS-codes anymore from now on */
2055 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2057 d_printf(_("migrating printer queue for: [%s] / [%s]\n"),
2058 printername
, sharename
);
2060 /* open dst printer handle */
2061 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
2062 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd_dst
)) {
2064 DEBUG(1,("could not open printer: %s\n", sharename
));
2067 /* check for existing dst printer */
2068 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, level
, &info_dst
)) {
2069 printf (_("could not get printer, creating printer.\n"));
2071 DEBUG(1,("printer already exists: %s\n", sharename
));
2072 /* close printer handle here - dst only, not got src yet. */
2073 if (is_valid_policy_hnd(&hnd_dst
)) {
2074 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
2079 /* now get again src printer ctr via getprinter,
2080 we first need a handle for that */
2082 /* open src printer handle */
2083 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
2084 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
2087 /* getprinter on the src server */
2088 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd_src
, level
, &info_src
))
2091 /* copy each src printer to a dst printer 1:1,
2092 maybe some values have to be changed though */
2093 d_printf(_("creating printer: %s\n"), printername
);
2095 info_ctr
.level
= level
;
2096 info_ctr
.info
.info2
= (struct spoolss_SetPrinterInfo2
*)
2097 (void *)&info_src
.info2
;
2099 result
= rpccli_spoolss_addprinterex(pipe_hnd_dst
,
2103 if (W_ERROR_IS_OK(result
))
2104 d_printf (_("printer [%s] successfully added.\n"),
2106 else if (W_ERROR_V(result
) == W_ERROR_V(WERR_PRINTER_ALREADY_EXISTS
))
2107 d_fprintf (stderr
, _("printer [%s] already exists.\n"),
2110 d_fprintf (stderr
, _("could not create printer [%s]\n"),
2115 /* close printer handles here */
2116 if (is_valid_policy_hnd(&hnd_src
)) {
2117 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
2120 if (is_valid_policy_hnd(&hnd_dst
)) {
2121 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
2125 nt_status
= NT_STATUS_OK
;
2128 if (is_valid_policy_hnd(&hnd_src
))
2129 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
2131 if (is_valid_policy_hnd(&hnd_dst
))
2132 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
2135 cli_shutdown(cli_dst
);
2141 * Migrate Printer-Settings from a src server to the dst server
2142 * (for this to work, printers and drivers already have to be migrated earlier)
2144 * All parameters are provided by the run_rpc_command function, except for
2145 * argc, argv which are passed through.
2147 * @param c A net_context structure
2148 * @param domain_sid The domain sid aquired from the remote server
2149 * @param cli A cli_state connected to the server.
2150 * @param mem_ctx Talloc context, destoyed on compleation of the function.
2151 * @param argc Standard main() style argc
2152 * @param argv Standard main() style argv. Initial components are already
2155 * @return Normal NTSTATUS return.
2158 NTSTATUS
rpc_printer_migrate_settings_internals(struct net_context
*c
,
2159 const DOM_SID
*domain_sid
,
2160 const char *domain_name
,
2161 struct cli_state
*cli
,
2162 struct rpc_pipe_client
*pipe_hnd
,
2163 TALLOC_CTX
*mem_ctx
,
2168 /* FIXME: Here the nightmare begins */
2171 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
2172 uint32_t i
= 0, p
= 0, j
= 0;
2173 uint32_t num_printers
;
2175 const char *printername
, *sharename
;
2176 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
2177 struct policy_handle hnd_src
, hnd_dst
;
2178 union spoolss_PrinterInfo
*info_enum
;
2179 union spoolss_PrinterInfo info_dst_publish
;
2180 union spoolss_PrinterInfo info_dst
;
2181 struct cli_state
*cli_dst
= NULL
;
2182 char *devicename
= NULL
, *unc_name
= NULL
, *url
= NULL
;
2183 const char *longname
;
2184 const char **keylist
= NULL
;
2187 ZERO_STRUCT(info_dst_publish
);
2189 DEBUG(3,("copying printer settings\n"));
2191 /* connect destination PI_SPOOLSS */
2192 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
,
2193 &ndr_table_spoolss
.syntax_id
);
2194 if (!NT_STATUS_IS_OK(nt_status
))
2197 /* enum src printers */
2198 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &info_enum
)) {
2199 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2203 if (!num_printers
) {
2204 printf (_("no printers found on server.\n"));
2205 nt_status
= NT_STATUS_OK
;
2210 /* needed for dns-strings in regkeys */
2211 longname
= get_mydnsfullname();
2213 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2217 /* do something for all printers */
2218 for (i
= 0; i
< num_printers
; i
++) {
2220 uint32_t value_offered
= 0, value_needed
;
2221 uint32_t data_offered
= 0, data_needed
;
2222 enum winreg_Type type
;
2223 uint8_t *buffer
= NULL
;
2224 const char *value_name
= NULL
;
2226 /* do some initialization */
2227 printername
= info_enum
[i
].info2
.printername
;
2228 sharename
= info_enum
[i
].info2
.sharename
;
2230 if (!printername
|| !sharename
) {
2231 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2234 /* we can reset NT_STATUS here because we do not
2235 get any real NT_STATUS-codes anymore from now on */
2236 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2238 d_printf(_("migrating printer settings for: [%s] / [%s]\n"),
2239 printername
, sharename
);
2242 /* open src printer handle */
2243 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
2244 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
2247 /* open dst printer handle */
2248 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
2249 PRINTER_ALL_ACCESS
, cli_dst
->user_name
, &hnd_dst
))
2252 /* check for existing dst printer */
2253 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
,
2258 /* STEP 1: COPY DEVICE-MODE and other
2259 PRINTER_INFO_2-attributes
2262 info_dst
.info2
= info_enum
[i
].info2
;
2264 /* why is the port always disconnected when the printer
2265 is correctly installed (incl. driver ???) */
2266 info_dst
.info2
.portname
= SAMBA_PRINTER_PORT_NAME
;
2268 /* check if printer is published */
2269 if (info_enum
[i
].info2
.attributes
& PRINTER_ATTRIBUTE_PUBLISHED
) {
2271 /* check for existing dst printer */
2272 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 7, &info_dst_publish
))
2275 info_dst_publish
.info7
.action
= DSPRINT_PUBLISH
;
2277 /* ignore false from setprinter due to WERR_IO_PENDING */
2278 net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 7, &info_dst_publish
);
2280 DEBUG(3,("republished printer\n"));
2283 if (info_enum
[i
].info2
.devmode
!= NULL
) {
2285 /* copy devmode (info level 2) */
2286 info_dst
.info2
.devmode
= info_enum
[i
].info2
.devmode
;
2288 /* do not copy security descriptor (we have another
2289 * command for that) */
2290 info_dst
.info2
.secdesc
= NULL
;
2293 info_dst
.info2
.devmode
.devicename
=
2294 talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
2295 longname
, printername
);
2296 if (!info_dst
.info2
.devmode
.devicename
) {
2297 nt_status
= NT_STATUS_NO_MEMORY
;
2301 if (!net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
,
2305 DEBUGADD(1,("\tSetPrinter of DEVICEMODE succeeded\n"));
2308 /* STEP 2: COPY REGISTRY VALUES */
2310 /* please keep in mind that samba parse_spools gives horribly
2311 crippled results when used to rpccli_spoolss_enumprinterdataex
2312 a win2k3-server. (Bugzilla #1851)
2313 FIXME: IIRC I've seen it too on a win2k-server
2316 /* enumerate data on src handle */
2317 nt_status
= rpccli_spoolss_EnumPrinterData(pipe_hnd
, mem_ctx
,
2329 data_offered
= data_needed
;
2330 value_offered
= value_needed
;
2331 buffer
= talloc_zero_array(mem_ctx
, uint8_t, data_needed
);
2332 value_name
= talloc_zero_array(mem_ctx
, char, value_needed
);
2334 /* loop for all printerdata of "PrinterDriverData" */
2335 while (NT_STATUS_IS_OK(nt_status
) && W_ERROR_IS_OK(result
)) {
2337 nt_status
= rpccli_spoolss_EnumPrinterData(pipe_hnd
, mem_ctx
,
2348 /* loop for all reg_keys */
2349 if (NT_STATUS_IS_OK(nt_status
) && W_ERROR_IS_OK(result
)) {
2351 struct regval_blob v
;
2353 union spoolss_PrinterData printer_data
;
2356 if (c
->opt_verbose
) {
2357 fstrcpy(v
.valuename
, value_name
);
2359 v
.size
= data_offered
;
2361 display_reg_value(SPOOL_PRINTERDATA_KEY
, v
);
2364 result
= pull_spoolss_PrinterData(mem_ctx
,
2368 if (!W_ERROR_IS_OK(result
)) {
2373 if (!net_spoolss_setprinterdata(pipe_hnd_dst
, mem_ctx
,
2374 &hnd_dst
, value_name
,
2375 type
, printer_data
))
2378 DEBUGADD(1,("\tSetPrinterData of [%s] succeeded\n",
2383 /* STEP 3: COPY SUBKEY VALUES */
2385 /* here we need to enum all printer_keys and then work
2386 on the result with enum_printer_key_ex. nt4 does not
2387 respond to enumprinterkey, win2k does, so continue
2388 in case of an error */
2390 if (!net_spoolss_enumprinterkey(pipe_hnd
, mem_ctx
, &hnd_src
, "", &keylist
)) {
2391 printf(_("got no key-data\n"));
2396 /* work on a list of printer keys
2397 each key has to be enumerated to get all required
2398 information. information is then set via setprinterdataex-calls */
2400 if (keylist
== NULL
)
2403 for (i
=0; keylist
&& keylist
[i
] != NULL
; i
++) {
2405 const char *subkey
= keylist
[i
];
2407 struct spoolss_PrinterEnumValues
*info
;
2409 /* enumerate all src subkeys */
2410 if (!net_spoolss_enumprinterdataex(pipe_hnd
, mem_ctx
, 0,
2416 for (j
=0; j
< count
; j
++) {
2418 struct regval_blob value
;
2421 /* although samba replies with sane data in most cases we
2422 should try to avoid writing wrong registry data */
2424 if (strequal(info
[j
].value_name
, SPOOL_REG_PORTNAME
) ||
2425 strequal(info
[j
].value_name
, SPOOL_REG_UNCNAME
) ||
2426 strequal(info
[j
].value_name
, SPOOL_REG_URL
) ||
2427 strequal(info
[j
].value_name
, SPOOL_REG_SHORTSERVERNAME
) ||
2428 strequal(info
[j
].value_name
, SPOOL_REG_SERVERNAME
)) {
2430 if (strequal(info
[j
].value_name
, SPOOL_REG_PORTNAME
)) {
2432 /* although windows uses a multi-sz, we use a sz */
2433 push_reg_sz(mem_ctx
, &blob
, SAMBA_PRINTER_PORT_NAME
);
2434 fstrcpy(value
.valuename
, SPOOL_REG_PORTNAME
);
2437 if (strequal(info
[j
].value_name
, SPOOL_REG_UNCNAME
)) {
2439 if (asprintf(&unc_name
, "\\\\%s\\%s", longname
, sharename
) < 0) {
2440 nt_status
= NT_STATUS_NO_MEMORY
;
2443 push_reg_sz(mem_ctx
, &blob
, unc_name
);
2444 fstrcpy(value
.valuename
, SPOOL_REG_UNCNAME
);
2447 if (strequal(info
[j
].value_name
, SPOOL_REG_URL
)) {
2452 /* FIXME: should we really do that ??? */
2453 if (asprintf(&url
, "http://%s:631/printers/%s", longname
, sharename
) < 0) {
2454 nt_status
= NT_STATUS_NO_MEMORY
;
2457 push_reg_sz(mem_ctx
, &blob
, url
);
2458 fstrcpy(value
.valuename
, SPOOL_REG_URL
);
2462 if (strequal(info
[j
].value_name
, SPOOL_REG_SERVERNAME
)) {
2464 push_reg_sz(mem_ctx
, &blob
, longname
);
2465 fstrcpy(value
.valuename
, SPOOL_REG_SERVERNAME
);
2468 if (strequal(info
[j
].value_name
, SPOOL_REG_SHORTSERVERNAME
)) {
2470 push_reg_sz(mem_ctx
, &blob
, global_myname());
2471 fstrcpy(value
.valuename
, SPOOL_REG_SHORTSERVERNAME
);
2474 value
.type
= REG_SZ
;
2475 value
.size
= blob
.length
;
2477 value
.data_p
= blob
.data
;
2479 value
.data_p
= NULL
;
2483 display_reg_value(subkey
, value
);
2485 /* here we have to set all subkeys on the dst server */
2486 if (!net_spoolss_setprinterdataex(pipe_hnd_dst
, mem_ctx
, &hnd_dst
,
2492 struct regval_blob v
;
2494 result
= push_spoolss_PrinterData(mem_ctx
, &blob
,
2497 if (!W_ERROR_IS_OK(result
)) {
2501 fstrcpy(v
.valuename
, info
[j
].value_name
);
2502 v
.type
= info
[j
].type
;
2503 v
.data_p
= blob
.data
;
2504 v
.size
= blob
.length
;
2506 if (c
->opt_verbose
) {
2507 display_reg_value(subkey
, v
);
2510 /* here we have to set all subkeys on the dst server */
2511 if (!net_spoolss_setprinterdataex(pipe_hnd_dst
, mem_ctx
, &hnd_dst
,
2518 DEBUGADD(1,("\tSetPrinterDataEx of key [%s\\%s] succeeded\n",
2519 subkey
, info
[j
].value_name
));
2524 TALLOC_FREE(keylist
);
2526 /* close printer handles here */
2527 if (is_valid_policy_hnd(&hnd_src
)) {
2528 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
2531 if (is_valid_policy_hnd(&hnd_dst
)) {
2532 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
2537 nt_status
= NT_STATUS_OK
;
2540 SAFE_FREE(devicename
);
2542 SAFE_FREE(unc_name
);
2544 if (is_valid_policy_hnd(&hnd_src
))
2545 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
2547 if (is_valid_policy_hnd(&hnd_dst
))
2548 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
2551 cli_shutdown(cli_dst
);