s3:client: Evaluate the AUTH_INFO_REQUIRED variable set by cups
authorAndreas Schneider <asn@samba.org>
Fri, 4 Jan 2019 08:21:24 +0000 (09:21 +0100)
committerKarolin Seeger <kseeger@samba.org>
Fri, 22 Mar 2019 08:14:07 +0000 (08:14 +0000)
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@samba.org>
Reviewed-by: Bryan Mason <bmason@redhat.com>
Signed-off-by: Guenther Deschner <gd@samba.org>
(cherry picked from commit 5274b09fbaa5e45cc58f3301818d4e9f6a402845)

source3/client/smbspool.c

index 4f312a6d2949efd02537bf73a033977af2b41657..ea91f68924c463c660178385984670cae310e934 100644 (file)
@@ -61,7 +61,7 @@
  * 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);
@@ -73,6 +73,8 @@ static char    *uri_unescape_alloc(const char *);
 static bool     smb_encrypt;
 #endif
 
+static const char *auth_info_required;
+
 /*
  * 'main()' - Main entry for SMB backend.
  */
@@ -186,6 +188,11 @@ main(int argc,                     /* I - Number of command-line arguments */
                }
        }
 
+       auth_info_required = getenv("AUTH_INFO_REQUIRED");
+       if (auth_info_required == NULL) {
+               auth_info_required = "none";
+       }
+
        cmp = strncmp(dev_uri, "smb://", 6);
        if (cmp != 0) {
                fprintf(stderr,
@@ -234,6 +241,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) {
@@ -353,8 +364,7 @@ done:
 
 static int
 get_exit_code(struct cli_state * cli,
-             NTSTATUS nt_status,
-             bool use_kerberos)
+             NTSTATUS nt_status)
 {
        int i;
 
@@ -381,10 +391,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);
                }
 
                /*
@@ -453,6 +460,7 @@ smb_complete_connection(const char *myname,
        }
 
        if (flags & CLI_FULL_CONNECTION_USE_KERBEROS) {
+               auth_info_required = "negotiate";
                use_kerberos = true;
        }
 
@@ -475,7 +483,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;
                }
 
@@ -489,7 +497,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;
                }
 
@@ -681,7 +689,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);
        }
 
        /*
@@ -699,7 +707,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",
@@ -715,7 +723,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);
        }