diff options
author | Jeremy Allison <jra@samba.org> | 2008-07-02 16:11:59 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2008-07-02 16:11:59 -0700 |
commit | 7cd752bce353923ed10a47670bc4e184f0aa6b8c (patch) | |
tree | a41e9f94d7517832b100788e6c004629ec2157e6 /source3/rpc_server | |
parent | 4b88ff157d3b0f3fd8cb0cafbe01c331678491b7 (diff) | |
download | samba-7cd752bce353923ed10a47670bc4e184f0aa6b8c.tar.gz samba-7cd752bce353923ed10a47670bc4e184f0aa6b8c.tar.bz2 samba-7cd752bce353923ed10a47670bc4e184f0aa6b8c.zip |
Canonicalize servername in the printer functions to remove leading '\\' characters. Ensure we always return consistent names.
Jeremy.
(This used to be commit fc2178b04743d2f94be7b489b793fc67826557ac)
Diffstat (limited to 'source3/rpc_server')
-rw-r--r-- | source3/rpc_server/srv_spoolss_nt.c | 113 |
1 files changed, 59 insertions, 54 deletions
diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 72ceb1d517..ca2574f984 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -72,6 +72,18 @@ struct xcv_api_table { WERROR(*fn) (NT_USER_TOKEN *token, RPC_BUFFER *in, RPC_BUFFER *out, uint32 *needed); }; +/******************************************************************** + * Canonicalize servername. + ********************************************************************/ + +static const char *canon_servername(const char *servername) +{ + const char *pservername = servername; + while (*pservername == '\\') { + pservername++; + } + return pservername; +} /* translate between internal status numbers and NT status numbers */ static int nt_printj_status(int v) @@ -455,13 +467,12 @@ static bool set_printer_hnd_name(Printer_entry *Printer, char *handlename) aprinter = handlename; if ( *handlename == '\\' ) { - servername = handlename + 2; - if ( (aprinter = strchr_m( handlename+2, '\\' )) != NULL ) { + servername = canon_servername(handlename); + if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) { *aprinter = '\0'; aprinter++; } - } - else { + } else { servername = ""; } @@ -4660,20 +4671,16 @@ static WERROR enumprinters_level1( uint32 flags, fstring name, * handle enumeration of printers at level 2 ********************************************************************/ -static WERROR enumprinters_level2( uint32 flags, fstring servername, +static WERROR enumprinters_level2( uint32 flags, const char *servername, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { - char *s = servername; - if (flags & PRINTER_ENUM_LOCAL) { return enum_all_printers_info_2(buffer, offered, needed, returned); } if (flags & PRINTER_ENUM_NAME) { - if ((servername[0] == '\\') && (servername[1] == '\\')) - s = servername + 2; - if (is_myname_or_ipaddr(s)) + if (is_myname_or_ipaddr(canon_servername(servername))) return enum_all_printers_info_2(buffer, offered, needed, returned); else return WERR_INVALID_NAME; @@ -4689,7 +4696,7 @@ static WERROR enumprinters_level2( uint32 flags, fstring servername, * handle enumeration of printers at level 5 ********************************************************************/ -static WERROR enumprinters_level5( uint32 flags, fstring servername, +static WERROR enumprinters_level5( uint32 flags, const char *servername, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { @@ -5109,7 +5116,7 @@ WERROR _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET * fill a DRIVER_INFO_1 struct ********************************************************************/ -static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername, fstring architecture) +static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, const char *servername, fstring architecture) { init_unistr( &info->name, driver.info_3->name); } @@ -5118,7 +5125,7 @@ static void fill_printer_driver_info_1(DRIVER_INFO_1 *info, NT_PRINTER_DRIVER_IN * construct_printer_driver_info_1 ********************************************************************/ -static WERROR construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fstring servername, fstring architecture, uint32 version) +static WERROR construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, const char *servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; @@ -5145,21 +5152,21 @@ static WERROR construct_printer_driver_info_1(DRIVER_INFO_1 *info, int snum, fst * fill a printer_info_2 struct ********************************************************************/ -static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername) +static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, const char *servername) { TALLOC_CTX *ctx = talloc_tos(); char *temp = NULL; + const char *cservername = canon_servername(servername); info->version=driver.info_3->cversion; init_unistr( &info->name, driver.info_3->name ); init_unistr( &info->architecture, driver.info_3->environment ); - if (strlen(driver.info_3->driverpath)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->driverpath); init_unistr( &info->driverpath, temp ); } else { @@ -5170,7 +5177,7 @@ static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->datafile)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->datafile); init_unistr( &info->datafile, temp ); } else @@ -5180,7 +5187,7 @@ static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->configfile)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->configfile); init_unistr( &info->configfile, temp ); } else @@ -5192,7 +5199,7 @@ static void fill_printer_driver_info_2(DRIVER_INFO_2 *info, NT_PRINTER_DRIVER_IN * fill a printer_info_2 struct ********************************************************************/ -static WERROR construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, fstring servername, fstring architecture, uint32 version) +static WERROR construct_printer_driver_info_2(DRIVER_INFO_2 *info, int snum, const char *servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; @@ -5248,7 +5255,7 @@ static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, const c if ( servername ) { line = talloc_asprintf(ctx, "\\\\%s%s", - servername, + canon_servername(servername), v); } else { line = talloc_strdup(ctx, v); @@ -5293,10 +5300,11 @@ static uint32 init_unistr_array(uint16 **uni_array, fstring *char_array, const c * fill a printer_info_3 struct ********************************************************************/ -static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername) +static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, const char *servername) { char *temp = NULL; TALLOC_CTX *ctx = talloc_tos(); + const char *cservername = canon_servername(servername); ZERO_STRUCTP(info); @@ -5308,7 +5316,7 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->driverpath)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->driverpath); init_unistr( &info->driverpath, temp ); } else @@ -5318,7 +5326,7 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->datafile)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->datafile); init_unistr( &info->datafile, temp ); } else @@ -5328,7 +5336,7 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->configfile)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->configfile); init_unistr( &info->configfile, temp ); } else @@ -5338,7 +5346,7 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->helpfile)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->helpfile); init_unistr( &info->helpfile, temp ); } else @@ -5349,7 +5357,7 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN init_unistr( &info->defaultdatatype, driver.info_3->defaultdatatype ); info->dependentfiles=NULL; - init_unistr_array(&info->dependentfiles, driver.info_3->dependentfiles, servername); + init_unistr_array(&info->dependentfiles, driver.info_3->dependentfiles, cservername); } /******************************************************************** @@ -5357,7 +5365,7 @@ static void fill_printer_driver_info_3(DRIVER_INFO_3 *info, NT_PRINTER_DRIVER_IN * fill a printer_info_3 struct ********************************************************************/ -static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fstring servername, fstring architecture, uint32 version) +static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, const char *servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; @@ -5416,11 +5424,12 @@ static WERROR construct_printer_driver_info_3(DRIVER_INFO_3 *info, int snum, fst * fill a printer_info_6 struct - we know that driver is really level 3. This sucks. JRA. ********************************************************************/ -static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, fstring servername) +static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_INFO_LEVEL driver, const char *servername) { char *temp = NULL; fstring nullstr; TALLOC_CTX *ctx = talloc_tos(); + const char *cservername = canon_servername(servername); ZERO_STRUCTP(info); memset(&nullstr, '\0', sizeof(fstring)); @@ -5433,7 +5442,7 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->driverpath)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->driverpath); init_unistr( &info->driverpath, temp ); } else @@ -5443,7 +5452,7 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->datafile)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->datafile); init_unistr( &info->datafile, temp ); } else @@ -5453,7 +5462,7 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->configfile)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->configfile); init_unistr( &info->configfile, temp ); } else @@ -5463,7 +5472,7 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN if (strlen(driver.info_3->helpfile)) { temp = talloc_asprintf(ctx, "\\\\%s%s", - servername, + cservername, driver.info_3->helpfile); init_unistr( &info->helpfile, temp ); } else @@ -5497,7 +5506,7 @@ static void fill_printer_driver_info_6(DRIVER_INFO_6 *info, NT_PRINTER_DRIVER_IN ********************************************************************/ static WERROR construct_printer_driver_info_6(DRIVER_INFO_6 *info, int snum, - fstring servername, fstring architecture, uint32 version) + const char *servername, fstring architecture, uint32 version) { NT_PRINTER_INFO_LEVEL *printer = NULL; NT_PRINTER_DRIVER_INFO_LEVEL driver; @@ -5564,7 +5573,7 @@ static void free_printer_driver_info_6(DRIVER_INFO_6 *info) /**************************************************************************** ****************************************************************************/ -static WERROR getprinterdriver2_level1(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinterdriver2_level1(const char *servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_1 *info=NULL; WERROR result; @@ -5602,7 +5611,7 @@ out: /**************************************************************************** ****************************************************************************/ -static WERROR getprinterdriver2_level2(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinterdriver2_level2(const char *servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_2 *info=NULL; WERROR result; @@ -5640,7 +5649,7 @@ out: /**************************************************************************** ****************************************************************************/ -static WERROR getprinterdriver2_level3(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinterdriver2_level3(const char *servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_3 info; WERROR result; @@ -5676,7 +5685,7 @@ out: /**************************************************************************** ****************************************************************************/ -static WERROR getprinterdriver2_level6(fstring servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) +static WERROR getprinterdriver2_level6(const char *servername, fstring architecture, uint32 version, int snum, RPC_BUFFER *buffer, uint32 offered, uint32 *needed) { DRIVER_INFO_6 info; WERROR result; @@ -6910,7 +6919,7 @@ WERROR _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u Enumerates all printer drivers at level 1. ****************************************************************************/ -static WERROR enumprinterdrivers_level1(fstring servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprinterdrivers_level1(const char *servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int i; int ndrivers; @@ -6994,7 +7003,7 @@ out: Enumerates all printer drivers at level 2. ****************************************************************************/ -static WERROR enumprinterdrivers_level2(fstring servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprinterdrivers_level2(const char *servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int i; int ndrivers; @@ -7079,7 +7088,7 @@ out: Enumerates all printer drivers at level 3. ****************************************************************************/ -static WERROR enumprinterdrivers_level3(fstring servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprinterdrivers_level3(const char *servername, fstring architecture, RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) { int i; int ndrivers; @@ -7175,7 +7184,7 @@ WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS uint32 offered = q_u->offered; uint32 *needed = &r_u->needed; uint32 *returned = &r_u->returned; - + const char *cservername; fstring servername; fstring architecture; @@ -7196,16 +7205,18 @@ WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS unistr2_to_ascii(architecture, &q_u->environment, sizeof(architecture)); unistr2_to_ascii(servername, &q_u->name, sizeof(servername)); - if ( !is_myname_or_ipaddr( servername ) ) + cservername = canon_servername(servername); + + if (!is_myname_or_ipaddr(cservername)) return WERR_UNKNOWN_PRINTER_DRIVER; switch (level) { case 1: - return enumprinterdrivers_level1(servername, architecture, buffer, offered, needed, returned); + return enumprinterdrivers_level1(cservername, architecture, buffer, offered, needed, returned); case 2: - return enumprinterdrivers_level2(servername, architecture, buffer, offered, needed, returned); + return enumprinterdrivers_level2(cservername, architecture, buffer, offered, needed, returned); case 3: - return enumprinterdrivers_level3(servername, architecture, buffer, offered, needed, returned); + return enumprinterdrivers_level3(cservername, architecture, buffer, offered, needed, returned); default: return WERR_UNKNOWN_LEVEL; } @@ -7992,7 +8003,7 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen char *path = NULL; char *long_archi = NULL; char *servername = NULL; - char *pservername = NULL; + const char *pservername = NULL; const char *short_archi; DRIVER_DIRECTORY_1 *info=NULL; WERROR result = WERR_OK; @@ -8007,15 +8018,9 @@ static WERROR getprinterdriverdir_level_1(UNISTR2 *name, UNISTR2 *uni_environmen return WERR_NOMEM; } - /* check for beginning double '\'s and that the server - long enough */ - - pservername = servername; - if ( *pservername == '\\' && strlen(servername)>2 ) { - pservername += 2; - } + pservername = canon_servername(servername); - if ( !is_myname_or_ipaddr( pservername ) ) + if ( !is_myname_or_ipaddr(pservername)) return WERR_INVALID_PARAM; if (!(short_archi = get_short_archi(long_archi))) |