]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/ipp.c
Merge pull request #5621 from zdohnal/cgigetarray-sigsegv
[thirdparty/cups.git] / scheduler / ipp.c
index c771f77f807473124f9d3238a4e5b41002bf1966..2fe3bf25cc3ac6d384663a95788ae9bf6f18deb2 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * IPP routines for the CUPS scheduler.
  *
- * Copyright © 2007-2018 by Apple Inc.
+ * Copyright © 2007-2019 by Apple Inc.
  * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
  *
  * This file contains Kerberos support code, copyright 2006 by
 #include <cups/ppd-private.h>
 
 #ifdef __APPLE__
-/*#  include <ApplicationServices/ApplicationServices.h>
-extern CFUUIDRef ColorSyncCreateUUIDFromUInt32(unsigned id);
-#  include <CoreFoundation/CoreFoundation.h>*/
 #  ifdef HAVE_MEMBERSHIP_H
 #    include <membership.h>
 #  endif /* HAVE_MEMBERSHIP_H */
-#  ifdef HAVE_MEMBERSHIPPRIV_H
-#    include <membershipPriv.h>
-#  else
 extern int mbr_user_name_to_uuid(const char* name, uuid_t uu);
 extern int mbr_group_name_to_uuid(const char* name, uuid_t uu);
 extern int mbr_check_membership_by_id(uuid_t user, gid_t group, int* ismember);
-#  endif /* HAVE_MEMBERSHIPPRIV_H */
 #endif /* __APPLE__ */
 
 
@@ -1909,18 +1902,14 @@ add_job(cupsd_client_t  *con,           /* I - Client connection */
   * Fill in the response info...
   */
 
-  httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL,
-                   con->clientname, con->clientport, "/jobs/%d", job->id);
-  ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI, "job-uri", NULL,
-               job_uri);
+  httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL, con->clientname, con->clientport, "/jobs/%d", job->id);
+  ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI, "job-uri", NULL, job_uri);
 
   ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
 
-  ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state",
-                job->state_value);
+  ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state", (int)job->state_value);
   ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_TEXT, "job-state-message", NULL, "");
-  ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, "job-state-reasons",
-               NULL, job->reasons->values[0].string.text);
+  ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, "job-state-reasons", NULL, job->reasons->values[0].string.text);
 
   con->response->request.status.status_code = IPP_OK;
 
