2 Samba Unix/Linux SMB client library
3 Distributed SMB/CIFS Server Management Utility
4 Copyright (C) 2004 Guenther Deschner (gd@samba.org)
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "utils/net.h"
23 const char *long_archi
;
24 const char *short_archi
;
29 /* support itanium as well */
30 static const struct table_node archi_table
[]= {
32 {"Windows 4.0", "WIN40", 0 },
33 {"Windows NT x86", "W32X86", 2 },
34 {"Windows NT x86", "W32X86", 3 },
35 {"Windows NT R4000", "W32MIPS", 2 },
36 {"Windows NT Alpha_AXP", "W32ALPHA", 2 },
37 {"Windows NT PowerPC", "W32PPC", 2 },
38 {"Windows IA64", "IA64", 3 },
39 {"Windows x64", "x64", 3 },
45 * This display-printdriver-functions was borrowed from rpcclient/cmd_spoolss.c.
46 * It is here for debugging purpose and should be removed later on.
49 /****************************************************************************
50 Printer info level 3 display function.
51 ****************************************************************************/
53 static void display_print_driver_3(DRIVER_INFO_3
*i1
)
56 fstring architecture
= "";
57 fstring driverpath
= "";
58 fstring datafile
= "";
59 fstring configfile
= "";
60 fstring helpfile
= "";
61 fstring dependentfiles
= "";
62 fstring monitorname
= "";
63 fstring defaultdatatype
= "";
71 rpcstr_pull(name
, i1
->name
.buffer
, sizeof(name
), -1, STR_TERMINATE
);
72 rpcstr_pull(architecture
, i1
->architecture
.buffer
, sizeof(architecture
), -1, STR_TERMINATE
);
73 rpcstr_pull(driverpath
, i1
->driverpath
.buffer
, sizeof(driverpath
), -1, STR_TERMINATE
);
74 rpcstr_pull(datafile
, i1
->datafile
.buffer
, sizeof(datafile
), -1, STR_TERMINATE
);
75 rpcstr_pull(configfile
, i1
->configfile
.buffer
, sizeof(configfile
), -1, STR_TERMINATE
);
76 rpcstr_pull(helpfile
, i1
->helpfile
.buffer
, sizeof(helpfile
), -1, STR_TERMINATE
);
77 rpcstr_pull(monitorname
, i1
->monitorname
.buffer
, sizeof(monitorname
), -1, STR_TERMINATE
);
78 rpcstr_pull(defaultdatatype
, i1
->defaultdatatype
.buffer
, sizeof(defaultdatatype
), -1, STR_TERMINATE
);
80 d_printf ("Printer Driver Info 3:\n");
81 d_printf ("\tVersion: [%x]\n", i1
->version
);
82 d_printf ("\tDriver Name: [%s]\n",name
);
83 d_printf ("\tArchitecture: [%s]\n", architecture
);
84 d_printf ("\tDriver Path: [%s]\n", driverpath
);
85 d_printf ("\tDatafile: [%s]\n", datafile
);
86 d_printf ("\tConfigfile: [%s]\n", configfile
);
87 d_printf ("\tHelpfile: [%s]\n\n", helpfile
);
90 rpcstr_pull(dependentfiles
, i1
->dependentfiles
+length
, sizeof(dependentfiles
), -1, STR_TERMINATE
);
92 length
+=strlen(dependentfiles
)+1;
94 if (strlen(dependentfiles
) > 0) {
95 d_printf ("\tDependentfiles: [%s]\n", dependentfiles
);
103 d_printf ("\tMonitorname: [%s]\n", monitorname
);
104 d_printf ("\tDefaultdatatype: [%s]\n\n", defaultdatatype
);
109 static void display_reg_value(const char *subkey
, REGISTRY_VALUE value
)
115 d_printf("\t[%s:%s]: REG_DWORD: 0x%08x\n", subkey
, value
.valuename
,
116 *((uint32
*) value
.data_p
));
120 rpcstr_pull_talloc(talloc_tos(),
128 d_printf("\t[%s:%s]: REG_SZ: %s\n", subkey
, value
.valuename
, text
);
132 d_printf("\t[%s:%s]: REG_BINARY: unknown length value not displayed\n",
133 subkey
, value
.valuename
);
137 uint32 i
, num_values
;
140 if (!W_ERROR_IS_OK(reg_pull_multi_sz(NULL
, value
.data_p
,
141 value
.size
, &num_values
,
143 d_printf("reg_pull_multi_sz failed\n");
147 for (i
=0; i
<num_values
; i
++) {
148 d_printf("%s\n", values
[i
]);
155 d_printf("\t%s: unknown type %d\n", value
.valuename
, value
.type
);
161 * Copies ACLs, DOS-attributes and timestamps from one
162 * file or directory from one connected share to another connected share
164 * @param c A net_context structure
165 * @param mem_ctx A talloc-context
166 * @param cli_share_src A connected cli_state
167 * @param cli_share_dst A connected cli_state
168 * @param src_file The source file-name
169 * @param dst_file The destination file-name
170 * @param copy_acls Whether to copy acls
171 * @param copy_attrs Whether to copy DOS attributes
172 * @param copy_timestamps Whether to preserve timestamps
173 * @param is_file Whether this file is a file or a dir
175 * @return Normal NTSTATUS return.
178 NTSTATUS
net_copy_fileattr(struct net_context
*c
,
180 struct cli_state
*cli_share_src
,
181 struct cli_state
*cli_share_dst
,
182 const char *src_name
, const char *dst_name
,
183 bool copy_acls
, bool copy_attrs
,
184 bool copy_timestamps
, bool is_file
)
186 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
191 time_t f_atime
, f_ctime
, f_mtime
;
194 if (!copy_timestamps
&& !copy_acls
&& !copy_attrs
)
197 /* open file/dir on the originating server */
199 DEBUGADD(3,("opening %s %s on originating server\n",
200 is_file
?"file":"dir", src_name
));
202 fnum_src
= cli_nt_create(cli_share_src
, src_name
, READ_CONTROL_ACCESS
);
203 if (fnum_src
== -1) {
204 DEBUGADD(0,("cannot open %s %s on originating server %s\n",
205 is_file
?"file":"dir", src_name
, cli_errstr(cli_share_src
)));
206 nt_status
= cli_nt_error(cli_share_src
);
213 /* get the security descriptor */
214 sd
= cli_query_secdesc(cli_share_src
, fnum_src
, mem_ctx
);
216 DEBUG(0,("failed to get security descriptor: %s\n",
217 cli_errstr(cli_share_src
)));
218 nt_status
= cli_nt_error(cli_share_src
);
222 if (c
->opt_verbose
&& DEBUGLEVEL
>= 3)
223 display_sec_desc(sd
);
227 if (copy_attrs
|| copy_timestamps
) {
229 /* get file attributes */
230 if (!cli_getattrE(cli_share_src
, fnum_src
, &attr
, NULL
,
231 &f_ctime
, &f_atime
, &f_mtime
)) {
232 DEBUG(0,("failed to get file-attrs: %s\n",
233 cli_errstr(cli_share_src
)));
234 nt_status
= cli_nt_error(cli_share_src
);
240 /* open the file/dir on the destination server */
242 fnum_dst
= cli_nt_create(cli_share_dst
, dst_name
, WRITE_DAC_ACCESS
| WRITE_OWNER_ACCESS
);
243 if (fnum_dst
== -1) {
244 DEBUG(0,("failed to open %s on the destination server: %s: %s\n",
245 is_file
?"file":"dir", dst_name
, cli_errstr(cli_share_dst
)));
246 nt_status
= cli_nt_error(cli_share_dst
);
250 if (copy_timestamps
) {
253 if (!cli_setattrE(cli_share_dst
, fnum_dst
, f_ctime
, f_atime
, f_mtime
)) {
254 DEBUG(0,("failed to set file-attrs (timestamps): %s\n",
255 cli_errstr(cli_share_dst
)));
256 nt_status
= cli_nt_error(cli_share_dst
);
264 if (!cli_set_secdesc(cli_share_dst
, fnum_dst
, sd
)) {
265 DEBUG(0,("could not set secdesc on %s: %s\n",
266 dst_name
, cli_errstr(cli_share_dst
)));
267 nt_status
= cli_nt_error(cli_share_dst
);
275 if (!cli_setatr(cli_share_dst
, dst_name
, attr
, 0)) {
276 DEBUG(0,("failed to set file-attrs: %s\n",
277 cli_errstr(cli_share_dst
)));
278 nt_status
= cli_nt_error(cli_share_dst
);
286 if (!cli_close(cli_share_src
, fnum_src
)) {
287 d_fprintf(stderr
, "could not close %s on originating server: %s\n",
288 is_file
?"file":"dir", cli_errstr(cli_share_src
));
289 nt_status
= cli_nt_error(cli_share_src
);
293 if (!cli_close(cli_share_dst
, fnum_dst
)) {
294 d_fprintf(stderr
, "could not close %s on destination server: %s\n",
295 is_file
?"file":"dir", cli_errstr(cli_share_dst
));
296 nt_status
= cli_nt_error(cli_share_dst
);
301 nt_status
= NT_STATUS_OK
;
307 cli_close(cli_share_src
, fnum_src
);
310 cli_close(cli_share_dst
, fnum_dst
);
316 * Copy a file or directory from a connected share to another connected share
318 * @param c A net_context structure
319 * @param mem_ctx A talloc-context
320 * @param cli_share_src A connected cli_state
321 * @param cli_share_dst A connected cli_state
322 * @param src_file The source file-name
323 * @param dst_file The destination file-name
324 * @param copy_acls Whether to copy acls
325 * @param copy_attrs Whether to copy DOS attributes
326 * @param copy_timestamps Whether to preserve timestamps
327 * @param is_file Whether this file is a file or a dir
329 * @return Normal NTSTATUS return.
332 NTSTATUS
net_copy_file(struct net_context
*c
,
334 struct cli_state
*cli_share_src
,
335 struct cli_state
*cli_share_dst
,
336 const char *src_name
, const char *dst_name
,
337 bool copy_acls
, bool copy_attrs
,
338 bool copy_timestamps
, bool is_file
)
340 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
343 static int io_bufsize
= 64512;
344 int read_size
= io_bufsize
;
349 if (!src_name
|| !dst_name
)
352 if (cli_share_src
== NULL
|| cli_share_dst
== NULL
)
355 /* open on the originating server */
356 DEBUGADD(3,("opening %s %s on originating server\n",
357 is_file
? "file":"dir", src_name
));
359 fnum_src
= cli_open(cli_share_src
, src_name
, O_RDONLY
, DENY_NONE
);
361 fnum_src
= cli_nt_create(cli_share_src
, src_name
, READ_CONTROL_ACCESS
);
363 if (fnum_src
== -1) {
364 DEBUGADD(0,("cannot open %s %s on originating server %s\n",
365 is_file
? "file":"dir",
366 src_name
, cli_errstr(cli_share_src
)));
367 nt_status
= cli_nt_error(cli_share_src
);
374 /* open file on the destination server */
375 DEBUGADD(3,("opening file %s on destination server\n", dst_name
));
376 fnum_dst
= cli_open(cli_share_dst
, dst_name
,
377 O_RDWR
|O_CREAT
|O_TRUNC
, DENY_NONE
);
379 if (fnum_dst
== -1) {
380 DEBUGADD(1,("cannot create file %s on destination server: %s\n",
381 dst_name
, cli_errstr(cli_share_dst
)));
382 nt_status
= cli_nt_error(cli_share_dst
);
386 /* allocate memory */
387 if (!(data
= (char *)SMB_MALLOC(read_size
))) {
388 d_fprintf(stderr
, "malloc fail for size %d\n", read_size
);
389 nt_status
= NT_STATUS_NO_MEMORY
;
396 if (c
->opt_verbose
) {
398 d_printf("copying [\\\\%s\\%s%s] => [\\\\%s\\%s%s] "
399 "%s ACLs and %s DOS Attributes %s\n",
400 cli_share_src
->desthost
, cli_share_src
->share
, src_name
,
401 cli_share_dst
->desthost
, cli_share_dst
->share
, dst_name
,
402 copy_acls
? "with" : "without",
403 copy_attrs
? "with" : "without",
404 copy_timestamps
? "(preserving timestamps)" : "" );
412 n
= cli_read(cli_share_src
, fnum_src
, data
, nread
,
418 ret
= cli_write(cli_share_dst
, fnum_dst
, 0, data
,
422 d_fprintf(stderr
, "Error writing file: %s\n",
423 cli_errstr(cli_share_dst
));
424 nt_status
= cli_nt_error(cli_share_dst
);
432 if (!is_file
&& !cli_chkpath(cli_share_dst
, dst_name
)) {
435 DEBUGADD(3,("creating dir %s on the destination server\n",
438 if (!cli_mkdir(cli_share_dst
, dst_name
)) {
439 DEBUG(0,("cannot create directory %s: %s\n",
440 dst_name
, cli_errstr(cli_share_dst
)));
441 nt_status
= NT_STATUS_NO_SUCH_FILE
;
444 if (!cli_chkpath(cli_share_dst
, dst_name
)) {
445 d_fprintf(stderr
, "cannot check for directory %s: %s\n",
446 dst_name
, cli_errstr(cli_share_dst
));
453 if (!cli_close(cli_share_src
, fnum_src
)) {
454 d_fprintf(stderr
, "could not close file on originating server: %s\n",
455 cli_errstr(cli_share_src
));
456 nt_status
= cli_nt_error(cli_share_src
);
460 if (is_file
&& !cli_close(cli_share_dst
, fnum_dst
)) {
461 d_fprintf(stderr
, "could not close file on destination server: %s\n",
462 cli_errstr(cli_share_dst
));
463 nt_status
= cli_nt_error(cli_share_dst
);
467 /* possibly we have to copy some file-attributes / acls / sd */
468 nt_status
= net_copy_fileattr(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
469 src_name
, dst_name
, copy_acls
,
470 copy_attrs
, copy_timestamps
, is_file
);
471 if (!NT_STATUS_IS_OK(nt_status
))
475 nt_status
= NT_STATUS_OK
;
481 cli_close(cli_share_src
, fnum_src
);
484 cli_close(cli_share_dst
, fnum_dst
);
492 * Copy a driverfile from on connected share to another connected share
493 * This silently assumes that a driver-file is picked up from
495 * \\src_server\print$\{arch}\{version}\file
499 * \\dst_server\print$\{arch}\file
501 * to be added via setdriver-calls later.
502 * @param c A net_context structure
503 * @param mem_ctx A talloc-context
504 * @param cli_share_src A cli_state connected to source print$-share
505 * @param cli_share_dst A cli_state connected to destination print$-share
506 * @param file The file-name to be copied
507 * @param short_archi The name of the driver-architecture (short form)
509 * @return Normal NTSTATUS return.
512 static NTSTATUS
net_copy_driverfile(struct net_context
*c
,
514 struct cli_state
*cli_share_src
,
515 struct cli_state
*cli_share_dst
,
516 char *file
, const char *short_archi
) {
518 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
526 /* scroll through the file until we have the part
527 beyond archi_table.short_archi */
529 while (next_token_talloc(mem_ctx
, &p
, &tok
, "\\")) {
530 if (strequal(tok
, short_archi
)) {
531 next_token_talloc(mem_ctx
, &p
, &version
, "\\");
532 next_token_talloc(mem_ctx
, &p
, &filename
, "\\");
536 /* build source file name */
537 if (asprintf(&src_name
, "\\%s\\%s\\%s", short_archi
, version
, filename
) < 0 )
538 return NT_STATUS_NO_MEMORY
;
541 /* create destination file name */
542 if (asprintf(&dst_name
, "\\%s\\%s", short_archi
, filename
) < 0 )
543 return NT_STATUS_NO_MEMORY
;
546 /* finally copy the file */
547 nt_status
= net_copy_file(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
548 src_name
, dst_name
, false, false, false, true);
549 if (!NT_STATUS_IS_OK(nt_status
))
552 nt_status
= NT_STATUS_OK
;
562 * Check for existing Architecture directory on a given server
564 * @param cli_share A cli_state connected to a print$-share
565 * @param short_archi The Architecture for the print-driver
567 * @return Normal NTSTATUS return.
570 static NTSTATUS
check_arch_dir(struct cli_state
*cli_share
, const char *short_archi
)
573 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
576 if (asprintf(&dir
, "\\%s", short_archi
) < 0) {
577 return NT_STATUS_NO_MEMORY
;
580 DEBUG(10,("creating print-driver dir for architecture: %s\n",
583 if (!cli_mkdir(cli_share
, dir
)) {
584 DEBUG(1,("cannot create directory %s: %s\n",
585 dir
, cli_errstr(cli_share
)));
586 nt_status
= NT_STATUS_NO_SUCH_FILE
;
589 if (!cli_chkpath(cli_share
, dir
)) {
590 d_fprintf(stderr
, "cannot check %s: %s\n",
591 dir
, cli_errstr(cli_share
));
595 nt_status
= NT_STATUS_OK
;
603 * Copy a print-driver (level 3) from one connected print$-share to another
604 * connected print$-share
606 * @param c A net_context structure
607 * @param mem_ctx A talloc-context
608 * @param cli_share_src A cli_state connected to a print$-share
609 * @param cli_share_dst A cli_state connected to a print$-share
610 * @param short_archi The Architecture for the print-driver
611 * @param i1 The DRIVER_INFO_3-struct
613 * @return Normal NTSTATUS return.
616 static NTSTATUS
copy_print_driver_3(struct net_context
*c
,
618 struct cli_state
*cli_share_src
,
619 struct cli_state
*cli_share_dst
,
620 const char *short_archi
, DRIVER_INFO_3
*i1
)
622 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
627 fstring driverpath
= "";
628 fstring datafile
= "";
629 fstring configfile
= "";
630 fstring helpfile
= "";
631 fstring dependentfiles
= "";
636 rpcstr_pull(name
, i1
->name
.buffer
, sizeof(name
), -1, STR_TERMINATE
);
637 rpcstr_pull(driverpath
, i1
->driverpath
.buffer
, sizeof(driverpath
), -1, STR_TERMINATE
);
638 rpcstr_pull(datafile
, i1
->datafile
.buffer
, sizeof(datafile
), -1, STR_TERMINATE
);
639 rpcstr_pull(configfile
, i1
->configfile
.buffer
, sizeof(configfile
), -1, STR_TERMINATE
);
640 rpcstr_pull(helpfile
, i1
->helpfile
.buffer
, sizeof(helpfile
), -1, STR_TERMINATE
);
644 d_printf("copying driver: [%s], for architecture: [%s], version: [%d]\n",
645 name
, short_archi
, i1
->version
);
647 nt_status
= net_copy_driverfile(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
648 driverpath
, short_archi
);
649 if (!NT_STATUS_IS_OK(nt_status
))
652 nt_status
= net_copy_driverfile(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
653 datafile
, short_archi
);
654 if (!NT_STATUS_IS_OK(nt_status
))
657 nt_status
= net_copy_driverfile(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
658 configfile
, short_archi
);
659 if (!NT_STATUS_IS_OK(nt_status
))
662 nt_status
= net_copy_driverfile(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
663 helpfile
, short_archi
);
664 if (!NT_STATUS_IS_OK(nt_status
))
669 rpcstr_pull(dependentfiles
, i1
->dependentfiles
+length
, sizeof(dependentfiles
), -1, STR_TERMINATE
);
670 length
+= strlen(dependentfiles
)+1;
672 if (strlen(dependentfiles
) > 0) {
674 nt_status
= net_copy_driverfile(c
, mem_ctx
,
675 cli_share_src
, cli_share_dst
,
676 dependentfiles
, short_archi
);
677 if (!NT_STATUS_IS_OK(nt_status
))
688 * net_spoolss-functions
689 * =====================
691 * the net_spoolss-functions aim to simplify spoolss-client-functions
692 * required during the migration-process wrt buffer-sizes, returned
695 * this greatly reduces the complexitiy of the migrate-functions.
699 static bool net_spoolss_enum_printers(struct rpc_pipe_client
*pipe_hnd
,
704 uint32
*num_printers
,
705 PRINTER_INFO_CTR
*ctr
)
710 result
= rpccli_spoolss_enum_printers(pipe_hnd
, mem_ctx
, name
, flags
,
711 level
, num_printers
, ctr
);
713 if (!W_ERROR_IS_OK(result
)) {
714 printf("cannot enum printers: %s\n", dos_errstr(result
));
721 static bool net_spoolss_open_printer_ex(struct rpc_pipe_client
*pipe_hnd
,
723 const char *printername
,
724 uint32 access_required
,
725 const char *username
,
729 fstring servername
, printername2
;
731 slprintf(servername
, sizeof(servername
)-1, "\\\\%s",
734 fstrcpy(printername2
, servername
);
735 fstrcat(printername2
, "\\");
736 fstrcat(printername2
, printername
);
738 DEBUG(10,("connecting to: %s as %s for %s and access: %x\n",
739 servername
, username
, printername2
, access_required
));
742 result
= rpccli_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, printername2
,
744 servername
, username
, hnd
);
746 /* be more verbose */
747 if (W_ERROR_V(result
) == W_ERROR_V(WERR_ACCESS_DENIED
)) {
748 d_fprintf(stderr
, "no access to printer [%s] on [%s] for user [%s] granted\n",
749 printername2
, servername
, username
);
753 if (!W_ERROR_IS_OK(result
)) {
754 d_fprintf(stderr
, "cannot open printer %s on server %s: %s\n",
755 printername2
, servername
, dos_errstr(result
));
759 DEBUG(2,("got printer handle for printer: %s, server: %s\n",
760 printername2
, servername
));
765 static bool net_spoolss_getprinter(struct rpc_pipe_client
*pipe_hnd
,
769 PRINTER_INFO_CTR
*ctr
)
773 /* getprinter call */
774 result
= rpccli_spoolss_getprinter(pipe_hnd
, mem_ctx
, hnd
, level
, ctr
);
776 if (!W_ERROR_IS_OK(result
)) {
777 printf("cannot get printer-info: %s\n", dos_errstr(result
));
784 static bool net_spoolss_setprinter(struct rpc_pipe_client
*pipe_hnd
,
788 PRINTER_INFO_CTR
*ctr
)
792 /* setprinter call */
793 result
= rpccli_spoolss_setprinter(pipe_hnd
, mem_ctx
, hnd
, level
, ctr
, 0);
795 if (!W_ERROR_IS_OK(result
)) {
796 printf("cannot set printer-info: %s\n", dos_errstr(result
));
804 static bool net_spoolss_setprinterdata(struct rpc_pipe_client
*pipe_hnd
,
807 REGISTRY_VALUE
*value
)
811 /* setprinterdata call */
812 result
= rpccli_spoolss_setprinterdata(pipe_hnd
, mem_ctx
, hnd
, value
);
814 if (!W_ERROR_IS_OK(result
)) {
815 printf ("unable to set printerdata: %s\n", dos_errstr(result
));
823 static bool net_spoolss_enumprinterkey(struct rpc_pipe_client
*pipe_hnd
,
831 /* enumprinterkey call */
832 result
= rpccli_spoolss_enumprinterkey(pipe_hnd
, mem_ctx
, hnd
, keyname
, keylist
, NULL
);
834 if (!W_ERROR_IS_OK(result
)) {
835 printf("enumprinterkey failed: %s\n", dos_errstr(result
));
842 static bool net_spoolss_enumprinterdataex(struct rpc_pipe_client
*pipe_hnd
,
851 /* enumprinterdataex call */
852 result
= rpccli_spoolss_enumprinterdataex(pipe_hnd
, mem_ctx
, hnd
, keyname
, ctr
);
854 if (!W_ERROR_IS_OK(result
)) {
855 printf("enumprinterdataex failed: %s\n", dos_errstr(result
));
863 static bool net_spoolss_setprinterdataex(struct rpc_pipe_client
*pipe_hnd
,
867 REGISTRY_VALUE
*value
)
871 /* setprinterdataex call */
872 result
= rpccli_spoolss_setprinterdataex(pipe_hnd
, mem_ctx
, hnd
,
875 if (!W_ERROR_IS_OK(result
)) {
876 printf("could not set printerdataex: %s\n", dos_errstr(result
));
883 static bool net_spoolss_enumforms(struct rpc_pipe_client
*pipe_hnd
,
893 result
= rpccli_spoolss_enumforms(pipe_hnd
, mem_ctx
, hnd
, level
, num_forms
, forms
);
895 if (!W_ERROR_IS_OK(result
)) {
896 printf("could not enum forms: %s\n", dos_errstr(result
));
903 static bool net_spoolss_enumprinterdrivers (struct rpc_pipe_client
*pipe_hnd
,
905 uint32 level
, const char *env
,
907 PRINTER_DRIVER_CTR
*ctr
)
911 /* enumprinterdrivers call */
912 result
= rpccli_spoolss_enumprinterdrivers(
913 pipe_hnd
, mem_ctx
, level
,
914 env
, num_drivers
, ctr
);
916 if (!W_ERROR_IS_OK(result
)) {
917 printf("cannot enum drivers: %s\n", dos_errstr(result
));
924 static bool net_spoolss_getprinterdriver(struct rpc_pipe_client
*pipe_hnd
,
926 POLICY_HND
*hnd
, uint32 level
,
927 const char *env
, int version
,
928 PRINTER_DRIVER_CTR
*ctr
)
932 /* getprinterdriver call */
933 result
= rpccli_spoolss_getprinterdriver(
934 pipe_hnd
, mem_ctx
, hnd
, level
,
937 if (!W_ERROR_IS_OK(result
)) {
938 DEBUG(1,("cannot get driver (for architecture: %s): %s\n",
939 env
, dos_errstr(result
)));
940 if (W_ERROR_V(result
) != W_ERROR_V(WERR_UNKNOWN_PRINTER_DRIVER
) &&
941 W_ERROR_V(result
) != W_ERROR_V(WERR_INVALID_ENVIRONMENT
)) {
942 printf("cannot get driver: %s\n", dos_errstr(result
));
951 static bool net_spoolss_addprinterdriver(struct rpc_pipe_client
*pipe_hnd
,
952 TALLOC_CTX
*mem_ctx
, uint32 level
,
953 PRINTER_DRIVER_CTR
*ctr
)
957 /* addprinterdriver call */
958 result
= rpccli_spoolss_addprinterdriver(pipe_hnd
, mem_ctx
, level
, ctr
);
960 /* be more verbose */
961 if (W_ERROR_V(result
) == W_ERROR_V(WERR_ACCESS_DENIED
)) {
962 printf("You are not allowed to add drivers\n");
965 if (!W_ERROR_IS_OK(result
)) {
966 printf("cannot add driver: %s\n", dos_errstr(result
));
974 * abstraction function to get uint32 num_printers and PRINTER_INFO_CTR ctr
975 * for a single printer or for all printers depending on argc/argv
978 static bool get_printer_info(struct rpc_pipe_client
*pipe_hnd
,
983 uint32
*num_printers
,
984 PRINTER_INFO_CTR
*ctr
)
989 /* no arguments given, enumerate all printers */
992 if (!net_spoolss_enum_printers(pipe_hnd
, mem_ctx
, NULL
,
993 PRINTER_ENUM_LOCAL
|PRINTER_ENUM_SHARED
,
994 level
, num_printers
, ctr
))
1001 /* argument given, get a single printer by name */
1002 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, argv
[0],
1003 MAXIMUM_ALLOWED_ACCESS
,
1004 pipe_hnd
->auth
->user_name
,
1008 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd
, level
, ctr
)) {
1009 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd
);
1013 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd
);
1018 DEBUG(3,("got %d printers\n", *num_printers
));
1025 * List print-queues (including local printers that are not shared)
1027 * All parameters are provided by the run_rpc_command function, except for
1028 * argc, argv which are passed through.
1030 * @param c A net_context structure
1031 * @param domain_sid The domain sid aquired from the remote server
1032 * @param cli A cli_state connected to the server.
1033 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1034 * @param argc Standard main() style argc
1035 * @param argv Standard main() style argv. Initial components are already
1038 * @return Normal NTSTATUS return.
1041 NTSTATUS
rpc_printer_list_internals(struct net_context
*c
,
1042 const DOM_SID
*domain_sid
,
1043 const char *domain_name
,
1044 struct cli_state
*cli
,
1045 struct rpc_pipe_client
*pipe_hnd
,
1046 TALLOC_CTX
*mem_ctx
,
1050 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1051 uint32 i
, num_printers
;
1053 char *printername
, *sharename
;
1054 PRINTER_INFO_CTR ctr
;
1056 printf("listing printers\n");
1058 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &ctr
))
1061 for (i
= 0; i
< num_printers
; i
++) {
1062 /* do some initialization */
1063 rpcstr_pull_talloc(mem_ctx
,
1065 ctr
.printers_2
[i
].printername
.buffer
,
1068 rpcstr_pull_talloc(mem_ctx
,
1070 ctr
.printers_2
[i
].sharename
.buffer
,
1074 if (printername
&& sharename
) {
1075 d_printf("printer %d: %s, shared as: %s\n",
1076 i
+1, printername
, sharename
);
1080 return NT_STATUS_OK
;
1084 * List printer-drivers from a server
1086 * All parameters are provided by the run_rpc_command function, except for
1087 * argc, argv which are passed through.
1089 * @param c A net_context structure
1090 * @param domain_sid The domain sid aquired from the remote server
1091 * @param cli A cli_state connected to the server.
1092 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1093 * @param argc Standard main() style argc
1094 * @param argv Standard main() style argv. Initial components are already
1097 * @return Normal NTSTATUS return.
1100 NTSTATUS
rpc_printer_driver_list_internals(struct net_context
*c
,
1101 const DOM_SID
*domain_sid
,
1102 const char *domain_name
,
1103 struct cli_state
*cli
,
1104 struct rpc_pipe_client
*pipe_hnd
,
1105 TALLOC_CTX
*mem_ctx
,
1109 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1112 PRINTER_DRIVER_CTR drv_ctr_enum
;
1115 ZERO_STRUCT(drv_ctr_enum
);
1117 printf("listing printer-drivers\n");
1119 for (i
=0; archi_table
[i
].long_archi
!=NULL
; i
++) {
1123 /* enum remote drivers */
1124 if (!net_spoolss_enumprinterdrivers(pipe_hnd
, mem_ctx
, level
,
1125 archi_table
[i
].long_archi
,
1126 &num_drivers
, &drv_ctr_enum
)) {
1127 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1131 if (num_drivers
== 0) {
1132 d_printf ("no drivers found on server for architecture: [%s].\n",
1133 archi_table
[i
].long_archi
);
1137 d_printf("got %d printer-drivers for architecture: [%s]\n",
1138 num_drivers
, archi_table
[i
].long_archi
);
1141 /* do something for all drivers for architecture */
1142 for (d
= 0; d
< num_drivers
; d
++) {
1143 display_print_driver_3(&(drv_ctr_enum
.info3
[d
]));
1147 nt_status
= NT_STATUS_OK
;
1155 * Publish print-queues with args-wrapper
1157 * @param cli A cli_state connected to the server.
1158 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1159 * @param argc Standard main() style argc
1160 * @param argv Standard main() style argv. Initial components are already
1164 * @return Normal NTSTATUS return.
1167 static NTSTATUS
rpc_printer_publish_internals_args(struct rpc_pipe_client
*pipe_hnd
,
1168 TALLOC_CTX
*mem_ctx
,
1173 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1174 uint32 i
, num_printers
;
1176 char *printername
, *sharename
;
1177 PRINTER_INFO_CTR ctr
, ctr_pub
;
1179 bool got_hnd
= false;
1181 const char *action_str
;
1183 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &ctr
))
1186 for (i
= 0; i
< num_printers
; i
++) {
1187 /* do some initialization */
1188 rpcstr_pull_talloc(mem_ctx
,
1190 ctr
.printers_2
[i
].printername
.buffer
,
1193 rpcstr_pull_talloc(mem_ctx
,
1195 ctr
.printers_2
[i
].sharename
.buffer
,
1198 if (!printername
|| !sharename
) {
1202 /* open printer handle */
1203 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1204 PRINTER_ALL_ACCESS
, pipe_hnd
->auth
->user_name
, &hnd
))
1209 /* check for existing dst printer */
1210 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd
, level
, &ctr_pub
))
1213 /* check action and set string */
1215 case SPOOL_DS_PUBLISH
:
1216 action_str
= "published";
1218 case SPOOL_DS_UPDATE
:
1219 action_str
= "updated";
1221 case SPOOL_DS_UNPUBLISH
:
1222 action_str
= "unpublished";
1225 action_str
= "unknown action";
1226 printf("unkown action: %d\n", action
);
1230 ctr_pub
.printers_7
->action
= action
;
1232 result
= rpccli_spoolss_setprinter(pipe_hnd
, mem_ctx
, &hnd
, level
, &ctr_pub
, 0);
1233 if (!W_ERROR_IS_OK(result
) && (W_ERROR_V(result
) != W_ERROR_V(WERR_IO_PENDING
))) {
1234 printf("cannot set printer-info: %s\n", dos_errstr(result
));
1238 printf("successfully %s printer %s in Active Directory\n", action_str
, sharename
);
1241 nt_status
= NT_STATUS_OK
;
1245 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd
);
1250 NTSTATUS
rpc_printer_publish_publish_internals(struct net_context
*c
,
1251 const DOM_SID
*domain_sid
,
1252 const char *domain_name
,
1253 struct cli_state
*cli
,
1254 struct rpc_pipe_client
*pipe_hnd
,
1255 TALLOC_CTX
*mem_ctx
,
1259 return rpc_printer_publish_internals_args(pipe_hnd
, mem_ctx
, argc
, argv
, SPOOL_DS_PUBLISH
);
1262 NTSTATUS
rpc_printer_publish_unpublish_internals(struct net_context
*c
,
1263 const DOM_SID
*domain_sid
,
1264 const char *domain_name
,
1265 struct cli_state
*cli
,
1266 struct rpc_pipe_client
*pipe_hnd
,
1267 TALLOC_CTX
*mem_ctx
,
1271 return rpc_printer_publish_internals_args(pipe_hnd
, mem_ctx
, argc
, argv
, SPOOL_DS_UNPUBLISH
);
1274 NTSTATUS
rpc_printer_publish_update_internals(struct net_context
*c
,
1275 const DOM_SID
*domain_sid
,
1276 const char *domain_name
,
1277 struct cli_state
*cli
,
1278 struct rpc_pipe_client
*pipe_hnd
,
1279 TALLOC_CTX
*mem_ctx
,
1283 return rpc_printer_publish_internals_args(pipe_hnd
, mem_ctx
, argc
, argv
, SPOOL_DS_UPDATE
);
1287 * List print-queues w.r.t. their publishing state
1289 * All parameters are provided by the run_rpc_command function, except for
1290 * argc, argv which are passed through.
1292 * @param c A net_context structure
1293 * @param domain_sid The domain sid aquired from the remote server
1294 * @param cli A cli_state connected to the server.
1295 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1296 * @param argc Standard main() style argc
1297 * @param argv Standard main() style argv. Initial components are already
1300 * @return Normal NTSTATUS return.
1303 NTSTATUS
rpc_printer_publish_list_internals(struct net_context
*c
,
1304 const DOM_SID
*domain_sid
,
1305 const char *domain_name
,
1306 struct cli_state
*cli
,
1307 struct rpc_pipe_client
*pipe_hnd
,
1308 TALLOC_CTX
*mem_ctx
,
1312 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1313 uint32 i
, num_printers
;
1315 char *printername
, *sharename
;
1317 PRINTER_INFO_CTR ctr
, ctr_pub
;
1319 bool got_hnd
= false;
1322 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &ctr
))
1325 for (i
= 0; i
< num_printers
; i
++) {
1326 ZERO_STRUCT(ctr_pub
);
1328 /* do some initialization */
1329 rpcstr_pull_talloc(mem_ctx
,
1331 ctr
.printers_2
[i
].printername
.buffer
,
1334 rpcstr_pull_talloc(mem_ctx
,
1336 ctr
.printers_2
[i
].sharename
.buffer
,
1339 if (!printername
|| !sharename
) {
1343 /* open printer handle */
1344 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1345 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd
))
1350 /* check for existing dst printer */
1351 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd
, level
, &ctr_pub
))
1354 rpcstr_pull_talloc(mem_ctx
,
1356 ctr_pub
.printers_7
->guid
.buffer
,
1362 state
= ctr_pub
.printers_7
->action
;
1364 case SPOOL_DS_PUBLISH
:
1365 printf("printer [%s] is published", sharename
);
1367 printf(", guid: %s", guid
);
1370 case SPOOL_DS_UNPUBLISH
:
1371 printf("printer [%s] is unpublished\n", sharename
);
1373 case SPOOL_DS_UPDATE
:
1374 printf("printer [%s] is currently updating\n", sharename
);
1377 printf("unkown state: %d\n", state
);
1382 nt_status
= NT_STATUS_OK
;
1386 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd
);
1392 * Migrate Printer-ACLs from a source server to the destination server
1394 * All parameters are provided by the run_rpc_command function, except for
1395 * argc, argv which are passed through.
1397 * @param c A net_context structure
1398 * @param domain_sid The domain sid aquired from the remote server
1399 * @param cli A cli_state connected to the server.
1400 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1401 * @param argc Standard main() style argc
1402 * @param argv Standard main() style argv. Initial components are already
1405 * @return Normal NTSTATUS return.
1408 NTSTATUS
rpc_printer_migrate_security_internals(struct net_context
*c
,
1409 const DOM_SID
*domain_sid
,
1410 const char *domain_name
,
1411 struct cli_state
*cli
,
1412 struct rpc_pipe_client
*pipe_hnd
,
1413 TALLOC_CTX
*mem_ctx
,
1417 /* TODO: what now, info2 or info3 ?
1418 convince jerry that we should add clientside setacls level 3 at least
1420 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1422 uint32 num_printers
;
1424 char *printername
, *sharename
;
1425 bool got_hnd_src
= false;
1426 bool got_hnd_dst
= false;
1427 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
1428 POLICY_HND hnd_src
, hnd_dst
;
1429 PRINTER_INFO_CTR ctr_src
, ctr_dst
, ctr_enum
;
1430 struct cli_state
*cli_dst
= NULL
;
1432 ZERO_STRUCT(ctr_src
);
1434 DEBUG(3,("copying printer ACLs\n"));
1436 /* connect destination PI_SPOOLSS */
1437 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
, PI_SPOOLSS
);
1438 if (!NT_STATUS_IS_OK(nt_status
))
1442 /* enum source printers */
1443 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &ctr_enum
)) {
1444 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1448 if (!num_printers
) {
1449 printf ("no printers found on server.\n");
1450 nt_status
= NT_STATUS_OK
;
1454 /* do something for all printers */
1455 for (i
= 0; i
< num_printers
; i
++) {
1456 /* do some initialization */
1457 rpcstr_pull_talloc(mem_ctx
,
1459 ctr_enum
.printers_2
[i
].printername
.buffer
,
1462 rpcstr_pull_talloc(mem_ctx
,
1464 ctr_enum
.printers_2
[i
].sharename
.buffer
,
1467 if (!printername
|| !sharename
) {
1468 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1472 /* we can reset NT_STATUS here because we do not
1473 get any real NT_STATUS-codes anymore from now on */
1474 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1476 d_printf("migrating printer ACLs for: [%s] / [%s]\n",
1477 printername
, sharename
);
1479 /* according to msdn you have specify these access-rights
1480 to see the security descriptor
1481 - READ_CONTROL (DACL)
1482 - ACCESS_SYSTEM_SECURITY (SACL)
1485 /* open src printer handle */
1486 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1487 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
1492 /* open dst printer handle */
1493 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
1494 PRINTER_ALL_ACCESS
, cli_dst
->user_name
, &hnd_dst
))
1499 /* check for existing dst printer */
1500 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, level
, &ctr_dst
))
1503 /* check for existing src printer */
1504 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd_src
, 3, &ctr_src
))
1507 /* Copy Security Descriptor */
1509 /* copy secdesc (info level 2) */
1510 ctr_dst
.printers_2
->devmode
= NULL
;
1511 ctr_dst
.printers_2
->secdesc
= dup_sec_desc(mem_ctx
, ctr_src
.printers_3
->secdesc
);
1514 display_sec_desc(ctr_dst
.printers_2
->secdesc
);
1516 if (!net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 2, &ctr_dst
))
1519 DEBUGADD(1,("\tSetPrinter of SECDESC succeeded\n"));
1522 /* close printer handles here */
1524 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
1525 got_hnd_src
= false;
1529 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
1530 got_hnd_dst
= false;
1535 nt_status
= NT_STATUS_OK
;
1540 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
1544 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
1548 cli_shutdown(cli_dst
);
1554 * Migrate printer-forms from a src server to the dst server
1556 * All parameters are provided by the run_rpc_command function, except for
1557 * argc, argv which are passed through.
1559 * @param c A net_context structure
1560 * @param domain_sid The domain sid aquired from the remote server
1561 * @param cli A cli_state connected to the server.
1562 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1563 * @param argc Standard main() style argc
1564 * @param argv Standard main() style argv. Initial components are already
1567 * @return Normal NTSTATUS return.
1570 NTSTATUS
rpc_printer_migrate_forms_internals(struct net_context
*c
,
1571 const DOM_SID
*domain_sid
,
1572 const char *domain_name
,
1573 struct cli_state
*cli
,
1574 struct rpc_pipe_client
*pipe_hnd
,
1575 TALLOC_CTX
*mem_ctx
,
1579 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1582 uint32 num_printers
;
1584 char *printername
, *sharename
;
1585 bool got_hnd_src
= false;
1586 bool got_hnd_dst
= false;
1587 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
1588 POLICY_HND hnd_src
, hnd_dst
;
1589 PRINTER_INFO_CTR ctr_enum
, ctr_dst
;
1592 struct cli_state
*cli_dst
= NULL
;
1594 ZERO_STRUCT(ctr_enum
);
1596 DEBUG(3,("copying forms\n"));
1598 /* connect destination PI_SPOOLSS */
1599 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
, PI_SPOOLSS
);
1600 if (!NT_STATUS_IS_OK(nt_status
))
1603 /* enum src printers */
1604 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &ctr_enum
)) {
1605 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1609 if (!num_printers
) {
1610 printf ("no printers found on server.\n");
1611 nt_status
= NT_STATUS_OK
;
1615 /* do something for all printers */
1616 for (i
= 0; i
< num_printers
; i
++) {
1617 /* do some initialization */
1618 rpcstr_pull_talloc(mem_ctx
,
1620 ctr_enum
.printers_2
[i
].printername
.buffer
,
1623 rpcstr_pull_talloc(mem_ctx
,
1625 ctr_enum
.printers_2
[i
].sharename
.buffer
,
1628 if (!printername
|| !sharename
) {
1629 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1632 /* we can reset NT_STATUS here because we do not
1633 get any real NT_STATUS-codes anymore from now on */
1634 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1636 d_printf("migrating printer forms for: [%s] / [%s]\n",
1637 printername
, sharename
);
1640 /* open src printer handle */
1641 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1642 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
1648 /* open dst printer handle */
1649 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
1650 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd_dst
))
1656 /* check for existing dst printer */
1657 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, level
, &ctr_dst
))
1660 /* finally migrate forms */
1661 if (!net_spoolss_enumforms(pipe_hnd
, mem_ctx
, &hnd_src
, level
, &num_forms
, &forms
))
1664 DEBUG(1,("got %d forms for printer\n", num_forms
));
1667 for (f
= 0; f
< num_forms
; f
++) {
1672 /* only migrate FORM_PRINTER types, according to jerry
1673 FORM_BUILTIN-types are hard-coded in samba */
1674 if (forms
[f
].flag
!= FORM_PRINTER
)
1677 if (forms
[f
].name
.buffer
)
1678 rpcstr_pull(form_name
, forms
[f
].name
.buffer
,
1679 sizeof(form_name
), -1, STR_TERMINATE
);
1682 d_printf("\tmigrating form # %d [%s] of type [%d]\n",
1683 f
, form_name
, forms
[f
].flag
);
1685 /* is there a more elegant way to do that ? */
1686 form
.flags
= FORM_PRINTER
;
1687 form
.size_x
= forms
[f
].width
;
1688 form
.size_y
= forms
[f
].length
;
1689 form
.left
= forms
[f
].left
;
1690 form
.top
= forms
[f
].top
;
1691 form
.right
= forms
[f
].right
;
1692 form
.bottom
= forms
[f
].bottom
;
1694 init_unistr2(&form
.name
, form_name
, UNI_STR_TERMINATE
);
1696 /* FIXME: there might be something wrong with samba's
1698 result
= rpccli_spoolss_addform(pipe_hnd_dst
, mem_ctx
,
1699 &hnd_dst
, 1, &form
);
1700 if (!W_ERROR_IS_OK(result
)) {
1701 d_printf("\tAddForm form %d: [%s] refused.\n",
1706 DEBUGADD(1,("\tAddForm of [%s] succeeded\n", form_name
));
1710 /* close printer handles here */
1712 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
1713 got_hnd_src
= false;
1717 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
1718 got_hnd_dst
= false;
1722 nt_status
= NT_STATUS_OK
;
1727 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
1730 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
1733 cli_shutdown(cli_dst
);
1739 * Migrate printer-drivers from a src server to the dst server
1741 * All parameters are provided by the run_rpc_command function, except for
1742 * argc, argv which are passed through.
1744 * @param c A net_context structure
1745 * @param domain_sid The domain sid aquired from the remote server
1746 * @param cli A cli_state connected to the server.
1747 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1748 * @param argc Standard main() style argc
1749 * @param argv Standard main() style argv. Initial components are already
1752 * @return Normal NTSTATUS return.
1755 NTSTATUS
rpc_printer_migrate_drivers_internals(struct net_context
*c
,
1756 const DOM_SID
*domain_sid
,
1757 const char *domain_name
,
1758 struct cli_state
*cli
,
1759 struct rpc_pipe_client
*pipe_hnd
,
1760 TALLOC_CTX
*mem_ctx
,
1764 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1766 uint32 num_printers
;
1768 char *printername
, *sharename
;
1769 bool got_hnd_src
= false;
1770 bool got_hnd_dst
= false;
1771 bool got_src_driver_share
= false;
1772 bool got_dst_driver_share
= false;
1773 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
1774 POLICY_HND hnd_src
, hnd_dst
;
1775 PRINTER_DRIVER_CTR drv_ctr_src
, drv_ctr_dst
;
1776 PRINTER_INFO_CTR info_ctr_enum
, info_ctr_dst
;
1777 struct cli_state
*cli_dst
= NULL
;
1778 struct cli_state
*cli_share_src
= NULL
;
1779 struct cli_state
*cli_share_dst
= NULL
;
1780 fstring drivername
= "";
1782 ZERO_STRUCT(drv_ctr_src
);
1783 ZERO_STRUCT(drv_ctr_dst
);
1784 ZERO_STRUCT(info_ctr_enum
);
1785 ZERO_STRUCT(info_ctr_dst
);
1787 DEBUG(3,("copying printer-drivers\n"));
1789 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
, PI_SPOOLSS
);
1790 if (!NT_STATUS_IS_OK(nt_status
))
1793 /* open print$-share on the src server */
1794 nt_status
= connect_to_service(c
, &cli_share_src
, &cli
->dest_ss
,
1795 cli
->desthost
, "print$", "A:");
1796 if (!NT_STATUS_IS_OK(nt_status
))
1799 got_src_driver_share
= true;
1802 /* open print$-share on the dst server */
1803 nt_status
= connect_to_service(c
, &cli_share_dst
, &cli_dst
->dest_ss
,
1804 cli_dst
->desthost
, "print$", "A:");
1805 if (!NT_STATUS_IS_OK(nt_status
))
1808 got_dst_driver_share
= true;
1811 /* enum src printers */
1812 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &info_ctr_enum
)) {
1813 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1817 if (num_printers
== 0) {
1818 printf ("no printers found on server.\n");
1819 nt_status
= NT_STATUS_OK
;
1824 /* do something for all printers */
1825 for (p
= 0; p
< num_printers
; p
++) {
1826 /* do some initialization */
1827 rpcstr_pull_talloc(mem_ctx
,
1829 info_ctr_enum
.printers_2
[p
].printername
.buffer
,
1832 rpcstr_pull_talloc(mem_ctx
,
1834 info_ctr_enum
.printers_2
[p
].sharename
.buffer
,
1837 if (!printername
|| !sharename
) {
1838 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1842 /* we can reset NT_STATUS here because we do not
1843 get any real NT_STATUS-codes anymore from now on */
1844 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1846 d_printf("migrating printer driver for: [%s] / [%s]\n",
1847 printername
, sharename
);
1849 /* open dst printer handle */
1850 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
1851 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd_dst
))
1856 /* check for existing dst printer */
1857 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 2, &info_ctr_dst
))
1861 /* open src printer handle */
1862 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1863 MAXIMUM_ALLOWED_ACCESS
,
1864 pipe_hnd
->auth
->user_name
,
1871 /* in a first step call getdriver for each shared printer (per arch)
1872 to get a list of all files that have to be copied */
1874 for (i
=0; archi_table
[i
].long_archi
!=NULL
; i
++) {
1877 if (!net_spoolss_getprinterdriver(pipe_hnd
, mem_ctx
, &hnd_src
,
1878 level
, archi_table
[i
].long_archi
,
1879 archi_table
[i
].version
, &drv_ctr_src
))
1882 rpcstr_pull(drivername
, drv_ctr_src
.info3
->name
.buffer
,
1883 sizeof(drivername
), -1, STR_TERMINATE
);
1886 display_print_driver_3(drv_ctr_src
.info3
);
1889 /* check arch dir */
1890 nt_status
= check_arch_dir(cli_share_dst
, archi_table
[i
].short_archi
);
1891 if (!NT_STATUS_IS_OK(nt_status
))
1895 /* copy driver-files */
1896 nt_status
= copy_print_driver_3(c
, mem_ctx
, cli_share_src
, cli_share_dst
,
1897 archi_table
[i
].short_archi
,
1899 if (!NT_STATUS_IS_OK(nt_status
))
1904 if (!net_spoolss_addprinterdriver(pipe_hnd_dst
, mem_ctx
, level
, &drv_ctr_src
)) {
1905 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1909 DEBUGADD(1,("Sucessfully added driver [%s] for printer [%s]\n",
1910 drivername
, printername
));
1914 if (strlen(drivername
) == 0) {
1915 DEBUGADD(1,("Did not get driver for printer %s\n",
1921 init_unistr(&info_ctr_dst
.printers_2
->drivername
, drivername
);
1923 if (!net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 2, &info_ctr_dst
)) {
1924 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1928 DEBUGADD(1,("Sucessfully set driver %s for printer %s\n",
1929 drivername
, printername
));
1933 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
1934 got_hnd_dst
= false;
1939 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
1940 got_hnd_src
= false;
1944 nt_status
= NT_STATUS_OK
;
1949 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
1952 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
1955 cli_shutdown(cli_dst
);
1958 if (got_src_driver_share
)
1959 cli_shutdown(cli_share_src
);
1961 if (got_dst_driver_share
)
1962 cli_shutdown(cli_share_dst
);
1969 * Migrate printer-queues from a src to the dst server
1970 * (requires a working "addprinter command" to be installed for the local smbd)
1972 * All parameters are provided by the run_rpc_command function, except for
1973 * argc, argv which are passed through.
1975 * @param c A net_context structure
1976 * @param domain_sid The domain sid aquired from the remote server
1977 * @param cli A cli_state connected to the server.
1978 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1979 * @param argc Standard main() style argc
1980 * @param argv Standard main() style argv. Initial components are already
1983 * @return Normal NTSTATUS return.
1986 NTSTATUS
rpc_printer_migrate_printers_internals(struct net_context
*c
,
1987 const DOM_SID
*domain_sid
,
1988 const char *domain_name
,
1989 struct cli_state
*cli
,
1990 struct rpc_pipe_client
*pipe_hnd
,
1991 TALLOC_CTX
*mem_ctx
,
1996 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1997 uint32 i
= 0, num_printers
;
1999 PRINTER_INFO_CTR ctr_src
, ctr_dst
, ctr_enum
;
2000 struct cli_state
*cli_dst
= NULL
;
2001 POLICY_HND hnd_dst
, hnd_src
;
2002 char *printername
, *sharename
;
2003 bool got_hnd_src
= false;
2004 bool got_hnd_dst
= false;
2005 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
2007 DEBUG(3,("copying printers\n"));
2009 /* connect destination PI_SPOOLSS */
2010 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
, PI_SPOOLSS
);
2011 if (!NT_STATUS_IS_OK(nt_status
))
2015 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &ctr_enum
)) {
2016 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2020 if (!num_printers
) {
2021 printf ("no printers found on server.\n");
2022 nt_status
= NT_STATUS_OK
;
2026 /* do something for all printers */
2027 for (i
= 0; i
< num_printers
; i
++) {
2028 /* do some initialization */
2029 rpcstr_pull_talloc(mem_ctx
,
2031 ctr_enum
.printers_2
[i
].printername
.buffer
,
2034 rpcstr_pull_talloc(mem_ctx
,
2036 ctr_enum
.printers_2
[i
].sharename
.buffer
,
2039 if (!printername
|| !sharename
) {
2040 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2043 /* we can reset NT_STATUS here because we do not
2044 get any real NT_STATUS-codes anymore from now on */
2045 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2047 d_printf("migrating printer queue for: [%s] / [%s]\n",
2048 printername
, sharename
);
2050 /* open dst printer handle */
2051 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
2052 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd_dst
)) {
2054 DEBUG(1,("could not open printer: %s\n", sharename
));
2059 /* check for existing dst printer */
2060 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, level
, &ctr_dst
)) {
2061 printf ("could not get printer, creating printer.\n");
2063 DEBUG(1,("printer already exists: %s\n", sharename
));
2064 /* close printer handle here - dst only, not got src yet. */
2066 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
2067 got_hnd_dst
= false;
2072 /* now get again src printer ctr via getprinter,
2073 we first need a handle for that */
2075 /* open src printer handle */
2076 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
2077 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
2082 /* getprinter on the src server */
2083 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd_src
, level
, &ctr_src
))
2086 /* copy each src printer to a dst printer 1:1,
2087 maybe some values have to be changed though */
2088 d_printf("creating printer: %s\n", printername
);
2089 result
= rpccli_spoolss_addprinterex (pipe_hnd_dst
, mem_ctx
, level
, &ctr_src
);
2091 if (W_ERROR_IS_OK(result
))
2092 d_printf ("printer [%s] successfully added.\n", printername
);
2093 else if (W_ERROR_V(result
) == W_ERROR_V(WERR_PRINTER_ALREADY_EXISTS
))
2094 d_fprintf (stderr
, "printer [%s] already exists.\n", printername
);
2096 d_fprintf (stderr
, "could not create printer [%s]\n", printername
);
2100 /* close printer handles here */
2102 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
2103 got_hnd_src
= false;
2107 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
2108 got_hnd_dst
= false;
2112 nt_status
= NT_STATUS_OK
;
2116 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
2119 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
2122 cli_shutdown(cli_dst
);
2128 * Migrate Printer-Settings from a src server to the dst server
2129 * (for this to work, printers and drivers already have to be migrated earlier)
2131 * All parameters are provided by the run_rpc_command function, except for
2132 * argc, argv which are passed through.
2134 * @param c A net_context structure
2135 * @param domain_sid The domain sid aquired from the remote server
2136 * @param cli A cli_state connected to the server.
2137 * @param mem_ctx Talloc context, destoyed on compleation of the function.
2138 * @param argc Standard main() style argc
2139 * @param argv Standard main() style argv. Initial components are already
2142 * @return Normal NTSTATUS return.
2145 NTSTATUS
rpc_printer_migrate_settings_internals(struct net_context
*c
,
2146 const DOM_SID
*domain_sid
,
2147 const char *domain_name
,
2148 struct cli_state
*cli
,
2149 struct rpc_pipe_client
*pipe_hnd
,
2150 TALLOC_CTX
*mem_ctx
,
2155 /* FIXME: Here the nightmare begins */
2158 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
2159 uint32 i
= 0, p
= 0, j
= 0;
2160 uint32 num_printers
, val_needed
, data_needed
;
2162 char *printername
, *sharename
;
2163 bool got_hnd_src
= false;
2164 bool got_hnd_dst
= false;
2165 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
2166 POLICY_HND hnd_src
, hnd_dst
;
2167 PRINTER_INFO_CTR ctr_enum
, ctr_dst
, ctr_dst_publish
;
2168 REGVAL_CTR
*reg_ctr
;
2169 struct cli_state
*cli_dst
= NULL
;
2170 char *devicename
= NULL
, *unc_name
= NULL
, *url
= NULL
;
2171 const char *longname
;
2173 uint16
*keylist
= NULL
, *curkey
;
2175 ZERO_STRUCT(ctr_enum
);
2177 DEBUG(3,("copying printer settings\n"));
2179 /* connect destination PI_SPOOLSS */
2180 nt_status
= connect_dst_pipe(c
, &cli_dst
, &pipe_hnd_dst
, PI_SPOOLSS
);
2181 if (!NT_STATUS_IS_OK(nt_status
))
2184 /* enum src printers */
2185 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &ctr_enum
)) {
2186 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2190 if (!num_printers
) {
2191 printf ("no printers found on server.\n");
2192 nt_status
= NT_STATUS_OK
;
2197 /* needed for dns-strings in regkeys */
2198 longname
= get_mydnsfullname();
2200 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2204 /* do something for all printers */
2205 for (i
= 0; i
< num_printers
; i
++) {
2206 /* do some initialization */
2207 rpcstr_pull_talloc(mem_ctx
,
2209 ctr_enum
.printers_2
[i
].printername
.buffer
,
2212 rpcstr_pull_talloc(mem_ctx
,
2214 ctr_enum
.printers_2
[i
].sharename
.buffer
,
2217 if (!printername
|| !sharename
) {
2218 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2221 /* we can reset NT_STATUS here because we do not
2222 get any real NT_STATUS-codes anymore from now on */
2223 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2225 d_printf("migrating printer settings for: [%s] / [%s]\n",
2226 printername
, sharename
);
2229 /* open src printer handle */
2230 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
2231 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
2237 /* open dst printer handle */
2238 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
2239 PRINTER_ALL_ACCESS
, cli_dst
->user_name
, &hnd_dst
))
2245 /* check for existing dst printer */
2246 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
,
2251 /* STEP 1: COPY DEVICE-MODE and other
2252 PRINTER_INFO_2-attributes
2255 ctr_dst
.printers_2
= &ctr_enum
.printers_2
[i
];
2257 /* why is the port always disconnected when the printer
2258 is correctly installed (incl. driver ???) */
2259 init_unistr( &ctr_dst
.printers_2
->portname
, SAMBA_PRINTER_PORT_NAME
);
2261 /* check if printer is published */
2262 if (ctr_enum
.printers_2
[i
].attributes
& PRINTER_ATTRIBUTE_PUBLISHED
) {
2264 /* check for existing dst printer */
2265 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 7, &ctr_dst_publish
))
2268 ctr_dst_publish
.printers_7
->action
= SPOOL_DS_PUBLISH
;
2270 /* ignore false from setprinter due to WERR_IO_PENDING */
2271 net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 7, &ctr_dst_publish
);
2273 DEBUG(3,("republished printer\n"));
2276 if (ctr_enum
.printers_2
[i
].devmode
!= NULL
) {
2278 /* copy devmode (info level 2) */
2279 ctr_dst
.printers_2
->devmode
= (DEVICEMODE
*)
2280 TALLOC_MEMDUP(mem_ctx
,
2281 ctr_enum
.printers_2
[i
].devmode
,
2282 sizeof(DEVICEMODE
));
2284 /* do not copy security descriptor (we have another
2285 * command for that) */
2286 ctr_dst
.printers_2
->secdesc
= NULL
;
2289 if (asprintf(&devicename
, "\\\\%s\\%s", longname
,
2291 nt_status
= NT_STATUS_NO_MEMORY
;
2295 init_unistr(&ctr_dst
.printers_2
->devmode
->devicename
,
2298 if (!net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
,
2302 DEBUGADD(1,("\tSetPrinter of DEVICEMODE succeeded\n"));
2305 /* STEP 2: COPY REGISTRY VALUES */
2307 /* please keep in mind that samba parse_spools gives horribly
2308 crippled results when used to rpccli_spoolss_enumprinterdataex
2309 a win2k3-server. (Bugzilla #1851)
2310 FIXME: IIRC I've seen it too on a win2k-server
2313 /* enumerate data on src handle */
2314 result
= rpccli_spoolss_enumprinterdata(pipe_hnd
, mem_ctx
, &hnd_src
, p
, 0, 0,
2315 &val_needed
, &data_needed
, NULL
);
2317 /* loop for all printerdata of "PrinterDriverData" */
2318 while (W_ERROR_IS_OK(result
)) {
2320 REGISTRY_VALUE value
;
2322 result
= rpccli_spoolss_enumprinterdata(
2323 pipe_hnd
, mem_ctx
, &hnd_src
, p
++, val_needed
,
2324 data_needed
, 0, 0, &value
);
2326 /* loop for all reg_keys */
2327 if (W_ERROR_IS_OK(result
)) {
2331 display_reg_value(SPOOL_PRINTERDATA_KEY
, value
);
2334 if (!net_spoolss_setprinterdata(pipe_hnd_dst
, mem_ctx
,
2338 DEBUGADD(1,("\tSetPrinterData of [%s] succeeded\n",
2343 /* STEP 3: COPY SUBKEY VALUES */
2345 /* here we need to enum all printer_keys and then work
2346 on the result with enum_printer_key_ex. nt4 does not
2347 respond to enumprinterkey, win2k does, so continue
2348 in case of an error */
2350 if (!net_spoolss_enumprinterkey(pipe_hnd
, mem_ctx
, &hnd_src
, "", &keylist
)) {
2351 printf("got no key-data\n");
2356 /* work on a list of printer keys
2357 each key has to be enumerated to get all required
2358 information. information is then set via setprinterdataex-calls */
2360 if (keylist
== NULL
)
2364 while (*curkey
!= 0) {
2366 rpcstr_pull_talloc(mem_ctx
,
2372 return NT_STATUS_NO_MEMORY
;
2375 curkey
+= strlen(subkey
) + 1;
2377 if ( !(reg_ctr
= TALLOC_ZERO_P( mem_ctx
, REGVAL_CTR
)) )
2378 return NT_STATUS_NO_MEMORY
;
2380 /* enumerate all src subkeys */
2381 if (!net_spoolss_enumprinterdataex(pipe_hnd
, mem_ctx
, 0,
2386 for (j
=0; j
< reg_ctr
->num_values
; 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(reg_ctr
->values
[j
]->valuename
, SPOOL_REG_PORTNAME
) ||
2395 strequal(reg_ctr
->values
[j
]->valuename
, SPOOL_REG_UNCNAME
) ||
2396 strequal(reg_ctr
->values
[j
]->valuename
, SPOOL_REG_URL
) ||
2397 strequal(reg_ctr
->values
[j
]->valuename
, SPOOL_REG_SHORTSERVERNAME
) ||
2398 strequal(reg_ctr
->values
[j
]->valuename
, SPOOL_REG_SERVERNAME
)) {
2400 if (strequal(reg_ctr
->values
[j
]->valuename
, 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(reg_ctr
->values
[j
]->valuename
, 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(reg_ctr
->values
[j
]->valuename
, 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(reg_ctr
->values
[j
]->valuename
, SPOOL_REG_SERVERNAME
)) {
2434 init_unistr2(&data
, longname
, UNI_STR_TERMINATE
);
2435 fstrcpy(value
.valuename
, SPOOL_REG_SERVERNAME
);
2438 if (strequal(reg_ctr
->values
[j
]->valuename
, 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
*)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
,
2463 display_reg_value(subkey
, *(reg_ctr
->values
[j
]));
2465 /* here we have to set all subkeys on the dst server */
2466 if (!net_spoolss_setprinterdataex(pipe_hnd_dst
, mem_ctx
, &hnd_dst
,
2467 subkey
, reg_ctr
->values
[j
]))
2472 DEBUGADD(1,("\tSetPrinterDataEx of key [%s\\%s] succeeded\n",
2473 subkey
, reg_ctr
->values
[j
]->valuename
));
2477 TALLOC_FREE( reg_ctr
);
2482 /* close printer handles here */
2484 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
2485 got_hnd_src
= false;
2489 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
2490 got_hnd_dst
= false;
2495 nt_status
= NT_STATUS_OK
;
2498 SAFE_FREE(devicename
);
2500 SAFE_FREE(unc_name
);
2503 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
2506 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
2509 cli_shutdown(cli_dst
);