2 Samba Unix/Linux SMB client library
3 Distributed SMB/CIFS Server Management Utility
4 Copyright (C) 2004,2009 Guenther Deschner (gd@samba.org)
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "utils/net.h"
21 #include "../librpc/gen_ndr/cli_spoolss.h"
23 /* support itanium as well */
24 static const struct print_architecture_table_node archi_table
[]= {
26 {"Windows 4.0", "WIN40", 0 },
27 {"Windows NT x86", "W32X86", 2 },
28 {"Windows NT x86", "W32X86", 3 },
29 {"Windows NT R4000", "W32MIPS", 2 },
30 {"Windows NT Alpha_AXP", "W32ALPHA", 2 },
31 {"Windows NT PowerPC", "W32PPC", 2 },
32 {"Windows IA64", "IA64", 3 },
33 {"Windows x64", "x64", 3 },
39 * This display-printdriver-functions was borrowed from rpcclient/cmd_spoolss.c.
40 * It is here for debugging purpose and should be removed later on.
43 /****************************************************************************
44 Printer info level 3 display function.
45 ****************************************************************************/
47 static void display_print_driver3(struct spoolss_DriverInfo3
*r
)
55 printf(_("Printer Driver Info 3:\n"));
56 printf(_("\tVersion: [%x]\n"), r
->version
);
57 printf(_("\tDriver Name: [%s]\n"), r
->driver_name
);
58 printf(_("\tArchitecture: [%s]\n"), r
->architecture
);
59 printf(_("\tDriver Path: [%s]\n"), r
->driver_path
);
60 printf(_("\tDatafile: [%s]\n"), r
->data_file
);
61 printf(_("\tConfigfile: [%s]\n\n"), r
->config_file
);
62 printf(_("\tHelpfile: [%s]\n\n"), r
->help_file
);
64 for (i
=0; r
->dependent_files
[i
] != NULL
; i
++) {
65 printf(_("\tDependentfiles: [%s]\n"), r
->dependent_files
[i
]);
70 printf(_("\tMonitorname: [%s]\n"), r
->monitor_name
);
71 printf(_("\tDefaultdatatype: [%s]\n\n"), r
->default_datatype
);
74 static void display_reg_value(const char *subkey
, struct regval_blob value
)
81 d_printf(_("\t[%s:%s]: REG_DWORD: 0x%08x\n"), subkey
,
82 value
.valuename
, *((uint32_t *) value
.data_p
));
86 blob
= data_blob_const(value
.data_p
, value
.size
);
87 pull_reg_sz(talloc_tos(), NULL
, &blob
, &text
);
91 d_printf(_("\t[%s:%s]: REG_SZ: %s\n"), subkey
, value
.valuename
,
96 d_printf(_("\t[%s:%s]: REG_BINARY: unknown length value not "
98 subkey
, value
.valuename
);
104 blob
= data_blob_const(value
.data_p
, value
.size
);
106 if (!pull_reg_multi_sz(NULL
, NULL
, &blob
, &values
)) {
107 d_printf("pull_reg_multi_sz failed\n");
111 printf("%s: REG_MULTI_SZ: \n", value
.valuename
);
112 for (i
=0; values
[i
] != NULL
; i
++) {
113 d_printf("%s\n", values
[i
]);
120 d_printf(_("\t%s: unknown type %d\n"), value
.valuename
,
127 * Copies ACLs, DOS-attributes and timestamps from one
128 * file or directory from one connected share to another connected share
130 * @param c A net_context structure
131 * @param mem_ctx A talloc-context
132 * @param cli_share_src A connected cli_state
133 * @param cli_share_dst A connected cli_state
134 * @param src_file The source file-name
135 * @param dst_file The destination file-name
136 * @param copy_acls Whether to copy acls
137 * @param copy_attrs Whether to copy DOS attributes
138 * @param copy_timestamps Whether to preserve timestamps
139 * @param is_file Whether this file is a file or a dir
141 * @return Normal NTSTATUS return.
144 NTSTATUS
net_copy_fileattr(struct net_context
*c
,
146 struct cli_state
*cli_share_src
,
147 struct cli_state
*cli_share_dst
,
148 const char *src_name
, const char *dst_name
,
149 bool copy_acls
, bool copy_attrs
,
150 bool copy_timestamps
, bool is_file
)
152 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
153 uint16_t fnum_src
= 0;
154 uint16_t fnum_dst
= 0;
157 time_t f_atime
, f_ctime
, f_mtime
;
160 if (!copy_timestamps
&& !copy_acls
&& !copy_attrs
)
163 /* open file/dir on the originating server */
165 DEBUGADD(3,("opening %s %s on originating server\n",
166 is_file
?"file":"dir", src_name
));
168 if (!NT_STATUS_IS_OK(cli_ntcreate(cli_share_src
, src_name
, 0, READ_CONTROL_ACCESS
, 0,
169 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0x0, 0x0, &fnum_src
))) {
170 DEBUGADD(0,("cannot open %s %s on originating server %s\n",
171 is_file
?"file":"dir", src_name
, cli_errstr(cli_share_src
)));
172 nt_status
= cli_nt_error(cli_share_src
);
179 /* get the security descriptor */
180 sd
= cli_query_secdesc(cli_share_src
, fnum_src
, mem_ctx
);
182 DEBUG(0,("failed to get security descriptor: %s\n",
183 cli_errstr(cli_share_src
)));
184 nt_status
= cli_nt_error(cli_share_src
);
188 if (c
->opt_verbose
&& DEBUGLEVEL
>= 3)
189 display_sec_desc(sd
);
193 if (copy_attrs
|| copy_timestamps
) {
195 /* get file attributes */
196 if (!NT_STATUS_IS_OK(cli_getattrE(cli_share_src
, fnum_src
, &attr
, NULL
,
197 &f_ctime
, &f_atime
, &f_mtime
))) {
198 DEBUG(0,("failed to get file-attrs: %s\n",
199 cli_errstr(cli_share_src
)));
200 nt_status
= cli_nt_error(cli_share_src
);
206 /* open the file/dir on the destination server */
208 if (!NT_STATUS_IS_OK(cli_ntcreate(cli_share_dst
, dst_name
, 0, WRITE_DAC_ACCESS
| WRITE_OWNER_ACCESS
, 0,
209 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0x0, 0x0, &fnum_dst
))) {
210 DEBUG(0,("failed to open %s on the destination server: %s: %s\n",
211 is_file
?"file":"dir", dst_name
, cli_errstr(cli_share_dst
)));
212 nt_status
= cli_nt_error(cli_share_dst
);
216 if (copy_timestamps
) {
219 if (!NT_STATUS_IS_OK(cli_setattrE(cli_share_dst
, fnum_dst
, f_ctime
, f_atime
, f_mtime
))) {
220 DEBUG(0,("failed to set file-attrs (timestamps): %s\n",
221 cli_errstr(cli_share_dst
)));
222 nt_status
= cli_nt_error(cli_share_dst
);
230 if (!cli_set_secdesc(cli_share_dst
, fnum_dst
, sd
)) {
231 DEBUG(0,("could not set secdesc on %s: %s\n",
232 dst_name
, cli_errstr(cli_share_dst
)));
233 nt_status
= cli_nt_error(cli_share_dst
);
241 if (!NT_STATUS_IS_OK(cli_setatr(cli_share_dst
, dst_name
, attr
, 0))) {
242 DEBUG(0,("failed to set file-attrs: %s\n",
243 cli_errstr(cli_share_dst
)));
244 nt_status
= cli_nt_error(cli_share_dst
);
252 if (!NT_STATUS_IS_OK(cli_close(cli_share_src
, fnum_src
))) {
254 _("could not close %s on originating server: %s\n"),
255 is_file
?"file":"dir", cli_errstr(cli_share_src
));
256 nt_status
= cli_nt_error(cli_share_src
);
260 if (!NT_STATUS_IS_OK(cli_close(cli_share_dst
, fnum_dst
))) {
262 _("could not close %s on destination server: %s\n"),
263 is_file
?"file":"dir", cli_errstr(cli_share_dst
));
264 nt_status
= cli_nt_error(cli_share_dst
);
269 nt_status
= NT_STATUS_OK
;
275 cli_close(cli_share_src
, fnum_src
);
278 cli_close(cli_share_dst
, fnum_dst
);
284 * Copy a file or directory from a connected share to another connected share
286 * @param c A net_context structure
287 * @param mem_ctx A talloc-context
288 * @param cli_share_src A connected cli_state
289 * @param cli_share_dst A connected cli_state
290 * @param src_file The source file-name
291 * @param dst_file The destination file-name
292 * @param copy_acls Whether to copy acls
293 * @param copy_attrs Whether to copy DOS attributes
294 * @param copy_timestamps Whether to preserve timestamps
295 * @param is_file Whether this file is a file or a dir
297 * @return Normal NTSTATUS return.
300 NTSTATUS
net_copy_file(struct net_context
*c
,
302 struct cli_state
*cli_share_src
,
303 struct cli_state
*cli_share_dst
,
304 const char *src_name
, const char *dst_name
,
305 bool copy_acls
, bool copy_attrs
,
306 bool copy_timestamps
, bool is_file
)
308 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
309 uint16_t fnum_src
= 0;
310 uint16_t fnum_dst
= 0;
311 static int io_bufsize
= 64512;
312 int read_size
= io_bufsize
;
317 if (!src_name
|| !dst_name
)
320 if (cli_share_src
== NULL
|| cli_share_dst
== NULL
)
323 /* open on the originating server */
324 DEBUGADD(3,("opening %s %s on originating server\n",
325 is_file
? "file":"dir", src_name
));
327 nt_status
= cli_open(cli_share_src
, src_name
, O_RDONLY
, DENY_NONE
, &fnum_src
);
329 nt_status
= cli_ntcreate(cli_share_src
, src_name
, 0, READ_CONTROL_ACCESS
, 0,
330 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN
, 0x0, 0x0, &fnum_src
);
332 if (!NT_STATUS_IS_OK(nt_status
)) {
333 DEBUGADD(0,("cannot open %s %s on originating server %s\n",
334 is_file
? "file":"dir",
335 src_name
, cli_errstr(cli_share_src
)));
342 /* open file on the destination server */
343 DEBUGADD(3,("opening file %s on destination server\n", dst_name
));
344 nt_status
= cli_open(cli_share_dst
, dst_name
,
345 O_RDWR
|O_CREAT
|O_TRUNC
, DENY_NONE
, &fnum_dst
);
347 if (!NT_STATUS_IS_OK(nt_status
)) {
348 DEBUGADD(1,("cannot create file %s on destination server: %s\n",
349 dst_name
, cli_errstr(cli_share_dst
)));
353 /* allocate memory */
354 if (!(data
= (char *)SMB_MALLOC(read_size
))) {
355 d_fprintf(stderr
, _("malloc fail for size %d\n"),
357 nt_status
= NT_STATUS_NO_MEMORY
;
364 if (c
->opt_verbose
) {
366 d_printf(_("copying [\\\\%s\\%s%s] => [\\\\%s\\%s%s] "
367 "%s ACLs and %s DOS Attributes %s\n"),
368 cli_share_src
->desthost
, cli_share_src
->share
, src_name
,
369 cli_share_dst
->desthost
, cli_share_dst
->share
, dst_name
,
370 copy_acls
? _("with") : _("without"),
371 copy_attrs
? _("with") : _("without"),
372 copy_timestamps
? _("(preserving timestamps)") : "" );
380 n
= cli_read(cli_share_src
, fnum_src
, data
, nread
,
386 ret
= cli_write(cli_share_dst
, fnum_dst
, 0, data
,
390 d_fprintf(stderr
, _("Error writing file: %s\n"),
391 cli_errstr(cli_share_dst
));
392 nt_status
= cli_nt_error(cli_share_dst
);
400 if (!is_file
&& !NT_STATUS_IS_OK(cli_chkpath(cli_share_dst
, dst_name
))) {
403 DEBUGADD(3,("creating dir %s on the destination server\n",
406 if (!NT_STATUS_IS_OK(cli_mkdir(cli_share_dst
, dst_name
))) {
407 DEBUG(0,("cannot create directory %s: %s\n",
408 dst_name
, cli_errstr(cli_share_dst
)));
409 nt_status
= NT_STATUS_NO_SUCH_FILE
;
412 if (!NT_STATUS_IS_OK(cli_chkpath(cli_share_dst
, dst_name
))) {
414 _("cannot check for directory %s: %s\n"),
415 dst_name
, cli_errstr(cli_share_dst
));
422 if (!NT_STATUS_IS_OK(cli_close(cli_share_src
, fnum_src
))) {
424 _("could not close file on originating server: %s\n"),
425 cli_errstr(cli_share_src
));
426 nt_status
= cli_nt_error(cli_share_src
);
430 if (is_file
&& !NT_STATUS_IS_OK(cli_close(cli_share_dst
, fnum_dst
))) {
432 _("could not close file on destination server: %s\n"),
433 cli_errstr(cli_share_dst
));
434 nt_status
= cli_nt_error(cli_share_dst
);
438 /* possibly we have to copy some file-attributes / acls / sd */
439 nt_status
= net_copy_fileattr(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
440 src_name
, dst_name
, copy_acls
,
441 copy_attrs
, copy_timestamps
, is_file
);
442 if (!NT_STATUS_IS_OK(nt_status
))
446 nt_status
= NT_STATUS_OK
;
452 cli_close(cli_share_src
, fnum_src
);
455 cli_close(cli_share_dst
, fnum_dst
);
463 * Copy a driverfile from on connected share to another connected share
464 * This silently assumes that a driver-file is picked up from
466 * \\src_server\print$\{arch}\{version}\file
470 * \\dst_server\print$\{arch}\file
472 * to be added via setdriver-calls later.
473 * @param c A net_context structure
474 * @param mem_ctx A talloc-context
475 * @param cli_share_src A cli_state connected to source print$-share
476 * @param cli_share_dst A cli_state connected to destination print$-share
477 * @param file The file-name to be copied
478 * @param short_archi The name of the driver-architecture (short form)
480 * @return Normal NTSTATUS return.
483 static NTSTATUS
net_copy_driverfile(struct net_context
*c
,
485 struct cli_state
*cli_share_src
,
486 struct cli_state
*cli_share_dst
,
487 const char *file
, const char *short_archi
) {
489 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
501 /* scroll through the file until we have the part
502 beyond archi_table.short_archi */
504 while (next_token_talloc(mem_ctx
, &p
, &tok
, "\\")) {
505 if (strequal(tok
, short_archi
)) {
506 next_token_talloc(mem_ctx
, &p
, &version
, "\\");
507 next_token_talloc(mem_ctx
, &p
, &filename
, "\\");
511 /* build source file name */
512 if (asprintf(&src_name
, "\\%s\\%s\\%s", short_archi
, version
, filename
) < 0 )
513 return NT_STATUS_NO_MEMORY
;
516 /* create destination file name */
517 if (asprintf(&dst_name
, "\\%s\\%s", short_archi
, filename
) < 0 )
518 return NT_STATUS_NO_MEMORY
;
521 /* finally copy the file */
522 nt_status
= net_copy_file(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
523 src_name
, dst_name
, false, false, false, true);
524 if (!NT_STATUS_IS_OK(nt_status
))
527 nt_status
= NT_STATUS_OK
;
537 * Check for existing Architecture directory on a given server
539 * @param cli_share A cli_state connected to a print$-share
540 * @param short_archi The Architecture for the print-driver
542 * @return Normal NTSTATUS return.
545 static NTSTATUS
check_arch_dir(struct cli_state
*cli_share
, const char *short_archi
)
548 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
551 if (asprintf(&dir
, "\\%s", short_archi
) < 0) {
552 return NT_STATUS_NO_MEMORY
;
555 DEBUG(10,("creating print-driver dir for architecture: %s\n",
558 if (!NT_STATUS_IS_OK(cli_mkdir(cli_share
, dir
))) {
559 DEBUG(1,("cannot create directory %s: %s\n",
560 dir
, cli_errstr(cli_share
)));
561 nt_status
= NT_STATUS_NO_SUCH_FILE
;
564 if (!NT_STATUS_IS_OK(cli_chkpath(cli_share
, dir
))) {
565 d_fprintf(stderr
, _("cannot check %s: %s\n"),
566 dir
, cli_errstr(cli_share
));
570 nt_status
= NT_STATUS_OK
;
578 * Copy a print-driver (level 3) from one connected print$-share to another
579 * connected print$-share
581 * @param c A net_context structure
582 * @param mem_ctx A talloc-context
583 * @param cli_share_src A cli_state connected to a print$-share
584 * @param cli_share_dst A cli_state connected to a print$-share
585 * @param short_archi The Architecture for the print-driver
586 * @param i1 The DRIVER_INFO_3-struct
588 * @return Normal NTSTATUS return.
591 static NTSTATUS
copy_print_driver_3(struct net_context
*c
,
593 struct cli_state
*cli_share_src
,
594 struct cli_state
*cli_share_dst
,
595 const char *short_archi
,
596 struct spoolss_DriverInfo3
*r
)
598 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
606 d_printf(_("copying driver: [%s], for architecture: [%s], "
608 r
->driver_name
, short_archi
, r
->version
);
610 nt_status
= net_copy_driverfile(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
611 r
->driver_path
, short_archi
);
612 if (!NT_STATUS_IS_OK(nt_status
))
615 nt_status
= net_copy_driverfile(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
616 r
->data_file
, short_archi
);
617 if (!NT_STATUS_IS_OK(nt_status
))
620 nt_status
= net_copy_driverfile(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
621 r
->config_file
, short_archi
);
622 if (!NT_STATUS_IS_OK(nt_status
))
625 nt_status
= net_copy_driverfile(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
626 r
->help_file
, short_archi
);
627 if (!NT_STATUS_IS_OK(nt_status
))
630 for (i
=0; r
->dependent_files
[i
] != NULL
; i
++) {
632 nt_status
= net_copy_driverfile(c
, mem_ctx
,
633 cli_share_src
, cli_share_dst
,
634 r
->dependent_files
[i
], short_archi
);
635 if (!NT_STATUS_IS_OK(nt_status
)) {
644 * net_spoolss-functions
645 * =====================
647 * the net_spoolss-functions aim to simplify spoolss-client-functions
648 * required during the migration-process wrt buffer-sizes, returned
651 * this greatly reduces the complexitiy of the migrate-functions.
655 static bool net_spoolss_enum_printers(struct rpc_pipe_client
*pipe_hnd
,
660 uint32_t *num_printers
,
661 union spoolss_PrinterInfo
**info
)
667 result
= rpccli_spoolss_enumprinters(pipe_hnd
, mem_ctx
,
674 if (!W_ERROR_IS_OK(result
)) {
675 printf(_("cannot enum printers: %s\n"), win_errstr(result
));
682 static bool net_spoolss_open_printer_ex(struct rpc_pipe_client
*pipe_hnd
,
684 const char *printername
,
685 uint32_t access_required
,
686 const char *username
,
687 struct policy_handle
*hnd
)
690 fstring printername2
;
692 fstrcpy(printername2
, pipe_hnd
->srv_name_slash
);
693 fstrcat(printername2
, "\\");
694 fstrcat(printername2
, printername
);
696 DEBUG(10,("connecting to: %s as %s for %s and access: %x\n",
697 pipe_hnd
->srv_name_slash
, username
, printername2
, access_required
));
700 result
= rpccli_spoolss_openprinter_ex(pipe_hnd
, mem_ctx
,
705 /* be more verbose */
706 if (W_ERROR_V(result
) == W_ERROR_V(WERR_ACCESS_DENIED
)) {
708 _("no access to printer [%s] on [%s] for user [%s] "
710 printername2
, pipe_hnd
->srv_name_slash
, username
);
714 if (!W_ERROR_IS_OK(result
)) {
715 d_fprintf(stderr
,_("cannot open printer %s on server %s: %s\n"),
716 printername2
, pipe_hnd
->srv_name_slash
, win_errstr(result
));
720 DEBUG(2,("got printer handle for printer: %s, server: %s\n",
721 printername2
, pipe_hnd
->srv_name_slash
));
726 static bool net_spoolss_getprinter(struct rpc_pipe_client
*pipe_hnd
,
728 struct policy_handle
*hnd
,
730 union spoolss_PrinterInfo
*info
)
734 /* getprinter call */
735 result
= rpccli_spoolss_getprinter(pipe_hnd
, mem_ctx
,
740 if (!W_ERROR_IS_OK(result
)) {
741 printf(_("cannot get printer-info: %s\n"), win_errstr(result
));
748 static bool net_spoolss_setprinter(struct rpc_pipe_client
*pipe_hnd
,
750 struct policy_handle
*hnd
,
752 union spoolss_PrinterInfo
*info
)
756 struct spoolss_SetPrinterInfoCtr info_ctr
;
757 struct spoolss_DevmodeContainer devmode_ctr
;
758 struct sec_desc_buf secdesc_ctr
;
760 ZERO_STRUCT(devmode_ctr
);
761 ZERO_STRUCT(secdesc_ctr
);
763 /* setprinter call */
765 info_ctr
.level
= level
;
768 info_ctr
.info
.info0
= (struct spoolss_SetPrinterInfo0
*)
769 (void *)&info
->info0
;
772 info_ctr
.info
.info1
= (struct spoolss_SetPrinterInfo1
*)
773 (void *)&info
->info1
;
776 info_ctr
.info
.info2
= (struct spoolss_SetPrinterInfo2
*)
777 (void *)&info
->info2
;
780 info_ctr
.info
.info3
= (struct spoolss_SetPrinterInfo3
*)
781 (void *)&info
->info3
;
784 info_ctr
.info
.info4
= (struct spoolss_SetPrinterInfo4
*)
785 (void *)&info
->info4
;
788 info_ctr
.info
.info5
= (struct spoolss_SetPrinterInfo5
*)
789 (void *)&info
->info5
;
792 info_ctr
.info
.info6
= (struct spoolss_SetPrinterInfo6
*)
793 (void *)&info
->info6
;
796 info_ctr
.info
.info7
= (struct spoolss_SetPrinterInfo7
*)
797 (void *)&info
->info7
;
801 info_ctr
.info
.info8
= (struct spoolss_SetPrinterInfo8
*)
802 (void *)&info
->info8
;
805 info_ctr
.info
.info9
= (struct spoolss_SetPrinterInfo9
*)
806 (void *)&info
->info9
;
813 status
= rpccli_spoolss_SetPrinter(pipe_hnd
, mem_ctx
,
821 if (!W_ERROR_IS_OK(result
)) {
822 printf(_("cannot set printer-info: %s\n"), win_errstr(result
));
830 static bool net_spoolss_setprinterdata(struct rpc_pipe_client
*pipe_hnd
,
832 struct policy_handle
*hnd
,
833 const char *value_name
,
834 enum winreg_Type type
,
841 /* setprinterdata call */
842 status
= rpccli_spoolss_SetPrinterData(pipe_hnd
, mem_ctx
,
850 if (!W_ERROR_IS_OK(result
)) {
851 printf (_("unable to set printerdata: %s\n"),
860 static bool net_spoolss_enumprinterkey(struct rpc_pipe_client
*pipe_hnd
,
862 struct policy_handle
*hnd
,
864 const char ***keylist
)
868 /* enumprinterkey call */
869 result
= rpccli_spoolss_enumprinterkey(pipe_hnd
, mem_ctx
, hnd
, keyname
, keylist
, 0);
871 if (!W_ERROR_IS_OK(result
)) {
872 printf(_("enumprinterkey failed: %s\n"), win_errstr(result
));
879 static bool net_spoolss_enumprinterdataex(struct rpc_pipe_client
*pipe_hnd
,
882 struct policy_handle
*hnd
,
885 struct spoolss_PrinterEnumValues
**info
)
889 /* enumprinterdataex call */
890 result
= rpccli_spoolss_enumprinterdataex(pipe_hnd
, mem_ctx
,
897 if (!W_ERROR_IS_OK(result
)) {
898 printf(_("enumprinterdataex failed: %s\n"), win_errstr(result
));
906 static bool net_spoolss_setprinterdataex(struct rpc_pipe_client
*pipe_hnd
,
908 struct policy_handle
*hnd
,
910 struct regval_blob
*value
)
915 /* setprinterdataex call */
916 status
= rpccli_spoolss_SetPrinterDataEx(pipe_hnd
, mem_ctx
,
925 if (!W_ERROR_IS_OK(result
)) {
926 printf(_("could not set printerdataex: %s\n"),
934 static bool net_spoolss_enumforms(struct rpc_pipe_client
*pipe_hnd
,
936 struct policy_handle
*hnd
,
939 union spoolss_FormInfo
**forms
)
944 result
= rpccli_spoolss_enumforms(pipe_hnd
, mem_ctx
,
950 if (!W_ERROR_IS_OK(result
)) {
951 printf(_("could not enum forms: %s\n"), win_errstr(result
));
958 static bool net_spoolss_enumprinterdrivers (struct rpc_pipe_client
*pipe_hnd
,
960 uint32_t level
, const char *env
,
962 union spoolss_DriverInfo
**info
)
966 /* enumprinterdrivers call */
967 result
= rpccli_spoolss_enumprinterdrivers(pipe_hnd
, mem_ctx
,
968 pipe_hnd
->srv_name_slash
,
974 if (!W_ERROR_IS_OK(result
)) {
975 printf(_("cannot enum drivers: %s\n"), win_errstr(result
));
982 static bool net_spoolss_getprinterdriver(struct rpc_pipe_client
*pipe_hnd
,
984 struct policy_handle
*hnd
, uint32_t level
,
985 const char *env
, int version
,
986 union spoolss_DriverInfo
*info
)
989 uint32_t server_major_version
;
990 uint32_t server_minor_version
;
992 /* getprinterdriver call */
993 result
= rpccli_spoolss_getprinterdriver2(pipe_hnd
, mem_ctx
,
1001 &server_major_version
,
1002 &server_minor_version
);
1003 if (!W_ERROR_IS_OK(result
)) {
1004 DEBUG(1,("cannot get driver (for architecture: %s): %s\n",
1005 env
, win_errstr(result
)));
1006 if (W_ERROR_V(result
) != W_ERROR_V(WERR_UNKNOWN_PRINTER_DRIVER
) &&
1007 W_ERROR_V(result
) != W_ERROR_V(WERR_INVALID_ENVIRONMENT
)) {
1008 printf(_("cannot get driver: %s\n"),
1009 win_errstr(result
));
1018 static bool net_spoolss_addprinterdriver(struct rpc_pipe_client
*pipe_hnd
,
1019 TALLOC_CTX
*mem_ctx
, uint32_t level
,
1020 union spoolss_DriverInfo
*info
)
1024 struct spoolss_AddDriverInfoCtr info_ctr
;
1026 info_ctr
.level
= level
;
1030 info_ctr
.info
.info2
= (struct spoolss_AddDriverInfo2
*)
1031 (void *)&info
->info2
;
1034 info_ctr
.info
.info3
= (struct spoolss_AddDriverInfo3
*)
1035 (void *)&info
->info3
;
1038 printf(_("unsupported info level: %d\n"), level
);
1042 /* addprinterdriver call */
1043 status
= rpccli_spoolss_AddPrinterDriver(pipe_hnd
, mem_ctx
,
1044 pipe_hnd
->srv_name_slash
,
1047 /* be more verbose */
1048 if (W_ERROR_V(result
) == W_ERROR_V(WERR_ACCESS_DENIED
)) {
1049 printf(_("You are not allowed to add drivers\n"));
1052 if (!W_ERROR_IS_OK(result
)) {
1053 printf(_("cannot add driver: %s\n"), win_errstr(result
));
1061 * abstraction function to get uint32_t num_printers and PRINTER_INFO_CTR ctr
1062 * for a single printer or for all printers depending on argc/argv
1065 static bool get_printer_info(struct rpc_pipe_client
*pipe_hnd
,
1066 TALLOC_CTX
*mem_ctx
,
1070 uint32_t *num_printers
,
1071 union spoolss_PrinterInfo
**info_p
)
1073 struct policy_handle hnd
;
1075 /* no arguments given, enumerate all printers */
1078 if (!net_spoolss_enum_printers(pipe_hnd
, mem_ctx
, NULL
,
1079 PRINTER_ENUM_LOCAL
|PRINTER_ENUM_SHARED
,
1080 level
, num_printers
, info_p
))
1086 /* argument given, get a single printer by name */
1087 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, argv
[0],
1088 MAXIMUM_ALLOWED_ACCESS
,
1089 pipe_hnd
->auth
->user_name
,
1093 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd
, level
, *info_p
)) {
1094 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd
, NULL
);
1098 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd
, NULL
);
1103 DEBUG(3,("got %d printers\n", *num_printers
));
1110 * List print-queues (including local printers that are not shared)
1112 * All parameters are provided by the run_rpc_command function, except for
1113 * argc, argv which are passed through.
1115 * @param c A net_context structure
1116 * @param domain_sid The domain sid aquired from the remote server
1117 * @param cli A cli_state connected to the server.
1118 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1119 * @param argc Standard main() style argc
1120 * @param argv Standard main() style argv. Initial components are already
1123 * @return Normal NTSTATUS return.
1126 NTSTATUS
rpc_printer_list_internals(struct net_context
*c
,
1127 const DOM_SID
*domain_sid
,
1128 const char *domain_name
,
1129 struct cli_state
*cli
,
1130 struct rpc_pipe_client
*pipe_hnd
,
1131 TALLOC_CTX
*mem_ctx
,
1135 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1136 uint32_t i
, num_printers
;
1138 const char *printername
, *sharename
;
1139 union spoolss_PrinterInfo
*info
;
1141 printf("listing printers\n");
1143 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &info
))
1146 for (i
= 0; i
< num_printers
; i
++) {
1148 /* do some initialization */
1149 printername
= info
[i
].info2
.printername
;
1150 sharename
= info
[i
].info2
.sharename
;
1152 if (printername
&& sharename
) {
1153 d_printf(_("printer %d: %s, shared as: %s\n"),
1154 i
+1, printername
, sharename
);
1158 return NT_STATUS_OK
;
1162 * List printer-drivers from a server
1164 * All parameters are provided by the run_rpc_command function, except for
1165 * argc, argv which are passed through.
1167 * @param c A net_context structure
1168 * @param domain_sid The domain sid aquired from the remote server
1169 * @param cli A cli_state connected to the server.
1170 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1171 * @param argc Standard main() style argc
1172 * @param argv Standard main() style argv. Initial components are already
1175 * @return Normal NTSTATUS return.
1178 NTSTATUS
rpc_printer_driver_list_internals(struct net_context
*c
,
1179 const DOM_SID
*domain_sid
,
1180 const char *domain_name
,
1181 struct cli_state
*cli
,
1182 struct rpc_pipe_client
*pipe_hnd
,
1183 TALLOC_CTX
*mem_ctx
,
1187 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1190 union spoolss_DriverInfo
*info
;
1193 printf(_("listing printer-drivers\n"));
1195 for (i
=0; archi_table
[i
].long_archi
!=NULL
; i
++) {
1197 uint32_t num_drivers
;
1199 /* enum remote drivers */
1200 if (!net_spoolss_enumprinterdrivers(pipe_hnd
, mem_ctx
, level
,
1201 archi_table
[i
].long_archi
,
1202 &num_drivers
, &info
)) {
1203 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1207 if (num_drivers
== 0) {
1208 d_printf(_("no drivers found on server for "
1209 "architecture: [%s].\n"),
1210 archi_table
[i
].long_archi
);
1214 d_printf(_("got %d printer-drivers for architecture: [%s]\n"),
1215 num_drivers
, archi_table
[i
].long_archi
);
1218 /* do something for all drivers for architecture */
1219 for (d
= 0; d
< num_drivers
; d
++) {
1220 display_print_driver3(&info
[d
].info3
);
1224 nt_status
= NT_STATUS_OK
;
1232 * Publish print-queues with args-wrapper
1234 * @param cli A cli_state connected to the server.
1235 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1236 * @param argc Standard main() style argc
1237 * @param argv Standard main() style argv. Initial components are already
1241 * @return Normal NTSTATUS return.
1244 static NTSTATUS
rpc_printer_publish_internals_args(struct rpc_pipe_client
*pipe_hnd
,
1245 TALLOC_CTX
*mem_ctx
,
1250 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1251 uint32_t i
, num_printers
;
1253 const char *printername
, *sharename
;
1254 union spoolss_PrinterInfo
*info_enum
;
1255 union spoolss_PrinterInfo info
;
1256 struct spoolss_SetPrinterInfoCtr info_ctr
;
1257 struct spoolss_DevmodeContainer devmode_ctr
;
1258 struct sec_desc_buf secdesc_ctr
;
1259 struct policy_handle hnd
;
1261 const char *action_str
;
1263 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &info_enum
))
1266 for (i
= 0; i
< num_printers
; i
++) {
1268 /* do some initialization */
1269 printername
= info_enum
[i
].info2
.printername
;
1270 sharename
= info_enum
[i
].info2
.sharename
;
1271 if (!printername
|| !sharename
) {
1275 /* open printer handle */
1276 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1277 PRINTER_ALL_ACCESS
, pipe_hnd
->auth
->user_name
, &hnd
))
1280 /* check for existing dst printer */
1281 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd
, level
, &info
))
1284 /* check action and set string */
1286 case DSPRINT_PUBLISH
:
1287 action_str
= N_("published");
1289 case DSPRINT_UPDATE
:
1290 action_str
= N_("updated");
1292 case DSPRINT_UNPUBLISH
:
1293 action_str
= N_("unpublished");
1296 action_str
= N_("unknown action");
1297 printf(_("unkown action: %d\n"), action
);
1301 info
.info7
.action
= action
;
1303 info_ctr
.info
.info7
= (struct spoolss_SetPrinterInfo7
*)
1304 (void *)&info
.info7
;
1306 ZERO_STRUCT(devmode_ctr
);
1307 ZERO_STRUCT(secdesc_ctr
);
1309 nt_status
= rpccli_spoolss_SetPrinter(pipe_hnd
, mem_ctx
,
1317 if (!W_ERROR_IS_OK(result
) && (W_ERROR_V(result
) != W_ERROR_V(WERR_IO_PENDING
))) {
1318 printf(_("cannot set printer-info: %s\n"),
1319 win_errstr(result
));
1323 printf(_("successfully %s printer %s in Active Directory\n"),
1324 action_str
, sharename
);
1327 nt_status
= NT_STATUS_OK
;
1330 if (is_valid_policy_hnd(&hnd
))
1331 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd
, NULL
);
1336 NTSTATUS
rpc_printer_publish_publish_internals(struct net_context
*c
,
1337 const DOM_SID
*domain_sid
,
1338 const char *domain_name
,
1339 struct cli_state
*cli
,
1340 struct rpc_pipe_client
*pipe_hnd
,
1341 TALLOC_CTX
*mem_ctx
,
1345 return rpc_printer_publish_internals_args(pipe_hnd
, mem_ctx
, argc
, argv
, DSPRINT_PUBLISH
);
1348 NTSTATUS
rpc_printer_publish_unpublish_internals(struct net_context
*c
,
1349 const DOM_SID
*domain_sid
,
1350 const char *domain_name
,
1351 struct cli_state
*cli
,
1352 struct rpc_pipe_client
*pipe_hnd
,
1353 TALLOC_CTX
*mem_ctx
,
1357 return rpc_printer_publish_internals_args(pipe_hnd
, mem_ctx
, argc
, argv
, DSPRINT_UNPUBLISH
);
1360 NTSTATUS
rpc_printer_publish_update_internals(struct net_context
*c
,
1361 const DOM_SID
*domain_sid
,
1362 const char *domain_name
,
1363 struct cli_state
*cli
,
1364 struct rpc_pipe_client
*pipe_hnd
,
1365 TALLOC_CTX
*mem_ctx
,
1369 return rpc_printer_publish_internals_args(pipe_hnd
, mem_ctx
, argc
, argv
, DSPRINT_UPDATE
);
1373 * List print-queues w.r.t. their publishing state
1375 * All parameters are provided by the run_rpc_command function, except for
1376 * argc, argv which are passed through.
1378 * @param c A net_context structure
1379 * @param domain_sid The domain sid aquired from the remote server
1380 * @param cli A cli_state connected to the server.
1381 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1382 * @param argc Standard main() style argc
1383 * @param argv Standard main() style argv. Initial components are already
1386 * @return Normal NTSTATUS return.
1389 NTSTATUS
rpc_printer_publish_list_internals(struct net_context
*c
,
1390 const DOM_SID
*domain_sid
,
1391 const char *domain_name
,
1392 struct cli_state
*cli
,
1393 struct rpc_pipe_client
*pipe_hnd
,
1394 TALLOC_CTX
*mem_ctx
,
1398 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1399 uint32_t i
, num_printers
;
1401 const char *printername
, *sharename
;
1402 union spoolss_PrinterInfo
*info_enum
;
1403 union spoolss_PrinterInfo info
;
1404 struct policy_handle hnd
;
1407 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &info_enum
))
1410 for (i
= 0; i
< num_printers
; i
++) {
1412 /* do some initialization */
1413 printername
= info_enum
[i
].info2
.printername
;
1414 sharename
= info_enum
[i
].info2
.sharename
;
1416 if (!printername
|| !sharename
) {
1420 /* open printer handle */
1421 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1422 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd
))
1425 /* check for existing dst printer */
1426 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd
, level
, &info
))
1429 if (!info
.info7
.guid
) {
1432 state
= info
.info7
.action
;
1434 case DSPRINT_PUBLISH
:
1435 printf(_("printer [%s] is published"),
1438 printf(_(", guid: %s"),info
.info7
.guid
);
1441 case DSPRINT_UNPUBLISH
:
1442 printf(_("printer [%s] is unpublished\n"),
1445 case DSPRINT_UPDATE
:
1446 printf(_("printer [%s] is currently updating\n"),
1450 printf(_("unkown state: %d\n"), state
);
1455 nt_status
= NT_STATUS_OK
;
1458 if (is_valid_policy_hnd(&hnd
))
1459 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd
, NULL
);
1465 * Migrate Printer-ACLs from a source server to the destination server
1467 * All parameters are provided by the run_rpc_command function, except for
1468 * argc, argv which are passed through.
1470 * @param c A net_context structure
1471 * @param domain_sid The domain sid aquired from the remote server
1472 * @param cli A cli_state connected to the server.
1473 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1474 * @param argc Standard main() style argc
1475 * @param argv Standard main() style argv. Initial components are already
1478 * @return Normal NTSTATUS return.
1481 NTSTATUS
rpc_printer_migrate_security_internals(struct net_context
*c
,
1482 const DOM_SID
*domain_sid
,
1483 const char *domain_name
,
1484 struct cli_state
*cli
,
1485 struct rpc_pipe_client
*pipe_hnd
,
1486 TALLOC_CTX
*mem_ctx
,
1490 /* TODO: what now, info2 or info3 ?
1491 convince jerry that we should add clientside setacls level 3 at least
1493 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1495 uint32_t num_printers
;
1497 const char *printername
, *sharename
;
1498 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
1499 struct policy_handle hnd_src
, hnd_dst
;
1500 union spoolss_PrinterInfo
*info_enum
;
1501 struct cli_state
*cli_dst
= NULL
;
1502 union spoolss_PrinterInfo info_src
, info_dst
;
1504 DEBUG(3,("copying printer ACLs\n"));
1506 /* connect destination PI_SPOOLSS */
1507 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
,
1508 &ndr_table_spoolss
.syntax_id
);
1509 if (!NT_STATUS_IS_OK(nt_status
))
1513 /* enum source printers */
1514 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &info_enum
)) {
1515 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1519 if (!num_printers
) {
1520 printf (_("no printers found on server.\n"));
1521 nt_status
= NT_STATUS_OK
;
1525 /* do something for all printers */
1526 for (i
= 0; i
< num_printers
; i
++) {
1528 /* do some initialization */
1529 printername
= info_enum
[i
].info2
.printername
;
1530 sharename
= info_enum
[i
].info2
.sharename
;
1532 if (!printername
|| !sharename
) {
1533 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1537 /* we can reset NT_STATUS here because we do not
1538 get any real NT_STATUS-codes anymore from now on */
1539 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1541 d_printf(_("migrating printer ACLs for: [%s] / [%s]\n"),
1542 printername
, sharename
);
1544 /* according to msdn you have specify these access-rights
1545 to see the security descriptor
1546 - READ_CONTROL (DACL)
1547 - ACCESS_SYSTEM_SECURITY (SACL)
1550 /* open src printer handle */
1551 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1552 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
1555 /* open dst printer handle */
1556 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
1557 PRINTER_ALL_ACCESS
, cli_dst
->user_name
, &hnd_dst
))
1560 /* check for existing dst printer */
1561 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, level
, &info_dst
))
1564 /* check for existing src printer */
1565 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd_src
, 3, &info_src
))
1568 /* Copy Security Descriptor */
1570 /* copy secdesc (info level 2) */
1571 info_dst
.info2
.devmode
= NULL
;
1572 info_dst
.info2
.secdesc
= dup_sec_desc(mem_ctx
, info_src
.info3
.secdesc
);
1575 display_sec_desc(info_dst
.info2
.secdesc
);
1577 if (!net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 2, &info_dst
))
1580 DEBUGADD(1,("\tSetPrinter of SECDESC succeeded\n"));
1583 /* close printer handles here */
1584 if (is_valid_policy_hnd(&hnd_src
)) {
1585 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
1588 if (is_valid_policy_hnd(&hnd_dst
)) {
1589 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
1594 nt_status
= NT_STATUS_OK
;
1598 if (is_valid_policy_hnd(&hnd_src
)) {
1599 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
1602 if (is_valid_policy_hnd(&hnd_dst
)) {
1603 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
1607 cli_shutdown(cli_dst
);
1613 * Migrate printer-forms from a src server to the dst server
1615 * All parameters are provided by the run_rpc_command function, except for
1616 * argc, argv which are passed through.
1618 * @param c A net_context structure
1619 * @param domain_sid The domain sid aquired from the remote server
1620 * @param cli A cli_state connected to the server.
1621 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1622 * @param argc Standard main() style argc
1623 * @param argv Standard main() style argv. Initial components are already
1626 * @return Normal NTSTATUS return.
1629 NTSTATUS
rpc_printer_migrate_forms_internals(struct net_context
*c
,
1630 const DOM_SID
*domain_sid
,
1631 const char *domain_name
,
1632 struct cli_state
*cli
,
1633 struct rpc_pipe_client
*pipe_hnd
,
1634 TALLOC_CTX
*mem_ctx
,
1638 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1641 uint32_t num_printers
;
1643 const char *printername
, *sharename
;
1644 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
1645 struct policy_handle hnd_src
, hnd_dst
;
1646 union spoolss_PrinterInfo
*info_enum
;
1647 union spoolss_PrinterInfo info_dst
;
1649 union spoolss_FormInfo
*forms
;
1650 struct cli_state
*cli_dst
= NULL
;
1652 DEBUG(3,("copying forms\n"));
1654 /* connect destination PI_SPOOLSS */
1655 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
,
1656 &ndr_table_spoolss
.syntax_id
);
1657 if (!NT_STATUS_IS_OK(nt_status
))
1660 /* enum src printers */
1661 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &info_enum
)) {
1662 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1666 if (!num_printers
) {
1667 printf (_("no printers found on server.\n"));
1668 nt_status
= NT_STATUS_OK
;
1672 /* do something for all printers */
1673 for (i
= 0; i
< num_printers
; i
++) {
1675 /* do some initialization */
1676 printername
= info_enum
[i
].info2
.printername
;
1677 sharename
= info_enum
[i
].info2
.sharename
;
1679 if (!printername
|| !sharename
) {
1680 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1683 /* we can reset NT_STATUS here because we do not
1684 get any real NT_STATUS-codes anymore from now on */
1685 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1687 d_printf(_("migrating printer forms for: [%s] / [%s]\n"),
1688 printername
, sharename
);
1691 /* open src printer handle */
1692 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1693 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
1696 /* open dst printer handle */
1697 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
1698 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd_dst
))
1701 /* check for existing dst printer */
1702 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, level
, &info_dst
))
1705 /* finally migrate forms */
1706 if (!net_spoolss_enumforms(pipe_hnd
, mem_ctx
, &hnd_src
, level
, &num_forms
, &forms
))
1709 DEBUG(1,("got %d forms for printer\n", num_forms
));
1712 for (f
= 0; f
< num_forms
; f
++) {
1714 union spoolss_AddFormInfo info
;
1717 /* only migrate FORM_PRINTER types, according to jerry
1718 FORM_BUILTIN-types are hard-coded in samba */
1719 if (forms
[f
].info1
.flags
!= SPOOLSS_FORM_PRINTER
)
1723 d_printf(_("\tmigrating form # %d [%s] of type "
1725 f
, forms
[f
].info1
.form_name
,
1726 forms
[f
].info1
.flags
);
1728 info
.info1
= (struct spoolss_AddFormInfo1
*)
1729 (void *)&forms
[f
].info1
;
1731 /* FIXME: there might be something wrong with samba's
1733 status
= rpccli_spoolss_AddForm(pipe_hnd_dst
, mem_ctx
,
1738 if (!W_ERROR_IS_OK(result
)) {
1739 d_printf(_("\tAddForm form %d: [%s] refused.\n"),
1740 f
, forms
[f
].info1
.form_name
);
1744 DEBUGADD(1,("\tAddForm of [%s] succeeded\n",
1745 forms
[f
].info1
.form_name
));
1749 /* close printer handles here */
1750 if (is_valid_policy_hnd(&hnd_src
)) {
1751 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
1754 if (is_valid_policy_hnd(&hnd_dst
)) {
1755 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
1759 nt_status
= NT_STATUS_OK
;
1763 if (is_valid_policy_hnd(&hnd_src
))
1764 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
1766 if (is_valid_policy_hnd(&hnd_dst
))
1767 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
1770 cli_shutdown(cli_dst
);
1776 * Migrate printer-drivers from a src server to the dst server
1778 * All parameters are provided by the run_rpc_command function, except for
1779 * argc, argv which are passed through.
1781 * @param c A net_context structure
1782 * @param domain_sid The domain sid aquired from the remote server
1783 * @param cli A cli_state connected to the server.
1784 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1785 * @param argc Standard main() style argc
1786 * @param argv Standard main() style argv. Initial components are already
1789 * @return Normal NTSTATUS return.
1792 NTSTATUS
rpc_printer_migrate_drivers_internals(struct net_context
*c
,
1793 const DOM_SID
*domain_sid
,
1794 const char *domain_name
,
1795 struct cli_state
*cli
,
1796 struct rpc_pipe_client
*pipe_hnd
,
1797 TALLOC_CTX
*mem_ctx
,
1801 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1803 uint32_t num_printers
;
1805 const char *printername
, *sharename
;
1806 bool got_src_driver_share
= false;
1807 bool got_dst_driver_share
= false;
1808 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
1809 struct policy_handle hnd_src
, hnd_dst
;
1810 union spoolss_DriverInfo drv_info_src
;
1811 union spoolss_PrinterInfo
*info_enum
;
1812 union spoolss_PrinterInfo info_dst
;
1813 struct cli_state
*cli_dst
= NULL
;
1814 struct cli_state
*cli_share_src
= NULL
;
1815 struct cli_state
*cli_share_dst
= NULL
;
1816 const char *drivername
= NULL
;
1818 DEBUG(3,("copying printer-drivers\n"));
1820 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
,
1821 &ndr_table_spoolss
.syntax_id
);
1822 if (!NT_STATUS_IS_OK(nt_status
))
1825 /* open print$-share on the src server */
1826 nt_status
= connect_to_service(c
, &cli_share_src
, &cli
->dest_ss
,
1827 cli
->desthost
, "print$", "A:");
1828 if (!NT_STATUS_IS_OK(nt_status
))
1831 got_src_driver_share
= true;
1834 /* open print$-share on the dst server */
1835 nt_status
= connect_to_service(c
, &cli_share_dst
, &cli_dst
->dest_ss
,
1836 cli_dst
->desthost
, "print$", "A:");
1837 if (!NT_STATUS_IS_OK(nt_status
))
1840 got_dst_driver_share
= true;
1843 /* enum src printers */
1844 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &info_enum
)) {
1845 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1849 if (num_printers
== 0) {
1850 printf (_("no printers found on server.\n"));
1851 nt_status
= NT_STATUS_OK
;
1856 /* do something for all printers */
1857 for (p
= 0; p
< num_printers
; p
++) {
1859 /* do some initialization */
1860 printername
= info_enum
[p
].info2
.printername
;
1861 sharename
= info_enum
[p
].info2
.sharename
;
1863 if (!printername
|| !sharename
) {
1864 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1868 /* we can reset NT_STATUS here because we do not
1869 get any real NT_STATUS-codes anymore from now on */
1870 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1872 d_printf(_("migrating printer driver for: [%s] / [%s]\n"),
1873 printername
, sharename
);
1875 /* open dst printer handle */
1876 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
1877 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd_dst
))
1880 /* check for existing dst printer */
1881 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 2, &info_dst
))
1885 /* open src printer handle */
1886 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1887 MAXIMUM_ALLOWED_ACCESS
,
1888 pipe_hnd
->auth
->user_name
,
1892 /* in a first step call getdriver for each shared printer (per arch)
1893 to get a list of all files that have to be copied */
1895 for (i
=0; archi_table
[i
].long_archi
!=NULL
; i
++) {
1898 if (!net_spoolss_getprinterdriver(pipe_hnd
, mem_ctx
, &hnd_src
,
1899 level
, archi_table
[i
].long_archi
,
1900 archi_table
[i
].version
, &drv_info_src
))
1903 drivername
= drv_info_src
.info3
.driver_name
;
1906 display_print_driver3(&drv_info_src
.info3
);
1908 /* check arch dir */
1909 nt_status
= check_arch_dir(cli_share_dst
, archi_table
[i
].short_archi
);
1910 if (!NT_STATUS_IS_OK(nt_status
))
1914 /* copy driver-files */
1915 nt_status
= copy_print_driver_3(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
1916 archi_table
[i
].short_archi
,
1917 &drv_info_src
.info3
);
1918 if (!NT_STATUS_IS_OK(nt_status
))
1923 if (!net_spoolss_addprinterdriver(pipe_hnd_dst
, mem_ctx
, level
, &drv_info_src
)) {
1924 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1928 DEBUGADD(1,("Sucessfully added driver [%s] for printer [%s]\n",
1929 drivername
, printername
));
1933 if (!drivername
|| strlen(drivername
) == 0) {
1934 DEBUGADD(1,("Did not get driver for printer %s\n",
1940 info_dst
.info2
.drivername
= drivername
;
1942 if (!net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 2, &info_dst
)) {
1943 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1947 DEBUGADD(1,("Sucessfully set driver %s for printer %s\n",
1948 drivername
, printername
));
1951 if (is_valid_policy_hnd(&hnd_dst
)) {
1952 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
1956 if (is_valid_policy_hnd(&hnd_src
)) {
1957 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
1961 nt_status
= NT_STATUS_OK
;
1965 if (is_valid_policy_hnd(&hnd_src
))
1966 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
1968 if (is_valid_policy_hnd(&hnd_dst
))
1969 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
1972 cli_shutdown(cli_dst
);
1975 if (got_src_driver_share
)
1976 cli_shutdown(cli_share_src
);
1978 if (got_dst_driver_share
)
1979 cli_shutdown(cli_share_dst
);
1986 * Migrate printer-queues from a src to the dst server
1987 * (requires a working "addprinter command" to be installed for the local smbd)
1989 * All parameters are provided by the run_rpc_command function, except for
1990 * argc, argv which are passed through.
1992 * @param c A net_context structure
1993 * @param domain_sid The domain sid aquired from the remote server
1994 * @param cli A cli_state connected to the server.
1995 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1996 * @param argc Standard main() style argc
1997 * @param argv Standard main() style argv. Initial components are already
2000 * @return Normal NTSTATUS return.
2003 NTSTATUS
rpc_printer_migrate_printers_internals(struct net_context
*c
,
2004 const DOM_SID
*domain_sid
,
2005 const char *domain_name
,
2006 struct cli_state
*cli
,
2007 struct rpc_pipe_client
*pipe_hnd
,
2008 TALLOC_CTX
*mem_ctx
,
2013 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
2014 uint32_t i
= 0, num_printers
;
2016 union spoolss_PrinterInfo info_dst
, info_src
;
2017 union spoolss_PrinterInfo
*info_enum
;
2018 struct cli_state
*cli_dst
= NULL
;
2019 struct policy_handle hnd_dst
, hnd_src
;
2020 const char *printername
, *sharename
;
2021 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
2022 struct spoolss_SetPrinterInfoCtr info_ctr
;
2024 DEBUG(3,("copying printers\n"));
2026 /* connect destination PI_SPOOLSS */
2027 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
,
2028 &ndr_table_spoolss
.syntax_id
);
2029 if (!NT_STATUS_IS_OK(nt_status
))
2033 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &info_enum
)) {
2034 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2038 if (!num_printers
) {
2039 printf (_("no printers found on server.\n"));
2040 nt_status
= NT_STATUS_OK
;
2044 /* do something for all printers */
2045 for (i
= 0; i
< num_printers
; i
++) {
2047 /* do some initialization */
2048 printername
= info_enum
[i
].info2
.printername
;
2049 sharename
= info_enum
[i
].info2
.sharename
;
2051 if (!printername
|| !sharename
) {
2052 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2055 /* we can reset NT_STATUS here because we do not
2056 get any real NT_STATUS-codes anymore from now on */
2057 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2059 d_printf(_("migrating printer queue for: [%s] / [%s]\n"),
2060 printername
, sharename
);
2062 /* open dst printer handle */
2063 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
2064 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd_dst
)) {
2066 DEBUG(1,("could not open printer: %s\n", sharename
));
2069 /* check for existing dst printer */
2070 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, level
, &info_dst
)) {
2071 printf (_("could not get printer, creating printer.\n"));
2073 DEBUG(1,("printer already exists: %s\n", sharename
));
2074 /* close printer handle here - dst only, not got src yet. */
2075 if (is_valid_policy_hnd(&hnd_dst
)) {
2076 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
2081 /* now get again src printer ctr via getprinter,
2082 we first need a handle for that */
2084 /* open src printer handle */
2085 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
2086 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
2089 /* getprinter on the src server */
2090 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd_src
, level
, &info_src
))
2093 /* copy each src printer to a dst printer 1:1,
2094 maybe some values have to be changed though */
2095 d_printf(_("creating printer: %s\n"), printername
);
2097 info_ctr
.level
= level
;
2098 info_ctr
.info
.info2
= (struct spoolss_SetPrinterInfo2
*)
2099 (void *)&info_src
.info2
;
2101 result
= rpccli_spoolss_addprinterex(pipe_hnd_dst
,
2105 if (W_ERROR_IS_OK(result
))
2106 d_printf (_("printer [%s] successfully added.\n"),
2108 else if (W_ERROR_V(result
) == W_ERROR_V(WERR_PRINTER_ALREADY_EXISTS
))
2109 d_fprintf (stderr
, _("printer [%s] already exists.\n"),
2112 d_fprintf (stderr
, _("could not create printer [%s]\n"),
2117 /* close printer handles here */
2118 if (is_valid_policy_hnd(&hnd_src
)) {
2119 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
2122 if (is_valid_policy_hnd(&hnd_dst
)) {
2123 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
2127 nt_status
= NT_STATUS_OK
;
2130 if (is_valid_policy_hnd(&hnd_src
))
2131 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
2133 if (is_valid_policy_hnd(&hnd_dst
))
2134 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
2137 cli_shutdown(cli_dst
);
2143 * Migrate Printer-Settings from a src server to the dst server
2144 * (for this to work, printers and drivers already have to be migrated earlier)
2146 * All parameters are provided by the run_rpc_command function, except for
2147 * argc, argv which are passed through.
2149 * @param c A net_context structure
2150 * @param domain_sid The domain sid aquired from the remote server
2151 * @param cli A cli_state connected to the server.
2152 * @param mem_ctx Talloc context, destoyed on compleation of the function.
2153 * @param argc Standard main() style argc
2154 * @param argv Standard main() style argv. Initial components are already
2157 * @return Normal NTSTATUS return.
2160 NTSTATUS
rpc_printer_migrate_settings_internals(struct net_context
*c
,
2161 const DOM_SID
*domain_sid
,
2162 const char *domain_name
,
2163 struct cli_state
*cli
,
2164 struct rpc_pipe_client
*pipe_hnd
,
2165 TALLOC_CTX
*mem_ctx
,
2170 /* FIXME: Here the nightmare begins */
2173 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
2174 uint32_t i
= 0, p
= 0, j
= 0;
2175 uint32_t num_printers
;
2177 const char *printername
, *sharename
;
2178 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
2179 struct policy_handle hnd_src
, hnd_dst
;
2180 union spoolss_PrinterInfo
*info_enum
;
2181 union spoolss_PrinterInfo info_dst_publish
;
2182 union spoolss_PrinterInfo info_dst
;
2183 struct cli_state
*cli_dst
= NULL
;
2184 char *devicename
= NULL
, *unc_name
= NULL
, *url
= NULL
;
2185 const char *longname
;
2186 const char **keylist
= NULL
;
2189 ZERO_STRUCT(info_dst_publish
);
2191 DEBUG(3,("copying printer settings\n"));
2193 /* connect destination PI_SPOOLSS */
2194 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
,
2195 &ndr_table_spoolss
.syntax_id
);
2196 if (!NT_STATUS_IS_OK(nt_status
))
2199 /* enum src printers */
2200 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &info_enum
)) {
2201 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2205 if (!num_printers
) {
2206 printf (_("no printers found on server.\n"));
2207 nt_status
= NT_STATUS_OK
;
2212 /* needed for dns-strings in regkeys */
2213 longname
= get_mydnsfullname();
2215 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2219 /* do something for all printers */
2220 for (i
= 0; i
< num_printers
; i
++) {
2222 uint32_t value_offered
= 0, value_needed
;
2223 uint32_t data_offered
= 0, data_needed
;
2224 enum winreg_Type type
;
2225 uint8_t *buffer
= NULL
;
2226 const char *value_name
= NULL
;
2228 /* do some initialization */
2229 printername
= info_enum
[i
].info2
.printername
;
2230 sharename
= info_enum
[i
].info2
.sharename
;
2232 if (!printername
|| !sharename
) {
2233 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2236 /* we can reset NT_STATUS here because we do not
2237 get any real NT_STATUS-codes anymore from now on */
2238 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2240 d_printf(_("migrating printer settings for: [%s] / [%s]\n"),
2241 printername
, sharename
);
2244 /* open src printer handle */
2245 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
2246 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
2249 /* open dst printer handle */
2250 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
2251 PRINTER_ALL_ACCESS
, cli_dst
->user_name
, &hnd_dst
))
2254 /* check for existing dst printer */
2255 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
,
2260 /* STEP 1: COPY DEVICE-MODE and other
2261 PRINTER_INFO_2-attributes
2264 info_dst
.info2
= info_enum
[i
].info2
;
2266 /* why is the port always disconnected when the printer
2267 is correctly installed (incl. driver ???) */
2268 info_dst
.info2
.portname
= SAMBA_PRINTER_PORT_NAME
;
2270 /* check if printer is published */
2271 if (info_enum
[i
].info2
.attributes
& PRINTER_ATTRIBUTE_PUBLISHED
) {
2273 /* check for existing dst printer */
2274 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 7, &info_dst_publish
))
2277 info_dst_publish
.info7
.action
= DSPRINT_PUBLISH
;
2279 /* ignore false from setprinter due to WERR_IO_PENDING */
2280 net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 7, &info_dst_publish
);
2282 DEBUG(3,("republished printer\n"));
2285 if (info_enum
[i
].info2
.devmode
!= NULL
) {
2287 /* copy devmode (info level 2) */
2288 info_dst
.info2
.devmode
= info_enum
[i
].info2
.devmode
;
2290 /* do not copy security descriptor (we have another
2291 * command for that) */
2292 info_dst
.info2
.secdesc
= NULL
;
2295 info_dst
.info2
.devmode
.devicename
=
2296 talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
2297 longname
, printername
);
2298 if (!info_dst
.info2
.devmode
.devicename
) {
2299 nt_status
= NT_STATUS_NO_MEMORY
;
2303 if (!net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
,
2307 DEBUGADD(1,("\tSetPrinter of DEVICEMODE succeeded\n"));
2310 /* STEP 2: COPY REGISTRY VALUES */
2312 /* please keep in mind that samba parse_spools gives horribly
2313 crippled results when used to rpccli_spoolss_enumprinterdataex
2314 a win2k3-server. (Bugzilla #1851)
2315 FIXME: IIRC I've seen it too on a win2k-server
2318 /* enumerate data on src handle */
2319 nt_status
= rpccli_spoolss_EnumPrinterData(pipe_hnd
, mem_ctx
,
2331 data_offered
= data_needed
;
2332 value_offered
= value_needed
;
2333 buffer
= talloc_zero_array(mem_ctx
, uint8_t, data_needed
);
2334 value_name
= talloc_zero_array(mem_ctx
, char, value_needed
);
2336 /* loop for all printerdata of "PrinterDriverData" */
2337 while (NT_STATUS_IS_OK(nt_status
) && W_ERROR_IS_OK(result
)) {
2339 nt_status
= rpccli_spoolss_EnumPrinterData(pipe_hnd
, mem_ctx
,
2350 /* loop for all reg_keys */
2351 if (NT_STATUS_IS_OK(nt_status
) && W_ERROR_IS_OK(result
)) {
2353 struct regval_blob v
;
2356 if (c
->opt_verbose
) {
2357 fstrcpy(v
.valuename
, value_name
);
2359 v
.size
= data_offered
;
2361 display_reg_value(SPOOL_PRINTERDATA_KEY
, v
);
2365 if (!net_spoolss_setprinterdata(pipe_hnd_dst
, mem_ctx
,
2366 &hnd_dst
, value_name
,
2367 type
, buffer
, data_offered
))
2370 DEBUGADD(1,("\tSetPrinterData of [%s] succeeded\n",
2375 /* STEP 3: COPY SUBKEY VALUES */
2377 /* here we need to enum all printer_keys and then work
2378 on the result with enum_printer_key_ex. nt4 does not
2379 respond to enumprinterkey, win2k does, so continue
2380 in case of an error */
2382 if (!net_spoolss_enumprinterkey(pipe_hnd
, mem_ctx
, &hnd_src
, "", &keylist
)) {
2383 printf(_("got no key-data\n"));
2388 /* work on a list of printer keys
2389 each key has to be enumerated to get all required
2390 information. information is then set via setprinterdataex-calls */
2392 if (keylist
== NULL
)
2395 for (i
=0; keylist
&& keylist
[i
] != NULL
; i
++) {
2397 const char *subkey
= keylist
[i
];
2399 struct spoolss_PrinterEnumValues
*info
;
2401 /* enumerate all src subkeys */
2402 if (!net_spoolss_enumprinterdataex(pipe_hnd
, mem_ctx
, 0,
2408 for (j
=0; j
< count
; j
++) {
2410 struct regval_blob value
;
2413 /* although samba replies with sane data in most cases we
2414 should try to avoid writing wrong registry data */
2416 if (strequal(info
[j
].value_name
, SPOOL_REG_PORTNAME
) ||
2417 strequal(info
[j
].value_name
, SPOOL_REG_UNCNAME
) ||
2418 strequal(info
[j
].value_name
, SPOOL_REG_URL
) ||
2419 strequal(info
[j
].value_name
, SPOOL_REG_SHORTSERVERNAME
) ||
2420 strequal(info
[j
].value_name
, SPOOL_REG_SERVERNAME
)) {
2422 if (strequal(info
[j
].value_name
, SPOOL_REG_PORTNAME
)) {
2424 /* although windows uses a multi-sz, we use a sz */
2425 push_reg_sz(mem_ctx
, NULL
, &blob
, SAMBA_PRINTER_PORT_NAME
);
2426 fstrcpy(value
.valuename
, SPOOL_REG_PORTNAME
);
2429 if (strequal(info
[j
].value_name
, SPOOL_REG_UNCNAME
)) {
2431 if (asprintf(&unc_name
, "\\\\%s\\%s", longname
, sharename
) < 0) {
2432 nt_status
= NT_STATUS_NO_MEMORY
;
2435 push_reg_sz(mem_ctx
, NULL
, &blob
, unc_name
);
2436 fstrcpy(value
.valuename
, SPOOL_REG_UNCNAME
);
2439 if (strequal(info
[j
].value_name
, SPOOL_REG_URL
)) {
2444 /* FIXME: should we really do that ??? */
2445 if (asprintf(&url
, "http://%s:631/printers/%s", longname
, sharename
) < 0) {
2446 nt_status
= NT_STATUS_NO_MEMORY
;
2449 push_reg_sz(mem_ctx
, NULL
, &blob
, url
);
2450 fstrcpy(value
.valuename
, SPOOL_REG_URL
);
2454 if (strequal(info
[j
].value_name
, SPOOL_REG_SERVERNAME
)) {
2456 push_reg_sz(mem_ctx
, NULL
, &blob
, longname
);
2457 fstrcpy(value
.valuename
, SPOOL_REG_SERVERNAME
);
2460 if (strequal(info
[j
].value_name
, SPOOL_REG_SHORTSERVERNAME
)) {
2462 push_reg_sz(mem_ctx
, NULL
, &blob
, global_myname());
2463 fstrcpy(value
.valuename
, SPOOL_REG_SHORTSERVERNAME
);
2466 value
.type
= REG_SZ
;
2467 value
.size
= blob
.length
;
2469 value
.data_p
= blob
.data
;
2471 value
.data_p
= NULL
;
2475 display_reg_value(subkey
, value
);
2477 /* here we have to set all subkeys on the dst server */
2478 if (!net_spoolss_setprinterdataex(pipe_hnd_dst
, mem_ctx
, &hnd_dst
,
2484 struct regval_blob v
;
2486 fstrcpy(v
.valuename
, info
[j
].value_name
);
2487 v
.type
= info
[j
].type
;
2488 v
.data_p
= info
[j
].data
->data
;
2489 v
.size
= info
[j
].data
->length
;
2491 if (c
->opt_verbose
) {
2492 display_reg_value(subkey
, v
);
2495 /* here we have to set all subkeys on the dst server */
2496 if (!net_spoolss_setprinterdataex(pipe_hnd_dst
, mem_ctx
, &hnd_dst
,
2503 DEBUGADD(1,("\tSetPrinterDataEx of key [%s\\%s] succeeded\n",
2504 subkey
, info
[j
].value_name
));
2509 TALLOC_FREE(keylist
);
2511 /* close printer handles here */
2512 if (is_valid_policy_hnd(&hnd_src
)) {
2513 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
2516 if (is_valid_policy_hnd(&hnd_dst
)) {
2517 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
2522 nt_status
= NT_STATUS_OK
;
2525 SAFE_FREE(devicename
);
2527 SAFE_FREE(unc_name
);
2529 if (is_valid_policy_hnd(&hnd_src
))
2530 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
2532 if (is_valid_policy_hnd(&hnd_dst
))
2533 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
2536 cli_shutdown(cli_dst
);