]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
The lpadmin command now allows default option values to be deleted (STR #2959)
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 11 May 2011 05:30:50 +0000 (05:30 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 11 May 2011 05:30:50 +0000 (05:30 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@9762 7a7537e8-13f0-0310-91df-b6672ffda945

CHANGES.txt
man/lpadmin.man
systemv/lpadmin.c

index 37bbf46f15e14b13c7258620abed0c47d53f0047..beadcb06ccf298101b1c75a334514e1e051a022e 100644 (file)
@@ -3,6 +3,8 @@ CHANGES.txt - 2011-05-10
 
 CHANGES IN CUPS V1.5b1
 
+       - The lpadmin command now allows default option values to be deleted
+         (STR #2959)
        - The lpadmin command now allows the cupsIPPSupplies and
          cupsSNMPSupplies keywords to be set in a PPD file (STR #3825)
        - Moving a held job no longer releases it (STR #3839)
index 84e321815922ebf38de4e5210a67c5322ce6bc6f..bfe5f786c29fdaa5ce4378b90f109227ae45ba83 100644 (file)
@@ -30,7 +30,11 @@ lpadmin \- configure cups printers and classes
 ] [ -h
 .I server[:port]
 ] -p
-.I destination option(s)
+.I destination
+[ -R
+.I name-default
+]
+.I option(s)
 .br
 .B lpadmin
 [ -E ] [-U
@@ -155,6 +159,10 @@ Sets the IPP operation policy associated with the destination. The
 name must be defined in the \fBcupsd.conf\fR in a Policy section.
 The default operation policy is "default".
 .TP 5
+-R name-default
+.br
+Deletes the named option from \fIprinter\fR.
+.TP 5
 -r class
 .br
 Removes the named \fIprinter\fR from \fIclass\fR.  If the
index 631ffbf544b5d59c7b88f561777d883bd1d6786e..ae673590ff65a25d16c5fe8b5fe31fc677ec699e 100644 (file)
@@ -19,7 +19,9 @@
  *   default_printer()           - Set the default printing destination.
  *   delete_printer()            - Delete a printer from the system.
  *   delete_printer_from_class() - Delete a printer from a class.
+ *   delete_printer_option()     - Delete a printer option.
  *   enable_printer()            - Enable a printer.
+ *   get_printer_type()          - Determine the printer type and URI.
  *   set_printer_options()       - Set the printer options and/or file.
  *   validate_name()             - Make sure the printer name only contains
  *                                 valid chars.
  * Local functions...
  */
 
-static int     add_printer_to_class(http_t *http, char *printer, char *pclass);
-static int     default_printer(http_t *http, char *printer);
-static int     delete_printer(http_t *http, char *printer);
-static int     delete_printer_from_class(http_t *http, char *printer,
-                                         char *pclass);
-static int     enable_printer(http_t *http, char *printer);
-static int     set_printer_options(http_t *http, char *printer,
-                                   int num_options, cups_option_t *options,
-                                   char *file);
-static int     validate_name(const char *name);
+static int             add_printer_to_class(http_t *http, char *printer, char *pclass);
+static int             default_printer(http_t *http, char *printer);
+static int             delete_printer(http_t *http, char *printer);
+static int             delete_printer_from_class(http_t *http, char *printer,
+                                                 char *pclass);
+static int             delete_printer_option(http_t *http, char *printer,
+                                             char *option);
+static int             enable_printer(http_t *http, char *printer);
+static cups_ptype_t    get_printer_type(http_t *http, char *printer, char *uri,
+                                        size_t urisize);
+static int             set_printer_options(http_t *http, char *printer,
+                                           int num_options, cups_option_t *options,
+                                           char *file);
+static int             validate_name(const char *name);
 
 
 /*
@@ -375,6 +381,51 @@ main(int  argc,                    /* I - Number of command-line arguments */
              return (1);
            break;
 
+        case 'R' : /* Remove option */
+           if (!http)
+           {
+              http = httpConnectEncrypt(cupsServer(), ippPort(),
+                                       cupsEncryption());
+
+             if (http == NULL)
+             {
+               _cupsLangPrintf(stderr,
+                               _("lpadmin: Unable to connect to server: %s"),
+                               strerror(errno));
+               return (1);
+             }
+            }
+
+           if (printer == NULL)
+           {
+             _cupsLangPuts(stderr,
+                           _("lpadmin: Unable to delete option:\n"
+                             "         You must specify a printer name "
+                             "first."));
+             return (1);
+           }
+
+           if (argv[i][2])
+             val = argv[i] + 2;
+           else
+           {
+             i ++;
+
+             if (i >= argc)
+             {
+               _cupsLangPuts(stderr,
+                             _("lpadmin: Expected name after \"-R\" "
+                               "option."));
+               return (1);
+             }
+
+             val = argv[i];
+           }
+
+            if (delete_printer_option(http, printer, val))
+             return (1);
+           break;
+
         case 'U' : /* Username */
            if (argv[i][2] != '\0')
              cupsSetUser(argv[i] + 2);
@@ -661,6 +712,7 @@ add_printer_to_class(http_t *http,  /* I - Server connection */
   *    attributes-charset
   *    attributes-natural-language
   *    printer-uri
+  *    requesting-user-name
   */
 
   request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
@@ -669,6 +721,8 @@ add_printer_to_class(http_t *http,  /* I - Server connection */
                    "localhost", 0, "/classes/%s", pclass);
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                "printer-uri", NULL, uri);
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
+               NULL, cupsUser());
 
  /*
   * Do the request and get back a response...
@@ -677,26 +731,30 @@ add_printer_to_class(http_t *http,        /* I - Server connection */
   response = cupsDoRequest(http, request, "/");
 
  /*
-  * Build a CUPS_ADD_CLASS request, which requires the following
+  * Build a CUPS_ADD_MODIFY_CLASS request, which requires the following
   * attributes:
   *
   *    attributes-charset
   *    attributes-natural-language
   *    printer-uri
+  *    requesting-user-name
   *    member-uris
   */
 
-  request = ippNewRequest(CUPS_ADD_CLASS);
+  request = ippNewRequest(CUPS_ADD_MODIFY_CLASS);
 
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                "printer-uri", NULL, uri);
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
+               NULL, cupsUser());
 
  /*
   * See if the printer is already in the class...
   */
 
   if (response != NULL &&
-      (members = ippFindAttribute(response, "member-names", IPP_TAG_NAME)) != NULL)
+      (members = ippFindAttribute(response, "member-names",
+                                  IPP_TAG_NAME)) != NULL)
     for (i = 0; i < members->num_values; i ++)
       if (strcasecmp(printer, members->values[i].string.text) == 0)
       {
@@ -716,7 +774,8 @@ add_printer_to_class(http_t *http,  /* I - Server connection */
                    "localhost", 0, "/printers/%s", printer);
 
   if (response != NULL &&
-      (members = ippFindAttribute(response, "member-uris", IPP_TAG_URI)) != NULL)
+      (members = ippFindAttribute(response, "member-uris",
+                                  IPP_TAG_URI)) != NULL)
   {
    /*
     * Add the printer to the existing list...
@@ -725,7 +784,8 @@ add_printer_to_class(http_t *http,  /* I - Server connection */
     attr = ippAddStrings(request, IPP_TAG_PRINTER, IPP_TAG_URI,
                          "member-uris", members->num_values + 1, NULL, NULL);
     for (i = 0; i < members->num_values; i ++)
-      attr->values[i].string.text = _cupsStrAlloc(members->values[i].string.text);
+      attr->values[i].string.text =
+          _cupsStrAlloc(members->values[i].string.text);
 
     attr->values[i].string.text = _cupsStrAlloc(uri);
   }
@@ -739,26 +799,15 @@ add_printer_to_class(http_t *http,        /* I - Server connection */
 
   ippDelete(response);
 
-  if ((response = cupsDoRequest(http, request, "/admin/")) == NULL)
-  {
-    _cupsLangPrintf(stderr, "lpadmin: %s", cupsLastErrorString());
-
-    return (1);
-  }
-  else if (response->request.status.status_code > IPP_OK_CONFLICT)
+  ippDelete(cupsDoRequest(http, request, "/admin/"));
+  if (cupsLastError() > IPP_OK_CONFLICT)
   {
-    _cupsLangPrintf(stderr, "lpadmin: %s", cupsLastErrorString());
-
-    ippDelete(response);
+    _cupsLangPrintf(stderr, _("%s: %s"), "lpadmin", cupsLastErrorString());
 
     return (1);
   }
   else
-  {
-    ippDelete(response);
-
     return (0);
-  }
 }
 
 
@@ -770,8 +819,7 @@ static int                          /* O - 0 on success, 1 on fail */
 default_printer(http_t *http,          /* I - Server connection */
                 char   *printer)       /* I - Printer name */
 {
-  ipp_t                *request,               /* IPP Request */
-               *response;              /* IPP Response */
+  ipp_t                *request;               /* IPP Request */
   char         uri[HTTP_MAX_URI];      /* URI for printer/class */
 
 
@@ -784,6 +832,7 @@ default_printer(http_t *http,               /* I - Server connection */
   *    attributes-charset
   *    attributes-natural-language
   *    printer-uri
+  *    requesting-user-name
   */
 
   httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
@@ -793,31 +842,23 @@ default_printer(http_t *http,             /* I - Server connection */
 
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                "printer-uri", NULL, uri);
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
+               NULL, cupsUser());
 
  /*
   * Do the request and get back a response...
   */
 
-  if ((response = cupsDoRequest(http, request, "/admin/")) == NULL)
-  {
-    _cupsLangPrintf(stderr, "lpadmin: %s", cupsLastErrorString());
+  ippDelete(cupsDoRequest(http, request, "/admin/"));
 
-    return (1);
-  }
-  else if (response->request.status.status_code > IPP_OK_CONFLICT)
+  if (cupsLastError() > IPP_OK_CONFLICT)
   {
-    _cupsLangPrintf(stderr, "lpadmin: %s", cupsLastErrorString());
-
-    ippDelete(response);
+    _cupsLangPrintf(stderr, _("%s: %s"), "lpadmin", cupsLastErrorString());
 
     return (1);
   }
   else
-  {
-    ippDelete(response);
-
     return (0);
-  }
 }
 
 
@@ -829,8 +870,7 @@ static int                          /* O - 0 on success, 1 on fail */
 delete_printer(http_t *http,           /* I - Server connection */
                char   *printer)                /* I - Printer to delete */
 {
-  ipp_t                *request,               /* IPP Request */
-               *response;              /* IPP Response */
+  ipp_t                *request;               /* IPP Request */
   char         uri[HTTP_MAX_URI];      /* URI for printer/class */
 
 
@@ -843,6 +883,7 @@ delete_printer(http_t *http,                /* I - Server connection */
   *    attributes-charset
   *    attributes-natural-language
   *    printer-uri
+  *    requesting-user-name
   */
 
   request = ippNewRequest(CUPS_DELETE_PRINTER);
@@ -851,31 +892,23 @@ delete_printer(http_t *http,              /* I - Server connection */
                    "localhost", 0, "/printers/%s", printer);
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                "printer-uri", NULL, uri);
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
+               NULL, cupsUser());
 
  /*
   * Do the request and get back a response...
   */
 
-  if ((response = cupsDoRequest(http, request, "/admin/")) == NULL)
-  {
-    _cupsLangPrintf(stderr, "lpadmin: %s", cupsLastErrorString());
+  ippDelete(cupsDoRequest(http, request, "/admin/"));
 
-    return (1);
-  }
-  else if (response->request.status.status_code > IPP_OK_CONFLICT)
+  if (cupsLastError() > IPP_OK_CONFLICT)
   {
-    _cupsLangPrintf(stderr, "lpadmin: %s", cupsLastErrorString());
-
-    ippDelete(response);
+    _cupsLangPrintf(stderr, _("%s: %s"), "lpadmin", cupsLastErrorString());
 
     return (1);
   }
   else
-  {
-    ippDelete(response);
-
     return (0);
-  }
 }
 
 
@@ -907,6 +940,7 @@ delete_printer_from_class(
   *    attributes-charset
   *    attributes-natural-language
   *    printer-uri
+  *    requesting-user-name
   */
 
   request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
@@ -915,6 +949,8 @@ delete_printer_from_class(
                    "localhost", 0, "/classes/%s", pclass);
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                "printer-uri", NULL, uri);
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
+               NULL, cupsUser());
 
  /*
   * Do the request and get back a response...
@@ -923,7 +959,7 @@ delete_printer_from_class(
   if ((response = cupsDoRequest(http, request, "/classes/")) == NULL ||
       response->request.status.status_code == IPP_NOT_FOUND)
   {
-    _cupsLangPrintf(stderr, "lpadmin: %s", cupsLastErrorString());
+    _cupsLangPrintf(stderr, _("%s: %s"), "lpadmin", cupsLastErrorString());
 
     ippDelete(response);
 
@@ -967,29 +1003,35 @@ delete_printer_from_class(
     *    attributes-charset
     *    attributes-natural-language
     *    printer-uri
+    *    requesting-user-name
     */
 
     request = ippNewRequest(CUPS_DELETE_CLASS);
 
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                 "printer-uri", NULL, uri);
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
+                 "requesting-user-name", NULL, cupsUser());
   }
   else
   {
    /*
-    * Build a CUPS_ADD_CLASS request, which requires the following
+    * Build a CUPS_ADD_MODIFY_CLASS request, which requires the following
     * attributes:
     *
     *    attributes-charset
     *    attributes-natural-language
     *    printer-uri
+    *    requesting-user-name
     *    member-uris
     */
 
-    request = ippNewRequest(CUPS_ADD_CLASS);
+    request = ippNewRequest(CUPS_ADD_MODIFY_CLASS);
 
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                 "printer-uri", NULL, uri);
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
+                 "requesting-user-name", NULL, cupsUser());
 
    /*
     * Delete the printer from the class...
@@ -1011,26 +1053,69 @@ delete_printer_from_class(
 
   ippDelete(response);
 
-  if ((response = cupsDoRequest(http, request, "/admin/")) == NULL)
+  ippDelete(cupsDoRequest(http, request, "/admin/"));
+
+  if (cupsLastError() > IPP_OK_CONFLICT)
   {
-    _cupsLangPrintf(stderr, "lpadmin: %s", cupsLastErrorString());
+    _cupsLangPrintf(stderr, _("%s: %s"), "lpadmin", cupsLastErrorString());
 
     return (1);
   }
-  else if (response->request.status.status_code > IPP_OK_CONFLICT)
-  {
-    _cupsLangPrintf(stderr, "lpadmin: %s", cupsLastErrorString());
+  else
+    return (0);
+}
 
-    ippDelete(response);
 
-    return (1);
-  }
+/*
+ * 'delete_printer_option()' - Delete a printer option.
+ */
+
+static int                             /* O - 0 on success, 1 on fail */
+delete_printer_option(http_t *http,    /* I - Server connection */
+                      char   *printer, /* I - Printer */
+                     char   *option)   /* I - Option to delete */
+{
+  ipp_t                *request;               /* IPP request */
+  char         uri[HTTP_MAX_URI];      /* URI for printer/class */
+
+
+ /*
+  * Build a CUPS_ADD_MODIFY_PRINTER or CUPS_ADD_MODIFY_CLASS request, which
+  * requires the following attributes:
+  *
+  *    attributes-charset
+  *    attributes-natural-language
+  *    printer-uri
+  *    requesting-user-name
+  *    option with deleteAttr tag
+  */
+
+  if (get_printer_type(http, printer, uri, sizeof(uri)) &
+          (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT))
+    request = ippNewRequest(CUPS_ADD_MODIFY_CLASS);
   else
+    request = ippNewRequest(CUPS_ADD_MODIFY_PRINTER);
+
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
+               "printer-uri", NULL, uri);
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
+               "requesting-user-name", NULL, cupsUser());
+  ippAddInteger(request, IPP_TAG_PRINTER, IPP_TAG_DELETEATTR, option, 0);
+
+ /*
+  * Do the request and get back a response...
+  */
+
+  ippDelete(cupsDoRequest(http, request, "/admin/"));
+
+  if (cupsLastError() > IPP_OK_CONFLICT)
   {
-    ippDelete(response);
+    _cupsLangPrintf(stderr, _("%s: %s"), "lpadmin", cupsLastErrorString());
 
-    return (0);
+    return (1);
   }
