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 mem_ctx A talloc-context
165 * @param cli_share_src A connected cli_state
166 * @param cli_share_dst A connected cli_state
167 * @param src_file The source file-name
168 * @param dst_file The destination file-name
169 * @param copy_acls Whether to copy acls
170 * @param copy_attrs Whether to copy DOS attributes
171 * @param copy_timestamps Whether to preserve timestamps
172 * @param is_file Whether this file is a file or a dir
174 * @return Normal NTSTATUS return.
177 NTSTATUS
net_copy_fileattr(TALLOC_CTX
*mem_ctx
,
178 struct cli_state
*cli_share_src
,
179 struct cli_state
*cli_share_dst
,
180 const char *src_name
, const char *dst_name
,
181 bool copy_acls
, bool copy_attrs
,
182 bool copy_timestamps
, bool is_file
)
184 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
189 time_t f_atime
, f_ctime
, f_mtime
;
192 if (!copy_timestamps
&& !copy_acls
&& !copy_attrs
)
195 /* open file/dir on the originating server */
197 DEBUGADD(3,("opening %s %s on originating server\n",
198 is_file
?"file":"dir", src_name
));
200 fnum_src
= cli_nt_create(cli_share_src
, src_name
, READ_CONTROL_ACCESS
);
201 if (fnum_src
== -1) {
202 DEBUGADD(0,("cannot open %s %s on originating server %s\n",
203 is_file
?"file":"dir", src_name
, cli_errstr(cli_share_src
)));
204 nt_status
= cli_nt_error(cli_share_src
);
211 /* get the security descriptor */
212 sd
= cli_query_secdesc(cli_share_src
, fnum_src
, mem_ctx
);
214 DEBUG(0,("failed to get security descriptor: %s\n",
215 cli_errstr(cli_share_src
)));
216 nt_status
= cli_nt_error(cli_share_src
);
220 if (opt_verbose
&& DEBUGLEVEL
>= 3)
221 display_sec_desc(sd
);
225 if (copy_attrs
|| copy_timestamps
) {
227 /* get file attributes */
228 if (!cli_getattrE(cli_share_src
, fnum_src
, &attr
, NULL
,
229 &f_ctime
, &f_atime
, &f_mtime
)) {
230 DEBUG(0,("failed to get file-attrs: %s\n",
231 cli_errstr(cli_share_src
)));
232 nt_status
= cli_nt_error(cli_share_src
);
238 /* open the file/dir on the destination server */
240 fnum_dst
= cli_nt_create(cli_share_dst
, dst_name
, WRITE_DAC_ACCESS
| WRITE_OWNER_ACCESS
);
241 if (fnum_dst
== -1) {
242 DEBUG(0,("failed to open %s on the destination server: %s: %s\n",
243 is_file
?"file":"dir", dst_name
, cli_errstr(cli_share_dst
)));
244 nt_status
= cli_nt_error(cli_share_dst
);
248 if (copy_timestamps
) {
251 if (!cli_setattrE(cli_share_dst
, fnum_dst
, f_ctime
, f_atime
, f_mtime
)) {
252 DEBUG(0,("failed to set file-attrs (timestamps): %s\n",
253 cli_errstr(cli_share_dst
)));
254 nt_status
= cli_nt_error(cli_share_dst
);
262 if (!cli_set_secdesc(cli_share_dst
, fnum_dst
, sd
)) {
263 DEBUG(0,("could not set secdesc on %s: %s\n",
264 dst_name
, cli_errstr(cli_share_dst
)));
265 nt_status
= cli_nt_error(cli_share_dst
);
273 if (!cli_setatr(cli_share_dst
, dst_name
, attr
, 0)) {
274 DEBUG(0,("failed to set file-attrs: %s\n",
275 cli_errstr(cli_share_dst
)));
276 nt_status
= cli_nt_error(cli_share_dst
);
284 if (!cli_close(cli_share_src
, fnum_src
)) {
285 d_fprintf(stderr
, "could not close %s on originating server: %s\n",
286 is_file
?"file":"dir", cli_errstr(cli_share_src
));
287 nt_status
= cli_nt_error(cli_share_src
);
291 if (!cli_close(cli_share_dst
, fnum_dst
)) {
292 d_fprintf(stderr
, "could not close %s on destination server: %s\n",
293 is_file
?"file":"dir", cli_errstr(cli_share_dst
));
294 nt_status
= cli_nt_error(cli_share_dst
);
299 nt_status
= NT_STATUS_OK
;
305 cli_close(cli_share_src
, fnum_src
);
308 cli_close(cli_share_dst
, fnum_dst
);
314 * Copy a file or directory from a connected share to another connected share
316 * @param mem_ctx A talloc-context
317 * @param cli_share_src A connected cli_state
318 * @param cli_share_dst A connected cli_state
319 * @param src_file The source file-name
320 * @param dst_file The destination file-name
321 * @param copy_acls Whether to copy acls
322 * @param copy_attrs Whether to copy DOS attributes
323 * @param copy_timestamps Whether to preserve timestamps
324 * @param is_file Whether this file is a file or a dir
326 * @return Normal NTSTATUS return.
329 NTSTATUS
net_copy_file(TALLOC_CTX
*mem_ctx
,
330 struct cli_state
*cli_share_src
,
331 struct cli_state
*cli_share_dst
,
332 const char *src_name
, const char *dst_name
,
333 bool copy_acls
, bool copy_attrs
,
334 bool copy_timestamps
, bool is_file
)
336 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
339 static int io_bufsize
= 64512;
340 int read_size
= io_bufsize
;
345 if (!src_name
|| !dst_name
)
348 if (cli_share_src
== NULL
|| cli_share_dst
== NULL
)
352 /* open on the originating server */
353 DEBUGADD(3,("opening %s %s on originating server\n",
354 is_file
? "file":"dir", src_name
));
356 fnum_src
= cli_open(cli_share_src
, src_name
, O_RDONLY
, DENY_NONE
);
358 fnum_src
= cli_nt_create(cli_share_src
, src_name
, READ_CONTROL_ACCESS
);
360 if (fnum_src
== -1) {
361 DEBUGADD(0,("cannot open %s %s on originating server %s\n",
362 is_file
? "file":"dir",
363 src_name
, cli_errstr(cli_share_src
)));
364 nt_status
= cli_nt_error(cli_share_src
);
371 /* open file on the destination server */
372 DEBUGADD(3,("opening file %s on destination server\n", dst_name
));
373 fnum_dst
= cli_open(cli_share_dst
, dst_name
,
374 O_RDWR
|O_CREAT
|O_TRUNC
, DENY_NONE
);
376 if (fnum_dst
== -1) {
377 DEBUGADD(1,("cannot create file %s on destination server: %s\n",
378 dst_name
, cli_errstr(cli_share_dst
)));
379 nt_status
= cli_nt_error(cli_share_dst
);
383 /* allocate memory */
384 if (!(data
= (char *)SMB_MALLOC(read_size
))) {
385 d_fprintf(stderr
, "malloc fail for size %d\n", read_size
);
386 nt_status
= NT_STATUS_NO_MEMORY
;
395 d_printf("copying [\\\\%s\\%s%s] => [\\\\%s\\%s%s] "
396 "%s ACLs and %s DOS Attributes %s\n",
397 cli_share_src
->desthost
, cli_share_src
->share
, src_name
,
398 cli_share_dst
->desthost
, cli_share_dst
->share
, dst_name
,
399 copy_acls
? "with" : "without",
400 copy_attrs
? "with" : "without",
401 copy_timestamps
? "(preserving timestamps)" : "" );
409 n
= cli_read(cli_share_src
, fnum_src
, data
, nread
,
415 ret
= cli_write(cli_share_dst
, fnum_dst
, 0, data
,
419 d_fprintf(stderr
, "Error writing file: %s\n",
420 cli_errstr(cli_share_dst
));
421 nt_status
= cli_nt_error(cli_share_dst
);
429 if (!is_file
&& !cli_chkpath(cli_share_dst
, dst_name
)) {
432 DEBUGADD(3,("creating dir %s on the destination server\n",
435 if (!cli_mkdir(cli_share_dst
, dst_name
)) {
436 DEBUG(0,("cannot create directory %s: %s\n",
437 dst_name
, cli_errstr(cli_share_dst
)));
438 nt_status
= NT_STATUS_NO_SUCH_FILE
;
441 if (!cli_chkpath(cli_share_dst
, dst_name
)) {
442 d_fprintf(stderr
, "cannot check for directory %s: %s\n",
443 dst_name
, cli_errstr(cli_share_dst
));
450 if (!cli_close(cli_share_src
, fnum_src
)) {
451 d_fprintf(stderr
, "could not close file on originating server: %s\n",
452 cli_errstr(cli_share_src
));
453 nt_status
= cli_nt_error(cli_share_src
);
457 if (is_file
&& !cli_close(cli_share_dst
, fnum_dst
)) {
458 d_fprintf(stderr
, "could not close file on destination server: %s\n",
459 cli_errstr(cli_share_dst
));
460 nt_status
= cli_nt_error(cli_share_dst
);
464 /* possibly we have to copy some file-attributes / acls / sd */
465 nt_status
= net_copy_fileattr(mem_ctx
, cli_share_src
, cli_share_dst
,
466 src_name
, dst_name
, copy_acls
,
467 copy_attrs
, copy_timestamps
, is_file
);
468 if (!NT_STATUS_IS_OK(nt_status
))
472 nt_status
= NT_STATUS_OK
;
478 cli_close(cli_share_src
, fnum_src
);
481 cli_close(cli_share_dst
, fnum_dst
);
489 * Copy a driverfile from on connected share to another connected share
490 * This silently assumes that a driver-file is picked up from
492 * \\src_server\print$\{arch}\{version}\file
496 * \\dst_server\print$\{arch}\file
498 * to be added via setdriver-calls later.
499 * @param mem_ctx A talloc-context
500 * @param cli_share_src A cli_state connected to source print$-share
501 * @param cli_share_dst A cli_state connected to destination print$-share
502 * @param file The file-name to be copied
503 * @param short_archi The name of the driver-architecture (short form)
505 * @return Normal NTSTATUS return.
508 static NTSTATUS
net_copy_driverfile(TALLOC_CTX
*mem_ctx
,
509 struct cli_state
*cli_share_src
,
510 struct cli_state
*cli_share_dst
,
511 char *file
, const char *short_archi
) {
513 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
521 /* scroll through the file until we have the part
522 beyond archi_table.short_archi */
524 while (next_token_talloc(mem_ctx
, &p
, &tok
, "\\")) {
525 if (strequal(tok
, short_archi
)) {
526 next_token_talloc(mem_ctx
, &p
, &version
, "\\");
527 next_token_talloc(mem_ctx
, &p
, &filename
, "\\");
531 /* build source file name */
532 if (asprintf(&src_name
, "\\%s\\%s\\%s", short_archi
, version
, filename
) < 0 )
533 return NT_STATUS_NO_MEMORY
;
536 /* create destination file name */
537 if (asprintf(&dst_name
, "\\%s\\%s", short_archi
, filename
) < 0 )
538 return NT_STATUS_NO_MEMORY
;
541 /* finally copy the file */
542 nt_status
= net_copy_file(mem_ctx
, cli_share_src
, cli_share_dst
,
543 src_name
, dst_name
, False
, False
, False
, True
);
544 if (!NT_STATUS_IS_OK(nt_status
))
547 nt_status
= NT_STATUS_OK
;
557 * Check for existing Architecture directory on a given server
559 * @param cli_share A cli_state connected to a print$-share
560 * @param short_archi The Architecture for the print-driver
562 * @return Normal NTSTATUS return.
565 static NTSTATUS
check_arch_dir(struct cli_state
*cli_share
, const char *short_archi
)
568 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
571 if (asprintf(&dir
, "\\%s", short_archi
) < 0) {
572 return NT_STATUS_NO_MEMORY
;
575 DEBUG(10,("creating print-driver dir for architecture: %s\n",
578 if (!cli_mkdir(cli_share
, dir
)) {
579 DEBUG(1,("cannot create directory %s: %s\n",
580 dir
, cli_errstr(cli_share
)));
581 nt_status
= NT_STATUS_NO_SUCH_FILE
;
584 if (!cli_chkpath(cli_share
, dir
)) {
585 d_fprintf(stderr
, "cannot check %s: %s\n",
586 dir
, cli_errstr(cli_share
));
590 nt_status
= NT_STATUS_OK
;
598 * Copy a print-driver (level 3) from one connected print$-share to another
599 * connected print$-share
601 * @param mem_ctx A talloc-context
602 * @param cli_share_src A cli_state connected to a print$-share
603 * @param cli_share_dst A cli_state connected to a print$-share
604 * @param short_archi The Architecture for the print-driver
605 * @param i1 The DRIVER_INFO_3-struct
607 * @return Normal NTSTATUS return.
610 static NTSTATUS
copy_print_driver_3(TALLOC_CTX
*mem_ctx
,
611 struct cli_state
*cli_share_src
,
612 struct cli_state
*cli_share_dst
,
613 const char *short_archi
, DRIVER_INFO_3
*i1
)
615 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
620 fstring driverpath
= "";
621 fstring datafile
= "";
622 fstring configfile
= "";
623 fstring helpfile
= "";
624 fstring dependentfiles
= "";
629 rpcstr_pull(name
, i1
->name
.buffer
, sizeof(name
), -1, STR_TERMINATE
);
630 rpcstr_pull(driverpath
, i1
->driverpath
.buffer
, sizeof(driverpath
), -1, STR_TERMINATE
);
631 rpcstr_pull(datafile
, i1
->datafile
.buffer
, sizeof(datafile
), -1, STR_TERMINATE
);
632 rpcstr_pull(configfile
, i1
->configfile
.buffer
, sizeof(configfile
), -1, STR_TERMINATE
);
633 rpcstr_pull(helpfile
, i1
->helpfile
.buffer
, sizeof(helpfile
), -1, STR_TERMINATE
);
637 d_printf("copying driver: [%s], for architecture: [%s], version: [%d]\n",
638 name
, short_archi
, i1
->version
);
640 nt_status
= net_copy_driverfile(mem_ctx
, cli_share_src
, cli_share_dst
,
641 driverpath
, short_archi
);
642 if (!NT_STATUS_IS_OK(nt_status
))
645 nt_status
= net_copy_driverfile(mem_ctx
, cli_share_src
, cli_share_dst
,
646 datafile
, short_archi
);
647 if (!NT_STATUS_IS_OK(nt_status
))
650 nt_status
= net_copy_driverfile(mem_ctx
, cli_share_src
, cli_share_dst
,
651 configfile
, short_archi
);
652 if (!NT_STATUS_IS_OK(nt_status
))
655 nt_status
= net_copy_driverfile(mem_ctx
, cli_share_src
, cli_share_dst
,
656 helpfile
, short_archi
);
657 if (!NT_STATUS_IS_OK(nt_status
))
662 rpcstr_pull(dependentfiles
, i1
->dependentfiles
+length
, sizeof(dependentfiles
), -1, STR_TERMINATE
);
663 length
+= strlen(dependentfiles
)+1;
665 if (strlen(dependentfiles
) > 0) {
667 nt_status
= net_copy_driverfile(mem_ctx
,
668 cli_share_src
, cli_share_dst
,
669 dependentfiles
, short_archi
);
670 if (!NT_STATUS_IS_OK(nt_status
))
681 * net_spoolss-functions
682 * =====================
684 * the net_spoolss-functions aim to simplify spoolss-client-functions
685 * required during the migration-process wrt buffer-sizes, returned
688 * this greatly reduces the complexitiy of the migrate-functions.
692 static bool net_spoolss_enum_printers(struct rpc_pipe_client
*pipe_hnd
,
697 uint32
*num_printers
,
698 PRINTER_INFO_CTR
*ctr
)
703 result
= rpccli_spoolss_enum_printers(pipe_hnd
, mem_ctx
, name
, flags
,
704 level
, num_printers
, ctr
);
706 if (!W_ERROR_IS_OK(result
)) {
707 printf("cannot enum printers: %s\n", dos_errstr(result
));
714 static bool net_spoolss_open_printer_ex(struct rpc_pipe_client
*pipe_hnd
,
716 const char *printername
,
717 uint32 access_required
,
718 const char *username
,
722 fstring servername
, printername2
;
724 slprintf(servername
, sizeof(servername
)-1, "\\\\%s", pipe_hnd
->cli
->desthost
);
726 fstrcpy(printername2
, servername
);
727 fstrcat(printername2
, "\\");
728 fstrcat(printername2
, printername
);
730 DEBUG(10,("connecting to: %s as %s for %s and access: %x\n",
731 servername
, username
, printername2
, access_required
));
734 result
= rpccli_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, printername2
,
736 servername
, username
, hnd
);
738 /* be more verbose */
739 if (W_ERROR_V(result
) == W_ERROR_V(WERR_ACCESS_DENIED
)) {
740 d_fprintf(stderr
, "no access to printer [%s] on [%s] for user [%s] granted\n",
741 printername2
, servername
, username
);
745 if (!W_ERROR_IS_OK(result
)) {
746 d_fprintf(stderr
, "cannot open printer %s on server %s: %s\n",
747 printername2
, servername
, dos_errstr(result
));
751 DEBUG(2,("got printer handle for printer: %s, server: %s\n",
752 printername2
, servername
));
757 static bool net_spoolss_getprinter(struct rpc_pipe_client
*pipe_hnd
,
761 PRINTER_INFO_CTR
*ctr
)
765 /* getprinter call */
766 result
= rpccli_spoolss_getprinter(pipe_hnd
, mem_ctx
, hnd
, level
, ctr
);
768 if (!W_ERROR_IS_OK(result
)) {
769 printf("cannot get printer-info: %s\n", dos_errstr(result
));
776 static bool net_spoolss_setprinter(struct rpc_pipe_client
*pipe_hnd
,
780 PRINTER_INFO_CTR
*ctr
)
784 /* setprinter call */
785 result
= rpccli_spoolss_setprinter(pipe_hnd
, mem_ctx
, hnd
, level
, ctr
, 0);
787 if (!W_ERROR_IS_OK(result
)) {
788 printf("cannot set printer-info: %s\n", dos_errstr(result
));
796 static bool net_spoolss_setprinterdata(struct rpc_pipe_client
*pipe_hnd
,
799 REGISTRY_VALUE
*value
)
803 /* setprinterdata call */
804 result
= rpccli_spoolss_setprinterdata(pipe_hnd
, mem_ctx
, hnd
, value
);
806 if (!W_ERROR_IS_OK(result
)) {
807 printf ("unable to set printerdata: %s\n", dos_errstr(result
));
815 static bool net_spoolss_enumprinterkey(struct rpc_pipe_client
*pipe_hnd
,
823 /* enumprinterkey call */
824 result
= rpccli_spoolss_enumprinterkey(pipe_hnd
, mem_ctx
, hnd
, keyname
, keylist
, NULL
);
826 if (!W_ERROR_IS_OK(result
)) {
827 printf("enumprinterkey failed: %s\n", dos_errstr(result
));
834 static bool net_spoolss_enumprinterdataex(struct rpc_pipe_client
*pipe_hnd
,
843 /* enumprinterdataex call */
844 result
= rpccli_spoolss_enumprinterdataex(pipe_hnd
, mem_ctx
, hnd
, keyname
, ctr
);
846 if (!W_ERROR_IS_OK(result
)) {
847 printf("enumprinterdataex failed: %s\n", dos_errstr(result
));
855 static bool net_spoolss_setprinterdataex(struct rpc_pipe_client
*pipe_hnd
,
859 REGISTRY_VALUE
*value
)
863 /* setprinterdataex call */
864 result
= rpccli_spoolss_setprinterdataex(pipe_hnd
, mem_ctx
, hnd
,
867 if (!W_ERROR_IS_OK(result
)) {
868 printf("could not set printerdataex: %s\n", dos_errstr(result
));
875 static bool net_spoolss_enumforms(struct rpc_pipe_client
*pipe_hnd
,
886 result
= rpccli_spoolss_enumforms(pipe_hnd
, mem_ctx
, hnd
, level
, num_forms
, forms
);
888 if (!W_ERROR_IS_OK(result
)) {
889 printf("could not enum forms: %s\n", dos_errstr(result
));
896 static bool net_spoolss_enumprinterdrivers (struct rpc_pipe_client
*pipe_hnd
,
898 uint32 level
, const char *env
,
900 PRINTER_DRIVER_CTR
*ctr
)
904 /* enumprinterdrivers call */
905 result
= rpccli_spoolss_enumprinterdrivers(
906 pipe_hnd
, mem_ctx
, level
,
907 env
, num_drivers
, ctr
);
909 if (!W_ERROR_IS_OK(result
)) {
910 printf("cannot enum drivers: %s\n", dos_errstr(result
));
917 static bool net_spoolss_getprinterdriver(struct rpc_pipe_client
*pipe_hnd
,
919 POLICY_HND
*hnd
, uint32 level
,
920 const char *env
, int version
,
921 PRINTER_DRIVER_CTR
*ctr
)
925 /* getprinterdriver call */
926 result
= rpccli_spoolss_getprinterdriver(
927 pipe_hnd
, mem_ctx
, hnd
, level
,
930 if (!W_ERROR_IS_OK(result
)) {
931 DEBUG(1,("cannot get driver (for architecture: %s): %s\n",
932 env
, dos_errstr(result
)));
933 if (W_ERROR_V(result
) != W_ERROR_V(WERR_UNKNOWN_PRINTER_DRIVER
) &&
934 W_ERROR_V(result
) != W_ERROR_V(WERR_INVALID_ENVIRONMENT
)) {
935 printf("cannot get driver: %s\n", dos_errstr(result
));
944 static bool net_spoolss_addprinterdriver(struct rpc_pipe_client
*pipe_hnd
,
945 TALLOC_CTX
*mem_ctx
, uint32 level
,
946 PRINTER_DRIVER_CTR
*ctr
)
950 /* addprinterdriver call */
951 result
= rpccli_spoolss_addprinterdriver(pipe_hnd
, mem_ctx
, level
, ctr
);
953 /* be more verbose */
954 if (W_ERROR_V(result
) == W_ERROR_V(WERR_ACCESS_DENIED
)) {
955 printf("You are not allowed to add drivers\n");
958 if (!W_ERROR_IS_OK(result
)) {
959 printf("cannot add driver: %s\n", dos_errstr(result
));
967 * abstraction function to get uint32 num_printers and PRINTER_INFO_CTR ctr
968 * for a single printer or for all printers depending on argc/argv
971 static bool get_printer_info(struct rpc_pipe_client
*pipe_hnd
,
976 uint32
*num_printers
,
977 PRINTER_INFO_CTR
*ctr
)
982 /* no arguments given, enumerate all printers */
985 if (!net_spoolss_enum_printers(pipe_hnd
, mem_ctx
, NULL
,
986 PRINTER_ENUM_LOCAL
|PRINTER_ENUM_SHARED
,
987 level
, num_printers
, ctr
))
994 /* argument given, get a single printer by name */
995 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, argv
[0],
996 MAXIMUM_ALLOWED_ACCESS
, pipe_hnd
->cli
->user_name
, &hnd
))
999 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd
, level
, ctr
)) {
1000 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd
);
1004 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd
);
1009 DEBUG(3,("got %d printers\n", *num_printers
));
1016 * List print-queues (including local printers that are not shared)
1018 * All parameters are provided by the run_rpc_command function, except for
1019 * argc, argv which are passed through.
1021 * @param domain_sid The domain sid aquired from the remote server
1022 * @param cli A cli_state connected to the server.
1023 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1024 * @param argc Standard main() style argc
1025 * @param argv Standard main() style argv. Initial components are already
1028 * @return Normal NTSTATUS return.
1031 NTSTATUS
rpc_printer_list_internals(const DOM_SID
*domain_sid
,
1032 const char *domain_name
,
1033 struct cli_state
*cli
,
1034 struct rpc_pipe_client
*pipe_hnd
,
1035 TALLOC_CTX
*mem_ctx
,
1039 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1040 uint32 i
, num_printers
;
1042 char *printername
, *sharename
;
1043 PRINTER_INFO_CTR ctr
;
1045 printf("listing printers\n");
1047 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &ctr
))
1050 for (i
= 0; i
< num_printers
; i
++) {
1051 /* do some initialization */
1052 rpcstr_pull_talloc(mem_ctx
,
1054 ctr
.printers_2
[i
].printername
.buffer
,
1057 rpcstr_pull_talloc(mem_ctx
,
1059 ctr
.printers_2
[i
].sharename
.buffer
,
1063 if (printername
&& sharename
) {
1064 d_printf("printer %d: %s, shared as: %s\n",
1065 i
+1, printername
, sharename
);
1069 return NT_STATUS_OK
;
1073 * List printer-drivers from a server
1075 * All parameters are provided by the run_rpc_command function, except for
1076 * argc, argv which are passed through.
1078 * @param domain_sid The domain sid aquired from the remote server
1079 * @param cli A cli_state connected to the server.
1080 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1081 * @param argc Standard main() style argc
1082 * @param argv Standard main() style argv. Initial components are already
1085 * @return Normal NTSTATUS return.
1088 NTSTATUS
rpc_printer_driver_list_internals(const DOM_SID
*domain_sid
,
1089 const char *domain_name
,
1090 struct cli_state
*cli
,
1091 struct rpc_pipe_client
*pipe_hnd
,
1092 TALLOC_CTX
*mem_ctx
,
1096 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1099 PRINTER_DRIVER_CTR drv_ctr_enum
;
1102 ZERO_STRUCT(drv_ctr_enum
);
1104 printf("listing printer-drivers\n");
1106 for (i
=0; archi_table
[i
].long_archi
!=NULL
; i
++) {
1110 /* enum remote drivers */
1111 if (!net_spoolss_enumprinterdrivers(pipe_hnd
, mem_ctx
, level
,
1112 archi_table
[i
].long_archi
,
1113 &num_drivers
, &drv_ctr_enum
)) {
1115 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1119 if (num_drivers
== 0) {
1120 d_printf ("no drivers found on server for architecture: [%s].\n",
1121 archi_table
[i
].long_archi
);
1125 d_printf("got %d printer-drivers for architecture: [%s]\n",
1126 num_drivers
, archi_table
[i
].long_archi
);
1129 /* do something for all drivers for architecture */
1130 for (d
= 0; d
< num_drivers
; d
++) {
1131 display_print_driver_3(&(drv_ctr_enum
.info3
[d
]));
1135 nt_status
= NT_STATUS_OK
;
1143 * Publish print-queues with args-wrapper
1145 * @param cli A cli_state connected to the server.
1146 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1147 * @param argc Standard main() style argc
1148 * @param argv Standard main() style argv. Initial components are already
1152 * @return Normal NTSTATUS return.
1155 static NTSTATUS
rpc_printer_publish_internals_args(struct rpc_pipe_client
*pipe_hnd
,
1156 TALLOC_CTX
*mem_ctx
,
1161 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1162 uint32 i
, num_printers
;
1164 char *printername
, *sharename
;
1165 PRINTER_INFO_CTR ctr
, ctr_pub
;
1167 bool got_hnd
= False
;
1169 const char *action_str
;
1171 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &ctr
))
1174 for (i
= 0; i
< num_printers
; i
++) {
1175 /* do some initialization */
1176 rpcstr_pull_talloc(mem_ctx
,
1178 ctr
.printers_2
[i
].printername
.buffer
,
1181 rpcstr_pull_talloc(mem_ctx
,
1183 ctr
.printers_2
[i
].sharename
.buffer
,
1186 if (!printername
|| !sharename
) {
1190 /* open printer handle */
1191 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1192 PRINTER_ALL_ACCESS
, pipe_hnd
->cli
->user_name
, &hnd
))
1197 /* check for existing dst printer */
1198 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd
, level
, &ctr_pub
))
1201 /* check action and set string */
1203 case SPOOL_DS_PUBLISH
:
1204 action_str
= "published";
1206 case SPOOL_DS_UPDATE
:
1207 action_str
= "updated";
1209 case SPOOL_DS_UNPUBLISH
:
1210 action_str
= "unpublished";
1213 action_str
= "unknown action";
1214 printf("unkown action: %d\n", action
);
1218 ctr_pub
.printers_7
->action
= action
;
1220 result
= rpccli_spoolss_setprinter(pipe_hnd
, mem_ctx
, &hnd
, level
, &ctr_pub
, 0);
1221 if (!W_ERROR_IS_OK(result
) && (W_ERROR_V(result
) != W_ERROR_V(WERR_IO_PENDING
))) {
1222 printf("cannot set printer-info: %s\n", dos_errstr(result
));
1226 printf("successfully %s printer %s in Active Directory\n", action_str
, sharename
);
1229 nt_status
= NT_STATUS_OK
;
1233 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd
);
1238 NTSTATUS
rpc_printer_publish_publish_internals(const DOM_SID
*domain_sid
,
1239 const char *domain_name
,
1240 struct cli_state
*cli
,
1241 struct rpc_pipe_client
*pipe_hnd
,
1242 TALLOC_CTX
*mem_ctx
,
1246 return rpc_printer_publish_internals_args(pipe_hnd
, mem_ctx
, argc
, argv
, SPOOL_DS_PUBLISH
);
1249 NTSTATUS
rpc_printer_publish_unpublish_internals(const DOM_SID
*domain_sid
,
1250 const char *domain_name
,
1251 struct cli_state
*cli
,
1252 struct rpc_pipe_client
*pipe_hnd
,
1253 TALLOC_CTX
*mem_ctx
,
1257 return rpc_printer_publish_internals_args(pipe_hnd
, mem_ctx
, argc
, argv
, SPOOL_DS_UNPUBLISH
);
1260 NTSTATUS
rpc_printer_publish_update_internals(const DOM_SID
*domain_sid
,
1261 const char *domain_name
,
1262 struct cli_state
*cli
,
1263 struct rpc_pipe_client
*pipe_hnd
,
1264 TALLOC_CTX
*mem_ctx
,
1268 return rpc_printer_publish_internals_args(pipe_hnd
, mem_ctx
, argc
, argv
, SPOOL_DS_UPDATE
);
1272 * List print-queues w.r.t. their publishing state
1274 * All parameters are provided by the run_rpc_command function, except for
1275 * argc, argv which are passed through.
1277 * @param domain_sid The domain sid aquired from the remote server
1278 * @param cli A cli_state connected to the server.
1279 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1280 * @param argc Standard main() style argc
1281 * @param argv Standard main() style argv. Initial components are already
1284 * @return Normal NTSTATUS return.
1287 NTSTATUS
rpc_printer_publish_list_internals(const DOM_SID
*domain_sid
,
1288 const char *domain_name
,
1289 struct cli_state
*cli
,
1290 struct rpc_pipe_client
*pipe_hnd
,
1291 TALLOC_CTX
*mem_ctx
,
1295 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1296 uint32 i
, num_printers
;
1298 char *printername
, *sharename
;
1300 PRINTER_INFO_CTR ctr
, ctr_pub
;
1302 bool got_hnd
= False
;
1305 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &ctr
))
1308 for (i
= 0; i
< num_printers
; i
++) {
1309 ZERO_STRUCT(ctr_pub
);
1311 /* do some initialization */
1312 rpcstr_pull_talloc(mem_ctx
,
1314 ctr
.printers_2
[i
].printername
.buffer
,
1317 rpcstr_pull_talloc(mem_ctx
,
1319 ctr
.printers_2
[i
].sharename
.buffer
,
1322 if (!printername
|| !sharename
) {
1326 /* open printer handle */
1327 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1328 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd
))
1333 /* check for existing dst printer */
1334 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd
, level
, &ctr_pub
))
1337 rpcstr_pull_talloc(mem_ctx
,
1339 ctr_pub
.printers_7
->guid
.buffer
,
1345 state
= ctr_pub
.printers_7
->action
;
1347 case SPOOL_DS_PUBLISH
:
1348 printf("printer [%s] is published", sharename
);
1350 printf(", guid: %s", guid
);
1353 case SPOOL_DS_UNPUBLISH
:
1354 printf("printer [%s] is unpublished\n", sharename
);
1356 case SPOOL_DS_UPDATE
:
1357 printf("printer [%s] is currently updating\n", sharename
);
1360 printf("unkown state: %d\n", state
);
1365 nt_status
= NT_STATUS_OK
;
1369 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd
);
1375 * Migrate Printer-ACLs from a source server to the destination server
1377 * All parameters are provided by the run_rpc_command function, except for
1378 * argc, argv which are passed through.
1380 * @param domain_sid The domain sid aquired from the remote server
1381 * @param cli A cli_state connected to the server.
1382 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1383 * @param argc Standard main() style argc
1384 * @param argv Standard main() style argv. Initial components are already
1387 * @return Normal NTSTATUS return.
1390 NTSTATUS
rpc_printer_migrate_security_internals(const DOM_SID
*domain_sid
,
1391 const char *domain_name
,
1392 struct cli_state
*cli
,
1393 struct rpc_pipe_client
*pipe_hnd
,
1394 TALLOC_CTX
*mem_ctx
,
1398 /* TODO: what now, info2 or info3 ?
1399 convince jerry that we should add clientside setacls level 3 at least
1401 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1403 uint32 num_printers
;
1405 char *printername
, *sharename
;
1406 bool got_hnd_src
= False
;
1407 bool got_hnd_dst
= False
;
1408 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
1409 POLICY_HND hnd_src
, hnd_dst
;
1410 PRINTER_INFO_CTR ctr_src
, ctr_dst
, ctr_enum
;
1411 struct cli_state
*cli_dst
= NULL
;
1413 ZERO_STRUCT(ctr_src
);
1415 DEBUG(3,("copying printer ACLs\n"));
1417 /* connect destination PI_SPOOLSS */
1418 nt_status
= connect_dst_pipe(&cli_dst
, &pipe_hnd_dst
, PI_SPOOLSS
);
1419 if (!NT_STATUS_IS_OK(nt_status
))
1423 /* enum source printers */
1424 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &ctr_enum
)) {
1425 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1429 if (!num_printers
) {
1430 printf ("no printers found on server.\n");
1431 nt_status
= NT_STATUS_OK
;
1435 /* do something for all printers */
1436 for (i
= 0; i
< num_printers
; i
++) {
1437 /* do some initialization */
1438 rpcstr_pull_talloc(mem_ctx
,
1440 ctr_enum
.printers_2
[i
].printername
.buffer
,
1443 rpcstr_pull_talloc(mem_ctx
,
1445 ctr_enum
.printers_2
[i
].sharename
.buffer
,
1448 if (!printername
|| !sharename
) {
1449 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1453 /* we can reset NT_STATUS here because we do not
1454 get any real NT_STATUS-codes anymore from now on */
1455 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1457 d_printf("migrating printer ACLs for: [%s] / [%s]\n",
1458 printername
, sharename
);
1460 /* according to msdn you have specify these access-rights
1461 to see the security descriptor
1462 - READ_CONTROL (DACL)
1463 - ACCESS_SYSTEM_SECURITY (SACL)
1466 /* open src printer handle */
1467 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1468 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
1473 /* open dst printer handle */
1474 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
1475 PRINTER_ALL_ACCESS
, cli_dst
->user_name
, &hnd_dst
))
1480 /* check for existing dst printer */
1481 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, level
, &ctr_dst
))
1484 /* check for existing src printer */
1485 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd_src
, 3, &ctr_src
))
1488 /* Copy Security Descriptor */
1490 /* copy secdesc (info level 2) */
1491 ctr_dst
.printers_2
->devmode
= NULL
;
1492 ctr_dst
.printers_2
->secdesc
= dup_sec_desc(mem_ctx
, ctr_src
.printers_3
->secdesc
);
1495 display_sec_desc(ctr_dst
.printers_2
->secdesc
);
1497 if (!net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 2, &ctr_dst
))
1500 DEBUGADD(1,("\tSetPrinter of SECDESC succeeded\n"));
1503 /* close printer handles here */
1505 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
1506 got_hnd_src
= False
;
1510 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
1511 got_hnd_dst
= False
;
1516 nt_status
= NT_STATUS_OK
;
1521 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
1525 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
1529 cli_shutdown(cli_dst
);
1535 * Migrate printer-forms from a src server to the dst server
1537 * All parameters are provided by the run_rpc_command function, except for
1538 * argc, argv which are passed through.
1540 * @param domain_sid The domain sid aquired from the remote server
1541 * @param cli A cli_state connected to the server.
1542 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1543 * @param argc Standard main() style argc
1544 * @param argv Standard main() style argv. Initial components are already
1547 * @return Normal NTSTATUS return.
1550 NTSTATUS
rpc_printer_migrate_forms_internals(const DOM_SID
*domain_sid
,
1551 const char *domain_name
,
1552 struct cli_state
*cli
,
1553 struct rpc_pipe_client
*pipe_hnd
,
1554 TALLOC_CTX
*mem_ctx
,
1558 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1561 uint32 num_printers
;
1563 char *printername
, *sharename
;
1564 bool got_hnd_src
= False
;
1565 bool got_hnd_dst
= False
;
1566 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
1567 POLICY_HND hnd_src
, hnd_dst
;
1568 PRINTER_INFO_CTR ctr_enum
, ctr_dst
;
1571 struct cli_state
*cli_dst
= NULL
;
1573 ZERO_STRUCT(ctr_enum
);
1575 DEBUG(3,("copying forms\n"));
1577 /* connect destination PI_SPOOLSS */
1578 nt_status
= connect_dst_pipe(&cli_dst
, &pipe_hnd_dst
, PI_SPOOLSS
);
1579 if (!NT_STATUS_IS_OK(nt_status
))
1582 /* enum src printers */
1583 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &ctr_enum
)) {
1584 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1588 if (!num_printers
) {
1589 printf ("no printers found on server.\n");
1590 nt_status
= NT_STATUS_OK
;
1594 /* do something for all printers */
1595 for (i
= 0; i
< num_printers
; i
++) {
1596 /* do some initialization */
1597 rpcstr_pull_talloc(mem_ctx
,
1599 ctr_enum
.printers_2
[i
].printername
.buffer
,
1602 rpcstr_pull_talloc(mem_ctx
,
1604 ctr_enum
.printers_2
[i
].sharename
.buffer
,
1607 if (!printername
|| !sharename
) {
1608 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1611 /* we can reset NT_STATUS here because we do not
1612 get any real NT_STATUS-codes anymore from now on */
1613 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1615 d_printf("migrating printer forms for: [%s] / [%s]\n",
1616 printername
, sharename
);
1619 /* open src printer handle */
1620 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1621 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
1627 /* open dst printer handle */
1628 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
1629 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd_dst
))
1635 /* check for existing dst printer */
1636 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, level
, &ctr_dst
))
1639 /* finally migrate forms */
1640 if (!net_spoolss_enumforms(pipe_hnd
, mem_ctx
, &hnd_src
, level
, &num_forms
, &forms
))
1643 DEBUG(1,("got %d forms for printer\n", num_forms
));
1646 for (f
= 0; f
< num_forms
; f
++) {
1651 /* only migrate FORM_PRINTER types, according to jerry
1652 FORM_BUILTIN-types are hard-coded in samba */
1653 if (forms
[f
].flag
!= FORM_PRINTER
)
1656 if (forms
[f
].name
.buffer
)
1657 rpcstr_pull(form_name
, forms
[f
].name
.buffer
,
1658 sizeof(form_name
), -1, STR_TERMINATE
);
1661 d_printf("\tmigrating form # %d [%s] of type [%d]\n",
1662 f
, form_name
, forms
[f
].flag
);
1664 /* is there a more elegant way to do that ? */
1665 form
.flags
= FORM_PRINTER
;
1666 form
.size_x
= forms
[f
].width
;
1667 form
.size_y
= forms
[f
].length
;
1668 form
.left
= forms
[f
].left
;
1669 form
.top
= forms
[f
].top
;
1670 form
.right
= forms
[f
].right
;
1671 form
.bottom
= forms
[f
].bottom
;
1673 init_unistr2(&form
.name
, form_name
, UNI_STR_TERMINATE
);
1675 /* FIXME: there might be something wrong with samba's
1677 result
= rpccli_spoolss_addform(pipe_hnd_dst
, mem_ctx
,
1678 &hnd_dst
, 1, &form
);
1679 if (!W_ERROR_IS_OK(result
)) {
1680 d_printf("\tAddForm form %d: [%s] refused.\n",
1685 DEBUGADD(1,("\tAddForm of [%s] succeeded\n", form_name
));
1689 /* close printer handles here */
1691 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
1692 got_hnd_src
= False
;
1696 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
1697 got_hnd_dst
= False
;
1701 nt_status
= NT_STATUS_OK
;
1706 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
1709 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
1712 cli_shutdown(cli_dst
);
1718 * Migrate printer-drivers from a src server to the dst server
1720 * All parameters are provided by the run_rpc_command function, except for
1721 * argc, argv which are passed through.
1723 * @param domain_sid The domain sid aquired from the remote server
1724 * @param cli A cli_state connected to the server.
1725 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1726 * @param argc Standard main() style argc
1727 * @param argv Standard main() style argv. Initial components are already
1730 * @return Normal NTSTATUS return.
1733 NTSTATUS
rpc_printer_migrate_drivers_internals(const DOM_SID
*domain_sid
,
1734 const char *domain_name
,
1735 struct cli_state
*cli
,
1736 struct rpc_pipe_client
*pipe_hnd
,
1737 TALLOC_CTX
*mem_ctx
,
1741 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1743 uint32 num_printers
;
1745 char *printername
, *sharename
;
1746 bool got_hnd_src
= False
;
1747 bool got_hnd_dst
= False
;
1748 bool got_src_driver_share
= False
;
1749 bool got_dst_driver_share
= False
;
1750 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
1751 POLICY_HND hnd_src
, hnd_dst
;
1752 PRINTER_DRIVER_CTR drv_ctr_src
, drv_ctr_dst
;
1753 PRINTER_INFO_CTR info_ctr_enum
, info_ctr_dst
;
1754 struct cli_state
*cli_dst
= NULL
;
1755 struct cli_state
*cli_share_src
= NULL
;
1756 struct cli_state
*cli_share_dst
= NULL
;
1757 fstring drivername
= "";
1759 ZERO_STRUCT(drv_ctr_src
);
1760 ZERO_STRUCT(drv_ctr_dst
);
1761 ZERO_STRUCT(info_ctr_enum
);
1762 ZERO_STRUCT(info_ctr_dst
);
1764 DEBUG(3,("copying printer-drivers\n"));
1766 nt_status
= connect_dst_pipe(&cli_dst
, &pipe_hnd_dst
, PI_SPOOLSS
);
1767 if (!NT_STATUS_IS_OK(nt_status
))
1770 /* open print$-share on the src server */
1771 nt_status
= connect_to_service(&cli_share_src
, &cli
->dest_ss
,
1772 cli
->desthost
, "print$", "A:");
1773 if (!NT_STATUS_IS_OK(nt_status
))
1776 got_src_driver_share
= True
;
1779 /* open print$-share on the dst server */
1780 nt_status
= connect_to_service(&cli_share_dst
, &cli_dst
->dest_ss
,
1781 cli_dst
->desthost
, "print$", "A:");
1782 if (!NT_STATUS_IS_OK(nt_status
))
1785 got_dst_driver_share
= True
;
1788 /* enum src printers */
1789 if (!get_printer_info(pipe_hnd
, mem_ctx
, 2, argc
, argv
, &num_printers
, &info_ctr_enum
)) {
1790 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1794 if (num_printers
== 0) {
1795 printf ("no printers found on server.\n");
1796 nt_status
= NT_STATUS_OK
;
1801 /* do something for all printers */
1802 for (p
= 0; p
< num_printers
; p
++) {
1803 /* do some initialization */
1804 rpcstr_pull_talloc(mem_ctx
,
1806 info_ctr_enum
.printers_2
[p
].printername
.buffer
,
1809 rpcstr_pull_talloc(mem_ctx
,
1811 info_ctr_enum
.printers_2
[p
].sharename
.buffer
,
1814 if (!printername
|| !sharename
) {
1815 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1819 /* we can reset NT_STATUS here because we do not
1820 get any real NT_STATUS-codes anymore from now on */
1821 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1823 d_printf("migrating printer driver for: [%s] / [%s]\n",
1824 printername
, sharename
);
1826 /* open dst printer handle */
1827 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
1828 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd_dst
))
1833 /* check for existing dst printer */
1834 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 2, &info_ctr_dst
))
1838 /* open src printer handle */
1839 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
1840 MAXIMUM_ALLOWED_ACCESS
, pipe_hnd
->cli
->user_name
, &hnd_src
))
1846 /* in a first step call getdriver for each shared printer (per arch)
1847 to get a list of all files that have to be copied */
1849 for (i
=0; archi_table
[i
].long_archi
!=NULL
; i
++) {
1852 if (!net_spoolss_getprinterdriver(pipe_hnd
, mem_ctx
, &hnd_src
,
1853 level
, archi_table
[i
].long_archi
,
1854 archi_table
[i
].version
, &drv_ctr_src
))
1857 rpcstr_pull(drivername
, drv_ctr_src
.info3
->name
.buffer
,
1858 sizeof(drivername
), -1, STR_TERMINATE
);
1861 display_print_driver_3(drv_ctr_src
.info3
);
1864 /* check arch dir */
1865 nt_status
= check_arch_dir(cli_share_dst
, archi_table
[i
].short_archi
);
1866 if (!NT_STATUS_IS_OK(nt_status
))
1870 /* copy driver-files */
1871 nt_status
= copy_print_driver_3(mem_ctx
, cli_share_src
, cli_share_dst
,
1872 archi_table
[i
].short_archi
,
1874 if (!NT_STATUS_IS_OK(nt_status
))
1879 if (!net_spoolss_addprinterdriver(pipe_hnd_dst
, mem_ctx
, level
, &drv_ctr_src
)) {
1880 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1884 DEBUGADD(1,("Sucessfully added driver [%s] for printer [%s]\n",
1885 drivername
, printername
));
1889 if (strlen(drivername
) == 0) {
1890 DEBUGADD(1,("Did not get driver for printer %s\n",
1896 init_unistr(&info_ctr_dst
.printers_2
->drivername
, drivername
);
1898 if (!net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 2, &info_ctr_dst
)) {
1899 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1903 DEBUGADD(1,("Sucessfully set driver %s for printer %s\n",
1904 drivername
, printername
));
1908 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
1909 got_hnd_dst
= False
;
1914 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
1915 got_hnd_src
= False
;
1919 nt_status
= NT_STATUS_OK
;
1924 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
1927 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
1930 cli_shutdown(cli_dst
);
1933 if (got_src_driver_share
)
1934 cli_shutdown(cli_share_src
);
1936 if (got_dst_driver_share
)
1937 cli_shutdown(cli_share_dst
);
1944 * Migrate printer-queues from a src to the dst server
1945 * (requires a working "addprinter command" to be installed for the local smbd)
1947 * All parameters are provided by the run_rpc_command function, except for
1948 * argc, argv which are passed through.
1950 * @param domain_sid The domain sid aquired from the remote server
1951 * @param cli A cli_state connected to the server.
1952 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1953 * @param argc Standard main() style argc
1954 * @param argv Standard main() style argv. Initial components are already
1957 * @return Normal NTSTATUS return.
1960 NTSTATUS
rpc_printer_migrate_printers_internals(const DOM_SID
*domain_sid
,
1961 const char *domain_name
,
1962 struct cli_state
*cli
,
1963 struct rpc_pipe_client
*pipe_hnd
,
1964 TALLOC_CTX
*mem_ctx
,
1969 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
1970 uint32 i
= 0, num_printers
;
1972 PRINTER_INFO_CTR ctr_src
, ctr_dst
, ctr_enum
;
1973 struct cli_state
*cli_dst
= NULL
;
1974 POLICY_HND hnd_dst
, hnd_src
;
1975 char *printername
, *sharename
;
1976 bool got_hnd_src
= False
;
1977 bool got_hnd_dst
= False
;
1978 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
1980 DEBUG(3,("copying printers\n"));
1982 /* connect destination PI_SPOOLSS */
1983 nt_status
= connect_dst_pipe(&cli_dst
, &pipe_hnd_dst
, PI_SPOOLSS
);
1984 if (!NT_STATUS_IS_OK(nt_status
))
1988 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &ctr_enum
)) {
1989 nt_status
= NT_STATUS_UNSUCCESSFUL
;
1993 if (!num_printers
) {
1994 printf ("no printers found on server.\n");
1995 nt_status
= NT_STATUS_OK
;
1999 /* do something for all printers */
2000 for (i
= 0; i
< num_printers
; i
++) {
2001 /* do some initialization */
2002 rpcstr_pull_talloc(mem_ctx
,
2004 ctr_enum
.printers_2
[i
].printername
.buffer
,
2007 rpcstr_pull_talloc(mem_ctx
,
2009 ctr_enum
.printers_2
[i
].sharename
.buffer
,
2012 if (!printername
|| !sharename
) {
2013 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2016 /* we can reset NT_STATUS here because we do not
2017 get any real NT_STATUS-codes anymore from now on */
2018 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2020 d_printf("migrating printer queue for: [%s] / [%s]\n",
2021 printername
, sharename
);
2023 /* open dst printer handle */
2024 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
2025 PRINTER_ALL_ACCESS
, cli
->user_name
, &hnd_dst
)) {
2027 DEBUG(1,("could not open printer: %s\n", sharename
));
2032 /* check for existing dst printer */
2033 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, level
, &ctr_dst
)) {
2034 printf ("could not get printer, creating printer.\n");
2036 DEBUG(1,("printer already exists: %s\n", sharename
));
2037 /* close printer handle here - dst only, not got src yet. */
2039 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
2040 got_hnd_dst
= False
;
2045 /* now get again src printer ctr via getprinter,
2046 we first need a handle for that */
2048 /* open src printer handle */
2049 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
2050 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
2055 /* getprinter on the src server */
2056 if (!net_spoolss_getprinter(pipe_hnd
, mem_ctx
, &hnd_src
, level
, &ctr_src
))
2059 /* copy each src printer to a dst printer 1:1,
2060 maybe some values have to be changed though */
2061 d_printf("creating printer: %s\n", printername
);
2062 result
= rpccli_spoolss_addprinterex (pipe_hnd_dst
, mem_ctx
, level
, &ctr_src
);
2064 if (W_ERROR_IS_OK(result
))
2065 d_printf ("printer [%s] successfully added.\n", printername
);
2066 else if (W_ERROR_V(result
) == W_ERROR_V(WERR_PRINTER_ALREADY_EXISTS
))
2067 d_fprintf (stderr
, "printer [%s] already exists.\n", printername
);
2069 d_fprintf (stderr
, "could not create printer [%s]\n", printername
);
2073 /* close printer handles here */
2075 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
2076 got_hnd_src
= False
;
2080 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
2081 got_hnd_dst
= False
;
2085 nt_status
= NT_STATUS_OK
;
2089 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
2092 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
2095 cli_shutdown(cli_dst
);
2101 * Migrate Printer-Settings from a src server to the dst server
2102 * (for this to work, printers and drivers already have to be migrated earlier)
2104 * All parameters are provided by the run_rpc_command function, except for
2105 * argc, argv which are passed through.
2107 * @param domain_sid The domain sid aquired from the remote server
2108 * @param cli A cli_state connected to the server.
2109 * @param mem_ctx Talloc context, destoyed on compleation of the function.
2110 * @param argc Standard main() style argc
2111 * @param argv Standard main() style argv. Initial components are already
2114 * @return Normal NTSTATUS return.
2117 NTSTATUS
rpc_printer_migrate_settings_internals(const DOM_SID
*domain_sid
,
2118 const char *domain_name
,
2119 struct cli_state
*cli
,
2120 struct rpc_pipe_client
*pipe_hnd
,
2121 TALLOC_CTX
*mem_ctx
,
2126 /* FIXME: Here the nightmare begins */
2129 NTSTATUS nt_status
= NT_STATUS_UNSUCCESSFUL
;
2130 uint32 i
= 0, p
= 0, j
= 0;
2131 uint32 num_printers
, val_needed
, data_needed
;
2133 char *printername
, *sharename
;
2134 bool got_hnd_src
= False
;
2135 bool got_hnd_dst
= False
;
2136 struct rpc_pipe_client
*pipe_hnd_dst
= NULL
;
2137 POLICY_HND hnd_src
, hnd_dst
;
2138 PRINTER_INFO_CTR ctr_enum
, ctr_dst
, ctr_dst_publish
;
2139 REGVAL_CTR
*reg_ctr
;
2140 struct cli_state
*cli_dst
= NULL
;
2141 char *devicename
= NULL
, *unc_name
= NULL
, *url
= NULL
;
2142 const char *longname
;
2144 uint16
*keylist
= NULL
, *curkey
;
2146 ZERO_STRUCT(ctr_enum
);
2148 DEBUG(3,("copying printer settings\n"));
2150 /* connect destination PI_SPOOLSS */
2151 nt_status
= connect_dst_pipe(&cli_dst
, &pipe_hnd_dst
, PI_SPOOLSS
);
2152 if (!NT_STATUS_IS_OK(nt_status
))
2155 /* enum src printers */
2156 if (!get_printer_info(pipe_hnd
, mem_ctx
, level
, argc
, argv
, &num_printers
, &ctr_enum
)) {
2157 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2161 if (!num_printers
) {
2162 printf ("no printers found on server.\n");
2163 nt_status
= NT_STATUS_OK
;
2168 /* needed for dns-strings in regkeys */
2169 longname
= get_mydnsfullname();
2171 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2175 /* do something for all printers */
2176 for (i
= 0; i
< num_printers
; i
++) {
2177 /* do some initialization */
2178 rpcstr_pull_talloc(mem_ctx
,
2180 ctr_enum
.printers_2
[i
].printername
.buffer
,
2183 rpcstr_pull_talloc(mem_ctx
,
2185 ctr_enum
.printers_2
[i
].sharename
.buffer
,
2188 if (!printername
|| !sharename
) {
2189 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2192 /* we can reset NT_STATUS here because we do not
2193 get any real NT_STATUS-codes anymore from now on */
2194 nt_status
= NT_STATUS_UNSUCCESSFUL
;
2196 d_printf("migrating printer settings for: [%s] / [%s]\n",
2197 printername
, sharename
);
2200 /* open src printer handle */
2201 if (!net_spoolss_open_printer_ex(pipe_hnd
, mem_ctx
, sharename
,
2202 MAXIMUM_ALLOWED_ACCESS
, cli
->user_name
, &hnd_src
))
2208 /* open dst printer handle */
2209 if (!net_spoolss_open_printer_ex(pipe_hnd_dst
, mem_ctx
, sharename
,
2210 PRINTER_ALL_ACCESS
, cli_dst
->user_name
, &hnd_dst
))
2216 /* check for existing dst printer */
2217 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
,
2222 /* STEP 1: COPY DEVICE-MODE and other
2223 PRINTER_INFO_2-attributes
2226 ctr_dst
.printers_2
= &ctr_enum
.printers_2
[i
];
2228 /* why is the port always disconnected when the printer
2229 is correctly installed (incl. driver ???) */
2230 init_unistr( &ctr_dst
.printers_2
->portname
, SAMBA_PRINTER_PORT_NAME
);
2232 /* check if printer is published */
2233 if (ctr_enum
.printers_2
[i
].attributes
& PRINTER_ATTRIBUTE_PUBLISHED
) {
2235 /* check for existing dst printer */
2236 if (!net_spoolss_getprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 7, &ctr_dst_publish
))
2239 ctr_dst_publish
.printers_7
->action
= SPOOL_DS_PUBLISH
;
2241 /* ignore False from setprinter due to WERR_IO_PENDING */
2242 net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
, 7, &ctr_dst_publish
);
2244 DEBUG(3,("republished printer\n"));
2247 if (ctr_enum
.printers_2
[i
].devmode
!= NULL
) {
2249 /* copy devmode (info level 2) */
2250 ctr_dst
.printers_2
->devmode
= (DEVICEMODE
*)
2251 TALLOC_MEMDUP(mem_ctx
,
2252 ctr_enum
.printers_2
[i
].devmode
,
2253 sizeof(DEVICEMODE
));
2255 /* do not copy security descriptor (we have another
2256 * command for that) */
2257 ctr_dst
.printers_2
->secdesc
= NULL
;
2260 if (asprintf(&devicename
, "\\\\%s\\%s", longname
,
2262 nt_status
= NT_STATUS_NO_MEMORY
;
2266 init_unistr(&ctr_dst
.printers_2
->devmode
->devicename
,
2269 if (!net_spoolss_setprinter(pipe_hnd_dst
, mem_ctx
, &hnd_dst
,
2273 DEBUGADD(1,("\tSetPrinter of DEVICEMODE succeeded\n"));
2276 /* STEP 2: COPY REGISTRY VALUES */
2278 /* please keep in mind that samba parse_spools gives horribly
2279 crippled results when used to rpccli_spoolss_enumprinterdataex
2280 a win2k3-server. (Bugzilla #1851)
2281 FIXME: IIRC I've seen it too on a win2k-server
2284 /* enumerate data on src handle */
2285 result
= rpccli_spoolss_enumprinterdata(pipe_hnd
, mem_ctx
, &hnd_src
, p
, 0, 0,
2286 &val_needed
, &data_needed
, NULL
);
2288 /* loop for all printerdata of "PrinterDriverData" */
2289 while (W_ERROR_IS_OK(result
)) {
2291 REGISTRY_VALUE value
;
2293 result
= rpccli_spoolss_enumprinterdata(
2294 pipe_hnd
, mem_ctx
, &hnd_src
, p
++, val_needed
,
2295 data_needed
, 0, 0, &value
);
2297 /* loop for all reg_keys */
2298 if (W_ERROR_IS_OK(result
)) {
2302 display_reg_value(SPOOL_PRINTERDATA_KEY
, value
);
2305 if (!net_spoolss_setprinterdata(pipe_hnd_dst
, mem_ctx
,
2309 DEBUGADD(1,("\tSetPrinterData of [%s] succeeded\n",
2314 /* STEP 3: COPY SUBKEY VALUES */
2316 /* here we need to enum all printer_keys and then work
2317 on the result with enum_printer_key_ex. nt4 does not
2318 respond to enumprinterkey, win2k does, so continue
2319 in case of an error */
2321 if (!net_spoolss_enumprinterkey(pipe_hnd
, mem_ctx
, &hnd_src
, "", &keylist
)) {
2322 printf("got no key-data\n");
2327 /* work on a list of printer keys
2328 each key has to be enumerated to get all required
2329 information. information is then set via setprinterdataex-calls */
2331 if (keylist
== NULL
)
2335 while (*curkey
!= 0) {
2337 rpcstr_pull_talloc(mem_ctx
,
2343 return NT_STATUS_NO_MEMORY
;
2346 curkey
+= strlen(subkey
) + 1;
2348 if ( !(reg_ctr
= TALLOC_ZERO_P( mem_ctx
, REGVAL_CTR
)) )
2349 return NT_STATUS_NO_MEMORY
;
2351 /* enumerate all src subkeys */
2352 if (!net_spoolss_enumprinterdataex(pipe_hnd
, mem_ctx
, 0,
2357 for (j
=0; j
< reg_ctr
->num_values
; j
++) {
2359 REGISTRY_VALUE value
;
2362 /* although samba replies with sane data in most cases we
2363 should try to avoid writing wrong registry data */
2365 if (strequal(reg_ctr
->values
[j
]->valuename
, SPOOL_REG_PORTNAME
) ||
2366 strequal(reg_ctr
->values
[j
]->valuename
, SPOOL_REG_UNCNAME
) ||
2367 strequal(reg_ctr
->values
[j
]->valuename
, SPOOL_REG_URL
) ||
2368 strequal(reg_ctr
->values
[j
]->valuename
, SPOOL_REG_SHORTSERVERNAME
) ||
2369 strequal(reg_ctr
->values
[j
]->valuename
, SPOOL_REG_SERVERNAME
)) {
2371 if (strequal(reg_ctr
->values
[j
]->valuename
, SPOOL_REG_PORTNAME
)) {
2373 /* although windows uses a multi-sz, we use a sz */
2374 init_unistr2(&data
, SAMBA_PRINTER_PORT_NAME
, UNI_STR_TERMINATE
);
2375 fstrcpy(value
.valuename
, SPOOL_REG_PORTNAME
);
2378 if (strequal(reg_ctr
->values
[j
]->valuename
, SPOOL_REG_UNCNAME
)) {
2380 if (asprintf(&unc_name
, "\\\\%s\\%s", longname
, sharename
) < 0) {
2381 nt_status
= NT_STATUS_NO_MEMORY
;
2384 init_unistr2(&data
, unc_name
, UNI_STR_TERMINATE
);
2385 fstrcpy(value
.valuename
, SPOOL_REG_UNCNAME
);
2388 if (strequal(reg_ctr
->values
[j
]->valuename
, SPOOL_REG_URL
)) {
2393 /* FIXME: should we really do that ??? */
2394 if (asprintf(&url
, "http://%s:631/printers/%s", longname
, sharename
) < 0) {
2395 nt_status
= NT_STATUS_NO_MEMORY
;
2398 init_unistr2(&data
, url
, UNI_STR_TERMINATE
);
2399 fstrcpy(value
.valuename
, SPOOL_REG_URL
);
2403 if (strequal(reg_ctr
->values
[j
]->valuename
, SPOOL_REG_SERVERNAME
)) {
2405 init_unistr2(&data
, longname
, UNI_STR_TERMINATE
);
2406 fstrcpy(value
.valuename
, SPOOL_REG_SERVERNAME
);
2409 if (strequal(reg_ctr
->values
[j
]->valuename
, SPOOL_REG_SHORTSERVERNAME
)) {
2411 init_unistr2(&data
, global_myname(), UNI_STR_TERMINATE
);
2412 fstrcpy(value
.valuename
, SPOOL_REG_SHORTSERVERNAME
);
2415 value
.type
= REG_SZ
;
2416 value
.size
= data
.uni_str_len
* 2;
2418 value
.data_p
= (uint8
*)TALLOC_MEMDUP(mem_ctx
, data
.buffer
, value
.size
);
2420 value
.data_p
= NULL
;
2424 display_reg_value(subkey
, value
);
2426 /* here we have to set all subkeys on the dst server */
2427 if (!net_spoolss_setprinterdataex(pipe_hnd_dst
, mem_ctx
, &hnd_dst
,
2434 display_reg_value(subkey
, *(reg_ctr
->values
[j
]));
2436 /* here we have to set all subkeys on the dst server */
2437 if (!net_spoolss_setprinterdataex(pipe_hnd_dst
, mem_ctx
, &hnd_dst
,
2438 subkey
, reg_ctr
->values
[j
]))
2443 DEBUGADD(1,("\tSetPrinterDataEx of key [%s\\%s] succeeded\n",
2444 subkey
, reg_ctr
->values
[j
]->valuename
));
2448 TALLOC_FREE( reg_ctr
);
2453 /* close printer handles here */
2455 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
2456 got_hnd_src
= False
;
2460 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
2461 got_hnd_dst
= False
;
2466 nt_status
= NT_STATUS_OK
;
2469 SAFE_FREE(devicename
);
2471 SAFE_FREE(unc_name
);
2474 rpccli_spoolss_close_printer(pipe_hnd
, mem_ctx
, &hnd_src
);
2477 rpccli_spoolss_close_printer(pipe_hnd_dst
, mem_ctx
, &hnd_dst
);
2480 cli_shutdown(cli_dst
);