2 Samba Unix/Linux SMB client library
3 Distributed SMB/CIFS Server Management Utility
4 Copyright (C) 2004,2009 Guenther Deschner (gd@samba.org)
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "utils/net.h"
21 #include "../librpc/gen_ndr/cli_spoolss.h"
22 #include "rpc_client/cli_spoolss.h"
23 #include "rpc_client/init_spoolss.h"
24 #include "nt_printing.h"
26 #include "registry/reg_objects.h"
28 /* support itanium as well */
29 static const struct print_architecture_table_node archi_table[]= {
31 {"Windows 4.0", "WIN40", 0 },
32 {"Windows NT x86", "W32X86", 2 },
33 {"Windows NT x86", "W32X86", 3 },
34 {"Windows NT R4000", "W32MIPS", 2 },
35 {"Windows NT Alpha_AXP", "W32ALPHA", 2 },
36 {"Windows NT PowerPC", "W32PPC", 2 },
37 {"Windows IA64", "IA64", 3 },
38 {"Windows x64", "x64", 3 },
44 * This display-printdriver-functions was borrowed from rpcclient/cmd_spoolss.c.
45 * It is here for debugging purpose and should be removed later on.
48 /****************************************************************************
49 Printer info level 3 display function.
50 ****************************************************************************/
52 static void display_print_driver3(struct spoolss_DriverInfo3 *r)
60 printf(_("Printer Driver Info 3:\n"));
61 printf(_("\tVersion: [%x]\n"), r->version);
62 printf(_("\tDriver Name: [%s]\n"), r->driver_name);
63 printf(_("\tArchitecture: [%s]\n"), r->architecture);
64 printf(_("\tDriver Path: [%s]\n"), r->driver_path);
65 printf(_("\tDatafile: [%s]\n"), r->data_file);
66 printf(_("\tConfigfile: [%s]\n\n"), r->config_file);
67 printf(_("\tHelpfile: [%s]\n\n"), r->help_file);
69 for (i=0; r->dependent_files[i] != NULL; i++) {
70 printf(_("\tDependentfiles: [%s]\n"), r->dependent_files[i]);
75 printf(_("\tMonitorname: [%s]\n"), r->monitor_name);
76 printf(_("\tDefaultdatatype: [%s]\n\n"), r->default_datatype);
79 static void display_reg_value(const char *subkey, struct regval_blob *value)
84 switch(regval_type(value)) {
86 d_printf(_("\t[%s:%s]: REG_DWORD: 0x%08x\n"), subkey,
87 regval_name(value), *((uint32_t *) regval_data_p(value)));
91 blob = data_blob_const(regval_data_p(value), regval_size(value));
92 pull_reg_sz(talloc_tos(), &blob, &text);
96 d_printf(_("\t[%s:%s]: REG_SZ: %s\n"), subkey, regval_name(value),
101 d_printf(_("\t[%s:%s]: REG_BINARY: unknown length value not "
103 subkey, regval_name(value));
109 blob = data_blob_const(regval_data_p(value), regval_size(value));
111 if (!pull_reg_multi_sz(NULL, &blob, &values)) {
112 d_printf("pull_reg_multi_sz failed\n");
116 printf("%s: REG_MULTI_SZ: \n", regval_name(value));
117 for (i=0; values[i] != NULL; i++) {
118 d_printf("%s\n", values[i]);
125 d_printf(_("\t%s: unknown type %d\n"), regval_name(value),
132 * Copies ACLs, DOS-attributes and timestamps from one
133 * file or directory from one connected share to another connected share
135 * @param c A net_context structure
136 * @param mem_ctx A talloc-context
137 * @param cli_share_src A connected cli_state
138 * @param cli_share_dst A connected cli_state
139 * @param src_file The source file-name
140 * @param dst_file The destination file-name
141 * @param copy_acls Whether to copy acls
142 * @param copy_attrs Whether to copy DOS attributes
143 * @param copy_timestamps Whether to preserve timestamps
144 * @param is_file Whether this file is a file or a dir
146 * @return Normal NTSTATUS return.
149 NTSTATUS net_copy_fileattr(struct net_context *c,
151 struct cli_state *cli_share_src,
152 struct cli_state *cli_share_dst,
153 const char *src_name, const char *dst_name,
154 bool copy_acls, bool copy_attrs,
155 bool copy_timestamps, bool is_file)
157 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
158 uint16_t fnum_src = 0;
159 uint16_t fnum_dst = 0;
160 struct security_descriptor *sd = NULL;
162 time_t f_atime, f_ctime, f_mtime;
165 if (!copy_timestamps && !copy_acls && !copy_attrs)
168 /* open file/dir on the originating server */
170 DEBUGADD(3,("opening %s %s on originating server\n",
171 is_file?"file":"dir", src_name));
173 if (!NT_STATUS_IS_OK(cli_ntcreate(cli_share_src, src_name, 0, READ_CONTROL_ACCESS, 0,
174 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum_src))) {
175 DEBUGADD(0,("cannot open %s %s on originating server %s\n",
176 is_file?"file":"dir", src_name, cli_errstr(cli_share_src)));
177 nt_status = cli_nt_error(cli_share_src);
184 /* get the security descriptor */
185 sd = cli_query_secdesc(cli_share_src, fnum_src, mem_ctx);
187 DEBUG(0,("failed to get security descriptor: %s\n",
188 cli_errstr(cli_share_src)));
189 nt_status = cli_nt_error(cli_share_src);
193 if (c->opt_verbose && DEBUGLEVEL >= 3)
194 display_sec_desc(sd);
198 if (copy_attrs || copy_timestamps) {
200 /* get file attributes */
201 if (!NT_STATUS_IS_OK(cli_getattrE(cli_share_src, fnum_src, &attr, NULL,
202 &f_ctime, &f_atime, &f_mtime))) {
203 DEBUG(0,("failed to get file-attrs: %s\n",
204 cli_errstr(cli_share_src)));
205 nt_status = cli_nt_error(cli_share_src);
211 /* open the file/dir on the destination server */
213 if (!NT_STATUS_IS_OK(cli_ntcreate(cli_share_dst, dst_name, 0, WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS, 0,
214 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum_dst))) {
215 DEBUG(0,("failed to open %s on the destination server: %s: %s\n",
216 is_file?"file":"dir", dst_name, cli_errstr(cli_share_dst)));
217 nt_status = cli_nt_error(cli_share_dst);
221 if (copy_timestamps) {
224 if (!NT_STATUS_IS_OK(cli_setattrE(cli_share_dst, fnum_dst, f_ctime, f_atime, f_mtime))) {
225 DEBUG(0,("failed to set file-attrs (timestamps): %s\n",
226 cli_errstr(cli_share_dst)));
227 nt_status = cli_nt_error(cli_share_dst);
235 if (!cli_set_secdesc(cli_share_dst, fnum_dst, sd)) {
236 DEBUG(0,("could not set secdesc on %s: %s\n",
237 dst_name, cli_errstr(cli_share_dst)));
238 nt_status = cli_nt_error(cli_share_dst);
246 if (!NT_STATUS_IS_OK(cli_setatr(cli_share_dst, dst_name, attr, 0))) {
247 DEBUG(0,("failed to set file-attrs: %s\n",
248 cli_errstr(cli_share_dst)));
249 nt_status = cli_nt_error(cli_share_dst);
257 if (!NT_STATUS_IS_OK(cli_close(cli_share_src, fnum_src))) {
259 _("could not close %s on originating server: %s\n"),
260 is_file?"file":"dir", cli_errstr(cli_share_src));
261 nt_status = cli_nt_error(cli_share_src);
265 if (!NT_STATUS_IS_OK(cli_close(cli_share_dst, fnum_dst))) {
267 _("could not close %s on destination server: %s\n"),
268 is_file?"file":"dir", cli_errstr(cli_share_dst));
269 nt_status = cli_nt_error(cli_share_dst);
274 nt_status = NT_STATUS_OK;
280 cli_close(cli_share_src, fnum_src);
283 cli_close(cli_share_dst, fnum_dst);
289 * Copy a file or directory from a connected share to another connected share
291 * @param c A net_context structure
292 * @param mem_ctx A talloc-context
293 * @param cli_share_src A connected cli_state
294 * @param cli_share_dst A connected cli_state
295 * @param src_file The source file-name
296 * @param dst_file The destination file-name
297 * @param copy_acls Whether to copy acls
298 * @param copy_attrs Whether to copy DOS attributes
299 * @param copy_timestamps Whether to preserve timestamps
300 * @param is_file Whether this file is a file or a dir
302 * @return Normal NTSTATUS return.
305 NTSTATUS net_copy_file(struct net_context *c,
307 struct cli_state *cli_share_src,
308 struct cli_state *cli_share_dst,
309 const char *src_name, const char *dst_name,
310 bool copy_acls, bool copy_attrs,
311 bool copy_timestamps, bool is_file)
313 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
314 uint16_t fnum_src = 0;
315 uint16_t fnum_dst = 0;
316 static int io_bufsize = 64512;
317 int read_size = io_bufsize;
322 if (!src_name || !dst_name)
325 if (cli_share_src == NULL || cli_share_dst == NULL)
328 /* open on the originating server */
329 DEBUGADD(3,("opening %s %s on originating server\n",
330 is_file ? "file":"dir", src_name));
332 nt_status = cli_open(cli_share_src, src_name, O_RDONLY, DENY_NONE, &fnum_src);
334 nt_status = cli_ntcreate(cli_share_src, src_name, 0, READ_CONTROL_ACCESS, 0,
335 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0x0, 0x0, &fnum_src);
337 if (!NT_STATUS_IS_OK(nt_status)) {
338 DEBUGADD(0,("cannot open %s %s on originating server %s\n",
339 is_file ? "file":"dir",
340 src_name, cli_errstr(cli_share_src)));
347 /* open file on the destination server */
348 DEBUGADD(3,("opening file %s on destination server\n", dst_name));
349 nt_status = cli_open(cli_share_dst, dst_name,
350 O_RDWR|O_CREAT|O_TRUNC, DENY_NONE, &fnum_dst);
352 if (!NT_STATUS_IS_OK(nt_status)) {
353 DEBUGADD(1,("cannot create file %s on destination server: %s\n",
354 dst_name, cli_errstr(cli_share_dst)));
358 /* allocate memory */
359 if (!(data = (char *)SMB_MALLOC(read_size))) {
360 d_fprintf(stderr, _("malloc fail for size %d\n"),
362 nt_status = NT_STATUS_NO_MEMORY;
369 if (c->opt_verbose) {
371 d_printf(_("copying [\\\\%s\\%s%s] => [\\\\%s\\%s%s] "
372 "%s ACLs and %s DOS Attributes %s\n"),
373 cli_share_src->desthost, cli_share_src->share, src_name,
374 cli_share_dst->desthost, cli_share_dst->share, dst_name,
375 copy_acls ? _("with") : _("without"),
376 copy_attrs ? _("with") : _("without"),
377 copy_timestamps ? _("(preserving timestamps)") : "" );
385 n = cli_read(cli_share_src, fnum_src, data, nread,
391 ret = cli_write(cli_share_dst, fnum_dst, 0, data,
395 d_fprintf(stderr, _("Error writing file: %s\n"),
396 cli_errstr(cli_share_dst));
397 nt_status = cli_nt_error(cli_share_dst);
405 if (!is_file && !NT_STATUS_IS_OK(cli_chkpath(cli_share_dst, dst_name))) {
408 DEBUGADD(3,("creating dir %s on the destination server\n",
411 if (!NT_STATUS_IS_OK(cli_mkdir(cli_share_dst, dst_name))) {
412 DEBUG(0,("cannot create directory %s: %s\n",
413 dst_name, cli_errstr(cli_share_dst)));
414 nt_status = NT_STATUS_NO_SUCH_FILE;
417 if (!NT_STATUS_IS_OK(cli_chkpath(cli_share_dst, dst_name))) {
419 _("cannot check for directory %s: %s\n"),
420 dst_name, cli_errstr(cli_share_dst));
427 if (!NT_STATUS_IS_OK(cli_close(cli_share_src, fnum_src))) {
429 _("could not close file on originating server: %s\n"),
430 cli_errstr(cli_share_src));
431 nt_status = cli_nt_error(cli_share_src);
435 if (is_file && !NT_STATUS_IS_OK(cli_close(cli_share_dst, fnum_dst))) {
437 _("could not close file on destination server: %s\n"),
438 cli_errstr(cli_share_dst));
439 nt_status = cli_nt_error(cli_share_dst);
443 /* possibly we have to copy some file-attributes / acls / sd */
444 nt_status = net_copy_fileattr(c, mem_ctx, cli_share_src, cli_share_dst,
445 src_name, dst_name, copy_acls,
446 copy_attrs, copy_timestamps, is_file);
447 if (!NT_STATUS_IS_OK(nt_status))
451 nt_status = NT_STATUS_OK;
457 cli_close(cli_share_src, fnum_src);
460 cli_close(cli_share_dst, fnum_dst);
468 * Copy a driverfile from on connected share to another connected share
469 * This silently assumes that a driver-file is picked up from
471 * \\src_server\print$\{arch}\{version}\file
475 * \\dst_server\print$\{arch}\file
477 * to be added via setdriver-calls later.
478 * @param c A net_context structure
479 * @param mem_ctx A talloc-context
480 * @param cli_share_src A cli_state connected to source print$-share
481 * @param cli_share_dst A cli_state connected to destination print$-share
482 * @param file The file-name to be copied
483 * @param short_archi The name of the driver-architecture (short form)
485 * @return Normal NTSTATUS return.
488 static NTSTATUS net_copy_driverfile(struct net_context *c,
490 struct cli_state *cli_share_src,
491 struct cli_state *cli_share_dst,
492 const char *file, const char *short_archi) {
497 char *version = NULL;
498 char *filename = NULL;
505 /* scroll through the file until we have the part
506 beyond archi_table.short_archi */
508 while (next_token_talloc(mem_ctx, &p, &tok, "\\")) {
509 if (strequal(tok, short_archi)) {
510 next_token_talloc(mem_ctx, &p, &version, "\\");
511 next_token_talloc(mem_ctx, &p, &filename, "\\");
515 if (version == NULL || filename == NULL) {
516 return NT_STATUS_UNSUCCESSFUL;
519 /* build source file name */
520 src_name = talloc_asprintf(mem_ctx, "\\%s\\%s\\%s",
521 short_archi, version, filename);
522 if (src_name == NULL) {
523 return NT_STATUS_NO_MEMORY;
526 /* create destination file name */
527 dst_name = talloc_asprintf(mem_ctx, "\\%s\\%s", short_archi, filename);
528 if (dst_name == NULL) {
529 return NT_STATUS_NO_MEMORY;
533 /* finally copy the file */
534 return net_copy_file(c, mem_ctx, cli_share_src, cli_share_dst,
535 src_name, dst_name, false, false, false, true);
539 * Check for existing Architecture directory on a given server
541 * @param cli_share A cli_state connected to a print$-share
542 * @param short_archi The Architecture for the print-driver
544 * @return Normal NTSTATUS return.
547 static NTSTATUS check_arch_dir(struct cli_state *cli_share, const char *short_archi)
550 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
553 if (asprintf(&dir, "\\%s", short_archi) < 0) {
554 return NT_STATUS_NO_MEMORY;
557 DEBUG(10,("creating print-driver dir for architecture: %s\n",
560 if (!NT_STATUS_IS_OK(cli_mkdir(cli_share, dir))) {
561 DEBUG(1,("cannot create directory %s: %s\n",
562 dir, cli_errstr(cli_share)));
563 nt_status = NT_STATUS_NO_SUCH_FILE;
566 if (!NT_STATUS_IS_OK(cli_chkpath(cli_share, dir))) {
567 d_fprintf(stderr, _("cannot check %s: %s\n"),
568 dir, cli_errstr(cli_share));
572 nt_status = NT_STATUS_OK;
580 * Copy a print-driver (level 3) from one connected print$-share to another
581 * connected print$-share
583 * @param c A net_context structure
584 * @param mem_ctx A talloc-context
585 * @param cli_share_src A cli_state connected to a print$-share
586 * @param cli_share_dst A cli_state connected to a print$-share
587 * @param short_archi The Architecture for the print-driver
588 * @param i1 The DRIVER_INFO_3-struct
590 * @return Normal NTSTATUS return.
593 static NTSTATUS copy_print_driver_3(struct net_context *c,
595 struct cli_state *cli_share_src,
596 struct cli_state *cli_share_dst,
597 const char *short_archi,
598 struct spoolss_DriverInfo3 *r)
600 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
608 d_printf(_("copying driver: [%s], for architecture: [%s], "
610 r->driver_name, short_archi, r->version);
612 nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst,
613 r->driver_path, short_archi);
614 if (!NT_STATUS_IS_OK(nt_status))
617 nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst,
618 r->data_file, short_archi);
619 if (!NT_STATUS_IS_OK(nt_status))
622 nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst,
623 r->config_file, short_archi);
624 if (!NT_STATUS_IS_OK(nt_status))
627 nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst,
628 r->help_file, short_archi);
629 if (!NT_STATUS_IS_OK(nt_status))
632 for (i=0; r->dependent_files[i] != NULL; i++) {
634 nt_status = net_copy_driverfile(c, mem_ctx,
635 cli_share_src, cli_share_dst,
636 r->dependent_files[i], short_archi);
637 if (!NT_STATUS_IS_OK(nt_status)) {
646 * net_spoolss-functions
647 * =====================
649 * the net_spoolss-functions aim to simplify spoolss-client-functions
650 * required during the migration-process wrt buffer-sizes, returned
653 * this greatly reduces the complexitiy of the migrate-functions.
657 static bool net_spoolss_enum_printers(struct rpc_pipe_client *pipe_hnd,
662 uint32_t *num_printers,
663 union spoolss_PrinterInfo **info)
669 result = rpccli_spoolss_enumprinters(pipe_hnd, mem_ctx,
676 if (!W_ERROR_IS_OK(result)) {
677 printf(_("cannot enum printers: %s\n"), win_errstr(result));
684 static bool net_spoolss_open_printer_ex(struct rpc_pipe_client *pipe_hnd,
686 const char *printername,
687 uint32_t access_required,
688 const char *username,
689 struct policy_handle *hnd)
692 fstring printername2;
694 fstrcpy(printername2, pipe_hnd->srv_name_slash);
695 fstrcat(printername2, "\\");
696 fstrcat(printername2, printername);
698 DEBUG(10,("connecting to: %s as %s for %s and access: %x\n",
699 pipe_hnd->srv_name_slash, username, printername2, access_required));
702 result = rpccli_spoolss_openprinter_ex(pipe_hnd, mem_ctx,
707 /* be more verbose */
708 if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) {
710 _("no access to printer [%s] on [%s] for user [%s] "
712 printername2, pipe_hnd->srv_name_slash, username);
716 if (!W_ERROR_IS_OK(result)) {
717 d_fprintf(stderr,_("cannot open printer %s on server %s: %s\n"),
718 printername2, pipe_hnd->srv_name_slash, win_errstr(result));
722 DEBUG(2,("got printer handle for printer: %s, server: %s\n",
723 printername2, pipe_hnd->srv_name_slash));
728 static bool net_spoolss_getprinter(struct rpc_pipe_client *pipe_hnd,
730 struct policy_handle *hnd,
732 union spoolss_PrinterInfo *info)
736 /* getprinter call */
737 result = rpccli_spoolss_getprinter(pipe_hnd, mem_ctx,
742 if (!W_ERROR_IS_OK(result)) {
743 printf(_("cannot get printer-info: %s\n"), win_errstr(result));
750 static bool net_spoolss_setprinter(struct rpc_pipe_client *pipe_hnd,
752 struct policy_handle *hnd,
754 union spoolss_PrinterInfo *info)
758 struct spoolss_SetPrinterInfoCtr info_ctr;
759 struct spoolss_SetPrinterInfo2 info2;
760 struct spoolss_DevmodeContainer devmode_ctr;
761 struct sec_desc_buf secdesc_ctr;
763 ZERO_STRUCT(devmode_ctr);
764 ZERO_STRUCT(secdesc_ctr);
766 /* setprinter call */
768 info_ctr.level = level;
771 info_ctr.info.info0 = (struct spoolss_SetPrinterInfo0 *)
772 (void *)&info->info0;
775 info_ctr.info.info1 = (struct spoolss_SetPrinterInfo1 *)
776 (void *)&info->info1;
779 spoolss_printerinfo2_to_setprinterinfo2(&info->info2, &info2);
780 info_ctr.info.info2 = &info2;
783 info_ctr.info.info3 = (struct spoolss_SetPrinterInfo3 *)
784 (void *)&info->info3;
787 info_ctr.info.info4 = (struct spoolss_SetPrinterInfo4 *)
788 (void *)&info->info4;
791 info_ctr.info.info5 = (struct spoolss_SetPrinterInfo5 *)
792 (void *)&info->info5;
795 info_ctr.info.info6 = (struct spoolss_SetPrinterInfo6 *)
796 (void *)&info->info6;
799 info_ctr.info.info7 = (struct spoolss_SetPrinterInfo7 *)
800 (void *)&info->info7;
804 info_ctr.info.info8 = (struct spoolss_SetPrinterInfo8 *)
805 (void *)&info->info8;
808 info_ctr.info.info9 = (struct spoolss_SetPrinterInfo9 *)
809 (void *)&info->info9;
816 status = rpccli_spoolss_SetPrinter(pipe_hnd, mem_ctx,
824 if (!W_ERROR_IS_OK(result)) {
825 printf(_("cannot set printer-info: %s\n"), win_errstr(result));
833 static bool net_spoolss_setprinterdata(struct rpc_pipe_client *pipe_hnd,
835 struct policy_handle *hnd,
836 const char *value_name,
837 enum winreg_Type type,
844 /* setprinterdata call */
845 status = rpccli_spoolss_SetPrinterData(pipe_hnd, mem_ctx,
853 if (!W_ERROR_IS_OK(result)) {
854 printf (_("unable to set printerdata: %s\n"),
863 static bool net_spoolss_enumprinterkey(struct rpc_pipe_client *pipe_hnd,
865 struct policy_handle *hnd,
867 const char ***keylist)
871 /* enumprinterkey call */
872 result = rpccli_spoolss_enumprinterkey(pipe_hnd, mem_ctx, hnd, keyname, keylist, 0);
874 if (!W_ERROR_IS_OK(result)) {
875 printf(_("enumprinterkey failed: %s\n"), win_errstr(result));
882 static bool net_spoolss_enumprinterdataex(struct rpc_pipe_client *pipe_hnd,
885 struct policy_handle *hnd,
888 struct spoolss_PrinterEnumValues **info)
892 /* enumprinterdataex call */
893 result = rpccli_spoolss_enumprinterdataex(pipe_hnd, mem_ctx,
900 if (!W_ERROR_IS_OK(result)) {
901 printf(_("enumprinterdataex failed: %s\n"), win_errstr(result));
909 static bool net_spoolss_setprinterdataex(struct rpc_pipe_client *pipe_hnd,
911 struct policy_handle *hnd,
913 struct regval_blob *value)
918 /* setprinterdataex call */
919 status = rpccli_spoolss_SetPrinterDataEx(pipe_hnd, mem_ctx,
924 regval_data_p(value),
928 if (!W_ERROR_IS_OK(result)) {
929 printf(_("could not set printerdataex: %s\n"),
937 static bool net_spoolss_enumforms(struct rpc_pipe_client *pipe_hnd,
939 struct policy_handle *hnd,
942 union spoolss_FormInfo **forms)
947 result = rpccli_spoolss_enumforms(pipe_hnd, mem_ctx,
953 if (!W_ERROR_IS_OK(result)) {
954 printf(_("could not enum forms: %s\n"), win_errstr(result));
961 static bool net_spoolss_enumprinterdrivers (struct rpc_pipe_client *pipe_hnd,
963 uint32_t level, const char *env,
965 union spoolss_DriverInfo **info)
969 /* enumprinterdrivers call */
970 result = rpccli_spoolss_enumprinterdrivers(pipe_hnd, mem_ctx,
971 pipe_hnd->srv_name_slash,
977 if (!W_ERROR_IS_OK(result)) {
978 printf(_("cannot enum drivers: %s\n"), win_errstr(result));
985 static bool net_spoolss_getprinterdriver(struct rpc_pipe_client *pipe_hnd,
987 struct policy_handle *hnd, uint32_t level,
988 const char *env, int version,
989 union spoolss_DriverInfo *info)
992 uint32_t server_major_version;
993 uint32_t server_minor_version;
995 /* getprinterdriver call */
996 result = rpccli_spoolss_getprinterdriver2(pipe_hnd, mem_ctx,
1004 &server_major_version,
1005 &server_minor_version);
1006 if (!W_ERROR_IS_OK(result)) {
1007 DEBUG(1,("cannot get driver (for architecture: %s): %s\n",
1008 env, win_errstr(result)));
1009 if (W_ERROR_V(result) != W_ERROR_V(WERR_UNKNOWN_PRINTER_DRIVER) &&
1010 W_ERROR_V(result) != W_ERROR_V(WERR_INVALID_ENVIRONMENT)) {
1011 printf(_("cannot get driver: %s\n"),
1012 win_errstr(result));
1021 static bool net_spoolss_addprinterdriver(struct rpc_pipe_client *pipe_hnd,
1022 TALLOC_CTX *mem_ctx, uint32_t level,
1023 union spoolss_DriverInfo *info)
1027 struct spoolss_AddDriverInfoCtr info_ctr;
1029 info_ctr.level = level;
1033 info_ctr.info.info2 = (struct spoolss_AddDriverInfo2 *)
1034 (void *)&info->info2;
1037 info_ctr.info.info3 = (struct spoolss_AddDriverInfo3 *)
1038 (void *)&info->info3;
1041 printf(_("unsupported info level: %d\n"), level);
1045 /* addprinterdriver call */
1046 status = rpccli_spoolss_AddPrinterDriver(pipe_hnd, mem_ctx,
1047 pipe_hnd->srv_name_slash,
1050 /* be more verbose */
1051 if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) {
1052 printf(_("You are not allowed to add drivers\n"));
1055 if (!W_ERROR_IS_OK(result)) {
1056 printf(_("cannot add driver: %s\n"), win_errstr(result));
1064 * abstraction function to get uint32_t num_printers and PRINTER_INFO_CTR ctr
1065 * for a single printer or for all printers depending on argc/argv
1068 static bool get_printer_info(struct rpc_pipe_client *pipe_hnd,
1069 TALLOC_CTX *mem_ctx,
1073 uint32_t *num_printers,
1074 union spoolss_PrinterInfo **info_p)
1076 struct policy_handle hnd;
1078 /* no arguments given, enumerate all printers */
1081 if (!net_spoolss_enum_printers(pipe_hnd, mem_ctx, NULL,
1082 PRINTER_ENUM_LOCAL|PRINTER_ENUM_SHARED,
1083 level, num_printers, info_p))
1089 /* argument given, get a single printer by name */
1090 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, argv[0],
1091 MAXIMUM_ALLOWED_ACCESS,
1092 pipe_hnd->auth->user_name,
1096 *info_p = talloc_zero(mem_ctx, union spoolss_PrinterInfo);
1097 if (*info_p == NULL) {
1101 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, *info_p)) {
1102 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1106 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1111 DEBUG(3,("got %d printers\n", *num_printers));
1118 * List print-queues (including local printers that are not shared)
1120 * All parameters are provided by the run_rpc_command function, except for
1121 * argc, argv which are passed through.
1123 * @param c A net_context structure
1124 * @param domain_sid The domain sid aquired from the remote server
1125 * @param cli A cli_state connected to the server.
1126 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1127 * @param argc Standard main() style argc
1128 * @param argv Standard main() style argv. Initial components are already
1131 * @return Normal NTSTATUS return.
1134 NTSTATUS rpc_printer_list_internals(struct net_context *c,
1135 const struct dom_sid *domain_sid,
1136 const char *domain_name,
1137 struct cli_state *cli,
1138 struct rpc_pipe_client *pipe_hnd,
1139 TALLOC_CTX *mem_ctx,
1143 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1144 uint32_t i, num_printers;
1146 const char *printername, *sharename;
1147 union spoolss_PrinterInfo *info;
1149 printf("listing printers\n");
1151 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &info))
1154 for (i = 0; i < num_printers; i++) {
1156 /* do some initialization */
1157 printername = info[i].info2.printername;
1158 sharename = info[i].info2.sharename;
1160 if (printername && sharename) {
1161 d_printf(_("printer %d: %s, shared as: %s\n"),
1162 i+1, printername, sharename);
1166 return NT_STATUS_OK;
1170 * List printer-drivers from a server
1172 * All parameters are provided by the run_rpc_command function, except for
1173 * argc, argv which are passed through.
1175 * @param c A net_context structure
1176 * @param domain_sid The domain sid aquired from the remote server
1177 * @param cli A cli_state connected to the server.
1178 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1179 * @param argc Standard main() style argc
1180 * @param argv Standard main() style argv. Initial components are already
1183 * @return Normal NTSTATUS return.
1186 NTSTATUS rpc_printer_driver_list_internals(struct net_context *c,
1187 const struct dom_sid *domain_sid,
1188 const char *domain_name,
1189 struct cli_state *cli,
1190 struct rpc_pipe_client *pipe_hnd,
1191 TALLOC_CTX *mem_ctx,
1195 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1198 union spoolss_DriverInfo *info;
1201 printf(_("listing printer-drivers\n"));
1203 for (i=0; archi_table[i].long_archi!=NULL; i++) {
1205 uint32_t num_drivers;
1207 /* enum remote drivers */
1208 if (!net_spoolss_enumprinterdrivers(pipe_hnd, mem_ctx, level,
1209 archi_table[i].long_archi,
1210 &num_drivers, &info)) {
1211 nt_status = NT_STATUS_UNSUCCESSFUL;
1215 if (num_drivers == 0) {
1216 d_printf(_("no drivers found on server for "
1217 "architecture: [%s].\n"),
1218 archi_table[i].long_archi);
1222 d_printf(_("got %d printer-drivers for architecture: [%s]\n"),
1223 num_drivers, archi_table[i].long_archi);
1226 /* do something for all drivers for architecture */
1227 for (d = 0; d < num_drivers; d++) {
1228 display_print_driver3(&info[d].info3);
1232 nt_status = NT_STATUS_OK;
1240 * Publish print-queues with args-wrapper
1242 * @param cli A cli_state connected to the server.
1243 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1244 * @param argc Standard main() style argc
1245 * @param argv Standard main() style argv. Initial components are already
1249 * @return Normal NTSTATUS return.
1252 static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_hnd,
1253 TALLOC_CTX *mem_ctx,
1258 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1259 uint32_t i, num_printers;
1261 const char *printername, *sharename;
1262 union spoolss_PrinterInfo *info_enum;
1263 union spoolss_PrinterInfo info;
1264 struct spoolss_SetPrinterInfoCtr info_ctr;
1265 struct spoolss_DevmodeContainer devmode_ctr;
1266 struct sec_desc_buf secdesc_ctr;
1267 struct policy_handle hnd;
1269 const char *action_str;
1271 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_enum))
1274 for (i = 0; i < num_printers; i++) {
1276 /* do some initialization */
1277 printername = info_enum[i].info2.printername;
1278 sharename = info_enum[i].info2.sharename;
1279 if (!printername || !sharename) {
1283 /* open printer handle */
1284 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1285 PRINTER_ALL_ACCESS, pipe_hnd->auth->user_name, &hnd))
1288 /* check for existing dst printer */
1289 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info))
1292 /* check action and set string */
1294 case DSPRINT_PUBLISH:
1295 action_str = N_("published");
1297 case DSPRINT_UPDATE:
1298 action_str = N_("updated");
1300 case DSPRINT_UNPUBLISH:
1301 action_str = N_("unpublished");
1304 action_str = N_("unknown action");
1305 printf(_("unkown action: %d\n"), action);
1309 info.info7.action = action;
1311 info_ctr.info.info7 = (struct spoolss_SetPrinterInfo7 *)
1312 (void *)&info.info7;
1314 ZERO_STRUCT(devmode_ctr);
1315 ZERO_STRUCT(secdesc_ctr);
1317 nt_status = rpccli_spoolss_SetPrinter(pipe_hnd, mem_ctx,
1325 if (!W_ERROR_IS_OK(result) && (W_ERROR_V(result) != W_ERROR_V(WERR_IO_PENDING))) {
1326 printf(_("cannot set printer-info: %s\n"),
1327 win_errstr(result));
1331 printf(_("successfully %s printer %s in Active Directory\n"),
1332 action_str, sharename);
1335 nt_status = NT_STATUS_OK;
1338 if (is_valid_policy_hnd(&hnd))
1339 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1344 NTSTATUS rpc_printer_publish_publish_internals(struct net_context *c,
1345 const struct dom_sid *domain_sid,
1346 const char *domain_name,
1347 struct cli_state *cli,
1348 struct rpc_pipe_client *pipe_hnd,
1349 TALLOC_CTX *mem_ctx,
1353 return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, DSPRINT_PUBLISH);
1356 NTSTATUS rpc_printer_publish_unpublish_internals(struct net_context *c,
1357 const struct dom_sid *domain_sid,
1358 const char *domain_name,
1359 struct cli_state *cli,
1360 struct rpc_pipe_client *pipe_hnd,
1361 TALLOC_CTX *mem_ctx,
1365 return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, DSPRINT_UNPUBLISH);
1368 NTSTATUS rpc_printer_publish_update_internals(struct net_context *c,
1369 const struct dom_sid *domain_sid,
1370 const char *domain_name,
1371 struct cli_state *cli,
1372 struct rpc_pipe_client *pipe_hnd,
1373 TALLOC_CTX *mem_ctx,
1377 return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, DSPRINT_UPDATE);
1381 * List print-queues w.r.t. their publishing state
1383 * All parameters are provided by the run_rpc_command function, except for
1384 * argc, argv which are passed through.
1386 * @param c A net_context structure
1387 * @param domain_sid The domain sid aquired from the remote server
1388 * @param cli A cli_state connected to the server.
1389 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1390 * @param argc Standard main() style argc
1391 * @param argv Standard main() style argv. Initial components are already
1394 * @return Normal NTSTATUS return.
1397 NTSTATUS rpc_printer_publish_list_internals(struct net_context *c,
1398 const struct dom_sid *domain_sid,
1399 const char *domain_name,
1400 struct cli_state *cli,
1401 struct rpc_pipe_client *pipe_hnd,
1402 TALLOC_CTX *mem_ctx,
1406 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1407 uint32_t i, num_printers;
1409 const char *printername, *sharename;
1410 union spoolss_PrinterInfo *info_enum;
1411 union spoolss_PrinterInfo info;
1412 struct policy_handle hnd;
1415 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_enum))
1418 for (i = 0; i < num_printers; i++) {
1420 /* do some initialization */
1421 printername = info_enum[i].info2.printername;
1422 sharename = info_enum[i].info2.sharename;
1424 if (!printername || !sharename) {
1428 /* open printer handle */
1429 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1430 PRINTER_ALL_ACCESS, cli->user_name, &hnd))
1433 /* check for existing dst printer */
1434 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &info))
1437 if (!info.info7.guid) {
1440 state = info.info7.action;
1442 case DSPRINT_PUBLISH:
1443 printf(_("printer [%s] is published"),
1446 printf(_(", guid: %s"),info.info7.guid);
1449 case DSPRINT_UNPUBLISH:
1450 printf(_("printer [%s] is unpublished\n"),
1453 case DSPRINT_UPDATE:
1454 printf(_("printer [%s] is currently updating\n"),
1458 printf(_("unkown state: %d\n"), state);
1463 nt_status = NT_STATUS_OK;
1466 if (is_valid_policy_hnd(&hnd))
1467 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd, NULL);
1473 * Migrate Printer-ACLs from a source server to the destination server
1475 * All parameters are provided by the run_rpc_command function, except for
1476 * argc, argv which are passed through.
1478 * @param c A net_context structure
1479 * @param domain_sid The domain sid aquired from the remote server
1480 * @param cli A cli_state connected to the server.
1481 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1482 * @param argc Standard main() style argc
1483 * @param argv Standard main() style argv. Initial components are already
1486 * @return Normal NTSTATUS return.
1489 NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c,
1490 const struct dom_sid *domain_sid,
1491 const char *domain_name,
1492 struct cli_state *cli,
1493 struct rpc_pipe_client *pipe_hnd,
1494 TALLOC_CTX *mem_ctx,
1498 /* TODO: what now, info2 or info3 ?
1499 convince jerry that we should add clientside setacls level 3 at least
1501 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1503 uint32_t num_printers;
1505 const char *printername, *sharename;
1506 struct rpc_pipe_client *pipe_hnd_dst = NULL;
1507 struct policy_handle hnd_src, hnd_dst;
1508 union spoolss_PrinterInfo *info_enum;
1509 struct cli_state *cli_dst = NULL;
1510 union spoolss_PrinterInfo info_src, info_dst;
1512 DEBUG(3,("copying printer ACLs\n"));
1514 /* connect destination PI_SPOOLSS */
1515 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
1516 &ndr_table_spoolss.syntax_id);
1517 if (!NT_STATUS_IS_OK(nt_status))
1521 /* enum source printers */
1522 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &info_enum)) {
1523 nt_status = NT_STATUS_UNSUCCESSFUL;
1527 if (!num_printers) {
1528 printf (_("no printers found on server.\n"));
1529 nt_status = NT_STATUS_OK;
1533 /* do something for all printers */
1534 for (i = 0; i < num_printers; i++) {
1536 /* do some initialization */
1537 printername = info_enum[i].info2.printername;
1538 sharename = info_enum[i].info2.sharename;
1540 if (!printername || !sharename) {
1541 nt_status = NT_STATUS_UNSUCCESSFUL;
1545 /* we can reset NT_STATUS here because we do not
1546 get any real NT_STATUS-codes anymore from now on */
1547 nt_status = NT_STATUS_UNSUCCESSFUL;
1549 d_printf(_("migrating printer ACLs for: [%s] / [%s]\n"),
1550 printername, sharename);
1552 /* according to msdn you have specify these access-rights
1553 to see the security descriptor
1554 - READ_CONTROL (DACL)
1555 - ACCESS_SYSTEM_SECURITY (SACL)
1558 /* open src printer handle */
1559 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1560 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
1563 /* open dst printer handle */
1564 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
1565 PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst))
1568 /* check for existing dst printer */
1569 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst))
1572 /* check for existing src printer */
1573 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, 3, &info_src))
1576 /* Copy Security Descriptor */
1578 /* copy secdesc (info level 2) */
1579 info_dst.info2.devmode = NULL;
1580 info_dst.info2.secdesc = dup_sec_desc(mem_ctx, info_src.info3.secdesc);
1583 display_sec_desc(info_dst.info2.secdesc);
1585 if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst))
1588 DEBUGADD(1,("\tSetPrinter of SECDESC succeeded\n"));
1591 /* close printer handles here */
1592 if (is_valid_policy_hnd(&hnd_src)) {
1593 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1596 if (is_valid_policy_hnd(&hnd_dst)) {
1597 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1602 nt_status = NT_STATUS_OK;
1606 if (is_valid_policy_hnd(&hnd_src)) {
1607 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1610 if (is_valid_policy_hnd(&hnd_dst)) {
1611 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1615 cli_shutdown(cli_dst);
1621 * Migrate printer-forms from a src server to the dst server
1623 * All parameters are provided by the run_rpc_command function, except for
1624 * argc, argv which are passed through.
1626 * @param c A net_context structure
1627 * @param domain_sid The domain sid aquired from the remote server
1628 * @param cli A cli_state connected to the server.
1629 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1630 * @param argc Standard main() style argc
1631 * @param argv Standard main() style argv. Initial components are already
1634 * @return Normal NTSTATUS return.
1637 NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c,
1638 const struct dom_sid *domain_sid,
1639 const char *domain_name,
1640 struct cli_state *cli,
1641 struct rpc_pipe_client *pipe_hnd,
1642 TALLOC_CTX *mem_ctx,
1646 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1649 uint32_t num_printers;
1651 const char *printername, *sharename;
1652 struct rpc_pipe_client *pipe_hnd_dst = NULL;
1653 struct policy_handle hnd_src, hnd_dst;
1654 union spoolss_PrinterInfo *info_enum;
1655 union spoolss_PrinterInfo info_dst;
1657 union spoolss_FormInfo *forms;
1658 struct cli_state *cli_dst = NULL;
1660 DEBUG(3,("copying forms\n"));
1662 /* connect destination PI_SPOOLSS */
1663 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
1664 &ndr_table_spoolss.syntax_id);
1665 if (!NT_STATUS_IS_OK(nt_status))
1668 /* enum src printers */
1669 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_enum)) {
1670 nt_status = NT_STATUS_UNSUCCESSFUL;
1674 if (!num_printers) {
1675 printf (_("no printers found on server.\n"));
1676 nt_status = NT_STATUS_OK;
1680 /* do something for all printers */
1681 for (i = 0; i < num_printers; i++) {
1683 /* do some initialization */
1684 printername = info_enum[i].info2.printername;
1685 sharename = info_enum[i].info2.sharename;
1687 if (!printername || !sharename) {
1688 nt_status = NT_STATUS_UNSUCCESSFUL;
1691 /* we can reset NT_STATUS here because we do not
1692 get any real NT_STATUS-codes anymore from now on */
1693 nt_status = NT_STATUS_UNSUCCESSFUL;
1695 d_printf(_("migrating printer forms for: [%s] / [%s]\n"),
1696 printername, sharename);
1699 /* open src printer handle */
1700 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1701 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
1704 /* open dst printer handle */
1705 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
1706 PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst))
1709 /* check for existing dst printer */
1710 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst))
1713 /* finally migrate forms */
1714 if (!net_spoolss_enumforms(pipe_hnd, mem_ctx, &hnd_src, level, &num_forms, &forms))
1717 DEBUG(1,("got %d forms for printer\n", num_forms));
1720 for (f = 0; f < num_forms; f++) {
1722 union spoolss_AddFormInfo info;
1725 /* only migrate FORM_PRINTER types, according to jerry
1726 FORM_BUILTIN-types are hard-coded in samba */
1727 if (forms[f].info1.flags != SPOOLSS_FORM_PRINTER)
1731 d_printf(_("\tmigrating form # %d [%s] of type "
1733 f, forms[f].info1.form_name,
1734 forms[f].info1.flags);
1736 info.info1 = (struct spoolss_AddFormInfo1 *)
1737 (void *)&forms[f].info1;
1739 /* FIXME: there might be something wrong with samba's
1741 status = rpccli_spoolss_AddForm(pipe_hnd_dst, mem_ctx,
1746 if (!W_ERROR_IS_OK(result)) {
1747 d_printf(_("\tAddForm form %d: [%s] refused.\n"),
1748 f, forms[f].info1.form_name);
1752 DEBUGADD(1,("\tAddForm of [%s] succeeded\n",
1753 forms[f].info1.form_name));
1757 /* close printer handles here */
1758 if (is_valid_policy_hnd(&hnd_src)) {
1759 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1762 if (is_valid_policy_hnd(&hnd_dst)) {
1763 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1767 nt_status = NT_STATUS_OK;
1771 if (is_valid_policy_hnd(&hnd_src))
1772 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1774 if (is_valid_policy_hnd(&hnd_dst))
1775 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1778 cli_shutdown(cli_dst);
1784 * Migrate printer-drivers from a src server to the dst server
1786 * All parameters are provided by the run_rpc_command function, except for
1787 * argc, argv which are passed through.
1789 * @param c A net_context structure
1790 * @param domain_sid The domain sid aquired from the remote server
1791 * @param cli A cli_state connected to the server.
1792 * @param mem_ctx Talloc context, destoyed on compleation of the function.
1793 * @param argc Standard main() style argc
1794 * @param argv Standard main() style argv. Initial components are already
1797 * @return Normal NTSTATUS return.
1800 NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c,
1801 const struct dom_sid *domain_sid,
1802 const char *domain_name,
1803 struct cli_state *cli,
1804 struct rpc_pipe_client *pipe_hnd,
1805 TALLOC_CTX *mem_ctx,
1809 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
1811 uint32_t num_printers;
1813 const char *printername, *sharename;
1814 bool got_src_driver_share = false;
1815 bool got_dst_driver_share = false;
1816 struct rpc_pipe_client *pipe_hnd_dst = NULL;
1817 struct policy_handle hnd_src, hnd_dst;
1818 union spoolss_DriverInfo drv_info_src;
1819 union spoolss_PrinterInfo *info_enum;
1820 union spoolss_PrinterInfo info_dst;
1821 struct cli_state *cli_dst = NULL;
1822 struct cli_state *cli_share_src = NULL;
1823 struct cli_state *cli_share_dst = NULL;
1824 const char *drivername = NULL;
1826 DEBUG(3,("copying printer-drivers\n"));
1828 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
1829 &ndr_table_spoolss.syntax_id);
1830 if (!NT_STATUS_IS_OK(nt_status))
1833 /* open print$-share on the src server */
1834 nt_status = connect_to_service(c, &cli_share_src, &cli->dest_ss,
1835 cli->desthost, "print$", "A:");
1836 if (!NT_STATUS_IS_OK(nt_status))
1839 got_src_driver_share = true;
1842 /* open print$-share on the dst server */
1843 nt_status = connect_to_service(c, &cli_share_dst, &cli_dst->dest_ss,
1844 cli_dst->desthost, "print$", "A:");
1845 if (!NT_STATUS_IS_OK(nt_status))
1848 got_dst_driver_share = true;
1851 /* enum src printers */
1852 if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_enum)) {
1853 nt_status = NT_STATUS_UNSUCCESSFUL;
1857 if (num_printers == 0) {
1858 printf (_("no printers found on server.\n"));
1859 nt_status = NT_STATUS_OK;
1864 /* do something for all printers */
1865 for (p = 0; p < num_printers; p++) {
1867 /* do some initialization */
1868 printername = info_enum[p].info2.printername;
1869 sharename = info_enum[p].info2.sharename;
1871 if (!printername || !sharename) {
1872 nt_status = NT_STATUS_UNSUCCESSFUL;
1876 /* we can reset NT_STATUS here because we do not
1877 get any real NT_STATUS-codes anymore from now on */
1878 nt_status = NT_STATUS_UNSUCCESSFUL;
1880 d_printf(_("migrating printer driver for: [%s] / [%s]\n"),
1881 printername, sharename);
1883 /* open dst printer handle */
1884 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
1885 PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst))
1888 /* check for existing dst printer */
1889 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst))
1893 /* open src printer handle */
1894 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
1895 MAXIMUM_ALLOWED_ACCESS,
1896 pipe_hnd->auth->user_name,
1900 /* in a first step call getdriver for each shared printer (per arch)
1901 to get a list of all files that have to be copied */
1903 for (i=0; archi_table[i].long_archi!=NULL; i++) {
1906 if (!net_spoolss_getprinterdriver(pipe_hnd, mem_ctx, &hnd_src,
1907 level, archi_table[i].long_archi,
1908 archi_table[i].version, &drv_info_src))
1911 drivername = drv_info_src.info3.driver_name;
1914 display_print_driver3(&drv_info_src.info3);
1916 /* check arch dir */
1917 nt_status = check_arch_dir(cli_share_dst, archi_table[i].short_archi);
1918 if (!NT_STATUS_IS_OK(nt_status))
1922 /* copy driver-files */
1923 nt_status = copy_print_driver_3(c, mem_ctx, cli_share_src, cli_share_dst,
1924 archi_table[i].short_archi,
1925 &drv_info_src.info3);
1926 if (!NT_STATUS_IS_OK(nt_status))
1931 if (!net_spoolss_addprinterdriver(pipe_hnd_dst, mem_ctx, level, &drv_info_src)) {
1932 nt_status = NT_STATUS_UNSUCCESSFUL;
1936 DEBUGADD(1,("Sucessfully added driver [%s] for printer [%s]\n",
1937 drivername, printername));
1941 if (!drivername || strlen(drivername) == 0) {
1942 DEBUGADD(1,("Did not get driver for printer %s\n",
1948 info_dst.info2.drivername = drivername;
1950 if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_dst)) {
1951 nt_status = NT_STATUS_UNSUCCESSFUL;
1955 DEBUGADD(1,("Sucessfully set driver %s for printer %s\n",
1956 drivername, printername));
1959 if (is_valid_policy_hnd(&hnd_dst)) {
1960 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1964 if (is_valid_policy_hnd(&hnd_src)) {
1965 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1969 nt_status = NT_STATUS_OK;
1973 if (is_valid_policy_hnd(&hnd_src))
1974 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
1976 if (is_valid_policy_hnd(&hnd_dst))
1977 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
1980 cli_shutdown(cli_dst);
1983 if (got_src_driver_share)
1984 cli_shutdown(cli_share_src);
1986 if (got_dst_driver_share)
1987 cli_shutdown(cli_share_dst);
1994 * Migrate printer-queues from a src to the dst server
1995 * (requires a working "addprinter command" to be installed for the local smbd)
1997 * All parameters are provided by the run_rpc_command function, except for
1998 * argc, argv which are passed through.
2000 * @param c A net_context structure
2001 * @param domain_sid The domain sid aquired from the remote server
2002 * @param cli A cli_state connected to the server.
2003 * @param mem_ctx Talloc context, destoyed on compleation of the function.
2004 * @param argc Standard main() style argc
2005 * @param argv Standard main() style argv. Initial components are already
2008 * @return Normal NTSTATUS return.
2011 NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c,
2012 const struct dom_sid *domain_sid,
2013 const char *domain_name,
2014 struct cli_state *cli,
2015 struct rpc_pipe_client *pipe_hnd,
2016 TALLOC_CTX *mem_ctx,
2021 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
2022 uint32_t i = 0, num_printers;
2024 union spoolss_PrinterInfo info_dst, info_src;
2025 union spoolss_PrinterInfo *info_enum;
2026 struct cli_state *cli_dst = NULL;
2027 struct policy_handle hnd_dst, hnd_src;
2028 const char *printername, *sharename;
2029 struct rpc_pipe_client *pipe_hnd_dst = NULL;
2030 struct spoolss_SetPrinterInfoCtr info_ctr;
2032 DEBUG(3,("copying printers\n"));
2034 /* connect destination PI_SPOOLSS */
2035 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
2036 &ndr_table_spoolss.syntax_id);
2037 if (!NT_STATUS_IS_OK(nt_status))
2041 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &info_enum)) {
2042 nt_status = NT_STATUS_UNSUCCESSFUL;
2046 if (!num_printers) {
2047 printf (_("no printers found on server.\n"));
2048 nt_status = NT_STATUS_OK;
2052 /* do something for all printers */
2053 for (i = 0; i < num_printers; i++) {
2055 struct spoolss_SetPrinterInfo2 info2;
2057 /* do some initialization */
2058 printername = info_enum[i].info2.printername;
2059 sharename = info_enum[i].info2.sharename;
2061 if (!printername || !sharename) {
2062 nt_status = NT_STATUS_UNSUCCESSFUL;
2065 /* we can reset NT_STATUS here because we do not
2066 get any real NT_STATUS-codes anymore from now on */
2067 nt_status = NT_STATUS_UNSUCCESSFUL;
2069 d_printf(_("migrating printer queue for: [%s] / [%s]\n"),
2070 printername, sharename);
2072 /* open dst printer handle */
2073 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
2074 PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) {
2076 DEBUG(1,("could not open printer: %s\n", sharename));
2079 /* check for existing dst printer */
2080 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &info_dst)) {
2081 printf (_("could not get printer, creating printer.\n"));
2083 DEBUG(1,("printer already exists: %s\n", sharename));
2084 /* close printer handle here - dst only, not got src yet. */
2085 if (is_valid_policy_hnd(&hnd_dst)) {
2086 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2091 /* now get again src printer ctr via getprinter,
2092 we first need a handle for that */
2094 /* open src printer handle */
2095 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
2096 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
2099 /* getprinter on the src server */
2100 if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, level, &info_src))
2103 /* copy each src printer to a dst printer 1:1,
2104 maybe some values have to be changed though */
2105 d_printf(_("creating printer: %s\n"), printername);
2107 info_ctr.level = level;
2108 spoolss_printerinfo2_to_setprinterinfo2(&info_src.info2, &info2);
2109 info_ctr.info.info2 = &info2;
2111 result = rpccli_spoolss_addprinterex(pipe_hnd_dst,
2115 if (W_ERROR_IS_OK(result))
2116 d_printf (_("printer [%s] successfully added.\n"),
2118 else if (W_ERROR_V(result) == W_ERROR_V(WERR_PRINTER_ALREADY_EXISTS))
2119 d_fprintf (stderr, _("printer [%s] already exists.\n"),
2122 d_fprintf (stderr, _("could not create printer [%s]\n"),
2127 /* close printer handles here */
2128 if (is_valid_policy_hnd(&hnd_src)) {
2129 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2132 if (is_valid_policy_hnd(&hnd_dst)) {
2133 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2137 nt_status = NT_STATUS_OK;
2140 if (is_valid_policy_hnd(&hnd_src))
2141 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2143 if (is_valid_policy_hnd(&hnd_dst))
2144 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2147 cli_shutdown(cli_dst);
2153 * Migrate Printer-Settings from a src server to the dst server
2154 * (for this to work, printers and drivers already have to be migrated earlier)
2156 * All parameters are provided by the run_rpc_command function, except for
2157 * argc, argv which are passed through.
2159 * @param c A net_context structure
2160 * @param domain_sid The domain sid aquired from the remote server
2161 * @param cli A cli_state connected to the server.
2162 * @param mem_ctx Talloc context, destoyed on compleation of the function.
2163 * @param argc Standard main() style argc
2164 * @param argv Standard main() style argv. Initial components are already
2167 * @return Normal NTSTATUS return.
2170 NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c,
2171 const struct dom_sid *domain_sid,
2172 const char *domain_name,
2173 struct cli_state *cli,
2174 struct rpc_pipe_client *pipe_hnd,
2175 TALLOC_CTX *mem_ctx,
2180 /* FIXME: Here the nightmare begins */
2183 NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
2184 uint32_t i = 0, p = 0, j = 0;
2185 uint32_t num_printers;
2187 const char *printername, *sharename;
2188 struct rpc_pipe_client *pipe_hnd_dst = NULL;
2189 struct policy_handle hnd_src, hnd_dst;
2190 union spoolss_PrinterInfo *info_enum;
2191 union spoolss_PrinterInfo info_dst_publish;
2192 union spoolss_PrinterInfo info_dst;
2193 struct cli_state *cli_dst = NULL;
2194 char *devicename = NULL, *unc_name = NULL, *url = NULL;
2195 const char *longname;
2196 const char **keylist = NULL;
2199 ZERO_STRUCT(info_dst_publish);
2201 DEBUG(3,("copying printer settings\n"));
2203 /* connect destination PI_SPOOLSS */
2204 nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst,
2205 &ndr_table_spoolss.syntax_id);
2206 if (!NT_STATUS_IS_OK(nt_status))
2209 /* enum src printers */
2210 if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &info_enum)) {
2211 nt_status = NT_STATUS_UNSUCCESSFUL;
2215 if (!num_printers) {
2216 printf (_("no printers found on server.\n"));
2217 nt_status = NT_STATUS_OK;
2222 /* needed for dns-strings in regkeys */
2223 longname = get_mydnsfullname();
2225 nt_status = NT_STATUS_UNSUCCESSFUL;
2229 /* do something for all printers */
2230 for (i = 0; i < num_printers; i++) {
2232 uint32_t value_offered = 0, value_needed;
2233 uint32_t data_offered = 0, data_needed;
2234 enum winreg_Type type;
2235 uint8_t *buffer = NULL;
2236 const char *value_name = NULL;
2238 /* do some initialization */
2239 printername = info_enum[i].info2.printername;
2240 sharename = info_enum[i].info2.sharename;
2242 if (!printername || !sharename) {
2243 nt_status = NT_STATUS_UNSUCCESSFUL;
2246 /* we can reset NT_STATUS here because we do not
2247 get any real NT_STATUS-codes anymore from now on */
2248 nt_status = NT_STATUS_UNSUCCESSFUL;
2250 d_printf(_("migrating printer settings for: [%s] / [%s]\n"),
2251 printername, sharename);
2254 /* open src printer handle */
2255 if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename,
2256 MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src))
2259 /* open dst printer handle */
2260 if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename,
2261 PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst))
2264 /* check for existing dst printer */
2265 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst,
2270 /* STEP 1: COPY DEVICE-MODE and other
2271 PRINTER_INFO_2-attributes
2274 info_dst.info2 = info_enum[i].info2;
2276 /* why is the port always disconnected when the printer
2277 is correctly installed (incl. driver ???) */
2278 info_dst.info2.portname = SAMBA_PRINTER_PORT_NAME;
2280 /* check if printer is published */
2281 if (info_enum[i].info2.attributes & PRINTER_ATTRIBUTE_PUBLISHED) {
2283 /* check for existing dst printer */
2284 if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 7, &info_dst_publish))
2287 info_dst_publish.info7.action = DSPRINT_PUBLISH;
2289 /* ignore false from setprinter due to WERR_IO_PENDING */
2290 net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 7, &info_dst_publish);
2292 DEBUG(3,("republished printer\n"));
2295 if (info_enum[i].info2.devmode != NULL) {
2297 /* copy devmode (info level 2) */
2298 info_dst.info2.devmode = info_enum[i].info2.devmode;
2300 /* do not copy security descriptor (we have another
2301 * command for that) */
2302 info_dst.info2.secdesc = NULL;
2305 info_dst.info2.devmode.devicename =
2306 talloc_asprintf(mem_ctx, "\\\\%s\\%s",
2307 longname, printername);
2308 if (!info_dst.info2.devmode.devicename) {
2309 nt_status = NT_STATUS_NO_MEMORY;
2313 if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst,
2317 DEBUGADD(1,("\tSetPrinter of DEVICEMODE succeeded\n"));
2320 /* STEP 2: COPY REGISTRY VALUES */
2322 /* please keep in mind that samba parse_spools gives horribly
2323 crippled results when used to rpccli_spoolss_enumprinterdataex
2324 a win2k3-server. (Bugzilla #1851)
2325 FIXME: IIRC I've seen it too on a win2k-server
2328 /* enumerate data on src handle */
2329 nt_status = rpccli_spoolss_EnumPrinterData(pipe_hnd, mem_ctx,
2341 data_offered = data_needed;
2342 value_offered = value_needed;
2343 buffer = talloc_zero_array(mem_ctx, uint8_t, data_needed);
2344 value_name = talloc_zero_array(mem_ctx, char, value_needed);
2346 /* loop for all printerdata of "PrinterDriverData" */
2347 while (NT_STATUS_IS_OK(nt_status) && W_ERROR_IS_OK(result)) {
2349 nt_status = rpccli_spoolss_EnumPrinterData(pipe_hnd, mem_ctx,
2360 /* loop for all reg_keys */
2361 if (NT_STATUS_IS_OK(nt_status) && W_ERROR_IS_OK(result)) {
2364 if (c->opt_verbose) {
2365 struct regval_blob *v;
2367 v = regval_compose(talloc_tos(),
2373 nt_status = NT_STATUS_NO_MEMORY;
2377 display_reg_value(SPOOL_PRINTERDATA_KEY, v);
2382 if (!net_spoolss_setprinterdata(pipe_hnd_dst, mem_ctx,
2383 &hnd_dst, value_name,
2384 type, buffer, data_offered))
2387 DEBUGADD(1,("\tSetPrinterData of [%s] succeeded\n",
2392 /* STEP 3: COPY SUBKEY VALUES */
2394 /* here we need to enum all printer_keys and then work
2395 on the result with enum_printer_key_ex. nt4 does not
2396 respond to enumprinterkey, win2k does, so continue
2397 in case of an error */
2399 if (!net_spoolss_enumprinterkey(pipe_hnd, mem_ctx, &hnd_src, "", &keylist)) {
2400 printf(_("got no key-data\n"));
2405 /* work on a list of printer keys
2406 each key has to be enumerated to get all required
2407 information. information is then set via setprinterdataex-calls */
2409 if (keylist == NULL)
2412 for (i=0; keylist && keylist[i] != NULL; i++) {
2414 const char *subkey = keylist[i];
2416 struct spoolss_PrinterEnumValues *info;
2418 /* enumerate all src subkeys */
2419 if (!net_spoolss_enumprinterdataex(pipe_hnd, mem_ctx, 0,
2425 for (j=0; j < count; j++) {
2427 struct regval_blob *value;
2432 /* although samba replies with sane data in most cases we
2433 should try to avoid writing wrong registry data */
2435 if (strequal(info[j].value_name, SPOOL_REG_PORTNAME) ||
2436 strequal(info[j].value_name, SPOOL_REG_UNCNAME) ||
2437 strequal(info[j].value_name, SPOOL_REG_URL) ||
2438 strequal(info[j].value_name, SPOOL_REG_SHORTSERVERNAME) ||
2439 strequal(info[j].value_name, SPOOL_REG_SERVERNAME)) {
2441 if (strequal(info[j].value_name, SPOOL_REG_PORTNAME)) {
2443 /* although windows uses a multi-sz, we use a sz */
2444 push_reg_sz(mem_ctx, &blob, SAMBA_PRINTER_PORT_NAME);
2447 if (strequal(info[j].value_name, SPOOL_REG_UNCNAME)) {
2449 if (asprintf(&unc_name, "\\\\%s\\%s", longname, sharename) < 0) {
2450 nt_status = NT_STATUS_NO_MEMORY;
2453 push_reg_sz(mem_ctx, &blob, unc_name);
2456 if (strequal(info[j].value_name, SPOOL_REG_URL)) {
2461 /* FIXME: should we really do that ??? */
2462 if (asprintf(&url, "http://%s:631/printers/%s", longname, sharename) < 0) {
2463 nt_status = NT_STATUS_NO_MEMORY;
2466 push_reg_sz(mem_ctx, NULL, &blob, url);
2467 fstrcpy(value.valuename, SPOOL_REG_URL);
2471 if (strequal(info[j].value_name, SPOOL_REG_SERVERNAME)) {
2473 push_reg_sz(mem_ctx, &blob, longname);
2476 if (strequal(info[j].value_name, SPOOL_REG_SHORTSERVERNAME)) {
2478 push_reg_sz(mem_ctx, &blob, global_myname());
2481 value = regval_compose(talloc_tos(),
2484 blob.length == 0 ? NULL : blob.data,
2486 if (value == NULL) {
2487 nt_status = NT_STATUS_NO_MEMORY;
2492 display_reg_value(subkey, value);
2494 /* here we have to set all subkeys on the dst server */
2495 if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst,
2505 struct regval_blob *v;
2507 v = regval_compose(talloc_tos(),
2511 info[j].data->length);
2513 nt_status = NT_STATUS_NO_MEMORY;
2517 if (c->opt_verbose) {
2518 display_reg_value(subkey, v);
2521 /* here we have to set all subkeys on the dst server */
2522 if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst,
2530 DEBUGADD(1,("\tSetPrinterDataEx of key [%s\\%s] succeeded\n",
2531 subkey, info[j].value_name));
2536 TALLOC_FREE(keylist);
2538 /* close printer handles here */
2539 if (is_valid_policy_hnd(&hnd_src)) {
2540 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2543 if (is_valid_policy_hnd(&hnd_dst)) {
2544 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2549 nt_status = NT_STATUS_OK;
2552 SAFE_FREE(devicename);
2554 SAFE_FREE(unc_name);
2556 if (is_valid_policy_hnd(&hnd_src))
2557 rpccli_spoolss_ClosePrinter(pipe_hnd, mem_ctx, &hnd_src, NULL);
2559 if (is_valid_policy_hnd(&hnd_dst))
2560 rpccli_spoolss_ClosePrinter(pipe_hnd_dst, mem_ctx, &hnd_dst, NULL);
2563 cli_shutdown(cli_dst);