2 Unix SMB/CIFS implementation.
3 Authentication utility functions
4 Copyright (C) Volker Lendecke 2010
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #define DBGC_CLASS DBGC_AUTH
25 /****************************************************************************
26 Create an auth_usersupplied_data structure
27 ****************************************************************************/
29 NTSTATUS make_user_info(struct auth_usersupplied_info **user_info,
31 const char *internal_username,
32 const char *client_domain,
34 const char *workstation_name,
35 const DATA_BLOB *lm_pwd,
36 const DATA_BLOB *nt_pwd,
37 const struct samr_Password *lm_interactive_pwd,
38 const struct samr_Password *nt_interactive_pwd,
39 const char *plaintext_password,
40 enum auth_password_state password_state)
43 DEBUG(5,("attempting to make a user_info for %s (%s)\n", internal_username, smb_name));
45 *user_info = SMB_MALLOC_P(struct auth_usersupplied_info);
46 if (*user_info == NULL) {
47 DEBUG(0,("malloc failed for user_info (size %lu)\n", (unsigned long)sizeof(*user_info)));
48 return NT_STATUS_NO_MEMORY;
51 ZERO_STRUCTP(*user_info);
53 DEBUG(5,("making strings for %s's user_info struct\n", internal_username));
55 (*user_info)->client.account_name = SMB_STRDUP(smb_name);
56 if ((*user_info)->client.account_name == NULL) {
57 free_user_info(user_info);
58 return NT_STATUS_NO_MEMORY;
61 (*user_info)->mapped.account_name = SMB_STRDUP(internal_username);
62 if ((*user_info)->mapped.account_name == NULL) {
63 free_user_info(user_info);
64 return NT_STATUS_NO_MEMORY;
67 (*user_info)->mapped.domain_name = SMB_STRDUP(domain);
68 if ((*user_info)->mapped.domain_name == NULL) {
69 free_user_info(user_info);
70 return NT_STATUS_NO_MEMORY;
73 (*user_info)->client.domain_name = SMB_STRDUP(client_domain);
74 if ((*user_info)->client.domain_name == NULL) {
75 free_user_info(user_info);
76 return NT_STATUS_NO_MEMORY;
79 (*user_info)->workstation_name = SMB_STRDUP(workstation_name);
80 if ((*user_info)->workstation_name == NULL) {
81 free_user_info(user_info);
82 return NT_STATUS_NO_MEMORY;
85 DEBUG(5,("making blobs for %s's user_info struct\n", internal_username));
88 (*user_info)->password.response.lanman = data_blob(lm_pwd->data, lm_pwd->length);
90 (*user_info)->password.response.nt = data_blob(nt_pwd->data, nt_pwd->length);
91 if (lm_interactive_pwd) {
92 (*user_info)->password.hash.lanman = SMB_MALLOC_P(struct samr_Password);
93 memcpy((*user_info)->password.hash.lanman->hash, lm_interactive_pwd->hash, sizeof((*user_info)->password.hash.lanman->hash));
96 if (nt_interactive_pwd) {
97 (*user_info)->password.hash.nt = SMB_MALLOC_P(struct samr_Password);
98 memcpy((*user_info)->password.hash.nt->hash, nt_interactive_pwd->hash, sizeof((*user_info)->password.hash.nt->hash));
101 if (plaintext_password)
102 (*user_info)->password.plaintext = SMB_STRDUP(plaintext_password);
104 (*user_info)->password_state = password_state;
106 (*user_info)->logon_parameters = 0;
108 DEBUG(10,("made a user_info for %s (%s)\n", internal_username, smb_name));
113 /***************************************************************************
114 Free a user_info struct
115 ***************************************************************************/
117 void free_user_info(struct auth_usersupplied_info **user_info)
119 DEBUG(5,("attempting to free (and zero) a user_info structure\n"));
120 if (*user_info != NULL) {
121 if ((*user_info)->client.account_name) {
122 DEBUG(10,("structure was created for %s\n",
123 (*user_info)->client.account_name));
125 SAFE_FREE((*user_info)->client.account_name);
126 SAFE_FREE((*user_info)->mapped.account_name);
127 SAFE_FREE((*user_info)->client.domain_name);
128 SAFE_FREE((*user_info)->mapped.domain_name);
129 SAFE_FREE((*user_info)->workstation_name);
130 data_blob_free(&(*user_info)->password.response.lanman);
131 data_blob_free(&(*user_info)->password.response.nt);
132 if ((*user_info)->password.hash.lanman) {
133 ZERO_STRUCTP((*user_info)->password.hash.lanman);
134 SAFE_FREE((*user_info)->password.hash.lanman);
136 if ((*user_info)->password.hash.nt) {
137 ZERO_STRUCTP((*user_info)->password.hash.nt);
138 SAFE_FREE((*user_info)->password.hash.nt);
140 if ((*user_info)->password.plaintext) {
141 memset((*user_info)->password.plaintext, '\0', strlen(((*user_info)->password.plaintext)));
142 SAFE_FREE((*user_info)->password.plaintext);
144 ZERO_STRUCT(**user_info);
146 SAFE_FREE(*user_info);