The branch, v4-8-test has been updated
       via  bb5cee3 s3:smbspool: Fix cmdline argument handling
       via  4a9c164 smbspool: Improve URI handling code
      from  02b898e s3: libsmbclient: Fix hard-coded connection error return of 
ETIMEDOUT.

https://git.samba.org/?p=samba.git;a=shortlog;h=v4-8-test


- Log -----------------------------------------------------------------
commit bb5cee36b67ca78d29474f6f33fab9372203b925
Author: Andreas Schneider <a...@samba.org>
Date:   Thu May 3 10:17:12 2018 +0200

    s3:smbspool: Fix cmdline argument handling
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13417
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Alexander Bokovoy <a...@samba.org>
    (cherry picked from commit a753ccfd946aaad320977ae8c5f483f73077c3f8)
    
    Autobuild-User(v4-8-test): Karolin Seeger <ksee...@samba.org>
    Autobuild-Date(v4-8-test): Wed May  9 14:22:22 CEST 2018 on sn-devel-144

commit 4a9c164d0abfa30db3f943d1224ca95d87fdf95a
Author: Andreas Schneider <a...@samba.org>
Date:   Fri Jan 5 10:50:57 2018 +0100

    smbspool: Improve URI handling code
    
    This also checks that the URI given via the environment variables
    starts with smb://
    
    Signed-off-by: Andreas Schneider <a...@samba.org>
    Reviewed-by: Alexander Bokovoy <a...@samba.org>
    Reviewed-by: David Disseldorp <dd...@samba.org>
    (cherry picked from commit a6eac8f64989235e7a297c14e349d98a3fc70e47)

-----------------------------------------------------------------------

Summary of changes:
 source3/client/smbspool.c             | 86 +++++++++++++++++++++++------------
 source3/script/tests/test_smbspool.sh | 30 ++++++++++++
 2 files changed, 88 insertions(+), 28 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/client/smbspool.c b/source3/client/smbspool.c
