2 Unix SMB/CIFS implementation.
4 Winbind daemon - pam auth funcions
6 Copyright (C) Andrew Tridgell 2000
7 Copyright (C) Tim Potter 2001
8 Copyright (C) Andrew Bartlett 2001
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /* Return a password structure from a username. */
29 enum winbindd_result winbindd_pam_auth(struct winbindd_cli_state *state)
32 fstring name_domain, name_user;
34 unsigned char trust_passwd[16];
35 time_t last_change_time;
37 NET_USER_INFO_3 info3;
38 struct cli_state *cli = NULL;
44 extern pstring global_myname;
46 DEBUG(3, ("[%5d]: pam auth %s\n", state->pid,
47 state->request.data.auth.user));
49 if (!(mem_ctx = talloc_init_named("winbind pam auth for %s", state->request.data.auth.user))) {
50 DEBUG(0, ("winbindd_pam_auth: could not talloc_init()!\n"));
51 return WINBINDD_ERROR;
54 /* Parse domain and username */
56 if (!parse_domain_user(state->request.data.auth.user, name_domain,
58 DEBUG(5,("no domain seperator (%s) in username (%s) - failing auth\n", lp_winbind_separator(), state->request.data.auth.user));
59 talloc_destroy(mem_ctx);
60 return WINBINDD_ERROR;
63 passlen = strlen(state->request.data.auth.pass);
65 if (!*state->request.data.auth.pass) {
66 return WINBINDD_ERROR;
67 talloc_destroy(mem_ctx);
69 unsigned char local_lm_response[24];
70 unsigned char local_nt_response[24];
72 generate_random_buffer(chal, 8, False);
73 SMBencrypt( (const uchar *)state->request.data.auth.pass, chal, local_lm_response);
75 SMBNTencrypt((const uchar *)state->request.data.auth.pass, chal, local_nt_response);
77 lm_resp = data_blob_talloc(mem_ctx, local_lm_response, sizeof(local_lm_response));
78 nt_resp = data_blob_talloc(mem_ctx, local_nt_response, sizeof(local_nt_response));
82 * Get the machine account password for our primary domain
85 if (!secrets_fetch_trust_account_password(
86 lp_workgroup(), trust_passwd, &last_change_time)) {
87 DEBUG(0, ("winbindd_pam_auth: could not fetch trust account "
88 "password for domain %s\n", lp_workgroup()));
89 talloc_destroy(mem_ctx);
90 return WINBINDD_ERROR;
93 /* We really don't care what LUID we give the user. */
95 generate_random_buffer( (unsigned char *)&smb_uid_low, 4, False);
99 result = cm_get_netlogon_cli(lp_workgroup(), trust_passwd, &cli);
101 if (!NT_STATUS_IS_OK(result)) {
102 DEBUG(3, ("could not open handle to NETLOGON pipe\n"));
106 result = cli_netlogon_sam_network_logon(cli, mem_ctx,
107 name_user, name_domain,
112 uni_group_cache_store_netlogon(mem_ctx, &info3);
118 talloc_destroy(mem_ctx);
120 return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
123 /* Challenge Response Authentication Protocol */
125 enum winbindd_result winbindd_pam_auth_crap(struct winbindd_cli_state *state)
128 unsigned char trust_passwd[16];
129 time_t last_change_time;
130 NET_USER_INFO_3 info3;
131 struct cli_state *cli = NULL;
133 const char *domain = NULL;
135 DATA_BLOB lm_resp, nt_resp;
137 extern pstring global_myname;
139 DEBUG(3, ("[%5d]: pam auth crap domain: %s user: %s\n", state->pid,
140 state->request.data.auth_crap.user, state->request.data.auth_crap.user));
142 if (!(mem_ctx = talloc_init_named("winbind pam auth crap for %s", state->request.data.auth.user))) {
143 DEBUG(0, ("winbindd_pam_auth_crap: could not talloc_init()!\n"));
144 return WINBINDD_ERROR;
147 if (*state->request.data.auth_crap.domain) {
148 domain = talloc_strdup(mem_ctx, state->request.data.auth_crap.domain);
149 } else if (lp_winbind_use_default_domain()) {
150 domain = talloc_strdup(mem_ctx, lp_workgroup());
152 DEBUG(5,("no domain specified with username (%s) - failing auth\n", state->request.data.auth.user));
153 talloc_destroy(mem_ctx);
154 return WINBINDD_ERROR;
158 DEBUG(0,("winbindd_pam_auth_crap: talloc_strdup failed!\n"));
159 talloc_destroy(mem_ctx);
160 return WINBINDD_ERROR;
163 lm_resp = data_blob_talloc(mem_ctx, state->request.data.auth_crap.lm_resp, state->request.data.auth_crap.lm_resp_len);
164 nt_resp = data_blob_talloc(mem_ctx, state->request.data.auth_crap.nt_resp, state->request.data.auth_crap.nt_resp_len);
167 * Get the machine account password for our primary domain
170 if (!secrets_fetch_trust_account_password(
171 lp_workgroup(), trust_passwd, &last_change_time)) {
172 DEBUG(0, ("winbindd_pam_auth: could not fetch trust account "
173 "password for domain %s\n", lp_workgroup()));
174 talloc_destroy(mem_ctx);
175 return WINBINDD_ERROR;
180 result = cm_get_netlogon_cli(lp_workgroup(), trust_passwd, &cli);
182 if (!NT_STATUS_IS_OK(result)) {
183 DEBUG(3, ("could not open handle to NETLOGON pipe\n"));
187 result = cli_netlogon_sam_network_logon(cli, mem_ctx,
188 state->request.data.auth_crap.user, domain,
189 global_myname, state->request.data.auth_crap.chal,
193 uni_group_cache_store_netlogon(mem_ctx, &info3);
195 talloc_destroy(mem_ctx);
200 return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
203 /* Change a user password */
205 enum winbindd_result winbindd_pam_chauthtok(struct winbindd_cli_state *state)
207 char *oldpass, *newpass;
208 fstring domain, user;
209 uchar nt_oldhash[16];
210 uchar lm_oldhash[16];
213 DEBUG(3, ("[%5d]: pam chauthtok %s\n", state->pid,
214 state->request.data.chauthtok.user));
219 return WINBINDD_ERROR;
221 if (!parse_domain_user(state->request.data.chauthtok.user, domain,
223 return WINBINDD_ERROR;
225 /* Change password */
227 oldpass = state->request.data.chauthtok.oldpass;
228 newpass = state->request.data.chauthtok.newpass;
232 if (!(hnd = cm_get_sam_handle(domain)))
233 return WINBINDD_ERROR;
235 if (!cli_oem_change_password(hnd->cli, user, newpass, oldpass)) {
236 DEBUG(0, ("password change failed for user %s/%s\n", domain,
238 return WINBINDD_ERROR;