[SCM] Samba Shared Repository - branch v4-9-test updated

Karolin Seeger kseeger at samba.org
Fri Mar 22 13:40:04 UTC 2019


The branch, v4-9-test has been updated
       via  b861e5e91f5 s4:librpc: Fix installation of Samba
       via  5f94bc518cc ctdb-tests: Add some testing for IPv4-mapped IPv6 address parsing
       via  eb4e66cd0ff ctdb: Initialize addr struct to zero before reparsing as IPV4
       via  9e4b17aaaba ctdb-packaging: Test package requires tcpdump
       via  6e76e884f5e ctdb-packaging: ctdb package should not own system library directory
       via  7f4492c7f5b s3:client: Fix smbspool device uri handling
       via  e07b8444f53 s3:client: Make sure we work on a copy of the title
       via  590fd475878 s3:client: Evaluate the AUTH_INFO_REQUIRED variable set by cups
       via  d311eff5aa4 s3:client: Pass DEVICE_URI and AUTH_INFO_REQUIRED env to smbspool
       via  6c2d5bca41e s3:script: Fix jobid check in test_smbspool.sh
       via  166dd92d249 ndr_spoolss_buf: fix out of scope use of stack variable in NDR_SPOOLSS_PUSH_ENUM_OUT()
       via  1e40887120d Send status to systemd on daemon start
      from  fc40f87ebbc lib:util: Move debug message for mkdir failing to log level 1

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


- Log -----------------------------------------------------------------
commit b861e5e91f54057194b8cd9f9c2eb28ccd6d6c3d
Author: Andreas Schneider <asn at samba.org>
Date:   Wed Mar 20 11:09:21 2019 +0100

    s4:librpc: Fix installation of Samba
    
    This breaks installation of Samba 4.10 on Fedora.
    
    https://bugzilla.samba.org/show_bug.cgi?id=13847
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>
    
    (cherry picked from commit bf469343f577e2d78df0e38d80e7976b351eaf0d)
    
    Autobuild-User(v4-9-test): Karolin Seeger <kseeger at samba.org>
    Autobuild-Date(v4-9-test): Fri Mar 22 13:39:46 UTC 2019 on sn-devel-144

commit 5f94bc518cc2ae8dfc24f4c9695580017ed8e0a5
Author: Martin Schwenke <martin at meltin.net>
Date:   Thu Mar 14 16:32:02 2019 +1100

    ctdb-tests: Add some testing for IPv4-mapped IPv6 address parsing
    
    ctdb_sock_addr values are hashed in some contexts.  This means that
    all of the memory used for the ctdb_sock_addr should be consistent
    regardless of how parsing is done.  The first 2 cases are just sanity
    checks but the 3rd case involving an IPv4-mapped IPv6 address is the
    real target of this test addition.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13839
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at samba.org>
    (cherry picked from commit d9286701cd9253bf3b42cac3d850ae8c23743e6d)

