Skip to content

Commit

Permalink
spoolss: cache_key handle allocation failures early
Browse files Browse the repository at this point in the history
On cache_key allocation failure, set_printer_hnd_name() currently
stumbles through the rest of the function, and includes extra logic to
handle a NULL key later on.
Handling the allocation failure early makes sense, and also allows for
the NULL key checks to be removed.

Signed-off-by: David Disseldorp <[email protected]>
Reviewed-by: Guenther Deschner <[email protected]>

Autobuild-User(master): Günther Deschner <[email protected]>
Autobuild-Date(master): Wed Apr 15 18:55:50 CEST 2015 on sn-devel-104
  • Loading branch information
ddiss authored and gd committed Apr 15, 2015
1 parent e8951eb commit a65e22c
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions source3/rpc_server/spoolss/srv_spoolss_nt.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,18 +622,18 @@ static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
found = true;
}

cache_key = talloc_asprintf(talloc_tos(), "PRINTERNAME/%s", aprinter);
if (cache_key == NULL) {
return WERR_NOMEM;
}

/*
* With hundreds of printers, the "for" loop iterating all
* shares can be quite expensive, as it is done on every
* OpenPrinter. The loop maps "aprinter" to "sname", the
* result of which we cache in gencache.
*/

cache_key = talloc_asprintf(talloc_tos(), "PRINTERNAME/%s",
aprinter);
if ((cache_key != NULL) &&
gencache_get(cache_key, talloc_tos(), &tmp, NULL)) {

if (gencache_get(cache_key, talloc_tos(), &tmp, NULL)) {
found = (strcmp(tmp, printer_not_found) != 0);
if (!found) {
DEBUG(4, ("Printer %s not found\n", aprinter));
Expand Down Expand Up @@ -702,20 +702,16 @@ static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
TALLOC_FREE(info2);
}

if ( !found ) {
if (cache_key != NULL) {
gencache_set(cache_key, printer_not_found,
time(NULL)+300);
TALLOC_FREE(cache_key);
}
if (!found) {
gencache_set(cache_key, printer_not_found,
time_mono(NULL) + 300);
TALLOC_FREE(cache_key);
DEBUGADD(4,("Printer not found\n"));
return WERR_INVALID_PRINTER_NAME;
}

if (cache_key != NULL) {
gencache_set(cache_key, sname, time(NULL)+300);
TALLOC_FREE(cache_key);
}
gencache_set(cache_key, sname, time_mono(NULL) + 300);
TALLOC_FREE(cache_key);

DEBUGADD(4,("set_printer_hnd_name: Printer found: %s -> %s\n", aprinter, sname));

Expand Down

0 comments on commit a65e22c

Please sign in to comment.