From 997b67343f7489183db0319c9f4eac82e1472794 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Mon, 18 Jun 2018 21:28:04 -0400 Subject: [PATCH] Use Enable-Printer and Resume-Printer operations so we don't create a bogus printer (Issue #5305) --- CHANGES.md | 2 ++ systemv/lpadmin.c | 38 +++++++++++++++++++------------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7538ea683b..ce3ff1e5ab 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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) diff --git a/systemv/lpadmin.c b/systemv/lpadmin.c index 5841d866c2..d7d02591a4 100644 --- a/systemv/lpadmin.c +++ b/systemv/lpadmin.c @@ -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); } -- 2.47.2