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"
23 const char *long_archi
;
24 const char *short_archi
;
29 /* support itanium as well */
30 static const struct table_node archi_table
[]= {
32 {"Windows 4.0", "WIN40", 0 },
33 {"Windows NT x86", "W32X86", 2 },
34 {"Windows NT x86", "W32X86", 3 },
35 {"Windows NT R4000", "W32MIPS", 2 },
36 {"Windows NT Alpha_AXP", "W32ALPHA", 2 },
37 {"Windows NT PowerPC", "W32PPC", 2 },
38 {"Windows IA64", "IA64", 3 },
39 {"Windows x64", "x64", 3 },
45 * This display-printdriver-functions was borrowed from rpcclient/cmd_spoolss.c.
46 * It is here for debugging purpose and should be removed later on.
49 /****************************************************************************
50 Printer info level 3 display function.
51 ****************************************************************************/
53 static void display_print_driver3(struct spoolss_DriverInfo3
*r
)
61 printf("Printer Driver Info 3:\n");
62 printf("\tVersion: [%x]\n", r
->version
);
63 printf("\tDriver Name: [%s]\n", r
->driver_name
);
64 printf("\tArchitecture: [%s]\n", r
->architecture
);
65 printf("\tDriver Path: [%s]\n", r
->driver_path
);
66 printf("\tDatafile: [%s]\n", r
->data_file
);
67 printf("\tConfigfile: [%s]\n\n", r
->config_file
);
68 printf("\tHelpfile: [%s]\n\n", r
->help_file
);
70 for (i
=0; r
->dependent_files
[i
] != NULL
; i
++) {
71 printf("\tDependentfiles: [%s]\n", r
->dependent_files
[i
]);
76 printf("\tMonitorname: [%s]\n", r
->monitor_name
);
77 printf("\tDefaultdatatype: [%s]\n\n", r
->default_datatype
);
80 static void display_reg_value(const char *subkey
, REGISTRY_VALUE value
)
86 d_printf("\t[%s:%s]: REG_DWORD: 0x%08x\n", subkey
, value
.valuename
,
87 *((uint32_t *) value
.data_p
));
91 rpcstr_pull_talloc(talloc_tos(),
99 d_printf("\t[%s:%s]: REG_SZ: %s\n", subkey
, value
.valuename
, text
);
103 d_printf("\t[%s:%s]: REG_BINARY: unknown length value not displayed\n",
104 subkey
, value
.valuename
);
108 uint32_t i
, num_values
;
111 if (!W_ERROR_IS_OK(reg_pull_multi_sz(NULL
, value
.data_p
,
112 value
.size
, &num_values
,
114 d_printf("reg_pull_multi_sz failed\n");
118 for (i
=0; i
<num_values
; i
++) {
119 d_printf("%s\n", values
[i
]);
126 d_printf("\t%s: unknown type %d\n", value
.valuename
, value
.type
);
132 * Copies ACLs, DOS-attributes and timestamps from one
133 * file or directory from one connected share to another connected share
135 * @param c A net_context structure
136 * @param mem_ctx A talloc-context
137 * @param cli_share_src A connected cli_state
138 * @param cli_share_dst A connected cli_state
139 * @param src_file The source file-name
140 * @param dst_file The destination file-name
141 * @param copy_acls Whether to copy acls
142 * @param copy_attrs Whether to copy DOS attributes
143 * @param copy_timestamps Whether to preserve timestamps
144 * @param is_file Whether this file is a file or a dir
146 * @return Normal NTSTATUS return.
149 NTSTATUS
net_copy_fileattr(struct net_context
*c
,
151 struct cli_state
*cli_share_src
,
152 struct cli_state
*cli_share_dst
,
153 const char *src_name
, const char *dst_name
,
154 bool copy_acls
, bool copy_attrs
,
155 bool copy_timestamps
, bool is_file
)
157 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
162 time_t f_atime
, f_ctime
, f_mtime
;
165 if (!copy_timestamps
&& !copy_acls
&& !copy_attrs
)
168 /* open file/dir on the originating server */
170 DEBUGADD(3,("opening %s %s on originating server\n",
171 is_file
?"file":"dir", src_name
));
173 fnum_src
= cli_nt_create(cli_share_src
, src_name
, READ_CONTROL_ACCESS
);
174 if (fnum_src
== -1) {
175 DEBUGADD(0,("cannot open %s %s on originating server %s\n",
176 is_file
?"file":"dir", src_name
, cli_errstr(cli_share_src
)));
177 nt_status
= cli_nt_error(cli_share_src
);
184 /* get the security descriptor */
185 sd
= cli_query_secdesc(cli_share_src
, fnum_src
, mem_ctx
);
187 DEBUG(0,("failed to get security descriptor: %s\n",
188 cli_errstr(cli_share_src
)));
189 nt_status
= cli_nt_error(cli_share_src
);
193 if (c
->opt_verbose
&& DEBUGLEVEL
>= 3)
194 display_sec_desc(sd
);
198 if (copy_attrs
|| copy_timestamps
) {
200 /* get file attributes */
201 if (!cli_getattrE(cli_share_src
, fnum_src
, &attr
, NULL
,
202 &f_ctime
, &f_atime
, &f_mtime
)) {
203 DEBUG(0,("failed to get file-attrs: %s\n",
204 cli_errstr(cli_share_src
)));
205 nt_status
= cli_nt_error(cli_share_src
);
211 /* open the file/dir on the destination server */
213 fnum_dst
= cli_nt_create(cli_share_dst
, dst_name
, WRITE_DAC_ACCESS
| WRITE_OWNER_ACCESS
);
214 if (fnum_dst
== -1) {
215 DEBUG(0,("failed to open %s on the destination server: %s: %s\n",
216 is_file
?"file":"dir", dst_name
, cli_errstr(cli_share_dst
)));
217 nt_status
= cli_nt_error(cli_share_dst
);
221 if (copy_timestamps
) {
224 if (!cli_setattrE(cli_share_dst
, fnum_dst
, f_ctime
, f_atime
, f_mtime
)) {
225 DEBUG(0,("failed to set file-attrs (timestamps): %s\n",
226 cli_errstr(cli_share_dst
)));
227 nt_status
= cli_nt_error(cli_share_dst
);
235 if (!cli_set_secdesc(cli_share_dst
, fnum_dst
, sd
)) {
236 DEBUG(0,("could not set secdesc on %s: %s\n",
237 dst_name
, cli_errstr(cli_share_dst
)));
238 nt_status
= cli_nt_error(cli_share_dst
);
246 if (!cli_setatr(cli_share_dst
, dst_name
, attr
, 0)) {
247 DEBUG(0,("failed to set file-attrs: %s\n",
248 cli_errstr(cli_share_dst
)));
249 nt_status
= cli_nt_error(cli_share_dst
);
257 if (!cli_close(cli_share_src
, fnum_src
)) {
258 d_fprintf(stderr
, "could not close %s on originating server: %s\n",
259 is_file
?"file":"dir", cli_errstr(cli_share_src
));
260 nt_status
= cli_nt_error(cli_share_src
);
264 if (!cli_close(cli_share_dst
, fnum_dst
)) {
265 d_fprintf(stderr
, "could not close %s on destination server: %s\n",
266 is_file
?"file":"dir", cli_errstr(cli_share_dst
));
267 nt_status
= cli_nt_error(cli_share_dst
);
272 nt_status
= NT_STATUS_OK
;
278 cli_close(cli_share_src
, fnum_src
);
281 cli_close(cli_share_dst
, fnum_dst
);
287 * Copy a file or directory from a connected share to another connected share
289 * @param c A net_context structure
290 * @param mem_ctx A talloc-context
291 * @param cli_share_src A connected cli_state
292 * @param cli_share_dst A connected cli_state
293 * @param src_file The source file-name
294 * @param dst_file The destination file-name
295 * @param copy_acls Whether to copy acls
296 * @param copy_attrs Whether to copy DOS attributes
297 * @param copy_timestamps Whether to preserve timestamps
298 * @param is_file Whether this file is a file or a dir
300 * @return Normal NTSTATUS return.
303 NTSTATUS
net_copy_file(struct net_context
*c
,
305 struct cli_state
*cli_share_src
,
306 struct cli_state
*cli_share_dst
,
307 const char *src_name
, const char *dst_name
,
308 bool copy_acls
, bool copy_attrs
,
309 bool copy_timestamps
, bool is_file
)
311 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
314 static int io_bufsize
= 64512;
315 int read_size
= io_bufsize
;
320 if (!src_name
|| !dst_name
)
323 if (cli_share_src
== NULL
|| cli_share_dst
== NULL
)
326 /* open on the originating server */
327 DEBUGADD(3,("opening %s %s on originating server\n",
328 is_file
? "file":"dir", src_name
));
330 fnum_src
= cli_open(cli_share_src
, src_name
, O_RDONLY
, DENY_NONE
);
332 fnum_src
= cli_nt_create(cli_share_src
, src_name
, READ_CONTROL_ACCESS
);
334 if (fnum_src
== -1) {
335 DEBUGADD(0,("cannot open %s %s on originating server %s\n",
336 is_file
? "file":"dir",
337 src_name
, cli_errstr(cli_share_src
)));
338 nt_status
= cli_nt_error(cli_share_src
);
345 /* open file on the destination server */
346 DEBUGADD(3,("opening file %s on destination server\n", dst_name
));
347 fnum_dst
= cli_open(cli_share_dst
, dst_name
,
348 O_RDWR
|O_CREAT
|O_TRUNC
, DENY_NONE
);
350 if (fnum_dst
== -1) {
351 DEBUGADD(1,("cannot create file %s on destination server: %s\n",
352 dst_name
, cli_errstr(cli_share_dst
)));
353 nt_status
= cli_nt_error(cli_share_dst
);
357 /* allocate memory */
358 if (!(data
= (char *)SMB_MALLOC(read_size
))) {
359 d_fprintf(stderr
, "malloc fail for size %d\n", read_size
);
360 nt_status
= NT_STATUS_NO_MEMORY
;
367 if (c
->opt_verbose
) {
369 d_printf("copying [\\\\%s\\%s%s] => [\\\\%s\\%s%s] "
370 "%s ACLs and %s DOS Attributes %s\n",
371 cli_share_src
->desthost
, cli_share_src
->share
, src_name
,
372 cli_share_dst
->desthost
, cli_share_dst
->share
, dst_name
,
373 copy_acls
? "with" : "without",
374 copy_attrs
? "with" : "without",
375 copy_timestamps
? "(preserving timestamps)" : "" );
383 n
= cli_read(cli_share_src
, fnum_src
, data
, nread
,
389 ret
= cli_write(cli_share_dst
, fnum_dst
, 0, data
,
393 d_fprintf(stderr
, "Error writing file: %s\n",
394 cli_errstr(cli_share_dst
));
395 nt_status
= cli_nt_error(cli_share_dst
);
403 if (!is_file
&& !cli_chkpath(cli_share_dst
, dst_name
)) {
406 DEBUGADD(3,("creating dir %s on the destination server\n",
409 if (!cli_mkdir(cli_share_dst
, dst_name
)) {
410 DEBUG(0,("cannot create directory %s: %s\n",
411 dst_name
, cli_errstr(cli_share_dst
)));
412 nt_status
= NT_STATUS_NO_SUCH_FILE
;
415 if (!cli_chkpath(cli_share_dst
, dst_name
)) {
416 d_fprintf(stderr
, "cannot check for directory %s: %s\n",
417 dst_name
, cli_errstr(cli_share_dst
));
424 if (!cli_close(cli_share_src
, fnum_src
)) {
425 d_fprintf(stderr
, "could not close file on originating server: %s\n",
426 cli_errstr(cli_share_src
));
427 nt_status
= cli_nt_error(cli_share_src
);
431 if (is_file
&& !cli_close(cli_share_dst
, fnum_dst
)) {
432 d_fprintf(stderr
, "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 (!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 (!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], version: [%d]\n",
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
)) {
706 d_fprintf(stderr
, "no access to printer [%s] on [%s] for user [%s] granted\n",
707 printername2
, pipe_hnd
->srv_name_slash
, username
);
711 if (!W_ERROR_IS_OK(result
)) {
712 d_fprintf(stderr
, "cannot open printer %s on server %s: %s\n",
713 printername2
, pipe_hnd
->srv_name_slash
, win_errstr(result
));
717 DEBUG(2,("got printer handle for printer: %s, server: %s\n",
718 printername2
, pipe_hnd
->srv_name_slash
));
723 static bool net_spoolss_getprinter(struct rpc_pipe_client
*pipe_hnd
,
725 struct policy_handle
*hnd
,
727 union spoolss_PrinterInfo
*info
)
731 /* getprinter call */
732 result
= rpccli_spoolss_getprinter(pipe_hnd
, mem_ctx
,
737 if (!W_ERROR_IS_OK(result
)) {
738 printf("cannot get printer-info: %s\n", win_errstr(result
));
745 static bool net_spoolss_setprinter(struct rpc_pipe_client
*pipe_hnd
,
747 struct policy_handle
*hnd
,
749 union spoolss_PrinterInfo
*info
)
753 struct spoolss_SetPrinterInfoCtr info_ctr
;
754 struct spoolss_DevmodeContainer devmode_ctr
;
755 struct sec_desc_buf secdesc_ctr
;
757 ZERO_STRUCT(devmode_ctr
);
758 ZERO_STRUCT(secdesc_ctr
);
760 /* setprinter call */
762 info_ctr
.level
= level
;
765 info_ctr
.info
.info0
= (struct spoolss_SetPrinterInfo0
*)&info
->info0
;
768 info_ctr
.info
.info1
= (struct spoolss_SetPrinterInfo1
*)&info
->info1
;
771 info_ctr
.info
.info2
= (struct spoolss_SetPrinterInfo2
*)&info
->info2
;
774 info_ctr
.info
.info3
= (struct spoolss_SetPrinterInfo3
*)&info
->info3
;
777 info_ctr
.info
.info4
= (struct spoolss_SetPrinterInfo4
*)&info
->info4
;
780 info_ctr
.info
.info5
= (struct spoolss_SetPrinterInfo5
*)&info
->info5
;
783 info_ctr
.info
.info6
= (struct spoolss_SetPrinterInfo6
*)&info
->info6
;
786 info_ctr
.info
.info7
= (struct spoolss_SetPrinterInfo7
*)&info
->info7
;
790 info_ctr
.info
.info8
= (struct spoolss_SetPrinterInfo8
*)&info
->info8
;
793 info_ctr
.info
.info9
= (struct spoolss_SetPrinterInfo9
*)&info
->info9
;
800 status
= rpccli_spoolss_SetPrinter(pipe_hnd
, mem_ctx
,
808 if (!W_ERROR_IS_OK(result
)) {
809 printf("cannot set printer-info: %s\n", win_errstr(result
));
817 static bool net_spoolss_setprinterdata(struct rpc_pipe_client
*pipe_hnd
,
819 struct policy_handle
*hnd
,
820 const char *value_name
,
821 enum winreg_Type type
,
822 union spoolss_PrinterData data
)
827 /* setprinterdata call */
828 status
= rpccli_spoolss_SetPrinterData(pipe_hnd
, mem_ctx
,
833 0, /* autocalculated */
836 if (!W_ERROR_IS_OK(result
)) {
837 printf ("unable to set printerdata: %s\n", win_errstr(result
));
845 static bool net_spoolss_enumprinterkey(struct rpc_pipe_client
*pipe_hnd
,
847 struct policy_handle
*hnd
,
849 const char ***keylist
)
853 /* enumprinterkey call */
854 result
= rpccli_spoolss_enumprinterkey(pipe_hnd
, mem_ctx
, hnd
, keyname
, keylist
, 0);
856 if (!W_ERROR_IS_OK(result
)) {
857 printf("enumprinterkey failed: %s\n", win_errstr(result
));
864 static bool net_spoolss_enumprinterdataex(struct rpc_pipe_client
*pipe_hnd
,
867 struct policy_handle
*hnd
,
870 struct spoolss_PrinterEnumValues
**info
)
874 /* enumprinterdataex call */
875 result
= rpccli_spoolss_enumprinterdataex(pipe_hnd
, mem_ctx
,
882 if (!W_ERROR_IS_OK(result
)) {
883 printf("enumprinterdataex failed: %s\n", win_errstr(result
));
891 static bool net_spoolss_setprinterdataex(struct rpc_pipe_client
*pipe_hnd
,
893 struct policy_handle
*hnd
,
895 REGISTRY_VALUE
*value
)
900 /* setprinterdataex call */
901 status
= rpccli_spoolss_SetPrinterDataEx(pipe_hnd
, mem_ctx
,
910 if (!W_ERROR_IS_OK(result
)) {
911 printf("could not set printerdataex: %s\n", win_errstr(result
));
918 static bool net_spoolss_enumforms(struct rpc_pipe_client
*pipe_hnd
,
920 struct policy_handle
*hnd
,
923 union spoolss_FormInfo
**forms
)
928 result
= rpccli_spoolss_enumforms(pipe_hnd
, mem_ctx
,
934 if (!W_ERROR_IS_OK(result
)) {
935 printf("could not enum forms: %s\n", win_errstr(result
));
942 static bool net_spoolss_enumprinterdrivers (struct rpc_pipe_client
*pipe_hnd
,
944 uint32_t level
, const char *env
,
946 union spoolss_DriverInfo
**info
)
950 /* enumprinterdrivers call */
951 result
= rpccli_spoolss_enumprinterdrivers(pipe_hnd
, mem_ctx
,
952 pipe_hnd
->srv_name_slash
,
958 if (!W_ERROR_IS_OK(result
)) {
959 printf("cannot enum drivers: %s\n", win_errstr(result
));
966 static bool net_spoolss_getprinterdriver(struct rpc_pipe_client
*pipe_hnd
,
968 struct policy_handle
*hnd
, uint32_t level
,
969 const char *env
, int version
,
970 union spoolss_DriverInfo
*info
)
973 uint32_t server_major_version
;
974 uint32_t server_minor_version
;
976 /* getprinterdriver call */
977 result
= rpccli_spoolss_getprinterdriver2(pipe_hnd
, mem_ctx
,
985 &server_major_version
,
986 &server_minor_version
);
987 if (!W_ERROR_IS_OK(result
)) {
988 DEBUG(1,("cannot get driver (for architecture: %s): %s\n",
989 env
, win_errstr(result
)));
990 if (W_ERROR_V(result
) != W_ERROR_V(WERR_UNKNOWN_PRINTER_DRIVER
) &&
991 W_ERROR_V(result
) != W_ERROR_V(WERR_INVALID_ENVIRONMENT
)) {
992 printf("cannot get driver: %s\n", win_errstr(result
));
1001 static bool net_spoolss_addprinterdriver(struct rpc_pipe_client
*pipe_hnd
,
1002 TALLOC_CTX
*mem_ctx
, uint32_t level
,
1003 union spoolss_DriverInfo
*info
)
1007 struct spoolss_AddDriverInfoCtr info_ctr
;
1009 info_ctr
.level
= level
;
1013 info_ctr
.info
.info2
= (struct spoolss_AddDriverInfo2
*)&info
->info2
;
1016 info_ctr
.info
.info3
= (struct spoolss_AddDriverInfo3
*)&info
->info3
;
1019 printf("unsupported info level: %d\n", level
);
1023 /* addprinterdriver call */
1024 status
= rpccli_spoolss_AddPrinterDriver(pipe_hnd
, mem_ctx
,
1025 pipe_hnd
->srv_name_slash
,
1028 /* be more verbose */
1029 if (W_ERROR_V(result
) == W_ERROR_V(WERR_ACCESS_DENIED
)) {
1030 printf("You are not allowed to add drivers\n");
1033 if (!W_ERROR_IS_OK(result
)) {
1034 printf("cannot add driver: %s\n", win_errstr(result
));
1042 * abstraction function to get uint32_t num_printers and PRINTER_INFO_CTR ctr
1043 * for a single printer or for all printers depending on argc/argv
1046 static bool get_printer_info(struct rpc_pipe_client
*pipe_hnd
,
1047 TALLOC_CTX
*mem_ctx
,
1051 uint32_t *num_printers
,
1052 union spoolss_PrinterInfo
**info_p
)
1054 struct policy_handle hnd
;
1056 /* no arguments given, enumerate all printers */
1059 if (!net_spoolss_enum_printers(pipe_hnd
, mem_ctx
, NULL
,
1060 PRINTER_ENUM_LOCAL
|PRINTER_ENUM_SHARED
,
1061 level
, num_printers
, info_p
))
1067 /* argument given, get a single printer by name */
1068 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, argv
[0],
1069 MAXIMUM_ALLOWED_ACCESS
,
1070 pipe_hnd
->auth
->user_name
,
1074 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd
, level
, *info_p
)) {
1075 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd
, NULL
);
1079 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd
, NULL
);
1084 DEBUG(3,("got %d printers\n", *num_printers
));
1091 * List print-queues (including local printers that are not shared)
1093 * All parameters are provided by the run_rpc_command function, except for
1094 * argc, argv which are passed through.
1096 * @param c A net_context structure
1097 * @param domain_sid The domain sid aquired from the remote server
1098 * @param cli A cli_state connected to the server.
1099 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1100 * @param argc Standard main() style argc
1101 * @param argv Standard main() style argv. Initial components are already
1104 * @return Normal NTSTATUS return.
1107 NTSTATUS
rpc_printer_list_internals(struct net_context
*c
,
1108 const DOM_SID
*domain_sid
,
1109 const char *domain_name
,
1110 struct cli_state
*cli
,
1111 struct rpc_pipe_client
*pipe_hnd
,
1112 TALLOC_CTX
*mem_ctx
,
1116 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1117 uint32_t i
, num_printers
;
1119 const char *printername
, *sharename
;
1120 union spoolss_PrinterInfo
*info
;
1122 printf("listing printers\n");
1124 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &info
))
1127 for (i
= 0; i
< num_printers
; i
++) {
1129 /* do some initialization */
1130 printername
= info
[i
].info2
.printername
;
1131 sharename
= info
[i
].info2
.sharename
;
1133 if (printername
&& sharename
) {
1134 d_printf("printer %d: %s, shared as: %s\n",
1135 i
+1, printername
, sharename
);
1139 return NT_STATUS_OK
;
1143 * List printer-drivers from a server
1145 * All parameters are provided by the run_rpc_command function, except for
1146 * argc, argv which are passed through.
1148 * @param c A net_context structure
1149 * @param domain_sid The domain sid aquired from the remote server
1150 * @param cli A cli_state connected to the server.
1151 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1152 * @param argc Standard main() style argc
1153 * @param argv Standard main() style argv. Initial components are already
1156 * @return Normal NTSTATUS return.
1159 NTSTATUS
rpc_printer_driver_list_internals(struct net_context
*c
,
1160 const DOM_SID
*domain_sid
,
1161 const char *domain_name
,
1162 struct cli_state
*cli
,
1163 struct rpc_pipe_client
*pipe_hnd
,
1164 TALLOC_CTX
*mem_ctx
,
1168 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1171 union spoolss_DriverInfo
*info
;
1174 printf("listing printer-drivers\n");
1176 for (i
=0; archi_table
[i
].long_archi
!=NULL
; i
++) {
1178 uint32_t num_drivers
;
1180 /* enum remote drivers */
1181 if (!net_spoolss_enumprinterdrivers(pipe_hnd
, mem_ctx
, level
,
1182 archi_table
[i
].long_archi
,
1183 &num_drivers
, &info
)) {
1184 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1188 if (num_drivers
== 0) {
1189 d_printf ("no drivers found on server for architecture: [%s].\n",
1190 archi_table
[i
].long_archi
);
1194 d_printf("got %d printer-drivers for architecture: [%s]\n",
1195 num_drivers
, archi_table
[i
].long_archi
);
1198 /* do something for all drivers for architecture */
1199 for (d
= 0; d
< num_drivers
; d
++) {
1200 display_print_driver3(&info
[d
].info3
);
1204 nt_status
= NT_STATUS_OK
;
1212 * Publish print-queues with args-wrapper
1214 * @param cli A cli_state connected to the server.
1215 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1216 * @param argc Standard main() style argc
1217 * @param argv Standard main() style argv. Initial components are already
1221 * @return Normal NTSTATUS return.
1224 static NTSTATUS
rpc_printer_publish_internals_args(struct rpc_pipe_client
*pipe_hnd
,
1225 TALLOC_CTX
*mem_ctx
,
1230 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1231 uint32_t i
, num_printers
;
1233 const char *printername
, *sharename
;
1234 union spoolss_PrinterInfo
*info_enum
;
1235 union spoolss_PrinterInfo info
;
1236 struct spoolss_SetPrinterInfoCtr info_ctr
;
1237 struct spoolss_DevmodeContainer devmode_ctr
;
1238 struct sec_desc_buf secdesc_ctr
;
1239 struct policy_handle hnd
;
1241 const char *action_str
;
1243 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &info_enum
))
1246 for (i
= 0; i
< num_printers
; i
++) {
1248 /* do some initialization */
1249 printername
= info_enum
[i
].info2
.printername
;
1250 sharename
= info_enum
[i
].info2
.sharename
;
1251 if (!printername
|| !sharename
) {
1255 /* open printer handle */
1256 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1257 PRINTER_ALL_ACCESS
, pipe_hnd
->auth
->user_name
, &hnd
))
1260 /* check for existing dst printer */
1261 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd
, level
, &info
))
1264 /* check action and set string */
1266 case DSPRINT_PUBLISH
:
1267 action_str
= "published";
1269 case DSPRINT_UPDATE
:
1270 action_str
= "updated";
1272 case DSPRINT_UNPUBLISH
:
1273 action_str
= "unpublished";
1276 action_str
= "unknown action";
1277 printf("unkown action: %d\n", action
);
1281 info
.info7
.action
= action
;
1283 info_ctr
.info
.info7
= (struct spoolss_SetPrinterInfo7
*)&info
.info7
;
1285 ZERO_STRUCT(devmode_ctr
);
1286 ZERO_STRUCT(secdesc_ctr
);
1288 nt_status
= rpccli_spoolss_SetPrinter(pipe_hnd
, mem_ctx
,
1296 if (!W_ERROR_IS_OK(result
) && (W_ERROR_V(result
) != W_ERROR_V(WERR_IO_PENDING
))) {
1297 printf("cannot set printer-info: %s\n", win_errstr(result
));
1301 printf("successfully %s printer %s in Active Directory\n", action_str
, sharename
);
1304 nt_status
= NT_STATUS_OK
;
1307 if (is_valid_policy_hnd(&hnd
))
1308 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd
, NULL
);
1313 NTSTATUS
rpc_printer_publish_publish_internals(struct net_context
*c
,
1314 const DOM_SID
*domain_sid
,
1315 const char *domain_name
,
1316 struct cli_state
*cli
,
1317 struct rpc_pipe_client
*pipe_hnd
,
1318 TALLOC_CTX
*mem_ctx
,
1322 return rpc_printer_publish_internals_args(pipe_hnd
, mem_ctx
, argc
, argv
, DSPRINT_PUBLISH
);
1325 NTSTATUS
rpc_printer_publish_unpublish_internals(struct net_context
*c
,
1326 const DOM_SID
*domain_sid
,
1327 const char *domain_name
,
1328 struct cli_state
*cli
,
1329 struct rpc_pipe_client
*pipe_hnd
,
1330 TALLOC_CTX
*mem_ctx
,
1334 return rpc_printer_publish_internals_args(pipe_hnd
, mem_ctx
, argc
, argv
, DSPRINT_UNPUBLISH
);
1337 NTSTATUS
rpc_printer_publish_update_internals(struct net_context
*c
,
1338 const DOM_SID
*domain_sid
,
1339 const char *domain_name
,
1340 struct cli_state
*cli
,
1341 struct rpc_pipe_client
*pipe_hnd
,
1342 TALLOC_CTX
*mem_ctx
,
1346 return rpc_printer_publish_internals_args(pipe_hnd
, mem_ctx
, argc
, argv
, DSPRINT_UPDATE
);
1350 * List print-queues w.r.t. their publishing state
1352 * All parameters are provided by the run_rpc_command function, except for
1353 * argc, argv which are passed through.
1355 * @param c A net_context structure
1356 * @param domain_sid The domain sid aquired from the remote server
1357 * @param cli A cli_state connected to the server.
1358 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1359 * @param argc Standard main() style argc
1360 * @param argv Standard main() style argv. Initial components are already
1363 * @return Normal NTSTATUS return.
1366 NTSTATUS
rpc_printer_publish_list_internals(struct net_context
*c
,
1367 const DOM_SID
*domain_sid
,
1368 const char *domain_name
,
1369 struct cli_state
*cli
,
1370 struct rpc_pipe_client
*pipe_hnd
,
1371 TALLOC_CTX
*mem_ctx
,
1375 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1376 uint32_t i
, num_printers
;
1378 const char *printername
, *sharename
;
1379 union spoolss_PrinterInfo
*info_enum
;
1380 union spoolss_PrinterInfo info
;
1381 struct policy_handle hnd
;
1384 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &info_enum
))
1387 for (i
= 0; i
< num_printers
; i
++) {
1389 /* do some initialization */
1390 printername
= info_enum
[i
].info2
.printername
;
1391 sharename
= info_enum
[i
].info2
.sharename
;
1393 if (!printername
|| !sharename
) {
1397 /* open printer handle */
1398 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1399 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd
))
1402 /* check for existing dst printer */
1403 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd
, level
, &info
))
1406 if (!info
.info7
.guid
) {
1409 state
= info
.info7
.action
;
1411 case DSPRINT_PUBLISH
:
1412 printf("printer [%s] is published", sharename
);
1414 printf(", guid: %s", info
.info7
.guid
);
1417 case DSPRINT_UNPUBLISH
:
1418 printf("printer [%s] is unpublished\n", sharename
);
1420 case DSPRINT_UPDATE
:
1421 printf("printer [%s] is currently updating\n", sharename
);
1424 printf("unkown state: %d\n", state
);
1429 nt_status
= NT_STATUS_OK
;
1432 if (is_valid_policy_hnd(&hnd
))
1433 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd
, NULL
);
1439 * Migrate Printer-ACLs from a source server to the destination server
1441 * All parameters are provided by the run_rpc_command function, except for
1442 * argc, argv which are passed through.
1444 * @param c A net_context structure
1445 * @param domain_sid The domain sid aquired from the remote server
1446 * @param cli A cli_state connected to the server.
1447 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1448 * @param argc Standard main() style argc
1449 * @param argv Standard main() style argv. Initial components are already
1452 * @return Normal NTSTATUS return.
1455 NTSTATUS
rpc_printer_migrate_security_internals(struct net_context
*c
,
1456 const DOM_SID
*domain_sid
,
1457 const char *domain_name
,
1458 struct cli_state
*cli
,
1459 struct rpc_pipe_client
*pipe_hnd
,
1460 TALLOC_CTX
*mem_ctx
,
1464 /* TODO: what now, info2 or info3 ?
1465 convince jerry that we should add clientside setacls level 3 at least
1467 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1469 uint32_t num_printers
;
1471 const char *printername
, *sharename
;
1472 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
1473 struct policy_handle hnd_src
, hnd_dst
;
1474 union spoolss_PrinterInfo
*info_enum
;
1475 struct cli_state
*cli_dst
= NULL
;
1476 union spoolss_PrinterInfo info_src
, info_dst
;
1478 DEBUG(3,("copying printer ACLs\n"));
1480 /* connect destination PI_SPOOLSS */
1481 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
,
1482 &ndr_table_spoolss
.syntax_id
);
1483 if (!NT_STATUS_IS_OK(nt_status
))
1487 /* enum source printers */
1488 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &info_enum
)) {
1489 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1493 if (!num_printers
) {
1494 printf ("no printers found on server.\n");
1495 nt_status
= NT_STATUS_OK
;
1499 /* do something for all printers */
1500 for (i
= 0; i
< num_printers
; i
++) {
1502 /* do some initialization */
1503 printername
= info_enum
[i
].info2
.printername
;
1504 sharename
= info_enum
[i
].info2
.sharename
;
1506 if (!printername
|| !sharename
) {
1507 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1511 /* we can reset NT_STATUS here because we do not
1512 get any real NT_STATUS-codes anymore from now on */
1513 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1515 d_printf("migrating printer ACLs for: [%s] / [%s]\n",
1516 printername
, sharename
);
1518 /* according to msdn you have specify these access-rights
1519 to see the security descriptor
1520 - READ_CONTROL (DACL)
1521 - ACCESS_SYSTEM_SECURITY (SACL)
1524 /* open src printer handle */
1525 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1526 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
1529 /* open dst printer handle */
1530 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
1531 PRINTER_ALL_ACCESS
, cli_dst
->user_name
, &hnd_dst
))
1534 /* check for existing dst printer */
1535 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, level
, &info_dst
))
1538 /* check for existing src printer */
1539 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd_src
, 3, &info_src
))
1542 /* Copy Security Descriptor */
1544 /* copy secdesc (info level 2) */
1545 info_dst
.info2
.devmode
= NULL
;
1546 info_dst
.info2
.secdesc
= dup_sec_desc(mem_ctx
, info_src
.info3
.secdesc
);
1549 display_sec_desc(info_dst
.info2
.secdesc
);
1551 if (!net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 2, &info_dst
))
1554 DEBUGADD(1,("\tSetPrinter of SECDESC succeeded\n"));
1557 /* close printer handles here */
1558 if (is_valid_policy_hnd(&hnd_src
)) {
1559 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
1562 if (is_valid_policy_hnd(&hnd_dst
)) {
1563 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
1568 nt_status
= NT_STATUS_OK
;
1572 if (is_valid_policy_hnd(&hnd_src
)) {
1573 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
1576 if (is_valid_policy_hnd(&hnd_dst
)) {
1577 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
1581 cli_shutdown(cli_dst
);
1587 * Migrate printer-forms from a src server to the dst server
1589 * All parameters are provided by the run_rpc_command function, except for
1590 * argc, argv which are passed through.
1592 * @param c A net_context structure
1593 * @param domain_sid The domain sid aquired from the remote server
1594 * @param cli A cli_state connected to the server.
1595 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1596 * @param argc Standard main() style argc
1597 * @param argv Standard main() style argv. Initial components are already
1600 * @return Normal NTSTATUS return.
1603 NTSTATUS
rpc_printer_migrate_forms_internals(struct net_context
*c
,
1604 const DOM_SID
*domain_sid
,
1605 const char *domain_name
,
1606 struct cli_state
*cli
,
1607 struct rpc_pipe_client
*pipe_hnd
,
1608 TALLOC_CTX
*mem_ctx
,
1612 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1615 uint32_t num_printers
;
1617 const char *printername
, *sharename
;
1618 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
1619 struct policy_handle hnd_src
, hnd_dst
;
1620 union spoolss_PrinterInfo
*info_enum
;
1621 union spoolss_PrinterInfo info_dst
;
1623 union spoolss_FormInfo
*forms
;
1624 struct cli_state
*cli_dst
= NULL
;
1626 DEBUG(3,("copying forms\n"));
1628 /* connect destination PI_SPOOLSS */
1629 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
,
1630 &ndr_table_spoolss
.syntax_id
);
1631 if (!NT_STATUS_IS_OK(nt_status
))
1634 /* enum src printers */
1635 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &info_enum
)) {
1636 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1640 if (!num_printers
) {
1641 printf ("no printers found on server.\n");
1642 nt_status
= NT_STATUS_OK
;
1646 /* do something for all printers */
1647 for (i
= 0; i
< num_printers
; i
++) {
1649 /* do some initialization */
1650 printername
= info_enum
[i
].info2
.printername
;
1651 sharename
= info_enum
[i
].info2
.sharename
;
1653 if (!printername
|| !sharename
) {
1654 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1657 /* we can reset NT_STATUS here because we do not
1658 get any real NT_STATUS-codes anymore from now on */
1659 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1661 d_printf("migrating printer forms for: [%s] / [%s]\n",
1662 printername
, sharename
);
1665 /* open src printer handle */
1666 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1667 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
1670 /* open dst printer handle */
1671 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
1672 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd_dst
))
1675 /* check for existing dst printer */
1676 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, level
, &info_dst
))
1679 /* finally migrate forms */
1680 if (!net_spoolss_enumforms(pipe_hnd
, mem_ctx
, &hnd_src
, level
, &num_forms
, &forms
))
1683 DEBUG(1,("got %d forms for printer\n", num_forms
));
1686 for (f
= 0; f
< num_forms
; f
++) {
1688 union spoolss_AddFormInfo info
;
1691 /* only migrate FORM_PRINTER types, according to jerry
1692 FORM_BUILTIN-types are hard-coded in samba */
1693 if (forms
[f
].info1
.flags
!= SPOOLSS_FORM_PRINTER
)
1697 d_printf("\tmigrating form # %d [%s] of type [%d]\n",
1698 f
, forms
[f
].info1
.form_name
,
1699 forms
[f
].info1
.flags
);
1701 info
.info1
= (struct spoolss_AddFormInfo1
*)&forms
[f
].info1
;
1703 /* FIXME: there might be something wrong with samba's
1705 status
= rpccli_spoolss_AddForm(pipe_hnd_dst
, mem_ctx
,
1710 if (!W_ERROR_IS_OK(result
)) {
1711 d_printf("\tAddForm form %d: [%s] refused.\n",
1712 f
, forms
[f
].info1
.form_name
);
1716 DEBUGADD(1,("\tAddForm of [%s] succeeded\n",
1717 forms
[f
].info1
.form_name
));
1721 /* close printer handles here */
1722 if (is_valid_policy_hnd(&hnd_src
)) {
1723 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
1726 if (is_valid_policy_hnd(&hnd_dst
)) {
1727 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
1731 nt_status
= NT_STATUS_OK
;
1735 if (is_valid_policy_hnd(&hnd_src
))
1736 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
1738 if (is_valid_policy_hnd(&hnd_dst
))
1739 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
1742 cli_shutdown(cli_dst
);
1748 * Migrate printer-drivers from a src server to the dst server
1750 * All parameters are provided by the run_rpc_command function, except for
1751 * argc, argv which are passed through.
1753 * @param c A net_context structure
1754 * @param domain_sid The domain sid aquired from the remote server
1755 * @param cli A cli_state connected to the server.
1756 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1757 * @param argc Standard main() style argc
1758 * @param argv Standard main() style argv. Initial components are already
1761 * @return Normal NTSTATUS return.
1764 NTSTATUS
rpc_printer_migrate_drivers_internals(struct net_context
*c
,
1765 const DOM_SID
*domain_sid
,
1766 const char *domain_name
,
1767 struct cli_state
*cli
,
1768 struct rpc_pipe_client
*pipe_hnd
,
1769 TALLOC_CTX
*mem_ctx
,
1773 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1775 uint32_t num_printers
;
1777 const char *printername
, *sharename
;
1778 bool got_src_driver_share
= false;
1779 bool got_dst_driver_share
= false;
1780 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
1781 struct policy_handle hnd_src
, hnd_dst
;
1782 union spoolss_DriverInfo drv_info_src
;
1783 union spoolss_PrinterInfo
*info_enum
;
1784 union spoolss_PrinterInfo info_dst
;
1785 struct cli_state
*cli_dst
= NULL
;
1786 struct cli_state
*cli_share_src
= NULL
;
1787 struct cli_state
*cli_share_dst
= NULL
;
1788 const char *drivername
= NULL
;
1790 DEBUG(3,("copying printer-drivers\n"));
1792 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
,
1793 &ndr_table_spoolss
.syntax_id
);
1794 if (!NT_STATUS_IS_OK(nt_status
))
1797 /* open print$-share on the src server */
1798 nt_status
= connect_to_service(c
, &cli_share_src
, &cli
->dest_ss
,
1799 cli
->desthost
, "print$", "A:");
1800 if (!NT_STATUS_IS_OK(nt_status
))
1803 got_src_driver_share
= true;
1806 /* open print$-share on the dst server */
1807 nt_status
= connect_to_service(c
, &cli_share_dst
, &cli_dst
->dest_ss
,
1808 cli_dst
->desthost
, "print$", "A:");
1809 if (!NT_STATUS_IS_OK(nt_status
))
1812 got_dst_driver_share
= true;
1815 /* enum src printers */
1816 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &info_enum
)) {
1817 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1821 if (num_printers
== 0) {
1822 printf ("no printers found on server.\n");
1823 nt_status
= NT_STATUS_OK
;
1828 /* do something for all printers */
1829 for (p
= 0; p
< num_printers
; p
++) {
1831 /* do some initialization */
1832 printername
= info_enum
[p
].info2
.printername
;
1833 sharename
= info_enum
[p
].info2
.sharename
;
1835 if (!printername
|| !sharename
) {
1836 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1840 /* we can reset NT_STATUS here because we do not
1841 get any real NT_STATUS-codes anymore from now on */
1842 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1844 d_printf("migrating printer driver for: [%s] / [%s]\n",
1845 printername
, sharename
);
1847 /* open dst printer handle */
1848 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
1849 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd_dst
))
1852 /* check for existing dst printer */
1853 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 2, &info_dst
))
1857 /* open src printer handle */
1858 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1859 MAXIMUM_ALLOWED_ACCESS
,
1860 pipe_hnd
->auth
->user_name
,
1864 /* in a first step call getdriver for each shared printer (per arch)
1865 to get a list of all files that have to be copied */
1867 for (i
=0; archi_table
[i
].long_archi
!=NULL
; i
++) {
1870 if (!net_spoolss_getprinterdriver(pipe_hnd
, mem_ctx
, &hnd_src
,
1871 level
, archi_table
[i
].long_archi
,
1872 archi_table
[i
].version
, &drv_info_src
))
1875 drivername
= drv_info_src
.info3
.driver_name
;
1878 display_print_driver3(&drv_info_src
.info3
);
1880 /* check arch dir */
1881 nt_status
= check_arch_dir(cli_share_dst
, archi_table
[i
].short_archi
);
1882 if (!NT_STATUS_IS_OK(nt_status
))
1886 /* copy driver-files */
1887 nt_status
= copy_print_driver_3(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
1888 archi_table
[i
].short_archi
,
1889 &drv_info_src
.info3
);
1890 if (!NT_STATUS_IS_OK(nt_status
))
1895 if (!net_spoolss_addprinterdriver(pipe_hnd_dst
, mem_ctx
, level
, &drv_info_src
)) {
1896 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1900 DEBUGADD(1,("Sucessfully added driver [%s] for printer [%s]\n",
1901 drivername
, printername
));
1905 if (!drivername
|| strlen(drivername
) == 0) {
1906 DEBUGADD(1,("Did not get driver for printer %s\n",
1912 info_dst
.info2
.drivername
= drivername
;
1914 if (!net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 2, &info_dst
)) {
1915 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1919 DEBUGADD(1,("Sucessfully set driver %s for printer %s\n",
1920 drivername
, printername
));
1923 if (is_valid_policy_hnd(&hnd_dst
)) {
1924 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
1928 if (is_valid_policy_hnd(&hnd_src
)) {
1929 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
1933 nt_status
= NT_STATUS_OK
;
1937 if (is_valid_policy_hnd(&hnd_src
))
1938 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
1940 if (is_valid_policy_hnd(&hnd_dst
))
1941 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
1944 cli_shutdown(cli_dst
);
1947 if (got_src_driver_share
)
1948 cli_shutdown(cli_share_src
);
1950 if (got_dst_driver_share
)
1951 cli_shutdown(cli_share_dst
);
1958 * Migrate printer-queues from a src to the dst server
1959 * (requires a working "addprinter command" to be installed for the local smbd)
1961 * All parameters are provided by the run_rpc_command function, except for
1962 * argc, argv which are passed through.
1964 * @param c A net_context structure
1965 * @param domain_sid The domain sid aquired from the remote server
1966 * @param cli A cli_state connected to the server.
1967 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1968 * @param argc Standard main() style argc
1969 * @param argv Standard main() style argv. Initial components are already
1972 * @return Normal NTSTATUS return.
1975 NTSTATUS
rpc_printer_migrate_printers_internals(struct net_context
*c
,
1976 const DOM_SID
*domain_sid
,
1977 const char *domain_name
,
1978 struct cli_state
*cli
,
1979 struct rpc_pipe_client
*pipe_hnd
,
1980 TALLOC_CTX
*mem_ctx
,
1985 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1986 uint32_t i
= 0, num_printers
;
1988 union spoolss_PrinterInfo info_dst
, info_src
;
1989 union spoolss_PrinterInfo
*info_enum
;
1990 struct cli_state
*cli_dst
= NULL
;
1991 struct policy_handle hnd_dst
, hnd_src
;
1992 const char *printername
, *sharename
;
1993 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
1994 struct spoolss_SetPrinterInfoCtr info_ctr
;
1996 DEBUG(3,("copying printers\n"));
1998 /* connect destination PI_SPOOLSS */
1999 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
,
2000 &ndr_table_spoolss
.syntax_id
);
2001 if (!NT_STATUS_IS_OK(nt_status
))
2005 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &info_enum
)) {
2006 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2010 if (!num_printers
) {
2011 printf ("no printers found on server.\n");
2012 nt_status
= NT_STATUS_OK
;
2016 /* do something for all printers */
2017 for (i
= 0; i
< num_printers
; i
++) {
2019 /* do some initialization */
2020 printername
= info_enum
[i
].info2
.printername
;
2021 sharename
= info_enum
[i
].info2
.sharename
;
2023 if (!printername
|| !sharename
) {
2024 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2027 /* we can reset NT_STATUS here because we do not
2028 get any real NT_STATUS-codes anymore from now on */
2029 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2031 d_printf("migrating printer queue for: [%s] / [%s]\n",
2032 printername
, sharename
);
2034 /* open dst printer handle */
2035 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
2036 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd_dst
)) {
2038 DEBUG(1,("could not open printer: %s\n", sharename
));
2041 /* check for existing dst printer */
2042 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, level
, &info_dst
)) {
2043 printf ("could not get printer, creating printer.\n");
2045 DEBUG(1,("printer already exists: %s\n", sharename
));
2046 /* close printer handle here - dst only, not got src yet. */
2047 if (is_valid_policy_hnd(&hnd_dst
)) {
2048 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
2053 /* now get again src printer ctr via getprinter,
2054 we first need a handle for that */
2056 /* open src printer handle */
2057 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
2058 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
2061 /* getprinter on the src server */
2062 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd_src
, level
, &info_src
))
2065 /* copy each src printer to a dst printer 1:1,
2066 maybe some values have to be changed though */
2067 d_printf("creating printer: %s\n", printername
);
2069 info_ctr
.level
= level
;
2070 info_ctr
.info
.info2
= (struct spoolss_SetPrinterInfo2
*)&info_src
.info2
;
2072 result
= rpccli_spoolss_addprinterex(pipe_hnd_dst
,
2076 if (W_ERROR_IS_OK(result
))
2077 d_printf ("printer [%s] successfully added.\n", printername
);
2078 else if (W_ERROR_V(result
) == W_ERROR_V(WERR_PRINTER_ALREADY_EXISTS
))
2079 d_fprintf (stderr
, "printer [%s] already exists.\n", printername
);
2081 d_fprintf (stderr
, "could not create printer [%s]\n", printername
);
2085 /* close printer handles here */
2086 if (is_valid_policy_hnd(&hnd_src
)) {
2087 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
2090 if (is_valid_policy_hnd(&hnd_dst
)) {
2091 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
2095 nt_status
= NT_STATUS_OK
;
2098 if (is_valid_policy_hnd(&hnd_src
))
2099 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
2101 if (is_valid_policy_hnd(&hnd_dst
))
2102 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
2105 cli_shutdown(cli_dst
);
2111 * Migrate Printer-Settings from a src server to the dst server
2112 * (for this to work, printers and drivers already have to be migrated earlier)
2114 * All parameters are provided by the run_rpc_command function, except for
2115 * argc, argv which are passed through.
2117 * @param c A net_context structure
2118 * @param domain_sid The domain sid aquired from the remote server
2119 * @param cli A cli_state connected to the server.
2120 * @param mem_ctx Talloc context, destoyed on compleation of the function.
2121 * @param argc Standard main() style argc
2122 * @param argv Standard main() style argv. Initial components are already
2125 * @return Normal NTSTATUS return.
2128 NTSTATUS
rpc_printer_migrate_settings_internals(struct net_context
*c
,
2129 const DOM_SID
*domain_sid
,
2130 const char *domain_name
,
2131 struct cli_state
*cli
,
2132 struct rpc_pipe_client
*pipe_hnd
,
2133 TALLOC_CTX
*mem_ctx
,
2138 /* FIXME: Here the nightmare begins */
2141 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
2142 uint32_t i
= 0, p
= 0, j
= 0;
2143 uint32_t num_printers
;
2145 const char *printername
, *sharename
;
2146 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
2147 struct policy_handle hnd_src
, hnd_dst
;
2148 union spoolss_PrinterInfo
*info_enum
;
2149 union spoolss_PrinterInfo info_dst_publish
;
2150 union spoolss_PrinterInfo info_dst
;
2151 struct cli_state
*cli_dst
= NULL
;
2152 char *devicename
= NULL
, *unc_name
= NULL
, *url
= NULL
;
2153 const char *longname
;
2154 const char **keylist
= NULL
;
2157 ZERO_STRUCT(info_dst_publish
);
2159 DEBUG(3,("copying printer settings\n"));
2161 /* connect destination PI_SPOOLSS */
2162 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
,
2163 &ndr_table_spoolss
.syntax_id
);
2164 if (!NT_STATUS_IS_OK(nt_status
))
2167 /* enum src printers */
2168 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &info_enum
)) {
2169 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2173 if (!num_printers
) {
2174 printf ("no printers found on server.\n");
2175 nt_status
= NT_STATUS_OK
;
2180 /* needed for dns-strings in regkeys */
2181 longname
= get_mydnsfullname();
2183 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2187 /* do something for all printers */
2188 for (i
= 0; i
< num_printers
; i
++) {
2190 uint32_t value_offered
= 0, value_needed
;
2191 uint32_t data_offered
= 0, data_needed
;
2192 enum winreg_Type type
;
2193 uint8_t *buffer
= NULL
;
2194 const char *value_name
= NULL
;
2196 /* do some initialization */
2197 printername
= info_enum
[i
].info2
.printername
;
2198 sharename
= info_enum
[i
].info2
.sharename
;
2200 if (!printername
|| !sharename
) {
2201 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2204 /* we can reset NT_STATUS here because we do not
2205 get any real NT_STATUS-codes anymore from now on */
2206 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2208 d_printf("migrating printer settings for: [%s] / [%s]\n",
2209 printername
, sharename
);
2212 /* open src printer handle */
2213 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
2214 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
2217 /* open dst printer handle */
2218 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
2219 PRINTER_ALL_ACCESS
, cli_dst
->user_name
, &hnd_dst
))
2222 /* check for existing dst printer */
2223 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
,
2228 /* STEP 1: COPY DEVICE-MODE and other
2229 PRINTER_INFO_2-attributes
2232 info_dst
.info2
= info_enum
[i
].info2
;
2234 /* why is the port always disconnected when the printer
2235 is correctly installed (incl. driver ???) */
2236 info_dst
.info2
.portname
= SAMBA_PRINTER_PORT_NAME
;
2238 /* check if printer is published */
2239 if (info_enum
[i
].info2
.attributes
& PRINTER_ATTRIBUTE_PUBLISHED
) {
2241 /* check for existing dst printer */
2242 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 7, &info_dst_publish
))
2245 info_dst_publish
.info7
.action
= DSPRINT_PUBLISH
;
2247 /* ignore false from setprinter due to WERR_IO_PENDING */
2248 net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 7, &info_dst_publish
);
2250 DEBUG(3,("republished printer\n"));
2253 if (info_enum
[i
].info2
.devmode
!= NULL
) {
2255 /* copy devmode (info level 2) */
2256 info_dst
.info2
.devmode
= info_enum
[i
].info2
.devmode
;
2258 /* do not copy security descriptor (we have another
2259 * command for that) */
2260 info_dst
.info2
.secdesc
= NULL
;
2263 info_dst
.info2
.devmode
.devicename
=
2264 talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
2265 longname
, printername
);
2266 if (!info_dst
.info2
.devmode
.devicename
) {
2267 nt_status
= NT_STATUS_NO_MEMORY
;
2271 if (!net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
,
2275 DEBUGADD(1,("\tSetPrinter of DEVICEMODE succeeded\n"));
2278 /* STEP 2: COPY REGISTRY VALUES */
2280 /* please keep in mind that samba parse_spools gives horribly
2281 crippled results when used to rpccli_spoolss_enumprinterdataex
2282 a win2k3-server. (Bugzilla #1851)
2283 FIXME: IIRC I've seen it too on a win2k-server
2286 /* enumerate data on src handle */
2287 nt_status
= rpccli_spoolss_EnumPrinterData(pipe_hnd
, mem_ctx
,
2299 data_offered
= data_needed
;
2300 value_offered
= value_needed
;
2301 buffer
= talloc_zero_array(mem_ctx
, uint8_t, data_needed
);
2302 value_name
= talloc_zero_array(mem_ctx
, char, value_needed
);
2304 /* loop for all printerdata of "PrinterDriverData" */
2305 while (NT_STATUS_IS_OK(nt_status
) && W_ERROR_IS_OK(result
)) {
2307 nt_status
= rpccli_spoolss_EnumPrinterData(pipe_hnd
, mem_ctx
,
2318 /* loop for all reg_keys */
2319 if (NT_STATUS_IS_OK(nt_status
) && W_ERROR_IS_OK(result
)) {
2323 union spoolss_PrinterData printer_data
;
2326 if (c
->opt_verbose
) {
2327 fstrcpy(v
.valuename
, value_name
);
2329 v
.size
= data_offered
;
2331 display_reg_value(SPOOL_PRINTERDATA_KEY
, v
);
2334 result
= pull_spoolss_PrinterData(mem_ctx
,
2338 if (!W_ERROR_IS_OK(result
)) {
2343 if (!net_spoolss_setprinterdata(pipe_hnd_dst
, mem_ctx
,
2344 &hnd_dst
, value_name
,
2345 type
, printer_data
))
2348 DEBUGADD(1,("\tSetPrinterData of [%s] succeeded\n",
2353 /* STEP 3: COPY SUBKEY VALUES */
2355 /* here we need to enum all printer_keys and then work
2356 on the result with enum_printer_key_ex. nt4 does not
2357 respond to enumprinterkey, win2k does, so continue
2358 in case of an error */
2360 if (!net_spoolss_enumprinterkey(pipe_hnd
, mem_ctx
, &hnd_src
, "", &keylist
)) {
2361 printf("got no key-data\n");
2366 /* work on a list of printer keys
2367 each key has to be enumerated to get all required
2368 information. information is then set via setprinterdataex-calls */
2370 if (keylist
== NULL
)
2373 for (i
=0; keylist
&& keylist
[i
] != NULL
; i
++) {
2375 const char *subkey
= keylist
[i
];
2377 struct spoolss_PrinterEnumValues
*info
;
2379 /* enumerate all src subkeys */
2380 if (!net_spoolss_enumprinterdataex(pipe_hnd
, mem_ctx
, 0,
2386 for (j
=0; j
< count
; j
++) {
2388 REGISTRY_VALUE value
;
2391 /* although samba replies with sane data in most cases we
2392 should try to avoid writing wrong registry data */
2394 if (strequal(info
[j
].value_name
, SPOOL_REG_PORTNAME
) ||
2395 strequal(info
[j
].value_name
, SPOOL_REG_UNCNAME
) ||
2396 strequal(info
[j
].value_name
, SPOOL_REG_URL
) ||
2397 strequal(info
[j
].value_name
, SPOOL_REG_SHORTSERVERNAME
) ||
2398 strequal(info
[j
].value_name
, SPOOL_REG_SERVERNAME
)) {
2400 if (strequal(info
[j
].value_name
, SPOOL_REG_PORTNAME
)) {
2402 /* although windows uses a multi-sz, we use a sz */
2403 init_unistr2(&data
, SAMBA_PRINTER_PORT_NAME
, UNI_STR_TERMINATE
);
2404 fstrcpy(value
.valuename
, SPOOL_REG_PORTNAME
);
2407 if (strequal(info
[j
].value_name
, SPOOL_REG_UNCNAME
)) {
2409 if (asprintf(&unc_name
, "\\\\%s\\%s", longname
, sharename
) < 0) {
2410 nt_status
= NT_STATUS_NO_MEMORY
;
2413 init_unistr2(&data
, unc_name
, UNI_STR_TERMINATE
);
2414 fstrcpy(value
.valuename
, SPOOL_REG_UNCNAME
);
2417 if (strequal(info
[j
].value_name
, SPOOL_REG_URL
)) {
2422 /* FIXME: should we really do that ??? */
2423 if (asprintf(&url
, "http://%s:631/printers/%s", longname
, sharename
) < 0) {
2424 nt_status
= NT_STATUS_NO_MEMORY
;
2427 init_unistr2(&data
, url
, UNI_STR_TERMINATE
);
2428 fstrcpy(value
.valuename
, SPOOL_REG_URL
);
2432 if (strequal(info
[j
].value_name
, SPOOL_REG_SERVERNAME
)) {
2434 init_unistr2(&data
, longname
, UNI_STR_TERMINATE
);
2435 fstrcpy(value
.valuename
, SPOOL_REG_SERVERNAME
);
2438 if (strequal(info
[j
].value_name
, SPOOL_REG_SHORTSERVERNAME
)) {
2440 init_unistr2(&data
, global_myname(), UNI_STR_TERMINATE
);
2441 fstrcpy(value
.valuename
, SPOOL_REG_SHORTSERVERNAME
);
2444 value
.type
= REG_SZ
;
2445 value
.size
= data
.uni_str_len
* 2;
2447 value
.data_p
= (uint8_t *)TALLOC_MEMDUP(mem_ctx
, data
.buffer
, value
.size
);
2449 value
.data_p
= NULL
;
2453 display_reg_value(subkey
, value
);
2455 /* here we have to set all subkeys on the dst server */
2456 if (!net_spoolss_setprinterdataex(pipe_hnd_dst
, mem_ctx
, &hnd_dst
,
2465 result
= push_spoolss_PrinterData(mem_ctx
, &blob
,
2468 if (!W_ERROR_IS_OK(result
)) {
2472 fstrcpy(v
.valuename
, info
[j
].value_name
);
2473 v
.type
= info
[j
].type
;
2474 v
.data_p
= blob
.data
;
2475 v
.size
= blob
.length
;
2477 if (c
->opt_verbose
) {
2478 display_reg_value(subkey
, v
);
2481 /* here we have to set all subkeys on the dst server */
2482 if (!net_spoolss_setprinterdataex(pipe_hnd_dst
, mem_ctx
, &hnd_dst
,
2489 DEBUGADD(1,("\tSetPrinterDataEx of key [%s\\%s] succeeded\n",
2490 subkey
, info
[j
].value_name
));
2495 TALLOC_FREE(keylist
);
2497 /* close printer handles here */
2498 if (is_valid_policy_hnd(&hnd_src
)) {
2499 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
2502 if (is_valid_policy_hnd(&hnd_dst
)) {
2503 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
2508 nt_status
= NT_STATUS_OK
;
2511 SAFE_FREE(devicename
);
2513 SAFE_FREE(unc_name
);
2515 if (is_valid_policy_hnd(&hnd_src
))
2516 rpccli_spoolss_ClosePrinter(pipe_hnd
, mem_ctx
, &hnd_src
, NULL
);
2518 if (is_valid_policy_hnd(&hnd_dst
))
2519 rpccli_spoolss_ClosePrinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, NULL
);
2522 cli_shutdown(cli_dst
);