]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - systemv/lpadmin.c
Interface scripts are no longer supported for security reasons
[thirdparty/cups.git] / systemv / lpadmin.c
index d954e75fb8e1935f5d5b262ca12148ad86cc7925..eb7ce0fb2f33acec24c0d67e3307afb3f574378e 100644 (file)
@@ -1,36 +1,24 @@
 /*
  * "$Id$"
  *
- *   "lpadmin" command for CUPS.
+ * "lpadmin" command for CUPS.
  *
- *   Copyright 2007-2011 by Apple Inc.
- *   Copyright 1997-2006 by Easy Software Products.
+ * Copyright 2007-2015 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
  *
- *   These coded instructions, statements, and computer programs are the
- *   property of Apple Inc. and are protected by Federal copyright
- *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- *   which should have been included with this file.  If this file is
- *   file is missing or damaged, see the license at "http://www.cups.org/".
- *
- * Contents:
- *
- *   main()                      - Parse options and configure the scheduler.
- *   add_printer_to_class()      - Add a printer to a class.
- *   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.
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file.  If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
  */
 
 /*
  * Include necessary headers...
  */
 
+#define _CUPS_NO_DEPRECATED
+#define _PPD_DEPRECATED
 #include <cups/cups-private.h>
 
 
@@ -46,6 +34,7 @@ static int            delete_printer_from_class(http_t *http, char *printer,
 static int             delete_printer_option(http_t *http, char *printer,
                                              char *option);
 static int             enable_printer(http_t *http, char *printer);
+static char            *get_printer_ppd(const char *uri, char *buffer, size_t bufsize);
 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,
@@ -69,7 +58,11 @@ main(int  argc,                      /* I - Number of command-line arguments */
                *val;           /* Pointer to allow/deny value */
   int          num_options;    /* Number of options */
   cups_option_t        *options;       /* Options */
-  char         *file;          /* New PPD file/interface script */
+  char         *file,          /* New PPD file */
+               evefile[1024] = "";
+                               /* IPP Everywhere PPD */
+  const char   *ppd_name,      /* ppd-name value */
+               *device_uri;    /* device-uri value */
 
 
   _cupsSetLocale(argv);
@@ -87,8 +80,7 @@ main(int  argc,                       /* I - Number of command-line arguments */
         case 'c' : /* Add printer to class */
            if (!http)
            {
-              http = httpConnectEncrypt(cupsServer(), ippPort(),
-                                       cupsEncryption());
+              http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL);
 
              if (http == NULL)
              {
@@ -140,8 +132,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
         case 'd' : /* Set as default destination */
            if (!http)
            {
-              http = httpConnectEncrypt(cupsServer(), ippPort(),
-                                       cupsEncryption());
+              http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL);
 
              if (http == NULL)
              {
@@ -208,7 +199,8 @@ main(int  argc,                     /* I - Number of command-line arguments */
            }
            break;
 
-        case 'i' : /* Use the specified interface script */
+        case 'P' : /* Use the specified PPD file */
+        case 'i' : /* Use the specified PPD file */
            if (argv[i][2])
              file = argv[i] + 2;
            else
@@ -217,9 +209,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
 
              if (i >= argc)
              {
-               _cupsLangPuts(stderr,
-                             _("lpadmin: Expected interface after \"-i\" "
-                               "option."));
+               _cupsLangPrintf(stderr, _("lpadmin: Expected PPD after \"-%c\" option."), argv[i - 1][1]);
                return (1);
              }
 
@@ -231,10 +221,10 @@ main(int  argc,                   /* I - Number of command-line arguments */
            if (printer == NULL)
            {
 #ifdef HAVE_SSL
-             cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
+             cupsSetEncryption(HTTP_ENCRYPTION_REQUIRED);
 
              if (http)
-               httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
+               httpEncryption(http, HTTP_ENCRYPTION_REQUIRED);
 #else
               _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."),
                              argv[0]);
@@ -244,8 +234,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
 
            if (!http)
            {
-              http = httpConnectEncrypt(cupsServer(), ippPort(),
-                                       cupsEncryption());
+              http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL);
 
              if (http == NULL)
              {
@@ -330,8 +319,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
         case 'r' : /* Remove printer from class */
            if (!http)
            {
-              http = httpConnectEncrypt(cupsServer(), ippPort(),
-                                       cupsEncryption());
+              http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL);
 
              if (http == NULL)
              {
@@ -384,8 +372,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
         case 'R' : /* Remove option */
            if (!http)
            {
-              http = httpConnectEncrypt(cupsServer(), ippPort(),
-                                       cupsEncryption());
+              http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL);
 
              if (http == NULL)
              {
@@ -501,8 +488,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
         case 'x' : /* Delete a printer */
            if (!http)
            {
-              http = httpConnectEncrypt(cupsServer(), ippPort(),
-                                       cupsEncryption());
+              http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL);
 
              if (http == NULL)
              {
@@ -601,24 +587,6 @@ main(int  argc,                    /* I - Number of command-line arguments */
            }
            break;
 
-        case 'P' : /* Use the specified PPD file */
-           if (argv[i][2])
-             file = argv[i] + 2;
-           else
-           {
-             i ++;
-
-             if (i >= argc)
-             {
-               _cupsLangPuts(stderr,
-                             _("lpadmin: Expected PPD after \"-P\" option."));
-               return (1);
-             }
-
-             file = argv[i];
-           }
-           break;
-
        default :
            _cupsLangPrintf(stderr,
                            _("lpadmin: Unknown option \"%c\"."), argv[i][1]);
@@ -635,11 +603,19 @@ main(int  argc,                   /* I - Number of command-line arguments */
   * Set options as needed...
   */
 
+  if ((ppd_name = cupsGetOption("ppd-name", num_options, options)) != NULL && !strcmp(ppd_name, "everywhere") && (device_uri = cupsGetOption("device-uri", num_options, options)) != NULL)
+  {
+    if ((file = get_printer_ppd(device_uri, evefile, sizeof(evefile))) == NULL)
+      return (1);
+
+    num_options = cupsRemoveOption("ppd-name", num_options, &options);
+  }
+
   if (num_options || file)
   {
     if (!http)
     {
-      http = httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
+      http = httpConnect2(cupsServer(), ippPort(), NULL, AF_UNSPEC, cupsEncryption(), 1, 30000, NULL);
 
       if (http == NULL)
       {
@@ -662,6 +638,9 @@ main(int  argc,                     /* I - Number of command-line arguments */
       return (1);
   }
 
+  if (evefile[0])
+    unlink(evefile);
+
   if (printer == NULL)
   {
     _cupsLangPuts(stdout,
@@ -706,7 +685,7 @@ add_printer_to_class(http_t *http,  /* I - Server connection */
                 printer, pclass));
 
  /*
-  * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the following
+  * Build an IPP_OP_GET_PRINTER_ATTRIBUTES request, which requires the following
   * attributes:
   *
   *    attributes-charset
@@ -715,7 +694,7 @@ add_printer_to_class(http_t *http,  /* I - Server connection */
   *    requesting-user-name
   */
 
-  request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
+  request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
 
   httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
                    "localhost", 0, "/classes/%s", pclass);
@@ -731,7 +710,7 @@ add_printer_to_class(http_t *http,  /* I - Server connection */
   response = cupsDoRequest(http, request, "/");
 
  /*
-  * Build a CUPS_ADD_MODIFY_CLASS request, which requires the following
+  * Build a CUPS-Add-Modify-Class request, which requires the following
   * attributes:
   *
   *    attributes-charset
@@ -741,7 +720,7 @@ add_printer_to_class(http_t *http,  /* I - Server connection */
   *    member-uris
   */
 
-  request = ippNewRequest(CUPS_ADD_MODIFY_CLASS);
+  request = ippNewRequest(IPP_OP_CUPS_ADD_MODIFY_CLASS);
 
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                "printer-uri", NULL, uri);
@@ -800,7 +779,7 @@ add_printer_to_class(http_t *http,  /* I - Server connection */
   ippDelete(response);
 
   ippDelete(cupsDoRequest(http, request, "/admin/"));
-  if (cupsLastError() > IPP_OK_CONFLICT)
+  if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
   {
     _cupsLangPrintf(stderr, _("%s: %s"), "lpadmin", cupsLastErrorString());
 
@@ -826,7 +805,7 @@ default_printer(http_t *http,               /* I - Server connection */
   DEBUG_printf(("default_printer(%p, \"%s\")\n", http, printer));
 
  /*
-  * Build a CUPS_SET_DEFAULT request, which requires the following
+  * Build a CUPS-Set-Default request, which requires the following
   * attributes:
   *
   *    attributes-charset
@@ -838,7 +817,7 @@ default_printer(http_t *http,               /* I - Server connection */
   httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
                    "localhost", 0, "/printers/%s", printer);
 
-  request = ippNewRequest(CUPS_SET_DEFAULT);
+  request = ippNewRequest(IPP_OP_CUPS_SET_DEFAULT);
 
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                "printer-uri", NULL, uri);
@@ -851,7 +830,7 @@ default_printer(http_t *http,               /* I - Server connection */
 
   ippDelete(cupsDoRequest(http, request, "/admin/"));
 
-  if (cupsLastError() > IPP_OK_CONFLICT)
+  if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
   {
     _cupsLangPrintf(stderr, _("%s: %s"), "lpadmin", cupsLastErrorString());
 
@@ -877,7 +856,7 @@ delete_printer(http_t *http,                /* I - Server connection */
   DEBUG_printf(("delete_printer(%p, \"%s\")\n", http, printer));
 
  /*
-  * Build a CUPS_DELETE_PRINTER request, which requires the following
+  * Build a CUPS-Delete-Printer request, which requires the following
   * attributes:
   *
   *    attributes-charset
@@ -886,7 +865,7 @@ delete_printer(http_t *http,                /* I - Server connection */
   *    requesting-user-name
   */
 
-  request = ippNewRequest(CUPS_DELETE_PRINTER);
+  request = ippNewRequest(IPP_OP_CUPS_DELETE_PRINTER);
 
   httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
                    "localhost", 0, "/printers/%s", printer);
@@ -901,7 +880,7 @@ delete_printer(http_t *http,                /* I - Server connection */
 
   ippDelete(cupsDoRequest(http, request, "/admin/"));
 
-  if (cupsLastError() > IPP_OK_CONFLICT)
+  if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
   {
     _cupsLangPrintf(stderr, _("%s: %s"), "lpadmin", cupsLastErrorString());
 
@@ -934,7 +913,7 @@ delete_printer_from_class(
                 printer, pclass));
 
  /*
-  * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the following
+  * Build an IPP_OP_GET_PRINTER_ATTRIBUTES request, which requires the following
   * attributes:
   *
   *    attributes-charset
@@ -943,7 +922,7 @@ delete_printer_from_class(
   *    requesting-user-name
   */
 
-  request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
+  request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
 
   httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
                    "localhost", 0, "/classes/%s", pclass);
@@ -957,7 +936,7 @@ delete_printer_from_class(
   */
 
   if ((response = cupsDoRequest(http, request, "/classes/")) == NULL ||
-      response->request.status.status_code == IPP_NOT_FOUND)
+      response->request.status.status_code == IPP_STATUS_ERROR_NOT_FOUND)
   {
     _cupsLangPrintf(stderr, _("%s: %s"), "lpadmin", cupsLastErrorString());
 
@@ -997,7 +976,7 @@ delete_printer_from_class(
   if (members->num_values == 1)
   {
    /*
-    * Build a CUPS_DELETE_CLASS request, which requires the following
+    * Build a CUPS-Delete-Class request, which requires the following
     * attributes:
     *
     *    attributes-charset
@@ -1006,7 +985,7 @@ delete_printer_from_class(
     *    requesting-user-name
     */
 
-    request = ippNewRequest(CUPS_DELETE_CLASS);
+    request = ippNewRequest(IPP_OP_CUPS_DELETE_CLASS);
 
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                 "printer-uri", NULL, uri);
@@ -1016,7 +995,7 @@ delete_printer_from_class(
   else
   {
    /*
-    * Build a CUPS_ADD_MODIFY_CLASS request, which requires the following
+    * Build a IPP_OP_CUPS_ADD_MODIFY_CLASS request, which requires the following
     * attributes:
     *
     *    attributes-charset
@@ -1026,7 +1005,7 @@ delete_printer_from_class(
     *    member-uris
     */
 
-    request = ippNewRequest(CUPS_ADD_MODIFY_CLASS);
+    request = ippNewRequest(IPP_OP_CUPS_ADD_MODIFY_CLASS);
 
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                 "printer-uri", NULL, uri);
@@ -1055,7 +1034,7 @@ delete_printer_from_class(
 
   ippDelete(cupsDoRequest(http, request, "/admin/"));
 
-  if (cupsLastError() > IPP_OK_CONFLICT)
+  if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
   {
     _cupsLangPrintf(stderr, _("%s: %s"), "lpadmin", cupsLastErrorString());
 
@@ -1080,7 +1059,7 @@ delete_printer_option(http_t *http,       /* I - Server connection */
 
 
  /*
-  * Build a CUPS_ADD_MODIFY_PRINTER or CUPS_ADD_MODIFY_CLASS request, which
+  * Build a IPP_OP_CUPS_ADD_MODIFY_PRINTER or IPP_OP_CUPS_ADD_MODIFY_CLASS request, which
   * requires the following attributes:
   *
   *    attributes-charset
@@ -1091,9 +1070,9 @@ delete_printer_option(http_t *http,       /* I - Server connection */
   */
 
   if (get_printer_type(http, printer, uri, sizeof(uri)) & CUPS_PRINTER_CLASS)
-    request = ippNewRequest(CUPS_ADD_MODIFY_CLASS);
+    request = ippNewRequest(IPP_OP_CUPS_ADD_MODIFY_CLASS);
   else
-    request = ippNewRequest(CUPS_ADD_MODIFY_PRINTER);
+    request = ippNewRequest(IPP_OP_CUPS_ADD_MODIFY_PRINTER);
 
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                "printer-uri", NULL, uri);
@@ -1107,7 +1086,7 @@ delete_printer_option(http_t *http,       /* I - Server connection */
 
   ippDelete(cupsDoRequest(http, request, "/admin/"));
 
-  if (cupsLastError() > IPP_OK_CONFLICT)
+  if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
   {
     _cupsLangPrintf(stderr, _("%s: %s"), "lpadmin", cupsLastErrorString());
 
@@ -1133,7 +1112,7 @@ enable_printer(http_t *http,              /* I - Server connection */
   DEBUG_printf(("enable_printer(%p, \"%s\")\n", http, printer));
 
  /*
-  * Build a CUPS_ADD_MODIFY_PRINTER or CUPS_ADD_MODIFY_CLASS request, which
+  * Build a IPP_OP_CUPS_ADD_MODIFY_PRINTER or IPP_OP_CUPS_ADD_MODIFY_CLASS request, which
   * require the following attributes:
   *
   *    attributes-charset
@@ -1145,16 +1124,16 @@ enable_printer(http_t *http,            /* I - Server connection */
   */
 
   if (get_printer_type(http, printer, uri, sizeof(uri)) & CUPS_PRINTER_CLASS)
-    request = ippNewRequest(CUPS_ADD_MODIFY_CLASS);
+    request = ippNewRequest(IPP_OP_CUPS_ADD_MODIFY_CLASS);
   else
-    request = ippNewRequest(CUPS_ADD_MODIFY_PRINTER);
+    request = ippNewRequest(IPP_OP_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_ENUM, "printer-state",
-                IPP_PRINTER_IDLE);
+                IPP_PSTATE_IDLE);
   ippAddBoolean(request, IPP_TAG_PRINTER, "printer-is-accepting-jobs", 1);
 
  /*
@@ -1163,7 +1142,7 @@ enable_printer(http_t *http,              /* I - Server connection */
 
   ippDelete(cupsDoRequest(http, request, "/admin/"));
 
-  if (cupsLastError() > IPP_OK_CONFLICT)
+  if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
   {
     _cupsLangPrintf(stderr, _("%s: %s"), "lpadmin", cupsLastErrorString());
 
@@ -1174,6 +1153,79 @@ enable_printer(http_t *http,             /* I - Server connection */
 }
 
 
+/*
+ * 'get_printer_ppd()' - Get an IPP Everywhere PPD file for the given URI.
+ */
+
+static char *                          /* O - Filename or NULL */
+get_printer_ppd(const char *uri,       /* I - Printer URI */
+                char       *buffer,    /* I - Filename buffer */
+               size_t     bufsize)     /* I - Size of filename buffer */
+{
+  http_t       *http;                  /* Connection to printer */
+  ipp_t                *request,               /* Get-Printer-Attributes request */
+               *response;              /* Get-Printer-Attributes response */
+  char         resolved[1024],         /* Resolved URI */
+               scheme[32],             /* URI scheme */
+               userpass[256],          /* Username:password */
+               host[256],              /* Hostname */
+               resource[256];          /* Resource path */
+  int          port;                   /* Port number */
+
+
+ /*
+  * Connect to the printer...
+  */
+
+  if (strstr(uri, "._tcp"))
+  {
+   /*
+    * Resolve URI...
+    */
+
+    if (!_httpResolveURI(uri, resolved, sizeof(resolved), _HTTP_RESOLVE_DEFAULT, NULL, NULL))
+    {
+      _cupsLangPrintf(stderr, _("%s: Unable to resolve \"%s\"."), "lpadmin", uri);
+      return (NULL);
+    }
+
+    uri = resolved;
+  }
+
+  if (httpSeparateURI(HTTP_URI_CODING_ALL, uri, scheme, sizeof(scheme), userpass, sizeof(userpass), host, sizeof(host), &port, resource, sizeof(resource)) < HTTP_URI_STATUS_OK)
+  {
+    _cupsLangPrintf(stderr, _("%s: Bad printer URI \"%s\"."), "lpadmin", uri);
+    return (NULL);
+  }
+
+  http = httpConnect2(host, port, NULL, AF_UNSPEC, !strcmp(scheme, "ipps") ? HTTP_ENCRYPTION_ALWAYS : HTTP_ENCRYPTION_IF_REQUESTED, 1, 30000, NULL);
+  if (!http)
+  {
+    _cupsLangPrintf(stderr, _("%s: Unable to connect to \"%s:%d\": %s"), "lpadmin", host, port, cupsLastErrorString());
+    return (NULL);
+  }
+
+ /*
+  * Send a Get-Printer-Attributes request...
+  */
+
+  request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
+  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
+  response = cupsDoRequest(http, request, resource);
+
+  if (!_ppdCreateFromIPP(buffer, bufsize, response))
+    _cupsLangPrintf(stderr, _("%s: Unable to create PPD file: %s"), "lpadmin", strerror(errno));
+
+  ippDelete(response);
+  httpClose(http);
+
+  if (buffer[0])
+    return (buffer);
+  else
+    return (NULL);
+}
+
+
 /*
  * 'get_printer_type()' - Determine the printer type and URI.
  */
@@ -1201,10 +1253,9 @@ get_printer_type(http_t *http,           /* I - Server connection */
   *    requesting-user-name
   */
 
-  httpAssembleURIf(HTTP_URI_CODING_ALL, uri, urisize, "ipp", NULL, "localhost",
-                   ippPort(), "/printers/%s", printer);
+  httpAssembleURIf(HTTP_URI_CODING_ALL, uri, (int)urisize, "ipp", NULL, "localhost", ippPort(), "/printers/%s", printer);
 
-  request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
+  request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                "printer-uri", NULL, uri);
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
@@ -1223,8 +1274,7 @@ get_printer_type(http_t *http,            /* I - Server connection */
     type = (cups_ptype_t)attr->values[0].integer;
 
     if (type & CUPS_PRINTER_CLASS)
-      httpAssembleURIf(HTTP_URI_CODING_ALL, uri, urisize, "ipp", NULL,
-                      "localhost", ippPort(), "/classes/%s", printer);
+      httpAssembleURIf(HTTP_URI_CODING_ALL, uri, (int)urisize, "ipp", NULL, "localhost", ippPort(), "/classes/%s", printer);
   }
   else
     type = CUPS_PRINTER_LOCAL;
@@ -1249,7 +1299,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 */
@@ -1259,11 +1309,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, "
@@ -1271,8 +1323,8 @@ set_printer_options(
                options, file));
 
  /*
-  * Build a CUPS_ADD_MODIFY_PRINTER or CUPS_ADD_MODIFY_CLASS request, which
-  * requires the following attributes:
+  * Build a CUPS-Add-Modify-Printer or CUPS-Add-Modify-Class request,
+  * which requires the following attributes:
   *
   *    attributes-charset
   *    attributes-natural-language
@@ -1282,19 +1334,45 @@ set_printer_options(
   */
 
   if (get_printer_type(http, printer, uri, sizeof(uri)) & CUPS_PRINTER_CLASS)
-    request = ippNewRequest(CUPS_ADD_MODIFY_CLASS);
+    request = ippNewRequest(IPP_OP_CUPS_ADD_MODIFY_CLASS);
   else
-    request = ippNewRequest(CUPS_ADD_MODIFY_PRINTER);
+    request = ippNewRequest(IPP_OP_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());
+  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());
 
  /*
   * Add the 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
+    ppdfile = NULL;
+
+  cupsEncodeOptions2(request, num_options, options, IPP_TAG_OPERATION);
   cupsEncodeOptions2(request, num_options, options, IPP_TAG_PRINTER);
 
   if ((protocol = cupsGetOption("protocol", num_options, options)) != NULL)
@@ -1307,20 +1385,21 @@ set_printer_options(
                    NULL, "tbcp");
   }
 
-  if (file)
-    ppdfile = file;
-  else if (request->request.op.operation_id == CUPS_ADD_MODIFY_PRINTER)
-    ppdfile = cupsGetPPD(printer);
-  else
-    ppdfile = NULL;
-
-  if (ppdfile != NULL)
+  if (ppdfile)
   {
    /*
     * 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);
 
@@ -1330,6 +1409,8 @@ set_printer_options(
       ippDelete(request);
       if (ppdfile != file)
         unlink(ppdfile);
+      if (copied_options)
+        cupsFreeOptions(num_options, options);
       return (1);
     }
 
@@ -1341,13 +1422,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) &&
@@ -1469,11 +1550,14 @@ set_printer_options(
     ippDelete(cupsDoRequest(http, request, "/admin/"));
   }
 
+  if (copied_options)
+    cupsFreeOptions(num_options, options);
+
  /*
   * Check the response...
   */
 
-  if (cupsLastError() > IPP_OK_CONFLICT)
+  if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
   {
     _cupsLangPrintf(stderr, _("%s: %s"), "lpadmin", cupsLastErrorString());