+  else
+    return (0);
 }
 
 
@@ -1042,60 +1127,113 @@ static int                             /* O - 0 on success, 1 on fail */
 enable_printer(http_t *http,           /* I - Server connection */
                char   *printer)                /* I - Printer to enable */
 {
-  ipp_t                *request,               /* IPP Request */
-               *response;              /* IPP Response */
+  ipp_t                *request;               /* IPP Request */
   char         uri[HTTP_MAX_URI];      /* URI for printer/class */
 
 
   DEBUG_printf(("enable_printer(%p, \"%s\")\n", http, printer));
 
  /*
-  * Build a CUPS_ADD_PRINTER request, which requires the following
-  * attributes:
+  * Build a CUPS_ADD_MODIFY_PRINTER or CUPS_ADD_MODIFY_CLASS request, which
+  * require the following attributes:
   *
   *    attributes-charset
   *    attributes-natural-language
   *    printer-uri
+  *    requesting-user-name
   *    printer-state
   *    printer-is-accepting-jobs
   */
 
-  request = ippNewRequest(CUPS_ADD_PRINTER);
+  if (get_printer_type(http, printer, uri, sizeof(uri)) &
+          (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT))
+    request = ippNewRequest(CUPS_ADD_MODIFY_CLASS);
+  else
+    request = ippNewRequest(CUPS_ADD_MODIFY_PRINTER);
 
-  httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
-                   "localhost", 0, "/printers/%s", printer);
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                "printer-uri", NULL, uri);
-
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
+               "requesting-user-name", NULL, cupsUser());
   ippAddInteger(request, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state",
                 IPP_PRINTER_IDLE);
