s4:auth - fixed problem reading bind DN from secrets database
[samba.git] / source4 / auth / credentials / credentials.c
index 89dddc9e0585408dde0bfa412030e68ebb363ad3..549c2691f0301f246b125eda0a79722a905968fe 100644 (file)
@@ -25,6 +25,7 @@
 #include "librpc/gen_ndr/samr.h" /* for struct samrPassword */
 #include "auth/credentials/credentials.h"
 #include "auth/credentials/credentials_krb5.h"
+#include "auth/credentials/credentials_proto.h"
 #include "libcli/auth/libcli_auth.h"
 #include "lib/events/events.h"
 #include "param/param.h"
 _PUBLIC_ struct cli_credentials *cli_credentials_init(TALLOC_CTX *mem_ctx) 
 {
        struct cli_credentials *cred = talloc(mem_ctx, struct cli_credentials);
-       if (!cred) {
+       if (cred == NULL) {
                return cred;
        }
 
-       cred->netlogon_creds = NULL;
-       cred->machine_account_pending = false;
        cred->workstation_obtained = CRED_UNINITIALISED;
        cred->username_obtained = CRED_UNINITIALISED;
        cred->password_obtained = CRED_UNINITIALISED;
@@ -49,23 +48,52 @@ _PUBLIC_ struct cli_credentials *cli_credentials_init(TALLOC_CTX *mem_ctx)
        cred->realm_obtained = CRED_UNINITIALISED;
        cred->ccache_obtained = CRED_UNINITIALISED;
        cred->client_gss_creds_obtained = CRED_UNINITIALISED;
-       cred->server_gss_creds_obtained = CRED_UNINITIALISED;
-       cred->keytab_obtained = CRED_UNINITIALISED;
        cred->principal_obtained = CRED_UNINITIALISED;
+       cred->keytab_obtained = CRED_UNINITIALISED;
+       cred->server_gss_creds_obtained = CRED_UNINITIALISED;
 
        cred->ccache_threshold = CRED_UNINITIALISED;
        cred->client_gss_creds_threshold = CRED_UNINITIALISED;
 
+       cred->workstation = NULL;
+       cred->username = NULL;
+       cred->password = NULL;
        cred->old_password = NULL;
-       cred->smb_krb5_context = NULL;
+       cred->domain = NULL;
+       cred->realm = NULL;
+       cred->principal = NULL;
        cred->salt_principal = NULL;
-       cred->machine_account = false;
 
        cred->bind_dn = NULL;
 
+       cred->nt_hash = NULL;
+
+       cred->ccache = NULL;
+       cred->client_gss_creds = NULL;
+       cred->keytab = NULL;
+       cred->server_gss_creds = NULL;
+
+       cred->workstation_cb = NULL;
+       cred->password_cb = NULL;
+       cred->username_cb = NULL;
+       cred->domain_cb = NULL;
+       cred->realm_cb = NULL;
+       cred->principal_cb = NULL;
+
+       cred->priv_data = NULL;
+
+       cred->netlogon_creds = NULL;
+
+       cred->smb_krb5_context = NULL;
+
+       cred->machine_account_pending = false;
+       cred->machine_account_pending_lp_ctx = NULL;
+
+       cred->machine_account = false;
+
        cred->tries = 3;
+
        cred->callback_running = false;
-       cred->ev = NULL;
 
        cli_credentials_set_kerberos_state(cred, CRED_AUTO_USE_KERBEROS);
        cli_credentials_set_gensec_features(cred, 0);
@@ -307,6 +335,8 @@ _PUBLIC_ bool cli_credentials_set_password(struct cli_credentials *cred,
                cli_credentials_invalidate_ccache(cred, cred->password_obtained);
 
                cred->nt_hash = NULL;
+               cred->lm_response = data_blob(NULL, 0);
+               cred->nt_response = data_blob(NULL, 0);
                return true;
        }
 
@@ -377,24 +407,6 @@ _PUBLIC_ const struct samr_Password *cli_credentials_get_nt_hash(struct cli_cred
        }
 }
 
-_PUBLIC_ bool cli_credentials_set_nt_hash(struct cli_credentials *cred,
-                                const struct samr_Password *nt_hash, 
-                                enum credentials_obtained obtained)
-{
-       if (obtained >= cred->password_obtained) {
-               cli_credentials_set_password(cred, NULL, obtained);
-               if (nt_hash) {
-                       cred->nt_hash = talloc(cred, struct samr_Password);
-                       *cred->nt_hash = *nt_hash;
-               } else {
-                       cred->nt_hash = NULL;
-               }
-               return true;
-       }
-
-       return false;
-}
-
 /**
  * Obtain the 'short' or 'NetBIOS' domain for this credentials context.
  * @param cred credentials context
@@ -675,7 +687,7 @@ _PUBLIC_ void cli_credentials_guess(struct cli_credentials *cred,
        }
        
        if (cli_credentials_get_kerberos_state(cred) != CRED_DONT_USE_KERBEROS) {
-               cli_credentials_set_ccache(cred, lp_ctx, NULL, CRED_GUESS_FILE);
+               cli_credentials_set_ccache(cred, event_context_find(cred), lp_ctx, NULL, CRED_GUESS_FILE);
        }
 }
 
@@ -684,7 +696,7 @@ _PUBLIC_ void cli_credentials_guess(struct cli_credentials *cred,
  */
 
 _PUBLIC_ void cli_credentials_set_netlogon_creds(struct cli_credentials *cred, 
-                                       struct creds_CredentialState *netlogon_creds)
+                                                struct netlogon_creds_CredentialState *netlogon_creds)
 {
        cred->netlogon_creds = talloc_reference(cred, netlogon_creds);
 }
@@ -693,7 +705,7 @@ _PUBLIC_ void cli_credentials_set_netlogon_creds(struct cli_credentials *cred,
  * Return attached NETLOGON credentials 
  */
 
-struct creds_CredentialState *cli_credentials_get_netlogon_creds(struct cli_credentials *cred)
+struct netlogon_creds_CredentialState *cli_credentials_get_netlogon_creds(struct cli_credentials *cred)
 {
        return cred->netlogon_creds;
 }
@@ -738,6 +750,11 @@ _PUBLIC_ bool cli_credentials_is_anonymous(struct cli_credentials *cred)
 {
        const char *username;
        
+       /* if bind dn is set it's not anonymous */
+       if (cred->bind_dn) {
+               return false;
+       }
+
        if (cred->machine_account_pending) {
                cli_credentials_set_machine_account(cred,
                                                    cred->machine_account_pending_lp_ctx);
@@ -775,22 +792,3 @@ _PUBLIC_ bool cli_credentials_wrong_password(struct cli_credentials *cred)
 
        return (cred->tries > 0);
 }
-
-/*
-  set the common event context for this set of credentials
- */
-_PUBLIC_ void cli_credentials_set_event_context(struct cli_credentials *cred, struct event_context *ev)
-{
-       cred->ev = ev;
-}
-
-/*
-  set the common event context for this set of credentials
- */
-_PUBLIC_ struct event_context *cli_credentials_get_event_context(struct cli_credentials *cred)
-{
-       if (cred->ev == NULL) {
-               cred->ev = event_context_find(cred);
-       }
-       return cred->ev;
-}