]> 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:53 +0000 (21:28 -0400)
committerMichael R Sweet <michael.r.sweet@gmail.com>
Tue, 19 Jun 2018 01:28:53 +0000 (21:28 -0400)
CHANGES.md
systemv/lpadmin.c

index b0278e1f4f7db60a2debf5226a8fee1c9c4334b5..a7c2f4b29546fc60afcda3c14ec624a1bbeadde8 100644 (file)
@@ -5,6 +5,8 @@ CHANGES - 2.2.9 - 2018-06-18
 Changes in CUPS v2.2.9
 ----------------------
 
+- The lpadmin command would create a non-working printer in some error cases
+  (Issue #5305)
 - Fixed a regression in the changes to ippValidateAttribute (Issue #5322,
   Issue #5330)
 - Fixed a crash bug in the Epson dot matrix driver (Issue #5323)
index 1ea0d3318502a5533dbb6aa577053b991a854ccd..5e2735d26084133746a1bb272aa64ac3c528f271 100644 (file)
@@ -1127,33 +1127,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/"));
 
@@ -1163,8 +1163,8 @@ enable_printer(http_t *http,              /* I - Server connection */
 
     return (1);
   }
-  else
-    return (0);
+
+  return (0);
 }