Blame SOURCES/cups-substitute-bad-attrs.patch

1d75c0
diff -up cups-2.2.7/scheduler/ipp.c.substitute-bad-attrs cups-2.2.7/scheduler/ipp.c
1d75c0
--- cups-2.2.7/scheduler/ipp.c.substitute-bad-attrs	2018-04-03 15:55:45.974344993 +0200
1d75c0
+++ cups-2.2.7/scheduler/ipp.c	2018-04-03 16:15:06.723859881 +0200
1d75c0
@@ -164,6 +164,7 @@ cupsdProcessIPPRequest(
1d75c0
   ipp_attribute_t	*uri = NULL;	/* Printer or job URI attribute */
1d75c0
   ipp_attribute_t	*username;	/* requesting-user-name attr */
1d75c0
   int			sub_id;		/* Subscription ID */
1d75c0
+  int			valid = 1;	/* Valid request? */
1d75c0
 
1d75c0
 
1d75c0
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdProcessIPPRequest(%p[%d]): operation_id=%04x(%s)", con, con->number, con->request->request.op.operation_id, ippOpString(con->request->request.op.operation_id));
1d75c0
@@ -423,20 +424,55 @@ cupsdProcessIPPRequest(
1d75c0
       else
1d75c0
       {
1d75c0
        /*
1d75c0
-	* OK, all the checks pass so far; make sure requesting-user-name is
1d75c0
-	* not "root" from a remote host...
1d75c0
+	* OK, all the checks pass so far; validate "requesting-user-name"
1d75c0
+	* attribute value...
1d75c0
 	*/
1d75c0
 
1d75c0
-        if ((username = ippFindAttribute(con->request, "requesting-user-name",
1d75c0
-	                                 IPP_TAG_NAME)) != NULL)
1d75c0
-	{
1d75c0
-	 /*
1d75c0
-	  * Check for root user...
1d75c0
-	  */
1d75c0
-
1d75c0
-	  if (!strcmp(username->values[0].string.text, "root") &&
1d75c0
-	      _cups_strcasecmp(con->http->hostname, "localhost") &&
1d75c0
-	      strcmp(con->username, "root"))
1d75c0
+        if ((username = ippFindAttribute(con->request, "requesting-user-name", IPP_TAG_ZERO)) != NULL)
1d75c0
+        {
1d75c0
+         /*
1d75c0
+          * Validate "requesting-user-name"...
1d75c0
+          */
1d75c0
+
1d75c0
+          if (username->group_tag != IPP_TAG_OPERATION && StrictConformance)
1d75c0
+          {
1d75c0
+	    cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, "%04X %s \"requesting-user-name\" attribute in wrong group.", IPP_STATUS_ERROR_BAD_REQUEST, con->http->hostname);
1d75c0
+	    send_ipp_status(con, IPP_STATUS_ERROR_BAD_REQUEST, _("\"requesting-user-name\" attribute in wrong group."));
1d75c0
+	    valid = 0;
1d75c0
+          }
1d75c0
+          else if (username->value_tag != IPP_TAG_NAME && username->value_tag != IPP_TAG_NAMELANG)
1d75c0
+          {
1d75c0
+	    cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, "%04X %s \"requesting-user-name\" attribute with wrong syntax.", IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES, con->http->hostname);
1d75c0
+	    send_ipp_status(con, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES, _("\"requesting-user-name\" attribute with wrong syntax."));
1d75c0
+	    if ((attr = ippCopyAttribute(con->response, username, 0)) != NULL)
1d75c0
+	      attr->group_tag = IPP_TAG_UNSUPPORTED_GROUP;
1d75c0
+	    valid = 0;
1d75c0
+          }
1d75c0
+          else if (!ippValidateAttribute(username))
1d75c0
+          {
1d75c0
+	    cupsdAddEvent(CUPSD_EVENT_SERVER_AUDIT, NULL, NULL, "%04X %s \"requesting-user-name\" attribute with bad value.", IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES, con->http->hostname);
1d75c0
+
1d75c0
+            if (StrictConformance)
1d75c0
+            {
1d75c0
+             /*
1d75c0
+              * Throw an error...
1d75c0
+              */
1d75c0
+
1d75c0
+	      send_ipp_status(con, IPP_STATUS_ERROR_ATTRIBUTES_OR_VALUES, _("\"requesting-user-name\" attribute with wrong syntax."));
1d75c0
+              if ((attr = ippCopyAttribute(con->response, username, 0)) != NULL)
1d75c0
+                attr->group_tag = IPP_TAG_UNSUPPORTED_GROUP;
1d75c0
+	      valid = 0;
1d75c0
+	    }
1d75c0
+	    else
1d75c0
+	    {
1d75c0
+	     /*
1d75c0
+	      * Map bad "requesting-user-name" to 'anonymous'...
1d75c0
+	      */
1d75c0
+
1d75c0
+              ippSetString(con->request, &username, 0, "anonymous");
1d75c0
+	    }
1d75c0
+          }
1d75c0
+          else if (!strcmp(username->values[0].string.text, "root") && _cups_strcasecmp(con->http->hostname, "localhost") && strcmp(con->username, "root"))
1d75c0
 	  {
1d75c0
 	   /*
1d75c0
 	    * Remote unauthenticated user masquerading as local root...
1d75c0
@@ -452,6 +488,8 @@ cupsdProcessIPPRequest(
1d75c0
 	else
1d75c0
 	  sub_id = 0;
1d75c0
 
1d75c0
+        if (valid)
1d75c0
+        {
1d75c0
        /*
1d75c0
         * Then try processing the operation...
1d75c0
 	*/
1d75c0
@@ -655,6 +693,7 @@ cupsdProcessIPPRequest(
1d75c0
 			      ippOpString(
1d75c0
 			          con->request->request.op.operation_id));
1d75c0
 	      break;
1d75c0
+        }
1d75c0
 	}
1d75c0
       }
1d75c0
     }
