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