commit eb4e66cd0ffbe6e0463fb9c0f4a19d26fc4f338f
Author: Zhu Shangzhong <zhu.shangzhong at zte.com.cn>
Date:   Tue Mar 12 20:49:48 2019 +0800

    ctdb: Initialize addr struct to zero before reparsing as IPV4
    
    Failed to kill the tcp connection that using IPv4-mapped IPv6 address
    (e.g. ctdb_killtcp eth0 ::ffff:192.168.200.44:2049
    ::ffff:192.168.200.45:863).
    
    When the ctdb_killtcp is used to kill the tcp connection, the IPs and
    ports in the connection will be parsed to conn.client and conn.server
    (call stack: main->ctdb_sock_addr_from_string->ip_from_string). In
    the ip_from_string, as we are using IPv4-mapped IPv6 addresses, the
    ipv6_from_string will be used to parse ip to addr.ip6 first. The next
    step the ipv4_from_string will be used to reparse ip to addr.ip.
    
    As a result, the data that dump from conn.server is "2 0 8 1 192 168
    200 44 0 0 0 0 0 0 0 0 0 0 255 255 192 168 200 44 0 0 0 0", the data
    from conn.client is "2 0 3 95 192 168 200 45 0 0 0 0 0 0 0 0 0 0 255 255
    192 168 200 45 0 0 0 0". The connection will be add to conn_list by
    ctdb_connection_list_add. Then the reset_connections_send uses conn_list
    as parameter to start to reset connections in the conn_list.
    
    In the reset_connections_send, the database "connections" will be
    created. The connections from conn_list will be written to the
    database(call db_hash_add), and use the data that dump from conn_client
    and conn_server as key.
    
    In the reset_connections_capture_tcp_handler, the
    ctdb_sys_read_tcp_packet will receive data on the raw socket. And
    extract the IPs and ports from the tcp packet. when extracting IP and
    port, the tcp4_extract OR tcp6_extract will be used. Then we got the
    new conn.client and conn.server. the data that dump from the
    conn.server is "2 0 8 1 192 168 200 44 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 0 0", the data from conn.client is "2 0 3 95 192 168 200 45 0 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0". Finally, we use the data as key to check
    if this connection is one being reset(call db_hash_delete). The
    db_hash_delete will return ENOENT. Because the two key that being used
    by db_hash_delete and db_hash_add are different.
    
    So, the TCP RST will be NOT sent for the connection forever. We should
    initialize addr struct to zero before reparsing as IPV4 in the
    ip_from_string.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13839
    
    Signed-off-by: Zhu Shangzhong <zhu.shangzhong at zte.com.cn>
    Reviewed-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at samba.org>
    (cherry picked from commit 539b5ff32b32b7c75dfaaa119e41f5af6ff1e6fc)

commit 9e4b17aaaba277ba3ab916165c3709b7ab13e8cf
Author: Martin Schwenke <martin at meltin.net>
Date:   Wed Mar 6 19:16:55 2019 +1100

    ctdb-packaging: Test package requires tcpdump
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13838
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at samba.org>
    (cherry picked from commit 957c38b65ca060eabe1e676f8dfb54839d706155)

commit 6e76e884f5e4228e386f2830d3aa9af4bff3f7d2
Author: Martin Schwenke <martin at meltin.net>
Date:   Wed Mar 6 14:36:01 2019 +1100

    ctdb-packaging: ctdb package should not own system library directory
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13838
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at samba.org>
    (cherry picked from commit b2b8dce4fc56c27ef0131104b316346565369dd7)

commit 7f4492c7f5b3daf41fddcb6778fad7e2e78db0ca
Author: Andreas Schneider <asn at samba.org>
Date:   Tue Mar 12 11:40:30 2019 +0100

    s3:client: Fix smbspool device uri handling
    
    If we are executed as a CUPS backend, argv[0] is set to the device uri.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13832
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Bryan Mason <bmason at redhat.com>
    Signed-off-by: Guenther Deschner <gd at samba.org>
    
    (cherry picked from commit 69d7a496d3bf52eaa10e81132bb61430863fdd8a)

commit e07b8444f53337f89b1641e7fe3553fa74d1f663
Author: Andreas Schneider <asn at samba.org>
Date:   Tue Mar 12 10:09:14 2019 +0100

    s3:client: Make sure we work on a copy of the title
    
    We can't be sure we can write to the input buffer.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13832
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Bryan Mason <bmason at redhat.com>
    Signed-off-by: Guenther Deschner <gd at samba.org>
    (cherry picked from commit 129ae27946318a075e99c9e6d1bacf8963f72282)

commit 590fd475878230420c7f74feed839f15619cc726
Author: Andreas Schneider <asn at samba.org>
Date:   Fri Jan 4 09:21:24 2019 +0100

    s3:client: Evaluate the AUTH_INFO_REQUIRED variable set by cups
    
    This should not switch to username,password if cups has been configured
    to use negotiate (Kerberos authentication).
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13832
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Bryan Mason <bmason at redhat.com>
    Signed-off-by: Guenther Deschner <gd at samba.org>
    (cherry picked from commit 5274b09fbaa5e45cc58f3301818d4e9f6a402845)

