From 61c9d9f8251f76740686f796cd5f016fdebf753a Mon Sep 17 00:00:00 2001 From: msweet Date: Wed, 6 May 2015 01:42:51 +0000 Subject: [PATCH] Fix lpadmin when both -m and -o are used (STR #4578) Grab server PPD and edit it as needed. git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@12603 a1ca3aef-8c08-0410-bb20-df032aa958be --- CHANGES-2.0.txt | 1 + cups/testppd.c | 14 ++++++++++++- systemv/lpadmin.c | 47 +++++++++++++++++++++++++++++++++++++------ test/run-stp-tests.sh | 4 ++-- 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/CHANGES-2.0.txt b/CHANGES-2.0.txt index 6422d712a..2d6dd8e1d 100644 --- a/CHANGES-2.0.txt +++ b/CHANGES-2.0.txt @@ -9,6 +9,7 @@ CHANGES IN CUPS V2.0.3 (STR #4598, STR #4599, STR #4600, STR #4601) - Fixed a gzip processing bug (#4602) - Fixed inside (STR #4575) + - Fixed lpadmin when both -m and -o are used (STR #4578) - Added Russian translation (STR #4577) diff --git a/cups/testppd.c b/cups/testppd.c index 42b5ab875..e87435fd8 100644 --- a/cups/testppd.c +++ b/cups/testppd.c @@ -910,7 +910,19 @@ main(int argc, /* I - Number of command-line arguments */ struct stat fileinfo; /* File information */ - if (!strncmp(argv[1], "-d", 2)) + if (strchr(argv[1], ':')) + { + /* + * Server PPD... + */ + + if ((filename = cupsGetServerPPD(CUPS_HTTP_DEFAULT, argv[1])) == NULL) + { + printf("%s: %s\n", argv[1], cupsLastErrorString()); + return (1); + } + } + else if (!strncmp(argv[1], "-d", 2)) { const char *printer; /* Printer name */ diff --git a/systemv/lpadmin.c b/systemv/lpadmin.c index 492ff9d6f..fa077b2b9 100644 --- a/systemv/lpadmin.c +++ b/systemv/lpadmin.c @@ -1318,7 +1318,7 @@ set_printer_options( { ipp_t *request; /* IPP Request */ const char *ppdfile; /* PPD filename */ - int ppdchanged; /* PPD changed? */ + int ppdchanged = 0; /* PPD changed? */ ppd_file_t *ppd; /* PPD file */ ppd_choice_t *choice; /* Marked choice */ char uri[HTTP_MAX_URI], /* URI for printer/class */ @@ -1328,11 +1328,13 @@ set_printer_options( tempfile[1024]; /* Temporary filename */ cups_file_t *in, /* PPD file */ *out; /* Temporary file */ - const char *protocol, /* Old protocol option */ + const char *ppdname, /* ppd-name value */ + *protocol, /* Old protocol option */ *customval, /* Custom option value */ *boolval; /* Boolean value */ int wrote_ipp_supplies = 0, /* Wrote cupsIPPSupplies keyword? */ - wrote_snmp_supplies = 0;/* Wrote cupsSNMPSupplies keyword? */ + wrote_snmp_supplies = 0,/* Wrote cupsSNMPSupplies keyword? */ + copied_options = 0; /* Copied options? */ DEBUG_printf(("set_printer_options(http=%p, printer=\"%s\", num_options=%d, " @@ -1364,6 +1366,26 @@ set_printer_options( if (file) ppdfile = file; + else if ((ppdname = cupsGetOption("ppd-name", num_options, options)) != NULL && strcmp(ppdname, "raw") && num_options > 1) + { + if ((ppdfile = cupsGetServerPPD(http, ppdname)) != NULL) + { + /* + * Copy options array and remove ppd-name from it... + */ + + cups_option_t *temp = NULL, *optr; + int i, num_temp = 0; + for (i = num_options, optr = options; i > 0; i --, optr ++) + if (strcmp(optr->name, "ppd-name")) + num_temp = cupsAddOption(optr->name, optr->value, num_temp, &temp); + + copied_options = 1; + ppdchanged = 1; + num_options = num_temp; + options = temp; + } + } else if (request->request.op.operation_id == IPP_OP_CUPS_ADD_MODIFY_PRINTER) ppdfile = cupsGetPPD(printer); else @@ -1388,7 +1410,15 @@ set_printer_options( * Set default options in the PPD file... */ - ppd = ppdOpenFile(ppdfile); + if ((ppd = ppdOpenFile(ppdfile)) == NULL) + { + int linenum; /* Line number of error */ + ppd_status_t status = ppdLastError(&linenum); + /* Status code */ + + _cupsLangPrintf(stderr, _("lpadmin: Unable to open PPD \"%s\": %s on line %d."), ppdfile, ppdErrorString(status), linenum); + } + ppdMarkDefaults(ppd); cupsMarkOptions(ppd, num_options, options); @@ -1398,6 +1428,8 @@ set_printer_options( ippDelete(request); if (ppdfile != file) unlink(ppdfile); + if (copied_options) + cupsFreeOptions(num_options, options); return (1); } @@ -1409,13 +1441,13 @@ set_printer_options( ippDelete(request); if (ppdfile != file) unlink(ppdfile); + if (copied_options) + cupsFreeOptions(num_options, options); cupsFileClose(out); unlink(tempfile); return (1); } - ppdchanged = 0; - while (cupsFileGets(in, line, sizeof(line))) { if (!strncmp(line, "*cupsIPPSupplies:", 17) && @@ -1537,6 +1569,9 @@ set_printer_options( ippDelete(cupsDoRequest(http, request, "/admin/")); } + if (copied_options) + cupsFreeOptions(num_options, options); + /* * Check the response... */ diff --git a/test/run-stp-tests.sh b/test/run-stp-tests.sh index 938d14d1f..0709e33aa 100755 --- a/test/run-stp-tests.sh +++ b/test/run-stp-tests.sh @@ -5,7 +5,7 @@ # Perform the complete set of IPP compliance tests specified in the # CUPS Software Test Plan. # -# Copyright 2007-2014 by Apple Inc. +# Copyright 2007-2015 by Apple Inc. # Copyright 1997-2007 by Easy Software Products, all rights reserved. # # These coded instructions, statements, and computer programs are the @@ -906,7 +906,7 @@ fi # Requests logged count=`wc -l $BASE/log/access_log | awk '{print $1}'` -expected=`expr 37 + 18 + 29 + $pjobs \* 8 + $pprinters \* $pjobs \* 4` +expected=`expr 37 + 18 + 30 + $pjobs \* 8 + $pprinters \* $pjobs \* 4` if test $count != $expected; then echo "FAIL: $count requests logged, expected $expected." echo "

FAIL: $count requests logged, expected $expected.

" >>$strfile -- 2.39.5