]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
auth:creds: Return bool for cli_credentials_guess()
authorAndreas Schneider <asn@samba.org>
Tue, 27 Apr 2021 14:15:30 +0000 (16:15 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 29 Jun 2021 02:19:35 +0000 (02:19 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
auth/credentials/credentials.c
auth/credentials/credentials.h
auth/credentials/tests/test_creds.c

index 49b350dc0d3e04bf1778bd2045567650c87553ea..02a3cf3b35488dc7c84416eb179eae9e396414fd 100644 (file)
@@ -1154,14 +1154,18 @@ _PUBLIC_ bool cli_credentials_set_conf(struct cli_credentials *cred,
  * 
  * @param cred Credentials structure to fill in
  */
-_PUBLIC_ void cli_credentials_guess(struct cli_credentials *cred,
-                          struct loadparm_context *lp_ctx)
+_PUBLIC_ bool cli_credentials_guess(struct cli_credentials *cred,
+                                   struct loadparm_context *lp_ctx)
 {
        const char *error_string;
        const char *env = NULL;
+       bool ok;
 
        if (lp_ctx != NULL) {
-               cli_credentials_set_conf(cred, lp_ctx);
+               ok = cli_credentials_set_conf(cred, lp_ctx);
+               if (!ok) {
+                       return false;
+               }
        }
 
        env = getenv("LOGNAME");
@@ -1169,7 +1173,9 @@ _PUBLIC_ void cli_credentials_guess(struct cli_credentials *cred,
                size_t len = strlen(env);
 
                if (len > 0 && len <= 1024) {
-                       cli_credentials_set_username(cred, env, CRED_GUESS_ENV);
+                       (void)cli_credentials_set_username(cred,
+                                                          env,
+                                                          CRED_GUESS_ENV);
                }
        }
 
@@ -1180,7 +1186,9 @@ _PUBLIC_ void cli_credentials_guess(struct cli_credentials *cred,
                if (len > 0 && len <= 1024) {
                        char *p = NULL;
 
-                       cli_credentials_parse_string(cred, env, CRED_GUESS_ENV);
+                       (void)cli_credentials_parse_string(cred,
+                                                          env,
+                                                          CRED_GUESS_ENV);
                        if ((p = strchr_m(env, '%'))) {
                                memset(p, '\0', strlen(cred->password));
                        }
@@ -1192,18 +1200,22 @@ _PUBLIC_ void cli_credentials_guess(struct cli_credentials *cred,
                size_t len = strlen(env);
 
                if (len > 0 && len <= 1024) {
-                       cli_credentials_set_password(cred, env, CRED_GUESS_ENV);
+                       (void)cli_credentials_set_password(cred,
+                                                          env,
+                                                          CRED_GUESS_ENV);
                }
        }
 
-       env = getenv("PASSWD");
+       env = getenv("PASSWD_FD");
        if (env != NULL) {
                size_t len = strlen(env);
 
                if (len > 0 && len <= 1024) {
                        int fd = atoi(env);
 
-                       cli_credentials_parse_password_fd(cred, fd, CRED_GUESS_FILE);
+                       (void)cli_credentials_parse_password_fd(cred,
+                                                               fd,
+                                                               CRED_GUESS_FILE);
                }
        }
 
@@ -1212,15 +1224,22 @@ _PUBLIC_ void cli_credentials_guess(struct cli_credentials *cred,
                size_t len = strlen(env);
 
                if (len > 0 && len <= 4096) {
-                       cli_credentials_parse_password_file(cred, env, CRED_GUESS_FILE);
+                       (void)cli_credentials_parse_password_file(cred,
+                                                                 env,
+                                                                 CRED_GUESS_FILE);
                }
        }
 
        if (lp_ctx != NULL &&
            cli_credentials_get_kerberos_state(cred) != CRED_USE_KERBEROS_DISABLED) {
-               cli_credentials_set_ccache(cred, lp_ctx, NULL, CRED_GUESS_FILE,
-                                          &error_string);
+               (void)cli_credentials_set_ccache(cred,
+                                                lp_ctx,
+                                                NULL,
+                                                CRED_GUESS_FILE,
+                                                &error_string);
        }
+
+       return true;
 }
 
 /**
index b8edc6d178fe828c4da32bc2f4f6a87629983f1d..4057565ad34c9ec2243a888187266147fb24c88a 100644 (file)
@@ -204,7 +204,7 @@ NTSTATUS cli_credentials_set_machine_account_db_ctx(struct cli_credentials *cred
                                                    struct db_context *db_ctx);
 
 bool cli_credentials_authentication_requested(struct cli_credentials *cred);
-void cli_credentials_guess(struct cli_credentials *cred,
+bool cli_credentials_guess(struct cli_credentials *cred,
                           struct loadparm_context *lp_ctx);
 bool cli_credentials_set_bind_dn(struct cli_credentials *cred, 
                                 const char *bind_dn);
index a7fb3ff5022602ad768af360c08f54f4c5d15089..a2f9642bfe0cf0440069237a511b1ebbe4125458 100644 (file)
@@ -118,12 +118,14 @@ static void torture_creds_guess(void **state)
        TALLOC_CTX *mem_ctx = *state;
        struct cli_credentials *creds = NULL;
        const char *env_user = getenv("USER");
+       bool ok;
 
        creds = cli_credentials_init(mem_ctx);
        assert_non_null(creds);
 
        setenv("PASSWD", "SECRET", 1);
-       cli_credentials_guess(creds, NULL);
+       ok = cli_credentials_guess(creds, NULL);
+       assert_true(ok);
 
        assert_string_equal(creds->username, env_user);
        assert_int_equal(creds->username_obtained, CRED_GUESS_ENV);
@@ -137,12 +139,14 @@ static void torture_creds_anon_guess(void **state)
 {
        TALLOC_CTX *mem_ctx = *state;
        struct cli_credentials *creds = NULL;
+       bool ok;
 
        creds = cli_credentials_init_anon(mem_ctx);
        assert_non_null(creds);
 
        setenv("PASSWD", "SECRET", 1);
-       cli_credentials_guess(creds, NULL);
+       ok = cli_credentials_guess(creds, NULL);
+       assert_true(ok);
 
        assert_string_equal(creds->username, "");
        assert_int_equal(creds->username_obtained, CRED_SPECIFIED);
@@ -232,7 +236,8 @@ static void torture_creds_krb5_state(void **state)
        assert_int_equal(creds->kerberos_state_obtained, CRED_SMB_CONF);
        assert_int_equal(creds->kerberos_state, CRED_USE_KERBEROS_DESIRED);
 
-       cli_credentials_guess(creds, lp_ctx);
+       ok = cli_credentials_guess(creds, lp_ctx);
+       assert_true(ok);
        assert_int_equal(creds->kerberos_state_obtained, CRED_SMB_CONF);
        assert_int_equal(creds->kerberos_state, CRED_USE_KERBEROS_DESIRED);
        assert_int_equal(creds->ccache_obtained, CRED_GUESS_FILE);