commit d311eff5aa43a49a3962776cc876a366238f3275
Author: Andreas Schneider <asn at samba.org>
Date:   Tue Mar 12 09:40:58 2019 +0100

    s3:client: Pass DEVICE_URI and AUTH_INFO_REQUIRED env to smbspool
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13832
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Bryan Mason <bmason at redhat.com>
    Signed-off-by: Guenther Deschner <gd at samba.org>
    (cherry picked from commit 43160184d254a57f87bb2adeba47f48d8539533a)

commit 6c2d5bca41e6cffe7502f4adfa6221ab0625a412
Author: Andreas Schneider <asn at samba.org>
Date:   Tue Mar 12 10:15:05 2019 +0100

    s3:script: Fix jobid check in test_smbspool.sh
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13832
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Bryan Mason <bmason at redhat.com>
    Signed-off-by: Guenther Deschner <gd at samba.org>
    (cherry picked from commit fad5e4eaeb9202c1b63c42ea09254c17c473e33a)

commit 166dd92d24950c8d21bdeff37a4f84a37b5ce244
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Mar 1 15:48:18 2019 +0100

    ndr_spoolss_buf: fix out of scope use of stack variable in NDR_SPOOLSS_PUSH_ENUM_OUT()
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=13818
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: David Disseldorp <ddiss at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Björn Jacke <bjacke at samba.org>
    Reviewed-by: Günther Deschner <gd at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    Reviewed-by: Garming Sam <garming at catalyst.net.nz>
    (cherry picked from commit 6da3664f8a11397fd3fb38e89c2432b8bf321e59)

commit 1e40887120df338d3b865599ff52b5ec176b64f3
Author: Marcos Mello <marcosfrm at gmail.com>
Date:   Fri Nov 30 09:25:07 2018 -0200

    Send status to systemd on daemon start
    
    systemd service files run in no-forking mode (--foreground) since
    8b6f58194da7e849cdb9d20712dff49b17a93a77.
    
    Rearrange sd_notify() call in become_daemon() to only send status to systemd
    in this mode (Type=notify is not designed to monitor forking). Drop READY=0
    (it does nothing) and MAINPID= (unnecessary because the process spawned by
    systemd is already the main PID).
    
    Also remove STATUS= prefix from debug messages.
    
    Signed-off-by: Marcos Mello <marcosfrm at gmail.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    (cherry picked from commit 440ddf8470b11a46066d282bf8945201d547c192)
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=11568

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

Summary of changes:
 ctdb/packaging/RPM/ctdb.spec.in        |   4 +-
 ctdb/protocol/protocol_util.c          |   3 +
 ctdb/tests/src/protocol_util_test.c    |  19 ++++
 lib/util/become_daemon.c               |  18 ++--
 librpc/ndr/ndr_spoolss_buf.c           |   4 +-
 source3/client/smbspool.c              | 160 +++++++++++++++++++++++++--------
 source3/client/smbspool_krb5_wrapper.c |  24 ++++-
 source3/script/tests/test_smbspool.sh  |   4 +-
 source4/librpc/wscript_build           |   8 --
 9 files changed, 180 insertions(+), 64 deletions(-)


Changeset truncated at 500 lines:

