]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/ipp.c
Fix stuck multi-file jobs (Issue #5359, Issue #5413)
[thirdparty/cups.git] / scheduler / ipp.c
index 89058d2851066e56a3f37328b2ce689968ac3804..c771f77f807473124f9d3238a4e5b41002bf1966 100644 (file)
@@ -115,9 +115,7 @@ static void save_auth_info(cupsd_client_t *con, cupsd_job_t *job,
 static void    send_document(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    send_http_error(cupsd_client_t *con, http_status_t status,
                                cupsd_printer_t *printer);
-static void    send_ipp_status(cupsd_client_t *con, ipp_status_t status,
-                               const char *message, ...)
-               __attribute__((__format__(__printf__, 3, 4)));
+static void    send_ipp_status(cupsd_client_t *con, ipp_status_t status, const char *message, ...) _CUPS_FORMAT(3, 4);
 static void    set_default(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    set_job_attrs(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    set_printer_attrs(cupsd_client_t *con, ipp_attribute_t *uri);
@@ -250,7 +248,7 @@ cupsdProcessIPPRequest(
       */
 
       attr = con->request->attrs;
-      if (attr && attr->name && !strcmp(attr->name, "attributes-charset") && (attr->value_tag & IPP_TAG_MASK) == IPP_TAG_CHARSET)
+      if (attr && attr->name && !strcmp(attr->name, "attributes-charset") && (attr->value_tag & IPP_TAG_MASK) == IPP_TAG_CHARSET && attr->group_tag == IPP_TAG_OPERATION)
        charset = attr;
       else
        charset = NULL;
@@ -258,7 +256,7 @@ cupsdProcessIPPRequest(
       if (attr)
         attr = attr->next;
 
-      if (attr && attr->name && !strcmp(attr->name, "attributes-natural-language") && (attr->value_tag & IPP_TAG_MASK) == IPP_TAG_LANGUAGE)
+      if (attr && attr->name && !strcmp(attr->name, "attributes-natural-language") && (attr->value_tag & IPP_TAG_MASK) == IPP_TAG_LANGUAGE && attr->group_tag == IPP_TAG_OPERATION)
       {
        language = attr;
 
@@ -276,12 +274,12 @@ cupsdProcessIPPRequest(
       else
        language = NULL;
 
-      if ((attr = ippFindAttribute(con->request, "printer-uri", IPP_TAG_URI)) != NULL)
+      if ((attr = ippFindAttribute(con->request, "printer-uri", IPP_TAG_URI)) != NULL && attr->group_tag == IPP_TAG_OPERATION)
        uri = attr;
-      else if ((attr = ippFindAttribute(con->request, "job-uri", IPP_TAG_URI)) != NULL)
+      else if ((attr = ippFindAttribute(con->request, "job-uri", IPP_TAG_URI)) != NULL && attr->group_tag == IPP_TAG_OPERATION)
        uri = attr;
-      else if (con->request->request.op.operation_id == CUPS_GET_PPD)
-        uri = ippFindAttribute(con->request, "ppd-name", IPP_TAG_NAME);
+      else if (con->request->request.op.operation_id == CUPS_GET_PPD && (attr = ippFindAttribute(con->request, "ppd-name", IPP_TAG_NAME)) != NULL && attr->group_tag == IPP_TAG_OPERATION)
+        uri = attr;
       else
        uri = NULL;
 
@@ -2014,7 +2012,7 @@ add_job_subscriptions(
                host[HTTP_MAX_URI],     /* Host portion of URI */
                resource[HTTP_MAX_URI]; /* Resource portion of URI */
         int    port;                   /* Port portion of URI */
-
+        struct stat info;              /* File information */
 
         recipient = attr->values[0].string.text;
 
@@ -2030,9 +2028,8 @@ add_job_subscriptions(
          return;
        }
 
-        snprintf(notifier, sizeof(notifier), "%s/notifier/%s", ServerBin,
-                scheme);
-        if (access(notifier, X_OK) || !strcmp(scheme, ".") || !strcmp(scheme, ".."))
+        snprintf(notifier, sizeof(notifier), "%s/notifier/%s", ServerBin, scheme);
+        if (access(notifier, X_OK) || stat(notifier, &info) || !S_ISREG(info.st_mode))
        {
           send_ipp_status(con, IPP_NOT_POSSIBLE,
                          _("notify-recipient-uri URI \"%s\" uses unknown "
@@ -4816,10 +4813,10 @@ copy_job_attrs(cupsd_client_t *con,     /* I - Client connection */
       ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-k-octets", job->koctets);
 
     if (job->name && (!ra || cupsArrayFind(ra, "job-name")))
-      ippAddString(con->response, IPP_TAG_JOB, IPP_CONST_TAG(IPP_TAG_NAME), "job-name", NULL, job->name);
+      ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL, job->name);
 
     if (job->username && (!ra || cupsArrayFind(ra, "job-originating-user-name")))
-      ippAddString(con->response, IPP_TAG_JOB, IPP_CONST_TAG(IPP_TAG_NAME), "job-originating-user-name", NULL, job->username);
+      ippAddString(con->response, IPP_TAG_JOB, IPP_TAG_NAME, "job-originating-user-name", NULL, job->username);
 
     if (!ra || cupsArrayFind(ra, "job-state"))
       ippAddInteger(con->response, IPP_TAG_JOB, IPP_TAG_ENUM, "job-state", (int)job->state_value);
@@ -4945,9 +4942,9 @@ copy_printer_attrs(
     };
 
     if (printer->type & CUPS_PRINTER_CLASS)
-      ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY, "printer-error-policy-supported", NULL, "retry-current-job");
+      ippAddString(con->response, IPP_TAG_PRINTER, IPP_CONST_TAG(IPP_TAG_NAME), "printer-error-policy-supported", NULL, "retry-current-job");
     else
-      ippAddStrings(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME | IPP_TAG_COPY, "printer-error-policy-supported", sizeof(errors) / sizeof(errors[0]), NULL, errors);
+      ippAddStrings(con->response, IPP_TAG_PRINTER, IPP_CONST_TAG(IPP_TAG_NAME), "printer-error-policy-supported", sizeof(errors) / sizeof(errors[0]), NULL, errors);
   }
 
   if (!ra || cupsArrayFind(ra, "printer-icons"))
@@ -5082,9 +5079,7 @@ copy_subscription_attrs(
        * Simple event list...
        */
 
-       ippAddString(con->response, IPP_TAG_SUBSCRIPTION,
-                    (ipp_tag_t)(IPP_TAG_KEYWORD | IPP_TAG_COPY),
-                    "notify-events", NULL, name);
+       ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_CONST_TAG(IPP_TAG_KEYWORD), "notify-events", NULL, name);
       }
       else
       {
@@ -5096,15 +5091,12 @@ copy_subscription_attrs(
          if (sub->mask & mask)
            count ++;
 
-       attr = ippAddStrings(con->response, IPP_TAG_SUBSCRIPTION,
-                            (ipp_tag_t)(IPP_TAG_KEYWORD | IPP_TAG_COPY),
-                            "notify-events", count, NULL, NULL);
+       attr = ippAddStrings(con->response, IPP_TAG_SUBSCRIPTION, IPP_CONST_TAG(IPP_TAG_KEYWORD), "notify-events", count, NULL, NULL);
 
        for (mask = 1, count = 0; mask < CUPSD_EVENT_ALL; mask <<= 1)
          if (sub->mask & mask)
          {
-           attr->values[count].string.text =
-               (char *)cupsdEventName((cupsd_eventmask_t)mask);
+           attr->values[count].string.text = (char *)cupsdEventName((cupsd_eventmask_t)mask);
 
            count ++;
          }
@@ -5758,7 +5750,7 @@ create_subscriptions(
 
         snprintf(notifier, sizeof(notifier), "%s/notifier/%s", ServerBin,
                 scheme);
-        if (access(notifier, X_OK))
+        if (access(notifier, X_OK) || !strcmp(scheme, ".") || !strcmp(scheme, ".."))
        {
           send_ipp_status(con, IPP_NOT_POSSIBLE,
                          _("notify-recipient-uri URI \"%s\" uses unknown "
@@ -5856,7 +5848,7 @@ create_subscriptions(
       {
         char   temp[64];               /* Temporary string */
 
-       memcpy(temp, user_data->values[0].unknown.data, user_data->values[0].unknown.length);
+       memcpy(temp, user_data->values[0].unknown.data, (size_t)user_data->values[0].unknown.length);
        temp[user_data->values[0].unknown.length] = '\0';
 
        if (httpSeparateURI(HTTP_URI_CODING_ALL, temp, scheme, sizeof(scheme), userpass, sizeof(userpass), host, sizeof(host), &port, resource, sizeof(resource)) < HTTP_URI_OK)