auth/credentials: add cli_credentials_set_utf16_password()
[obnox/samba/samba-obnox.git] / auth / credentials / credentials.c
index 642eef7932854c824ab1cee247ff9452833203a2..a9e4fc864d46426de0d769fa0e5926fdd216bad6 100644 (file)
@@ -496,24 +496,27 @@ _PUBLIC_ bool cli_credentials_set_old_password(struct cli_credentials *cred,
 _PUBLIC_ struct samr_Password *cli_credentials_get_nt_hash(struct cli_credentials *cred,
                                                           TALLOC_CTX *mem_ctx)
 {
-       const char *password = cli_credentials_get_password(cred);
+       const char *password = NULL;
 
-       if (password) {
+       if (cred->nt_hash != NULL) {
                struct samr_Password *nt_hash = talloc(mem_ctx, struct samr_Password);
                if (!nt_hash) {
                        return NULL;
                }
 
-               E_md4hash(password, nt_hash->hash);    
+               *nt_hash = *cred->nt_hash;
 
                return nt_hash;
-       } else if (cred->nt_hash != NULL) {
+       }
+
+       password = cli_credentials_get_password(cred);
+       if (password) {
                struct samr_Password *nt_hash = talloc(mem_ctx, struct samr_Password);
                if (!nt_hash) {
                        return NULL;
                }
 
-               *nt_hash = *cred->nt_hash;
+               E_md4hash(password, nt_hash->hash);
 
                return nt_hash;
        }
@@ -836,7 +839,11 @@ _PUBLIC_ void cli_credentials_guess(struct cli_credentials *cred,
 _PUBLIC_ void cli_credentials_set_netlogon_creds(struct cli_credentials *cred, 
                                                 struct netlogon_creds_CredentialState *netlogon_creds)
 {
-       cred->netlogon_creds = talloc_reference(cred, netlogon_creds);
+       TALLOC_FREE(cred->netlogon_creds);
+       if (netlogon_creds == NULL) {
+               return;
+       }
+       cred->netlogon_creds = netlogon_creds_copy(cred, netlogon_creds);
 }
 
 /**