-
   ippAddBoolean(request, IPP_TAG_PRINTER, "printer-is-accepting-jobs", 1);
 
  /*
   * Do the request and get back a response...
   */
 
-  if ((response = cupsDoRequest(http, request, "/admin/")) == NULL)
-  {
-    _cupsLangPrintf(stderr, "lpadmin: %s", cupsLastErrorString());
+  ippDelete(cupsDoRequest(http, request, "/admin/"));
 
-    return (1);
-  }
-  else if (response->request.status.status_code > IPP_OK_CONFLICT)
+  if (cupsLastError() > IPP_OK_CONFLICT)
   {
-    _cupsLangPrintf(stderr, "lpadmin: %s", cupsLastErrorString());
-
-    ippDelete(response);
+    _cupsLangPrintf(stderr, _("%s: %s"), "lpadmin", cupsLastErrorString());
 
     return (1);
   }
   else
+    return (0);
+}
+
+
+/*
+ * 'get_printer_type()' - Determine the printer type and URI.
+ */
+
+static cups_ptype_t                    /* O - printer-type value */
+get_printer_type(http_t *http,         /* I - Server connection */
+                 char   *printer,      /* I - Printer name */
+                char   *uri,           /* I - URI buffer */
+                 size_t urisize)       /* I - Size of URI buffer */
+{
+  ipp_t                        *request,       /* IPP request */
+                       *response;      /* IPP response */
+  ipp_attribute_t      *attr;          /* printer-type attribute */
+  cups_ptype_t         type;           /* printer-type value */
+
+
+ /*
+  * Build a GET_PRINTER_ATTRIBUTES request, which requires the following
+  * attributes:
+  *
+  *    attributes-charset
+  *    attributes-natural-language
+  *    printer-uri
+  *    requested-attributes
+  *    requesting-user-name
+  */
+
+  httpAssembleURIf(HTTP_URI_CODING_ALL, uri, urisize, "ipp", NULL, "localhost",
+                   ippPort(), "/printers/%s", printer);
+
+  request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
+               "printer-uri", NULL, uri);
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
+               "requested-attributes", NULL, "printer-type");
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
+               "requesting-user-name", NULL, cupsUser());
+
+ /*
+  * Do the request...
+  */
+
+  response = cupsDoRequest(http, request, "/");
+  if ((attr = ippFindAttribute(response, "printer-type",
+                               IPP_TAG_ENUM)) != NULL)
   {
-    ippDelete(response);
+    type = (cups_ptype_t)attr->values[0].integer;
 
-    return (0);
+    if (type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT))
+      httpAssembleURIf(HTTP_URI_CODING_ALL, uri, urisize, "ipp", NULL,
+                      "localhost", ippPort(), "/classes/%s", printer);
   }
