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

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