diff --git a/ctdb/packaging/RPM/ctdb.spec.in b/ctdb/packaging/RPM/ctdb.spec.in
index 4c9cae486fd..90753d01e72 100644
--- a/ctdb/packaging/RPM/ctdb.spec.in
+++ b/ctdb/packaging/RPM/ctdb.spec.in
@@ -221,7 +221,7 @@ fi
 %{_bindir}/onnode
 %dir %{_libexecdir}/ctdb
 %{_libexecdir}/ctdb/*
-%dir %{_libdir}
+%dir %{_libdir}/ctdb
 %{_libdir}/ctdb/lib*
 %dir %{_datadir}/ctdb/events
 %{_datadir}/ctdb/events/*
@@ -257,7 +257,7 @@ development libraries for ctdb
 Summary: CTDB test suite
 Group: Development/Tools
 Requires: ctdb = %{version}
-Requires: nc
+Requires: nc, tcpdump
 
 %description tests
 test suite for ctdb
diff --git a/ctdb/protocol/protocol_util.c b/ctdb/protocol/protocol_util.c
index a0127a643bc..7edefc6a334 100644
--- a/ctdb/protocol/protocol_util.c
+++ b/ctdb/protocol/protocol_util.c
@@ -251,6 +251,9 @@ static int ip_from_string(const char *str, ctdb_sock_addr *addr)
 		if (memcmp(&addr->ip6.sin6_addr.s6_addr[0],
 			   ipv4_mapped_prefix,
 			   sizeof(ipv4_mapped_prefix)) == 0) {
+                        /* Initialize addr struct to zero before reparsing as IPV4 */
+                        ZERO_STRUCTP(addr);
+
 			/* Reparse as IPv4 */
 			ret = ipv4_from_string(p+1, &addr->ip);
 		}
diff --git a/ctdb/tests/src/protocol_util_test.c b/ctdb/tests/src/protocol_util_test.c
index 5608b13920c..9be95eca2ef 100644
--- a/ctdb/tests/src/protocol_util_test.c
+++ b/ctdb/tests/src/protocol_util_test.c
@@ -52,6 +52,20 @@ static void test_sock_addr_from_string_bad(const char *ip, bool with_port)
 	assert(ret == EINVAL);
 }
 
+static void test_sock_addr_from_string_memcmp(const char *ip1,
+					      const char* ip2)
+{
+	ctdb_sock_addr sa1, sa2;
+	int ret;
+
+	ret = ctdb_sock_addr_from_string(ip1, &sa1, false);
+	assert(ret == 0);
+	ret = ctdb_sock_addr_from_string(ip2, &sa2, false);
+	assert(ret == 0);
+	ret = memcmp(&sa1, &sa2, sizeof(ctdb_sock_addr));
+	assert(ret == 0);
+}
+
 static void test_sock_addr_cmp(const char *ip1, const char *ip2,
 			       bool with_port, int res)
 {
@@ -299,6 +313,11 @@ int main(int argc, char *argv[])
 	test_sock_addr_from_string_bad("junk", false);
 	test_sock_addr_from_string_bad("0.0.0.0:0 trailing junk", true);
 
+	test_sock_addr_from_string_memcmp("127.0.0.1", "127.0.0.1");
+	test_sock_addr_from_string_memcmp("fe80::6af7:28ff:fefa:d136",
+					  "fe80::6af7:28ff:fefa:d136");
+	test_sock_addr_from_string_memcmp("::ffff:192.0.2.128", "192.0.2.128");
+
 	test_sock_addr_cmp("127.0.0.1", "127.0.0.1" , false, 0);
 	test_sock_addr_cmp("127.0.0.1", "127.0.0.2" , false, -1);
 	test_sock_addr_cmp("127.0.0.2", "127.0.0.1" , false, 1);
diff --git a/lib/util/become_daemon.c b/lib/util/become_daemon.c
index 232eda69b64..89991b7981c 100644
--- a/lib/util/become_daemon.c
+++ b/lib/util/become_daemon.c
@@ -73,14 +73,12 @@ void become_daemon(bool do_fork, bool no_session, bool log_stdout)
 			exit_daemon("Fork failed", errno);
 		}
 		if (newpid) {
-#if defined(HAVE_LIBSYSTEMD_DAEMON) || defined(HAVE_LIBSYSTEMD)
-			sd_notifyf(0,
-				   "READY=0\nSTATUS=Starting process...\n"
-				   "MAINPID=%lu",
-				   (unsigned long) newpid);
-#endif /* HAVE_LIBSYSTEMD_DAEMON */
 			_exit(0);
 		}
+#if defined(HAVE_LIBSYSTEMD_DAEMON) || defined(HAVE_LIBSYSTEMD)
+	} else {
+		sd_notify(0, "STATUS=Starting process...");
+#endif
 	}
 
 	/* detach from the terminal */
