From 4e45d5f8244fae0e26a6d0592a092f2a9c791666 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 11 May 2010 10:46:10 +0200 Subject: s3-printing: Removed unused get_a_printer functions. Signed-off-by: Jim McDonough --- source3/printing/nt_printing.c | 523 ----------------------------------------- 1 file changed, 523 deletions(-) (limited to 'source3/printing') diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c index 74a2dc433e..2cb2ce690a 100644 --- a/source3/printing/nt_printing.c +++ b/source3/printing/nt_printing.c @@ -3324,122 +3324,6 @@ struct regval_blob* get_printer_data( NT_PRINTER_INFO_LEVEL_2 *p2, const char *k return regval_ctr_getvalue( p2->data->keys[key_index].values, value ); } -/**************************************************************************** - Unpack a list of registry values frem the TDB - ***************************************************************************/ - -static int unpack_values(NT_PRINTER_DATA *printer_data, const uint8 *buf, int buflen) -{ - int len = 0; - uint32 type; - fstring string; - const char *valuename = NULL; - const char *keyname = NULL; - char *str; - int size; - uint8 *data_p; - struct regval_blob *regval_p; - int key_index; - - /* add the "PrinterDriverData" key first for performance reasons */ - - add_new_printer_key( printer_data, SPOOL_PRINTERDATA_KEY ); - - /* loop and unpack the rest of the registry values */ - - while ( True ) { - - /* check to see if there are any more registry values */ - - regval_p = NULL; - len += tdb_unpack(buf+len, buflen-len, "p", ®val_p); - if ( !regval_p ) - break; - - /* unpack the next regval */ - - len += tdb_unpack(buf+len, buflen-len, "fdB", - string, - &type, - &size, - &data_p); - - /* lookup for subkey names which have a type of REG_NONE */ - /* there's no data with this entry */ - - if ( type == REG_NONE ) { - if ( (key_index=lookup_printerkey( printer_data, string)) == -1 ) - add_new_printer_key( printer_data, string ); - continue; - } - - /* - * break of the keyname from the value name. - * Valuenames can have embedded '\'s so be careful. - * only support one level of keys. See the - * "Konica Fiery S300 50C-K v1.1. enu" 2k driver. - * -- jerry - */ - - str = strchr_m( string, '\\'); - - /* Put in "PrinterDriverData" is no key specified */ - - if ( !str ) { - keyname = SPOOL_PRINTERDATA_KEY; - valuename = string; - } - else { - *str = '\0'; - keyname = string; - valuename = str+1; - } - - /* see if we need a new key */ - - if ( (key_index=lookup_printerkey( printer_data, keyname )) == -1 ) - key_index = add_new_printer_key( printer_data, keyname ); - - if ( key_index == -1 ) { - DEBUG(0,("unpack_values: Failed to allocate a new key [%s]!\n", - keyname)); - break; - } - - DEBUG(8,("specific: [%s:%s], len: %d\n", keyname, valuename, size)); - - /* Vista doesn't like unknown REG_BINARY values in DsSpooler. - Thanks to Martin Zielinski for the hint. */ - - if ( type == REG_BINARY && - strequal( keyname, SPOOL_DSSPOOLER_KEY ) && - strequal( valuename, "objectGUID" ) ) - { - struct GUID guid; - - /* convert the GUID to a UNICODE string */ - - memcpy( &guid, data_p, sizeof(struct GUID) ); - - regval_ctr_addvalue_sz(printer_data->keys[key_index].values, - valuename, - GUID_string(talloc_tos(), &guid)); - - } else { - /* add the value */ - - regval_ctr_addvalue( printer_data->keys[key_index].values, - valuename, type, data_p, - size ); - } - - SAFE_FREE(data_p); /* 'B' option to tdbpack does a malloc() */ - - } - - return len; -} - /**************************************************************************** ***************************************************************************/ @@ -3478,81 +3362,6 @@ static bool set_driver_mapping(const char *from, const char *to) return true; } -static void map_to_os2_driver(fstring drivername) -{ - char *mapfile = lp_os2_driver_map(); - char **lines = NULL; - int numlines = 0; - int i; - - if (!strlen(drivername)) - return; - - if (!*mapfile) - return; - - if (strequal(drivername, get_win_driver())) { - DEBUG(3,("Mapped Windows driver %s to OS/2 driver %s\n", - drivername, get_os2_driver())); - fstrcpy(drivername, get_os2_driver()); - return; - } - - lines = file_lines_load(mapfile, &numlines,0,NULL); - if (numlines == 0 || lines == NULL) { - DEBUG(0,("No entries in OS/2 driver map %s\n",mapfile)); - TALLOC_FREE(lines); - return; - } - - DEBUG(4,("Scanning OS/2 driver map %s\n",mapfile)); - - for( i = 0; i < numlines; i++) { - char *nt_name = lines[i]; - char *os2_name = strchr(nt_name,'='); - - if (!os2_name) - continue; - - *os2_name++ = 0; - - while (isspace(*nt_name)) - nt_name++; - - if (!*nt_name || strchr("#;",*nt_name)) - continue; - - { - int l = strlen(nt_name); - while (l && isspace(nt_name[l-1])) { - nt_name[l-1] = 0; - l--; - } - } - - while (isspace(*os2_name)) - os2_name++; - - { - int l = strlen(os2_name); - while (l && isspace(os2_name[l-1])) { - os2_name[l-1] = 0; - l--; - } - } - - if (strequal(nt_name,drivername)) { - DEBUG(3,("Mapped windows driver %s to os2 driver%s\n",drivername,os2_name)); - set_driver_mapping(drivername,os2_name); - fstrcpy(drivername,os2_name); - TALLOC_FREE(lines); - return; - } - } - - TALLOC_FREE(lines); -} - /** * @internal * @@ -3657,253 +3466,6 @@ WERROR spoolss_map_to_os2_driver(TALLOC_CTX *mem_ctx, const char **pdrivername) return WERR_OK; } -/**************************************************************************** - Get a default printer info 2 struct. -****************************************************************************/ - -static WERROR get_a_printer_2_default(NT_PRINTER_INFO_LEVEL_2 *info, - const char *servername, - const char* sharename, - bool get_loc_com) -{ - int snum = lp_servicenumber(sharename); - WERROR result; - - slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", servername); - slprintf(info->printername, sizeof(info->printername)-1, "\\\\%s\\%s", - servername, sharename); - fstrcpy(info->sharename, sharename); - fstrcpy(info->portname, SAMBA_PRINTER_PORT_NAME); - - /* by setting the driver name to an empty string, a local NT admin - can now run the **local** APW to install a local printer driver - for a Samba shared printer in 2.2. Without this, drivers **must** be - installed on the Samba server for NT clients --jerry */ -#if 0 /* JERRY --do not uncomment-- */ - if (!*info->drivername) - fstrcpy(info->drivername, "NO DRIVER AVAILABLE FOR THIS PRINTER"); -#endif - - - DEBUG(10,("get_a_printer_2_default: driver name set to [%s]\n", info->drivername)); - - strlcpy(info->comment, "", sizeof(info->comment)); - fstrcpy(info->printprocessor, "winprint"); - fstrcpy(info->datatype, "RAW"); - -#ifdef HAVE_CUPS - if (get_loc_com && (enum printing_types)lp_printing(snum) == PRINT_CUPS ) { - /* Pull the location and comment strings from cups if we don't - already have one */ - if ( !strlen(info->location) || !strlen(info->comment) ) { - char *comment = NULL; - char *location = NULL; - if (cups_pull_comment_location(info, info->sharename, - &comment, &location)) { - strlcpy(info->comment, comment, sizeof(info->comment)); - fstrcpy(info->location, location); - TALLOC_FREE(comment); - TALLOC_FREE(location); - } - } - } -#endif - - info->attributes = PRINTER_ATTRIBUTE_SAMBA; - - info->starttime = 0; /* Minutes since 12:00am GMT */ - info->untiltime = 0; /* Minutes since 12:00am GMT */ - info->priority = 1; - info->default_priority = 1; - info->setuptime = (uint32)time(NULL); - - /* - * I changed this as I think it is better to have a generic - * DEVMODE than to crash Win2k explorer.exe --jerry - * See the HP Deskjet 990c Win2k drivers for an example. - * - * However the default devmode appears to cause problems - * with the HP CLJ 8500 PCL driver. Hence the addition of - * the "default devmode" parameter --jerry 22/01/2002 - */ - - if (lp_default_devmode(snum)) { - result = spoolss_create_default_devmode(info, - info->printername, - &info->devmode); - if (!W_ERROR_IS_OK(result)) { - goto fail; - } - } else { - info->devmode = NULL; - } - - if (!nt_printing_getsec(info, sharename, &info->secdesc_buf)) { - goto fail; - } - - info->data = TALLOC_ZERO_P(info, NT_PRINTER_DATA); - if (!info->data) { - goto fail; - } - - add_new_printer_key(info->data, SPOOL_PRINTERDATA_KEY); - - return WERR_OK; - -fail: - TALLOC_FREE(info->devmode); - - return WERR_ACCESS_DENIED; -} - -/**************************************************************************** -****************************************************************************/ - -static WERROR get_a_printer_2(NT_PRINTER_INFO_LEVEL_2 *info, - const char *servername, - const char *sharename, - bool get_loc_com) -{ - int len = 0; - int snum = lp_servicenumber(sharename); - TDB_DATA kbuf, dbuf; - fstring printername; - char *comment = NULL; - WERROR result; - - kbuf = make_printer_tdbkey(talloc_tos(), sharename); - - dbuf = tdb_fetch(tdb_printers, kbuf); - if (!dbuf.dptr) { - return get_a_printer_2_default(info, servername, - sharename, get_loc_com); - } - - len += tdb_unpack(dbuf.dptr+len, dbuf.dsize-len, "dddddddddddfffffPfffff", - &info->attributes, - &info->priority, - &info->default_priority, - &info->starttime, - &info->untiltime, - &info->status, - &info->cjobs, - &info->averageppm, - &info->changeid, - &info->c_setprinter, - &info->setuptime, - info->servername, - info->printername, - info->sharename, - info->portname, - info->drivername, - &comment, - info->location, - info->sepfile, - info->printprocessor, - info->datatype, - info->parameters); - - if (comment) { - strlcpy(info->comment, comment, sizeof(info->comment)); - SAFE_FREE(comment); - } - - /* Samba has to have shared raw drivers. */ - info->attributes |= PRINTER_ATTRIBUTE_SAMBA; - info->attributes &= ~PRINTER_ATTRIBUTE_NOT_SAMBA; - - /* Restore the stripped strings. */ - slprintf(info->servername, sizeof(info->servername)-1, "\\\\%s", servername); - - if ( lp_force_printername(snum) ) { - slprintf(printername, sizeof(printername)-1, "\\\\%s\\%s", servername, sharename ); - } else { - slprintf(printername, sizeof(printername)-1, "\\\\%s\\%s", servername, info->printername); - } - - fstrcpy(info->printername, printername); - -#ifdef HAVE_CUPS - if (get_loc_com && (enum printing_types)lp_printing(snum) == PRINT_CUPS ) { - /* Pull the location and comment strings from cups if we don't - already have one */ - if ( !strlen(info->location) || !strlen(info->comment) ) { - char *location = NULL; - comment = NULL; - if (cups_pull_comment_location(info, info->sharename, - &comment, &location)) { - strlcpy(info->comment, comment, sizeof(info->comment)); - fstrcpy(info->location, location); - TALLOC_FREE(comment); - TALLOC_FREE(location); - } - } - } -#endif - - len += unpack_devicemode(info, dbuf.dptr+len, - dbuf.dsize-len, - &info->devmode); - - /* - * Some client drivers freak out if there is a NULL devmode - * (probably the driver is not checking before accessing - * the devmode pointer) --jerry - * - * See comments in get_a_printer_2_default() - */ - - if (lp_default_devmode(snum) && !info->devmode) { - DEBUG(8,("get_a_printer_2: Constructing a default device mode for [%s]\n", - printername)); - result = spoolss_create_default_devmode(info, printername, - &info->devmode); - if (!W_ERROR_IS_OK(result)) { - goto done; - } - } - - if (info->devmode) { - info->devmode->devicename = talloc_strdup(info->devmode, - info->printername); - if (!info->devmode->devicename) { - result = WERR_NOMEM; - goto done; - } - } - - if ( !(info->data = TALLOC_ZERO_P( info, NT_PRINTER_DATA )) ) { - DEBUG(0,("unpack_values: talloc() failed!\n")); - result = WERR_NOMEM; - goto done; - } - len += unpack_values( info->data, dbuf.dptr+len, dbuf.dsize-len ); - - /* This will get the current RPC talloc context, but we should be - passing this as a parameter... fixme... JRA ! */ - - if (!nt_printing_getsec(info, sharename, &info->secdesc_buf)) { - result = WERR_NOMEM; - goto done; - } - - /* Fix for OS/2 drivers. */ - - if (get_remote_arch() == RA_OS2) { - map_to_os2_driver(info->drivername); - } - - DEBUG(9,("Unpacked printer [%s] name [%s] running driver [%s]\n", - sharename, info->printername, info->drivername)); - - result = WERR_OK; - -done: - SAFE_FREE(dbuf.dptr); - return result; -} - /**************************************************************************** Debugging function, dump at level 6 the struct in the logs. ****************************************************************************/ @@ -4048,91 +3610,6 @@ WERROR mod_a_printer(NT_PRINTER_INFO_LEVEL *printer, uint32 level) return result; } -/**************************************************************************** - Get a NT_PRINTER_INFO_LEVEL struct. It returns malloced memory. - - Previously the code had a memory allocation problem because it always - used the TALLOC_CTX from the Printer_entry*. This context lasts - as a long as the original handle is open. So if the client made a lot - of getprinter[data]() calls, the memory usage would climb. Now we use - a short lived TALLOC_CTX for printer_info_2 objects returned. We - still use the Printer_entry->ctx for maintaining the cache copy though - since that object must live as long as the handle by definition. - --jerry - -****************************************************************************/ - -static WERROR get_a_printer_internal( Printer_entry *print_hnd, NT_PRINTER_INFO_LEVEL **pp_printer, uint32 level, - const char *sharename, bool get_loc_com) -{ - WERROR result; - fstring servername; - - DEBUG(10,("get_a_printer: [%s] level %u\n", sharename, (unsigned int)level)); - - if ( !(*pp_printer = TALLOC_ZERO_P(NULL, NT_PRINTER_INFO_LEVEL)) ) { - DEBUG(0,("get_a_printer: talloc() fail.\n")); - return WERR_NOMEM; - } - - switch (level) { - case 2: - if ( !((*pp_printer)->info_2 = TALLOC_ZERO_P(*pp_printer, NT_PRINTER_INFO_LEVEL_2)) ) { - DEBUG(0,("get_a_printer: talloc() fail.\n")); - TALLOC_FREE( *pp_printer ); - return WERR_NOMEM; - } - - if ( print_hnd ) - fstrcpy( servername, print_hnd->servername ); - else { - fstrcpy( servername, "%L" ); - standard_sub_basic( "", "", servername, - sizeof(servername)-1 ); - } - - result = get_a_printer_2( (*pp_printer)->info_2, - servername, sharename, get_loc_com); - - /* we have a new printer now. Save it with this handle */ - - if ( !W_ERROR_IS_OK(result) ) { - TALLOC_FREE( *pp_printer ); - DEBUG(10,("get_a_printer: [%s] level %u returning %s\n", - sharename, (unsigned int)level, win_errstr(result))); - return result; - } - - dump_a_printer( *pp_printer, level); - - break; - - default: - TALLOC_FREE( *pp_printer ); - return WERR_UNKNOWN_LEVEL; - } - - return WERR_OK; -} - -WERROR get_a_printer( Printer_entry *print_hnd, - NT_PRINTER_INFO_LEVEL **pp_printer, - uint32 level, - const char *sharename) -{ - return get_a_printer_internal(print_hnd, pp_printer, level, - sharename, true); -} - -WERROR get_a_printer_search( Printer_entry *print_hnd, - NT_PRINTER_INFO_LEVEL **pp_printer, - uint32 level, - const char *sharename) -{ - return get_a_printer_internal(print_hnd, pp_printer, level, - sharename, false); -} - /**************************************************************************** Deletes a NT_PRINTER_INFO_LEVEL struct. ****************************************************************************/ -- cgit