@@ -2601,8 +2590,7 @@ add_printer(cupsd_client_t  *con, /* I - Client connection */
       if (!strcmp(attr->values[i].string.text, "none"))
         continue;
 
-      printer->reasons[printer->num_reasons] =
-          _cupsStrRetain(attr->values[i].string.text);
+      printer->reasons[printer->num_reasons] = _cupsStrAlloc(attr->values[i].string.text);
       printer->num_reasons ++;
 
       if (!strcmp(attr->values[i].string.text, "paused") &&
@@ -3291,7 +3279,7 @@ cancel_all_jobs(cupsd_client_t  *con,     /* I - Client connection */
       * Cancel all jobs on all printers...
       */
 
-      cupsdCancelJobs(NULL, username, purge);
+      cupsdCancelJobs(NULL, username, purge != CUPSD_JOB_DEFAULT);
 
       cupsdLogMessage(CUPSD_LOG_INFO, "All jobs were %s by \"%s\".",
                      purge == CUPSD_JOB_PURGE ? "purged" : "canceled",
@@ -3350,7 +3338,7 @@ cancel_all_jobs(cupsd_client_t  *con,     /* I - Client connection */
       * Cancel all of the jobs on the named printer...
       */
 
-      cupsdCancelJobs(printer->name, username, purge);
+      cupsdCancelJobs(printer->name, username, purge != CUPSD_JOB_DEFAULT);
 
       cupsdLogMessage(CUPSD_LOG_INFO, "All jobs on \"%s\" were %s by \"%s\".",
                      printer->name,
@@ -4006,8 +3994,7 @@ close_job(cupsd_client_t  *con,           /* I - Client connection */
 
   ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
 
-  ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state",
-                job->state_value);
+  ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state", (int)job->state_value);
 
   con->response->request.status.status_code = IPP_OK;
 
@@ -4892,7 +4879,7 @@ copy_printer_attrs(
 
         if ((p2_uri = ippFindAttribute(p2->attrs, "printer-uri-supported", IPP_TAG_URI)) != NULL)
         {
-          member_uris->values[i].string.text = _cupsStrRetain(p2_uri->values[0].string.text);
+          member_uris->values[i].string.text = _cupsStrAlloc(p2_uri->values[0].string.text);
         }
         else
        {
@@ -4973,7 +4960,7 @@ copy_printer_attrs(
     ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-op-policy", NULL, printer->op_policy);
 
   if (!ra || cupsArrayFind(ra, "printer-state"))
-    ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state", printer->state);
+    ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state", (int)printer->state);
 
   if (!ra || cupsArrayFind(ra, "printer-state-change-date-time"))
     ippAddDate(con->response, IPP_TAG_PRINTER, "printer-state-change-date-time", ippTimeToDate(printer->state_time));
@@ -5256,6 +5243,11 @@ create_local_bg_thread(
                *response;              /* Response from printer */
   ipp_attribute_t *attr;               /* Attribute in response */
   ipp_status_t status;                 /* Status code */
+  static const char * const pattrs[] = /* Printer attributes we need */
+  {
+    "all",
+    "media-col-database"
+  };
 
 
  /*
@@ -5290,7 +5282,7 @@ create_local_bg_thread(
   request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
   ippSetVersion(request, 2, 0);
   ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, printer->device_uri);
-  ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", NULL, "all");
+  ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", (int)(sizeof(pattrs) / sizeof(pattrs[0])), NULL, pattrs);
 
   response = cupsDoRequest(http, request, resource);
   status   = cupsLastError();
@@ -5513,7 +5505,7 @@ create_local_printer(
   add_printer_attributes:
 
   ippAddBoolean(con->response, IPP_TAG_PRINTER, "printer-is-accepting-jobs", (char)printer->accepting);
-  ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state", printer->state);
+  ippAddInteger(con->response, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state", (int)printer->state);
   add_printer_state_reasons(con, printer);
 
   httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), httpIsEncrypted(con->http) ? "ipps" : "ipp", NULL, con->clientname, con->clientport, "/printers/%s", printer->name);
@@ -9950,17 +9942,13 @@ send_document(cupsd_client_t  *con,     /* I - Client connection */
   * Fill in the response info...
   */
 
-  httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL,
-                   con->clientname, con->clientport, "/jobs/%d", jobid);
-  ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI, "job-uri", NULL,
-               job_uri);
+  httpAssembleURIf(HTTP_URI_CODING_ALL, job_uri, sizeof(job_uri), "ipp", NULL, con->clientname, con->clientport, "/jobs/%d", jobid);
+  ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_URI, "job-uri", NULL, job_uri);
 
   ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", jobid);
 
-  ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state",
-                job->state_value);
-  ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, "job-state-reasons",
-               NULL, job->reasons->values[0].string.text);
+  ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state", (int)job->state_value);
+  ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_KEYWORD, "job-state-reasons", NULL, job->reasons->values[0].string.text);
 
   con->response->request.status.status_code = IPP_OK;
 
@@ -10441,7 +10429,7 @@ set_job_attrs(cupsd_client_t  *con,     /* I - Client connection */
 
          case IPP_JOB_PROCESSING :
          case IPP_JOB_STOPPED :
-             if (job->state_value != attr->values[0].integer)
+             if (job->state_value != (ipp_jstate_t)attr->values[0].integer)
              {
                send_ipp_status(con, IPP_NOT_POSSIBLE,
                                _("Job state cannot be changed."));