@@ -120,7 +118,7 @@ void exit_daemon(const char *msg, int error)
 				  msg,
 				  error);
 #endif
-	DBG_ERR("STATUS=daemon failed to start: %s, error code %d\n",
+	DBG_ERR("daemon failed to start: %s, error code %d\n",
 		msg, error);
 	exit(1);
 }
@@ -134,7 +132,7 @@ void daemon_ready(const char *daemon)
 	sd_notifyf(0, "READY=1\nSTATUS=%s: ready to serve connections...",
 		   daemon);
 #endif
-	DBG_ERR("STATUS=daemon '%s' finished starting up and ready to serve "
+	DBG_ERR("daemon '%s' finished starting up and ready to serve "
 		"connections\n", daemon);
 }
 
@@ -144,7 +142,7 @@ void daemon_status(const char *daemon, const char *msg)
 		daemon = "Samba";
 	}
 #if defined(HAVE_LIBSYSTEMD_DAEMON) || defined(HAVE_LIBSYSTEMD)
-	sd_notifyf(0, "\nSTATUS=%s: %s", daemon, msg);
+	sd_notifyf(0, "STATUS=%s: %s", daemon, msg);
 #endif
-	DBG_ERR("STATUS=daemon '%s' : %s\n", daemon, msg);
+	DBG_ERR("daemon '%s' : %s\n", daemon, msg);
 }
diff --git a/librpc/ndr/ndr_spoolss_buf.c b/librpc/ndr/ndr_spoolss_buf.c
index c1d175fcbe5..244d692dca8 100644
--- a/librpc/ndr/ndr_spoolss_buf.c
+++ b/librpc/ndr/ndr_spoolss_buf.c
@@ -43,7 +43,8 @@
 } while(0)
 
 #define NDR_SPOOLSS_PUSH_ENUM_OUT(fn) do { \
-	struct ndr_push *_ndr_info;\
+	DATA_BLOB _data_blob_info = data_blob_null;\
+	struct ndr_push *_ndr_info = NULL;\
 	_r.in.level	= r->in.level;\
 	_r.in.buffer	= r->in.buffer;\
 	_r.in.offered	= r->in.offered;\
