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/>.
22 #include "librpc/gen_ndr/samr.h"
23 #include "../lib/tsocket/tsocket.h"
26 #define DBGC_CLASS DBGC_AUTH
28 static int clear_samr_Password(struct samr_Password
*password
)
30 memset(password
->hash
, '\0', sizeof(password
->hash
));
34 static int clear_string(char *password
)
36 memset(password
, '\0', strlen(password
));
40 /****************************************************************************
41 Create an auth_usersupplied_data structure
42 ****************************************************************************/
44 NTSTATUS
make_user_info(TALLOC_CTX
*mem_ctx
,
45 struct auth_usersupplied_info
**ret_user_info
,
47 const char *internal_username
,
48 const char *client_domain
,
50 const char *workstation_name
,
51 const struct tsocket_address
*remote_address
,
52 const DATA_BLOB
*lm_pwd
,
53 const DATA_BLOB
*nt_pwd
,
54 const struct samr_Password
*lm_interactive_pwd
,
55 const struct samr_Password
*nt_interactive_pwd
,
56 const char *plaintext_password
,
57 enum auth_password_state password_state
)
59 struct auth_usersupplied_info
*user_info
;
60 *ret_user_info
= NULL
;
62 DEBUG(5,("attempting to make a user_info for %s (%s)\n", internal_username
, smb_name
));
64 user_info
= talloc_zero(mem_ctx
, struct auth_usersupplied_info
);
65 if (user_info
== NULL
) {
66 DEBUG(0,("talloc failed for user_info\n"));
67 return NT_STATUS_NO_MEMORY
;
70 DEBUG(5,("making strings for %s's user_info struct\n", internal_username
));
72 user_info
->client
.account_name
= talloc_strdup(user_info
, smb_name
);
73 if (user_info
->client
.account_name
== NULL
) {
74 TALLOC_FREE(user_info
);
75 return NT_STATUS_NO_MEMORY
;
78 user_info
->mapped
.account_name
= talloc_strdup(user_info
, internal_username
);
79 if (user_info
->mapped
.account_name
== NULL
) {
80 TALLOC_FREE(user_info
);
81 return NT_STATUS_NO_MEMORY
;
84 user_info
->mapped
.domain_name
= talloc_strdup(user_info
, domain
);
85 if (user_info
->mapped
.domain_name
== NULL
) {
86 TALLOC_FREE(user_info
);
87 return NT_STATUS_NO_MEMORY
;
90 user_info
->client
.domain_name
= talloc_strdup(user_info
, client_domain
);
91 if (user_info
->client
.domain_name
== NULL
) {
92 TALLOC_FREE(user_info
);
93 return NT_STATUS_NO_MEMORY
;
96 user_info
->workstation_name
= talloc_strdup(user_info
, workstation_name
);
97 if (user_info
->workstation_name
== NULL
) {
98 TALLOC_FREE(user_info
);
99 return NT_STATUS_NO_MEMORY
;
102 user_info
->remote_host
= tsocket_address_copy(remote_address
, user_info
);
103 if (user_info
->remote_host
== NULL
) {
104 TALLOC_FREE(user_info
);
105 return NT_STATUS_NO_MEMORY
;
108 DEBUG(5,("making blobs for %s's user_info struct\n", internal_username
));
110 if (lm_pwd
&& lm_pwd
->data
) {
111 user_info
->password
.response
.lanman
= data_blob_talloc(user_info
, lm_pwd
->data
, lm_pwd
->length
);
112 if (user_info
->password
.response
.lanman
.data
== NULL
) {
113 TALLOC_FREE(user_info
);
114 return NT_STATUS_NO_MEMORY
;
117 if (nt_pwd
&& nt_pwd
->data
) {
118 user_info
->password
.response
.nt
= data_blob_talloc(user_info
, nt_pwd
->data
, nt_pwd
->length
);
119 if (user_info
->password
.response
.nt
.data
== NULL
) {
120 TALLOC_FREE(user_info
);
121 return NT_STATUS_NO_MEMORY
;
124 if (lm_interactive_pwd
) {
125 user_info
->password
.hash
.lanman
= talloc(user_info
, struct samr_Password
);
126 if (user_info
->password
.hash
.lanman
== NULL
) {
127 TALLOC_FREE(user_info
);
128 return NT_STATUS_NO_MEMORY
;
130 memcpy(user_info
->password
.hash
.lanman
->hash
, lm_interactive_pwd
->hash
,
131 sizeof(user_info
->password
.hash
.lanman
->hash
));
132 talloc_set_destructor(user_info
->password
.hash
.lanman
, clear_samr_Password
);
135 if (nt_interactive_pwd
) {
136 user_info
->password
.hash
.nt
= talloc(user_info
, struct samr_Password
);
137 if (user_info
->password
.hash
.nt
== NULL
) {
138 TALLOC_FREE(user_info
);
139 return NT_STATUS_NO_MEMORY
;
141 memcpy(user_info
->password
.hash
.nt
->hash
, nt_interactive_pwd
->hash
,
142 sizeof(user_info
->password
.hash
.nt
->hash
));
143 talloc_set_destructor(user_info
->password
.hash
.nt
, clear_samr_Password
);
146 if (plaintext_password
) {
147 user_info
->password
.plaintext
= talloc_strdup(user_info
, plaintext_password
);
148 if (user_info
->password
.plaintext
== NULL
) {
149 TALLOC_FREE(user_info
);
150 return NT_STATUS_NO_MEMORY
;
152 talloc_set_destructor(user_info
->password
.plaintext
, clear_string
);
155 user_info
->password_state
= password_state
;
157 user_info
->logon_parameters
= 0;
159 DEBUG(10,("made a user_info for %s (%s)\n", internal_username
, smb_name
));
160 *ret_user_info
= user_info
;