]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Use Enable-Printer and Resume-Printer operations so we don't create a bogus printer...
authorMichael R Sweet <michael.r.sweet@gmail.com>
Tue, 19 Jun 2018 01:28:04 +0000 (21:28 -0400)
committerMichael R Sweet <michael.r.sweet@gmail.com>
Tue, 19 Jun 2018 01:28:04 +0000 (21:28 -0400)
CHANGES.md
systemv/lpadmin.c

index 7538ea683ba1ebc196ad1bbc5c57a98e10f984ea..ce3ff1e5ab5384a445faa81a5f63528fb73b9c0f 100644 (file)
@@ -5,6 +5,8 @@ Changes in CUPS v2.3b6
 ----------------------
 
 - Localization update (Issue #5339)
+- The lpadmin command would create a non-working printer in some error cases
+  (Issue #5305)
 - The scheduler did not idle-exit on some Linux distributions (Issue #5319)
 - Fixed a regression in the changes to ippValidateAttribute (Issue #5322,
   Issue #5330)
index 5841d866c2ad6d4a733dcfa1ca7fba24779ebd91..d7d02591a46a9b772acc3bb835c5ba6c9654c25e 100644 (file)
@@ -1125,33 +1125,33 @@ enable_printer(http_t *http,            /* I - Server connection */
   DEBUG_printf(("enable_printer(%p, \"%s\")\n", http, printer));
 
  /*
-  * Build a IPP_OP_CUPS_ADD_MODIFY_PRINTER or IPP_OP_CUPS_ADD_MODIFY_CLASS request, which
+  * Send IPP_OP_ENABLE_PRINTER and IPP_OP_RESUME_PRINTER requests, which
   * require the following attributes:
   *
   *    attributes-charset
   *    attributes-natural-language
   *    printer-uri
   *    requesting-user-name
-  *    printer-state
-  *    printer-is-accepting-jobs
   */
 
-  if (get_printer_type(http, printer, uri, sizeof(uri)) & CUPS_PRINTER_CLASS)
-    request = ippNewRequest(IPP_OP_CUPS_ADD_MODIFY_CLASS);
-  else
-    request = ippNewRequest(IPP_OP_CUPS_ADD_MODIFY_PRINTER);
+  request = ippNewRequest(IPP_OP_ENABLE_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_PSTATE_IDLE);
-  ippAddBoolean(request, IPP_TAG_PRINTER, "printer-is-accepting-jobs", 1);
+  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...
-  */
+  ippDelete(cupsDoRequest(http, request, "/admin/"));
+
+  if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
+  {
+    _cupsLangPrintf(stderr, _("%s: %s"), "lpadmin", cupsLastErrorString());
+
+    return (1);
+  }
+
+  request = ippNewRequest(IPP_OP_RESUME_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());
 
   ippDelete(cupsDoRequest(http, request, "/admin/"));
 
@@ -1161,8 +1161,8 @@ enable_printer(http_t *http,              /* I - Server connection */
 
     return (1);
   }
-  else
-    return (0);
+
+  return (0);
 }