index 3b732c9..d6e944d 100644
--- a/source3/client/smbspool.c
+++ b/source3/client/smbspool.c
@@ -100,6 +100,11 @@ main(int argc,                     /* I - Number of 
command-line arguments */
        const char     *dev_uri;
        const char     *config_file = NULL;
        TALLOC_CTX     *frame = talloc_stackframe();
+       bool device_uri_cmdline = false;
+       const char *print_file = NULL;
+       const char *print_copies = NULL;
+       int cmp;
+       int len;
 
        null_str[0] = '\0';
 
@@ -117,7 +122,12 @@ main(int argc,                     /* I - Number of 
command-line arguments */
                goto done;
        }
 
-       if (argc < 7 || argc > 8) {
+       /*
+        * We need at least 5 options if the DEVICE_URI is passed via an env
+        * variable and printing data comes via stdin.
+        * We don't accept more than 7 options in total, including optional.
+        */
+       if (argc < 5 || argc > 8) {
                fprintf(stderr,
 "Usage: %s [DEVICE_URI] job-id user title copies options [file]\n"
 "       The DEVICE_URI environment variable can also contain the\n"
@@ -129,46 +139,66 @@ main(int argc,                    /* I - Number of 
command-line arguments */
        }
 
        /*
-         * If we have 7 arguments, print the file named on the command-line.
-         * Otherwise, print data from stdin...
-         */
-
+        * If we have 6 arguments find out if we have the device_uri from the
+        * command line or the print data
+        */
        if (argc == 7) {
-               /*
-                * Print from Copy stdin to a temporary file...
-                */
+               cmp = strncmp(argv[1], "smb://", 6);
+               if (cmp == 0) {
+                       device_uri_cmdline = true;
+               } else {
+                       print_copies = argv[4];
+                       print_file = argv[6];
+               }
+       } else if (argc == 8) {
+               device_uri_cmdline = true;
+               print_copies = argv[5];
+               print_file = argv[7];
+       }
 
-               fp = stdin;
-               copies = 1;
-       } else if ((fp = fopen(argv[7], "rb")) == NULL) {
-               perror("ERROR: Unable to open print file");
-               goto done;
-       } else {
-               char *p = argv[5];
+       if (print_file != NULL) {
                char *endp;
 
-               copies = strtol(p, &endp, 10);
-               if (p == endp) {
+               fp = fopen(print_file, "rb");
+               if (fp == NULL) {
+                       perror("ERROR: Unable to open print file");
+                       goto done;
+               }
+
+               copies = strtol(print_copies, &endp, 10);
+               if (print_copies == endp) {
                        perror("ERROR: Unable to determine number of copies");
                        goto done;
                }
+       } else {
+               fp = stdin;
+               copies = 1;
        }
 
        /*
-         * Find the URI...
-         */
-
-       dev_uri = getenv("DEVICE_URI");
-       if (dev_uri) {
-               strncpy(uri, dev_uri, sizeof(uri) - 1);
-       } else if (strncmp(argv[1], "smb://", 6) == 0) {
-               strncpy(uri, argv[1], sizeof(uri) - 1);
+        * Find the URI ...
+        */
+       if (device_uri_cmdline) {
+               dev_uri = argv[1];
        } else {
-               fputs("ERROR: No device URI found in DEVICE_URI environment 
variable or arg1 !\n", stderr);
-               goto done;
+               dev_uri = getenv("DEVICE_URI");
+               if (dev_uri == NULL || strlen(dev_uri) == 0) {
+                       dev_uri = "";
+               }
        }
 
-       uri[sizeof(uri) - 1] = '\0';
+       cmp = strncmp(dev_uri, "smb://", 6);
+       if (cmp != 0) {
+               fprintf(stderr,
+                       "ERROR: No valid device URI has been specified\n");
+               goto done;
+       }
+       len = snprintf(uri, sizeof(uri), "%s", dev_uri);
+       if (len >= sizeof(uri)) {
+               fprintf(stderr,
+                       "ERROR: The URI is too long.\n");
+               goto done;
+       }
 
        /*
          * Extract the destination from the URI...
diff --git a/source3/script/tests/test_smbspool.sh 
b/source3/script/tests/test_smbspool.sh
index 8f9426f..899b34d 100755
--- a/source3/script/tests/test_smbspool.sh
+++ b/source3/script/tests/test_smbspool.sh
@@ -139,6 +139,36 @@ testit "vlp verify example.ps" \
        test_vlp_verify \
        || failed=$(expr $failed + 1)
 
+testit "smbspool print example.ps via stdin" \
+       $samba_smbspool smb://$USERNAME:$PASSWORD@$SERVER_IP/print1 200 
$USERNAME "Testprint" 1 "options" < $SRCDIR/testdata/printing/example.ps || \
+       failed=$(expr $failed + 1)
+
+testit "vlp verify example.ps" \
+       test_vlp_verify \
+       || failed=$(expr $failed + 1)
+
+DEVICE_URI="smb://$USERNAME:$PASSWORD@$SERVER_IP/print1"
+export DEVICE_URI
+testit "smbspool print DEVICE_URI example.ps" \
+       $samba_smbspool 200 $USERNAME "Testprint" 1 "options" 
$SRCDIR/testdata/printing/example.ps || \
+       failed=$(expr $failed + 1)
+unset DEVICE_URI
+
+testit "vlp verify example.ps" \
+       test_vlp_verify \
+       || failed=$(expr $failed + 1)
+
+DEVICE_URI="smb://$USERNAME:$PASSWORD@$SERVER_IP/print1"
+export DEVICE_URI
+testit "smbspool print DEVICE_URI example.ps via stdin" \
+       $samba_smbspool 200 $USERNAME "Testprint" 1 "options" < 
$SRCDIR/testdata/printing/example.ps || \
+       failed=$(expr $failed + 1)
+unset DEVICE_URI
+
+testit "vlp verify example.ps" \
+       test_vlp_verify \
+       || failed=$(expr $failed + 1)
+
 AUTH_INFO_REQUIRED="username,password"
 export AUTH_INFO_REQUIRED
 testit "smbspool_krb5(username,password) print example.ps" \


-- 
Samba Shared Repository

Reply via email to