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

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