2 Unix SMB/Netbios implementation.
5 Winbind daemon - pam auth funcions
7 Copyright (C) Andrew Tridgell 2000
8 Copyright (C) Tim Potter 2001
9 Copyright (C) Andrew Bartlett 2001
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 /* Return a password structure from a username. */
30 enum winbindd_result winbindd_pam_auth(struct winbindd_cli_state *state)
33 fstring name_domain, name_user;
35 unsigned char trust_passwd[16];
36 time_t last_change_time;
38 NET_USER_INFO_3 info3;
39 struct cli_state *cli;
45 extern pstring global_myname;
47 DEBUG(3, ("[%5d]: pam auth %s\n", state->pid,
48 state->request.data.auth.user));
50 if (!(mem_ctx = talloc_init_named("winbind pam auth for %s", state->request.data.auth.user))) {
51 DEBUG(0, ("winbindd_pam_auth: could not talloc_init()!\n"));
52 return WINBINDD_ERROR;
55 /* Parse domain and username */
57 if (!parse_domain_user(state->request.data.auth.user, name_domain,
59 return WINBINDD_ERROR;
61 passlen = strlen(state->request.data.auth.pass);
63 if (!*state->request.data.auth.pass) {
64 return WINBINDD_ERROR;
66 unsigned char local_lm_response[24];
67 unsigned char local_nt_response[24];
69 generate_random_buffer(chal, 8, False);
70 SMBencrypt( (const uchar *)state->request.data.auth.pass, chal, local_lm_response);
72 SMBNTencrypt((const uchar *)state->request.data.auth.pass, chal, local_nt_response);
74 lm_resp = data_blob(local_lm_response, sizeof(local_lm_response));
75 nt_resp = data_blob(local_nt_response, sizeof(local_nt_response));
79 * Get the machine account password for our primary domain
82 if (!secrets_fetch_trust_account_password(
83 lp_workgroup(), trust_passwd, &last_change_time)) {
84 DEBUG(0, ("winbindd_pam_auth: could not fetch trust account "
85 "password for domain %s\n", lp_workgroup()));
86 return WINBINDD_ERROR;
89 /* We really don't care what LUID we give the user. */
91 generate_random_buffer( (unsigned char *)&smb_uid_low, 4, False);
95 result = cm_get_netlogon_cli(lp_workgroup(), trust_passwd, &cli);
97 if (!NT_STATUS_IS_OK(result)) {
98 DEBUG(3, ("could not open handle to NETLOGON pipe\n"));
102 result = cli_netlogon_sam_network_logon(cli, mem_ctx,
103 name_user, name_domain,
109 data_blob_free(&lm_resp);
110 data_blob_free(&nt_resp);
114 talloc_destroy(mem_ctx);
116 return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
119 /* Challenge Response Authentication Protocol */
121 enum winbindd_result winbindd_pam_auth_crap(struct winbindd_cli_state *state)
124 fstring name_domain, name_user;
125 unsigned char trust_passwd[16];
126 time_t last_change_time;
127 NET_USER_INFO_3 info3;
128 struct cli_state *cli;
131 DATA_BLOB lm_resp, nt_resp;
133 extern pstring global_myname;
135 DEBUG(3, ("[%5d]: pam auth crap %s\n", state->pid,
136 state->request.data.auth_crap.user));
138 if (!(mem_ctx = talloc_init_named("winbind pam auth for %s", state->request.data.auth.user))) {
139 DEBUG(0, ("winbindd_pam_auth_crap: could not talloc_init()!\n"));
140 return WINBINDD_ERROR;
143 /* Parse domain and username */
144 if (!parse_domain_user(state->request.data.auth_crap.user, name_domain,
146 return WINBINDD_ERROR;
150 lm_resp = data_blob(state->request.data.auth_crap.lm_resp, state->request.data.auth_crap.lm_resp_len);
151 nt_resp = data_blob(state->request.data.auth_crap.nt_resp, state->request.data.auth_crap.nt_resp_len);
154 * Get the machine account password for our primary domain
157 if (!secrets_fetch_trust_account_password(
158 lp_workgroup(), trust_passwd, &last_change_time)) {
159 DEBUG(0, ("winbindd_pam_auth: could not fetch trust account "
160 "password for domain %s\n", lp_workgroup()));
161 return WINBINDD_ERROR;
166 result = cm_get_netlogon_cli(lp_workgroup(), trust_passwd, &cli);
168 if (!NT_STATUS_IS_OK(result)) {
169 DEBUG(3, ("could not open handle to NETLOGON pipe\n"));
173 result = cli_netlogon_sam_network_logon(cli, mem_ctx,
174 name_user, name_domain,
175 global_myname, state->request.data.auth_crap.chal,
180 talloc_destroy(mem_ctx);
184 return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
187 /* Change a user password */
189 enum winbindd_result winbindd_pam_chauthtok(struct winbindd_cli_state *state)
191 char *oldpass, *newpass;
192 fstring domain, user;
193 uchar nt_oldhash[16];
194 uchar lm_oldhash[16];
196 DEBUG(3, ("[%5d]: pam chauthtok %s\n", state->pid,
197 state->request.data.chauthtok.user));
202 return WINBINDD_ERROR;
204 if (!parse_domain_user(state->request.data.chauthtok.user, domain, user))
205 return WINBINDD_ERROR;
207 oldpass = state->request.data.chauthtok.oldpass;
208 newpass = state->request.data.chauthtok.newpass;
210 nt_lm_owf_gen(oldpass, nt_oldhash, lm_oldhash);
212 /* Change password */
218 if (!msrpc_sam_ntchange_pwd(server_state.controller, domain, user,
219 lm_oldhash, nt_oldhash, newpass)) {
220 DEBUG(0, ("password change failed for user %s/%s\n", domain, user));
221 return WINBINDD_ERROR;