Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lpadmin silently ignores -o when creating .ppd #4578

Closed
michaelrsweet opened this issue Feb 12, 2015 · 2 comments
Closed

lpadmin silently ignores -o when creating .ppd #4578

michaelrsweet opened this issue Feb 12, 2015 · 2 comments
Milestone

Comments

@michaelrsweet
Copy link
Collaborator

Version: 2.0-current
CUPS.org User: yg344

It appears that when using lpadmin to generate a .ppd that was not there before with -m, options provided with -o are not applied. When using lpadmin to modify a preexisting .ppd, options provided with -o are applied.

There is no output to indicate that this is what is occurring, and nothing in the manpage for lpadmin that would clue users in.

We noticed this on an hour-long bughunt through our mass-deployed printer setup scripts to identify what was causing a printer to default to using the wrong paper size. We would run the script (which first removed all the .ppds), observe that the generated .ppd was wrong, then run the same lpadmin command on the command line (which was now modifying the .ppd created by the earlier run in the script), then observe that the generated .ppd was now correct.

For reference, the command used was:

/usr/sbin/lpadmin -p [name] -E -m MCS/[name].ppd -D "[description]" -L "[location]" -v "[address]" -o PageSize=Letter -o HPOption_Duplexer=True -o printer-is-shared=true -u allow:root,remroot

Where MCS/[name].ppd had the correct PageSize setting, different from the .ppd generated in /etc/cups/ppd/ by the above command. Running the same command again corrected the file.

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: mike

Fixed in Subversion repository.

@michaelrsweet
Copy link
Collaborator Author

"str4578.patch":

Index: cups/testppd.c

--- cups/testppd.c (revision 12597)
+++ cups/testppd.c (working copy)
@@ -910,8 +910,20 @@
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 */

    if (argv[1][2])

Index: systemv/lpadmin.c

--- systemv/lpadmin.c (revision 12597)
+++ systemv/lpadmin.c (working copy)
@@ -1318,7 +1318,7 @@
{
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 @@
    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 @@

    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 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 @@
ippDelete(request);
if (ppdfile != file)
unlink(ppdfile);

  •  if (copied_options)
    
  •    cupsFreeOptions(num_options, options);
    
    return (1);
    }

@@ -1409,13 +1441,13 @@
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 @@
ippDelete(cupsDoRequest(http, request, "/admin/"));
}

  • if (copied_options)
  • cupsFreeOptions(num_options, options);

/*

  • Check the response...
    */
    Index: test/run-stp-tests.sh

    --- test/run-stp-tests.sh (revision 12597)
    +++ test/run-stp-tests.sh (working copy)
    @@ -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 @@

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant