]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
ippfind fixes:
authormsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Tue, 26 Aug 2014 15:36:07 +0000 (15:36 +0000)
committermsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Tue, 26 Aug 2014 15:36:07 +0000 (15:36 +0000)
- Fix a bug with '{name}' substitution in ippfind.
- Fix a bug with --txt-name option handling in ippfind.
- Add some more debugging output to ippfind when IPPFIND_DEBUG env var is set.

ippserver fixes:

- Include TLS and UUID keys in TXT record.
- Implement HTTP Upgrade to TLS.

IPP Everywhere test file fixes:

- Separate access and value tests, confusing.
- Fix some of the tests to work properly (cut/paste errors)

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@12118 a1ca3aef-8c08-0410-bb20-df032aa958be

everywhere/bonjour-access-tests.test [new file with mode: 0644]
everywhere/bonjour-tests.sh
everywhere/bonjour-value-tests.test [moved from everywhere/bonjour-tests.test with 74% similarity]
test/ippfind.c
test/ippserver.c

diff --git a/everywhere/bonjour-access-tests.test b/everywhere/bonjour-access-tests.test
new file mode 100644 (file)
index 0000000..b1fcea6
--- /dev/null
@@ -0,0 +1,42 @@
+#
+# "$Id$"
+#
+# IPP Everywhere Printer Self-Certification Manual 1.0: Section 5: Bonjour Tests.
+#
+# Copyright 2014 by The Printer Working Group.
+# Copyright 2007-2013 by Apple Inc.
+# Copyright 2001-2006 by Easy Software Products. All rights reserved.
+#
+# These coded instructions, statements, and computer programs are the
+# property of Apple Inc. and are protected by Federal copyright
+# law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+# which should have been included with this file.  If this file is
+# file is missing or damaged, see the license at "http://www.cups.org/".
+#
+# Usage:
+#
+#   ./ipptool -tI printer-uri bonjour-access-tests.test
+#
+
+FILE-ID "org.pwg.ipp-everywhere.bonjour-20140825"
+
+{
+       # The name of the test...
+       NAME "Validate access using Get-Printer-Attributes"
+
+       # The operation to use
+       OPERATION Get-Printer-Attributes
+
+       # Attributes, starting in the operation group...
+       GROUP operation-attributes-tag
+       ATTR charset attributes-charset utf-8
+       ATTR language attributes-natural-language en
+       ATTR uri printer-uri $uri
+
+       # What statuses are OK?
+       STATUS successful-ok
+}
+
+#
+# End of "$Id$".
+#
index 91ce766c284624bf8d1314f6ba9533ae66ddb5f6..ad938d1cd73e410375748064e34f90f49f8cf335 100755 (executable)
@@ -121,8 +121,8 @@ if test "$2" = _fail2 -o "$2" = _fail4 -o "$2" = _fail5.3 -o "$2" = _fail5.5; th
        fi
 
        if test "$2" = _fail4 -o "$2" = _fail5.5; then
-               $IPPTOOL -t -d "ADMINURL=$IPPFIND_TXT_ADMINURL" -d "UUID=$IPPFIND_TXT_UUID" $IPPFIND_SERVICE_URI bonjour-tests.test
-               $IPPTOOL -t -d "ADMINURL=$IPPFIND_TXT_ADMINURL" -d "UUID=$IPPFIND_TXT_UUID" $IPPFIND_SERVICE_URI bonjour-tests.test | egrep '(GOT|EXPECTED):' | sed -e '1,$s/^[         ]*//' | awk '{print "<string>" $0 "</string>" }' >>"$PLIST"
+               $IPPTOOL -t -d "ADMINURL=$IPPFIND_TXT_ADMINURL" -d "UUID=$IPPFIND_TXT_UUID" $IPPFIND_SERVICE_URI bonjour-value-tests.test
+               $IPPTOOL -t -d "ADMINURL=$IPPFIND_TXT_ADMINURL" -d "UUID=$IPPFIND_TXT_UUID" $IPPFIND_SERVICE_URI bonjour-value-tests.test | egrep '(GOT|EXPECTED):' | sed -e '1,$s/^[   ]*//' | awk '{print "<string>" $0 "</string>" }' >>"$PLIST"
        fi
 
        echo "</array>" >>"$PLIST"
@@ -203,7 +203,7 @@ fi
 
 # B-4. IPP TXT values test: The IPP TXT record values match the reported IPP attribute values.
 start_test "B-4. IPP TXT values test"
-$IPPFIND "$1._ipp._tcp.local." --txt-adminurl '^(http:|https:)//' --txt-pdl 'image/pwg-raster' --txt-pdl 'image/jpeg' --txt-rp '^ipp/(print|print/[^/]+)$' --txt-UUID '^[0-9a-fA-F]{8,8}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{12,12}$' -x $IPPTOOL -q -d 'ADMINURL={txt_adminurl}' -d 'UUID={txt_uuid}' '{}' bonjour-tests.test \;
+$IPPFIND "$1._ipp._tcp.local." --txt-adminurl '^(http:|https:)//' --txt-pdl 'image/pwg-raster' --txt-pdl 'image/jpeg' --txt-rp '^ipp/(print|print/[^/]+)$' --txt-UUID '^[0-9a-fA-F]{8,8}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{12,12}$' -x $IPPTOOL -q -d 'ADMINURL={txt_adminurl}' -d 'UUID={txt_uuid}' '{}' bonjour-value-tests.test \;
 if test $? = 0; then
        pass=`expr $pass + 1`
        end_test PASS
@@ -228,13 +228,16 @@ fi
 # B-5.1 HTTP Upgrade test: Printer responds to an IPP Get-Printer-Attributes request after doing an HTTP Upgrade to TLS.
 start_test "B-5.1 HTTP Upgrade test"
 if test $HAVE_TLS = 1; then
-       $IPPFIND "$1._ipp._tcp.local." -x $IPPTOOL -E -q -d NO_VALUE_TESTS '{}' bonjour-tests.test \;
+       error=`$IPPFIND "$1._ipp._tcp.local." -x $IPPTOOL -E -q '{}' bonjour-access-tests.test \; 2>&1`
        if test $? = 0; then
                pass=`expr $pass + 1`
                end_test PASS
        else
                fail=`expr $fail + 1`
+               echo "<key>Errors</key><array><string>$error</string></array>" >>"$PLIST"
+
                end_test FAIL
+               echo "    $error"
        fi
 else
        skip=`expr $skip + 1`
@@ -295,7 +298,7 @@ fi
 # B-5.5 IPPS TXT values test: The TXT record values for IPPS match the reported IPPS attribute values.
 start_test "B-5.5 IPPS TXT values test"
 if test $HAVE_TLS = 1; then
-       $IPPFIND "$1._ipps._tcp.local." --txt-adminurl '^(http:|https:)//' --txt-pdl 'image/pwg-raster' --txt-pdl 'image/jpeg' --txt-rp '^ipp/(print|print/[^/]+)$' --txt-UUID '^[0-9a-fA-F]{8,8}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{12,12}$' -x $IPPTOOL -q -d 'ADMINURL={txt_adminurl}' -d 'UUID={txt_uuid}' '{}' bonjour-tests.test \;
+       $IPPFIND "$1._ipps._tcp.local." --txt-adminurl '^(http:|https:)//' --txt-pdl 'image/pwg-raster' --txt-pdl 'image/jpeg' --txt-rp '^ipp/(print|print/[^/]+)$' --txt-UUID '^[0-9a-fA-F]{8,8}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{4,4}-[0-9a-fA-F]{12,12}$' -x $IPPTOOL -q -d 'ADMINURL={txt_adminurl}' -d 'UUID={txt_uuid}' '{}' bonjour-value-tests.test \;
        if test $? = 0; then
                pass=`expr $pass + 1`
                end_test PASS
similarity index 74%
rename from everywhere/bonjour-tests.test
rename to everywhere/bonjour-value-tests.test
index 1ac8448e186ba9c4451e273d59ea0996d1d68aac..53470d09ceeef8098e838e3af7607c20834025ed 100644 (file)
 #
 # Usage:
 #
-#   ./ipptool -tI printer-uri -d ADMINURL=url -d UUID=uuid bonjour-tests.test
+#   ./ipptool -tI printer-uri -d ADMINURL=url -d UUID=uuid bonjour-value-tests.test
 #
 
 FILE-ID "org.pwg.ipp-everywhere.bonjour-20140825"
 
 {
-       SKIP-IF-DEFINED NO_VALUE_TESTS
-
        # The name of the test...
        NAME "Validate TXT record values using Get-Printer-Attributes"
 
@@ -43,25 +41,6 @@ FILE-ID "org.pwg.ipp-everywhere.bonjour-20140825"
        EXPECT printer-uuid OF-TYPE uri IN-GROUP printer-attributes-tag COUNT 1 WITH-VALUE "urn:uuid:$UUID"
 }
 