1d75c0
@@ -1615,27 +1654,34 @@ add_job(cupsd_client_t  *con,		/* I - Cl
1d75c0
                     _("Bad job-name value: Wrong type or count."));
1d75c0
     if ((attr = ippCopyAttribute(con->response, attr, 0)) != NULL)
1d75c0
       attr->group_tag = IPP_TAG_UNSUPPORTED_GROUP;
1d75c0
-    return (NULL);
1d75c0
+
1d75c0
+    if (StrictConformance)
1d75c0
+      return (NULL);
1d75c0
+
1d75c0
+    /* Don't use invalid attribute */
1d75c0
+    ippDeleteAttribute(con->request, attr);
1d75c0
+
1d75c0
+    ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL, "Untitled");
1d75c0
   }
1d75c0
   else if (!ippValidateAttribute(attr))
1d75c0
   {
1d75c0
     send_ipp_status(con, IPP_ATTRIBUTES, _("Bad job-name value: %s"),
1d75c0
                     cupsLastErrorString());
1d75c0
+
1d75c0
     if ((attr = ippCopyAttribute(con->response, attr, 0)) != NULL)
1d75c0
       attr->group_tag = IPP_TAG_UNSUPPORTED_GROUP;
1d75c0
-    return (NULL);
1d75c0
-  }
1d75c0
 
1d75c0
-  attr = ippFindAttribute(con->request, "requesting-user-name", IPP_TAG_NAME);
1d75c0
+    if (StrictConformance)
1d75c0
+      return (NULL);
1d75c0
 
1d75c0
-  if (attr && !ippValidateAttribute(attr))
1d75c0
-  {
1d75c0
-    send_ipp_status(con, IPP_ATTRIBUTES, _("Bad requesting-user-name value: %s"), cupsLastErrorString());
1d75c0
-    if ((attr = ippCopyAttribute(con->response, attr, 0)) != NULL)
1d75c0
-      attr->group_tag = IPP_TAG_UNSUPPORTED_GROUP;
1d75c0
-    return (NULL);
1d75c0
+    /* Don't use invalid attribute */
1d75c0
+    ippDeleteAttribute(con->request, attr);
1d75c0
+
1d75c0
+    ippAddString(con->request, IPP_TAG_JOB, IPP_TAG_NAME, "job-name", NULL, "Untitled");
1d75c0
   }
1d75c0
 
1d75c0
+  attr = ippFindAttribute(con->request, "requesting-user-name", IPP_TAG_NAME);
1d75c0
+
1d75c0
 #ifdef WITH_LSPP
1d75c0
   if (is_lspp_config())
1d75c0
   {