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. Specify whether cached data
31 enum winbindd_result winbindd_pam_auth(struct winbindd_cli_state *state)
34 fstring name_domain, name_user;
36 unsigned char trust_passwd[16];
37 time_t last_change_time;
38 auth_usersupplied_info *user_info;
40 NET_USER_INFO_3 info3;
42 struct cli_state *cli;
45 DEBUG(3, ("[%5d]: pam auth %s\n", state->pid,
46 state->request.data.auth.user));
48 /* Parse domain and username */
50 parse_domain_user(state->request.data.auth.user, name_domain,
53 /* don't allow the null domain */
55 if (strcmp(name_domain,"") == 0)
56 return WINBINDD_ERROR;
58 passlen = strlen(state->request.data.auth.pass);
60 if (state->request.data.auth.pass[0])
61 make_user_info_winbind(&user_info,
62 name_user, name_domain,
63 state->request.data.auth.pass,
66 return WINBINDD_ERROR;
69 * Get the machine account password for our primary domain
72 if (!secrets_fetch_trust_account_password(
73 lp_workgroup(), trust_passwd, &last_change_time)) {
74 DEBUG(0, ("winbindd_pam_auth: could not fetch trust account "
75 "password for domain %s\n", lp_workgroup()));
76 return WINBINDD_ERROR;
79 /* We really don't care what LUID we give the user. */
81 generate_random_buffer( (unsigned char *)&smb_uid_low, 4, False);
85 result = cm_get_netlogon_cli(lp_workgroup(), trust_passwd, &cli);
87 if (!NT_STATUS_IS_OK(result)) {
88 DEBUG(3, ("could not open handle to NETLOGON pipe\n"));
92 result = cli_nt_login_network(cli, user_info, chal, smb_uid_low,
95 free_user_info(&user_info);
100 return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
103 /* Challenge Response Authentication Protocol */
105 enum winbindd_result winbindd_pam_auth_crap(struct winbindd_cli_state *state)
108 fstring name_domain, name_user;
109 unsigned char trust_passwd[16];
110 time_t last_change_time;
112 auth_usersupplied_info *user_info;
114 NET_USER_INFO_3 info3;
116 struct cli_state *cli;
118 DEBUG(3, ("[%5d]: pam auth crap %s\n", state->pid,
119 state->request.data.auth_crap.user));
121 /* Parse domain and username */
123 parse_domain_user(state->request.data.auth_crap.user, name_domain,
126 make_user_info_winbind_crap(
127 &user_info, name_user,
129 (uchar *)state->request.data.auth_crap.lm_resp,
130 state->request.data.auth_crap.lm_resp_len,
131 (uchar *)state->request.data.auth_crap.nt_resp,
132 state->request.data.auth_crap.nt_resp_len);
135 * Get the machine account password for our primary domain
138 if (!secrets_fetch_trust_account_password(
139 lp_workgroup(), trust_passwd, &last_change_time)) {
140 DEBUG(0, ("winbindd_pam_auth: could not fetch trust account "
141 "password for domain %s\n", lp_workgroup()));
142 return WINBINDD_ERROR;
145 /* We really don't care what LUID we give the user. */
147 generate_random_buffer( (unsigned char *)&smb_uid_low, 4, False);
151 result = cm_get_netlogon_cli(lp_workgroup(), trust_passwd, &cli);
153 if (!NT_STATUS_IS_OK(result)) {
154 DEBUG(3, ("could not open handle to NETLOGON pipe\n"));
158 result = cli_nt_login_network(cli, user_info, state->request.data.auth_crap.chal,
159 smb_uid_low, &ctr, &info3);
161 free_user_info(&user_info);
166 return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
169 /* Change a user password */
171 enum winbindd_result winbindd_pam_chauthtok(struct winbindd_cli_state *state)
173 char *oldpass, *newpass;
174 fstring domain, user;
175 uchar nt_oldhash[16];
176 uchar lm_oldhash[16];
178 DEBUG(3, ("[%5d]: pam chauthtok %s\n", state->pid,
179 state->request.data.chauthtok.user));
183 if (state == NULL) return WINBINDD_ERROR;
185 parse_domain_user(state->request.data.chauthtok.user, domain, user);
187 oldpass = state->request.data.chauthtok.oldpass;
188 newpass = state->request.data.chauthtok.newpass;
190 nt_lm_owf_gen(oldpass, nt_oldhash, lm_oldhash);
192 /* Change password */
198 if (!msrpc_sam_ntchange_pwd(server_state.controller, domain, user,
199 lm_oldhash, nt_oldhash, newpass)) {
200 DEBUG(0, ("password change failed for user %s/%s\n", domain, user));
201 return WINBINDD_ERROR;