+  else
+    type = CUPS_PRINTER_LOCAL;
+
+  ippDelete(response);
+
+  return (type);
 }
 
 
@@ -1111,10 +1249,7 @@ set_printer_options(
     cups_option_t *options,            /* I - Options */
     char          *file)               /* I - PPD file/interface script */
 {
-  ipp_t                *request,               /* IPP Request */
-               *response;              /* IPP Response */
-  ipp_attribute_t *attr;               /* IPP attribute */
-  ipp_op_t     op;                     /* Operation to perform */
+  ipp_t                *request;               /* IPP Request */
   const char   *ppdfile;               /* PPD filename */
   int          ppdchanged;             /* PPD changed? */
   ppd_file_t   *ppd;                   /* PPD file */
@@ -1137,52 +1272,6 @@ set_printer_options(
                 "options=%p, file=\"%s\")\n", http, printer, num_options,
                options, file));
 
-  httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
-                   "localhost", 0, "/printers/%s", printer);
-
- /*
-  * Build a GET_PRINTER_ATTRIBUTES request, which requires the following
-  * attributes:
-  *
-  *    attributes-charset
-  *    attributes-natural-language
-  *    printer-uri
-  *    requested-attributes
-  */
-
-  request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
-
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
-               "printer-uri", NULL, uri);
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
-               "requested-attributes", NULL, "printer-type");
-
- /*
-  * Do the request...
-  */
-
-  op = CUPS_ADD_MODIFY_PRINTER;
-
-  if ((response = cupsDoRequest(http, request, "/")) != NULL)
-  {
-   /*
-    * See what kind of printer or class it is...
-    */
-
-    if ((attr = ippFindAttribute(response, "printer-type",
-                                 IPP_TAG_ENUM)) != NULL)
-    {
-      if (attr->values[0].integer & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT))
-      {
-        op = CUPS_ADD_MODIFY_CLASS;
-       httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
-                        "localhost", 0, "/classes/%s", printer);
-      }
-    }
-
-    ippDelete(response);
-  }
-
  /*
   * Build a CUPS_ADD_MODIFY_PRINTER or CUPS_ADD_MODIFY_CLASS request, which
   * requires the following attributes:
@@ -1190,10 +1279,15 @@ set_printer_options(
   *    attributes-charset
   *    attributes-natural-language
   *    printer-uri
+  *    requesting-user-name
   *    other options
   */
 
-  request = ippNewRequest(op);
+  if (get_printer_type(http, printer, uri, sizeof(uri)) &
+          (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT))
+    request = ippNewRequest(CUPS_ADD_MODIFY_CLASS);
+  else
+    request = ippNewRequest(CUPS_ADD_MODIFY_PRINTER);
 
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                "printer-uri", NULL, uri);
@@ -1218,7 +1312,7 @@ set_printer_options(
 
   if (file)
     ppdfile = file;
-  else if (op == CUPS_ADD_MODIFY_PRINTER)
+  else if (request->request.op.operation_id == CUPS_ADD_MODIFY_PRINTER)
     ppdfile = cupsGetPPD(printer);
   else
     ppdfile = NULL;
@@ -1384,7 +1478,7 @@ set_printer_options(
 
   if (cupsLastError() > IPP_OK_CONFLICT)
   {
-    _cupsLangPrintf(stderr, "lpadmin: %s", cupsLastErrorString());
+    _cupsLangPrintf(stderr, _("%s: %s"), "lpadmin", cupsLastErrorString());
 
     return (1);
   }