From 60727acc3b33cb90309a43c10813fadcb94142eb Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 10 Aug 2004 14:27:17 +0000 Subject: r1692: first commit :) * add IA64 to the architecture table of printer-drivers * add new "net"-subcommands: net rpc printer migrate {drivers|printers|forms|security|settings|all} [printer] net rpc share migrate {shares|files|all} [share] this is the first part of the migration suite. this will will (once feature-complete) allow to do 1:1 server-cloning in the best possible way by making heavy use of samba's rpc_client-functions. all migration-steps are implemented as rpc/smb-client-calls; net communicates via rpc/smb with two servers at the same time (a remote, source server and a destination server that currently defaults to the local smbd). this allows e. g. printer-driver migration including driverfiles, recursive mirroring of file-shares including file-acls, etc. almost any migration step can be called with a migrate-subcommand to provide more flexibility during a migration process (at the cost of quite some redundancy :) ). "net rpc printer migrate settings" is still in a bad condition (many open questions that hopefully can be adressed soon). "net rpc share migrate security" as an isolated call to just migrate share-ACLs will be added later. Before playing with it, make sure to use a test-server. Migration is a serious business and this tool-set can perfectly overwrite your existing file/print-shares. * along with the migration functions had to make I the following changes: - implement setprinter level 3 client-side - implement net_add_share level 502 client-side - allow security descriptor to be set in setprinterdata level 2 serverside guenther (This used to be commit 8f1716a29b7e85baf738bc14df7dabf03762f723) --- source3/utils/net_rpc_printer.c | 2185 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 2185 insertions(+) create mode 100644 source3/utils/net_rpc_printer.c (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c new file mode 100644 index 0000000000..b7d2438df7 --- /dev/null +++ b/source3/utils/net_rpc_printer.c @@ -0,0 +1,2185 @@ +/* + Samba Unix/Linux SMB client library + Distributed SMB/CIFS Server Management Utility + Copyright (C) 2004 Guenther Deschner (gd@samba.org) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include "includes.h" +#include "../utils/net.h" + +struct table_node { + const char *long_archi; + const char *short_archi; + int version; +}; + + +/* support itanium as well */ +static const struct table_node archi_table[]= { + + {"Windows 4.0", "WIN40", 0 }, + {"Windows NT x86", "W32X86", 2 }, + {"Windows NT R4000", "W32MIPS", 2 }, + {"Windows NT Alpha_AXP", "W32ALPHA", 2 }, + {"Windows NT PowerPC", "W32PPC", 2 }, + {"Windows IA64", "IA64", 3 }, + {NULL, "", -1 } +}; + + +/** + * The display-functions for Security-Descriptors were taken from rpcclient + * + * They reside here for debugging purpose and should + * possibly be removed later on + * + **/ +/**************************************************************************** +convert a security permissions into a string +****************************************************************************/ +char *get_sec_mask_str(uint32 type) +{ + static fstring typestr=""; + + typestr[0] = 0; + + if (type & GENERIC_ALL_ACCESS) + fstrcat(typestr, "Generic all access "); + if (type & GENERIC_EXECUTE_ACCESS) + fstrcat(typestr, "Generic execute access "); + if (type & GENERIC_WRITE_ACCESS) + fstrcat(typestr, "Generic write access "); + if (type & GENERIC_READ_ACCESS) + fstrcat(typestr, "Generic read access "); + if (type & MAXIMUM_ALLOWED_ACCESS) + fstrcat(typestr, "MAXIMUM_ALLOWED_ACCESS "); + if (type & SYSTEM_SECURITY_ACCESS) + fstrcat(typestr, "SYSTEM_SECURITY_ACCESS "); + if (type & SYNCHRONIZE_ACCESS) + fstrcat(typestr, "SYNCHRONIZE_ACCESS "); + if (type & WRITE_OWNER_ACCESS) + fstrcat(typestr, "WRITE_OWNER_ACCESS "); + if (type & WRITE_DAC_ACCESS) + fstrcat(typestr, "WRITE_DAC_ACCESS "); + if (type & READ_CONTROL_ACCESS) + fstrcat(typestr, "READ_CONTROL_ACCESS "); + if (type & DELETE_ACCESS) + fstrcat(typestr, "DELETE_ACCESS "); + + printf("\t\tSpecific bits: 0x%lx\n", (unsigned long)type&SPECIFIC_RIGHTS_MASK); + + return typestr; +} + + +/**************************************************************************** + display sec_ace structure + ****************************************************************************/ +void display_sec_ace(SEC_ACE *ace) +{ + fstring sid_str; + + printf("\tACE\n\t\ttype: "); + switch (ace->type) { + case SEC_ACE_TYPE_ACCESS_ALLOWED: + printf("ACCESS ALLOWED"); + break; + case SEC_ACE_TYPE_ACCESS_DENIED: + printf("ACCESS DENIED"); + break; + case SEC_ACE_TYPE_SYSTEM_AUDIT: + printf("SYSTEM AUDIT"); + break; + case SEC_ACE_TYPE_SYSTEM_ALARM: + printf("SYSTEM ALARM"); + break; + default: + printf("????"); + break; + } + printf(" (%d) flags: %d\n", ace->type, ace->flags); + printf("\t\tPermissions: 0x%x: %s\n", ace->info.mask, get_sec_mask_str(ace->info.mask)); + + sid_to_string(sid_str, &ace->trustee); + printf("\t\tSID: %s\n\n", sid_str); +} + + +/**************************************************************************** + display sec_acl structure + ****************************************************************************/ +void display_sec_acl(SEC_ACL *sec_acl) +{ + int i; + + printf("\tACL\tNum ACEs:\t%d\trevision:\t%x\n", + sec_acl->num_aces, sec_acl->revision); + printf("\t---\n"); + + if (sec_acl->size != 0 && sec_acl->num_aces != 0) + for (i = 0; i < sec_acl->num_aces; i++) + display_sec_ace(&sec_acl->ace[i]); + +} + +/**************************************************************************** + display sec_desc structure + ****************************************************************************/ +void display_sec_desc(SEC_DESC *sec) +{ + fstring sid_str; + + if (sec == NULL) + return; + + if (sec->sacl) { + printf("SACL\n"); + display_sec_acl(sec->sacl); + } + + if (sec->dacl) { + printf("DACL\n"); + display_sec_acl(sec->dacl); + } + + if (sec->owner_sid) { + sid_to_string(sid_str, sec->owner_sid); + printf("\tOwner SID:\t%s\n", sid_str); + } + + if (sec->grp_sid) { + sid_to_string(sid_str, sec->grp_sid); + printf("\tParent SID:\t%s\n", sid_str); + } +} + + +/** + * This display-printdriver-functions was borrowed from rpcclient/cmd_spoolss.c. + * It is here for debugging purpose and should be removed later on. + **/ + +/**************************************************************************** +printer info level 3 display function +****************************************************************************/ +static void display_print_driver_3(DRIVER_INFO_3 *i1) +{ + fstring name = ""; + fstring architecture = ""; + fstring driverpath = ""; + fstring datafile = ""; + fstring configfile = ""; + fstring helpfile = ""; + fstring dependentfiles = ""; + fstring monitorname = ""; + fstring defaultdatatype = ""; + + int length=0; + BOOL valid = True; + + if (i1 == NULL) + return; + + rpcstr_pull(name, i1->name.buffer, sizeof(name), -1, STR_TERMINATE); + rpcstr_pull(architecture, i1->architecture.buffer, sizeof(architecture), -1, STR_TERMINATE); + rpcstr_pull(driverpath, i1->driverpath.buffer, sizeof(driverpath), -1, STR_TERMINATE); + rpcstr_pull(datafile, i1->datafile.buffer, sizeof(datafile), -1, STR_TERMINATE); + rpcstr_pull(configfile, i1->configfile.buffer, sizeof(configfile), -1, STR_TERMINATE); + rpcstr_pull(helpfile, i1->helpfile.buffer, sizeof(helpfile), -1, STR_TERMINATE); + rpcstr_pull(monitorname, i1->monitorname.buffer, sizeof(monitorname), -1, STR_TERMINATE); + rpcstr_pull(defaultdatatype, i1->defaultdatatype.buffer, sizeof(defaultdatatype), -1, STR_TERMINATE); + + d_printf ("Printer Driver Info 3:\n"); + d_printf ("\tVersion: [%x]\n", i1->version); + d_printf ("\tDriver Name: [%s]\n",name); + d_printf ("\tArchitecture: [%s]\n", architecture); + d_printf ("\tDriver Path: [%s]\n", driverpath); + d_printf ("\tDatafile: [%s]\n", datafile); + d_printf ("\tConfigfile: [%s]\n", configfile); + d_printf ("\tHelpfile: [%s]\n\n", helpfile); + + while (valid) { + rpcstr_pull(dependentfiles, i1->dependentfiles+length, sizeof(dependentfiles), -1, STR_TERMINATE); + + length+=strlen(dependentfiles)+1; + + if (strlen(dependentfiles) > 0) { + d_printf ("\tDependentfiles: [%s]\n", dependentfiles); + } else { + valid = False; + } + } + + printf ("\n"); + + d_printf ("\tMonitorname: [%s]\n", monitorname); + d_printf ("\tDefaultdatatype: [%s]\n\n", defaultdatatype); + + return; +} + + +static void display_reg_value(pstring subkey, REGISTRY_VALUE value) +{ + pstring text; + + switch(value.type) { + case REG_DWORD: + d_printf("\t[%s:%s]: REG_DWORD: 0x%08x\n", subkey, value.valuename, + *((uint32 *) value.data_p)); + break; + + case REG_SZ: + rpcstr_pull(text, value.data_p, sizeof(text), value.size, + STR_TERMINATE); + d_printf("\t[%s:%s]: REG_SZ: %s\n", subkey, value.valuename, text); + break; + + case REG_BINARY: + d_printf("\t[%s:%s]: REG_BINARY: unknown length value not displayed\n", + subkey, value.valuename); + break; + + case REG_MULTI_SZ: { + uint16 *curstr = (uint16 *) value.data_p; + uint8 *start = value.data_p; + d_printf("\t[%s:%s]: REG_MULTI_SZ:\n", subkey, value.valuename); + while ((*curstr != 0) && + ((uint8 *) curstr < start + value.size)) { + rpcstr_pull(text, curstr, sizeof(text), -1, + STR_TERMINATE); + d_printf("%s\n", text); + curstr += strlen(text) + 1; + } + } + break; + + default: + d_printf("\t%s: unknown type %d\n", value.valuename, value.type); + } + +} + + +/** + * Copy a file or directory from a connected share to another connected share + * + * @param mem_ctx A talloc-context + * @param cli_share_src A connected cli_state + * @param cli_share_dst A connected cli_state + * @param src_file The source file-name + * @param dst_file The destination file-name + * @param copy_acls Whether to copy acls + * @param is_file Whether this file is a file or a dir + * + * @return Normal NTSTATUS return. + **/ +NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, + struct cli_state *cli_share_src, + struct cli_state *cli_share_dst, + char *src_name, char *dst_name, + BOOL copy_acls, BOOL is_file) +{ + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; + int fnum_src = 0; + int fnum_dst = 0; + static int io_bufsize = 64512; + int read_size = io_bufsize; + char *data = NULL; + off_t start = 0; + off_t nread = 0; + SEC_DESC *sd = NULL; + + + /* open on the originating server */ + DEBUGADD(3,("opening %s %s on originating server\n", + is_file ? "file":"dir", src_name)); + + if (is_file) + fnum_src = cli_open(cli_share_src, src_name, + O_RDONLY, DENY_NONE); + else + fnum_src = cli_nt_create(cli_share_src, src_name, + READ_CONTROL_ACCESS); + + if (fnum_src == -1) { + DEBUGADD(0,("cannot open file %s on originating server %s\n", + src_name, cli_errstr(cli_share_src))); + nt_status = cli_nt_error(cli_share_src); + goto out; + } + + /* open on the destination server */ + if (is_file) { + DEBUGADD(3,("opening file %s on destination server\n", dst_name)); + fnum_dst = cli_open(cli_share_dst, dst_name, + O_RDWR|O_CREAT|O_TRUNC, DENY_NONE); + } + + if (fnum_dst == -1) { + DEBUGADD(1,("cannot create file %s on destination server: %s\n", + dst_name, cli_errstr(cli_share_dst))); + nt_status = cli_nt_error(cli_share_dst); + goto out; + } + + + /* allocate memory */ + if (!(data = (char *)malloc(read_size))) { + d_printf("malloc fail for size %d\n", read_size); + goto out; + } + + + if (copy_acls) { + + /* get the security descriptor */ + sd = cli_query_secdesc(cli_share_src, fnum_src, mem_ctx); + if (!sd) { + DEBUG(0, ("failed to get security descriptor\n")); + nt_status = cli_nt_error(cli_share_src); + goto out; + } + } + + /* copying file */ + if (opt_verbose) { + + d_printf("copying [\\\\%s\\%s%s] => [\\\\%s\\%s%s] %s acls.\n", + cli_share_src->desthost, cli_share_src->share, src_name, + cli_share_dst->desthost, cli_share_dst->share, dst_name, + copy_acls ? "with" : "without" ); + + if (DEBUGLEVEL >= 3 && copy_acls) + display_sec_desc(sd); + } + + while (is_file) { + + int n = cli_read(cli_share_src, fnum_src, data, nread + start, + read_size); + + if (n <= 0) + break; + + int ret = cli_write(cli_share_dst, fnum_dst, 0, data, + nread + start, n); + + if (n != ret) { + d_printf("Error writing file: %s\n", + cli_errstr(cli_share_dst)); + nt_status = cli_nt_error(cli_share_dst); + goto out; + } + + nread += n; + } + + /* creating dir */ + if (!is_file && !cli_chkpath(cli_share_dst, dst_name)) { + + DEBUGADD(1,("creating dir %s on the destination server\n", + dst_name)); + + if (!cli_mkdir(cli_share_dst, dst_name)) { + DEBUG(0,("cannot create directory %s: %s\n", + dst_name, cli_errstr(cli_share_dst))); + nt_status = NT_STATUS_NO_SUCH_FILE; + } + + if (!cli_chkpath(cli_share_dst, dst_name)) { + d_printf("cannot check for directory %s: %s\n", + dst_name, cli_errstr(cli_share_dst)); + goto out; + } + } + + + /* closing files */ + if (!cli_close(cli_share_src, fnum_src)) { + d_printf("could not close file on originating server: %s\n", + cli_errstr(cli_share_src)); + nt_status = cli_nt_error(cli_share_src); + goto out; + } + + if (is_file && !cli_close(cli_share_dst, fnum_dst)) { + d_printf("could not close file on destinantion server: %s\n", + cli_errstr(cli_share_dst)); + nt_status = cli_nt_error(cli_share_dst); + goto out; + } + + + /* finally set acls */ + if (copy_acls) { + + /* Open the file/dir a second time */ + fnum_dst = cli_nt_create(cli_share_dst, dst_name, + WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS); + + if (fnum_dst == -1) { + DEBUG(0, ("failed to open file/dir again: %s: %s\n", + dst_name, cli_errstr(cli_share_dst))); + nt_status = cli_nt_error(cli_share_dst); + goto out; + } + + if (!cli_set_secdesc(cli_share_dst, fnum_dst, sd)) { + DEBUG(0, ("could not set secdesc on %s %s: %s\n", + is_file? "file":"dir", dst_name, + cli_errstr(cli_share_dst))); + nt_status = cli_nt_error(cli_share_dst); + goto out; + } + } + + + nt_status = NT_STATUS_OK; + +out: + + /* cleaning up */ + if (fnum_src) + cli_close(cli_share_src, fnum_src); + + if (fnum_dst) + cli_close(cli_share_dst, fnum_dst); + + SAFE_FREE(data); + + return nt_status; +} + + +/** + * Copy a driverfile from on connected share to another connected share + * This silently assumes that a driver-file is picked up from + * + * \\src_server\print$\{arch}\{version}\file + * + * and copied to + * + * \\dst_server\print$\{arch}\file + * + * to be added via setdriver-calls later. + * @param mem_ctx A talloc-context + * @param cli_share_src A cli_state connected to source print$-share + * @param cli_share_dst A cli_state connected to destination print$-share + * @param file The file-name to be copied + * @param short_archi The name of the driver-architecture (short form) + * + * @return Normal NTSTATUS return. + **/ +static NTSTATUS net_copy_driverfile(TALLOC_CTX *mem_ctx, + struct cli_state *cli_share_src, + struct cli_state *cli_share_dst, + char *file, const char *short_archi) { + + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; + const char *p; + char *src_name; + char *dst_name; + fstring version; + fstring filename; + fstring tok; + + /* scroll through the file until we have the part + beyond archi_table.short_archi */ + p = file; + while (next_token(&p, tok, "\\", sizeof(tok))) { + if (strequal(tok, short_archi)) { + next_token(&p, version, "\\", sizeof(version)); + next_token(&p, filename, "\\", sizeof(filename)); + } + } + + /* build source file name */ + if (asprintf(&src_name, "\\%s\\%s\\%s", short_archi, version, filename) < 0 ) + return NT_STATUS_NO_MEMORY; + + + /* create destination file name */ + if (asprintf(&dst_name, "\\%s\\%s", short_archi, filename) < 0 ) + return NT_STATUS_NO_MEMORY; + + + /* finally copy the file */ + nt_status = net_copy_file(mem_ctx, cli_share_src, cli_share_dst, + src_name, dst_name, False, True); + if (!NT_STATUS_IS_OK(nt_status)) + goto out; + + nt_status = NT_STATUS_OK; + +out: + SAFE_FREE(src_name); + SAFE_FREE(dst_name); + + return nt_status; +} + + +/** + * Check for existing Architecture directory on a given server + * + * @param cli_share A cli_state connected to a print$-share + * @param short_archi The Architecture for the print-driver + * + * @return Normal NTSTATUS return. + **/ +static NTSTATUS +check_arch_dir(struct cli_state *cli_share, const char *short_archi) +{ + + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; + char *dir; + + if (asprintf(&dir, "\\%s", short_archi) < 0) { + return NT_STATUS_NO_MEMORY; + } + + DEBUG(10,("creating print-driver dir for architecture: %s\n", + short_archi)); + + if (!cli_mkdir(cli_share, dir)) { + DEBUG(1,("cannot create directory %s: %s\n", + dir, cli_errstr(cli_share))); + nt_status = NT_STATUS_NO_SUCH_FILE; + } + + if (!cli_chkpath(cli_share, dir)) { + d_printf("cannot check %s: %s\n", + dir, cli_errstr(cli_share)); + goto out; + } + + nt_status = NT_STATUS_OK; + +out: + SAFE_FREE(dir); + return nt_status; +} + + +/** + * Copy a print-driver (level 3) from one connected print$-share to another + * connected print$-share + * + * @param mem_ctx A talloc-context + * @param cli_share_src A cli_state connected to a print$-share + * @param cli_share_dst A cli_state connected to a print$-share + * @param short_archi The Architecture for the print-driver + * @param i1 The DRIVER_INFO_3-struct + * + * @return Normal NTSTATUS return. + **/ +static NTSTATUS +copy_print_driver_3(TALLOC_CTX *mem_ctx, + struct cli_state *cli_share_src, + struct cli_state *cli_share_dst, + const char *short_archi, DRIVER_INFO_3 *i1) +{ + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; + int length = 0; + BOOL valid = True; + + fstring name = ""; + fstring driverpath = ""; + fstring datafile = ""; + fstring configfile = ""; + fstring helpfile = ""; + fstring dependentfiles = ""; + + if (i1 == NULL) + return nt_status; + + rpcstr_pull(name, i1->name.buffer, sizeof(name), -1, STR_TERMINATE); + rpcstr_pull(driverpath, i1->driverpath.buffer, sizeof(driverpath), -1, STR_TERMINATE); + rpcstr_pull(datafile, i1->datafile.buffer, sizeof(datafile), -1, STR_TERMINATE); + rpcstr_pull(configfile, i1->configfile.buffer, sizeof(configfile), -1, STR_TERMINATE); + rpcstr_pull(helpfile, i1->helpfile.buffer, sizeof(helpfile), -1, STR_TERMINATE); + + + if (opt_verbose) + d_printf("copying driver: [%s], for architecture: [%s], version: [%d]\n", + name, short_archi, i1->version); + + nt_status = net_copy_driverfile(mem_ctx, cli_share_src, cli_share_dst, + driverpath, short_archi); + if (!NT_STATUS_IS_OK(nt_status)) + return nt_status; + + nt_status = net_copy_driverfile(mem_ctx, cli_share_src, cli_share_dst, + datafile, short_archi); + if (!NT_STATUS_IS_OK(nt_status)) + return nt_status; + + nt_status = net_copy_driverfile(mem_ctx, cli_share_src, cli_share_dst, + configfile, short_archi); + if (!NT_STATUS_IS_OK(nt_status)) + return nt_status; + + nt_status = net_copy_driverfile(mem_ctx, cli_share_src, cli_share_dst, + helpfile, short_archi); + if (!NT_STATUS_IS_OK(nt_status)) + return nt_status; + + while (valid) { + rpcstr_pull(dependentfiles, i1->dependentfiles+length, sizeof(dependentfiles), -1, STR_TERMINATE); + length+=strlen(dependentfiles)+1; + if (strlen(dependentfiles) > 0) { + + nt_status = net_copy_driverfile(mem_ctx, + cli_share_src, cli_share_dst, + dependentfiles, short_archi); + if (!NT_STATUS_IS_OK(nt_status)) + return nt_status; + } else { + valid = False; + } + } + + return NT_STATUS_OK; +} + + +/** + * net_spoolss-functions + * ===================== + * + * the net_spoolss-functions aim to simplify spoolss-client-functions + * required during the migration-process wrt buffer-sizes, returned + * error-codes, etc. + * + * this greatly reduces the complexitiy of the migrate-functions. + * + **/ + +static BOOL +net_spoolss_enum_printers(struct cli_state *cli, TALLOC_CTX *mem_ctx, + char *name, uint32 flags, uint32 level, + uint32 *num_printers, PRINTER_INFO_CTR *ctr) +{ + + WERROR result; + uint32 needed; + + /* enum printers */ + result = cli_spoolss_enum_printers( + cli, mem_ctx, 0, &needed, name, flags, + level, num_printers, ctr); + + if (W_ERROR_V(result) == W_ERROR_V(WERR_INSUFFICIENT_BUFFER)) + result = cli_spoolss_enum_printers( + cli, mem_ctx, needed, NULL, name, flags, + level, num_printers, ctr); + + + if (!W_ERROR_IS_OK(result)) { + printf("cannot enum printers: %s\n", dos_errstr(result)); + return False; + } + + return True; +} + + +static BOOL +net_spoolss_open_printer_ex(struct cli_state *cli, TALLOC_CTX *mem_ctx, + const char *printername, const char *datatype, + uint32 access_required, const char *servername, + const char *username, POLICY_HND *hnd) +{ + WERROR result; + + fstring servername2; + slprintf(servername2, sizeof(servername2)-1, "\\\\%s", cli->desthost); + + DEBUG(10,("connecting to: %s as %s for %s and access: %x\n", + servername2, username, printername, access_required)); + + /* open printer */ + result = cli_spoolss_open_printer_ex(cli, mem_ctx, printername, + "", access_required, + servername2, username, hnd); + + /* be more verbose */ + if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) { + d_printf("no access to printer [%s] on [%s] for user [%s] granted\n", + printername, servername2, username); + return False; + } + + if (!W_ERROR_IS_OK(result)) { + d_printf("cannot open printer %s on server %s: %s\n", + printername, servername2, dos_errstr(result)); + return False; + } + + DEBUG(2,("got printer handle for printer: %s, server: %s\n", + printername, servername2)); + + return True; +} + + +static BOOL +net_spoolss_getprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *hnd, uint32 level, + PRINTER_INFO_CTR *ctr) +{ + WERROR result; + uint32 needed; + + /* getprinter call */ + result = cli_spoolss_getprinter(cli, + mem_ctx, 0, &needed, hnd, level, ctr); + + if (W_ERROR_V(result) == W_ERROR_V(WERR_INSUFFICIENT_BUFFER)) + result = cli_spoolss_getprinter(cli, + mem_ctx, needed, NULL, hnd, level, ctr); + + if (!W_ERROR_IS_OK(result)) { + printf("cannot get printer-info: %s\n", dos_errstr(result)); + return False; + } + + return True; +} + + +static BOOL +net_spoolss_setprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *hnd, uint32 level, + PRINTER_INFO_CTR *ctr) +{ + WERROR result; + + /* setprinter call */ + result = cli_spoolss_setprinter(cli, mem_ctx, hnd, level, ctr, 0); + + if (!W_ERROR_IS_OK(result)) { + printf("cannot set printer-info: %s\n", dos_errstr(result)); + return False; + } + + return True; +} + + +static BOOL +net_spoolss_setprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *hnd, REGISTRY_VALUE *value) +{ + WERROR result; + + /* setprinterdata call */ + result = cli_spoolss_setprinterdata(cli, mem_ctx, hnd, value); + + if (!W_ERROR_IS_OK(result)) { + printf ("unable to set printerdata: %s\n", dos_errstr(result)); + return False; + } + + return True; +} + + +static BOOL +net_spoolss_enumprinterkey(struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *hnd, const char *keyname, + uint16 **keylist) +{ + WERROR result; + uint32 needed, len; + + /* enumprinterkey call */ + result = cli_spoolss_enumprinterkey( + cli, mem_ctx, 0, &needed, hnd, keyname, NULL, NULL); + + if (W_ERROR_V(result) == W_ERROR_V(WERR_MORE_DATA)) + result = cli_spoolss_enumprinterkey( + cli, mem_ctx, needed, NULL, hnd, keyname, keylist, + &len); + + if (!W_ERROR_IS_OK(result)) { + printf("enumprinterkey failed: %s\n", dos_errstr(result)); + return False; + } + + return True; +} + + +static BOOL +net_spoolss_enumprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx, + uint32 offered, + POLICY_HND *hnd, const char *keyname, + REGVAL_CTR *ctr) +{ + WERROR result; + uint32 needed; + + /* enumprinterdataex call */ + result = cli_spoolss_enumprinterdataex( + cli, mem_ctx, 0, &needed, hnd, keyname, NULL); + + if (W_ERROR_V(result) == W_ERROR_V(WERR_MORE_DATA)) + result = cli_spoolss_enumprinterdataex( + cli, mem_ctx, needed, NULL, hnd, keyname, ctr); + + if (!W_ERROR_IS_OK(result)) { + printf("enumprinterdataex failed: %s\n", dos_errstr(result)); + return False; + } + + return True; +} + + +static BOOL +net_spoolss_setprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *hnd, char *keyname, + REGISTRY_VALUE *value) +{ + WERROR result; + + /* setprinterdataex call */ + result = cli_spoolss_setprinterdataex(cli, mem_ctx, hnd, + keyname, value); + + if (!W_ERROR_IS_OK(result)) { + printf("could not set printerdataex: %s\n", dos_errstr(result)); + return False; + } + + return True; +} + + +static BOOL +net_spoolss_enumforms(struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *hnd, int level, uint32 *num_forms, + FORM_1 **forms) + +{ + WERROR result; + uint32 needed; + + /* enumforms call */ + result = cli_spoolss_enumforms( + cli, mem_ctx, 0, &needed, hnd, level, num_forms, forms); + + if (W_ERROR_V(result) == W_ERROR_V(WERR_INSUFFICIENT_BUFFER)) + result = cli_spoolss_enumforms( + cli, mem_ctx, needed, NULL, hnd, level, + num_forms, forms); + + if (!W_ERROR_IS_OK(result)) { + printf("could not enum forms: %s\n", dos_errstr(result)); + return False; + } + + return True; +} + + +static BOOL +net_spoolss_enumprinterdrivers (struct cli_state *cli, TALLOC_CTX *mem_ctx, + uint32 level, const char *env, + uint32 *num_drivers, + PRINTER_DRIVER_CTR *ctr) +{ + WERROR result; + uint32 needed; + + /* enumprinterdrivers call */ + result = cli_spoolss_enumprinterdrivers( + cli, mem_ctx, 0, &needed, level, + env, num_drivers, ctr); + + if (W_ERROR_V(result) == W_ERROR_V(WERR_INSUFFICIENT_BUFFER)) + result = cli_spoolss_enumprinterdrivers( + cli, mem_ctx, needed, NULL, level, + env, num_drivers, ctr); + + if (!W_ERROR_IS_OK(result)) { + printf("cannot enum drivers: %s\n", dos_errstr(result)); + return False; + } + + return True; +} + + +static BOOL +net_spoolss_getprinterdriver(struct cli_state *cli, + TALLOC_CTX *mem_ctx, + POLICY_HND *hnd, uint32 level, + const char *env, int version, + PRINTER_DRIVER_CTR *ctr) +{ + WERROR result; + uint32 needed; + + /* getprinterdriver call */ + result = cli_spoolss_getprinterdriver( + cli, mem_ctx, 0, &needed, hnd, level, + env, version, ctr); + + if (W_ERROR_V(result) == W_ERROR_V(WERR_INSUFFICIENT_BUFFER)) + result = cli_spoolss_getprinterdriver( + cli, mem_ctx, needed, NULL, hnd, level, + env, version, ctr); + + if (!W_ERROR_IS_OK(result)) { + DEBUG(1,("cannot get driver (for architecture: %s): %s\n", + env, dos_errstr(result))); + if (W_ERROR_V(result) != W_ERROR_V(WERR_UNKNOWN_PRINTER_DRIVER)) { + printf("cannot get driver: %s\n", dos_errstr(result)); + } + return False; + } + + return True; +} + + +static BOOL +net_spoolss_addprinterdriver(struct cli_state *cli, + TALLOC_CTX *mem_ctx, uint32 level, + PRINTER_DRIVER_CTR *ctr) +{ + WERROR result; + + /* addprinterdriver call */ + result = cli_spoolss_addprinterdriver(cli, mem_ctx, level, ctr); + + /* be more verbose */ + if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) { + printf("You are not allowed to add drivers\n"); + return False; + } + if (!W_ERROR_IS_OK(result)) { + printf("cannot add driver: %s\n", dos_errstr(result)); + return False; + } + + return True; +} + +/** + * abstraction function to get uint32 num_printers and PRINTER_INFO_CTR ctr + * for a single printer or for all printers depending on argc/argv + **/ +static BOOL +get_printer_info(struct cli_state *cli, TALLOC_CTX *mem_ctx, + int level, int argc, const char **argv, + uint32 *num_printers, PRINTER_INFO_CTR *ctr) +{ + + char *sharename; + fstring servername; + POLICY_HND hnd; + + /* no arguments given, enumerate all printers */ + if (argc == 0) { + + if (!net_spoolss_enum_printers(cli, mem_ctx, NULL, + PRINTER_ENUM_LOCAL|PRINTER_ENUM_SHARED, + level, num_printers, ctr)) + return False; + + goto out; + } + + + /* argument given, get a single printer by name */ + sharename = strdup(argv[0]); + + if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, "", + MAXIMUM_ALLOWED_ACCESS, servername, + cli->user_name, &hnd)) + return False; + + if (!net_spoolss_getprinter(cli, mem_ctx, &hnd, level, ctr)) { + cli_spoolss_close_printer(cli, mem_ctx, &hnd); + return False; + } + + cli_spoolss_close_printer(cli, mem_ctx, &hnd); + + *num_printers = 1; + +out: + DEBUG(3,("got %d printers\n", *num_printers)); + + return True; + +} + + +/** + * List print-queues (including local printers that are not shared) + * + * All parameters are provided by the run_rpc_command function, except for + * argc, argv which are passed through. + * + * @param domain_sid The domain sid aquired from the remote server + * @param cli A cli_state connected to the server. + * @param mem_ctx Talloc context, destoyed on compleation of the function. + * @param argc Standard main() style argc + * @param argv Standard main() style argv. Initial components are already + * stripped + * + * @return Normal NTSTATUS return. + **/ +NTSTATUS rpc_printer_list_internals(const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv) +{ + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; + uint32 i, num_printers; + uint32 level = 2; + pstring printername, sharename; + PRINTER_INFO_CTR ctr; + + printf("listing printers\n"); + + if (!get_printer_info(cli, mem_ctx, level, argc, argv, &num_printers, &ctr)) + return nt_status; + + for (i = 0; i < num_printers; i++) { + + /* do some initialization */ + rpcstr_pull(printername, ctr.printers_2[i].printername.buffer, + sizeof(printername), -1, STR_TERMINATE); + rpcstr_pull(sharename, ctr.printers_2[i].sharename.buffer, + sizeof(sharename), -1, STR_TERMINATE); + + d_printf("printer %d: %s, shared as: %s\n", + i+1, printername, sharename); + } + + return NT_STATUS_OK; +} + + +/** + * List printer-drivers from a server + * + * All parameters are provided by the run_rpc_command function, except for + * argc, argv which are passed through. + * + * @param domain_sid The domain sid aquired from the remote server + * @param cli A cli_state connected to the server. + * @param mem_ctx Talloc context, destoyed on compleation of the function. + * @param argc Standard main() style argc + * @param argv Standard main() style argv. Initial components are already + * stripped + * + * @return Normal NTSTATUS return. + **/ +NTSTATUS rpc_printer_driver_list_internals(const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv) +{ + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; + uint32 i; + uint32 level = 3; + PRINTER_DRIVER_CTR drv_ctr_enum; + int d; + + ZERO_STRUCT(drv_ctr_enum); + + + printf("listing printer-drivers\n"); + + for (i=0; archi_table[i].long_archi!=NULL; i++) { + + int num_drivers; + + /* enum remote drivers */ + if (!net_spoolss_enumprinterdrivers(cli, mem_ctx, level, + archi_table[i].long_archi, + &num_drivers, &drv_ctr_enum)) { + + nt_status = NT_STATUS_UNSUCCESSFUL; + goto done; + } + + if (num_drivers == 0) { + d_printf ("no drivers found on server for architecture: [%s].\n", + archi_table[i].long_archi); + continue; + } + + d_printf("got %d printer-drivers for architecture: [%s]\n", + num_drivers, archi_table[i].long_archi); + + + /* do something for all drivers for architecture */ + for (d = 0; d < num_drivers; d++) { + display_print_driver_3(&(drv_ctr_enum.info3[d])); + } + } + + nt_status = NT_STATUS_OK; + +done: + return nt_status; + +} + + +/** + * Migrate Printer-ACLs from a source server to the destination server + * + * All parameters are provided by the run_rpc_command function, except for + * argc, argv which are passed through. + * + * @param domain_sid The domain sid aquired from the remote server + * @param cli A cli_state connected to the server. + * @param mem_ctx Talloc context, destoyed on compleation of the function. + * @param argc Standard main() style argc + * @param argv Standard main() style argv. Initial components are already + * stripped + * + * @return Normal NTSTATUS return. + **/ +NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv) +{ + /* TODO: what now, info2 or info3 ? + convince jerry that we should add clientside setacls level 3 at least + */ + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; + uint32 i = 0; + uint32 num_printers; + uint32 level = 2; + fstring servername = ""; + pstring printername = "", sharename = ""; + BOOL got_hnd_src = False; + BOOL got_hnd_dst = False; + BOOL got_dst_spoolss_pipe = False; + POLICY_HND hnd_src, hnd_dst; + PRINTER_INFO_CTR ctr_src, ctr_dst, ctr_enum; + struct cli_state *cli_dst = NULL; + + ZERO_STRUCT(ctr_src); + + DEBUG(3,("copying printer ACLs\n")); + + /* connect local PI_SPOOLSS */ + nt_status = connect_local_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + if (!NT_STATUS_IS_OK(nt_status)) + return nt_status; + + + /* enum remote printers */ + if (!get_printer_info(cli, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) { + nt_status = NT_STATUS_UNSUCCESSFUL; + goto done; + } + + if (!num_printers) { + printf ("no printers found on server.\n"); + nt_status = NT_STATUS_OK; + goto done; + } + + + /* do something for all printers */ + for (i = 0; i < num_printers; i++) { + + /* do some initialization */ + rpcstr_pull(printername, ctr_enum.printers_2[i].printername.buffer, + sizeof(printername), -1, STR_TERMINATE); + rpcstr_pull(sharename, ctr_enum.printers_2[i].sharename.buffer, + sizeof(sharename), -1, STR_TERMINATE); + /* we can reset NT_STATUS here because we do not + get any real NT_STATUS-codes anymore from now on */ + nt_status = NT_STATUS_UNSUCCESSFUL; + + d_printf("migrating printer ACLs for: [%s] / [%s]\n", + printername, sharename); + + /* according to msdn you have specify these access-rights + to see the security descriptor + - READ_CONTROL (DACL) + - ACCESS_SYSTEM_SECURITY (SACL) + */ + + /* open src printer handle */ + if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, "", + MAXIMUM_ALLOWED_ACCESS, servername, cli->user_name, &hnd_src)) + goto done; + + got_hnd_src = True; + + + /* open dst printer handle */ + if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, "", + PRINTER_ALL_ACCESS, servername, cli_dst->user_name, &hnd_dst)) + goto done; + + got_hnd_dst = True; + + + /* check for existing dst printer */ + if (!net_spoolss_getprinter(cli_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) + goto done; + + /* check for existing src printer */ + if (!net_spoolss_getprinter(cli, mem_ctx, &hnd_src, 3, &ctr_src)) + goto done; + + + /* Copy Security Descriptor */ + + /* copy secdesc (info level 2) */ + ctr_dst.printers_2->devmode = NULL; + ctr_dst.printers_2->secdesc = dup_sec_desc(mem_ctx, ctr_src.printers_3->secdesc); + + if (opt_verbose) + display_sec_desc(ctr_dst.printers_2->secdesc); + + if (!net_spoolss_setprinter(cli_dst, mem_ctx, &hnd_dst, 2, &ctr_dst)) + goto done; + + DEBUGADD(1,("\tSetPrinter of SECDESC succeeded\n")); + + + /* close printer handles here */ + if (got_hnd_src) { + cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + got_hnd_src = False; + } + + if (got_hnd_dst) { + cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + got_hnd_dst = False; + } + + } + + nt_status = NT_STATUS_OK; + +done: + + if (got_hnd_src) + cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + + if (got_hnd_dst) + cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + + if (got_dst_spoolss_pipe) { + cli_nt_session_close(cli_dst); + cli_shutdown(cli_dst); + } + return nt_status; +} + + +/** + * Migrate printer-forms from a src server to the dst server + * + * All parameters are provided by the run_rpc_command function, except for + * argc, argv which are passed through. + * + * @param domain_sid The domain sid aquired from the remote server + * @param cli A cli_state connected to the server. + * @param mem_ctx Talloc context, destoyed on compleation of the function. + * @param argc Standard main() style argc + * @param argv Standard main() style argv. Initial components are already + * stripped + * + * @return Normal NTSTATUS return. + **/ +NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv) +{ + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; + WERROR result; + uint32 i, f; + uint32 num_printers; + uint32 level = 1; + fstring servername = ""; + pstring printername = "", sharename = ""; + BOOL got_hnd_src = False; + BOOL got_hnd_dst = False; + BOOL got_dst_spoolss_pipe = False; + POLICY_HND hnd_src, hnd_dst; + PRINTER_INFO_CTR ctr_enum, ctr_dst; + uint32 num_forms; + FORM_1 *forms; + struct cli_state *cli_dst = NULL; + + ZERO_STRUCT(ctr_enum); + + DEBUG(3,("copying forms\n")); + + /* connect local PI_SPOOLSS */ + nt_status = connect_local_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + if (!NT_STATUS_IS_OK(nt_status)) + return nt_status; + + + /* enum src printers */ + if (!get_printer_info(cli, mem_ctx, 2, argc, argv, &num_printers, &ctr_enum)) { + nt_status = NT_STATUS_UNSUCCESSFUL; + goto done; + } + + if (!num_printers) { + printf ("no printers found on server.\n"); + nt_status = NT_STATUS_OK; + goto done; + } + + + /* do something for all printers */ + for (i = 0; i < num_printers; i++) { + + /* do some initialization */ + rpcstr_pull(printername, ctr_enum.printers_2[i].printername.buffer, + sizeof(printername), -1, STR_TERMINATE); + rpcstr_pull(sharename, ctr_enum.printers_2[i].sharename.buffer, + sizeof(sharename), -1, STR_TERMINATE); + /* we can reset NT_STATUS here because we do not + get any real NT_STATUS-codes anymore from now on */ + nt_status = NT_STATUS_UNSUCCESSFUL; + + d_printf("migrating printer forms for: [%s] / [%s]\n", + printername, sharename); + + + /* open src printer handle */ + if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, "", + MAXIMUM_ALLOWED_ACCESS, servername, cli->user_name, &hnd_src)) + goto done; + + got_hnd_src = True; + + + /* open dst printer handle */ + if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, "", + PRINTER_ALL_ACCESS, servername, cli->user_name, &hnd_dst)) + goto done; + + got_hnd_dst = True; + + + /* check for existing dst printer */ + if (!net_spoolss_getprinter(cli_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) + goto done; + + /* finally migrate forms */ + if (!net_spoolss_enumforms(cli, mem_ctx, &hnd_src, level, &num_forms, &forms)) + goto done; + + DEBUG(1,("got %d forms for printer\n", num_forms)); + + + for (f = 0; f < num_forms; f++) { + + FORM form; + fstring form_name; + + /* only migrate FORM_PRINTER types, according to jerry + FORM_BUILTIN-types are hard-coded in samba */ + if (forms[f].flag != FORM_PRINTER) + continue; + + if (forms[f].name.buffer) + rpcstr_pull(form_name, forms[f].name.buffer, + sizeof(form_name), -1, STR_TERMINATE); + + if (opt_verbose) + d_printf("\tmigrating form # %d [%s] of type [%d]\n", + f, form_name, forms[f].flag); + + /* is there a more elegant way to do that ? */ + form.flags = FORM_PRINTER; + form.size_x = forms[f].width; + form.size_y = forms[f].length; + form.left = forms[f].left; + form.top = forms[f].top; + form.right = forms[f].right; + form.bottom = forms[f].bottom; + + init_unistr2(&form.name, form_name, UNI_STR_TERMINATE); + + /* FIXME: there might be something wrong with samba's + builtin-forms */ + result = cli_spoolss_addform(cli_dst, mem_ctx, + &hnd_dst, 1, &form); + if (!W_ERROR_IS_OK(result)) { + d_printf("\tAddForm form %d: [%s] refused.\n", + f, form_name); + continue; + } + + DEBUGADD(1,("\tAddForm of [%s] succeeded\n", form_name)); + } + + + /* close printer handles here */ + if (got_hnd_src) { + cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + got_hnd_src = False; + } + + if (got_hnd_dst) { + cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + got_hnd_dst = False; + } + } + + nt_status = NT_STATUS_OK; + +done: + + if (got_hnd_src) + cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + + if (got_hnd_dst) + cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + + if (got_dst_spoolss_pipe) { + cli_nt_session_close(cli_dst); + cli_shutdown(cli_dst); + } + return nt_status; + +} + + +/** + * Migrate printer-drivers from a src server to the dst server + * + * All parameters are provided by the run_rpc_command function, except for + * argc, argv which are passed through. + * + * @param domain_sid The domain sid aquired from the remote server + * @param cli A cli_state connected to the server. + * @param mem_ctx Talloc context, destoyed on compleation of the function. + * @param argc Standard main() style argc + * @param argv Standard main() style argv. Initial components are already + * stripped + * + * @return Normal NTSTATUS return. + **/ +NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv) +{ + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; + uint32 i, p; + uint32 num_printers; + uint32 level = 3; + fstring servername = ""; + pstring printername = "", sharename = ""; + BOOL got_hnd_src = False; + BOOL got_hnd_dst = False; + BOOL got_dst_spoolss_pipe = False; + BOOL got_src_driver_share = False; + BOOL got_dst_driver_share = False; + POLICY_HND hnd_src, hnd_dst; + PRINTER_DRIVER_CTR drv_ctr_src, drv_ctr_dst; + PRINTER_INFO_CTR info_ctr_enum, info_ctr_dst; + struct cli_state *cli_dst = NULL; + struct cli_state *cli_share_src = NULL; + struct cli_state *cli_share_dst = NULL; + fstring drivername = ""; + + ZERO_STRUCT(drv_ctr_src); + ZERO_STRUCT(drv_ctr_dst); + ZERO_STRUCT(info_ctr_enum); + ZERO_STRUCT(info_ctr_dst); + + + DEBUG(3,("copying printer-drivers\n")); + + nt_status = connect_local_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + if (!NT_STATUS_IS_OK(nt_status)) + return nt_status; + + + /* open print$-share on the src server */ + nt_status = connect_to_service(&cli_share_src, &cli->dest_ip, + cli->desthost, "print$", "A:"); + if (!NT_STATUS_IS_OK(nt_status)) + return nt_status; + + got_src_driver_share = True; + + + /* open print$-share on the dst server */ + nt_status = connect_to_service(&cli_share_dst, &cli_dst->dest_ip, + cli_dst->desthost, "print$", "A:"); + if (!NT_STATUS_IS_OK(nt_status)) + return nt_status; + + got_dst_driver_share = True; + + + /* enum src printers */ + if (!get_printer_info(cli, mem_ctx, 2, argc, argv, &num_printers, &info_ctr_enum)) { + nt_status = NT_STATUS_UNSUCCESSFUL; + goto done; + } + + if (!num_printers) { + printf ("no printers found on server.\n"); + nt_status = NT_STATUS_OK; + goto done; + } + + + /* do something for all printers */ + for (p = 0; p < num_printers; p++) { + + /* do some initialization */ + rpcstr_pull(printername, info_ctr_enum.printers_2[p].printername.buffer, + sizeof(printername), -1, STR_TERMINATE); + rpcstr_pull(sharename, info_ctr_enum.printers_2[p].sharename.buffer, + sizeof(sharename), -1, STR_TERMINATE); + /* we can reset NT_STATUS here because we do not + get any real NT_STATUS-codes anymore from now on */ + nt_status = NT_STATUS_UNSUCCESSFUL; + + d_printf("migrating printer driver for: [%s] / [%s]\n", + printername, sharename); + + /* open dst printer handle */ + if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, "", + PRINTER_ALL_ACCESS, servername, cli->user_name, &hnd_dst)) + goto done; + + got_hnd_dst = True; + + /* check for existing dst printer */ + if (!net_spoolss_getprinter(cli_dst, mem_ctx, &hnd_dst, 2, &info_ctr_dst)) + goto done; + + + /* open src printer handle */ + if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, "", + MAXIMUM_ALLOWED_ACCESS, servername, cli->user_name, &hnd_src)) + goto done; + + got_hnd_src = True; + + + /* in a first step call getdriver for each shared printer (per arch) + to get a list of all files that have to be copied */ + + for (i=0; archi_table[i].long_archi!=NULL; i++) { + + /* getdriver src */ + if (!net_spoolss_getprinterdriver(cli, mem_ctx, &hnd_src, + level, archi_table[i].long_archi, + archi_table[i].version, &drv_ctr_src)) + continue; + + rpcstr_pull(drivername, drv_ctr_src.info3->name.buffer, + sizeof(drivername), -1, STR_TERMINATE); + + if (opt_verbose) + display_print_driver_3(drv_ctr_src.info3); + + + /* check arch dir */ + nt_status = check_arch_dir(cli_share_dst, archi_table[i].short_archi); + if (!NT_STATUS_IS_OK(nt_status)) + goto done; + + + /* copy driver-files */ + nt_status = copy_print_driver_3(mem_ctx, cli_share_src, cli_share_dst, + archi_table[i].short_archi, + drv_ctr_src.info3); + if (!NT_STATUS_IS_OK(nt_status)) + goto done; + + + /* adddriver dst */ + if (!net_spoolss_addprinterdriver(cli_dst, mem_ctx, level, &drv_ctr_src)) { + nt_status = NT_STATUS_UNSUCCESSFUL; + goto done; + } + + DEBUGADD(1,("Sucessfully added driver [%s] for printer [%s]\n", + drivername, printername)); + + } + + /* setdriver dst */ + init_unistr(&info_ctr_dst.printers_2->drivername, drivername); + + if (!net_spoolss_setprinter(cli_dst, mem_ctx, &hnd_dst, 2, &info_ctr_dst)) { + nt_status = NT_STATUS_UNSUCCESSFUL; + goto done; + } + + DEBUGADD(1,("Sucessfully set driver %s for printer %s\n", + drivername, printername)); + + /* close dst */ + if (got_hnd_dst) { + cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + got_hnd_dst = False; + } + + /* close src */ + if (got_hnd_src) { + cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + got_hnd_src = False; + } + } + + nt_status = NT_STATUS_OK; + +done: + + if (got_hnd_src) + cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + + if (got_hnd_dst) + cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + + if (got_dst_spoolss_pipe) { + cli_nt_session_close(cli_dst); + cli_shutdown(cli_dst); + } + + if (got_src_driver_share) + cli_shutdown(cli_share_src); + + if (got_dst_driver_share) + cli_shutdown(cli_share_dst); + + return nt_status; + +} + + +/** + * Migrate printer-queues from a src to the dst server + * (requires a working "addprinter command" to be installed for the local smbd) + * + * All parameters are provided by the run_rpc_command function, except for + * argc, argv which are passed through. + * + * @param domain_sid The domain sid aquired from the remote server + * @param cli A cli_state connected to the server. + * @param mem_ctx Talloc context, destoyed on compleation of the function. + * @param argc Standard main() style argc + * @param argv Standard main() style argv. Initial components are already + * stripped + * + * @return Normal NTSTATUS return. + **/ +NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv) +{ + WERROR result; + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; + uint32 i = 0, num_printers; + uint32 level = 2; + PRINTER_INFO_CTR ctr_src, ctr_dst, ctr_enum; + struct cli_state *cli_dst = NULL; + POLICY_HND hnd_dst, hnd_src; + pstring printername, sharename; + fstring servername; + BOOL got_hnd_src = False; + BOOL got_hnd_dst = False; + BOOL got_dst_spoolss_pipe = False; + + DEBUG(3,("copying printers\n")); + + /* connect local PI_SPOOLSS */ + nt_status = connect_local_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + if (!NT_STATUS_IS_OK(nt_status)) + return nt_status; + + + /* enum printers */ + if (!get_printer_info(cli, mem_ctx, 2, argc, argv, &num_printers, &ctr_enum)) { + nt_status = NT_STATUS_UNSUCCESSFUL; + goto done; + } + + if (!num_printers) { + printf ("no printers found on server.\n"); + nt_status = NT_STATUS_OK; + goto done; + } + + + /* do something for all printers */ + for (i = 0; i < num_printers; i++) { + + /* do some initialization */ + rpcstr_pull(printername, ctr_enum.printers_2[i].printername.buffer, + sizeof(printername), -1, STR_TERMINATE); + rpcstr_pull(sharename, ctr_enum.printers_2[i].sharename.buffer, + sizeof(sharename), -1, STR_TERMINATE); + /* we can reset NT_STATUS here because we do not + get any real NT_STATUS-codes anymore from now on */ + nt_status = NT_STATUS_UNSUCCESSFUL; + + d_printf("migrating printer queue for: [%s] / [%s]\n", + printername, sharename); + + + /* open dst printer handle */ + if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, "", + PRINTER_ALL_ACCESS, servername, cli->user_name, &hnd_dst)) { + + DEBUG(1,("could not open printer: %s\n", sharename)); + } else { + got_hnd_dst = True; + } + + + /* check for existing dst printer */ + if (!net_spoolss_getprinter(cli_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) { + printf ("could not get printer, creating printer.\n"); + } else { + DEBUG(1,("printer already exists: %s\n", sharename)); + /* close printer handles here */ + if (got_hnd_src) { + cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + got_hnd_src = False; + } + + if (got_hnd_dst) { + cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + got_hnd_dst = False; + } + continue; + } + + + /* now get again src printer ctr via getprinter, + we first need a handle for that */ + + /* open src printer handle */ + if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, "", + MAXIMUM_ALLOWED_ACCESS, servername, cli->user_name, &hnd_src)) + goto done; + + got_hnd_src = True; + + /* getprinter on the src server */ + if (!net_spoolss_getprinter(cli, mem_ctx, &hnd_src, level, &ctr_src)) + goto done; + + + /* copy each src printer to a dst printer 1:1, + maybe some values have to be changed though */ + d_printf("creating printer: %s\n", printername); + result = cli_spoolss_addprinterex (cli_dst, mem_ctx, level, &ctr_src); + + if (W_ERROR_IS_OK(result)) + d_printf ("printer [%s] successfully added.\n", printername); + else if (W_ERROR_V(result) == W_ERROR_V(WERR_PRINTER_ALREADY_EXISTS)) + d_printf ("printer [%s] already exists.\n", printername); + else { + printf ("could not create printer\n"); + goto done; + } + + /* close printer handles here */ + if (got_hnd_src) { + cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + got_hnd_src = False; + } + + if (got_hnd_dst) { + cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + got_hnd_dst = False; + } + } + + nt_status = NT_STATUS_OK; + +done: + if (got_hnd_src) + cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + + if (got_hnd_dst) + cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + + if (got_dst_spoolss_pipe) { + cli_nt_session_close(cli_dst); + cli_shutdown(cli_dst); + } + return nt_status; +} + + +/** + * Migrate Printer-Settings from a src server to the dst server + * (for this to work, printers and drivers already have to be migrated earlier) + * + * All parameters are provided by the run_rpc_command function, except for + * argc, argv which are passed through. + * + * @param domain_sid The domain sid aquired from the remote server + * @param cli A cli_state connected to the server. + * @param mem_ctx Talloc context, destoyed on compleation of the function. + * @param argc Standard main() style argc + * @param argv Standard main() style argv. Initial components are already + * stripped + * + * @return Normal NTSTATUS return. + **/ +NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv) +{ + + /* FIXME: Here the nightmare begins */ + + WERROR result; + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; + uint32 i = 0, p = 0, j = 0; + uint32 num_printers, val_needed, data_needed; + uint32 level = 2; + fstring servername = ""; + pstring printername = "", sharename = ""; + BOOL got_hnd_src = False; + BOOL got_hnd_dst = False; + BOOL got_dst_spoolss_pipe = False; + POLICY_HND hnd_src, hnd_dst; + PRINTER_INFO_CTR ctr_enum, ctr_dst; + REGVAL_CTR reg_ctr; + struct cli_state *cli_dst = NULL; + char *devicename = NULL, *unc_name = NULL, *url = NULL; + fstring longname; + + const char *keyname = NULL; + uint16 *keylist = NULL, *curkey; + + ZERO_STRUCT(ctr_enum); + + DEBUG(3,("copying printer settings\n")); + + /* connect local PI_SPOOLSS */ + nt_status = connect_local_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + if (!NT_STATUS_IS_OK(nt_status)) + return nt_status; + + + /* enum src printers */ + if (!get_printer_info(cli, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) { + nt_status = NT_STATUS_UNSUCCESSFUL; + goto done; + } + + if (!num_printers) { + printf ("no printers found on server.\n"); + nt_status = NT_STATUS_OK; + goto done; + } + + + /* needed for dns-strings in regkeys */ + get_mydnsfullname(longname); + + /* do something for all printers */ + for (i = 0; i < num_printers; i++) { + + /* do some initialization */ + rpcstr_pull(printername, ctr_enum.printers_2[i].printername.buffer, + sizeof(printername), -1, STR_TERMINATE); + rpcstr_pull(sharename, ctr_enum.printers_2[i].sharename.buffer, + sizeof(sharename), -1, STR_TERMINATE); + keyname = ""; + /* we can reset NT_STATUS here because we do not + get any real NT_STATUS-codes anymore from now on */ + nt_status = NT_STATUS_UNSUCCESSFUL; + + d_printf("migrating printer settings for: [%s] / [%s]\n", + printername, sharename); + + + /* open src printer handle */ + if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, "", + MAXIMUM_ALLOWED_ACCESS, servername, cli->user_name, &hnd_src)) + goto done; + + got_hnd_src = True; + + + /* open dst printer handle */ + if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, "", + PRINTER_ALL_ACCESS, servername, cli_dst->user_name, &hnd_dst)) + goto done; + + got_hnd_dst = True; + + + /* check for existing dst printer */ + if (!net_spoolss_getprinter(cli_dst, mem_ctx, &hnd_dst, + level, &ctr_dst)) + goto done; + + + /* STEP 1: COPY DEVICE-MODE and other + PRINTER_INFO_2-attributes + */ + + ctr_dst.printers_2 = &ctr_enum.printers_2[i]; + + /* why is the port always disconnected when the printer + is correctly installed (incl. driver ???) */ + init_unistr( &ctr_dst.printers_2->portname, SAMBA_PRINTER_PORT_NAME); + + /* copy devmode (info level 2) */ + ctr_dst.printers_2->devmode = talloc_memdup(mem_ctx, + ctr_enum.printers_2[i].devmode, sizeof(DEVICEMODE)); + + /* do not copy security descriptor (we have another command for that) */ + ctr_dst.printers_2->secdesc = NULL; + + + /* devmode->devicename is possibly broken at the moment for all + strlen(longprinternames) > MAXDEVICENAME (that is 32 chars) + this fires up thousands of safe_strncpy-debug0-messages + on my test-servers + TODO: tell jerry, jra, etc. again. + */ + +#if 0 + if (asprintf(&devicename, "\\\\%s\\%s", longname, printername) < 0) { + nt_status = NT_STATUS_NO_MEMORY; + goto done; + } + + init_unistr(&ctr_dst.printers_2->devmode->devicename, devicename); +#endif + if (!net_spoolss_setprinter(cli_dst, mem_ctx, &hnd_dst, + level, &ctr_dst)) + goto done; + + DEBUGADD(1,("\tSetPrinter of DEVICEMODE succeeded\n")); + + + + /* STEP 2: COPY REGISTRY VALUES */ + + /* please keep in mind that samba parse_spools gives horribly + crippled results when used to cli_spoolss_enumprinterdataex + a win2k3-server. + FIXME: IIRC I've seen it too on a win2k-server + */ + + /* enumerate data on src handle */ + result = cli_spoolss_enumprinterdata(cli, mem_ctx, &hnd_src, p, 0, 0, + &val_needed, &data_needed, NULL); + + /* loop for all printerdata */ + while (W_ERROR_IS_OK(result)) { + + REGISTRY_VALUE value; + + result = cli_spoolss_enumprinterdata( + cli, mem_ctx, &hnd_src, p++, val_needed, + data_needed, 0, 0, &value); + + /* loop for all reg_keys */ + if (W_ERROR_IS_OK(result)) { + + /* display_value */ + if (opt_verbose) + display_reg_value(NULL, value); + + /* set_value */ + if (!net_spoolss_setprinterdata(cli_dst, mem_ctx, + &hnd_dst, &value)) + goto done; + + DEBUGADD(1,("\tSetPrinterData of [%s] succeeded\n", + value.valuename)); + } + } + + /* STEP 3: COPY SUBKEY VALUES */ + + /* here we need to enum all printer_keys and then work + on the result with enum_printer_key_ex. nt4 does not + respond to enumprinterkey, win2k does, so continue + in case of an error */ + + if (!net_spoolss_enumprinterkey(cli, mem_ctx, &hnd_src, keyname, &keylist)) { + printf("got no key-data\n"); + continue; + } + + + /* work on a list of printer keys + each key has to be enumerated to get all required + information. information is then set via setprinterdataex-calls */ + + if (keylist == NULL) + continue; + + curkey = keylist; + while (*curkey != 0) { + + pstring subkey; + rpcstr_pull(subkey, curkey, sizeof(subkey), -1, STR_TERMINATE); + + curkey += strlen(subkey) + 1; + + /* enumerate all src subkeys */ + if (!net_spoolss_enumprinterdataex(cli, mem_ctx, 0, + &hnd_src, subkey, + ®_ctr)) + goto done; + + for (j=0; j < reg_ctr.num_values; j++) { + + REGISTRY_VALUE value; + UNISTR2 data; + + /* although samba replies with sane data in most cases we + should try to avoid writing wrong registry data */ + + if (strequal(reg_ctr.values[j]->valuename, SPOOL_REG_PORTNAME) || + strequal(reg_ctr.values[j]->valuename, SPOOL_REG_UNCNAME) || + strequal(reg_ctr.values[j]->valuename, SPOOL_REG_URL) || + strequal(reg_ctr.values[j]->valuename, SPOOL_REG_SHORTSERVERNAME) || + strequal(reg_ctr.values[j]->valuename, SPOOL_REG_SERVERNAME)) { + + if (strequal(reg_ctr.values[j]->valuename, SPOOL_REG_PORTNAME)) { + + /* although windows uses a multi-sz, we use a sz */ + init_unistr2(&data, SAMBA_PRINTER_PORT_NAME, UNI_STR_TERMINATE); + fstrcpy(value.valuename, SPOOL_REG_PORTNAME); + } + + if (strequal(reg_ctr.values[j]->valuename, SPOOL_REG_UNCNAME)) { + + if (asprintf(&unc_name, "\\\\%s\\%s", longname, sharename) < 0) { + nt_status = NT_STATUS_NO_MEMORY; + goto done; + } + init_unistr2(&data, unc_name, UNI_STR_TERMINATE); + fstrcpy(value.valuename, SPOOL_REG_UNCNAME); + } + + if (strequal(reg_ctr.values[j]->valuename, SPOOL_REG_URL)) { + + continue; + +#if 0 + /* FIXME: should we really do that ??? */ + if (asprintf(&url, "http://%s:631/printers/%s", longname, sharename) < 0) { + nt_status = NT_STATUS_NO_MEMORY; + goto done; + } + init_unistr2(&data, url, UNI_STR_TERMINATE); + fstrcpy(value.valuename, SPOOL_REG_URL); +#endif + } + + if (strequal(reg_ctr.values[j]->valuename, SPOOL_REG_SERVERNAME)) { + + init_unistr2(&data, longname, UNI_STR_TERMINATE); + fstrcpy(value.valuename, SPOOL_REG_SERVERNAME); + } + + if (strequal(reg_ctr.values[j]->valuename, SPOOL_REG_SHORTSERVERNAME)) { + + init_unistr2(&data, global_myname(), UNI_STR_TERMINATE); + fstrcpy(value.valuename, SPOOL_REG_SHORTSERVERNAME); + } + + value.type = REG_SZ; + value.size = data.uni_str_len * 2; + value.data_p = talloc_memdup(mem_ctx, data.buffer, value.size); + + if (opt_verbose) + display_reg_value(subkey, value); + + /* here we have to set all subkeys on the dst server */ + if (!net_spoolss_setprinterdataex(cli_dst, mem_ctx, &hnd_dst, + subkey, &value)) + goto done; + + } else { + + if (opt_verbose) + display_reg_value(subkey, *(reg_ctr.values[j])); + + /* here we have to set all subkeys on the dst server */ + if (!net_spoolss_setprinterdataex(cli_dst, mem_ctx, &hnd_dst, + subkey, reg_ctr.values[j])) + goto done; + + } + + DEBUGADD(1,("\tSetPrinterDataEx of key [%s\\%s] succeeded\n", + subkey, reg_ctr.values[j]->valuename)); + + } + + regval_ctr_destroy(®_ctr); + } + + safe_free(keylist); + + /* close printer handles here */ + if (got_hnd_src) { + cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + got_hnd_src = False; + } + + if (got_hnd_dst) { + cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + got_hnd_dst = False; + } + + } + + nt_status = NT_STATUS_OK; + +done: + SAFE_FREE(devicename); + SAFE_FREE(url); + SAFE_FREE(unc_name); + + if (got_hnd_src) + cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + + if (got_hnd_dst) + cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + + if (got_dst_spoolss_pipe) { + cli_nt_session_close(cli_dst); + cli_shutdown(cli_dst); + } + return nt_status; +} -- cgit From 61b9639ac7fbefc963de74f371186183cd0e3306 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 10 Aug 2004 16:42:58 +0000 Subject: r1698: fix build. guenther (This used to be commit 925e28d0cbd9667bceb0762ef1e429735250c209) --- source3/utils/net_rpc_printer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index b7d2438df7..e4197d72ce 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -369,13 +369,14 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, while (is_file) { - int n = cli_read(cli_share_src, fnum_src, data, nread + start, + int n, ret; + n = cli_read(cli_share_src, fnum_src, data, nread + start, read_size); if (n <= 0) break; - int ret = cli_write(cli_share_dst, fnum_dst, 0, data, + ret = cli_write(cli_share_dst, fnum_dst, 0, data, nread + start, n); if (n != ret) { -- cgit From 19e949a91ba342ec1de2c01e5bfddf8392cb68b5 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 20 Aug 2004 20:13:05 +0000 Subject: r1966: further work on and cleanup of the net-migration-tool. It's now possible to migrate files preserving dos-attributes and correct timestamps. Also added some small docu- and syntax-fixes. Guenther (This used to be commit 0e990582a0416933a8671ca660d22e980f828402) --- source3/utils/net_rpc_printer.c | 103 ++++++++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 31 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index e4197d72ce..7684878677 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -283,6 +283,8 @@ static void display_reg_value(pstring subkey, REGISTRY_VALUE value) * @param src_file The source file-name * @param dst_file The destination file-name * @param copy_acls Whether to copy acls + * @param copy_attrs Whether to copy DOS attributes + * @param copy_timestamps Whether to preserve timestamps * @param is_file Whether this file is a file or a dir * * @return Normal NTSTATUS return. @@ -291,7 +293,8 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, struct cli_state *cli_share_src, struct cli_state *cli_share_dst, char *src_name, char *dst_name, - BOOL copy_acls, BOOL is_file) + BOOL copy_acls, BOOL copy_attrs, + BOOL copy_timestamps, BOOL is_file) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; int fnum_src = 0; @@ -302,6 +305,8 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, off_t start = 0; off_t nread = 0; SEC_DESC *sd = NULL; + uint16 attr; + time_t atime, ctime, mtime; /* open on the originating server */ @@ -349,7 +354,20 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, /* get the security descriptor */ sd = cli_query_secdesc(cli_share_src, fnum_src, mem_ctx); if (!sd) { - DEBUG(0, ("failed to get security descriptor\n")); + DEBUG(0, ("failed to get security descriptor: %s\n", + cli_errstr(cli_share_src))); + nt_status = cli_nt_error(cli_share_src); + goto out; + } + } + + if (copy_attrs || copy_timestamps) { + + /* get dos attributes */ + if (!cli_getattrE(cli_share_src, fnum_src, &attr, NULL, + &ctime, &atime, &mtime)) { + DEBUG(0, ("failed to get file-attrs: %s\n", + cli_errstr(cli_share_src))); nt_status = cli_nt_error(cli_share_src); goto out; } @@ -358,10 +376,13 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, /* copying file */ if (opt_verbose) { - d_printf("copying [\\\\%s\\%s%s] => [\\\\%s\\%s%s] %s acls.\n", - cli_share_src->desthost, cli_share_src->share, src_name, + d_printf("copying [\\\\%s\\%s%s] => [\\\\%s\\%s%s] " + "%s acls and %s DOS Attributes %s\n", + cli_share_src->desthost, cli_share_src->share, src_name, cli_share_dst->desthost, cli_share_dst->share, dst_name, - copy_acls ? "with" : "without" ); + copy_acls ? "with" : "without", + copy_attrs ? "with" : "without", + copy_timestamps ? "(preserving timestamps)" : "" ); if (DEBUGLEVEL >= 3 && copy_acls) display_sec_desc(sd); @@ -392,7 +413,7 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, /* creating dir */ if (!is_file && !cli_chkpath(cli_share_dst, dst_name)) { - DEBUGADD(1,("creating dir %s on the destination server\n", + DEBUGADD(3,("creating dir %s on the destination server\n", dst_name)); if (!cli_mkdir(cli_share_dst, dst_name)) { @@ -408,47 +429,67 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, } } - - /* closing files */ - if (!cli_close(cli_share_src, fnum_src)) { - d_printf("could not close file on originating server: %s\n", - cli_errstr(cli_share_src)); - nt_status = cli_nt_error(cli_share_src); - goto out; - } - - if (is_file && !cli_close(cli_share_dst, fnum_dst)) { - d_printf("could not close file on destinantion server: %s\n", - cli_errstr(cli_share_dst)); + /* open the file/dir a second time */ + fnum_dst = cli_nt_create(cli_share_dst, dst_name, + WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS); + + if (fnum_dst == -1) { + DEBUG(0,("failed to open file/dir again: %s: %s\n", + dst_name, cli_errstr(cli_share_dst))); nt_status = cli_nt_error(cli_share_dst); goto out; } + /* set timestamps */ + if (copy_timestamps) { + + if (!cli_setattrE(cli_share_dst, fnum_dst, ctime, atime, mtime)) { + DEBUG(0,("failed to set file-attrs (timestamps): %s\n", + cli_errstr(cli_share_dst))); + nt_status = cli_nt_error(cli_share_dst); + goto out; + } + } - /* finally set acls */ + /* set acls */ if (copy_acls) { - /* Open the file/dir a second time */ - fnum_dst = cli_nt_create(cli_share_dst, dst_name, - WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS); - - if (fnum_dst == -1) { - DEBUG(0, ("failed to open file/dir again: %s: %s\n", - dst_name, cli_errstr(cli_share_dst))); + if (!cli_set_secdesc(cli_share_dst, fnum_dst, sd)) { + DEBUG(0,("could not set secdesc on %s %s: %s\n", + is_file? "file":"dir", dst_name, + cli_errstr(cli_share_dst))); nt_status = cli_nt_error(cli_share_dst); goto out; } + } - if (!cli_set_secdesc(cli_share_dst, fnum_dst, sd)) { - DEBUG(0, ("could not set secdesc on %s %s: %s\n", - is_file? "file":"dir", dst_name, + /* set attrs */ + if (copy_attrs) { + + if (!cli_setatr(cli_share_dst, dst_name, attr, 0)) { + DEBUG(0,("failed to set file-attrs: %s\n", cli_errstr(cli_share_dst))); nt_status = cli_nt_error(cli_share_dst); goto out; } } - + /* closing files */ + if (!cli_close(cli_share_src, fnum_src)) { + d_printf("could not close file on originating server: %s\n", + cli_errstr(cli_share_src)); + nt_status = cli_nt_error(cli_share_src); + goto out; + } + + if (is_file && !cli_close(cli_share_dst, fnum_dst)) { + d_printf("could not close file on destination server: %s\n", + cli_errstr(cli_share_dst)); + nt_status = cli_nt_error(cli_share_dst); + goto out; + } + + nt_status = NT_STATUS_OK; out: @@ -520,7 +561,7 @@ static NTSTATUS net_copy_driverfile(TALLOC_CTX *mem_ctx, /* finally copy the file */ nt_status = net_copy_file(mem_ctx, cli_share_src, cli_share_dst, - src_name, dst_name, False, True); + src_name, dst_name, False, False, False, True); if (!NT_STATUS_IS_OK(nt_status)) goto out; -- cgit From c542a2c17956c9e9e49d2aecdb8fd06f589bb8c9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 24 Aug 2004 20:52:56 +0000 Subject: r2022: Add net_copy_fileattr as a separate function to copy just ACLs, attrs and timestamps. This makes net_copy_file less complex. Guenther (This used to be commit 43af9e67dd7c0328f214def4b591041e9b69614a) --- source3/utils/net_rpc_printer.c | 299 ++++++++++++++++++++++++++-------------- 1 file changed, 198 insertions(+), 101 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 7684878677..d43b2ed94c 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -274,6 +274,161 @@ static void display_reg_value(pstring subkey, REGISTRY_VALUE value) } +/** + * Copies ACLs, DOS-attributes and timestamps from one + * file or directory from one connected share to another connected share + * + * @param mem_ctx A talloc-context + * @param cli_share_src A connected cli_state + * @param cli_share_dst A connected cli_state + * @param src_file The source file-name + * @param dst_file The destination file-name + * @param copy_acls Whether to copy acls + * @param copy_attrs Whether to copy DOS attributes + * @param copy_timestamps Whether to preserve timestamps + * @param is_file Whether this file is a file or a dir + * + * @return Normal NTSTATUS return. + **/ +static NTSTATUS +net_copy_fileattr(TALLOC_CTX *mem_ctx, + struct cli_state *cli_share_src, + struct cli_state *cli_share_dst, + char *src_name, char *dst_name, + BOOL copy_acls, BOOL copy_attrs, + BOOL copy_timestamps, BOOL is_file) +{ + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; + int fnum_src = 0; + int fnum_dst = 0; + SEC_DESC *sd = NULL; + uint16 attr; + time_t atime, ctime, mtime; + + + if (!copy_timestamps && !copy_acls && !copy_attrs) + return NT_STATUS_OK; + + + /* open file/dir on the originating server */ + + DEBUGADD(3,("opening %s %s on originating server\n", + is_file?"file":"dir", src_name)); + + fnum_src = cli_nt_create(cli_share_src, src_name, READ_CONTROL_ACCESS); + if (fnum_src == -1) { + DEBUGADD(0,("cannot open %s %s on originating server %s\n", + is_file?"file":"dir", src_name, cli_errstr(cli_share_src))); + nt_status = cli_nt_error(cli_share_src); + goto out; + } + + + if (copy_acls) { + + /* get the security descriptor */ + sd = cli_query_secdesc(cli_share_src, fnum_src, mem_ctx); + if (!sd) { + DEBUG(0,("failed to get security descriptor: %s\n", + cli_errstr(cli_share_src))); + nt_status = cli_nt_error(cli_share_src); + goto out; + } + + if (opt_verbose && DEBUGLEVEL >= 3) + display_sec_desc(sd); + } + + + if (copy_attrs || copy_timestamps) { + + /* get file attributes */ + if (!cli_getattrE(cli_share_src, fnum_src, &attr, NULL, + &ctime, &atime, &mtime)) { + DEBUG(0,("failed to get file-attrs: %s\n", + cli_errstr(cli_share_src))); + nt_status = cli_nt_error(cli_share_src); + goto out; + } + } + + + /* open the file/dir on the destination server */ + + fnum_dst = cli_nt_create(cli_share_dst, dst_name, WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS); + if (fnum_dst == -1) { + DEBUG(0,("failed to open %s on the destination server: %s: %s\n", + is_file?"file":"dir", dst_name, cli_errstr(cli_share_dst))); + nt_status = cli_nt_error(cli_share_dst); + goto out; + } + + if (copy_timestamps) { + + /* set timestamps */ + if (!cli_setattrE(cli_share_dst, fnum_dst, ctime, atime, mtime)) { + DEBUG(0,("failed to set file-attrs (timestamps): %s\n", + cli_errstr(cli_share_dst))); + nt_status = cli_nt_error(cli_share_dst); + goto out; + } + } + + if (copy_acls) { + + /* set acls */ + if (!cli_set_secdesc(cli_share_dst, fnum_dst, sd)) { + DEBUG(0,("could not set secdesc on %s: %s\n", + dst_name, cli_errstr(cli_share_dst))); + nt_status = cli_nt_error(cli_share_dst); + goto out; + } + } + + if (copy_attrs) { + + /* set attrs */ + if (!cli_setatr(cli_share_dst, dst_name, attr, 0)) { + DEBUG(0,("failed to set file-attrs: %s\n", + cli_errstr(cli_share_dst))); + nt_status = cli_nt_error(cli_share_dst); + goto out; + } + } + + + /* closing files */ + + if (!cli_close(cli_share_src, fnum_src)) { + d_printf("could not close %s on originating server: %s\n", + is_file?"file":"dir", cli_errstr(cli_share_src)); + nt_status = cli_nt_error(cli_share_src); + goto out; + } + + if (!cli_close(cli_share_dst, fnum_dst)) { + d_printf("could not close %s on destination server: %s\n", + is_file?"file":"dir", cli_errstr(cli_share_dst)); + nt_status = cli_nt_error(cli_share_dst); + goto out; + } + + + nt_status = NT_STATUS_OK; + +out: + + /* cleaning up */ + if (fnum_src) + cli_close(cli_share_src, fnum_src); + + if (fnum_dst) + cli_close(cli_share_dst, fnum_dst); + + return nt_status; +} + + /** * Copy a file or directory from a connected share to another connected share * @@ -304,92 +459,70 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, char *data = NULL; off_t start = 0; off_t nread = 0; - SEC_DESC *sd = NULL; - uint16 attr; - time_t atime, ctime, mtime; + if (!src_name || !dst_name) + goto out; + + if (cli_share_dst == NULL || cli_share_dst == NULL) + goto out; + + /* open on the originating server */ DEBUGADD(3,("opening %s %s on originating server\n", is_file ? "file":"dir", src_name)); - if (is_file) - fnum_src = cli_open(cli_share_src, src_name, - O_RDONLY, DENY_NONE); + fnum_src = cli_open(cli_share_src, src_name, O_RDONLY, DENY_NONE); else - fnum_src = cli_nt_create(cli_share_src, src_name, - READ_CONTROL_ACCESS); + fnum_src = cli_nt_create(cli_share_src, src_name, READ_CONTROL_ACCESS); if (fnum_src == -1) { DEBUGADD(0,("cannot open file %s on originating server %s\n", - src_name, cli_errstr(cli_share_src))); + src_name, cli_errstr(cli_share_src))); nt_status = cli_nt_error(cli_share_src); goto out; } - /* open on the destination server */ + if (is_file) { + + /* open file on the destination server */ DEBUGADD(3,("opening file %s on destination server\n", dst_name)); fnum_dst = cli_open(cli_share_dst, dst_name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE); - } - if (fnum_dst == -1) { - DEBUGADD(1,("cannot create file %s on destination server: %s\n", + if (fnum_dst == -1) { + DEBUGADD(1,("cannot create file %s on destination server: %s\n", dst_name, cli_errstr(cli_share_dst))); - nt_status = cli_nt_error(cli_share_dst); - goto out; - } - - - /* allocate memory */ - if (!(data = (char *)malloc(read_size))) { - d_printf("malloc fail for size %d\n", read_size); - goto out; - } - - - if (copy_acls) { - - /* get the security descriptor */ - sd = cli_query_secdesc(cli_share_src, fnum_src, mem_ctx); - if (!sd) { - DEBUG(0, ("failed to get security descriptor: %s\n", - cli_errstr(cli_share_src))); - nt_status = cli_nt_error(cli_share_src); + nt_status = cli_nt_error(cli_share_dst); goto out; } - } - - if (copy_attrs || copy_timestamps) { - /* get dos attributes */ - if (!cli_getattrE(cli_share_src, fnum_src, &attr, NULL, - &ctime, &atime, &mtime)) { - DEBUG(0, ("failed to get file-attrs: %s\n", - cli_errstr(cli_share_src))); - nt_status = cli_nt_error(cli_share_src); + /* allocate memory */ + if (!(data = (char *)malloc(read_size))) { + d_printf("malloc fail for size %d\n", read_size); + nt_status = NT_STATUS_NO_MEMORY; goto out; } + } - /* copying file */ + if (opt_verbose) { d_printf("copying [\\\\%s\\%s%s] => [\\\\%s\\%s%s] " - "%s acls and %s DOS Attributes %s\n", + "%s ACLs and %s DOS Attributes %s\n", cli_share_src->desthost, cli_share_src->share, src_name, cli_share_dst->desthost, cli_share_dst->share, dst_name, copy_acls ? "with" : "without", copy_attrs ? "with" : "without", copy_timestamps ? "(preserving timestamps)" : "" ); - - if (DEBUGLEVEL >= 3 && copy_acls) - display_sec_desc(sd); } + while (is_file) { + /* copying file */ int n, ret; n = cli_read(cli_share_src, fnum_src, data, nread + start, read_size); @@ -400,79 +533,36 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, ret = cli_write(cli_share_dst, fnum_dst, 0, data, nread + start, n); - if (n != ret) { - d_printf("Error writing file: %s\n", + if (n != ret) { + d_printf("Error writing file: %s\n", cli_errstr(cli_share_dst)); nt_status = cli_nt_error(cli_share_dst); - goto out; - } + goto out; + } nread += n; } - /* creating dir */ + if (!is_file && !cli_chkpath(cli_share_dst, dst_name)) { + /* creating dir */ DEBUGADD(3,("creating dir %s on the destination server\n", dst_name)); if (!cli_mkdir(cli_share_dst, dst_name)) { - DEBUG(0,("cannot create directory %s: %s\n", - dst_name, cli_errstr(cli_share_dst))); - nt_status = NT_STATUS_NO_SUCH_FILE; - } + DEBUG(0,("cannot create directory %s: %s\n", + dst_name, cli_errstr(cli_share_dst))); + nt_status = NT_STATUS_NO_SUCH_FILE; + } - if (!cli_chkpath(cli_share_dst, dst_name)) { + if (!cli_chkpath(cli_share_dst, dst_name)) { d_printf("cannot check for directory %s: %s\n", dst_name, cli_errstr(cli_share_dst)); - goto out; - } - } - - /* open the file/dir a second time */ - fnum_dst = cli_nt_create(cli_share_dst, dst_name, - WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS); - - if (fnum_dst == -1) { - DEBUG(0,("failed to open file/dir again: %s: %s\n", - dst_name, cli_errstr(cli_share_dst))); - nt_status = cli_nt_error(cli_share_dst); - goto out; - } - - /* set timestamps */ - if (copy_timestamps) { - - if (!cli_setattrE(cli_share_dst, fnum_dst, ctime, atime, mtime)) { - DEBUG(0,("failed to set file-attrs (timestamps): %s\n", - cli_errstr(cli_share_dst))); - nt_status = cli_nt_error(cli_share_dst); goto out; } } - /* set acls */ - if (copy_acls) { - - if (!cli_set_secdesc(cli_share_dst, fnum_dst, sd)) { - DEBUG(0,("could not set secdesc on %s %s: %s\n", - is_file? "file":"dir", dst_name, - cli_errstr(cli_share_dst))); - nt_status = cli_nt_error(cli_share_dst); - goto out; - } - } - - /* set attrs */ - if (copy_attrs) { - - if (!cli_setatr(cli_share_dst, dst_name, attr, 0)) { - DEBUG(0,("failed to set file-attrs: %s\n", - cli_errstr(cli_share_dst))); - nt_status = cli_nt_error(cli_share_dst); - goto out; - } - } /* closing files */ if (!cli_close(cli_share_src, fnum_src)) { @@ -489,6 +579,13 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, goto out; } + /* possibly we have to copy some file-attributes / acls / sd */ + nt_status = net_copy_fileattr(mem_ctx, cli_share_src, cli_share_dst, + src_name, dst_name, copy_acls, + copy_attrs, copy_timestamps, is_file); + if (!NT_STATUS_IS_OK(nt_status)) + goto out; + nt_status = NT_STATUS_OK; -- cgit From f5a2dd73da452bec1fcdaa60a8460b35a43ba3dc Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 26 Aug 2004 21:32:49 +0000 Subject: r2079: Clear the publish-bit from the attributes-mask when migrating printer-settings. publishing-info is not handled yet. Guenther (This used to be commit 1d76adb93c98857ed3460db241847e423c021a99) --- source3/utils/net_rpc_printer.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index d43b2ed94c..b414b38a79 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -2095,6 +2095,12 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const is correctly installed (incl. driver ???) */ init_unistr( &ctr_dst.printers_2->portname, SAMBA_PRINTER_PORT_NAME); + /* check if printer is published -> no publish-migration for the moment */ + if (ctr_enum.printers_2[i].attributes & PRINTER_ATTRIBUTE_PUBLISHED) { + printf("printer on originating server was published, ignoring that\n"); + ctr_dst.printers_2->attributes = PRINTER_ATTRIBUTE_SAMBA; + } + /* copy devmode (info level 2) */ ctr_dst.printers_2->devmode = talloc_memdup(mem_ctx, ctr_enum.printers_2[i].devmode, sizeof(DEVICEMODE)); -- cgit From e4c4d91896f08dadf3bc52e067941adb60de0e00 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 26 Aug 2004 21:37:20 +0000 Subject: r2080: Remove last traces of static migration to localhost. Needed to allow a local netbios-alias bound to non-loopback interface as a migration target. It's now possible to migrate printers|shares|files from Server A to Server B while running the net-command on client C. Guenther (This used to be commit 0cfd2866dfe5e959ede169a77c39480790300de3) --- source3/utils/net_rpc_printer.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index b414b38a79..11f9c0ba2f 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -1324,13 +1324,13 @@ NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, const DEBUG(3,("copying printer ACLs\n")); - /* connect local PI_SPOOLSS */ - nt_status = connect_local_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + /* connect destination PI_SPOOLSS */ + nt_status = connect_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; - /* enum remote printers */ + /* enum source printers */ if (!get_printer_info(cli, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; @@ -1474,8 +1474,8 @@ NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, const ch DEBUG(3,("copying forms\n")); - /* connect local PI_SPOOLSS */ - nt_status = connect_local_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + /* connect destination PI_SPOOLSS */ + nt_status = connect_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; @@ -1656,7 +1656,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const DEBUG(3,("copying printer-drivers\n")); - nt_status = connect_local_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + nt_status = connect_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; @@ -1855,8 +1855,8 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, const DEBUG(3,("copying printers\n")); - /* connect local PI_SPOOLSS */ - nt_status = connect_local_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + /* connect destination PI_SPOOLSS */ + nt_status = connect_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; @@ -2024,8 +2024,8 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const DEBUG(3,("copying printer settings\n")); - /* connect local PI_SPOOLSS */ - nt_status = connect_local_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + /* connect destination PI_SPOOLSS */ + nt_status = connect_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; -- cgit From d25aba1d144eef4fb400b730ffde308120440d17 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 21 Sep 2004 13:31:57 +0000 Subject: r2476: now that PRINTER_ATTRIBUTE_PUBLISHED does not get reset anymore, migrate the publishing-state for migrated printers as well. Therefor added client-side-support for setprinter level 7. Next will be a "net rpc printer publish"-command (just for completeness). Guenther (This used to be commit 224920738fdc65ef170152062177421cfed85bbf) --- source3/utils/net_rpc_printer.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 11f9c0ba2f..51f4df7b05 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -2011,7 +2011,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const BOOL got_hnd_dst = False; BOOL got_dst_spoolss_pipe = False; POLICY_HND hnd_src, hnd_dst; - PRINTER_INFO_CTR ctr_enum, ctr_dst; + PRINTER_INFO_CTR ctr_enum, ctr_dst, ctr_dst_publish; REGVAL_CTR reg_ctr; struct cli_state *cli_dst = NULL; char *devicename = NULL, *unc_name = NULL, *url = NULL; @@ -2095,10 +2095,19 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const is correctly installed (incl. driver ???) */ init_unistr( &ctr_dst.printers_2->portname, SAMBA_PRINTER_PORT_NAME); - /* check if printer is published -> no publish-migration for the moment */ + /* check if printer is published */ if (ctr_enum.printers_2[i].attributes & PRINTER_ATTRIBUTE_PUBLISHED) { - printf("printer on originating server was published, ignoring that\n"); - ctr_dst.printers_2->attributes = PRINTER_ATTRIBUTE_SAMBA; + + /* check for existing dst printer */ + if (!net_spoolss_getprinter(cli_dst, mem_ctx, &hnd_dst, 7, &ctr_dst_publish)) + goto done; + + ctr_dst_publish.printers_7->action = SPOOL_DS_PUBLISH; + + /* ignore False from setprinter due to WERR_IO_PENDING */ + net_spoolss_setprinter(cli_dst, mem_ctx, &hnd_dst, 7, &ctr_dst_publish); + + DEBUG(3,("republished printer\n")); } /* copy devmode (info level 2) */ -- cgit From 2d016a67b87b5fee71fbdd33ea6b6fa78b0c8828 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 4 Oct 2004 22:13:57 +0000 Subject: r2821: Adding "Windows x64" as architecture string and driverdir "x64" for the 64bit AMD platform. (This used to be "Windows AMD64" and "AMD64" in one of the release candidates of SP2 for Windows XP. AMD64 is obviously still supported but not documented.) Guenther (This used to be commit cc5892f0411b8eb5daebe746164a2cf21d3d4c68) --- source3/utils/net_rpc_printer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 51f4df7b05..732af254d0 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -35,7 +35,8 @@ static const struct table_node archi_table[]= { {"Windows NT R4000", "W32MIPS", 2 }, {"Windows NT Alpha_AXP", "W32ALPHA", 2 }, {"Windows NT PowerPC", "W32PPC", 2 }, - {"Windows IA64", "IA64", 3 }, + {"Windows IA64", "IA64", 3 }, + {"Windows x64", "x64", 3 }, {NULL, "", -1 } }; -- cgit From b4cf9e95059071df49b34ff8574e48cb96f42da1 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 7 Oct 2004 04:01:18 +0000 Subject: r2835: Since we always have -I. and -I$(srcdir) in CFLAGS, we can get rid of '..' from all #include preprocessor commands. This fixes bugzilla #1880 where OpenVMS gets confused about the '.' characters. (This used to be commit 7f161702fa4916979602cc0295919b541912acd6) --- source3/utils/net_rpc_printer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 732af254d0..50d0d4e7df 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -18,7 +18,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "includes.h" -#include "../utils/net.h" +#include "utils/net.h" struct table_node { const char *long_archi; -- cgit From e81aa8c59ed89dfe7b1a3b1378895e0d6aafd190 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 7 Oct 2004 11:01:13 +0000 Subject: r2837: Fix printer-migration w.r.t. to new naming-convention for policy-handles. Also remove some unused vars. Guenther (This used to be commit 5181c1b2192d1802616e8c30cd9458c00a306a46) --- source3/utils/net_rpc_printer.c | 77 ++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 40 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 50d0d4e7df..e635b78573 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -840,38 +840,41 @@ net_spoolss_enum_printers(struct cli_state *cli, TALLOC_CTX *mem_ctx, static BOOL net_spoolss_open_printer_ex(struct cli_state *cli, TALLOC_CTX *mem_ctx, - const char *printername, const char *datatype, - uint32 access_required, const char *servername, + const char *printername, uint32 access_required, const char *username, POLICY_HND *hnd) { WERROR result; + fstring servername, printername2; - fstring servername2; - slprintf(servername2, sizeof(servername2)-1, "\\\\%s", cli->desthost); + slprintf(servername, sizeof(servername)-1, "\\\\%s", cli->desthost); + + fstrcpy(printername2, servername); + fstrcat(printername2, "\\"); + fstrcat(printername2, printername); DEBUG(10,("connecting to: %s as %s for %s and access: %x\n", - servername2, username, printername, access_required)); + servername, username, printername2, access_required)); /* open printer */ - result = cli_spoolss_open_printer_ex(cli, mem_ctx, printername, + result = cli_spoolss_open_printer_ex(cli, mem_ctx, printername2, "", access_required, - servername2, username, hnd); + servername, username, hnd); /* be more verbose */ if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) { d_printf("no access to printer [%s] on [%s] for user [%s] granted\n", - printername, servername2, username); + printername2, servername, username); return False; } if (!W_ERROR_IS_OK(result)) { d_printf("cannot open printer %s on server %s: %s\n", - printername, servername2, dos_errstr(result)); + printername2, servername, dos_errstr(result)); return False; } DEBUG(2,("got printer handle for printer: %s, server: %s\n", - printername, servername2)); + printername2, servername)); return True; } @@ -1089,7 +1092,8 @@ net_spoolss_getprinterdriver(struct cli_state *cli, if (!W_ERROR_IS_OK(result)) { DEBUG(1,("cannot get driver (for architecture: %s): %s\n", env, dos_errstr(result))); - if (W_ERROR_V(result) != W_ERROR_V(WERR_UNKNOWN_PRINTER_DRIVER)) { + if (W_ERROR_V(result) != W_ERROR_V(WERR_UNKNOWN_PRINTER_DRIVER) && + W_ERROR_V(result) != W_ERROR_V(WERR_INVALID_ENVIRONMENT)) { printf("cannot get driver: %s\n", dos_errstr(result)); } return False; @@ -1133,7 +1137,6 @@ get_printer_info(struct cli_state *cli, TALLOC_CTX *mem_ctx, { char *sharename; - fstring servername; POLICY_HND hnd; /* no arguments given, enumerate all printers */ @@ -1151,9 +1154,8 @@ get_printer_info(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* argument given, get a single printer by name */ sharename = strdup(argv[0]); - if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, "", - MAXIMUM_ALLOWED_ACCESS, servername, - cli->user_name, &hnd)) + if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, + MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd)) return False; if (!net_spoolss_getprinter(cli, mem_ctx, &hnd, level, ctr)) { @@ -1312,7 +1314,6 @@ NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, const uint32 i = 0; uint32 num_printers; uint32 level = 2; - fstring servername = ""; pstring printername = "", sharename = ""; BOOL got_hnd_src = False; BOOL got_hnd_dst = False; @@ -1366,16 +1367,16 @@ NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, const */ /* open src printer handle */ - if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, "", - MAXIMUM_ALLOWED_ACCESS, servername, cli->user_name, &hnd_src)) + if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, + MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) goto done; got_hnd_src = True; /* open dst printer handle */ - if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, "", - PRINTER_ALL_ACCESS, servername, cli_dst->user_name, &hnd_dst)) + if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, + PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst)) goto done; got_hnd_dst = True; @@ -1460,7 +1461,6 @@ NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, const ch uint32 i, f; uint32 num_printers; uint32 level = 1; - fstring servername = ""; pstring printername = "", sharename = ""; BOOL got_hnd_src = False; BOOL got_hnd_dst = False; @@ -1511,16 +1511,16 @@ NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, const ch /* open src printer handle */ - if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, "", - MAXIMUM_ALLOWED_ACCESS, servername, cli->user_name, &hnd_src)) + if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, + MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) goto done; got_hnd_src = True; /* open dst printer handle */ - if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, "", - PRINTER_ALL_ACCESS, servername, cli->user_name, &hnd_dst)) + if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, + PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) goto done; got_hnd_dst = True; @@ -1634,7 +1634,6 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const uint32 i, p; uint32 num_printers; uint32 level = 3; - fstring servername = ""; pstring printername = "", sharename = ""; BOOL got_hnd_src = False; BOOL got_hnd_dst = False; @@ -1709,8 +1708,8 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const printername, sharename); /* open dst printer handle */ - if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, "", - PRINTER_ALL_ACCESS, servername, cli->user_name, &hnd_dst)) + if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, + PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) goto done; got_hnd_dst = True; @@ -1721,8 +1720,8 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const /* open src printer handle */ - if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, "", - MAXIMUM_ALLOWED_ACCESS, servername, cli->user_name, &hnd_src)) + if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, + MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) goto done; got_hnd_src = True; @@ -1849,7 +1848,6 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, const struct cli_state *cli_dst = NULL; POLICY_HND hnd_dst, hnd_src; pstring printername, sharename; - fstring servername; BOOL got_hnd_src = False; BOOL got_hnd_dst = False; BOOL got_dst_spoolss_pipe = False; @@ -1892,8 +1890,8 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, const /* open dst printer handle */ - if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, "", - PRINTER_ALL_ACCESS, servername, cli->user_name, &hnd_dst)) { + if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, + PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) { DEBUG(1,("could not open printer: %s\n", sharename)); } else { @@ -1924,8 +1922,8 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, const we first need a handle for that */ /* open src printer handle */ - if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, "", - MAXIMUM_ALLOWED_ACCESS, servername, cli->user_name, &hnd_src)) + if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, + MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) goto done; got_hnd_src = True; @@ -2006,7 +2004,6 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const uint32 i = 0, p = 0, j = 0; uint32 num_printers, val_needed, data_needed; uint32 level = 2; - fstring servername = ""; pstring printername = "", sharename = ""; BOOL got_hnd_src = False; BOOL got_hnd_dst = False; @@ -2065,16 +2062,16 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const /* open src printer handle */ - if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, "", - MAXIMUM_ALLOWED_ACCESS, servername, cli->user_name, &hnd_src)) + if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, + MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) goto done; got_hnd_src = True; /* open dst printer handle */ - if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, "", - PRINTER_ALL_ACCESS, servername, cli_dst->user_name, &hnd_dst)) + if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, + PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst)) goto done; got_hnd_dst = True; -- cgit From d15e6af706fe7187972ce6f65a3d53a99c67fab2 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 7 Oct 2004 14:47:53 +0000 Subject: r2852: Oh. Allow to migrate win2k3/xp-drivers as well. Thanks to Bjoern Jacke for his moral support :) Guenther (This used to be commit ab875d3ecf3a80f5648432f7f4573f57442e6698) --- source3/utils/net_rpc_printer.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index e635b78573..f470d8b6d9 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -32,6 +32,7 @@ static const struct table_node archi_table[]= { {"Windows 4.0", "WIN40", 0 }, {"Windows NT x86", "W32X86", 2 }, + {"Windows NT x86", "W32X86", 3 }, {"Windows NT R4000", "W32MIPS", 2 }, {"Windows NT Alpha_AXP", "W32ALPHA", 2 }, {"Windows NT PowerPC", "W32PPC", 2 }, -- cgit From 3eff1f48d5806aeb0347f13c50e7620bbdc04dd5 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 13 Oct 2004 01:40:35 +0000 Subject: r2942: Add client-side support of triggering ads printer publishing over msrpc setprinter calls inside the net-tool. This is usefull to mimic the same queries a windows-client does. At least win2k returns WERR_IO_PENDING when printer is published via setprinter, samba returns WERR_OK but this does not hurt. Guenther (This used to be commit 69b745fb98b8054d1f52e8a3fe3b933fb04336db) --- source3/utils/net_rpc_printer.c | 188 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index f470d8b6d9..a7e0ebeb6c 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -1288,6 +1288,194 @@ done: } +/** + * Publish print-queues with args-wrapper + * + * @param cli A cli_state connected to the server. + * @param mem_ctx Talloc context, destoyed on compleation of the function. + * @param argc Standard main() style argc + * @param argv Standard main() style argv. Initial components are already + * stripped + * @param action + * + * @return Normal NTSTATUS return. + **/ + +static NTSTATUS rpc_printer_publish_internals_args(struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv, uint32 action) +{ + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; + uint32 i, num_printers; + uint32 level = 7; + pstring printername, sharename; + PRINTER_INFO_CTR ctr, ctr_pub; + POLICY_HND hnd; + BOOL got_hnd = False; + WERROR result; + char *action_str; + + if (!get_printer_info(cli, mem_ctx, 2, argc, argv, &num_printers, &ctr)) + return nt_status; + + for (i = 0; i < num_printers; i++) { + + /* do some initialization */ + rpcstr_pull(printername, ctr.printers_2[i].printername.buffer, + sizeof(printername), -1, STR_TERMINATE); + rpcstr_pull(sharename, ctr.printers_2[i].sharename.buffer, + sizeof(sharename), -1, STR_TERMINATE); + + /* open printer handle */ + if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, + PRINTER_ALL_ACCESS, cli->user_name, &hnd)) + goto done; + + got_hnd = True; + + /* check for existing dst printer */ + if (!net_spoolss_getprinter(cli, mem_ctx, &hnd, level, &ctr_pub)) + goto done; + + /* check action and set string */ + switch (action) { + case SPOOL_DS_PUBLISH: + action_str = "published"; + break; + case SPOOL_DS_UPDATE: + action_str = "updated"; + break; + case SPOOL_DS_UNPUBLISH: + action_str = "unpublished"; + break; + default: + printf("unkown action: %d\n", action); + break; + } + + ctr_pub.printers_7->action = action; + + result = cli_spoolss_setprinter(cli, mem_ctx, &hnd, level, &ctr_pub, 0); + if (!W_ERROR_IS_OK(result) && (W_ERROR_V(result) =! W_ERROR_V(WERR_IO_PENDING))) { + printf("cannot set printer-info: %s\n", dos_errstr(result)); + goto done; + } + + printf("successfully %s printer %s in Active Directory\n", action_str, sharename); + } + + nt_status = NT_STATUS_OK; + +done: + if (got_hnd) + cli_spoolss_close_printer(cli, mem_ctx, &hnd); + + return nt_status; +} + +NTSTATUS rpc_printer_publish_publish_internals(const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv) +{ + return rpc_printer_publish_internals_args(cli, mem_ctx, argc, argv, SPOOL_DS_PUBLISH); +} + +NTSTATUS rpc_printer_publish_unpublish_internals(const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv) +{ + return rpc_printer_publish_internals_args(cli, mem_ctx, argc, argv, SPOOL_DS_UNPUBLISH); +} + +NTSTATUS rpc_printer_publish_update_internals(const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv) +{ + return rpc_printer_publish_internals_args(cli, mem_ctx, argc, argv, SPOOL_DS_UPDATE); +} + +/** + * List print-queues w.r.t. thei publishing + * + * All parameters are provided by the run_rpc_command function, except for + * argc, argv which are passed through. + * + * @param domain_sid The domain sid aquired from the remote server + * @param cli A cli_state connected to the server. + * @param mem_ctx Talloc context, destoyed on compleation of the function. + * @param argc Standard main() style argc + * @param argv Standard main() style argv. Initial components are already + * stripped + * + * @return Normal NTSTATUS return. + **/ +NTSTATUS rpc_printer_publish_list_internals(const DOM_SID *domain_sid, const char *domain_name, + struct cli_state *cli, TALLOC_CTX *mem_ctx, + int argc, const char **argv) +{ + NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; + uint32 i, num_printers; + uint32 level = 7; + pstring printername, sharename; + pstring guid; + PRINTER_INFO_CTR ctr, ctr_pub; + POLICY_HND hnd; + BOOL got_hnd = False; + int state; + + if (!get_printer_info(cli, mem_ctx, 2, argc, argv, &num_printers, &ctr)) + return nt_status; + + for (i = 0; i < num_printers; i++) { + + ZERO_STRUCT(ctr_pub); + + /* do some initialization */ + rpcstr_pull(printername, ctr.printers_2[i].printername.buffer, + sizeof(printername), -1, STR_TERMINATE); + rpcstr_pull(sharename, ctr.printers_2[i].sharename.buffer, + sizeof(sharename), -1, STR_TERMINATE); + + /* open printer handle */ + if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, + PRINTER_ALL_ACCESS, cli->user_name, &hnd)) + goto done; + + got_hnd = True; + + /* check for existing dst printer */ + if (!net_spoolss_getprinter(cli, mem_ctx, &hnd, level, &ctr_pub)) + goto done; + + rpcstr_pull(guid, ctr_pub.printers_7->guid.buffer, sizeof(guid), -1, STR_TERMINATE); + + state = ctr_pub.printers_7->action; + switch (state) { + case SPOOL_DS_PUBLISH: + printf("printer [%s] is published", sharename); + if (opt_verbose) + printf(", guid: %s", guid); + printf("\n"); + break; + case SPOOL_DS_UNPUBLISH: + printf("printer [%s] is unpublished\n", sharename); + break; + case SPOOL_DS_UPDATE: + printf("printer [%s] is currently updating\n", sharename); + break; + default: + printf("unkown state: %d\n", state); + break; + } + } + + nt_status = NT_STATUS_OK; + +done: + if (got_hnd) + cli_spoolss_close_printer(cli, mem_ctx, &hnd); + + return nt_status; +} /** * Migrate Printer-ACLs from a source server to the destination server -- cgit From 9b8bedf2febd821c56adbef635559f3a1f299744 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 19 Nov 2004 19:45:03 +0000 Subject: r3880: Tidy up some unused/shadowed variable usage. Jeremy. (This used to be commit 1fd1a98782c3ca7171428b62336936aef4c6685b) --- source3/utils/net_rpc_printer.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index a7e0ebeb6c..25f3ab5184 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -305,7 +305,7 @@ net_copy_fileattr(TALLOC_CTX *mem_ctx, int fnum_dst = 0; SEC_DESC *sd = NULL; uint16 attr; - time_t atime, ctime, mtime; + time_t f_atime, f_ctime, f_mtime; if (!copy_timestamps && !copy_acls && !copy_attrs) @@ -346,7 +346,7 @@ net_copy_fileattr(TALLOC_CTX *mem_ctx, /* get file attributes */ if (!cli_getattrE(cli_share_src, fnum_src, &attr, NULL, - &ctime, &atime, &mtime)) { + &f_ctime, &f_atime, &f_mtime)) { DEBUG(0,("failed to get file-attrs: %s\n", cli_errstr(cli_share_src))); nt_status = cli_nt_error(cli_share_src); @@ -368,7 +368,7 @@ net_copy_fileattr(TALLOC_CTX *mem_ctx, if (copy_timestamps) { /* set timestamps */ - if (!cli_setattrE(cli_share_dst, fnum_dst, ctime, atime, mtime)) { + if (!cli_setattrE(cli_share_dst, fnum_dst, f_ctime, f_atime, f_mtime)) { DEBUG(0,("failed to set file-attrs (timestamps): %s\n", cli_errstr(cli_share_dst))); nt_status = cli_nt_error(cli_share_dst); @@ -1312,7 +1312,7 @@ static NTSTATUS rpc_printer_publish_internals_args(struct cli_state *cli, TALLOC POLICY_HND hnd; BOOL got_hnd = False; WERROR result; - char *action_str; + const char *action_str; if (!get_printer_info(cli, mem_ctx, 2, argc, argv, &num_printers, &ctr)) return nt_status; @@ -1348,6 +1348,7 @@ static NTSTATUS rpc_printer_publish_internals_args(struct cli_state *cli, TALLOC action_str = "unpublished"; break; default: + action_str = "unknown action"; printf("unkown action: %d\n", action); break; } -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/utils/net_rpc_printer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 25f3ab5184..456a29287f 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -501,7 +501,7 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, } /* allocate memory */ - if (!(data = (char *)malloc(read_size))) { + if (!(data = (char *)SMB_MALLOC(read_size))) { d_printf("malloc fail for size %d\n", read_size); nt_status = NT_STATUS_NO_MEMORY; goto out; @@ -1153,7 +1153,7 @@ get_printer_info(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* argument given, get a single printer by name */ - sharename = strdup(argv[0]); + sharename = SMB_STRDUP(argv[0]); if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd)) @@ -2299,7 +2299,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const } /* copy devmode (info level 2) */ - ctr_dst.printers_2->devmode = talloc_memdup(mem_ctx, + ctr_dst.printers_2->devmode = TALLOC_MEMDUP(mem_ctx, ctr_enum.printers_2[i].devmode, sizeof(DEVICEMODE)); /* do not copy security descriptor (we have another command for that) */ @@ -2461,7 +2461,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const value.type = REG_SZ; value.size = data.uni_str_len * 2; - value.data_p = talloc_memdup(mem_ctx, data.buffer, value.size); + value.data_p = TALLOC_MEMDUP(mem_ctx, data.buffer, value.size); if (opt_verbose) display_reg_value(subkey, value); -- cgit From c3a5d90db43e6340e974f879f0c3b9c361bf3bb9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 24 Feb 2005 17:00:24 +0000 Subject: r5541: Fix crash bug in the client-spoolss enumdataex-call. With Windows2003 it's perfectly legal to receive no data when querying a value-less subkey. Found while migrating printer settings. Guenther (This used to be commit 3e04def03377b2eae2987c87b18ccadf5b48a6fe) --- source3/utils/net_rpc_printer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 456a29287f..00b038dd8b 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -980,7 +980,7 @@ net_spoolss_enumprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* enumprinterdataex call */ result = cli_spoolss_enumprinterdataex( - cli, mem_ctx, 0, &needed, hnd, keyname, NULL); + cli, mem_ctx, 0, &needed, hnd, keyname, ctr); if (W_ERROR_V(result) == W_ERROR_V(WERR_MORE_DATA)) result = cli_spoolss_enumprinterdataex( -- cgit From 4b03bd3b18cc35270a7f92cbe5da3852dc7ba5b3 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 24 Feb 2005 23:25:35 +0000 Subject: r5546: Fix some comments in "net rpc printer migrate settings" Guenther (This used to be commit 67552103ee77013d08e06ed651f6ca6b3b76813e) --- source3/utils/net_rpc_printer.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 00b038dd8b..8fc65b3877 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -2205,7 +2205,6 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const char *devicename = NULL, *unc_name = NULL, *url = NULL; fstring longname; - const char *keyname = NULL; uint16 *keylist = NULL, *curkey; ZERO_STRUCT(ctr_enum); @@ -2242,7 +2241,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const sizeof(printername), -1, STR_TERMINATE); rpcstr_pull(sharename, ctr_enum.printers_2[i].sharename.buffer, sizeof(sharename), -1, STR_TERMINATE); - keyname = ""; + /* we can reset NT_STATUS here because we do not get any real NT_STATUS-codes anymore from now on */ nt_status = NT_STATUS_UNSUCCESSFUL; @@ -2305,14 +2304,6 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const /* do not copy security descriptor (we have another command for that) */ ctr_dst.printers_2->secdesc = NULL; - - /* devmode->devicename is possibly broken at the moment for all - strlen(longprinternames) > MAXDEVICENAME (that is 32 chars) - this fires up thousands of safe_strncpy-debug0-messages - on my test-servers - TODO: tell jerry, jra, etc. again. - */ - #if 0 if (asprintf(&devicename, "\\\\%s\\%s", longname, printername) < 0) { nt_status = NT_STATUS_NO_MEMORY; @@ -2333,7 +2324,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const /* please keep in mind that samba parse_spools gives horribly crippled results when used to cli_spoolss_enumprinterdataex - a win2k3-server. + a win2k3-server. (Bugzilla #1851) FIXME: IIRC I've seen it too on a win2k-server */ @@ -2341,7 +2332,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const result = cli_spoolss_enumprinterdata(cli, mem_ctx, &hnd_src, p, 0, 0, &val_needed, &data_needed, NULL); - /* loop for all printerdata */ + /* loop for all printerdata of "PrinterDriverData" */ while (W_ERROR_IS_OK(result)) { REGISTRY_VALUE value; @@ -2355,7 +2346,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const /* display_value */ if (opt_verbose) - display_reg_value(NULL, value); + display_reg_value(SPOOL_PRINTERDATA_KEY, value); /* set_value */ if (!net_spoolss_setprinterdata(cli_dst, mem_ctx, @@ -2374,7 +2365,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const respond to enumprinterkey, win2k does, so continue in case of an error */ - if (!net_spoolss_enumprinterkey(cli, mem_ctx, &hnd_src, keyname, &keylist)) { + if (!net_spoolss_enumprinterkey(cli, mem_ctx, &hnd_src, "", &keylist)) { printf("got no key-data\n"); continue; } -- cgit From 4ef6976c58a0ca895fb23c490b1f8c55def83923 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 24 Feb 2005 23:30:47 +0000 Subject: r5547: Fix compile warning. Guenther (This used to be commit a5e215650e09f087f8aede96475bd26649aa244e) --- source3/utils/net_rpc_printer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 8fc65b3877..4b53dec36e 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -234,7 +234,7 @@ static void display_print_driver_3(DRIVER_INFO_3 *i1) } -static void display_reg_value(pstring subkey, REGISTRY_VALUE value) +static void display_reg_value(const char *subkey, REGISTRY_VALUE value) { pstring text; -- cgit From bf427362514bc24a0f433ffecdea7da2db2bece1 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 22 Mar 2005 21:24:16 +0000 Subject: r5971: Check for the correct cli-struct when copying files. Good catch from Lars Mueller . Guenther (This used to be commit 90e2383bc50e8312ad37f5869630130e0cd6ae78) --- source3/utils/net_rpc_printer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 4b53dec36e..9f5730994e 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -466,7 +466,7 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, if (!src_name || !dst_name) goto out; - if (cli_share_dst == NULL || cli_share_dst == NULL) + if (cli_share_src == NULL || cli_share_dst == NULL) goto out; -- cgit From ce8dee5c3c3aef931ee6aae6feec9d87fa1a1dde Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 26 Apr 2005 12:26:32 +0000 Subject: r6488: net rpc printer migrate should not try to set stuff that's not there. This fixes two segfaults. Thanks to Karolin Segger to find the bug and test the patch. Volker (This used to be commit 5fa5454218acf9975578dee1386d530f09ac7339) --- source3/utils/net_rpc_printer.c | 44 ++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 9f5730994e..b348c2b4e8 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -1960,6 +1960,12 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const } + if (strlen(drivername) == 0) { + DEBUGADD(1,("Did not get driver for printer %s\n", + printername)); + goto done; + } + /* setdriver dst */ init_unistr(&info_ctr_dst.printers_2->drivername, drivername); @@ -2297,28 +2303,34 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const DEBUG(3,("republished printer\n")); } - /* copy devmode (info level 2) */ - ctr_dst.printers_2->devmode = TALLOC_MEMDUP(mem_ctx, - ctr_enum.printers_2[i].devmode, sizeof(DEVICEMODE)); + if (ctr_enum.printers_2[i].devmode != NULL) { + + /* copy devmode (info level 2) */ + ctr_dst.printers_2->devmode = + TALLOC_MEMDUP(mem_ctx, + ctr_enum.printers_2[i].devmode, + sizeof(DEVICEMODE)); - /* do not copy security descriptor (we have another command for that) */ - ctr_dst.printers_2->secdesc = NULL; + /* do not copy security descriptor (we have another + * command for that) */ + ctr_dst.printers_2->secdesc = NULL; #if 0 - if (asprintf(&devicename, "\\\\%s\\%s", longname, printername) < 0) { - nt_status = NT_STATUS_NO_MEMORY; - goto done; - } + if (asprintf(&devicename, "\\\\%s\\%s", longname, + printername) < 0) { + nt_status = NT_STATUS_NO_MEMORY; + goto done; + } - init_unistr(&ctr_dst.printers_2->devmode->devicename, devicename); + init_unistr(&ctr_dst.printers_2->devmode->devicename, + devicename); #endif - if (!net_spoolss_setprinter(cli_dst, mem_ctx, &hnd_dst, - level, &ctr_dst)) - goto done; + if (!net_spoolss_setprinter(cli_dst, mem_ctx, &hnd_dst, + level, &ctr_dst)) + goto done; - DEBUGADD(1,("\tSetPrinter of DEVICEMODE succeeded\n")); - - + DEBUGADD(1,("\tSetPrinter of DEVICEMODE succeeded\n")); + } /* STEP 2: COPY REGISTRY VALUES */ -- cgit From ebb42167c9912492428e7ed8e03f06505a5c86fe Mon Sep 17 00:00:00 2001 From: Lars Müller Date: Sun, 12 Jun 2005 21:18:16 +0000 Subject: r7512: Fix net share migrate files to also migrate the ACLs of the top level dir of a share. Till now we excluded '.' and '..' in general. For the fix the information about top or lower level dir is stored in the copy_clistate. src and dst share are now also part of this struct and we only pass a pointer to the struct to the functions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This bug was found by Bill Calero of Novell. Thanks Bill! With this checkin no new functionality was added. But the copy_clistate already knows about a mode. Later beside the migrate an additional report mode will be added. This changes are coordinated with Günther . Lars (This used to be commit 506aaefa3716c7683eef9afe0d1bb5b6e2533c4b) --- source3/utils/net_rpc_printer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index b348c2b4e8..5cc89b41dd 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -479,7 +479,8 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, fnum_src = cli_nt_create(cli_share_src, src_name, READ_CONTROL_ACCESS); if (fnum_src == -1) { - DEBUGADD(0,("cannot open file %s on originating server %s\n", + DEBUGADD(0,("cannot open %s %s on originating server %s\n", + is_file ? "file":"dir", src_name, cli_errstr(cli_share_src))); nt_status = cli_nt_error(cli_share_src); goto out; -- cgit From 95ce7e65eb325d64f821e87f479b4898e577bc75 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 15 Jun 2005 13:01:19 +0000 Subject: r7607: Some minor fixes (typos, const) Guenther (This used to be commit 11504681861c9c8b509589d6d22551202d98e390) --- source3/utils/net_rpc_printer.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 5cc89b41dd..840688be9a 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -296,7 +296,7 @@ static NTSTATUS net_copy_fileattr(TALLOC_CTX *mem_ctx, struct cli_state *cli_share_src, struct cli_state *cli_share_dst, - char *src_name, char *dst_name, + const char *src_name, const char *dst_name, BOOL copy_acls, BOOL copy_attrs, BOOL copy_timestamps, BOOL is_file) { @@ -449,7 +449,7 @@ out: NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, struct cli_state *cli_share_src, struct cli_state *cli_share_dst, - char *src_name, char *dst_name, + const char *src_name, const char *dst_name, BOOL copy_acls, BOOL copy_attrs, BOOL copy_timestamps, BOOL is_file) { @@ -1138,7 +1138,6 @@ get_printer_info(struct cli_state *cli, TALLOC_CTX *mem_ctx, uint32 *num_printers, PRINTER_INFO_CTR *ctr) { - char *sharename; POLICY_HND hnd; /* no arguments given, enumerate all printers */ @@ -1154,9 +1153,7 @@ get_printer_info(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* argument given, get a single printer by name */ - sharename = SMB_STRDUP(argv[0]); - - if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, + if (!net_spoolss_open_printer_ex(cli, mem_ctx, argv[0], MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd)) return False; @@ -1255,7 +1252,7 @@ NTSTATUS rpc_printer_driver_list_internals(const DOM_SID *domain_sid, const char for (i=0; archi_table[i].long_archi!=NULL; i++) { - int num_drivers; + uint32 num_drivers; /* enum remote drivers */ if (!net_spoolss_enumprinterdrivers(cli, mem_ctx, level, @@ -1396,7 +1393,7 @@ NTSTATUS rpc_printer_publish_update_internals(const DOM_SID *domain_sid, const c } /** - * List print-queues w.r.t. thei publishing + * List print-queues w.r.t. their publishing state * * All parameters are provided by the run_rpc_command function, except for * argc, argv which are passed through. -- cgit From 7cbd740c62238406e64819e3594caeca341a25c9 Mon Sep 17 00:00:00 2001 From: Lars Müller Date: Wed, 15 Jun 2005 14:24:11 +0000 Subject: r7609: Move top level dir handling in from of the loop. This makes the code much straither. copy_top_level_perms() is jra's work. I modified the copy_top_level_perms() function to use the copy_clistate. And I don't forget trunk. Lars (This used to be commit 2c68568e5232c057d4f76f4bb044c54d18272602) --- source3/utils/net_rpc_printer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 840688be9a..f1f82a5cea 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -292,8 +292,7 @@ static void display_reg_value(const char *subkey, REGISTRY_VALUE value) * * @return Normal NTSTATUS return. **/ -static NTSTATUS -net_copy_fileattr(TALLOC_CTX *mem_ctx, +NTSTATUS net_copy_fileattr(TALLOC_CTX *mem_ctx, struct cli_state *cli_share_src, struct cli_state *cli_share_dst, const char *src_name, const char *dst_name, -- cgit From 44b93eec71b9b208ac0f4016f2a9410643caf2eb Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 19 Jul 2005 09:37:42 +0000 Subject: r8592: I'm pretty sure this should be != instead of =!. Bugzilla #2893. (This used to be commit 26539ddd7290860831e0bda62e1126945420b06f) --- source3/utils/net_rpc_printer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index f1f82a5cea..4185f805ee 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -1353,7 +1353,7 @@ static NTSTATUS rpc_printer_publish_internals_args(struct cli_state *cli, TALLOC ctr_pub.printers_7->action = action; result = cli_spoolss_setprinter(cli, mem_ctx, &hnd, level, &ctr_pub, 0); - if (!W_ERROR_IS_OK(result) && (W_ERROR_V(result) =! W_ERROR_V(WERR_IO_PENDING))) { + if (!W_ERROR_IS_OK(result) && (W_ERROR_V(result) != W_ERROR_V(WERR_IO_PENDING))) { printf("cannot set printer-info: %s\n", dos_errstr(result)); goto done; } -- cgit From ecafd3754f35a2109a3a1eecbbdd72ade06b8502 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 20 Jul 2005 15:35:29 +0000 Subject: r8654: merging cli_spoolss_XX() updates from trunk (This used to be commit cd961e50a3029898868d21263ccacb7d5f1f07b9) --- source3/utils/net_rpc_printer.c | 60 +++++------------------------------------ 1 file changed, 7 insertions(+), 53 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 4185f805ee..e2080cdc28 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -817,19 +817,11 @@ net_spoolss_enum_printers(struct cli_state *cli, TALLOC_CTX *mem_ctx, { WERROR result; - uint32 needed; /* enum printers */ - result = cli_spoolss_enum_printers( - cli, mem_ctx, 0, &needed, name, flags, + result = cli_spoolss_enum_printers(cli, mem_ctx, name, flags, level, num_printers, ctr); - if (W_ERROR_V(result) == W_ERROR_V(WERR_INSUFFICIENT_BUFFER)) - result = cli_spoolss_enum_printers( - cli, mem_ctx, needed, NULL, name, flags, - level, num_printers, ctr); - - if (!W_ERROR_IS_OK(result)) { printf("cannot enum printers: %s\n", dos_errstr(result)); return False; @@ -887,16 +879,10 @@ net_spoolss_getprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, PRINTER_INFO_CTR *ctr) { WERROR result; - uint32 needed; /* getprinter call */ - result = cli_spoolss_getprinter(cli, - mem_ctx, 0, &needed, hnd, level, ctr); + result = cli_spoolss_getprinter(cli, mem_ctx, hnd, level, ctr); - if (W_ERROR_V(result) == W_ERROR_V(WERR_INSUFFICIENT_BUFFER)) - result = cli_spoolss_getprinter(cli, - mem_ctx, needed, NULL, hnd, level, ctr); - if (!W_ERROR_IS_OK(result)) { printf("cannot get printer-info: %s\n", dos_errstr(result)); return False; @@ -949,17 +935,10 @@ net_spoolss_enumprinterkey(struct cli_state *cli, TALLOC_CTX *mem_ctx, uint16 **keylist) { WERROR result; - uint32 needed, len; /* enumprinterkey call */ - result = cli_spoolss_enumprinterkey( - cli, mem_ctx, 0, &needed, hnd, keyname, NULL, NULL); + result = cli_spoolss_enumprinterkey(cli, mem_ctx, hnd, keyname, NULL, NULL); - if (W_ERROR_V(result) == W_ERROR_V(WERR_MORE_DATA)) - result = cli_spoolss_enumprinterkey( - cli, mem_ctx, needed, NULL, hnd, keyname, keylist, - &len); - if (!W_ERROR_IS_OK(result)) { printf("enumprinterkey failed: %s\n", dos_errstr(result)); return False; @@ -976,16 +955,10 @@ net_spoolss_enumprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx, REGVAL_CTR *ctr) { WERROR result; - uint32 needed; /* enumprinterdataex call */ - result = cli_spoolss_enumprinterdataex( - cli, mem_ctx, 0, &needed, hnd, keyname, ctr); + result = cli_spoolss_enumprinterdataex(cli, mem_ctx, hnd, keyname, ctr); - if (W_ERROR_V(result) == W_ERROR_V(WERR_MORE_DATA)) - result = cli_spoolss_enumprinterdataex( - cli, mem_ctx, needed, NULL, hnd, keyname, ctr); - if (!W_ERROR_IS_OK(result)) { printf("enumprinterdataex failed: %s\n", dos_errstr(result)); return False; @@ -1022,16 +995,9 @@ net_spoolss_enumforms(struct cli_state *cli, TALLOC_CTX *mem_ctx, { WERROR result; - uint32 needed; /* enumforms call */ - result = cli_spoolss_enumforms( - cli, mem_ctx, 0, &needed, hnd, level, num_forms, forms); - - if (W_ERROR_V(result) == W_ERROR_V(WERR_INSUFFICIENT_BUFFER)) - result = cli_spoolss_enumforms( - cli, mem_ctx, needed, NULL, hnd, level, - num_forms, forms); + result = cli_spoolss_enumforms(cli, mem_ctx, hnd, level, num_forms, forms); if (!W_ERROR_IS_OK(result)) { printf("could not enum forms: %s\n", dos_errstr(result)); @@ -1049,18 +1015,12 @@ net_spoolss_enumprinterdrivers (struct cli_state *cli, TALLOC_CTX *mem_ctx, PRINTER_DRIVER_CTR *ctr) { WERROR result; - uint32 needed; /* enumprinterdrivers call */ result = cli_spoolss_enumprinterdrivers( - cli, mem_ctx, 0, &needed, level, + cli, mem_ctx, level, env, num_drivers, ctr); - if (W_ERROR_V(result) == W_ERROR_V(WERR_INSUFFICIENT_BUFFER)) - result = cli_spoolss_enumprinterdrivers( - cli, mem_ctx, needed, NULL, level, - env, num_drivers, ctr); - if (!W_ERROR_IS_OK(result)) { printf("cannot enum drivers: %s\n", dos_errstr(result)); return False; @@ -1078,18 +1038,12 @@ net_spoolss_getprinterdriver(struct cli_state *cli, PRINTER_DRIVER_CTR *ctr) { WERROR result; - uint32 needed; /* getprinterdriver call */ result = cli_spoolss_getprinterdriver( - cli, mem_ctx, 0, &needed, hnd, level, + cli, mem_ctx, hnd, level, env, version, ctr); - if (W_ERROR_V(result) == W_ERROR_V(WERR_INSUFFICIENT_BUFFER)) - result = cli_spoolss_getprinterdriver( - cli, mem_ctx, needed, NULL, hnd, level, - env, version, ctr); - if (!W_ERROR_IS_OK(result)) { DEBUG(1,("cannot get driver (for architecture: %s): %s\n", env, dos_errstr(result))); -- cgit From fefbaf2bca42569f6a3cc8b68578200159409ec9 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Tue, 2 Aug 2005 06:24:45 +0000 Subject: r8911: cosmetic fixes. Guenther (This used to be commit bf67a8611491ed748c6975787ce2f0572586a3c6) --- source3/utils/net_rpc_printer.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index e2080cdc28..b47f43b178 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -780,8 +780,10 @@ copy_print_driver_3(TALLOC_CTX *mem_ctx, return nt_status; while (valid) { + rpcstr_pull(dependentfiles, i1->dependentfiles+length, sizeof(dependentfiles), -1, STR_TERMINATE); - length+=strlen(dependentfiles)+1; + length += strlen(dependentfiles)+1; + if (strlen(dependentfiles) > 0) { nt_status = net_copy_driverfile(mem_ctx, @@ -1468,7 +1470,7 @@ NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, const DEBUG(3,("copying printer ACLs\n")); /* connect destination PI_SPOOLSS */ - nt_status = connect_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + nt_status = connect_dst_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; @@ -1617,7 +1619,7 @@ NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, const ch DEBUG(3,("copying forms\n")); /* connect destination PI_SPOOLSS */ - nt_status = connect_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + nt_status = connect_dst_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; @@ -1797,7 +1799,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const DEBUG(3,("copying printer-drivers\n")); - nt_status = connect_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + nt_status = connect_dst_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; @@ -1806,7 +1808,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const nt_status = connect_to_service(&cli_share_src, &cli->dest_ip, cli->desthost, "print$", "A:"); if (!NT_STATUS_IS_OK(nt_status)) - return nt_status; + goto done; got_src_driver_share = True; @@ -1826,7 +1828,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const goto done; } - if (!num_printers) { + if (num_printers == 0) { printf ("no printers found on server.\n"); nt_status = NT_STATUS_OK; goto done; @@ -2002,13 +2004,13 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, const DEBUG(3,("copying printers\n")); /* connect destination PI_SPOOLSS */ - nt_status = connect_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + nt_status = connect_dst_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; /* enum printers */ - if (!get_printer_info(cli, mem_ctx, 2, argc, argv, &num_printers, &ctr_enum)) { + if (!get_printer_info(cli, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } @@ -2169,7 +2171,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const DEBUG(3,("copying printer settings\n")); /* connect destination PI_SPOOLSS */ - nt_status = connect_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + nt_status = connect_dst_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; -- cgit From 8ea8a78abc233ecbee2972e1feff9d16715a3b8f Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Thu, 4 Aug 2005 23:20:48 +0000 Subject: r9076: fix two other issues invented along the cli_spoolss_enumprinterkey-changes. Guenther (This used to be commit db8fce2e05bf1981866a7737703ad414ea91febc) --- source3/utils/net_rpc_printer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index b47f43b178..6194f40b09 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -939,7 +939,7 @@ net_spoolss_enumprinterkey(struct cli_state *cli, TALLOC_CTX *mem_ctx, WERROR result; /* enumprinterkey call */ - result = cli_spoolss_enumprinterkey(cli, mem_ctx, hnd, keyname, NULL, NULL); + result = cli_spoolss_enumprinterkey(cli, mem_ctx, hnd, keyname, keylist, NULL); if (!W_ERROR_IS_OK(result)) { printf("enumprinterkey failed: %s\n", dos_errstr(result)); -- cgit From 44707ad2e00a91f459e80efbe8f362b5853b0a62 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 29 Aug 2005 14:55:40 +0000 Subject: r9739: conver the reg_objects (REGSUBKEY_CTR & REGVAL_CTR) to use the new talloc() features: Note that the REGSUB_CTR and REGVAL_CTR objects *must* be talloc()'d since the methods use the object pointer as the talloc context for internal private data. There is no longer a regXXX_ctr_intit() and regXXX_ctr_destroy() pair of functions. Simply TALLOC_ZERO_P() and TALLOC_FREE() the object. Also had to convert the printer_info_2->NT_PRINTER_DATA field to be talloc()'d as well. This is just a stop on the road to cleaning up the printer memory management. (This used to be commit ef721333ab9639cb5346067497e99fbd0d4425dd) --- source3/utils/net_rpc_printer.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 6194f40b09..e82db46b9f 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -2159,7 +2159,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const BOOL got_dst_spoolss_pipe = False; POLICY_HND hnd_src, hnd_dst; PRINTER_INFO_CTR ctr_enum, ctr_dst, ctr_dst_publish; - REGVAL_CTR reg_ctr; + REGVAL_CTR *reg_ctr; struct cli_state *cli_dst = NULL; char *devicename = NULL, *unc_name = NULL, *url = NULL; fstring longname; @@ -2351,13 +2351,16 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const curkey += strlen(subkey) + 1; + if ( !(reg_ctr = TALLOC_ZERO_P( mem_ctx, REGVAL_CTR )) ) + return NT_STATUS_NO_MEMORY; + /* enumerate all src subkeys */ if (!net_spoolss_enumprinterdataex(cli, mem_ctx, 0, &hnd_src, subkey, - ®_ctr)) + reg_ctr)) goto done; - for (j=0; j < reg_ctr.num_values; j++) { + for (j=0; j < reg_ctr->num_values; j++) { REGISTRY_VALUE value; UNISTR2 data; @@ -2365,20 +2368,20 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const /* although samba replies with sane data in most cases we should try to avoid writing wrong registry data */ - if (strequal(reg_ctr.values[j]->valuename, SPOOL_REG_PORTNAME) || - strequal(reg_ctr.values[j]->valuename, SPOOL_REG_UNCNAME) || - strequal(reg_ctr.values[j]->valuename, SPOOL_REG_URL) || - strequal(reg_ctr.values[j]->valuename, SPOOL_REG_SHORTSERVERNAME) || - strequal(reg_ctr.values[j]->valuename, SPOOL_REG_SERVERNAME)) { + if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_PORTNAME) || + strequal(reg_ctr->values[j]->valuename, SPOOL_REG_UNCNAME) || + strequal(reg_ctr->values[j]->valuename, SPOOL_REG_URL) || + strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SHORTSERVERNAME) || + strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SERVERNAME)) { - if (strequal(reg_ctr.values[j]->valuename, SPOOL_REG_PORTNAME)) { + if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_PORTNAME)) { /* although windows uses a multi-sz, we use a sz */ init_unistr2(&data, SAMBA_PRINTER_PORT_NAME, UNI_STR_TERMINATE); fstrcpy(value.valuename, SPOOL_REG_PORTNAME); } - if (strequal(reg_ctr.values[j]->valuename, SPOOL_REG_UNCNAME)) { + if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_UNCNAME)) { if (asprintf(&unc_name, "\\\\%s\\%s", longname, sharename) < 0) { nt_status = NT_STATUS_NO_MEMORY; @@ -2388,7 +2391,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const fstrcpy(value.valuename, SPOOL_REG_UNCNAME); } - if (strequal(reg_ctr.values[j]->valuename, SPOOL_REG_URL)) { + if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_URL)) { continue; @@ -2403,13 +2406,13 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const #endif } - if (strequal(reg_ctr.values[j]->valuename, SPOOL_REG_SERVERNAME)) { + if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SERVERNAME)) { init_unistr2(&data, longname, UNI_STR_TERMINATE); fstrcpy(value.valuename, SPOOL_REG_SERVERNAME); } - if (strequal(reg_ctr.values[j]->valuename, SPOOL_REG_SHORTSERVERNAME)) { + if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SHORTSERVERNAME)) { init_unistr2(&data, global_myname(), UNI_STR_TERMINATE); fstrcpy(value.valuename, SPOOL_REG_SHORTSERVERNAME); @@ -2430,21 +2433,21 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const } else { if (opt_verbose) - display_reg_value(subkey, *(reg_ctr.values[j])); + display_reg_value(subkey, *(reg_ctr->values[j])); /* here we have to set all subkeys on the dst server */ if (!net_spoolss_setprinterdataex(cli_dst, mem_ctx, &hnd_dst, - subkey, reg_ctr.values[j])) + subkey, reg_ctr->values[j])) goto done; } DEBUGADD(1,("\tSetPrinterDataEx of key [%s\\%s] succeeded\n", - subkey, reg_ctr.values[j]->valuename)); + subkey, reg_ctr->values[j]->valuename)); } - regval_ctr_destroy(®_ctr); + TALLOC_FREE( reg_ctr ); } safe_free(keylist); -- cgit From 54abd2aa66069e6baf7769c496f46d9dba18db39 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 30 Sep 2005 17:13:37 +0000 Subject: r10656: BIG merge from trunk. Features not copied over * \PIPE\unixinfo * winbindd's {group,alias}membership new functions * winbindd's lookupsids() functionality * swat (trunk changes to be reverted as per discussion with Deryck) (This used to be commit 939c3cb5d78e3a2236209b296aa8aba8bdce32d3) --- source3/utils/net_rpc_printer.c | 538 ++++++++++++++++++++++------------------ 1 file changed, 292 insertions(+), 246 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index e82db46b9f..d8f3099dec 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -49,9 +49,11 @@ static const struct table_node archi_table[]= { * possibly be removed later on * **/ + /**************************************************************************** -convert a security permissions into a string + Convert a security permissions into a string. ****************************************************************************/ + char *get_sec_mask_str(uint32 type) { static fstring typestr=""; @@ -86,10 +88,10 @@ char *get_sec_mask_str(uint32 type) return typestr; } - /**************************************************************************** - display sec_ace structure + Display sec_ace structure. ****************************************************************************/ + void display_sec_ace(SEC_ACE *ace) { fstring sid_str; @@ -119,10 +121,10 @@ void display_sec_ace(SEC_ACE *ace) printf("\t\tSID: %s\n\n", sid_str); } - /**************************************************************************** - display sec_acl structure + Display sec_acl structure. ****************************************************************************/ + void display_sec_acl(SEC_ACL *sec_acl) { int i; @@ -138,8 +140,9 @@ void display_sec_acl(SEC_ACL *sec_acl) } /**************************************************************************** - display sec_desc structure + Display sec_desc structure. ****************************************************************************/ + void display_sec_desc(SEC_DESC *sec) { fstring sid_str; @@ -175,8 +178,9 @@ void display_sec_desc(SEC_DESC *sec) **/ /**************************************************************************** -printer info level 3 display function + Printer info level 3 display function. ****************************************************************************/ + static void display_print_driver_3(DRIVER_INFO_3 *i1) { fstring name = ""; @@ -233,7 +237,6 @@ static void display_print_driver_3(DRIVER_INFO_3 *i1) return; } - static void display_reg_value(const char *subkey, REGISTRY_VALUE value) { pstring text; @@ -275,7 +278,6 @@ static void display_reg_value(const char *subkey, REGISTRY_VALUE value) } - /** * Copies ACLs, DOS-attributes and timestamps from one * file or directory from one connected share to another connected share @@ -292,6 +294,7 @@ static void display_reg_value(const char *subkey, REGISTRY_VALUE value) * * @return Normal NTSTATUS return. **/ + NTSTATUS net_copy_fileattr(TALLOC_CTX *mem_ctx, struct cli_state *cli_share_src, struct cli_state *cli_share_dst, @@ -310,7 +313,6 @@ NTSTATUS net_copy_fileattr(TALLOC_CTX *mem_ctx, if (!copy_timestamps && !copy_acls && !copy_attrs) return NT_STATUS_OK; - /* open file/dir on the originating server */ DEBUGADD(3,("opening %s %s on originating server\n", @@ -429,7 +431,6 @@ out: return nt_status; } - /** * Copy a file or directory from a connected share to another connected share * @@ -445,6 +446,7 @@ out: * * @return Normal NTSTATUS return. **/ + NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, struct cli_state *cli_share_src, struct cli_state *cli_share_dst, @@ -605,7 +607,6 @@ out: return nt_status; } - /** * Copy a driverfile from on connected share to another connected share * This silently assumes that a driver-file is picked up from @@ -625,6 +626,7 @@ out: * * @return Normal NTSTATUS return. **/ + static NTSTATUS net_copy_driverfile(TALLOC_CTX *mem_ctx, struct cli_state *cli_share_src, struct cli_state *cli_share_dst, @@ -673,7 +675,6 @@ out: return nt_status; } - /** * Check for existing Architecture directory on a given server * @@ -682,8 +683,8 @@ out: * * @return Normal NTSTATUS return. **/ -static NTSTATUS -check_arch_dir(struct cli_state *cli_share, const char *short_archi) + +static NTSTATUS check_arch_dir(struct cli_state *cli_share, const char *short_archi) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; @@ -715,7 +716,6 @@ out: return nt_status; } - /** * Copy a print-driver (level 3) from one connected print$-share to another * connected print$-share @@ -728,8 +728,8 @@ out: * * @return Normal NTSTATUS return. **/ -static NTSTATUS -copy_print_driver_3(TALLOC_CTX *mem_ctx, + +static NTSTATUS copy_print_driver_3(TALLOC_CTX *mem_ctx, struct cli_state *cli_share_src, struct cli_state *cli_share_dst, const char *short_archi, DRIVER_INFO_3 *i1) @@ -799,7 +799,6 @@ copy_print_driver_3(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } - /** * net_spoolss-functions * ===================== @@ -812,16 +811,18 @@ copy_print_driver_3(TALLOC_CTX *mem_ctx, * **/ -static BOOL -net_spoolss_enum_printers(struct cli_state *cli, TALLOC_CTX *mem_ctx, - char *name, uint32 flags, uint32 level, - uint32 *num_printers, PRINTER_INFO_CTR *ctr) +static BOOL net_spoolss_enum_printers(struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + char *name, + uint32 flags, + uint32 level, + uint32 *num_printers, + PRINTER_INFO_CTR *ctr) { - WERROR result; /* enum printers */ - result = cli_spoolss_enum_printers(cli, mem_ctx, name, flags, + result = rpccli_spoolss_enum_printers(pipe_hnd, mem_ctx, name, flags, level, num_printers, ctr); if (!W_ERROR_IS_OK(result)) { @@ -832,16 +833,17 @@ net_spoolss_enum_printers(struct cli_state *cli, TALLOC_CTX *mem_ctx, return True; } - -static BOOL -net_spoolss_open_printer_ex(struct cli_state *cli, TALLOC_CTX *mem_ctx, - const char *printername, uint32 access_required, - const char *username, POLICY_HND *hnd) +static BOOL net_spoolss_open_printer_ex(struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + const char *printername, + uint32 access_required, + const char *username, + POLICY_HND *hnd) { WERROR result; fstring servername, printername2; - slprintf(servername, sizeof(servername)-1, "\\\\%s", cli->desthost); + slprintf(servername, sizeof(servername)-1, "\\\\%s", pipe_hnd->cli->desthost); fstrcpy(printername2, servername); fstrcat(printername2, "\\"); @@ -851,7 +853,7 @@ net_spoolss_open_printer_ex(struct cli_state *cli, TALLOC_CTX *mem_ctx, servername, username, printername2, access_required)); /* open printer */ - result = cli_spoolss_open_printer_ex(cli, mem_ctx, printername2, + result = rpccli_spoolss_open_printer_ex(pipe_hnd, mem_ctx, printername2, "", access_required, servername, username, hnd); @@ -874,16 +876,16 @@ net_spoolss_open_printer_ex(struct cli_state *cli, TALLOC_CTX *mem_ctx, return True; } - -static BOOL -net_spoolss_getprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *hnd, uint32 level, - PRINTER_INFO_CTR *ctr) +static BOOL net_spoolss_getprinter(struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + POLICY_HND *hnd, + uint32 level, + PRINTER_INFO_CTR *ctr) { WERROR result; /* getprinter call */ - result = cli_spoolss_getprinter(cli, mem_ctx, hnd, level, ctr); + result = rpccli_spoolss_getprinter(pipe_hnd, mem_ctx, hnd, level, ctr); if (!W_ERROR_IS_OK(result)) { printf("cannot get printer-info: %s\n", dos_errstr(result)); @@ -893,16 +895,16 @@ net_spoolss_getprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, return True; } - -static BOOL -net_spoolss_setprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *hnd, uint32 level, - PRINTER_INFO_CTR *ctr) +static BOOL net_spoolss_setprinter(struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + POLICY_HND *hnd, + uint32 level, + PRINTER_INFO_CTR *ctr) { WERROR result; /* setprinter call */ - result = cli_spoolss_setprinter(cli, mem_ctx, hnd, level, ctr, 0); + result = rpccli_spoolss_setprinter(pipe_hnd, mem_ctx, hnd, level, ctr, 0); if (!W_ERROR_IS_OK(result)) { printf("cannot set printer-info: %s\n", dos_errstr(result)); @@ -913,14 +915,15 @@ net_spoolss_setprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx, } -static BOOL -net_spoolss_setprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *hnd, REGISTRY_VALUE *value) +static BOOL net_spoolss_setprinterdata(struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + POLICY_HND *hnd, + REGISTRY_VALUE *value) { WERROR result; /* setprinterdata call */ - result = cli_spoolss_setprinterdata(cli, mem_ctx, hnd, value); + result = rpccli_spoolss_setprinterdata(pipe_hnd, mem_ctx, hnd, value); if (!W_ERROR_IS_OK(result)) { printf ("unable to set printerdata: %s\n", dos_errstr(result)); @@ -931,15 +934,16 @@ net_spoolss_setprinterdata(struct cli_state *cli, TALLOC_CTX *mem_ctx, } -static BOOL -net_spoolss_enumprinterkey(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *hnd, const char *keyname, - uint16 **keylist) +static BOOL net_spoolss_enumprinterkey(struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + POLICY_HND *hnd, + const char *keyname, + uint16 **keylist) { WERROR result; /* enumprinterkey call */ - result = cli_spoolss_enumprinterkey(cli, mem_ctx, hnd, keyname, keylist, NULL); + result = rpccli_spoolss_enumprinterkey(pipe_hnd, mem_ctx, hnd, keyname, keylist, NULL); if (!W_ERROR_IS_OK(result)) { printf("enumprinterkey failed: %s\n", dos_errstr(result)); @@ -949,17 +953,17 @@ net_spoolss_enumprinterkey(struct cli_state *cli, TALLOC_CTX *mem_ctx, return True; } - -static BOOL -net_spoolss_enumprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx, - uint32 offered, - POLICY_HND *hnd, const char *keyname, - REGVAL_CTR *ctr) +static BOOL net_spoolss_enumprinterdataex(struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + uint32 offered, + POLICY_HND *hnd, + const char *keyname, + REGVAL_CTR *ctr) { WERROR result; /* enumprinterdataex call */ - result = cli_spoolss_enumprinterdataex(cli, mem_ctx, hnd, keyname, ctr); + result = rpccli_spoolss_enumprinterdataex(pipe_hnd, mem_ctx, hnd, keyname, ctr); if (!W_ERROR_IS_OK(result)) { printf("enumprinterdataex failed: %s\n", dos_errstr(result)); @@ -970,15 +974,16 @@ net_spoolss_enumprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx, } -static BOOL -net_spoolss_setprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *hnd, char *keyname, - REGISTRY_VALUE *value) +static BOOL net_spoolss_setprinterdataex(struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + POLICY_HND *hnd, + char *keyname, + REGISTRY_VALUE *value) { WERROR result; /* setprinterdataex call */ - result = cli_spoolss_setprinterdataex(cli, mem_ctx, hnd, + result = rpccli_spoolss_setprinterdataex(pipe_hnd, mem_ctx, hnd, keyname, value); if (!W_ERROR_IS_OK(result)) { @@ -989,17 +994,18 @@ net_spoolss_setprinterdataex(struct cli_state *cli, TALLOC_CTX *mem_ctx, return True; } - -static BOOL -net_spoolss_enumforms(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *hnd, int level, uint32 *num_forms, - FORM_1 **forms) +static BOOL net_spoolss_enumforms(struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + POLICY_HND *hnd, + int level, + uint32 *num_forms, + FORM_1 **forms) { WERROR result; /* enumforms call */ - result = cli_spoolss_enumforms(cli, mem_ctx, hnd, level, num_forms, forms); + result = rpccli_spoolss_enumforms(pipe_hnd, mem_ctx, hnd, level, num_forms, forms); if (!W_ERROR_IS_OK(result)) { printf("could not enum forms: %s\n", dos_errstr(result)); @@ -1009,18 +1015,17 @@ net_spoolss_enumforms(struct cli_state *cli, TALLOC_CTX *mem_ctx, return True; } - -static BOOL -net_spoolss_enumprinterdrivers (struct cli_state *cli, TALLOC_CTX *mem_ctx, - uint32 level, const char *env, - uint32 *num_drivers, - PRINTER_DRIVER_CTR *ctr) +static BOOL net_spoolss_enumprinterdrivers (struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + uint32 level, const char *env, + uint32 *num_drivers, + PRINTER_DRIVER_CTR *ctr) { WERROR result; /* enumprinterdrivers call */ - result = cli_spoolss_enumprinterdrivers( - cli, mem_ctx, level, + result = rpccli_spoolss_enumprinterdrivers( + pipe_hnd, mem_ctx, level, env, num_drivers, ctr); if (!W_ERROR_IS_OK(result)) { @@ -1031,9 +1036,7 @@ net_spoolss_enumprinterdrivers (struct cli_state *cli, TALLOC_CTX *mem_ctx, return True; } - -static BOOL -net_spoolss_getprinterdriver(struct cli_state *cli, +static BOOL net_spoolss_getprinterdriver(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, uint32 level, const char *env, int version, @@ -1042,8 +1045,8 @@ net_spoolss_getprinterdriver(struct cli_state *cli, WERROR result; /* getprinterdriver call */ - result = cli_spoolss_getprinterdriver( - cli, mem_ctx, hnd, level, + result = rpccli_spoolss_getprinterdriver( + pipe_hnd, mem_ctx, hnd, level, env, version, ctr); if (!W_ERROR_IS_OK(result)) { @@ -1060,15 +1063,14 @@ net_spoolss_getprinterdriver(struct cli_state *cli, } -static BOOL -net_spoolss_addprinterdriver(struct cli_state *cli, +static BOOL net_spoolss_addprinterdriver(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, uint32 level, PRINTER_DRIVER_CTR *ctr) { WERROR result; /* addprinterdriver call */ - result = cli_spoolss_addprinterdriver(cli, mem_ctx, level, ctr); + result = rpccli_spoolss_addprinterdriver(pipe_hnd, mem_ctx, level, ctr); /* be more verbose */ if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) { @@ -1087,10 +1089,14 @@ net_spoolss_addprinterdriver(struct cli_state *cli, * abstraction function to get uint32 num_printers and PRINTER_INFO_CTR ctr * for a single printer or for all printers depending on argc/argv **/ -static BOOL -get_printer_info(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int level, int argc, const char **argv, - uint32 *num_printers, PRINTER_INFO_CTR *ctr) + +static BOOL get_printer_info(struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int level, + int argc, + const char **argv, + uint32 *num_printers, + PRINTER_INFO_CTR *ctr) { POLICY_HND hnd; @@ -1098,7 +1104,7 @@ get_printer_info(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* no arguments given, enumerate all printers */ if (argc == 0) { - if (!net_spoolss_enum_printers(cli, mem_ctx, NULL, + if (!net_spoolss_enum_printers(pipe_hnd, mem_ctx, NULL, PRINTER_ENUM_LOCAL|PRINTER_ENUM_SHARED, level, num_printers, ctr)) return False; @@ -1108,16 +1114,16 @@ get_printer_info(struct cli_state *cli, TALLOC_CTX *mem_ctx, /* argument given, get a single printer by name */ - if (!net_spoolss_open_printer_ex(cli, mem_ctx, argv[0], - MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd)) + if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, argv[0], + MAXIMUM_ALLOWED_ACCESS, pipe_hnd->cli->user_name, &hnd)) return False; - if (!net_spoolss_getprinter(cli, mem_ctx, &hnd, level, ctr)) { - cli_spoolss_close_printer(cli, mem_ctx, &hnd); + if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, ctr)) { + rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd); return False; } - cli_spoolss_close_printer(cli, mem_ctx, &hnd); + rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd); *num_printers = 1; @@ -1128,7 +1134,6 @@ out: } - /** * List print-queues (including local printers that are not shared) * @@ -1144,9 +1149,14 @@ out: * * @return Normal NTSTATUS return. **/ -NTSTATUS rpc_printer_list_internals(const DOM_SID *domain_sid, const char *domain_name, - struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv) + +NTSTATUS rpc_printer_list_internals(const DOM_SID *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; uint32 i, num_printers; @@ -1156,7 +1166,7 @@ NTSTATUS rpc_printer_list_internals(const DOM_SID *domain_sid, const char *domai printf("listing printers\n"); - if (!get_printer_info(cli, mem_ctx, level, argc, argv, &num_printers, &ctr)) + if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr)) return nt_status; for (i = 0; i < num_printers; i++) { @@ -1174,7 +1184,6 @@ NTSTATUS rpc_printer_list_internals(const DOM_SID *domain_sid, const char *domai return NT_STATUS_OK; } - /** * List printer-drivers from a server * @@ -1190,9 +1199,14 @@ NTSTATUS rpc_printer_list_internals(const DOM_SID *domain_sid, const char *domai * * @return Normal NTSTATUS return. **/ -NTSTATUS rpc_printer_driver_list_internals(const DOM_SID *domain_sid, const char *domain_name, - struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv) + +NTSTATUS rpc_printer_driver_list_internals(const DOM_SID *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; uint32 i; @@ -1202,7 +1216,6 @@ NTSTATUS rpc_printer_driver_list_internals(const DOM_SID *domain_sid, const char ZERO_STRUCT(drv_ctr_enum); - printf("listing printer-drivers\n"); for (i=0; archi_table[i].long_archi!=NULL; i++) { @@ -1210,7 +1223,7 @@ NTSTATUS rpc_printer_driver_list_internals(const DOM_SID *domain_sid, const char uint32 num_drivers; /* enum remote drivers */ - if (!net_spoolss_enumprinterdrivers(cli, mem_ctx, level, + if (!net_spoolss_enumprinterdrivers(pipe_hnd, mem_ctx, level, archi_table[i].long_archi, &num_drivers, &drv_ctr_enum)) { @@ -1254,8 +1267,11 @@ done: * @return Normal NTSTATUS return. **/ -static NTSTATUS rpc_printer_publish_internals_args(struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv, uint32 action) +static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv, + uint32 action) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; uint32 i, num_printers; @@ -1267,7 +1283,7 @@ static NTSTATUS rpc_printer_publish_internals_args(struct cli_state *cli, TALLOC WERROR result; const char *action_str; - if (!get_printer_info(cli, mem_ctx, 2, argc, argv, &num_printers, &ctr)) + if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr)) return nt_status; for (i = 0; i < num_printers; i++) { @@ -1279,14 +1295,14 @@ static NTSTATUS rpc_printer_publish_internals_args(struct cli_state *cli, TALLOC sizeof(sharename), -1, STR_TERMINATE); /* open printer handle */ - if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, - PRINTER_ALL_ACCESS, cli->user_name, &hnd)) + if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, + PRINTER_ALL_ACCESS, pipe_hnd->cli->user_name, &hnd)) goto done; got_hnd = True; /* check for existing dst printer */ - if (!net_spoolss_getprinter(cli, mem_ctx, &hnd, level, &ctr_pub)) + if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &ctr_pub)) goto done; /* check action and set string */ @@ -1308,7 +1324,7 @@ static NTSTATUS rpc_printer_publish_internals_args(struct cli_state *cli, TALLOC ctr_pub.printers_7->action = action; - result = cli_spoolss_setprinter(cli, mem_ctx, &hnd, level, &ctr_pub, 0); + result = rpccli_spoolss_setprinter(pipe_hnd, mem_ctx, &hnd, level, &ctr_pub, 0); if (!W_ERROR_IS_OK(result) && (W_ERROR_V(result) != W_ERROR_V(WERR_IO_PENDING))) { printf("cannot set printer-info: %s\n", dos_errstr(result)); goto done; @@ -1321,30 +1337,42 @@ static NTSTATUS rpc_printer_publish_internals_args(struct cli_state *cli, TALLOC done: if (got_hnd) - cli_spoolss_close_printer(cli, mem_ctx, &hnd); + rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd); return nt_status; } -NTSTATUS rpc_printer_publish_publish_internals(const DOM_SID *domain_sid, const char *domain_name, - struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv) +NTSTATUS rpc_printer_publish_publish_internals(const DOM_SID *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv) { - return rpc_printer_publish_internals_args(cli, mem_ctx, argc, argv, SPOOL_DS_PUBLISH); + return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, SPOOL_DS_PUBLISH); } -NTSTATUS rpc_printer_publish_unpublish_internals(const DOM_SID *domain_sid, const char *domain_name, - struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv) +NTSTATUS rpc_printer_publish_unpublish_internals(const DOM_SID *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv) { - return rpc_printer_publish_internals_args(cli, mem_ctx, argc, argv, SPOOL_DS_UNPUBLISH); + return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, SPOOL_DS_UNPUBLISH); } -NTSTATUS rpc_printer_publish_update_internals(const DOM_SID *domain_sid, const char *domain_name, - struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv) +NTSTATUS rpc_printer_publish_update_internals(const DOM_SID *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv) { - return rpc_printer_publish_internals_args(cli, mem_ctx, argc, argv, SPOOL_DS_UPDATE); + return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, SPOOL_DS_UPDATE); } /** @@ -1362,9 +1390,14 @@ NTSTATUS rpc_printer_publish_update_internals(const DOM_SID *domain_sid, const c * * @return Normal NTSTATUS return. **/ -NTSTATUS rpc_printer_publish_list_internals(const DOM_SID *domain_sid, const char *domain_name, - struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv) + +NTSTATUS rpc_printer_publish_list_internals(const DOM_SID *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; uint32 i, num_printers; @@ -1376,7 +1409,7 @@ NTSTATUS rpc_printer_publish_list_internals(const DOM_SID *domain_sid, const cha BOOL got_hnd = False; int state; - if (!get_printer_info(cli, mem_ctx, 2, argc, argv, &num_printers, &ctr)) + if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr)) return nt_status; for (i = 0; i < num_printers; i++) { @@ -1390,14 +1423,14 @@ NTSTATUS rpc_printer_publish_list_internals(const DOM_SID *domain_sid, const cha sizeof(sharename), -1, STR_TERMINATE); /* open printer handle */ - if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, + if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, PRINTER_ALL_ACCESS, cli->user_name, &hnd)) goto done; got_hnd = True; /* check for existing dst printer */ - if (!net_spoolss_getprinter(cli, mem_ctx, &hnd, level, &ctr_pub)) + if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &ctr_pub)) goto done; rpcstr_pull(guid, ctr_pub.printers_7->guid.buffer, sizeof(guid), -1, STR_TERMINATE); @@ -1426,7 +1459,7 @@ NTSTATUS rpc_printer_publish_list_internals(const DOM_SID *domain_sid, const cha done: if (got_hnd) - cli_spoolss_close_printer(cli, mem_ctx, &hnd); + rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd); return nt_status; } @@ -1446,9 +1479,14 @@ done: * * @return Normal NTSTATUS return. **/ -NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, const char *domain_name, - struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv) + +NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv) { /* TODO: what now, info2 or info3 ? convince jerry that we should add clientside setacls level 3 at least @@ -1460,7 +1498,7 @@ NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, const pstring printername = "", sharename = ""; BOOL got_hnd_src = False; BOOL got_hnd_dst = False; - BOOL got_dst_spoolss_pipe = False; + struct rpc_pipe_client *pipe_hnd_dst = NULL; POLICY_HND hnd_src, hnd_dst; PRINTER_INFO_CTR ctr_src, ctr_dst, ctr_enum; struct cli_state *cli_dst = NULL; @@ -1470,13 +1508,13 @@ NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, const DEBUG(3,("copying printer ACLs\n")); /* connect destination PI_SPOOLSS */ - nt_status = connect_dst_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + nt_status = connect_dst_pipe(&cli_dst, &pipe_hnd_dst, PI_SPOOLSS); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; /* enum source printers */ - if (!get_printer_info(cli, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) { + if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } @@ -1487,7 +1525,6 @@ NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, const goto done; } - /* do something for all printers */ for (i = 0; i < num_printers; i++) { @@ -1510,30 +1547,27 @@ NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, const */ /* open src printer handle */ - if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, + if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) goto done; got_hnd_src = True; - /* open dst printer handle */ - if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, + if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename, PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst)) goto done; got_hnd_dst = True; - /* check for existing dst printer */ - if (!net_spoolss_getprinter(cli_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) + if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) goto done; /* check for existing src printer */ - if (!net_spoolss_getprinter(cli, mem_ctx, &hnd_src, 3, &ctr_src)) + if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, 3, &ctr_src)) goto done; - /* Copy Security Descriptor */ /* copy secdesc (info level 2) */ @@ -1543,7 +1577,7 @@ NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, const if (opt_verbose) display_sec_desc(ctr_dst.printers_2->secdesc); - if (!net_spoolss_setprinter(cli_dst, mem_ctx, &hnd_dst, 2, &ctr_dst)) + if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &ctr_dst)) goto done; DEBUGADD(1,("\tSetPrinter of SECDESC succeeded\n")); @@ -1551,12 +1585,12 @@ NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, const /* close printer handles here */ if (got_hnd_src) { - cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); got_hnd_src = False; } if (got_hnd_dst) { - cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); got_hnd_dst = False; } @@ -1566,20 +1600,20 @@ NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, const done: - if (got_hnd_src) - cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + if (got_hnd_src) { + rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); + } - if (got_hnd_dst) - cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + if (got_hnd_dst) { + rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); + } - if (got_dst_spoolss_pipe) { - cli_nt_session_close(cli_dst); + if (cli_dst) { cli_shutdown(cli_dst); } return nt_status; } - /** * Migrate printer-forms from a src server to the dst server * @@ -1595,9 +1629,14 @@ done: * * @return Normal NTSTATUS return. **/ -NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, const char *domain_name, - struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv) + +NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; WERROR result; @@ -1607,7 +1646,7 @@ NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, const ch pstring printername = "", sharename = ""; BOOL got_hnd_src = False; BOOL got_hnd_dst = False; - BOOL got_dst_spoolss_pipe = False; + struct rpc_pipe_client *pipe_hnd_dst = NULL; POLICY_HND hnd_src, hnd_dst; PRINTER_INFO_CTR ctr_enum, ctr_dst; uint32 num_forms; @@ -1619,13 +1658,13 @@ NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, const ch DEBUG(3,("copying forms\n")); /* connect destination PI_SPOOLSS */ - nt_status = connect_dst_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + nt_status = connect_dst_pipe(&cli_dst, &pipe_hnd_dst, PI_SPOOLSS); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; /* enum src printers */ - if (!get_printer_info(cli, mem_ctx, 2, argc, argv, &num_printers, &ctr_enum)) { + if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr_enum)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } @@ -1654,7 +1693,7 @@ NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, const ch /* open src printer handle */ - if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, + if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) goto done; @@ -1662,7 +1701,7 @@ NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, const ch /* open dst printer handle */ - if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, + if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename, PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) goto done; @@ -1670,11 +1709,11 @@ NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, const ch /* check for existing dst printer */ - if (!net_spoolss_getprinter(cli_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) + if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) goto done; /* finally migrate forms */ - if (!net_spoolss_enumforms(cli, mem_ctx, &hnd_src, level, &num_forms, &forms)) + if (!net_spoolss_enumforms(pipe_hnd, mem_ctx, &hnd_src, level, &num_forms, &forms)) goto done; DEBUG(1,("got %d forms for printer\n", num_forms)); @@ -1711,7 +1750,7 @@ NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, const ch /* FIXME: there might be something wrong with samba's builtin-forms */ - result = cli_spoolss_addform(cli_dst, mem_ctx, + result = rpccli_spoolss_addform(pipe_hnd_dst, mem_ctx, &hnd_dst, 1, &form); if (!W_ERROR_IS_OK(result)) { d_printf("\tAddForm form %d: [%s] refused.\n", @@ -1725,12 +1764,12 @@ NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, const ch /* close printer handles here */ if (got_hnd_src) { - cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); got_hnd_src = False; } if (got_hnd_dst) { - cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); got_hnd_dst = False; } } @@ -1740,20 +1779,17 @@ NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, const ch done: if (got_hnd_src) - cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); if (got_hnd_dst) - cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); - if (got_dst_spoolss_pipe) { - cli_nt_session_close(cli_dst); + if (cli_dst) { cli_shutdown(cli_dst); } return nt_status; - } - /** * Migrate printer-drivers from a src server to the dst server * @@ -1769,9 +1805,14 @@ done: * * @return Normal NTSTATUS return. **/ -NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const char *domain_name, - struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv) + +NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; uint32 i, p; @@ -1780,9 +1821,9 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const pstring printername = "", sharename = ""; BOOL got_hnd_src = False; BOOL got_hnd_dst = False; - BOOL got_dst_spoolss_pipe = False; BOOL got_src_driver_share = False; BOOL got_dst_driver_share = False; + struct rpc_pipe_client *pipe_hnd_dst = NULL; POLICY_HND hnd_src, hnd_dst; PRINTER_DRIVER_CTR drv_ctr_src, drv_ctr_dst; PRINTER_INFO_CTR info_ctr_enum, info_ctr_dst; @@ -1799,7 +1840,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const DEBUG(3,("copying printer-drivers\n")); - nt_status = connect_dst_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + nt_status = connect_dst_pipe(&cli_dst, &pipe_hnd_dst, PI_SPOOLSS); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; @@ -1823,7 +1864,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const /* enum src printers */ - if (!get_printer_info(cli, mem_ctx, 2, argc, argv, &num_printers, &info_ctr_enum)) { + if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &info_ctr_enum)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } @@ -1851,20 +1892,20 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const printername, sharename); /* open dst printer handle */ - if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, + if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename, PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) goto done; got_hnd_dst = True; /* check for existing dst printer */ - if (!net_spoolss_getprinter(cli_dst, mem_ctx, &hnd_dst, 2, &info_ctr_dst)) + if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_ctr_dst)) goto done; /* open src printer handle */ - if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, - MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) + if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, + MAXIMUM_ALLOWED_ACCESS, pipe_hnd->cli->user_name, &hnd_src)) goto done; got_hnd_src = True; @@ -1876,7 +1917,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const for (i=0; archi_table[i].long_archi!=NULL; i++) { /* getdriver src */ - if (!net_spoolss_getprinterdriver(cli, mem_ctx, &hnd_src, + if (!net_spoolss_getprinterdriver(pipe_hnd, mem_ctx, &hnd_src, level, archi_table[i].long_archi, archi_table[i].version, &drv_ctr_src)) continue; @@ -1903,7 +1944,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const /* adddriver dst */ - if (!net_spoolss_addprinterdriver(cli_dst, mem_ctx, level, &drv_ctr_src)) { + if (!net_spoolss_addprinterdriver(pipe_hnd_dst, mem_ctx, level, &drv_ctr_src)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } @@ -1922,7 +1963,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const /* setdriver dst */ init_unistr(&info_ctr_dst.printers_2->drivername, drivername); - if (!net_spoolss_setprinter(cli_dst, mem_ctx, &hnd_dst, 2, &info_ctr_dst)) { + if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_ctr_dst)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } @@ -1932,13 +1973,13 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const /* close dst */ if (got_hnd_dst) { - cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); got_hnd_dst = False; } /* close src */ if (got_hnd_src) { - cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); got_hnd_src = False; } } @@ -1948,13 +1989,12 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, const done: if (got_hnd_src) - cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); if (got_hnd_dst) - cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); - if (got_dst_spoolss_pipe) { - cli_nt_session_close(cli_dst); + if (cli_dst) { cli_shutdown(cli_dst); } @@ -1968,7 +2008,6 @@ done: } - /** * Migrate printer-queues from a src to the dst server * (requires a working "addprinter command" to be installed for the local smbd) @@ -1985,9 +2024,14 @@ done: * * @return Normal NTSTATUS return. **/ -NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, const char *domain_name, - struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv) + +NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv) { WERROR result; NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; @@ -1999,18 +2043,18 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, const pstring printername, sharename; BOOL got_hnd_src = False; BOOL got_hnd_dst = False; - BOOL got_dst_spoolss_pipe = False; + struct rpc_pipe_client *pipe_hnd_dst = NULL; DEBUG(3,("copying printers\n")); /* connect destination PI_SPOOLSS */ - nt_status = connect_dst_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + nt_status = connect_dst_pipe(&cli_dst, &pipe_hnd_dst, PI_SPOOLSS); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; /* enum printers */ - if (!get_printer_info(cli, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) { + if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } @@ -2039,7 +2083,7 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, const /* open dst printer handle */ - if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, + if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename, PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) { DEBUG(1,("could not open printer: %s\n", sharename)); @@ -2049,18 +2093,18 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, const /* check for existing dst printer */ - if (!net_spoolss_getprinter(cli_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) { + if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) { printf ("could not get printer, creating printer.\n"); } else { DEBUG(1,("printer already exists: %s\n", sharename)); /* close printer handles here */ if (got_hnd_src) { - cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); got_hnd_src = False; } if (got_hnd_dst) { - cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); got_hnd_dst = False; } continue; @@ -2071,21 +2115,21 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, const we first need a handle for that */ /* open src printer handle */ - if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, + if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) goto done; got_hnd_src = True; /* getprinter on the src server */ - if (!net_spoolss_getprinter(cli, mem_ctx, &hnd_src, level, &ctr_src)) + if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, level, &ctr_src)) goto done; /* copy each src printer to a dst printer 1:1, maybe some values have to be changed though */ d_printf("creating printer: %s\n", printername); - result = cli_spoolss_addprinterex (cli_dst, mem_ctx, level, &ctr_src); + result = rpccli_spoolss_addprinterex (pipe_hnd_dst, mem_ctx, level, &ctr_src); if (W_ERROR_IS_OK(result)) d_printf ("printer [%s] successfully added.\n", printername); @@ -2098,12 +2142,12 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, const /* close printer handles here */ if (got_hnd_src) { - cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); got_hnd_src = False; } if (got_hnd_dst) { - cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); got_hnd_dst = False; } } @@ -2112,19 +2156,17 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, const done: if (got_hnd_src) - cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); if (got_hnd_dst) - cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); - if (got_dst_spoolss_pipe) { - cli_nt_session_close(cli_dst); + if (cli_dst) { cli_shutdown(cli_dst); } return nt_status; } - /** * Migrate Printer-Settings from a src server to the dst server * (for this to work, printers and drivers already have to be migrated earlier) @@ -2141,9 +2183,14 @@ done: * * @return Normal NTSTATUS return. **/ -NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const char *domain_name, - struct cli_state *cli, TALLOC_CTX *mem_ctx, - int argc, const char **argv) + +NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, + const char *domain_name, + struct cli_state *cli, + struct rpc_pipe_client *pipe_hnd, + TALLOC_CTX *mem_ctx, + int argc, + const char **argv) { /* FIXME: Here the nightmare begins */ @@ -2156,7 +2203,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const pstring printername = "", sharename = ""; BOOL got_hnd_src = False; BOOL got_hnd_dst = False; - BOOL got_dst_spoolss_pipe = False; + struct rpc_pipe_client *pipe_hnd_dst = NULL; POLICY_HND hnd_src, hnd_dst; PRINTER_INFO_CTR ctr_enum, ctr_dst, ctr_dst_publish; REGVAL_CTR *reg_ctr; @@ -2171,13 +2218,13 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const DEBUG(3,("copying printer settings\n")); /* connect destination PI_SPOOLSS */ - nt_status = connect_dst_pipe(&cli_dst, PI_SPOOLSS, &got_dst_spoolss_pipe); + nt_status = connect_dst_pipe(&cli_dst, &pipe_hnd_dst, PI_SPOOLSS); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; /* enum src printers */ - if (!get_printer_info(cli, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) { + if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } @@ -2210,7 +2257,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const /* open src printer handle */ - if (!net_spoolss_open_printer_ex(cli, mem_ctx, sharename, + if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) goto done; @@ -2218,7 +2265,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const /* open dst printer handle */ - if (!net_spoolss_open_printer_ex(cli_dst, mem_ctx, sharename, + if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename, PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst)) goto done; @@ -2226,7 +2273,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const /* check for existing dst printer */ - if (!net_spoolss_getprinter(cli_dst, mem_ctx, &hnd_dst, + if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) goto done; @@ -2245,13 +2292,13 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const if (ctr_enum.printers_2[i].attributes & PRINTER_ATTRIBUTE_PUBLISHED) { /* check for existing dst printer */ - if (!net_spoolss_getprinter(cli_dst, mem_ctx, &hnd_dst, 7, &ctr_dst_publish)) + if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 7, &ctr_dst_publish)) goto done; ctr_dst_publish.printers_7->action = SPOOL_DS_PUBLISH; /* ignore False from setprinter due to WERR_IO_PENDING */ - net_spoolss_setprinter(cli_dst, mem_ctx, &hnd_dst, 7, &ctr_dst_publish); + net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 7, &ctr_dst_publish); DEBUG(3,("republished printer\n")); } @@ -2278,7 +2325,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const init_unistr(&ctr_dst.printers_2->devmode->devicename, devicename); #endif - if (!net_spoolss_setprinter(cli_dst, mem_ctx, &hnd_dst, + if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) goto done; @@ -2288,13 +2335,13 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const /* STEP 2: COPY REGISTRY VALUES */ /* please keep in mind that samba parse_spools gives horribly - crippled results when used to cli_spoolss_enumprinterdataex + crippled results when used to rpccli_spoolss_enumprinterdataex a win2k3-server. (Bugzilla #1851) FIXME: IIRC I've seen it too on a win2k-server */ /* enumerate data on src handle */ - result = cli_spoolss_enumprinterdata(cli, mem_ctx, &hnd_src, p, 0, 0, + result = rpccli_spoolss_enumprinterdata(pipe_hnd, mem_ctx, &hnd_src, p, 0, 0, &val_needed, &data_needed, NULL); /* loop for all printerdata of "PrinterDriverData" */ @@ -2302,8 +2349,8 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const REGISTRY_VALUE value; - result = cli_spoolss_enumprinterdata( - cli, mem_ctx, &hnd_src, p++, val_needed, + result = rpccli_spoolss_enumprinterdata( + pipe_hnd, mem_ctx, &hnd_src, p++, val_needed, data_needed, 0, 0, &value); /* loop for all reg_keys */ @@ -2314,7 +2361,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const display_reg_value(SPOOL_PRINTERDATA_KEY, value); /* set_value */ - if (!net_spoolss_setprinterdata(cli_dst, mem_ctx, + if (!net_spoolss_setprinterdata(pipe_hnd_dst, mem_ctx, &hnd_dst, &value)) goto done; @@ -2330,7 +2377,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const respond to enumprinterkey, win2k does, so continue in case of an error */ - if (!net_spoolss_enumprinterkey(cli, mem_ctx, &hnd_src, "", &keylist)) { + if (!net_spoolss_enumprinterkey(pipe_hnd, mem_ctx, &hnd_src, "", &keylist)) { printf("got no key-data\n"); continue; } @@ -2355,7 +2402,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const return NT_STATUS_NO_MEMORY; /* enumerate all src subkeys */ - if (!net_spoolss_enumprinterdataex(cli, mem_ctx, 0, + if (!net_spoolss_enumprinterdataex(pipe_hnd, mem_ctx, 0, &hnd_src, subkey, reg_ctr)) goto done; @@ -2426,7 +2473,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const display_reg_value(subkey, value); /* here we have to set all subkeys on the dst server */ - if (!net_spoolss_setprinterdataex(cli_dst, mem_ctx, &hnd_dst, + if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst, subkey, &value)) goto done; @@ -2436,7 +2483,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const display_reg_value(subkey, *(reg_ctr->values[j])); /* here we have to set all subkeys on the dst server */ - if (!net_spoolss_setprinterdataex(cli_dst, mem_ctx, &hnd_dst, + if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst, subkey, reg_ctr->values[j])) goto done; @@ -2446,7 +2493,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const subkey, reg_ctr->values[j]->valuename)); } - + TALLOC_FREE( reg_ctr ); } @@ -2454,12 +2501,12 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, const /* close printer handles here */ if (got_hnd_src) { - cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); got_hnd_src = False; } if (got_hnd_dst) { - cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); got_hnd_dst = False; } @@ -2473,13 +2520,12 @@ done: SAFE_FREE(unc_name); if (got_hnd_src) - cli_spoolss_close_printer(cli, mem_ctx, &hnd_src); + rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); if (got_hnd_dst) - cli_spoolss_close_printer(cli_dst, mem_ctx, &hnd_dst); + rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); - if (got_dst_spoolss_pipe) { - cli_nt_session_close(cli_dst); + if (cli_dst) { cli_shutdown(cli_dst); } return nt_status; -- cgit From c42be9fd38556a1cc2e16c8d763a592beb863806 Mon Sep 17 00:00:00 2001 From: Lars Müller Date: Tue, 17 Jan 2006 21:22:00 +0000 Subject: r12986: Use d_fprintf(stderr, ...) for any error message in net. All 'usage' messages are still printed to stdout. Fix some compiler warnings for system() calls where we didn't used the return code. Add appropriate error messages and return with the error code we got from system() or NT_STATUS_UNSUCCESSFUL. (This used to be commit f650e3bdafc4c6bcd7eb4bcf8b6b885b979919eb) --- source3/utils/net_rpc_printer.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index d8f3099dec..5e282403a2 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -403,14 +403,14 @@ NTSTATUS net_copy_fileattr(TALLOC_CTX *mem_ctx, /* closing files */ if (!cli_close(cli_share_src, fnum_src)) { - d_printf("could not close %s on originating server: %s\n", + d_fprintf(stderr, "could not close %s on originating server: %s\n", is_file?"file":"dir", cli_errstr(cli_share_src)); nt_status = cli_nt_error(cli_share_src); goto out; } if (!cli_close(cli_share_dst, fnum_dst)) { - d_printf("could not close %s on destination server: %s\n", + d_fprintf(stderr, "could not close %s on destination server: %s\n", is_file?"file":"dir", cli_errstr(cli_share_dst)); nt_status = cli_nt_error(cli_share_dst); goto out; @@ -504,7 +504,7 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, /* allocate memory */ if (!(data = (char *)SMB_MALLOC(read_size))) { - d_printf("malloc fail for size %d\n", read_size); + d_fprintf(stderr, "malloc fail for size %d\n", read_size); nt_status = NT_STATUS_NO_MEMORY; goto out; } @@ -538,7 +538,7 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, nread + start, n); if (n != ret) { - d_printf("Error writing file: %s\n", + d_fprintf(stderr, "Error writing file: %s\n", cli_errstr(cli_share_dst)); nt_status = cli_nt_error(cli_share_dst); goto out; @@ -561,7 +561,7 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, } if (!cli_chkpath(cli_share_dst, dst_name)) { - d_printf("cannot check for directory %s: %s\n", + d_fprintf(stderr, "cannot check for directory %s: %s\n", dst_name, cli_errstr(cli_share_dst)); goto out; } @@ -570,14 +570,14 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, /* closing files */ if (!cli_close(cli_share_src, fnum_src)) { - d_printf("could not close file on originating server: %s\n", + d_fprintf(stderr, "could not close file on originating server: %s\n", cli_errstr(cli_share_src)); nt_status = cli_nt_error(cli_share_src); goto out; } if (is_file && !cli_close(cli_share_dst, fnum_dst)) { - d_printf("could not close file on destination server: %s\n", + d_fprintf(stderr, "could not close file on destination server: %s\n", cli_errstr(cli_share_dst)); nt_status = cli_nt_error(cli_share_dst); goto out; @@ -704,7 +704,7 @@ static NTSTATUS check_arch_dir(struct cli_state *cli_share, const char *short_ar } if (!cli_chkpath(cli_share, dir)) { - d_printf("cannot check %s: %s\n", + d_fprintf(stderr, "cannot check %s: %s\n", dir, cli_errstr(cli_share)); goto out; } @@ -859,13 +859,13 @@ static BOOL net_spoolss_open_printer_ex(struct rpc_pipe_client *pipe_hnd, /* be more verbose */ if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) { - d_printf("no access to printer [%s] on [%s] for user [%s] granted\n", + d_fprintf(stderr, "no access to printer [%s] on [%s] for user [%s] granted\n", printername2, servername, username); return False; } if (!W_ERROR_IS_OK(result)) { - d_printf("cannot open printer %s on server %s: %s\n", + d_fprintf(stderr, "cannot open printer %s on server %s: %s\n", printername2, servername, dos_errstr(result)); return False; } @@ -2134,9 +2134,9 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, if (W_ERROR_IS_OK(result)) d_printf ("printer [%s] successfully added.\n", printername); else if (W_ERROR_V(result) == W_ERROR_V(WERR_PRINTER_ALREADY_EXISTS)) - d_printf ("printer [%s] already exists.\n", printername); + d_fprintf (stderr, "printer [%s] already exists.\n", printername); else { - printf ("could not create printer\n"); + d_fprintf (stderr, "could not create printer [%s]\n", printername); goto done; } -- cgit From 9f2e29799eac96068fa033bdc4a9df5a82ec470d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 6 Mar 2006 15:22:00 +0000 Subject: r13864: Some cleanup and the samr set security object function client-side. Guenther (This used to be commit 0ae3fddf95a95ec8a2f4d52e1276c1721b33ddfd) --- source3/utils/net_rpc_printer.c | 130 ---------------------------------------- 1 file changed, 130 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 5e282403a2..9bae6a9b4e 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -42,136 +42,6 @@ static const struct table_node archi_table[]= { }; -/** - * The display-functions for Security-Descriptors were taken from rpcclient - * - * They reside here for debugging purpose and should - * possibly be removed later on - * - **/ - -/**************************************************************************** - Convert a security permissions into a string. -****************************************************************************/ - -char *get_sec_mask_str(uint32 type) -{ - static fstring typestr=""; - - typestr[0] = 0; - - if (type & GENERIC_ALL_ACCESS) - fstrcat(typestr, "Generic all access "); - if (type & GENERIC_EXECUTE_ACCESS) - fstrcat(typestr, "Generic execute access "); - if (type & GENERIC_WRITE_ACCESS) - fstrcat(typestr, "Generic write access "); - if (type & GENERIC_READ_ACCESS) - fstrcat(typestr, "Generic read access "); - if (type & MAXIMUM_ALLOWED_ACCESS) - fstrcat(typestr, "MAXIMUM_ALLOWED_ACCESS "); - if (type & SYSTEM_SECURITY_ACCESS) - fstrcat(typestr, "SYSTEM_SECURITY_ACCESS "); - if (type & SYNCHRONIZE_ACCESS) - fstrcat(typestr, "SYNCHRONIZE_ACCESS "); - if (type & WRITE_OWNER_ACCESS) - fstrcat(typestr, "WRITE_OWNER_ACCESS "); - if (type & WRITE_DAC_ACCESS) - fstrcat(typestr, "WRITE_DAC_ACCESS "); - if (type & READ_CONTROL_ACCESS) - fstrcat(typestr, "READ_CONTROL_ACCESS "); - if (type & DELETE_ACCESS) - fstrcat(typestr, "DELETE_ACCESS "); - - printf("\t\tSpecific bits: 0x%lx\n", (unsigned long)type&SPECIFIC_RIGHTS_MASK); - - return typestr; -} - -/**************************************************************************** - Display sec_ace structure. - ****************************************************************************/ - -void display_sec_ace(SEC_ACE *ace) -{ - fstring sid_str; - - printf("\tACE\n\t\ttype: "); - switch (ace->type) { - case SEC_ACE_TYPE_ACCESS_ALLOWED: - printf("ACCESS ALLOWED"); - break; - case SEC_ACE_TYPE_ACCESS_DENIED: - printf("ACCESS DENIED"); - break; - case SEC_ACE_TYPE_SYSTEM_AUDIT: - printf("SYSTEM AUDIT"); - break; - case SEC_ACE_TYPE_SYSTEM_ALARM: - printf("SYSTEM ALARM"); - break; - default: - printf("????"); - break; - } - printf(" (%d) flags: %d\n", ace->type, ace->flags); - printf("\t\tPermissions: 0x%x: %s\n", ace->info.mask, get_sec_mask_str(ace->info.mask)); - - sid_to_string(sid_str, &ace->trustee); - printf("\t\tSID: %s\n\n", sid_str); -} - -/**************************************************************************** - Display sec_acl structure. - ****************************************************************************/ - -void display_sec_acl(SEC_ACL *sec_acl) -{ - int i; - - printf("\tACL\tNum ACEs:\t%d\trevision:\t%x\n", - sec_acl->num_aces, sec_acl->revision); - printf("\t---\n"); - - if (sec_acl->size != 0 && sec_acl->num_aces != 0) - for (i = 0; i < sec_acl->num_aces; i++) - display_sec_ace(&sec_acl->ace[i]); - -} - -/**************************************************************************** - Display sec_desc structure. - ****************************************************************************/ - -void display_sec_desc(SEC_DESC *sec) -{ - fstring sid_str; - - if (sec == NULL) - return; - - if (sec->sacl) { - printf("SACL\n"); - display_sec_acl(sec->sacl); - } - - if (sec->dacl) { - printf("DACL\n"); - display_sec_acl(sec->dacl); - } - - if (sec->owner_sid) { - sid_to_string(sid_str, sec->owner_sid); - printf("\tOwner SID:\t%s\n", sid_str); - } - - if (sec->grp_sid) { - sid_to_string(sid_str, sec->grp_sid); - printf("\tParent SID:\t%s\n", sid_str); - } -} - - /** * This display-printdriver-functions was borrowed from rpcclient/cmd_spoolss.c. * It is here for debugging purpose and should be removed later on. -- cgit From fa57a318b452ba7832492ee7e2ac0c28749881e0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 15 Mar 2006 03:00:49 +0000 Subject: r14416: Remove deadcode. Coverity #198. Jeremy. (This used to be commit 7fc61f5a63c982cfd0fbe1838979ba7be8f69fca) --- source3/utils/net_rpc_printer.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 9bae6a9b4e..8808d549ac 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -1922,7 +1922,6 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, if (!NT_STATUS_IS_OK(nt_status)) return nt_status; - /* enum printers */ if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) { nt_status = NT_STATUS_UNSUCCESSFUL; @@ -1951,7 +1950,6 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, d_printf("migrating printer queue for: [%s] / [%s]\n", printername, sharename); - /* open dst printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename, PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) { @@ -1961,18 +1959,12 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, got_hnd_dst = True; } - /* check for existing dst printer */ if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) { printf ("could not get printer, creating printer.\n"); } else { DEBUG(1,("printer already exists: %s\n", sharename)); - /* close printer handles here */ - if (got_hnd_src) { - rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); - got_hnd_src = False; - } - + /* close printer handle here - dst only, not got src yet. */ if (got_hnd_dst) { rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); got_hnd_dst = False; @@ -1980,7 +1972,6 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, continue; } - /* now get again src printer ctr via getprinter, we first need a handle for that */ @@ -1995,7 +1986,6 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, level, &ctr_src)) goto done; - /* copy each src printer to a dst printer 1:1, maybe some values have to be changed though */ d_printf("creating printer: %s\n", printername); -- cgit From fbdcf2663b56007a438ac4f0d8d82436b1bfe688 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Jul 2006 18:01:26 +0000 Subject: r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need to do the upper layer directories but this is what everyone is waiting for.... Jeremy. (This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8) --- source3/utils/net_rpc_printer.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 8808d549ac..50ab50bace 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -129,18 +129,23 @@ static void display_reg_value(const char *subkey, REGISTRY_VALUE value) break; case REG_MULTI_SZ: { - uint16 *curstr = (uint16 *) value.data_p; - uint8 *start = value.data_p; - d_printf("\t[%s:%s]: REG_MULTI_SZ:\n", subkey, value.valuename); - while ((*curstr != 0) && - ((uint8 *) curstr < start + value.size)) { - rpcstr_pull(text, curstr, sizeof(text), -1, - STR_TERMINATE); - d_printf("%s\n", text); - curstr += strlen(text) + 1; + int i, num_values; + char **values; + + if (!NT_STATUS_IS_OK(reg_pull_multi_sz(NULL, value.data_p, + value.size, + &num_values, + &values))) { + d_printf("reg_pull_multi_sz failed\n"); + break; + } + + for (i=0; i Date: Sun, 30 Jul 2006 16:36:56 +0000 Subject: r17316: More C++ warnings -- 456 left (This used to be commit 1e4ee728df7eeafc1b4d533240acb032f73b4f5c) --- source3/utils/net_rpc_printer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 50ab50bace..dc3cb42dbe 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -2171,7 +2171,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, if (ctr_enum.printers_2[i].devmode != NULL) { /* copy devmode (info level 2) */ - ctr_dst.printers_2->devmode = + ctr_dst.printers_2->devmode = (struct devicemode *) TALLOC_MEMDUP(mem_ctx, ctr_enum.printers_2[i].devmode, sizeof(DEVICEMODE)); @@ -2332,7 +2332,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, value.type = REG_SZ; value.size = data.uni_str_len * 2; - value.data_p = TALLOC_MEMDUP(mem_ctx, data.buffer, value.size); + value.data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, data.buffer, value.size); if (opt_verbose) display_reg_value(subkey, value); -- cgit From 202f63e476fc1dc60d9f1271673b292288cfb436 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 21 Nov 2006 02:21:45 +0000 Subject: r19811: Decode REG_MULTI_SZ and REG_BINARY (This used to be commit 679330175185f8504bb5968339dcc7cb20d9140c) --- source3/utils/net_rpc_printer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index dc3cb42dbe..5a18253aaf 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -129,7 +129,7 @@ static void display_reg_value(const char *subkey, REGISTRY_VALUE value) break; case REG_MULTI_SZ: { - int i, num_values; + uint32 i, num_values; char **values; if (!NT_STATUS_IS_OK(reg_pull_multi_sz(NULL, value.data_p, -- cgit From ecf90c495eb850cd6f376fb4e090640b69f0c029 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 1 Dec 2006 20:01:09 +0000 Subject: r19991: Sorry for this 2000-liner... The main thing here is a rewrite of srv_winreg_nt.c. The core functionality has moved to registry/reg_api.c which is then usable by the rest of Samba as well. On that way it fixes creating keys with more than one element in the path. This did not work before. Two things that sneaked in (sorry :-) is the change of some routines from NTSTATUS to WERROR the removed "parent" argument to regkey_open_internal. Volker (This used to be commit fea52801de8c7b85c578d200c599475680c5339f) --- source3/utils/net_rpc_printer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 5a18253aaf..d0b55454f9 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -132,10 +132,9 @@ static void display_reg_value(const char *subkey, REGISTRY_VALUE value) uint32 i, num_values; char **values; - if (!NT_STATUS_IS_OK(reg_pull_multi_sz(NULL, value.data_p, - value.size, - &num_values, - &values))) { + if (!W_ERROR_IS_OK(reg_pull_multi_sz(NULL, value.data_p, + value.size, &num_values, + &values))) { d_printf("reg_pull_multi_sz failed\n"); break; } -- cgit From 79de0ad9463a5cd64978beae37df79fbb4f74632 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 30 Apr 2007 01:34:28 +0000 Subject: r22588: Make all uses of TALLOC_MEMDUP consistent. Jeremy. (This used to be commit 8ad13718af0ba1fcb10a6f1631b1ed3cb8d11175) --- source3/utils/net_rpc_printer.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index d0b55454f9..63ea50a67b 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -2331,7 +2331,11 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, value.type = REG_SZ; value.size = data.uni_str_len * 2; - value.data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, data.buffer, value.size); + if (value.size) { + value.data_p = (uint8 *)TALLOC_MEMDUP(mem_ctx, data.buffer, value.size); + } else { + value.data_p = NULL; + } if (opt_verbose) display_reg_value(subkey, value); -- cgit From 8b79106829034ff543406b68fd2ce6e84a28b5e4 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 16 May 2007 11:57:37 +0000 Subject: r22932: Use the same symbol in sizeof and cast for talloc. (This used to be commit 550498e68db9305e31da38dbc9c642961418a8b0) --- source3/utils/net_rpc_printer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 63ea50a67b..6f9d52ddec 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -2170,7 +2170,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, if (ctr_enum.printers_2[i].devmode != NULL) { /* copy devmode (info level 2) */ - ctr_dst.printers_2->devmode = (struct devicemode *) + ctr_dst.printers_2->devmode = (DEVICEMODE *) TALLOC_MEMDUP(mem_ctx, ctr_enum.printers_2[i].devmode, sizeof(DEVICEMODE)); -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/utils/net_rpc_printer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 6f9d52ddec..8c911b4207 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -5,7 +5,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/utils/net_rpc_printer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 8c911b4207..1f0936cf96 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + along with this program. If not, see . */ #include "includes.h" #include "utils/net.h" -- cgit From 6824731cb09dcf736f5282d55723fffb253cec95 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 29 Aug 2007 14:08:29 +0000 Subject: r24783: Remove unused off_t type. Guenther (This used to be commit 85c816c27f2b9d20dfaf411b12ec1803a49574ce) --- source3/utils/net_rpc_printer.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 1f0936cf96..cba88370db 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -333,7 +333,6 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, static int io_bufsize = 64512; int read_size = io_bufsize; char *data = NULL; - off_t start = 0; off_t nread = 0; @@ -401,14 +400,14 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, /* copying file */ int n, ret; - n = cli_read(cli_share_src, fnum_src, data, nread + start, + n = cli_read(cli_share_src, fnum_src, data, nread, read_size); if (n <= 0) break; ret = cli_write(cli_share_dst, fnum_dst, 0, data, - nread + start, n); + nread, n); if (n != ret) { d_fprintf(stderr, "Error writing file: %s\n", -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/utils/net_rpc_printer.c | 66 ++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index cba88370db..20821cd2e6 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -63,7 +63,7 @@ static void display_print_driver_3(DRIVER_INFO_3 *i1) fstring defaultdatatype = ""; int length=0; - BOOL valid = True; + bool valid = True; if (i1 == NULL) return; @@ -172,8 +172,8 @@ NTSTATUS net_copy_fileattr(TALLOC_CTX *mem_ctx, struct cli_state *cli_share_src, struct cli_state *cli_share_dst, const char *src_name, const char *dst_name, - BOOL copy_acls, BOOL copy_attrs, - BOOL copy_timestamps, BOOL is_file) + bool copy_acls, bool copy_attrs, + bool copy_timestamps, bool is_file) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; int fnum_src = 0; @@ -324,8 +324,8 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, struct cli_state *cli_share_src, struct cli_state *cli_share_dst, const char *src_name, const char *dst_name, - BOOL copy_acls, BOOL copy_attrs, - BOOL copy_timestamps, BOOL is_file) + bool copy_acls, bool copy_attrs, + bool copy_timestamps, bool is_file) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; int fnum_src = 0; @@ -608,7 +608,7 @@ static NTSTATUS copy_print_driver_3(TALLOC_CTX *mem_ctx, { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; int length = 0; - BOOL valid = True; + bool valid = True; fstring name = ""; fstring driverpath = ""; @@ -683,7 +683,7 @@ static NTSTATUS copy_print_driver_3(TALLOC_CTX *mem_ctx, * **/ -static BOOL net_spoolss_enum_printers(struct rpc_pipe_client *pipe_hnd, +static bool net_spoolss_enum_printers(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, char *name, uint32 flags, @@ -705,7 +705,7 @@ static BOOL net_spoolss_enum_printers(struct rpc_pipe_client *pipe_hnd, return True; } -static BOOL net_spoolss_open_printer_ex(struct rpc_pipe_client *pipe_hnd, +static bool net_spoolss_open_printer_ex(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, const char *printername, uint32 access_required, @@ -748,7 +748,7 @@ static BOOL net_spoolss_open_printer_ex(struct rpc_pipe_client *pipe_hnd, return True; } -static BOOL net_spoolss_getprinter(struct rpc_pipe_client *pipe_hnd, +static bool net_spoolss_getprinter(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, uint32 level, @@ -767,7 +767,7 @@ static BOOL net_spoolss_getprinter(struct rpc_pipe_client *pipe_hnd, return True; } -static BOOL net_spoolss_setprinter(struct rpc_pipe_client *pipe_hnd, +static bool net_spoolss_setprinter(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, uint32 level, @@ -787,7 +787,7 @@ static BOOL net_spoolss_setprinter(struct rpc_pipe_client *pipe_hnd, } -static BOOL net_spoolss_setprinterdata(struct rpc_pipe_client *pipe_hnd, +static bool net_spoolss_setprinterdata(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, REGISTRY_VALUE *value) @@ -806,7 +806,7 @@ static BOOL net_spoolss_setprinterdata(struct rpc_pipe_client *pipe_hnd, } -static BOOL net_spoolss_enumprinterkey(struct rpc_pipe_client *pipe_hnd, +static bool net_spoolss_enumprinterkey(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, const char *keyname, @@ -825,7 +825,7 @@ static BOOL net_spoolss_enumprinterkey(struct rpc_pipe_client *pipe_hnd, return True; } -static BOOL net_spoolss_enumprinterdataex(struct rpc_pipe_client *pipe_hnd, +static bool net_spoolss_enumprinterdataex(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, uint32 offered, POLICY_HND *hnd, @@ -846,7 +846,7 @@ static BOOL net_spoolss_enumprinterdataex(struct rpc_pipe_client *pipe_hnd, } -static BOOL net_spoolss_setprinterdataex(struct rpc_pipe_client *pipe_hnd, +static bool net_spoolss_setprinterdataex(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, char *keyname, @@ -866,7 +866,7 @@ static BOOL net_spoolss_setprinterdataex(struct rpc_pipe_client *pipe_hnd, return True; } -static BOOL net_spoolss_enumforms(struct rpc_pipe_client *pipe_hnd, +static bool net_spoolss_enumforms(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, int level, @@ -887,7 +887,7 @@ static BOOL net_spoolss_enumforms(struct rpc_pipe_client *pipe_hnd, return True; } -static BOOL net_spoolss_enumprinterdrivers (struct rpc_pipe_client *pipe_hnd, +static bool net_spoolss_enumprinterdrivers (struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, uint32 level, const char *env, uint32 *num_drivers, @@ -908,7 +908,7 @@ static BOOL net_spoolss_enumprinterdrivers (struct rpc_pipe_client *pipe_hnd, return True; } -static BOOL net_spoolss_getprinterdriver(struct rpc_pipe_client *pipe_hnd, +static bool net_spoolss_getprinterdriver(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, uint32 level, const char *env, int version, @@ -935,7 +935,7 @@ static BOOL net_spoolss_getprinterdriver(struct rpc_pipe_client *pipe_hnd, } -static BOOL net_spoolss_addprinterdriver(struct rpc_pipe_client *pipe_hnd, +static bool net_spoolss_addprinterdriver(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, uint32 level, PRINTER_DRIVER_CTR *ctr) { @@ -962,7 +962,7 @@ static BOOL net_spoolss_addprinterdriver(struct rpc_pipe_client *pipe_hnd, * for a single printer or for all printers depending on argc/argv **/ -static BOOL get_printer_info(struct rpc_pipe_client *pipe_hnd, +static bool get_printer_info(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, int level, int argc, @@ -1151,7 +1151,7 @@ static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_ pstring printername, sharename; PRINTER_INFO_CTR ctr, ctr_pub; POLICY_HND hnd; - BOOL got_hnd = False; + bool got_hnd = False; WERROR result; const char *action_str; @@ -1278,7 +1278,7 @@ NTSTATUS rpc_printer_publish_list_internals(const DOM_SID *domain_sid, pstring guid; PRINTER_INFO_CTR ctr, ctr_pub; POLICY_HND hnd; - BOOL got_hnd = False; + bool got_hnd = False; int state; if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr)) @@ -1368,8 +1368,8 @@ NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, uint32 num_printers; uint32 level = 2; pstring printername = "", sharename = ""; - BOOL got_hnd_src = False; - BOOL got_hnd_dst = False; + bool got_hnd_src = False; + bool got_hnd_dst = False; struct rpc_pipe_client *pipe_hnd_dst = NULL; POLICY_HND hnd_src, hnd_dst; PRINTER_INFO_CTR ctr_src, ctr_dst, ctr_enum; @@ -1516,8 +1516,8 @@ NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, uint32 num_printers; uint32 level = 1; pstring printername = "", sharename = ""; - BOOL got_hnd_src = False; - BOOL got_hnd_dst = False; + bool got_hnd_src = False; + bool got_hnd_dst = False; struct rpc_pipe_client *pipe_hnd_dst = NULL; POLICY_HND hnd_src, hnd_dst; PRINTER_INFO_CTR ctr_enum, ctr_dst; @@ -1691,10 +1691,10 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, uint32 num_printers; uint32 level = 3; pstring printername = "", sharename = ""; - BOOL got_hnd_src = False; - BOOL got_hnd_dst = False; - BOOL got_src_driver_share = False; - BOOL got_dst_driver_share = False; + bool got_hnd_src = False; + bool got_hnd_dst = False; + bool got_src_driver_share = False; + bool got_dst_driver_share = False; struct rpc_pipe_client *pipe_hnd_dst = NULL; POLICY_HND hnd_src, hnd_dst; PRINTER_DRIVER_CTR drv_ctr_src, drv_ctr_dst; @@ -1913,8 +1913,8 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, struct cli_state *cli_dst = NULL; POLICY_HND hnd_dst, hnd_src; pstring printername, sharename; - BOOL got_hnd_src = False; - BOOL got_hnd_dst = False; + bool got_hnd_src = False; + bool got_hnd_dst = False; struct rpc_pipe_client *pipe_hnd_dst = NULL; DEBUG(3,("copying printers\n")); @@ -2063,8 +2063,8 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, uint32 num_printers, val_needed, data_needed; uint32 level = 2; pstring printername = "", sharename = ""; - BOOL got_hnd_src = False; - BOOL got_hnd_dst = False; + bool got_hnd_src = False; + bool got_hnd_dst = False; struct rpc_pipe_client *pipe_hnd_dst = NULL; POLICY_HND hnd_src, hnd_dst; PRINTER_INFO_CTR ctr_enum, ctr_dst, ctr_dst_publish; -- cgit From f88b7a076be74a29a3bf876b4e2705f4a1ecf42b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 24 Oct 2007 14:16:54 -0700 Subject: This is a large patch (sorry). Migrate from struct in_addr to struct sockaddr_storage in most places that matter (ie. not the nmbd and NetBIOS lookups). This passes make test on an IPv4 box, but I'll have to do more work/testing on IPv6 enabled boxes. This should now give us a framework for testing and finishing the IPv6 migration. It's at the state where someone with a working IPv6 setup should (theorecically) be able to type : smbclient //ipv6-address/share and have it work. Jeremy. (This used to be commit 98e154c3125d5732c37a72d74b0eb5cd7b6155fd) --- source3/utils/net_rpc_printer.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 20821cd2e6..d14caad975 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -1689,7 +1689,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; uint32 i, p; uint32 num_printers; - uint32 level = 3; + uint32 level = 3; pstring printername = "", sharename = ""; bool got_hnd_src = False; bool got_hnd_dst = False; @@ -1703,7 +1703,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, struct cli_state *cli_share_src = NULL; struct cli_state *cli_share_dst = NULL; fstring drivername = ""; - + ZERO_STRUCT(drv_ctr_src); ZERO_STRUCT(drv_ctr_dst); ZERO_STRUCT(info_ctr_enum); @@ -1715,21 +1715,20 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, nt_status = connect_dst_pipe(&cli_dst, &pipe_hnd_dst, PI_SPOOLSS); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; - /* open print$-share on the src server */ - nt_status = connect_to_service(&cli_share_src, &cli->dest_ip, + nt_status = connect_to_service(&cli_share_src, &cli->dest_ss, cli->desthost, "print$", "A:"); - if (!NT_STATUS_IS_OK(nt_status)) + if (!NT_STATUS_IS_OK(nt_status)) goto done; got_src_driver_share = True; /* open print$-share on the dst server */ - nt_status = connect_to_service(&cli_share_dst, &cli_dst->dest_ip, + nt_status = connect_to_service(&cli_share_dst, &cli_dst->dest_ss, cli_dst->desthost, "print$", "A:"); - if (!NT_STATUS_IS_OK(nt_status)) + if (!NT_STATUS_IS_OK(nt_status)) return nt_status; got_dst_driver_share = True; -- cgit From d40e47db4b5da41c8604a2058f3a0b0a82164f08 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 8 Nov 2007 17:25:45 -0800 Subject: Remove more fstring/pstring bad useage. Go talloc ! Jeremy. (This used to be commit 2a0173743d2cf615d52278f3dd87cc804abe2d16) --- source3/utils/net_rpc_printer.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index d14caad975..5e85bae7ee 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -2070,7 +2070,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, REGVAL_CTR *reg_ctr; struct cli_state *cli_dst = NULL; char *devicename = NULL, *unc_name = NULL, *url = NULL; - fstring longname; + const char *longname; uint16 *keylist = NULL, *curkey; @@ -2094,12 +2094,16 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, printf ("no printers found on server.\n"); nt_status = NT_STATUS_OK; goto done; - } - + } + /* needed for dns-strings in regkeys */ - get_mydnsfullname(longname); - + longname = get_mydnsfullname(); + if (!longname) { + nt_status = NT_STATUS_UNSUCCESSFUL; + goto done; + } + /* do something for all printers */ for (i = 0; i < num_printers; i++) { -- cgit From 3c219ce238d1d4cc0985be4473594deee61d4d6f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 4 Dec 2007 15:45:20 -0800 Subject: Remove pstrings. Jeremy. (This used to be commit e3c02796f8cf49af388741d175c4011825670df0) --- source3/utils/net_rpc_printer.c | 250 ++++++++++++++++++++++++++-------------- 1 file changed, 166 insertions(+), 84 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 5e85bae7ee..d40b953707 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -108,7 +108,7 @@ static void display_print_driver_3(DRIVER_INFO_3 *i1) static void display_reg_value(const char *subkey, REGISTRY_VALUE value) { - pstring text; + char *text; switch(value.type) { case REG_DWORD: @@ -117,12 +117,18 @@ static void display_reg_value(const char *subkey, REGISTRY_VALUE value) break; case REG_SZ: - rpcstr_pull(text, value.data_p, sizeof(text), value.size, - STR_TERMINATE); + rpcstr_pull_talloc(talloc_tos(), + &text, + value.data_p, + value.size, + STR_TERMINATE); + if (!text) { + break; + } d_printf("\t[%s:%s]: REG_SZ: %s\n", subkey, value.valuename, text); break; - case REG_BINARY: + case REG_BINARY: d_printf("\t[%s:%s]: REG_BINARY: unknown length value not displayed\n", subkey, value.valuename); break; @@ -1033,7 +1039,7 @@ NTSTATUS rpc_printer_list_internals(const DOM_SID *domain_sid, NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; uint32 i, num_printers; uint32 level = 2; - pstring printername, sharename; + char *printername, *sharename; PRINTER_INFO_CTR ctr; printf("listing printers\n"); @@ -1042,15 +1048,22 @@ NTSTATUS rpc_printer_list_internals(const DOM_SID *domain_sid, return nt_status; for (i = 0; i < num_printers; i++) { - /* do some initialization */ - rpcstr_pull(printername, ctr.printers_2[i].printername.buffer, - sizeof(printername), -1, STR_TERMINATE); - rpcstr_pull(sharename, ctr.printers_2[i].sharename.buffer, - sizeof(sharename), -1, STR_TERMINATE); - - d_printf("printer %d: %s, shared as: %s\n", - i+1, printername, sharename); + rpcstr_pull_talloc(mem_ctx, + &printername, + ctr.printers_2[i].printername.buffer, + -1, + STR_TERMINATE); + rpcstr_pull_talloc(mem_ctx, + &sharename, + ctr.printers_2[i].sharename.buffer, + -1, + STR_TERMINATE); + + if (printername && sharename) { + d_printf("printer %d: %s, shared as: %s\n", + i+1, printername, sharename); + } } return NT_STATUS_OK; @@ -1148,7 +1161,7 @@ static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_ NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; uint32 i, num_printers; uint32 level = 7; - pstring printername, sharename; + char *printername, *sharename; PRINTER_INFO_CTR ctr, ctr_pub; POLICY_HND hnd; bool got_hnd = False; @@ -1159,12 +1172,20 @@ static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_ return nt_status; for (i = 0; i < num_printers; i++) { - /* do some initialization */ - rpcstr_pull(printername, ctr.printers_2[i].printername.buffer, - sizeof(printername), -1, STR_TERMINATE); - rpcstr_pull(sharename, ctr.printers_2[i].sharename.buffer, - sizeof(sharename), -1, STR_TERMINATE); + rpcstr_pull_talloc(mem_ctx, + &printername, + ctr.printers_2[i].printername.buffer, + -1, + STR_TERMINATE); + rpcstr_pull_talloc(mem_ctx, + &sharename, + ctr.printers_2[i].sharename.buffer, + -1, + STR_TERMINATE); + if (!printername || !sharename) { + goto done; + } /* open printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, @@ -1274,8 +1295,8 @@ NTSTATUS rpc_printer_publish_list_internals(const DOM_SID *domain_sid, NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; uint32 i, num_printers; uint32 level = 7; - pstring printername, sharename; - pstring guid; + char *printername, *sharename; + char *guid; PRINTER_INFO_CTR ctr, ctr_pub; POLICY_HND hnd; bool got_hnd = False; @@ -1285,14 +1306,22 @@ NTSTATUS rpc_printer_publish_list_internals(const DOM_SID *domain_sid, return nt_status; for (i = 0; i < num_printers; i++) { - ZERO_STRUCT(ctr_pub); /* do some initialization */ - rpcstr_pull(printername, ctr.printers_2[i].printername.buffer, - sizeof(printername), -1, STR_TERMINATE); - rpcstr_pull(sharename, ctr.printers_2[i].sharename.buffer, - sizeof(sharename), -1, STR_TERMINATE); + rpcstr_pull_talloc(mem_ctx, + &printername, + ctr.printers_2[i].printername.buffer, + -1, + STR_TERMINATE); + rpcstr_pull_talloc(mem_ctx, + &sharename, + ctr.printers_2[i].sharename.buffer, + -1, + STR_TERMINATE); + if (!printername || !sharename) { + goto done; + } /* open printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, @@ -1305,8 +1334,14 @@ NTSTATUS rpc_printer_publish_list_internals(const DOM_SID *domain_sid, if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &ctr_pub)) goto done; - rpcstr_pull(guid, ctr_pub.printers_7->guid.buffer, sizeof(guid), -1, STR_TERMINATE); - + rpcstr_pull_talloc(mem_ctx, + &guid, + ctr_pub.printers_7->guid.buffer, + -1, + STR_TERMINATE); + if (!guid) { + goto done; + } state = ctr_pub.printers_7->action; switch (state) { case SPOOL_DS_PUBLISH: @@ -1367,7 +1402,7 @@ NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, uint32 i = 0; uint32 num_printers; uint32 level = 2; - pstring printername = "", sharename = ""; + char *printername, *sharename; bool got_hnd_src = False; bool got_hnd_dst = False; struct rpc_pipe_client *pipe_hnd_dst = NULL; @@ -1395,20 +1430,30 @@ NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, printf ("no printers found on server.\n"); nt_status = NT_STATUS_OK; goto done; - } - + } + /* do something for all printers */ for (i = 0; i < num_printers; i++) { - /* do some initialization */ - rpcstr_pull(printername, ctr_enum.printers_2[i].printername.buffer, - sizeof(printername), -1, STR_TERMINATE); - rpcstr_pull(sharename, ctr_enum.printers_2[i].sharename.buffer, - sizeof(sharename), -1, STR_TERMINATE); - /* we can reset NT_STATUS here because we do not + rpcstr_pull_talloc(mem_ctx, + &printername, + ctr_enum.printers_2[i].printername.buffer, + -1, + STR_TERMINATE); + rpcstr_pull_talloc(mem_ctx, + &sharename, + ctr_enum.printers_2[i].sharename.buffer, + -1, + STR_TERMINATE); + if (!printername || !sharename) { + nt_status = NT_STATUS_UNSUCCESSFUL; + goto done; + } + + /* we can reset NT_STATUS here because we do not get any real NT_STATUS-codes anymore from now on */ nt_status = NT_STATUS_UNSUCCESSFUL; - + d_printf("migrating printer ACLs for: [%s] / [%s]\n", printername, sharename); @@ -1515,7 +1560,7 @@ NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, uint32 i, f; uint32 num_printers; uint32 level = 1; - pstring printername = "", sharename = ""; + char *printername, *sharename; bool got_hnd_src = False; bool got_hnd_dst = False; struct rpc_pipe_client *pipe_hnd_dst = NULL; @@ -1524,16 +1569,15 @@ NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, uint32 num_forms; FORM_1 *forms; struct cli_state *cli_dst = NULL; - + ZERO_STRUCT(ctr_enum); DEBUG(3,("copying forms\n")); - + /* connect destination PI_SPOOLSS */ nt_status = connect_dst_pipe(&cli_dst, &pipe_hnd_dst, PI_SPOOLSS); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; - /* enum src printers */ if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr_enum)) { @@ -1545,22 +1589,30 @@ NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, printf ("no printers found on server.\n"); nt_status = NT_STATUS_OK; goto done; - } - + } /* do something for all printers */ for (i = 0; i < num_printers; i++) { - /* do some initialization */ - rpcstr_pull(printername, ctr_enum.printers_2[i].printername.buffer, - sizeof(printername), -1, STR_TERMINATE); - rpcstr_pull(sharename, ctr_enum.printers_2[i].sharename.buffer, - sizeof(sharename), -1, STR_TERMINATE); - /* we can reset NT_STATUS here because we do not + rpcstr_pull_talloc(mem_ctx, + &printername, + ctr_enum.printers_2[i].printername.buffer, + -1, + STR_TERMINATE); + rpcstr_pull_talloc(mem_ctx, + &sharename, + ctr_enum.printers_2[i].sharename.buffer, + -1, + STR_TERMINATE); + if (!printername || !sharename) { + nt_status = NT_STATUS_UNSUCCESSFUL; + goto done; + } + /* we can reset NT_STATUS here because we do not get any real NT_STATUS-codes anymore from now on */ nt_status = NT_STATUS_UNSUCCESSFUL; - - d_printf("migrating printer forms for: [%s] / [%s]\n", + + d_printf("migrating printer forms for: [%s] / [%s]\n", printername, sharename); @@ -1690,7 +1742,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, uint32 i, p; uint32 num_printers; uint32 level = 3; - pstring printername = "", sharename = ""; + char *printername, *sharename; bool got_hnd_src = False; bool got_hnd_dst = False; bool got_src_driver_share = False; @@ -1709,7 +1761,6 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, ZERO_STRUCT(info_ctr_enum); ZERO_STRUCT(info_ctr_dst); - DEBUG(3,("copying printer-drivers\n")); nt_status = connect_dst_pipe(&cli_dst, &pipe_hnd_dst, PI_SPOOLSS); @@ -1744,17 +1795,27 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, printf ("no printers found on server.\n"); nt_status = NT_STATUS_OK; goto done; - } - + } + /* do something for all printers */ for (p = 0; p < num_printers; p++) { - /* do some initialization */ - rpcstr_pull(printername, info_ctr_enum.printers_2[p].printername.buffer, - sizeof(printername), -1, STR_TERMINATE); - rpcstr_pull(sharename, info_ctr_enum.printers_2[p].sharename.buffer, - sizeof(sharename), -1, STR_TERMINATE); + rpcstr_pull_talloc(mem_ctx, + &printername, + info_ctr_enum.printers_2[p].printername.buffer, + -1, + STR_TERMINATE); + rpcstr_pull_talloc(mem_ctx, + &sharename, + info_ctr_enum.printers_2[p].sharename.buffer, + -1, + STR_TERMINATE); + if (!printername || !sharename) { + nt_status = NT_STATUS_UNSUCCESSFUL; + goto done; + } + /* we can reset NT_STATUS here because we do not get any real NT_STATUS-codes anymore from now on */ nt_status = NT_STATUS_UNSUCCESSFUL; @@ -1766,7 +1827,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename, PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) goto done; - + got_hnd_dst = True; /* check for existing dst printer */ @@ -1911,7 +1972,7 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, PRINTER_INFO_CTR ctr_src, ctr_dst, ctr_enum; struct cli_state *cli_dst = NULL; POLICY_HND hnd_dst, hnd_src; - pstring printername, sharename; + char *printername, *sharename; bool got_hnd_src = False; bool got_hnd_dst = False; struct rpc_pipe_client *pipe_hnd_dst = NULL; @@ -1933,21 +1994,29 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, printf ("no printers found on server.\n"); nt_status = NT_STATUS_OK; goto done; - } - + } /* do something for all printers */ for (i = 0; i < num_printers; i++) { - /* do some initialization */ - rpcstr_pull(printername, ctr_enum.printers_2[i].printername.buffer, - sizeof(printername), -1, STR_TERMINATE); - rpcstr_pull(sharename, ctr_enum.printers_2[i].sharename.buffer, - sizeof(sharename), -1, STR_TERMINATE); - /* we can reset NT_STATUS here because we do not + rpcstr_pull_talloc(mem_ctx, + &printername, + ctr_enum.printers_2[i].printername.buffer, + -1, + STR_TERMINATE); + rpcstr_pull_talloc(mem_ctx, + &sharename, + ctr_enum.printers_2[i].sharename.buffer, + -1, + STR_TERMINATE); + if (!printername || !sharename) { + nt_status = NT_STATUS_UNSUCCESSFUL; + goto done; + } + /* we can reset NT_STATUS here because we do not get any real NT_STATUS-codes anymore from now on */ nt_status = NT_STATUS_UNSUCCESSFUL; - + d_printf("migrating printer queue for: [%s] / [%s]\n", printername, sharename); @@ -2061,7 +2130,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, uint32 i = 0, p = 0, j = 0; uint32 num_printers, val_needed, data_needed; uint32 level = 2; - pstring printername = "", sharename = ""; + char *printername, *sharename; bool got_hnd_src = False; bool got_hnd_dst = False; struct rpc_pipe_client *pipe_hnd_dst = NULL; @@ -2083,7 +2152,6 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, if (!NT_STATUS_IS_OK(nt_status)) return nt_status; - /* enum src printers */ if (!get_printer_info(pipe_hnd, mem_ctx, level, argc, argv, &num_printers, &ctr_enum)) { nt_status = NT_STATUS_UNSUCCESSFUL; @@ -2106,17 +2174,25 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, /* do something for all printers */ for (i = 0; i < num_printers; i++) { - /* do some initialization */ - rpcstr_pull(printername, ctr_enum.printers_2[i].printername.buffer, - sizeof(printername), -1, STR_TERMINATE); - rpcstr_pull(sharename, ctr_enum.printers_2[i].sharename.buffer, - sizeof(sharename), -1, STR_TERMINATE); - + rpcstr_pull_talloc(mem_ctx, + &printername, + ctr_enum.printers_2[i].printername.buffer, + -1, + STR_TERMINATE); + rpcstr_pull_talloc(mem_ctx, + &sharename, + ctr_enum.printers_2[i].sharename.buffer, + -1, + STR_TERMINATE); + if (!printername || !sharename) { + nt_status = NT_STATUS_UNSUCCESSFUL; + goto done; + } /* we can reset NT_STATUS here because we do not get any real NT_STATUS-codes anymore from now on */ nt_status = NT_STATUS_UNSUCCESSFUL; - + d_printf("migrating printer settings for: [%s] / [%s]\n", printername, sharename); @@ -2257,9 +2333,15 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, curkey = keylist; while (*curkey != 0) { - - pstring subkey; - rpcstr_pull(subkey, curkey, sizeof(subkey), -1, STR_TERMINATE); + char *subkey; + rpcstr_pull_talloc(mem_ctx, + &subkey, + curkey, + -1, + STR_TERMINATE); + if (!subkey) { + return NT_STATUS_NO_MEMORY; + } curkey += strlen(subkey) + 1; -- cgit From 42cfffae80480eae4381902fff3f7c61f858a933 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 7 Dec 2007 17:32:32 -0800 Subject: Remove next_token - all uses must now be next_token_talloc. No more temptations to use static length strings. Jeremy. (This used to be commit ec003f39369910dee852b7cafb883ddaa321c2de) --- source3/utils/net_rpc_printer.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index d40b953707..bcfb37713c 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -514,17 +514,17 @@ static NTSTATUS net_copy_driverfile(TALLOC_CTX *mem_ctx, const char *p; char *src_name; char *dst_name; - fstring version; - fstring filename; - fstring tok; + char *version; + char *filename; + char *tok; /* scroll through the file until we have the part beyond archi_table.short_archi */ p = file; - while (next_token(&p, tok, "\\", sizeof(tok))) { + while (next_token_talloc(mem_ctx, &p, &tok, "\\")) { if (strequal(tok, short_archi)) { - next_token(&p, version, "\\", sizeof(version)); - next_token(&p, filename, "\\", sizeof(filename)); + next_token_talloc(mem_ctx, &p, &version, "\\"); + next_token_talloc(mem_ctx, &p, &filename, "\\"); } } -- cgit From 2a2188591b5ed922d09dc723adcf10f8b8f5e5a0 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 19 Apr 2008 21:56:43 +0200 Subject: Add "desthost" to rpc_pipe_client This reduces the dependency on cli_state (This used to be commit 783afab9c891dd7bcb78895b2a639b6f3a0edf5b) --- source3/utils/net_rpc_printer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index bcfb37713c..80140792a3 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -721,7 +721,8 @@ static bool net_spoolss_open_printer_ex(struct rpc_pipe_client *pipe_hnd, WERROR result; fstring servername, printername2; - slprintf(servername, sizeof(servername)-1, "\\\\%s", pipe_hnd->cli->desthost); + slprintf(servername, sizeof(servername)-1, "\\\\%s", + pipe_hnd->desthost); fstrcpy(printername2, servername); fstrcat(printername2, "\\"); -- cgit From cf2442bdcb68d75582da98ba15da8928c37fb058 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 20 Apr 2008 00:01:52 +0200 Subject: Use rpc_pipe_client->user_name instead of rpc_pipe_client->cli->user_name Also make sure that rpc_pipe_client->user_name is always talloced. (This used to be commit 3f6c5b99664a75a6f490ee3b6980b89cacf7f579) --- source3/utils/net_rpc_printer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 80140792a3..9dc409123e 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -994,7 +994,7 @@ static bool get_printer_info(struct rpc_pipe_client *pipe_hnd, /* argument given, get a single printer by name */ if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, argv[0], - MAXIMUM_ALLOWED_ACCESS, pipe_hnd->cli->user_name, &hnd)) + MAXIMUM_ALLOWED_ACCESS, pipe_hnd->user_name, &hnd)) return False; if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, ctr)) { @@ -1190,7 +1190,7 @@ static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_ /* open printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, - PRINTER_ALL_ACCESS, pipe_hnd->cli->user_name, &hnd)) + PRINTER_ALL_ACCESS, pipe_hnd->user_name, &hnd)) goto done; got_hnd = True; @@ -1838,7 +1838,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, /* open src printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, - MAXIMUM_ALLOWED_ACCESS, pipe_hnd->cli->user_name, &hnd_src)) + MAXIMUM_ALLOWED_ACCESS, pipe_hnd->user_name, &hnd_src)) goto done; got_hnd_src = True; -- cgit From 862d7e32b90f7020d46e025de918f6338f40441b Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 21 Apr 2008 22:27:29 +0200 Subject: Move user/domain from rpc_pipe_client to cli_pipe_auth_data (This used to be commit 42de50d2cd43e760d776694f7b5f003ba51d7f84) --- source3/utils/net_rpc_printer.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 9dc409123e..bdf5b09205 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -994,7 +994,9 @@ static bool get_printer_info(struct rpc_pipe_client *pipe_hnd, /* argument given, get a single printer by name */ if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, argv[0], - MAXIMUM_ALLOWED_ACCESS, pipe_hnd->user_name, &hnd)) + MAXIMUM_ALLOWED_ACCESS, + pipe_hnd->auth->user_name, + &hnd)) return False; if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, ctr)) { @@ -1190,7 +1192,7 @@ static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_ /* open printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, - PRINTER_ALL_ACCESS, pipe_hnd->user_name, &hnd)) + PRINTER_ALL_ACCESS, pipe_hnd->auth->user_name, &hnd)) goto done; got_hnd = True; @@ -1838,7 +1840,9 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, /* open src printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, - MAXIMUM_ALLOWED_ACCESS, pipe_hnd->user_name, &hnd_src)) + MAXIMUM_ALLOWED_ACCESS, + pipe_hnd->auth->user_name, + &hnd_src)) goto done; got_hnd_src = True; -- cgit From f5769109447d8da0f09b102d444a816ad97a00dc Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Fri, 9 May 2008 23:22:12 +0200 Subject: net: Remove globals (This used to be commit 1e9319cf88b65a2a8d4f5099a1fe5297e405ed2e) --- source3/utils/net_rpc_printer.c | 116 ++++++++++++++++++++++++---------------- 1 file changed, 70 insertions(+), 46 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index bdf5b09205..4c1985a0af 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -14,8 +14,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - + along with this program. If not, see . +*/ #include "includes.h" #include "utils/net.h" @@ -161,6 +161,7 @@ static void display_reg_value(const char *subkey, REGISTRY_VALUE value) * Copies ACLs, DOS-attributes and timestamps from one * file or directory from one connected share to another connected share * + * @param c A net_context structure * @param mem_ctx A talloc-context * @param cli_share_src A connected cli_state * @param cli_share_dst A connected cli_state @@ -174,7 +175,8 @@ static void display_reg_value(const char *subkey, REGISTRY_VALUE value) * @return Normal NTSTATUS return. **/ -NTSTATUS net_copy_fileattr(TALLOC_CTX *mem_ctx, +NTSTATUS net_copy_fileattr(struct net_context *c, + TALLOC_CTX *mem_ctx, struct cli_state *cli_share_src, struct cli_state *cli_share_dst, const char *src_name, const char *dst_name, @@ -217,7 +219,7 @@ NTSTATUS net_copy_fileattr(TALLOC_CTX *mem_ctx, goto out; } - if (opt_verbose && DEBUGLEVEL >= 3) + if (c->opt_verbose && DEBUGLEVEL >= 3) display_sec_desc(sd); } @@ -313,6 +315,7 @@ out: /** * Copy a file or directory from a connected share to another connected share * + * @param c A net_context structure * @param mem_ctx A talloc-context * @param cli_share_src A connected cli_state * @param cli_share_dst A connected cli_state @@ -326,7 +329,8 @@ out: * @return Normal NTSTATUS return. **/ -NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, +NTSTATUS net_copy_file(struct net_context *c, + TALLOC_CTX *mem_ctx, struct cli_state *cli_share_src, struct cli_state *cli_share_dst, const char *src_name, const char *dst_name, @@ -348,7 +352,6 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, if (cli_share_src == NULL || cli_share_dst == NULL) goto out; - /* open on the originating server */ DEBUGADD(3,("opening %s %s on originating server\n", is_file ? "file":"dir", src_name)); @@ -390,7 +393,7 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, } - if (opt_verbose) { + if (c->opt_verbose) { d_printf("copying [\\\\%s\\%s%s] => [\\\\%s\\%s%s] " "%s ACLs and %s DOS Attributes %s\n", @@ -462,7 +465,7 @@ NTSTATUS net_copy_file(TALLOC_CTX *mem_ctx, } /* possibly we have to copy some file-attributes / acls / sd */ - nt_status = net_copy_fileattr(mem_ctx, cli_share_src, cli_share_dst, + nt_status = net_copy_fileattr(c, mem_ctx, cli_share_src, cli_share_dst, src_name, dst_name, copy_acls, copy_attrs, copy_timestamps, is_file); if (!NT_STATUS_IS_OK(nt_status)) @@ -496,6 +499,7 @@ out: * \\dst_server\print$\{arch}\file * * to be added via setdriver-calls later. + * @param c A net_context structure * @param mem_ctx A talloc-context * @param cli_share_src A cli_state connected to source print$-share * @param cli_share_dst A cli_state connected to destination print$-share @@ -505,7 +509,8 @@ out: * @return Normal NTSTATUS return. **/ -static NTSTATUS net_copy_driverfile(TALLOC_CTX *mem_ctx, +static NTSTATUS net_copy_driverfile(struct net_context *c, + TALLOC_CTX *mem_ctx, struct cli_state *cli_share_src, struct cli_state *cli_share_dst, char *file, const char *short_archi) { @@ -539,8 +544,8 @@ static NTSTATUS net_copy_driverfile(TALLOC_CTX *mem_ctx, /* finally copy the file */ - nt_status = net_copy_file(mem_ctx, cli_share_src, cli_share_dst, - src_name, dst_name, False, False, False, True); + nt_status = net_copy_file(c, mem_ctx, cli_share_src, cli_share_dst, + src_name, dst_name, false, false, false, true); if (!NT_STATUS_IS_OK(nt_status)) goto out; @@ -598,6 +603,7 @@ out: * Copy a print-driver (level 3) from one connected print$-share to another * connected print$-share * + * @param c A net_context structure * @param mem_ctx A talloc-context * @param cli_share_src A cli_state connected to a print$-share * @param cli_share_dst A cli_state connected to a print$-share @@ -607,7 +613,8 @@ out: * @return Normal NTSTATUS return. **/ -static NTSTATUS copy_print_driver_3(TALLOC_CTX *mem_ctx, +static NTSTATUS copy_print_driver_3(struct net_context *c, + TALLOC_CTX *mem_ctx, struct cli_state *cli_share_src, struct cli_state *cli_share_dst, const char *short_archi, DRIVER_INFO_3 *i1) @@ -633,26 +640,26 @@ static NTSTATUS copy_print_driver_3(TALLOC_CTX *mem_ctx, rpcstr_pull(helpfile, i1->helpfile.buffer, sizeof(helpfile), -1, STR_TERMINATE); - if (opt_verbose) + if (c->opt_verbose) d_printf("copying driver: [%s], for architecture: [%s], version: [%d]\n", name, short_archi, i1->version); - nt_status = net_copy_driverfile(mem_ctx, cli_share_src, cli_share_dst, + nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst, driverpath, short_archi); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; - nt_status = net_copy_driverfile(mem_ctx, cli_share_src, cli_share_dst, + nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst, datafile, short_archi); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; - nt_status = net_copy_driverfile(mem_ctx, cli_share_src, cli_share_dst, + nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst, configfile, short_archi); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; - nt_status = net_copy_driverfile(mem_ctx, cli_share_src, cli_share_dst, + nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst, helpfile, short_archi); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; @@ -664,7 +671,7 @@ static NTSTATUS copy_print_driver_3(TALLOC_CTX *mem_ctx, if (strlen(dependentfiles) > 0) { - nt_status = net_copy_driverfile(mem_ctx, + nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst, dependentfiles, short_archi); if (!NT_STATUS_IS_OK(nt_status)) @@ -879,7 +886,6 @@ static bool net_spoolss_enumforms(struct rpc_pipe_client *pipe_hnd, int level, uint32 *num_forms, FORM_1 **forms) - { WERROR result; @@ -1021,6 +1027,7 @@ out: * All parameters are provided by the run_rpc_command function, except for * argc, argv which are passed through. * + * @param c A net_context structure * @param domain_sid The domain sid aquired from the remote server * @param cli A cli_state connected to the server. * @param mem_ctx Talloc context, destoyed on compleation of the function. @@ -1031,7 +1038,8 @@ out: * @return Normal NTSTATUS return. **/ -NTSTATUS rpc_printer_list_internals(const DOM_SID *domain_sid, +NTSTATUS rpc_printer_list_internals(struct net_context *c, + const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, @@ -1078,6 +1086,7 @@ NTSTATUS rpc_printer_list_internals(const DOM_SID *domain_sid, * All parameters are provided by the run_rpc_command function, except for * argc, argv which are passed through. * + * @param c A net_context structure * @param domain_sid The domain sid aquired from the remote server * @param cli A cli_state connected to the server. * @param mem_ctx Talloc context, destoyed on compleation of the function. @@ -1088,7 +1097,8 @@ NTSTATUS rpc_printer_list_internals(const DOM_SID *domain_sid, * @return Normal NTSTATUS return. **/ -NTSTATUS rpc_printer_driver_list_internals(const DOM_SID *domain_sid, +NTSTATUS rpc_printer_driver_list_internals(struct net_context *c, + const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, @@ -1114,7 +1124,6 @@ NTSTATUS rpc_printer_driver_list_internals(const DOM_SID *domain_sid, if (!net_spoolss_enumprinterdrivers(pipe_hnd, mem_ctx, level, archi_table[i].long_archi, &num_drivers, &drv_ctr_enum)) { - nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } @@ -1238,7 +1247,8 @@ done: return nt_status; } -NTSTATUS rpc_printer_publish_publish_internals(const DOM_SID *domain_sid, +NTSTATUS rpc_printer_publish_publish_internals(struct net_context *c, + const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, @@ -1249,7 +1259,8 @@ NTSTATUS rpc_printer_publish_publish_internals(const DOM_SID *domain_sid, return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, SPOOL_DS_PUBLISH); } -NTSTATUS rpc_printer_publish_unpublish_internals(const DOM_SID *domain_sid, +NTSTATUS rpc_printer_publish_unpublish_internals(struct net_context *c, + const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, @@ -1260,7 +1271,8 @@ NTSTATUS rpc_printer_publish_unpublish_internals(const DOM_SID *domain_sid, return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, SPOOL_DS_UNPUBLISH); } -NTSTATUS rpc_printer_publish_update_internals(const DOM_SID *domain_sid, +NTSTATUS rpc_printer_publish_update_internals(struct net_context *c, + const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, @@ -1277,6 +1289,7 @@ NTSTATUS rpc_printer_publish_update_internals(const DOM_SID *domain_sid, * All parameters are provided by the run_rpc_command function, except for * argc, argv which are passed through. * + * @param c A net_context structure * @param domain_sid The domain sid aquired from the remote server * @param cli A cli_state connected to the server. * @param mem_ctx Talloc context, destoyed on compleation of the function. @@ -1287,7 +1300,8 @@ NTSTATUS rpc_printer_publish_update_internals(const DOM_SID *domain_sid, * @return Normal NTSTATUS return. **/ -NTSTATUS rpc_printer_publish_list_internals(const DOM_SID *domain_sid, +NTSTATUS rpc_printer_publish_list_internals(struct net_context *c, + const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, @@ -1349,7 +1363,7 @@ NTSTATUS rpc_printer_publish_list_internals(const DOM_SID *domain_sid, switch (state) { case SPOOL_DS_PUBLISH: printf("printer [%s] is published", sharename); - if (opt_verbose) + if (c->opt_verbose) printf(", guid: %s", guid); printf("\n"); break; @@ -1380,6 +1394,7 @@ done: * All parameters are provided by the run_rpc_command function, except for * argc, argv which are passed through. * + * @param c A net_context structure * @param domain_sid The domain sid aquired from the remote server * @param cli A cli_state connected to the server. * @param mem_ctx Talloc context, destoyed on compleation of the function. @@ -1390,7 +1405,8 @@ done: * @return Normal NTSTATUS return. **/ -NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, +NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c, + const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, @@ -1418,7 +1434,7 @@ NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, DEBUG(3,("copying printer ACLs\n")); /* connect destination PI_SPOOLSS */ - nt_status = connect_dst_pipe(&cli_dst, &pipe_hnd_dst, PI_SPOOLSS); + nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, PI_SPOOLSS); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; @@ -1494,7 +1510,7 @@ NTSTATUS rpc_printer_migrate_security_internals(const DOM_SID *domain_sid, ctr_dst.printers_2->devmode = NULL; ctr_dst.printers_2->secdesc = dup_sec_desc(mem_ctx, ctr_src.printers_3->secdesc); - if (opt_verbose) + if (c->opt_verbose) display_sec_desc(ctr_dst.printers_2->secdesc); if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &ctr_dst)) @@ -1540,6 +1556,7 @@ done: * All parameters are provided by the run_rpc_command function, except for * argc, argv which are passed through. * + * @param c A net_context structure * @param domain_sid The domain sid aquired from the remote server * @param cli A cli_state connected to the server. * @param mem_ctx Talloc context, destoyed on compleation of the function. @@ -1550,7 +1567,8 @@ done: * @return Normal NTSTATUS return. **/ -NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, +NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c, + const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, @@ -1578,7 +1596,7 @@ NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, DEBUG(3,("copying forms\n")); /* connect destination PI_SPOOLSS */ - nt_status = connect_dst_pipe(&cli_dst, &pipe_hnd_dst, PI_SPOOLSS); + nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, PI_SPOOLSS); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; @@ -1660,7 +1678,7 @@ NTSTATUS rpc_printer_migrate_forms_internals(const DOM_SID *domain_sid, rpcstr_pull(form_name, forms[f].name.buffer, sizeof(form_name), -1, STR_TERMINATE); - if (opt_verbose) + if (c->opt_verbose) d_printf("\tmigrating form # %d [%s] of type [%d]\n", f, form_name, forms[f].flag); @@ -1723,6 +1741,7 @@ done: * All parameters are provided by the run_rpc_command function, except for * argc, argv which are passed through. * + * @param c A net_context structure * @param domain_sid The domain sid aquired from the remote server * @param cli A cli_state connected to the server. * @param mem_ctx Talloc context, destoyed on compleation of the function. @@ -1733,7 +1752,8 @@ done: * @return Normal NTSTATUS return. **/ -NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, +NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c, + const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, @@ -1766,12 +1786,12 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, DEBUG(3,("copying printer-drivers\n")); - nt_status = connect_dst_pipe(&cli_dst, &pipe_hnd_dst, PI_SPOOLSS); + nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, PI_SPOOLSS); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; /* open print$-share on the src server */ - nt_status = connect_to_service(&cli_share_src, &cli->dest_ss, + nt_status = connect_to_service(c, &cli_share_src, &cli->dest_ss, cli->desthost, "print$", "A:"); if (!NT_STATUS_IS_OK(nt_status)) goto done; @@ -1780,7 +1800,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, /* open print$-share on the dst server */ - nt_status = connect_to_service(&cli_share_dst, &cli_dst->dest_ss, + nt_status = connect_to_service(c, &cli_share_dst, &cli_dst->dest_ss, cli_dst->desthost, "print$", "A:"); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; @@ -1862,7 +1882,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, rpcstr_pull(drivername, drv_ctr_src.info3->name.buffer, sizeof(drivername), -1, STR_TERMINATE); - if (opt_verbose) + if (c->opt_verbose) display_print_driver_3(drv_ctr_src.info3); @@ -1873,7 +1893,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(const DOM_SID *domain_sid, /* copy driver-files */ - nt_status = copy_print_driver_3(mem_ctx, cli_share_src, cli_share_dst, + nt_status = copy_print_driver_3(c, mem_ctx, cli_share_src, cli_share_dst, archi_table[i].short_archi, drv_ctr_src.info3); if (!NT_STATUS_IS_OK(nt_status)) @@ -1952,6 +1972,7 @@ done: * All parameters are provided by the run_rpc_command function, except for * argc, argv which are passed through. * + * @param c A net_context structure * @param domain_sid The domain sid aquired from the remote server * @param cli A cli_state connected to the server. * @param mem_ctx Talloc context, destoyed on compleation of the function. @@ -1962,7 +1983,8 @@ done: * @return Normal NTSTATUS return. **/ -NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, +NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c, + const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, @@ -1985,7 +2007,7 @@ NTSTATUS rpc_printer_migrate_printers_internals(const DOM_SID *domain_sid, DEBUG(3,("copying printers\n")); /* connect destination PI_SPOOLSS */ - nt_status = connect_dst_pipe(&cli_dst, &pipe_hnd_dst, PI_SPOOLSS); + nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, PI_SPOOLSS); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; @@ -2109,6 +2131,7 @@ done: * All parameters are provided by the run_rpc_command function, except for * argc, argv which are passed through. * + * @param c A net_context structure * @param domain_sid The domain sid aquired from the remote server * @param cli A cli_state connected to the server. * @param mem_ctx Talloc context, destoyed on compleation of the function. @@ -2119,7 +2142,8 @@ done: * @return Normal NTSTATUS return. **/ -NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, +NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, + const DOM_SID *domain_sid, const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, @@ -2153,7 +2177,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, DEBUG(3,("copying printer settings\n")); /* connect destination PI_SPOOLSS */ - nt_status = connect_dst_pipe(&cli_dst, &pipe_hnd_dst, PI_SPOOLSS); + nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, PI_SPOOLSS); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; @@ -2303,7 +2327,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, if (W_ERROR_IS_OK(result)) { /* display_value */ - if (opt_verbose) + if (c->opt_verbose) display_reg_value(SPOOL_PRINTERDATA_KEY, value); /* set_value */ @@ -2425,7 +2449,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, value.data_p = NULL; } - if (opt_verbose) + if (c->opt_verbose) display_reg_value(subkey, value); /* here we have to set all subkeys on the dst server */ @@ -2435,7 +2459,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(const DOM_SID *domain_sid, } else { - if (opt_verbose) + if (c->opt_verbose) display_reg_value(subkey, *(reg_ctr->values[j])); /* here we have to set all subkeys on the dst server */ -- cgit From 4206d9754486d2c1e18217cbcdbaad8f31f5244b Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Thu, 8 May 2008 11:23:38 +0200 Subject: net: more whitespace cleanup (This used to be commit ef0184d580500734fc7af51e1c790b075180a3d0) --- source3/utils/net_rpc_printer.c | 510 ++++++++++++++++++++-------------------- 1 file changed, 255 insertions(+), 255 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 4c1985a0af..9fcbb2272c 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -1,18 +1,18 @@ -/* - Samba Unix/Linux SMB client library - Distributed SMB/CIFS Server Management Utility +/* + Samba Unix/Linux SMB client library + Distributed SMB/CIFS Server Management Utility Copyright (C) 2004 Guenther Deschner (gd@samba.org) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program. If not, see . */ @@ -61,10 +61,10 @@ static void display_print_driver_3(DRIVER_INFO_3 *i1) fstring dependentfiles = ""; fstring monitorname = ""; fstring defaultdatatype = ""; - + int length=0; bool valid = True; - + if (i1 == NULL) return; @@ -88,22 +88,22 @@ static void display_print_driver_3(DRIVER_INFO_3 *i1) while (valid) { rpcstr_pull(dependentfiles, i1->dependentfiles+length, sizeof(dependentfiles), -1, STR_TERMINATE); - + length+=strlen(dependentfiles)+1; - + if (strlen(dependentfiles) > 0) { d_printf ("\tDependentfiles: [%s]\n", dependentfiles); } else { valid = False; } } - + printf ("\n"); d_printf ("\tMonitorname: [%s]\n", monitorname); d_printf ("\tDefaultdatatype: [%s]\n\n", defaultdatatype); - return; + return; } static void display_reg_value(const char *subkey, REGISTRY_VALUE value) @@ -112,7 +112,7 @@ static void display_reg_value(const char *subkey, REGISTRY_VALUE value) switch(value.type) { case REG_DWORD: - d_printf("\t[%s:%s]: REG_DWORD: 0x%08x\n", subkey, value.valuename, + d_printf("\t[%s:%s]: REG_DWORD: 0x%08x\n", subkey, value.valuename, *((uint32 *) value.data_p)); break; @@ -129,7 +129,7 @@ static void display_reg_value(const char *subkey, REGISTRY_VALUE value) break; case REG_BINARY: - d_printf("\t[%s:%s]: REG_BINARY: unknown length value not displayed\n", + d_printf("\t[%s:%s]: REG_BINARY: unknown length value not displayed\n", subkey, value.valuename); break; @@ -154,17 +154,17 @@ static void display_reg_value(const char *subkey, REGISTRY_VALUE value) default: d_printf("\t%s: unknown type %d\n", value.valuename, value.type); } - + } /** - * Copies ACLs, DOS-attributes and timestamps from one - * file or directory from one connected share to another connected share + * Copies ACLs, DOS-attributes and timestamps from one + * file or directory from one connected share to another connected share * * @param c A net_context structure * @param mem_ctx A talloc-context - * @param cli_share_src A connected cli_state - * @param cli_share_dst A connected cli_state + * @param cli_share_src A connected cli_state + * @param cli_share_dst A connected cli_state * @param src_file The source file-name * @param dst_file The destination file-name * @param copy_acls Whether to copy acls @@ -173,12 +173,12 @@ static void display_reg_value(const char *subkey, REGISTRY_VALUE value) * @param is_file Whether this file is a file or a dir * * @return Normal NTSTATUS return. - **/ + **/ NTSTATUS net_copy_fileattr(struct net_context *c, TALLOC_CTX *mem_ctx, struct cli_state *cli_share_src, - struct cli_state *cli_share_dst, + struct cli_state *cli_share_dst, const char *src_name, const char *dst_name, bool copy_acls, bool copy_attrs, bool copy_timestamps, bool is_file) @@ -196,12 +196,12 @@ NTSTATUS net_copy_fileattr(struct net_context *c, /* open file/dir on the originating server */ - DEBUGADD(3,("opening %s %s on originating server\n", + DEBUGADD(3,("opening %s %s on originating server\n", is_file?"file":"dir", src_name)); fnum_src = cli_nt_create(cli_share_src, src_name, READ_CONTROL_ACCESS); if (fnum_src == -1) { - DEBUGADD(0,("cannot open %s %s on originating server %s\n", + DEBUGADD(0,("cannot open %s %s on originating server %s\n", is_file?"file":"dir", src_name, cli_errstr(cli_share_src))); nt_status = cli_nt_error(cli_share_src); goto out; @@ -227,9 +227,9 @@ NTSTATUS net_copy_fileattr(struct net_context *c, if (copy_attrs || copy_timestamps) { /* get file attributes */ - if (!cli_getattrE(cli_share_src, fnum_src, &attr, NULL, + if (!cli_getattrE(cli_share_src, fnum_src, &attr, NULL, &f_ctime, &f_atime, &f_mtime)) { - DEBUG(0,("failed to get file-attrs: %s\n", + DEBUG(0,("failed to get file-attrs: %s\n", cli_errstr(cli_share_src))); nt_status = cli_nt_error(cli_share_src); goto out; @@ -237,7 +237,7 @@ NTSTATUS net_copy_fileattr(struct net_context *c, } - /* open the file/dir on the destination server */ + /* open the file/dir on the destination server */ fnum_dst = cli_nt_create(cli_share_dst, dst_name, WRITE_DAC_ACCESS | WRITE_OWNER_ACCESS); if (fnum_dst == -1) { @@ -284,14 +284,14 @@ NTSTATUS net_copy_fileattr(struct net_context *c, /* closing files */ if (!cli_close(cli_share_src, fnum_src)) { - d_fprintf(stderr, "could not close %s on originating server: %s\n", + d_fprintf(stderr, "could not close %s on originating server: %s\n", is_file?"file":"dir", cli_errstr(cli_share_src)); nt_status = cli_nt_error(cli_share_src); goto out; } if (!cli_close(cli_share_dst, fnum_dst)) { - d_fprintf(stderr, "could not close %s on destination server: %s\n", + d_fprintf(stderr, "could not close %s on destination server: %s\n", is_file?"file":"dir", cli_errstr(cli_share_dst)); nt_status = cli_nt_error(cli_share_dst); goto out; @@ -313,12 +313,12 @@ out: } /** - * Copy a file or directory from a connected share to another connected share + * Copy a file or directory from a connected share to another connected share * * @param c A net_context structure * @param mem_ctx A talloc-context - * @param cli_share_src A connected cli_state - * @param cli_share_dst A connected cli_state + * @param cli_share_src A connected cli_state + * @param cli_share_dst A connected cli_state * @param src_file The source file-name * @param dst_file The destination file-name * @param copy_acls Whether to copy acls @@ -327,12 +327,12 @@ out: * @param is_file Whether this file is a file or a dir * * @return Normal NTSTATUS return. - **/ + **/ NTSTATUS net_copy_file(struct net_context *c, TALLOC_CTX *mem_ctx, struct cli_state *cli_share_src, - struct cli_state *cli_share_dst, + struct cli_state *cli_share_dst, const char *src_name, const char *dst_name, bool copy_acls, bool copy_attrs, bool copy_timestamps, bool is_file) @@ -350,10 +350,10 @@ NTSTATUS net_copy_file(struct net_context *c, goto out; if (cli_share_src == NULL || cli_share_dst == NULL) - goto out; - + goto out; + /* open on the originating server */ - DEBUGADD(3,("opening %s %s on originating server\n", + DEBUGADD(3,("opening %s %s on originating server\n", is_file ? "file":"dir", src_name)); if (is_file) fnum_src = cli_open(cli_share_src, src_name, O_RDONLY, DENY_NONE); @@ -373,7 +373,7 @@ NTSTATUS net_copy_file(struct net_context *c, /* open file on the destination server */ DEBUGADD(3,("opening file %s on destination server\n", dst_name)); - fnum_dst = cli_open(cli_share_dst, dst_name, + fnum_dst = cli_open(cli_share_dst, dst_name, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE); if (fnum_dst == -1) { @@ -396,10 +396,10 @@ NTSTATUS net_copy_file(struct net_context *c, if (c->opt_verbose) { d_printf("copying [\\\\%s\\%s%s] => [\\\\%s\\%s%s] " - "%s ACLs and %s DOS Attributes %s\n", + "%s ACLs and %s DOS Attributes %s\n", cli_share_src->desthost, cli_share_src->share, src_name, cli_share_dst->desthost, cli_share_dst->share, dst_name, - copy_acls ? "with" : "without", + copy_acls ? "with" : "without", copy_attrs ? "with" : "without", copy_timestamps ? "(preserving timestamps)" : "" ); } @@ -409,17 +409,17 @@ NTSTATUS net_copy_file(struct net_context *c, /* copying file */ int n, ret; - n = cli_read(cli_share_src, fnum_src, data, nread, + n = cli_read(cli_share_src, fnum_src, data, nread, read_size); if (n <= 0) break; - ret = cli_write(cli_share_dst, fnum_dst, 0, data, + ret = cli_write(cli_share_dst, fnum_dst, 0, data, nread, n); if (n != ret) { - d_fprintf(stderr, "Error writing file: %s\n", + d_fprintf(stderr, "Error writing file: %s\n", cli_errstr(cli_share_dst)); nt_status = cli_nt_error(cli_share_dst); goto out; @@ -432,7 +432,7 @@ NTSTATUS net_copy_file(struct net_context *c, if (!is_file && !cli_chkpath(cli_share_dst, dst_name)) { /* creating dir */ - DEBUGADD(3,("creating dir %s on the destination server\n", + DEBUGADD(3,("creating dir %s on the destination server\n", dst_name)); if (!cli_mkdir(cli_share_dst, dst_name)) { @@ -451,14 +451,14 @@ NTSTATUS net_copy_file(struct net_context *c, /* closing files */ if (!cli_close(cli_share_src, fnum_src)) { - d_fprintf(stderr, "could not close file on originating server: %s\n", + d_fprintf(stderr, "could not close file on originating server: %s\n", cli_errstr(cli_share_src)); nt_status = cli_nt_error(cli_share_src); goto out; } if (is_file && !cli_close(cli_share_dst, fnum_dst)) { - d_fprintf(stderr, "could not close file on destination server: %s\n", + d_fprintf(stderr, "could not close file on destination server: %s\n", cli_errstr(cli_share_dst)); nt_status = cli_nt_error(cli_share_dst); goto out; @@ -466,7 +466,7 @@ NTSTATUS net_copy_file(struct net_context *c, /* possibly we have to copy some file-attributes / acls / sd */ nt_status = net_copy_fileattr(c, mem_ctx, cli_share_src, cli_share_dst, - src_name, dst_name, copy_acls, + src_name, dst_name, copy_acls, copy_attrs, copy_timestamps, is_file); if (!NT_STATUS_IS_OK(nt_status)) goto out; @@ -489,30 +489,30 @@ out: } /** - * Copy a driverfile from on connected share to another connected share - * This silently assumes that a driver-file is picked up from + * Copy a driverfile from on connected share to another connected share + * This silently assumes that a driver-file is picked up from * - * \\src_server\print$\{arch}\{version}\file + * \\src_server\print$\{arch}\{version}\file * * and copied to * - * \\dst_server\print$\{arch}\file - * + * \\dst_server\print$\{arch}\file + * * to be added via setdriver-calls later. * @param c A net_context structure * @param mem_ctx A talloc-context * @param cli_share_src A cli_state connected to source print$-share * @param cli_share_dst A cli_state connected to destination print$-share - * @param file The file-name to be copied + * @param file The file-name to be copied * @param short_archi The name of the driver-architecture (short form) * * @return Normal NTSTATUS return. - **/ + **/ static NTSTATUS net_copy_driverfile(struct net_context *c, TALLOC_CTX *mem_ctx, struct cli_state *cli_share_src, - struct cli_state *cli_share_dst, + struct cli_state *cli_share_dst, char *file, const char *short_archi) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; @@ -523,7 +523,7 @@ static NTSTATUS net_copy_driverfile(struct net_context *c, char *filename; char *tok; - /* scroll through the file until we have the part + /* scroll through the file until we have the part beyond archi_table.short_archi */ p = file; while (next_token_talloc(mem_ctx, &p, &tok, "\\")) { @@ -534,7 +534,7 @@ static NTSTATUS net_copy_driverfile(struct net_context *c, } /* build source file name */ - if (asprintf(&src_name, "\\%s\\%s\\%s", short_archi, version, filename) < 0 ) + if (asprintf(&src_name, "\\%s\\%s\\%s", short_archi, version, filename) < 0 ) return NT_STATUS_NO_MEMORY; @@ -577,7 +577,7 @@ static NTSTATUS check_arch_dir(struct cli_state *cli_share, const char *short_ar return NT_STATUS_NO_MEMORY; } - DEBUG(10,("creating print-driver dir for architecture: %s\n", + DEBUG(10,("creating print-driver dir for architecture: %s\n", short_archi)); if (!cli_mkdir(cli_share, dir)) { @@ -587,7 +587,7 @@ static NTSTATUS check_arch_dir(struct cli_state *cli_share, const char *short_ar } if (!cli_chkpath(cli_share, dir)) { - d_fprintf(stderr, "cannot check %s: %s\n", + d_fprintf(stderr, "cannot check %s: %s\n", dir, cli_errstr(cli_share)); goto out; } @@ -600,7 +600,7 @@ out: } /** - * Copy a print-driver (level 3) from one connected print$-share to another + * Copy a print-driver (level 3) from one connected print$-share to another * connected print$-share * * @param c A net_context structure @@ -615,21 +615,21 @@ out: static NTSTATUS copy_print_driver_3(struct net_context *c, TALLOC_CTX *mem_ctx, - struct cli_state *cli_share_src, - struct cli_state *cli_share_dst, + struct cli_state *cli_share_src, + struct cli_state *cli_share_dst, const char *short_archi, DRIVER_INFO_3 *i1) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; int length = 0; bool valid = True; - + fstring name = ""; fstring driverpath = ""; fstring datafile = ""; fstring configfile = ""; fstring helpfile = ""; fstring dependentfiles = ""; - + if (i1 == NULL) return nt_status; @@ -641,38 +641,38 @@ static NTSTATUS copy_print_driver_3(struct net_context *c, if (c->opt_verbose) - d_printf("copying driver: [%s], for architecture: [%s], version: [%d]\n", + d_printf("copying driver: [%s], for architecture: [%s], version: [%d]\n", name, short_archi, i1->version); - + nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst, driverpath, short_archi); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; - + nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst, datafile, short_archi); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; - + nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst, configfile, short_archi); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; - + nt_status = net_copy_driverfile(c, mem_ctx, cli_share_src, cli_share_dst, helpfile, short_archi); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; while (valid) { - + rpcstr_pull(dependentfiles, i1->dependentfiles+length, sizeof(dependentfiles), -1, STR_TERMINATE); length += strlen(dependentfiles)+1; - + if (strlen(dependentfiles) > 0) { nt_status = net_copy_driverfile(c, mem_ctx, - cli_share_src, cli_share_dst, + cli_share_src, cli_share_dst, dependentfiles, short_archi); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; @@ -690,17 +690,17 @@ static NTSTATUS copy_print_driver_3(struct net_context *c, * * the net_spoolss-functions aim to simplify spoolss-client-functions * required during the migration-process wrt buffer-sizes, returned - * error-codes, etc. + * error-codes, etc. * * this greatly reduces the complexitiy of the migrate-functions. * **/ static bool net_spoolss_enum_printers(struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, char *name, uint32 flags, - uint32 level, + uint32 level, uint32 *num_printers, PRINTER_INFO_CTR *ctr) { @@ -721,7 +721,7 @@ static bool net_spoolss_enum_printers(struct rpc_pipe_client *pipe_hnd, static bool net_spoolss_open_printer_ex(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, const char *printername, - uint32 access_required, + uint32 access_required, const char *username, POLICY_HND *hnd) { @@ -735,7 +735,7 @@ static bool net_spoolss_open_printer_ex(struct rpc_pipe_client *pipe_hnd, fstrcat(printername2, "\\"); fstrcat(printername2, printername); - DEBUG(10,("connecting to: %s as %s for %s and access: %x\n", + DEBUG(10,("connecting to: %s as %s for %s and access: %x\n", servername, username, printername2, access_required)); /* open printer */ @@ -745,18 +745,18 @@ static bool net_spoolss_open_printer_ex(struct rpc_pipe_client *pipe_hnd, /* be more verbose */ if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) { - d_fprintf(stderr, "no access to printer [%s] on [%s] for user [%s] granted\n", + d_fprintf(stderr, "no access to printer [%s] on [%s] for user [%s] granted\n", printername2, servername, username); return False; } if (!W_ERROR_IS_OK(result)) { - d_fprintf(stderr, "cannot open printer %s on server %s: %s\n", + d_fprintf(stderr, "cannot open printer %s on server %s: %s\n", printername2, servername, dos_errstr(result)); return False; } - DEBUG(2,("got printer handle for printer: %s, server: %s\n", + DEBUG(2,("got printer handle for printer: %s, server: %s\n", printername2, servername)); return True; @@ -765,7 +765,7 @@ static bool net_spoolss_open_printer_ex(struct rpc_pipe_client *pipe_hnd, static bool net_spoolss_getprinter(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, - uint32 level, + uint32 level, PRINTER_INFO_CTR *ctr) { WERROR result; @@ -784,7 +784,7 @@ static bool net_spoolss_getprinter(struct rpc_pipe_client *pipe_hnd, static bool net_spoolss_setprinter(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, - uint32 level, + uint32 level, PRINTER_INFO_CTR *ctr) { WERROR result; @@ -807,7 +807,7 @@ static bool net_spoolss_setprinterdata(struct rpc_pipe_client *pipe_hnd, REGISTRY_VALUE *value) { WERROR result; - + /* setprinterdata call */ result = rpccli_spoolss_setprinterdata(pipe_hnd, mem_ctx, hnd, value); @@ -830,32 +830,32 @@ static bool net_spoolss_enumprinterkey(struct rpc_pipe_client *pipe_hnd, /* enumprinterkey call */ result = rpccli_spoolss_enumprinterkey(pipe_hnd, mem_ctx, hnd, keyname, keylist, NULL); - + if (!W_ERROR_IS_OK(result)) { printf("enumprinterkey failed: %s\n", dos_errstr(result)); return False; } - + return True; } static bool net_spoolss_enumprinterdataex(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, - uint32 offered, + uint32 offered, POLICY_HND *hnd, - const char *keyname, - REGVAL_CTR *ctr) + const char *keyname, + REGVAL_CTR *ctr) { WERROR result; /* enumprinterdataex call */ result = rpccli_spoolss_enumprinterdataex(pipe_hnd, mem_ctx, hnd, keyname, ctr); - + if (!W_ERROR_IS_OK(result)) { printf("enumprinterdataex failed: %s\n", dos_errstr(result)); return False; } - + return True; } @@ -863,20 +863,20 @@ static bool net_spoolss_enumprinterdataex(struct rpc_pipe_client *pipe_hnd, static bool net_spoolss_setprinterdataex(struct rpc_pipe_client *pipe_hnd, TALLOC_CTX *mem_ctx, POLICY_HND *hnd, - char *keyname, + char *keyname, REGISTRY_VALUE *value) { WERROR result; /* setprinterdataex call */ - result = rpccli_spoolss_setprinterdataex(pipe_hnd, mem_ctx, hnd, + result = rpccli_spoolss_setprinterdataex(pipe_hnd, mem_ctx, hnd, keyname, value); - + if (!W_ERROR_IS_OK(result)) { printf("could not set printerdataex: %s\n", dos_errstr(result)); return False; } - + return True; } @@ -896,7 +896,7 @@ static bool net_spoolss_enumforms(struct rpc_pipe_client *pipe_hnd, printf("could not enum forms: %s\n", dos_errstr(result)); return False; } - + return True; } @@ -922,20 +922,20 @@ static bool net_spoolss_enumprinterdrivers (struct rpc_pipe_client *pipe_hnd, } static bool net_spoolss_getprinterdriver(struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, - POLICY_HND *hnd, uint32 level, - const char *env, int version, + TALLOC_CTX *mem_ctx, + POLICY_HND *hnd, uint32 level, + const char *env, int version, PRINTER_DRIVER_CTR *ctr) { WERROR result; - + /* getprinterdriver call */ result = rpccli_spoolss_getprinterdriver( pipe_hnd, mem_ctx, hnd, level, env, version, ctr); if (!W_ERROR_IS_OK(result)) { - DEBUG(1,("cannot get driver (for architecture: %s): %s\n", + DEBUG(1,("cannot get driver (for architecture: %s): %s\n", env, dos_errstr(result))); if (W_ERROR_V(result) != W_ERROR_V(WERR_UNKNOWN_PRINTER_DRIVER) && W_ERROR_V(result) != W_ERROR_V(WERR_INVALID_ENVIRONMENT)) { @@ -971,15 +971,15 @@ static bool net_spoolss_addprinterdriver(struct rpc_pipe_client *pipe_hnd, } /** - * abstraction function to get uint32 num_printers and PRINTER_INFO_CTR ctr - * for a single printer or for all printers depending on argc/argv + * abstraction function to get uint32 num_printers and PRINTER_INFO_CTR ctr + * for a single printer or for all printers depending on argc/argv **/ static bool get_printer_info(struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, int level, int argc, - const char **argv, + const char **argv, uint32 *num_printers, PRINTER_INFO_CTR *ctr) { @@ -989,9 +989,9 @@ static bool get_printer_info(struct rpc_pipe_client *pipe_hnd, /* no arguments given, enumerate all printers */ if (argc == 0) { - if (!net_spoolss_enum_printers(pipe_hnd, mem_ctx, NULL, - PRINTER_ENUM_LOCAL|PRINTER_ENUM_SHARED, - level, num_printers, ctr)) + if (!net_spoolss_enum_printers(pipe_hnd, mem_ctx, NULL, + PRINTER_ENUM_LOCAL|PRINTER_ENUM_SHARED, + level, num_printers, ctr)) return False; goto out; @@ -1021,11 +1021,11 @@ out: } -/** +/** * List print-queues (including local printers that are not shared) * * All parameters are provided by the run_rpc_command function, except for - * argc, argv which are passed through. + * argc, argv which are passed through. * * @param c A net_context structure * @param domain_sid The domain sid aquired from the remote server @@ -1040,15 +1040,15 @@ out: NTSTATUS rpc_printer_list_internals(struct net_context *c, const DOM_SID *domain_sid, - const char *domain_name, + const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, int argc, const char **argv) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; - uint32 i, num_printers; + uint32 i, num_printers; uint32 level = 2; char *printername, *sharename; PRINTER_INFO_CTR ctr; @@ -1080,11 +1080,11 @@ NTSTATUS rpc_printer_list_internals(struct net_context *c, return NT_STATUS_OK; } -/** - * List printer-drivers from a server +/** + * List printer-drivers from a server * * All parameters are provided by the run_rpc_command function, except for - * argc, argv which are passed through. + * argc, argv which are passed through. * * @param c A net_context structure * @param domain_sid The domain sid aquired from the remote server @@ -1099,19 +1099,19 @@ NTSTATUS rpc_printer_list_internals(struct net_context *c, NTSTATUS rpc_printer_driver_list_internals(struct net_context *c, const DOM_SID *domain_sid, - const char *domain_name, + const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, int argc, const char **argv) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; uint32 i; - uint32 level = 3; + uint32 level = 3; PRINTER_DRIVER_CTR drv_ctr_enum; int d; - + ZERO_STRUCT(drv_ctr_enum); printf("listing printer-drivers\n"); @@ -1122,19 +1122,19 @@ NTSTATUS rpc_printer_driver_list_internals(struct net_context *c, /* enum remote drivers */ if (!net_spoolss_enumprinterdrivers(pipe_hnd, mem_ctx, level, - archi_table[i].long_archi, + archi_table[i].long_archi, &num_drivers, &drv_ctr_enum)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } if (num_drivers == 0) { - d_printf ("no drivers found on server for architecture: [%s].\n", + d_printf ("no drivers found on server for architecture: [%s].\n", archi_table[i].long_archi); continue; - } - - d_printf("got %d printer-drivers for architecture: [%s]\n", + } + + d_printf("got %d printer-drivers for architecture: [%s]\n", num_drivers, archi_table[i].long_archi); @@ -1143,7 +1143,7 @@ NTSTATUS rpc_printer_driver_list_internals(struct net_context *c, display_print_driver_3(&(drv_ctr_enum.info3[d])); } } - + nt_status = NT_STATUS_OK; done: @@ -1151,7 +1151,7 @@ done: } -/** +/** * Publish print-queues with args-wrapper * * @param cli A cli_state connected to the server. @@ -1165,13 +1165,13 @@ done: **/ static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, int argc, const char **argv, uint32 action) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; - uint32 i, num_printers; + uint32 i, num_printers; uint32 level = 7; char *printername, *sharename; PRINTER_INFO_CTR ctr, ctr_pub; @@ -1207,7 +1207,7 @@ static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_ got_hnd = True; /* check for existing dst printer */ - if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &ctr_pub)) + if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &ctr_pub)) goto done; /* check action and set string */ @@ -1241,18 +1241,18 @@ static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_ nt_status = NT_STATUS_OK; done: - if (got_hnd) + if (got_hnd) rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd); - + return nt_status; } NTSTATUS rpc_printer_publish_publish_internals(struct net_context *c, const DOM_SID *domain_sid, - const char *domain_name, + const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, int argc, const char **argv) { @@ -1261,10 +1261,10 @@ NTSTATUS rpc_printer_publish_publish_internals(struct net_context *c, NTSTATUS rpc_printer_publish_unpublish_internals(struct net_context *c, const DOM_SID *domain_sid, - const char *domain_name, + const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, int argc, const char **argv) { @@ -1273,21 +1273,21 @@ NTSTATUS rpc_printer_publish_unpublish_internals(struct net_context *c, NTSTATUS rpc_printer_publish_update_internals(struct net_context *c, const DOM_SID *domain_sid, - const char *domain_name, + const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, int argc, const char **argv) { return rpc_printer_publish_internals_args(pipe_hnd, mem_ctx, argc, argv, SPOOL_DS_UPDATE); } -/** +/** * List print-queues w.r.t. their publishing state * * All parameters are provided by the run_rpc_command function, except for - * argc, argv which are passed through. + * argc, argv which are passed through. * * @param c A net_context structure * @param domain_sid The domain sid aquired from the remote server @@ -1302,15 +1302,15 @@ NTSTATUS rpc_printer_publish_update_internals(struct net_context *c, NTSTATUS rpc_printer_publish_list_internals(struct net_context *c, const DOM_SID *domain_sid, - const char *domain_name, + const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, int argc, const char **argv) { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; - uint32 i, num_printers; + uint32 i, num_printers; uint32 level = 7; char *printername, *sharename; char *guid; @@ -1342,13 +1342,13 @@ NTSTATUS rpc_printer_publish_list_internals(struct net_context *c, /* open printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, - PRINTER_ALL_ACCESS, cli->user_name, &hnd)) + PRINTER_ALL_ACCESS, cli->user_name, &hnd)) goto done; got_hnd = True; /* check for existing dst printer */ - if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &ctr_pub)) + if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &ctr_pub)) goto done; rpcstr_pull_talloc(mem_ctx, @@ -1382,17 +1382,17 @@ NTSTATUS rpc_printer_publish_list_internals(struct net_context *c, nt_status = NT_STATUS_OK; done: - if (got_hnd) + if (got_hnd) rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd); - + return nt_status; } -/** +/** * Migrate Printer-ACLs from a source server to the destination server * * All parameters are provided by the run_rpc_command function, except for - * argc, argv which are passed through. + * argc, argv which are passed through. * * @param c A net_context structure * @param domain_sid The domain sid aquired from the remote server @@ -1407,14 +1407,14 @@ done: NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c, const DOM_SID *domain_sid, - const char *domain_name, + const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, int argc, const char **argv) { - /* TODO: what now, info2 or info3 ? + /* TODO: what now, info2 or info3 ? convince jerry that we should add clientside setacls level 3 at least */ NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; @@ -1473,10 +1473,10 @@ NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c, get any real NT_STATUS-codes anymore from now on */ nt_status = NT_STATUS_UNSUCCESSFUL; - d_printf("migrating printer ACLs for: [%s] / [%s]\n", + d_printf("migrating printer ACLs for: [%s] / [%s]\n", printername, sharename); - /* according to msdn you have specify these access-rights + /* according to msdn you have specify these access-rights to see the security descriptor - READ_CONTROL (DACL) - ACCESS_SYSTEM_SECURITY (SACL) @@ -1484,38 +1484,38 @@ NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c, /* open src printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, - MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) + MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) goto done; got_hnd_src = True; /* open dst printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename, - PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst)) + PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst)) goto done; got_hnd_dst = True; /* check for existing dst printer */ - if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) + if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) goto done; /* check for existing src printer */ - if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, 3, &ctr_src)) + if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, 3, &ctr_src)) goto done; /* Copy Security Descriptor */ /* copy secdesc (info level 2) */ - ctr_dst.printers_2->devmode = NULL; + ctr_dst.printers_2->devmode = NULL; ctr_dst.printers_2->secdesc = dup_sec_desc(mem_ctx, ctr_src.printers_3->secdesc); if (c->opt_verbose) display_sec_desc(ctr_dst.printers_2->secdesc); - - if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &ctr_dst)) + + if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &ctr_dst)) goto done; - + DEBUGADD(1,("\tSetPrinter of SECDESC succeeded\n")); @@ -1531,7 +1531,7 @@ NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c, } } - + nt_status = NT_STATUS_OK; done: @@ -1550,11 +1550,11 @@ done: return nt_status; } -/** +/** * Migrate printer-forms from a src server to the dst server * * All parameters are provided by the run_rpc_command function, except for - * argc, argv which are passed through. + * argc, argv which are passed through. * * @param c A net_context structure * @param domain_sid The domain sid aquired from the remote server @@ -1569,10 +1569,10 @@ done: NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c, const DOM_SID *domain_sid, - const char *domain_name, + const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, int argc, const char **argv) { @@ -1639,7 +1639,7 @@ NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c, /* open src printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, - MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) + MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) goto done; got_hnd_src = True; @@ -1647,14 +1647,14 @@ NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c, /* open dst printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename, - PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) + PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) goto done; got_hnd_dst = True; /* check for existing dst printer */ - if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) + if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) goto done; /* finally migrate forms */ @@ -1668,8 +1668,8 @@ NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c, FORM form; fstring form_name; - - /* only migrate FORM_PRINTER types, according to jerry + + /* only migrate FORM_PRINTER types, according to jerry FORM_BUILTIN-types are hard-coded in samba */ if (forms[f].flag != FORM_PRINTER) continue; @@ -1679,7 +1679,7 @@ NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c, sizeof(form_name), -1, STR_TERMINATE); if (c->opt_verbose) - d_printf("\tmigrating form # %d [%s] of type [%d]\n", + d_printf("\tmigrating form # %d [%s] of type [%d]\n", f, form_name, forms[f].flag); /* is there a more elegant way to do that ? */ @@ -1690,19 +1690,19 @@ NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c, form.top = forms[f].top; form.right = forms[f].right; form.bottom = forms[f].bottom; - + init_unistr2(&form.name, form_name, UNI_STR_TERMINATE); - /* FIXME: there might be something wrong with samba's + /* FIXME: there might be something wrong with samba's builtin-forms */ - result = rpccli_spoolss_addform(pipe_hnd_dst, mem_ctx, + result = rpccli_spoolss_addform(pipe_hnd_dst, mem_ctx, &hnd_dst, 1, &form); if (!W_ERROR_IS_OK(result)) { - d_printf("\tAddForm form %d: [%s] refused.\n", + d_printf("\tAddForm form %d: [%s] refused.\n", f, form_name); continue; } - + DEBUGADD(1,("\tAddForm of [%s] succeeded\n", form_name)); } @@ -1735,11 +1735,11 @@ done: return nt_status; } -/** +/** * Migrate printer-drivers from a src server to the dst server * * All parameters are provided by the run_rpc_command function, except for - * argc, argv which are passed through. + * argc, argv which are passed through. * * @param c A net_context structure * @param domain_sid The domain sid aquired from the remote server @@ -1754,10 +1754,10 @@ done: NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c, const DOM_SID *domain_sid, - const char *domain_name, + const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, int argc, const char **argv) { @@ -1839,22 +1839,22 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c, goto done; } - /* we can reset NT_STATUS here because we do not + /* we can reset NT_STATUS here because we do not get any real NT_STATUS-codes anymore from now on */ nt_status = NT_STATUS_UNSUCCESSFUL; - d_printf("migrating printer driver for: [%s] / [%s]\n", + d_printf("migrating printer driver for: [%s] / [%s]\n", printername, sharename); /* open dst printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename, - PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) + PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) goto done; got_hnd_dst = True; /* check for existing dst printer */ - if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_ctr_dst)) + if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_ctr_dst)) goto done; @@ -1870,16 +1870,16 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c, /* in a first step call getdriver for each shared printer (per arch) to get a list of all files that have to be copied */ - + for (i=0; archi_table[i].long_archi!=NULL; i++) { /* getdriver src */ - if (!net_spoolss_getprinterdriver(pipe_hnd, mem_ctx, &hnd_src, - level, archi_table[i].long_archi, - archi_table[i].version, &drv_ctr_src)) + if (!net_spoolss_getprinterdriver(pipe_hnd, mem_ctx, &hnd_src, + level, archi_table[i].long_archi, + archi_table[i].version, &drv_ctr_src)) continue; - rpcstr_pull(drivername, drv_ctr_src.info3->name.buffer, + rpcstr_pull(drivername, drv_ctr_src.info3->name.buffer, sizeof(drivername), -1, STR_TERMINATE); if (c->opt_verbose) @@ -1894,19 +1894,19 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c, /* copy driver-files */ nt_status = copy_print_driver_3(c, mem_ctx, cli_share_src, cli_share_dst, - archi_table[i].short_archi, + archi_table[i].short_archi, drv_ctr_src.info3); if (!NT_STATUS_IS_OK(nt_status)) goto done; /* adddriver dst */ - if (!net_spoolss_addprinterdriver(pipe_hnd_dst, mem_ctx, level, &drv_ctr_src)) { + if (!net_spoolss_addprinterdriver(pipe_hnd_dst, mem_ctx, level, &drv_ctr_src)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } - - DEBUGADD(1,("Sucessfully added driver [%s] for printer [%s]\n", + + DEBUGADD(1,("Sucessfully added driver [%s] for printer [%s]\n", drivername, printername)); } @@ -1919,13 +1919,13 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c, /* setdriver dst */ init_unistr(&info_ctr_dst.printers_2->drivername, drivername); - - if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_ctr_dst)) { + + if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_ctr_dst)) { nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } - DEBUGADD(1,("Sucessfully set driver %s for printer %s\n", + DEBUGADD(1,("Sucessfully set driver %s for printer %s\n", drivername, printername)); /* close dst */ @@ -1965,12 +1965,12 @@ done: } -/** +/** * Migrate printer-queues from a src to the dst server * (requires a working "addprinter command" to be installed for the local smbd) * * All parameters are provided by the run_rpc_command function, except for - * argc, argv which are passed through. + * argc, argv which are passed through. * * @param c A net_context structure * @param domain_sid The domain sid aquired from the remote server @@ -1985,10 +1985,10 @@ done: NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c, const DOM_SID *domain_sid, - const char *domain_name, + const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, int argc, const char **argv) { @@ -2044,13 +2044,13 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c, get any real NT_STATUS-codes anymore from now on */ nt_status = NT_STATUS_UNSUCCESSFUL; - d_printf("migrating printer queue for: [%s] / [%s]\n", + d_printf("migrating printer queue for: [%s] / [%s]\n", printername, sharename); /* open dst printer handle */ - if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename, + if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename, PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) { - + DEBUG(1,("could not open printer: %s\n", sharename)); } else { got_hnd_dst = True; @@ -2069,28 +2069,28 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c, continue; } - /* now get again src printer ctr via getprinter, + /* now get again src printer ctr via getprinter, we first need a handle for that */ /* open src printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, - MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) + MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) goto done; got_hnd_src = True; /* getprinter on the src server */ - if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, level, &ctr_src)) + if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, level, &ctr_src)) goto done; - /* copy each src printer to a dst printer 1:1, + /* copy each src printer to a dst printer 1:1, maybe some values have to be changed though */ d_printf("creating printer: %s\n", printername); result = rpccli_spoolss_addprinterex (pipe_hnd_dst, mem_ctx, level, &ctr_src); if (W_ERROR_IS_OK(result)) d_printf ("printer [%s] successfully added.\n", printername); - else if (W_ERROR_V(result) == W_ERROR_V(WERR_PRINTER_ALREADY_EXISTS)) + else if (W_ERROR_V(result) == W_ERROR_V(WERR_PRINTER_ALREADY_EXISTS)) d_fprintf (stderr, "printer [%s] already exists.\n", printername); else { d_fprintf (stderr, "could not create printer [%s]\n", printername); @@ -2124,12 +2124,12 @@ done: return nt_status; } -/** +/** * Migrate Printer-Settings from a src server to the dst server * (for this to work, printers and drivers already have to be migrated earlier) * * All parameters are provided by the run_rpc_command function, except for - * argc, argv which are passed through. + * argc, argv which are passed through. * * @param c A net_context structure * @param domain_sid The domain sid aquired from the remote server @@ -2144,10 +2144,10 @@ done: NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, const DOM_SID *domain_sid, - const char *domain_name, + const char *domain_name, struct cli_state *cli, struct rpc_pipe_client *pipe_hnd, - TALLOC_CTX *mem_ctx, + TALLOC_CTX *mem_ctx, int argc, const char **argv) { @@ -2218,17 +2218,17 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, nt_status = NT_STATUS_UNSUCCESSFUL; goto done; } - /* we can reset NT_STATUS here because we do not + /* we can reset NT_STATUS here because we do not get any real NT_STATUS-codes anymore from now on */ nt_status = NT_STATUS_UNSUCCESSFUL; - d_printf("migrating printer settings for: [%s] / [%s]\n", + d_printf("migrating printer settings for: [%s] / [%s]\n", printername, sharename); /* open src printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd, mem_ctx, sharename, - MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) + MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) goto done; got_hnd_src = True; @@ -2236,29 +2236,29 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, /* open dst printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename, - PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst)) + PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst)) goto done; got_hnd_dst = True; /* check for existing dst printer */ - if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, - level, &ctr_dst)) + if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, + level, &ctr_dst)) goto done; - /* STEP 1: COPY DEVICE-MODE and other + /* STEP 1: COPY DEVICE-MODE and other PRINTER_INFO_2-attributes */ ctr_dst.printers_2 = &ctr_enum.printers_2[i]; - /* why is the port always disconnected when the printer + /* why is the port always disconnected when the printer is correctly installed (incl. driver ???) */ init_unistr( &ctr_dst.printers_2->portname, SAMBA_PRINTER_PORT_NAME); - /* check if printer is published */ + /* check if printer is published */ if (ctr_enum.printers_2[i].attributes & PRINTER_ATTRIBUTE_PUBLISHED) { /* check for existing dst printer */ @@ -2293,21 +2293,21 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, } init_unistr(&ctr_dst.printers_2->devmode->devicename, - devicename); + devicename); #endif if (!net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, - level, &ctr_dst)) + level, &ctr_dst)) goto done; - + DEBUGADD(1,("\tSetPrinter of DEVICEMODE succeeded\n")); } /* STEP 2: COPY REGISTRY VALUES */ - - /* please keep in mind that samba parse_spools gives horribly - crippled results when used to rpccli_spoolss_enumprinterdataex + + /* please keep in mind that samba parse_spools gives horribly + crippled results when used to rpccli_spoolss_enumprinterdataex a win2k3-server. (Bugzilla #1851) - FIXME: IIRC I've seen it too on a win2k-server + FIXME: IIRC I've seen it too on a win2k-server */ /* enumerate data on src handle */ @@ -2316,9 +2316,9 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, /* loop for all printerdata of "PrinterDriverData" */ while (W_ERROR_IS_OK(result)) { - + REGISTRY_VALUE value; - + result = rpccli_spoolss_enumprinterdata( pipe_hnd, mem_ctx, &hnd_src, p++, val_needed, data_needed, 0, 0, &value); @@ -2331,20 +2331,20 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, display_reg_value(SPOOL_PRINTERDATA_KEY, value); /* set_value */ - if (!net_spoolss_setprinterdata(pipe_hnd_dst, mem_ctx, - &hnd_dst, &value)) + if (!net_spoolss_setprinterdata(pipe_hnd_dst, mem_ctx, + &hnd_dst, &value)) goto done; - DEBUGADD(1,("\tSetPrinterData of [%s] succeeded\n", + DEBUGADD(1,("\tSetPrinterData of [%s] succeeded\n", value.valuename)); } } - + /* STEP 3: COPY SUBKEY VALUES */ - /* here we need to enum all printer_keys and then work + /* here we need to enum all printer_keys and then work on the result with enum_printer_key_ex. nt4 does not - respond to enumprinterkey, win2k does, so continue + respond to enumprinterkey, win2k does, so continue in case of an error */ if (!net_spoolss_enumprinterkey(pipe_hnd, mem_ctx, &hnd_src, "", &keylist)) { @@ -2353,9 +2353,9 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, } - /* work on a list of printer keys + /* work on a list of printer keys each key has to be enumerated to get all required - information. information is then set via setprinterdataex-calls */ + information. information is then set via setprinterdataex-calls */ if (keylist == NULL) continue; @@ -2378,34 +2378,34 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, return NT_STATUS_NO_MEMORY; /* enumerate all src subkeys */ - if (!net_spoolss_enumprinterdataex(pipe_hnd, mem_ctx, 0, - &hnd_src, subkey, - reg_ctr)) + if (!net_spoolss_enumprinterdataex(pipe_hnd, mem_ctx, 0, + &hnd_src, subkey, + reg_ctr)) goto done; for (j=0; j < reg_ctr->num_values; j++) { - + REGISTRY_VALUE value; UNISTR2 data; - - /* although samba replies with sane data in most cases we + + /* although samba replies with sane data in most cases we should try to avoid writing wrong registry data */ - - if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_PORTNAME) || + + if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_PORTNAME) || strequal(reg_ctr->values[j]->valuename, SPOOL_REG_UNCNAME) || strequal(reg_ctr->values[j]->valuename, SPOOL_REG_URL) || strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SHORTSERVERNAME) || strequal(reg_ctr->values[j]->valuename, SPOOL_REG_SERVERNAME)) { if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_PORTNAME)) { - + /* although windows uses a multi-sz, we use a sz */ init_unistr2(&data, SAMBA_PRINTER_PORT_NAME, UNI_STR_TERMINATE); fstrcpy(value.valuename, SPOOL_REG_PORTNAME); } - + if (strequal(reg_ctr->values[j]->valuename, SPOOL_REG_UNCNAME)) { - + if (asprintf(&unc_name, "\\\\%s\\%s", longname, sharename) < 0) { nt_status = NT_STATUS_NO_MEMORY; goto done; @@ -2453,23 +2453,23 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, display_reg_value(subkey, value); /* here we have to set all subkeys on the dst server */ - if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst, - subkey, &value)) + if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst, + subkey, &value)) goto done; - + } else { if (c->opt_verbose) display_reg_value(subkey, *(reg_ctr->values[j])); /* here we have to set all subkeys on the dst server */ - if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst, - subkey, reg_ctr->values[j])) + if (!net_spoolss_setprinterdataex(pipe_hnd_dst, mem_ctx, &hnd_dst, + subkey, reg_ctr->values[j])) goto done; } - DEBUGADD(1,("\tSetPrinterDataEx of key [%s\\%s] succeeded\n", + DEBUGADD(1,("\tSetPrinterDataEx of key [%s\\%s] succeeded\n", subkey, reg_ctr->values[j]->valuename)); } @@ -2491,7 +2491,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, } } - + nt_status = NT_STATUS_OK; done: -- cgit From 16938883e6fcae7601eb6343177aa2d56dd2136e Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Mon, 12 May 2008 11:53:23 +0200 Subject: net: Use true/false instead of True/False. (This used to be commit a8b567aac3b0e39cfe67fb97167b10312ca5e73a) --- source3/utils/net_rpc_printer.c | 148 ++++++++++++++++++++-------------------- 1 file changed, 74 insertions(+), 74 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index 9fcbb2272c..fd938cbeaa 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -63,7 +63,7 @@ static void display_print_driver_3(DRIVER_INFO_3 *i1) fstring defaultdatatype = ""; int length=0; - bool valid = True; + bool valid = true; if (i1 == NULL) return; @@ -94,7 +94,7 @@ static void display_print_driver_3(DRIVER_INFO_3 *i1) if (strlen(dependentfiles) > 0) { d_printf ("\tDependentfiles: [%s]\n", dependentfiles); } else { - valid = False; + valid = false; } } @@ -621,7 +621,7 @@ static NTSTATUS copy_print_driver_3(struct net_context *c, { NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL; int length = 0; - bool valid = True; + bool valid = true; fstring name = ""; fstring driverpath = ""; @@ -677,7 +677,7 @@ static NTSTATUS copy_print_driver_3(struct net_context *c, if (!NT_STATUS_IS_OK(nt_status)) return nt_status; } else { - valid = False; + valid = false; } } @@ -712,10 +712,10 @@ static bool net_spoolss_enum_printers(struct rpc_pipe_client *pipe_hnd, if (!W_ERROR_IS_OK(result)) { printf("cannot enum printers: %s\n", dos_errstr(result)); - return False; + return false; } - return True; + return true; } static bool net_spoolss_open_printer_ex(struct rpc_pipe_client *pipe_hnd, @@ -747,19 +747,19 @@ static bool net_spoolss_open_printer_ex(struct rpc_pipe_client *pipe_hnd, if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) { d_fprintf(stderr, "no access to printer [%s] on [%s] for user [%s] granted\n", printername2, servername, username); - return False; + return false; } if (!W_ERROR_IS_OK(result)) { d_fprintf(stderr, "cannot open printer %s on server %s: %s\n", printername2, servername, dos_errstr(result)); - return False; + return false; } DEBUG(2,("got printer handle for printer: %s, server: %s\n", printername2, servername)); - return True; + return true; } static bool net_spoolss_getprinter(struct rpc_pipe_client *pipe_hnd, @@ -775,10 +775,10 @@ static bool net_spoolss_getprinter(struct rpc_pipe_client *pipe_hnd, if (!W_ERROR_IS_OK(result)) { printf("cannot get printer-info: %s\n", dos_errstr(result)); - return False; + return false; } - return True; + return true; } static bool net_spoolss_setprinter(struct rpc_pipe_client *pipe_hnd, @@ -794,10 +794,10 @@ static bool net_spoolss_setprinter(struct rpc_pipe_client *pipe_hnd, if (!W_ERROR_IS_OK(result)) { printf("cannot set printer-info: %s\n", dos_errstr(result)); - return False; + return false; } - return True; + return true; } @@ -813,10 +813,10 @@ static bool net_spoolss_setprinterdata(struct rpc_pipe_client *pipe_hnd, if (!W_ERROR_IS_OK(result)) { printf ("unable to set printerdata: %s\n", dos_errstr(result)); - return False; + return false; } - return True; + return true; } @@ -833,10 +833,10 @@ static bool net_spoolss_enumprinterkey(struct rpc_pipe_client *pipe_hnd, if (!W_ERROR_IS_OK(result)) { printf("enumprinterkey failed: %s\n", dos_errstr(result)); - return False; + return false; } - return True; + return true; } static bool net_spoolss_enumprinterdataex(struct rpc_pipe_client *pipe_hnd, @@ -853,10 +853,10 @@ static bool net_spoolss_enumprinterdataex(struct rpc_pipe_client *pipe_hnd, if (!W_ERROR_IS_OK(result)) { printf("enumprinterdataex failed: %s\n", dos_errstr(result)); - return False; + return false; } - return True; + return true; } @@ -874,10 +874,10 @@ static bool net_spoolss_setprinterdataex(struct rpc_pipe_client *pipe_hnd, if (!W_ERROR_IS_OK(result)) { printf("could not set printerdataex: %s\n", dos_errstr(result)); - return False; + return false; } - return True; + return true; } static bool net_spoolss_enumforms(struct rpc_pipe_client *pipe_hnd, @@ -894,10 +894,10 @@ static bool net_spoolss_enumforms(struct rpc_pipe_client *pipe_hnd, if (!W_ERROR_IS_OK(result)) { printf("could not enum forms: %s\n", dos_errstr(result)); - return False; + return false; } - return True; + return true; } static bool net_spoolss_enumprinterdrivers (struct rpc_pipe_client *pipe_hnd, @@ -915,10 +915,10 @@ static bool net_spoolss_enumprinterdrivers (struct rpc_pipe_client *pipe_hnd, if (!W_ERROR_IS_OK(result)) { printf("cannot enum drivers: %s\n", dos_errstr(result)); - return False; + return false; } - return True; + return true; } static bool net_spoolss_getprinterdriver(struct rpc_pipe_client *pipe_hnd, @@ -941,10 +941,10 @@ static bool net_spoolss_getprinterdriver(struct rpc_pipe_client *pipe_hnd, W_ERROR_V(result) != W_ERROR_V(WERR_INVALID_ENVIRONMENT)) { printf("cannot get driver: %s\n", dos_errstr(result)); } - return False; + return false; } - return True; + return true; } @@ -960,14 +960,14 @@ static bool net_spoolss_addprinterdriver(struct rpc_pipe_client *pipe_hnd, /* be more verbose */ if (W_ERROR_V(result) == W_ERROR_V(WERR_ACCESS_DENIED)) { printf("You are not allowed to add drivers\n"); - return False; + return false; } if (!W_ERROR_IS_OK(result)) { printf("cannot add driver: %s\n", dos_errstr(result)); - return False; + return false; } - return True; + return true; } /** @@ -992,7 +992,7 @@ static bool get_printer_info(struct rpc_pipe_client *pipe_hnd, if (!net_spoolss_enum_printers(pipe_hnd, mem_ctx, NULL, PRINTER_ENUM_LOCAL|PRINTER_ENUM_SHARED, level, num_printers, ctr)) - return False; + return false; goto out; } @@ -1003,11 +1003,11 @@ static bool get_printer_info(struct rpc_pipe_client *pipe_hnd, MAXIMUM_ALLOWED_ACCESS, pipe_hnd->auth->user_name, &hnd)) - return False; + return false; if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, ctr)) { rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd); - return False; + return false; } rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd); @@ -1017,7 +1017,7 @@ static bool get_printer_info(struct rpc_pipe_client *pipe_hnd, out: DEBUG(3,("got %d printers\n", *num_printers)); - return True; + return true; } @@ -1176,7 +1176,7 @@ static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_ char *printername, *sharename; PRINTER_INFO_CTR ctr, ctr_pub; POLICY_HND hnd; - bool got_hnd = False; + bool got_hnd = false; WERROR result; const char *action_str; @@ -1204,7 +1204,7 @@ static NTSTATUS rpc_printer_publish_internals_args(struct rpc_pipe_client *pipe_ PRINTER_ALL_ACCESS, pipe_hnd->auth->user_name, &hnd)) goto done; - got_hnd = True; + got_hnd = true; /* check for existing dst printer */ if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &ctr_pub)) @@ -1316,7 +1316,7 @@ NTSTATUS rpc_printer_publish_list_internals(struct net_context *c, char *guid; PRINTER_INFO_CTR ctr, ctr_pub; POLICY_HND hnd; - bool got_hnd = False; + bool got_hnd = false; int state; if (!get_printer_info(pipe_hnd, mem_ctx, 2, argc, argv, &num_printers, &ctr)) @@ -1345,7 +1345,7 @@ NTSTATUS rpc_printer_publish_list_internals(struct net_context *c, PRINTER_ALL_ACCESS, cli->user_name, &hnd)) goto done; - got_hnd = True; + got_hnd = true; /* check for existing dst printer */ if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd, level, &ctr_pub)) @@ -1422,8 +1422,8 @@ NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c, uint32 num_printers; uint32 level = 2; char *printername, *sharename; - bool got_hnd_src = False; - bool got_hnd_dst = False; + bool got_hnd_src = false; + bool got_hnd_dst = false; struct rpc_pipe_client *pipe_hnd_dst = NULL; POLICY_HND hnd_src, hnd_dst; PRINTER_INFO_CTR ctr_src, ctr_dst, ctr_enum; @@ -1487,14 +1487,14 @@ NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c, MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) goto done; - got_hnd_src = True; + got_hnd_src = true; /* open dst printer handle */ if (!net_spoolss_open_printer_ex(pipe_hnd_dst, mem_ctx, sharename, PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst)) goto done; - got_hnd_dst = True; + got_hnd_dst = true; /* check for existing dst printer */ if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, level, &ctr_dst)) @@ -1522,12 +1522,12 @@ NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c, /* close printer handles here */ if (got_hnd_src) { rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); - got_hnd_src = False; + got_hnd_src = false; } if (got_hnd_dst) { rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); - got_hnd_dst = False; + got_hnd_dst = false; } } @@ -1582,8 +1582,8 @@ NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c, uint32 num_printers; uint32 level = 1; char *printername, *sharename; - bool got_hnd_src = False; - bool got_hnd_dst = False; + bool got_hnd_src = false; + bool got_hnd_dst = false; struct rpc_pipe_client *pipe_hnd_dst = NULL; POLICY_HND hnd_src, hnd_dst; PRINTER_INFO_CTR ctr_enum, ctr_dst; @@ -1642,7 +1642,7 @@ NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c, MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) goto done; - got_hnd_src = True; + got_hnd_src = true; /* open dst printer handle */ @@ -1650,7 +1650,7 @@ NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c, PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) goto done; - got_hnd_dst = True; + got_hnd_dst = true; /* check for existing dst printer */ @@ -1710,12 +1710,12 @@ NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c, /* close printer handles here */ if (got_hnd_src) { rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); - got_hnd_src = False; + got_hnd_src = false; } if (got_hnd_dst) { rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); - got_hnd_dst = False; + got_hnd_dst = false; } } @@ -1766,10 +1766,10 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c, uint32 num_printers; uint32 level = 3; char *printername, *sharename; - bool got_hnd_src = False; - bool got_hnd_dst = False; - bool got_src_driver_share = False; - bool got_dst_driver_share = False; + bool got_hnd_src = false; + bool got_hnd_dst = false; + bool got_src_driver_share = false; + bool got_dst_driver_share = false; struct rpc_pipe_client *pipe_hnd_dst = NULL; POLICY_HND hnd_src, hnd_dst; PRINTER_DRIVER_CTR drv_ctr_src, drv_ctr_dst; @@ -1796,7 +1796,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c, if (!NT_STATUS_IS_OK(nt_status)) goto done; - got_src_driver_share = True; + got_src_driver_share = true; /* open print$-share on the dst server */ @@ -1805,7 +1805,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c, if (!NT_STATUS_IS_OK(nt_status)) return nt_status; - got_dst_driver_share = True; + got_dst_driver_share = true; /* enum src printers */ @@ -1851,7 +1851,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c, PRINTER_ALL_ACCESS, cli->user_name, &hnd_dst)) goto done; - got_hnd_dst = True; + got_hnd_dst = true; /* check for existing dst printer */ if (!net_spoolss_getprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 2, &info_ctr_dst)) @@ -1865,7 +1865,7 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c, &hnd_src)) goto done; - got_hnd_src = True; + got_hnd_src = true; /* in a first step call getdriver for each shared printer (per arch) @@ -1931,13 +1931,13 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c, /* close dst */ if (got_hnd_dst) { rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); - got_hnd_dst = False; + got_hnd_dst = false; } /* close src */ if (got_hnd_src) { rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); - got_hnd_src = False; + got_hnd_src = false; } } @@ -2000,8 +2000,8 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c, struct cli_state *cli_dst = NULL; POLICY_HND hnd_dst, hnd_src; char *printername, *sharename; - bool got_hnd_src = False; - bool got_hnd_dst = False; + bool got_hnd_src = false; + bool got_hnd_dst = false; struct rpc_pipe_client *pipe_hnd_dst = NULL; DEBUG(3,("copying printers\n")); @@ -2053,7 +2053,7 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c, DEBUG(1,("could not open printer: %s\n", sharename)); } else { - got_hnd_dst = True; + got_hnd_dst = true; } /* check for existing dst printer */ @@ -2064,7 +2064,7 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c, /* close printer handle here - dst only, not got src yet. */ if (got_hnd_dst) { rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); - got_hnd_dst = False; + got_hnd_dst = false; } continue; } @@ -2077,7 +2077,7 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c, MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) goto done; - got_hnd_src = True; + got_hnd_src = true; /* getprinter on the src server */ if (!net_spoolss_getprinter(pipe_hnd, mem_ctx, &hnd_src, level, &ctr_src)) @@ -2100,12 +2100,12 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c, /* close printer handles here */ if (got_hnd_src) { rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); - got_hnd_src = False; + got_hnd_src = false; } if (got_hnd_dst) { rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); - got_hnd_dst = False; + got_hnd_dst = false; } } @@ -2160,8 +2160,8 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, uint32 num_printers, val_needed, data_needed; uint32 level = 2; char *printername, *sharename; - bool got_hnd_src = False; - bool got_hnd_dst = False; + bool got_hnd_src = false; + bool got_hnd_dst = false; struct rpc_pipe_client *pipe_hnd_dst = NULL; POLICY_HND hnd_src, hnd_dst; PRINTER_INFO_CTR ctr_enum, ctr_dst, ctr_dst_publish; @@ -2231,7 +2231,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, MAXIMUM_ALLOWED_ACCESS, cli->user_name, &hnd_src)) goto done; - got_hnd_src = True; + got_hnd_src = true; /* open dst printer handle */ @@ -2239,7 +2239,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, PRINTER_ALL_ACCESS, cli_dst->user_name, &hnd_dst)) goto done; - got_hnd_dst = True; + got_hnd_dst = true; /* check for existing dst printer */ @@ -2267,7 +2267,7 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, ctr_dst_publish.printers_7->action = SPOOL_DS_PUBLISH; - /* ignore False from setprinter due to WERR_IO_PENDING */ + /* ignore false from setprinter due to WERR_IO_PENDING */ net_spoolss_setprinter(pipe_hnd_dst, mem_ctx, &hnd_dst, 7, &ctr_dst_publish); DEBUG(3,("republished printer\n")); @@ -2482,12 +2482,12 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, /* close printer handles here */ if (got_hnd_src) { rpccli_spoolss_close_printer(pipe_hnd, mem_ctx, &hnd_src); - got_hnd_src = False; + got_hnd_src = false; } if (got_hnd_dst) { rpccli_spoolss_close_printer(pipe_hnd_dst, mem_ctx, &hnd_dst); - got_hnd_dst = False; + got_hnd_dst = false; } } -- cgit From 05cc3fda05ced80828d8a7bbc00674c495bf46d3 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 20 Jul 2008 18:44:32 +0200 Subject: Refactoring: connect_dst_pipe uses ndr_syntax_id instead of pipe_idx (This used to be commit 0f77746f36b98acc5171727fa3fc236af9fd2000) --- source3/utils/net_rpc_printer.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'source3/utils/net_rpc_printer.c') diff --git a/source3/utils/net_rpc_printer.c b/source3/utils/net_rpc_printer.c index fd938cbeaa..f4b305d4ab 100644 --- a/source3/utils/net_rpc_printer.c +++ b/source3/utils/net_rpc_printer.c @@ -1434,7 +1434,8 @@ NTSTATUS rpc_printer_migrate_security_internals(struct net_context *c, DEBUG(3,("copying printer ACLs\n")); /* connect destination PI_SPOOLSS */ - nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, PI_SPOOLSS); + nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, + &syntax_spoolss); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; @@ -1596,7 +1597,8 @@ NTSTATUS rpc_printer_migrate_forms_internals(struct net_context *c, DEBUG(3,("copying forms\n")); /* connect destination PI_SPOOLSS */ - nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, PI_SPOOLSS); + nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, + &syntax_spoolss); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; @@ -1786,7 +1788,8 @@ NTSTATUS rpc_printer_migrate_drivers_internals(struct net_context *c, DEBUG(3,("copying printer-drivers\n")); - nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, PI_SPOOLSS); + nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, + &syntax_spoolss); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; @@ -2007,7 +2010,8 @@ NTSTATUS rpc_printer_migrate_printers_internals(struct net_context *c, DEBUG(3,("copying printers\n")); /* connect destination PI_SPOOLSS */ - nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, PI_SPOOLSS); + nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, + &syntax_spoolss); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; @@ -2177,7 +2181,8 @@ NTSTATUS rpc_printer_migrate_settings_internals(struct net_context *c, DEBUG(3,("copying printer settings\n")); /* connect destination PI_SPOOLSS */ - nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, PI_SPOOLSS); + nt_status = connect_dst_pipe(c, &cli_dst, &pipe_hnd_dst, + &syntax_spoolss); if (!NT_STATUS_IS_OK(nt_status)) return nt_status; -- cgit