2 Unix SMB/Netbios implementation.
5 Winbind daemon - pam auuth 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 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
29 form DOMAIN/user into a domain and a user */
31 static void parse_domain_user(char *domuser, fstring domain, fstring user)
34 char *sep = lp_winbind_separator();
36 p = strchr(domuser,*sep);
37 if (!p) p = strchr(domuser,'\\');
40 fstrcpy(user, domuser);
45 fstrcpy(domain, domuser);
46 domain[PTR_DIFF(p, domuser)] = 0;
50 /* Return a password structure from a username. Specify whether cached data
53 enum winbindd_result winbindd_pam_auth(struct winbindd_cli_state *state)
56 fstring name_domain, name_user, auth_dc;
58 unsigned char trust_passwd[16];
59 time_t last_change_time;
61 auth_usersupplied_info *user_info;
62 auth_serversupplied_info *server_info;
64 DEBUG(3, ("[%5d]: pam auth %s\n", state->pid,
65 state->request.data.auth.user));
67 /* Parse domain and username */
69 parse_domain_user(state->request.data.auth.user, name_domain,
72 /* don't allow the null domain */
74 if (strcmp(name_domain,"") == 0)
75 return WINBINDD_ERROR;
77 passlen = strlen(state->request.data.auth.pass);
79 if (state->request.data.auth.pass[0]) {
80 make_user_info_for_winbind(&user_info,
81 name_user, name_domain,
82 state->request.data.auth.pass);
84 return WINBINDD_ERROR;
88 * Get the machine account password for our primary domain
91 if (!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd, &last_change_time))
93 DEBUG(0, ("winbindd_pam_auth: could not fetch trust account password for domain %s\n", lp_workgroup()));
94 return WINBINDD_ERROR;
97 if (!cm_get_dc_name(lp_workgroup(), auth_dc)) {
98 DEBUG(3, ("Could not find dc for workgroup %s\n",
100 return WINBINDD_ERROR;
103 /* So domain_client_validate() actually opens a new connection
104 for each authentication performed. This can theoretically
105 be optimised to use an already open IPC$ connection. */
107 result = domain_client_validate(user_info, &server_info,
108 auth_dc, trust_passwd,
111 free_server_info(&server_info); /* No info needed */
113 return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
116 /* Challenge Response Authentication Protocol */
118 enum winbindd_result winbindd_pam_auth_crap(struct winbindd_cli_state *state)
121 fstring name_domain, name_user, auth_dc;
122 unsigned char trust_passwd[16];
123 time_t last_change_time;
124 auth_usersupplied_info *user_info;
125 auth_serversupplied_info *server_info;
127 DEBUG(3, ("[%5d]: pam auth crap %s\n", state->pid,
128 state->request.data.auth_crap.user));
130 /* Parse domain and username */
132 parse_domain_user(state->request.data.auth_crap.user, name_domain,
135 make_user_info_winbind_crap(&user_info, name_user,
136 name_domain, state->request.data.auth_crap.chal,
137 (uchar *)state->request.data.auth_crap.lm_resp, 24,
138 (uchar *)state->request.data.auth_crap.nt_resp, 24);
141 * Get the machine account password for our primary domain
144 if (!secrets_fetch_trust_account_password(lp_workgroup(), trust_passwd, &last_change_time))
146 DEBUG(0, ("winbindd_pam_auth: could not fetch trust account password for domain %s\n", lp_workgroup()));
147 return WINBINDD_ERROR;
150 if (!cm_get_dc_name(lp_workgroup(), auth_dc)) {
151 DEBUG(3, ("Could not find dc for workgroup %s\n",
153 return WINBINDD_ERROR;
156 /* So domain_client_validate() actually opens a new connection
157 for each authentication performed. This can theoretically
158 be optimised to use an already open IPC$ connection. */
160 result = domain_client_validate(user_info, &server_info,
161 auth_dc, trust_passwd,
164 free_server_info(&server_info); /* No info needed */
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;