@@ -56,7 +57,6 @@
 			"SPOOLSS Buffer: *r->out.info but there's no r->in.buffer");\
 	}\
 	if (r->in.buffer) {\
-		DATA_BLOB _data_blob_info;\
 		_ndr_info = ndr_push_init_ctx(ndr);\
 		NDR_ERR_HAVE_NO_MEMORY(_ndr_info);\
 		_ndr_info->flags= ndr->flags;\
diff --git a/source3/client/smbspool.c b/source3/client/smbspool.c
index 389e4ea553f..97d00bdd011 100644
--- a/source3/client/smbspool.c
+++ b/source3/client/smbspool.c
@@ -60,18 +60,20 @@
  * Local functions...
  */
 
-static int      get_exit_code(struct cli_state * cli, NTSTATUS nt_status, bool use_kerberos);
+static int      get_exit_code(struct cli_state * cli, NTSTATUS nt_status);
 static void     list_devices(void);
 static struct cli_state *smb_complete_connection(const char *, const char *,
 	int, const char *, const char *, const char *, const char *, int, bool *need_auth);
 static struct cli_state *smb_connect(const char *, const char *, int, const
 	char *, const char *, const char *, const char *, bool *need_auth);
-static int      smb_print(struct cli_state *, char *, FILE *);
+static int      smb_print(struct cli_state *, const char *, FILE *);
 static char    *uri_unescape_alloc(const char *);
 #if 0
 static bool     smb_encrypt;
 #endif
 
+static const char *auth_info_required;
+
 /*
  * 'main()' - Main entry for SMB backend.
  */
@@ -97,10 +99,12 @@ main(int argc,			/* I - Number of command-line arguments */
 	char            empty_str[] = "";
 	int             tries = 0;
 	bool		need_auth = true;
-	const char     *dev_uri;
+	const char     *dev_uri = NULL;
+	const char     *env = NULL;
 	const char     *config_file = NULL;
 	TALLOC_CTX     *frame = talloc_stackframe();
-	bool device_uri_cmdline = false;
+	const char *print_user = NULL;
+	const char *print_title = NULL;
 	const char *print_file = NULL;
 	const char *print_copies = NULL;
 	int cmp;
@@ -137,21 +141,81 @@ main(int argc,			/* I - Number of command-line arguments */
 	}
 
 	/*
-	 * If we have 6 arguments find out if we have the device_uri from the
-	 * command line or the print data
+	 * Find out if we have the device_uri in the command line.
+	 *
+	 * If we are started as a CUPS backend argv[0] is normally the
+	 * device_uri!
 	 */
-	if (argc == 7) {
-		cmp = strncmp(argv[1], "smb://", 6);
-		if (cmp == 0) {
-			device_uri_cmdline = true;
+	if (argc == 8) {
+		/*
+		 * smbspool <uri> <job> <user> <title> <copies> <options> <file>
+		 * 0        1     2     3      4       5        6         7
+		 */
+
+		dev_uri = argv[1];
+
+		print_user = argv[3];
+		print_title = argv[4];
+		print_copies = argv[5];
+		print_file = argv[7];
+	} else if (argc == 7) {
+		int cmp1;
+		int cmp2;
+
+		/*
+		 * <uri>    <job> <user> <title> <copies> <options> <file>
+		 * smbspool <uri> <job>  <user>  <title>  <copies>  <options>
+		 * smbspool <job> <user> <title> <copies> <options> <file> | DEVICE_URI
+		 */
+		cmp1 = strncmp(argv[0], "smb://", 6);
+		cmp2 = strncmp(argv[1], "smb://", 6);
+
+		if (cmp1 == 0) {
+			/*
+			 * <uri>    <job> <user> <title> <copies> <options> <file>
+			 * 0        1     2      3       4        5         6
+			 */
+			dev_uri = argv[0];
+
+			print_user = argv[2];
+			print_title = argv[3];
+			print_copies = argv[4];
+			print_file = argv[6];
+		} else if (cmp2 == 0) {
+			/*
+			 * smbspool <uri> <job>  <user>  <title>  <copies>  <options>
+			 * 0        1     2      3       4        5         6
+			 */
+			dev_uri = argv[1];
+
+			print_user = argv[3];
+			print_title = argv[4];
+			print_copies = argv[5];
+			print_file = NULL;
 		} else {
+			/*
+			 * smbspool <job> <user> <title> <copies> <options> <file> | DEVICE_URI
+			 * 0        1     2      3       4        5         6
+			 */
+			print_user = argv[2];
+			print_title = argv[3];
 			print_copies = argv[4];
 			print_file = argv[6];
 		}
-	} else if (argc == 8) {
-		device_uri_cmdline = true;
-		print_copies = argv[5];
-		print_file = argv[7];
+	} else if (argc == 6) {
+		/*
+		 * <uri>    <job> <user> <title> <copies> <options>
+		 * smbspool <job> <user> <title> <copies> <options> | DEVICE_URI
+		 * 0        1     2      3       4        5
+		 */
+		cmp = strncmp(argv[0], "smb://", 6);
+		if (cmp == 0) {
+			dev_uri = argv[0];
+		}
+
+		print_user = argv[2];
+		print_title = argv[3];
+		print_copies = argv[4];
 	}
 
 	if (print_file != NULL) {
@@ -176,15 +240,19 @@ main(int argc,			/* I - Number of command-line arguments */
 	/*
 	 * Find the URI ...
 	 */
-	if (device_uri_cmdline) {
-		dev_uri = argv[1];
-	} else {
-		dev_uri = getenv("DEVICE_URI");
-		if (dev_uri == NULL || strlen(dev_uri) == 0) {
-			dev_uri = "";
+	if (dev_uri == NULL) {
+		env = getenv("DEVICE_URI");
+		if (env != NULL && env[0] != '\0') {
+			dev_uri = env;
 		}
 	}
 
+	if (dev_uri == NULL) {
+		fprintf(stderr,
+			"ERROR: No valid device URI has been specified\n");
+		goto done;
+	}
+
 	cmp = strncmp(dev_uri, "smb://", 6);
 	if (cmp != 0) {
 		fprintf(stderr,
@@ -198,6 +266,11 @@ main(int argc,			/* I - Number of command-line arguments */
 		goto done;
 	}
 
+	auth_info_required = getenv("AUTH_INFO_REQUIRED");
+	if (auth_info_required == NULL) {
+		auth_info_required = "none";
+	}
+
 	/*
          * Extract the destination from the URI...
          */
@@ -233,6 +306,10 @@ main(int argc,			/* I - Number of command-line arguments */
 		server = uri + 6;
 	}
 
+	if (password != empty_str) {
+		auth_info_required = "username,password";
+	}
+
 	tmp = server;
 
 	if ((sep = strchr_m(tmp, '/')) == NULL) {
@@ -290,8 +367,14 @@ main(int argc,			/* I - Number of command-line arguments */
 	load_interfaces();
 
 	do {
-		cli = smb_connect(workgroup, server, port, printer,
-			username, password, argv[3], &need_auth);
+		cli = smb_connect(workgroup,
+				  server,
+				  port,
+				  printer,
+				  username,
+				  password,
+				  print_user,
+				  &need_auth);
 		if (cli == NULL) {
 			if (need_auth) {
 				exit(2);
@@ -327,7 +410,7 @@ main(int argc,			/* I - Number of command-line arguments */
          */
 
 	for (i = 0; i < copies; i++) {
-		status = smb_print(cli, argv[4] /* title */ , fp);
+		status = smb_print(cli, print_title, fp);
 		if (status != 0) {
 			break;
 		}
@@ -352,8 +435,7 @@ done:
 
 static int
 get_exit_code(struct cli_state * cli,
-	      NTSTATUS nt_status,
-	      bool use_kerberos)
+	      NTSTATUS nt_status)
 {
 	int i;
 
@@ -380,10 +462,7 @@ get_exit_code(struct cli_state * cli,
 		}
 
 		if (cli) {
-			if (use_kerberos)
-				fputs("ATTR: auth-info-required=negotiate\n", stderr);
-			else
-				fputs("ATTR: auth-info-required=username,password\n", stderr);
+			fprintf(stderr, "ATTR: auth-info-required=%s\n", auth_info_required);
 		}
 
 		/*
@@ -452,6 +531,7 @@ smb_complete_connection(const char *myname,
 	}
 
 	if (flags & CLI_FULL_CONNECTION_USE_KERBEROS) {
+		auth_info_required = "negotiate";
 		use_kerberos = true;
 	}
 
@@ -474,7 +554,7 @@ smb_complete_connection(const char *myname,
 	if (!NT_STATUS_IS_OK(nt_status)) {
 		fprintf(stderr, "ERROR: Session setup failed: %s\n", nt_errstr(nt_status));
 
-		if (get_exit_code(cli, nt_status, use_kerberos) == 2) {
+		if (get_exit_code(cli, nt_status) == 2) {
 			*need_auth = true;
 		}
 
@@ -488,7 +568,7 @@ smb_complete_connection(const char *myname,
 		fprintf(stderr, "ERROR: Tree connect failed (%s)\n",
 			nt_errstr(nt_status));
 
-		if (get_exit_code(cli, nt_status, use_kerberos) == 2) {
+		if (get_exit_code(cli, nt_status) == 2) {
 			*need_auth = true;
 		}
 
@@ -647,7 +727,7 @@ kerberos_auth:
 
 static int			/* O - 0 = success, non-0 = failure */
 smb_print(struct cli_state * cli,	/* I - SMB connection */
-	  char *title,		/* I - Title/job name */
+	  const char *print_title,		/* I - Title/job name */
 	  FILE * fp)
 {				/* I - File to print */
 	uint16_t             fnum;	/* File number */
@@ -655,12 +735,18 @@ smb_print(struct cli_state * cli,	/* I - SMB connection */
 	                tbytes;	/* Total bytes read */
 	char            buffer[8192],	/* Buffer for copy */
 	               *ptr;	/* Pointer into title */
+	char title[1024] = {0};
+	int len;
 	NTSTATUS nt_status;
 
 
 	/*
-         * Sanitize the title...
-         */
+	 * Sanitize the title...
+	 */
+	len = snprintf(title, sizeof(title), "%s", print_title);
+	if (len != strlen(print_title)) {
+		return 2;
+	}
 
 	for (ptr = title; *ptr; ptr++) {
 		if (!isalnum((int) *ptr) && !isspace((int) *ptr)) {
@@ -677,7 +763,7 @@ smb_print(struct cli_state * cli,	/* I - SMB connection */
 	if (!NT_STATUS_IS_OK(nt_status)) {
 		fprintf(stderr, "ERROR: %s opening remote spool %s\n",
 			nt_errstr(nt_status), title);
-		return get_exit_code(cli, nt_status, false);
+		return get_exit_code(cli, nt_status);
 	}
 
 	/*
@@ -695,7 +781,7 @@ smb_print(struct cli_state * cli,	/* I - SMB connection */
 		status = cli_writeall(cli, fnum, 0, (uint8_t *)buffer,
 				      tbytes, nbytes, NULL);
 		if (!NT_STATUS_IS_OK(status)) {
-			int ret = get_exit_code(cli, status, false);
+			int ret = get_exit_code(cli, status);
 			fprintf(stderr, "ERROR: Error writing spool: %s\n",
 				nt_errstr(status));
 			fprintf(stderr, "DEBUG: Returning status %d...\n",
@@ -711,7 +797,7 @@ smb_print(struct cli_state * cli,	/* I - SMB connection */
 	if (!NT_STATUS_IS_OK(nt_status)) {
 		fprintf(stderr, "ERROR: %s closing remote spool %s\n",
 			nt_errstr(nt_status), title);
-		return get_exit_code(cli, nt_status, false);
+		return get_exit_code(cli, nt_status);
 	} else {
 		return (0);
 	}
diff --git a/source3/client/smbspool_krb5_wrapper.c b/source3/client/smbspool_krb5_wrapper.c
index dee3b4c54be..5c4da33238b 100644
--- a/source3/client/smbspool_krb5_wrapper.c
+++ b/source3/client/smbspool_krb5_wrapper.c
@@ -84,24 +84,36 @@ int main(int argc, char *argv[])
 	struct passwd *pwd;
 	char gen_cc[PATH_MAX] = {0};
 	struct stat sb;
-	char *env;
+	char *env = NULL;
+	char auth_info_required[256] = {0};
+	char device_uri[4096] = {0};
 	uid_t uid = (uid_t)-1;
 	gid_t gid = (gid_t)-1;
 	unsigned long tmp;
 	int cmp;
 	int rc;
 
+	env = getenv("DEVICE_URI");
+	if (env != NULL && strlen(env) > 2) {
+		snprintf(device_uri, sizeof(device_uri), "%s", env);
+	}
+
 	/* Check if AuthInfoRequired is set to negotiate */
 	env = getenv("AUTH_INFO_REQUIRED");
 
         /* If not set, then just call smbspool. */
-	if (env == NULL) {
+	if (env == NULL || env[0] == 0) {
 		CUPS_SMB_DEBUG("AUTH_INFO_REQUIRED is not set - "
 			       "execute smbspool");
 		goto smbspool;
 	} else {
 		CUPS_SMB_DEBUG("AUTH_INFO_REQUIRED=%s", env);
 
+		snprintf(auth_info_required,
+			 sizeof(auth_info_required),
+			 "%s",
+			 env);
+


-- 
Samba Shared Repository



More information about the samba-cvs mailing list