-{
-       SKIP-IF-NOT-DEFINED NO_VALUE_TESTS
-
-       # The name of the test...
-       NAME "Validate Get-Printer-Attributes after HTTP Upgrade"
-
-       # The operation to use
-       OPERATION Get-Printer-Attributes
-
-       # Attributes, starting in the operation group...
-       GROUP operation-attributes-tag
-       ATTR charset attributes-charset utf-8
-       ATTR language attributes-natural-language en
-       ATTR uri printer-uri $uri
-
-       # What statuses are OK?
-       STATUS successful-ok
-}
-
 #
 # End of "$Id$".
 #
index 9c5cfc68941edb4f237b4fab4a925100e8bb76be..fd1606b14e4c429ae794f52211d38b7035ccfb4d 100644 (file)
@@ -603,9 +603,9 @@ main(int  argc,                             /* I - Number of command-line args */
                                NULL)) == NULL)
             return (IPPFIND_EXIT_MEMORY);
         }
-        else if (!strncmp(argv[i], "--txt-", 5))
+        else if (!strncmp(argv[i], "--txt-", 6))
         {
-          const char *key = argv[i] + 5;/* TXT key */
+          const char *key = argv[i] + 6;/* TXT key */
 
           i ++;
           if (i >= argc)
@@ -1803,6 +1803,9 @@ eval_expr(ippfind_srv_t  *service,        /* I - Service */
            result = !regexec(&(expression->re), val, 0, NULL, 0);
          else
            result = 0;
+
+         if (getenv("IPPFIND_DEBUG"))
+           printf("TXT_REGEX of \"%s\": %d\n", val, result);
           break;
       case IPPFIND_OP_URI_REGEX :
           result = !regexec(&(expression->re), service->uri, 0, NULL, 0);
@@ -1976,9 +1979,9 @@ exec_program(ippfind_srv_t *service,      /* I - Service */
            strlcpy(tptr, scheme + 22, sizeof(temp) - (size_t)(tptr - temp));
          else if (!strncmp(keyword, "txt_", 4))
          {
-           if ((ptr = (char *)cupsGetOption(keyword + 4, service->num_txt,
-                                            service->txt)) != NULL)
-             strlcpy(tptr, strdup(ptr), sizeof(temp) - (size_t)(tptr - temp));
+           const char *txt = cupsGetOption(keyword + 4, service->num_txt, service->txt);
+           if (txt)
+             strlcpy(tptr, txt, sizeof(temp) - (size_t)(tptr - temp));
            else
              *tptr = '\0';
          }
@@ -2070,6 +2073,14 @@ exec_program(ippfind_srv_t *service,     /* I - Service */
   * Return whether the program succeeded or crashed...
   */
 
+  if (getenv("IPPFIND_DEBUG"))
+  {
+    if (WIFEXITED(status))
+      printf("Exit Status: %d\n", WEXITSTATUS(status));
+    else
+      printf("Terminating Signal: %d\n", WTERMSIG(status));
+  }
+
   return (status == 0);
 }
 
index 41fed5f873cff088a844785c6134ae31d679e650..42230befbf1a8961b9bbe53862d17114ae032199 100644 (file)
@@ -374,11 +374,7 @@ static int         process_http(_ipp_client_t *client);
 static int             process_ipp(_ipp_client_t *client);
 static void            *process_job(_ipp_job_t *job);
 #ifdef HAVE_DNSSD
-static int             register_printer(_ipp_printer_t *printer,
-                                        const char *location, const char *make,
-                                        const char *model, const char *formats,
-                                        const char *adminurl, int color,
-                                        int duplex, const char *regtype);
+static int             register_printer(_ipp_printer_t *printer, const char *location, const char *make, const char *model, const char *formats, const char *adminurl, const char *uuid, int color, int duplex, const char *regtype);
 #endif /* HAVE_DNSSD */
 static int             respond_http(_ipp_client_t *client, http_status_t code,
                                     const char *content_coding,
@@ -2021,8 +2017,7 @@ create_printer(const char *servername,    /* I - Server hostname (NULL for default)
   * Register the printer with Bonjour...
   */
 
-  if (!register_printer(printer, location, make, model, docformats, adminurl,
-                        ppm_color > 0, duplex, subtype))
+  if (!register_printer(printer, location, make, model, docformats, adminurl, uuid + 9, ppm_color > 0, duplex, subtype))
     goto bad_printer;
 #endif /* HAVE_DNSSD */
 
@@ -4316,13 +4311,15 @@ process_client(_ipp_client_t *client)   /* I - Client */
 
       if (recv(httpGetFd(client->http), buf, 1, MSG_PEEK) == 1 && (!buf[0] || !strchr("DGHOPT", buf[0])))
       {
-        fprintf(stderr, "%s Negotiating TLS session.\n", client->hostname);
+        fprintf(stderr, "%s Starting HTTPS session.\n", client->hostname);
 
        if (httpEncryption(client->http, HTTP_ENCRYPTION_ALWAYS))
        {
          fprintf(stderr, "%s Unable to encrypt connection: %s\n", client->hostname, cupsLastErrorString());
          break;
         }
+
+        fprintf(stderr, "%s Connection now encrypted.\n", client->hostname);
       }
 
       first_time = 0;
@@ -4437,7 +4434,8 @@ process_http(_ipp_client_t *client)       /* I - Client connection */
   if (httpSeparateURI(HTTP_URI_CODING_MOST, uri, scheme, sizeof(scheme),
                      userpass, sizeof(userpass),
                      hostname, sizeof(hostname), &port,
-                     client->uri, sizeof(client->uri)) < HTTP_URI_STATUS_OK)
+                     client->uri, sizeof(client->uri)) < HTTP_URI_STATUS_OK &&
+      (http_state != HTTP_STATE_OPTIONS || strcmp(uri, "*")))
   {
     fprintf(stderr, "%s Bad URI \"%s\".\n", client->hostname, uri);
     respond_http(client, HTTP_STATUS_BAD_REQUEST, NULL, NULL, 0);
@@ -4484,6 +4482,25 @@ process_http(_ipp_client_t *client)      /* I - Client connection */
   if (!strcasecmp(httpGetField(client->http, HTTP_FIELD_CONNECTION),
                         "Upgrade"))
   {
+#ifdef HAVE_SSL
+    if (strstr(httpGetField(client->http, HTTP_FIELD_UPGRADE), "TLS/") != NULL && !httpIsEncrypted(client->http))
+    {
+      if (!respond_http(client, HTTP_STATUS_SWITCHING_PROTOCOLS, NULL, NULL, 0))
+        return (0);
+
+      fprintf(stderr, "%s Upgrading to encrypted connection.\n", client->hostname);
+
+      if (httpEncryption(client->http, HTTP_ENCRYPTION_REQUIRED))
+      {
+        fprintf(stderr, "%s Unable to encrypt connection: %s\n", client->hostname, cupsLastErrorString());
+       return (0);
+      }
+
+      fprintf(stderr, "%s Connection now encrypted.\n", client->hostname);
+    }
+    else
+#endif /* HAVE_SSL */
+
     if (!respond_http(client, HTTP_STATUS_NOT_IMPLEMENTED, NULL, NULL, 0))
       return (0);
   }
@@ -4526,7 +4543,7 @@ process_http(_ipp_client_t *client)       /* I - Client connection */
   {
     case HTTP_STATE_OPTIONS :
        /*
-       * Do HEAD/OPTIONS command...
+       * Do OPTIONS command...
        */
 
        return (respond_http(client, HTTP_STATUS_OK, NULL, NULL, 0));
@@ -5280,6 +5297,7 @@ register_printer(
     const char     *model,             /* I - Model name */
     const char     *formats,           /* I - Supported formats */
     const char     *adminurl,          /* I - Web interface URL */
+    const char     *uuid,              /* I - Printer UUID */
     int            color,              /* I - 1 = color, 0 = monochrome */
     int            duplex,             /* I - 1 = duplex, 0 = simplex */
     const char     *subtype)           /* I - Service subtype */
@@ -5316,6 +5334,10 @@ register_printer(
                     make);
   TXTRecordSetValue(&(printer->ipp_txt), "usb_MDL", (uint8_t)strlen(model),
                     model);
+  TXTRecordSetValue(&(printer->ipp_txt), "UUID", (uint8_t)strlen(uuid), uuid);
+#  ifdef HAVE_SSL
+  TXTRecordSetValue(&(printer->ipp_txt), "TLS", 3, "1.2");
+#  endif /* HAVE_SSL */
 
  /*
   * Create a shared service reference for Bonjour...
@@ -5461,7 +5483,7 @@ respond_http(
   * Format an error message...
   */
 
-  if (!type && !length && code != HTTP_STATUS_OK)
+  if (!type && !length && code != HTTP_STATUS_OK && code != HTTP_STATUS_SWITCHING_PROTOCOLS)
   {
     snprintf(message, sizeof(message), "%d - %s\n", code, httpStatus(code));