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-2002
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.
28 #define DBGC_CLASS DBGC_WINBIND
31 static NTSTATUS append_info3_as_ndr(TALLOC_CTX *mem_ctx,
32 struct winbindd_cli_state *state,
33 NET_USER_INFO_3 *info3)
37 if (!prs_init(&ps, 256 /* Random, non-zero number */, mem_ctx, MARSHALL)) {
38 return NT_STATUS_NO_MEMORY;
40 if (!net_io_user_info3("", info3, &ps, 1, 3)) {
42 return NT_STATUS_UNSUCCESSFUL;
45 size = prs_data_size(&ps);
46 state->response.extra_data = SMB_MALLOC(size);
47 if (!state->response.extra_data) {
49 return NT_STATUS_NO_MEMORY;
51 memset( state->response.extra_data, '\0', size );
52 prs_copy_all_data_out(state->response.extra_data, &ps);
53 state->response.length += size;
58 static NTSTATUS check_info3_in_group(TALLOC_CTX *mem_ctx,
59 NET_USER_INFO_3 *info3,
60 const char *group_sid)
62 DOM_SID require_membership_of_sid;
64 size_t num_all_sids = (2 + info3->num_groups2 + info3->num_other_sids);
67 /* Parse the 'required group' SID */
69 if (!group_sid || !group_sid[0]) {
70 /* NO sid supplied, all users may access */
74 if (!string_to_sid(&require_membership_of_sid, group_sid)) {
75 DEBUG(0, ("check_info3_in_group: could not parse %s as a SID!",
78 return NT_STATUS_INVALID_PARAMETER;
81 all_sids = TALLOC_ARRAY(mem_ctx, DOM_SID, num_all_sids);
83 return NT_STATUS_NO_MEMORY;
85 /* and create (by appending rids) the 'domain' sids */
87 sid_copy(&all_sids[0], &(info3->dom_sid.sid));
89 if (!sid_append_rid(&all_sids[0], info3->user_rid)) {
90 DEBUG(3,("could not append user's primary RID 0x%x\n",
93 return NT_STATUS_INVALID_PARAMETER;
97 sid_copy(&all_sids[1], &(info3->dom_sid.sid));
99 if (!sid_append_rid(&all_sids[1], info3->group_rid)) {
100 DEBUG(3,("could not append additional group rid 0x%x\n",
103 return NT_STATUS_INVALID_PARAMETER;
107 for (i = 0; i < info3->num_groups2; i++) {
109 sid_copy(&all_sids[j], &(info3->dom_sid.sid));
111 if (!sid_append_rid(&all_sids[j], info3->gids[i].g_rid)) {
112 DEBUG(3,("could not append additional group rid 0x%x\n",
113 info3->gids[i].g_rid));
115 return NT_STATUS_INVALID_PARAMETER;
120 /* Copy 'other' sids. We need to do sid filtering here to
121 prevent possible elevation of privileges. See:
123 http://www.microsoft.com/windows2000/techinfo/administration/security/sidfilter.asp
126 for (i = 0; i < info3->num_other_sids; i++) {
127 sid_copy(&all_sids[info3->num_groups2 + i + 2],
128 &info3->other_sids[i].sid);
132 for (i = 0; i < j; i++) {
134 DEBUG(10, ("User has SID: %s\n",
135 sid_to_string(sid1, &all_sids[i])));
136 if (sid_equal(&require_membership_of_sid, &all_sids[i])) {
137 DEBUG(10, ("SID %s matches %s - user permitted to authenticate!\n",
138 sid_to_string(sid1, &require_membership_of_sid), sid_to_string(sid2, &all_sids[i])));
143 /* Do not distinguish this error from a wrong username/pw */
145 return NT_STATUS_LOGON_FAILURE;
148 static struct winbindd_domain *find_auth_domain(const char *domain_name)
150 struct winbindd_domain *domain;
153 domain = find_domain_from_name_noinit(domain_name);
154 if (domain == NULL) {
155 DEBUG(3, ("Authentication for domain [%s] "
156 "as it is not a trusted domain\n",
162 if (is_myname(domain_name)) {
163 DEBUG(3, ("Authentication for domain %s (local domain "
164 "to this server) not supported at this "
165 "stage\n", domain_name));
169 return find_our_domain();
172 static void set_auth_errors(struct winbindd_response *resp, NTSTATUS result)
174 resp->data.auth.nt_status = NT_STATUS_V(result);
175 fstrcpy(resp->data.auth.nt_status_string, nt_errstr(result));
177 /* we might have given a more useful error above */
178 if (*resp->data.auth.error_string == '\0')
179 fstrcpy(resp->data.auth.error_string,
180 get_friendly_nt_error_msg(result));
181 resp->data.auth.pam_error = nt_status_to_pam(result);
184 /**********************************************************************
185 Authenticate a user with a clear text password
186 **********************************************************************/
188 void winbindd_pam_auth(struct winbindd_cli_state *state)
190 struct winbindd_domain *domain;
191 fstring name_domain, name_user;
193 /* Ensure null termination */
194 state->request.data.auth.user
195 [sizeof(state->request.data.auth.user)-1]='\0';
197 /* Ensure null termination */
198 state->request.data.auth.pass
199 [sizeof(state->request.data.auth.pass)-1]='\0';
201 DEBUG(3, ("[%5lu]: pam auth %s\n", (unsigned long)state->pid,
202 state->request.data.auth.user));
204 /* Parse domain and username */
206 parse_domain_user(state->request.data.auth.user,
207 name_domain, name_user);
209 domain = find_auth_domain(name_domain);
211 if (domain == NULL) {
212 set_auth_errors(&state->response, NT_STATUS_NO_SUCH_USER);
213 DEBUG(5, ("Plain text authentication for %s returned %s "
215 state->request.data.auth.user,
216 state->response.data.auth.nt_status_string,
217 state->response.data.auth.pam_error));
218 request_error(state);
222 sendto_domain(state, domain);
225 enum winbindd_result winbindd_dual_pam_auth(struct winbindd_domain *domain,
226 struct winbindd_cli_state *state)
229 fstring name_domain, name_user;
230 const char *srv_name_slash;
231 NET_USER_INFO_3 info3;
232 unsigned char *session_key;
233 struct rpc_pipe_client *pipe_cli;
238 DOM_CRED *credentials;
240 unsigned char local_lm_response[24];
241 unsigned char local_nt_response[24];
242 struct winbindd_domain *contact_domain;
245 /* Ensure null termination */
246 state->request.data.auth.user[sizeof(state->request.data.auth.user)-1]='\0';
248 /* Ensure null termination */
249 state->request.data.auth.pass[sizeof(state->request.data.auth.pass)-1]='\0';
251 DEBUG(3, ("[%5lu]: pam auth %s\n", (unsigned long)state->pid,
252 state->request.data.auth.user));
254 /* Parse domain and username */
256 parse_domain_user(state->request.data.auth.user, name_domain, name_user);
258 /* do password magic */
261 generate_random_buffer(chal, 8);
262 if (lp_client_ntlmv2_auth()) {
263 DATA_BLOB server_chal;
264 DATA_BLOB names_blob;
265 DATA_BLOB nt_response;
266 DATA_BLOB lm_response;
267 server_chal = data_blob_talloc(state->mem_ctx, chal, 8);
269 /* note that the 'workgroup' here is a best guess - we don't know
270 the server's domain at this point. The 'server name' is also
273 names_blob = NTLMv2_generate_names_blob(global_myname(), lp_workgroup());
275 if (!SMBNTLMv2encrypt(name_user, name_domain,
276 state->request.data.auth.pass,
279 &lm_response, &nt_response, NULL)) {
280 data_blob_free(&names_blob);
281 data_blob_free(&server_chal);
282 DEBUG(0, ("winbindd_pam_auth: SMBNTLMv2encrypt() failed!\n"));
283 result = NT_STATUS_NO_MEMORY;
286 data_blob_free(&names_blob);
287 data_blob_free(&server_chal);
288 lm_resp = data_blob_talloc(state->mem_ctx, lm_response.data,
290 nt_resp = data_blob_talloc(state->mem_ctx, nt_response.data,
292 data_blob_free(&lm_response);
293 data_blob_free(&nt_response);
296 if (lp_client_lanman_auth()
297 && SMBencrypt(state->request.data.auth.pass,
299 local_lm_response)) {
300 lm_resp = data_blob_talloc(state->mem_ctx,
302 sizeof(local_lm_response));
304 lm_resp = data_blob(NULL, 0);
306 SMBNTencrypt(state->request.data.auth.pass,
310 nt_resp = data_blob_talloc(state->mem_ctx,
312 sizeof(local_nt_response));
316 /* what domain should we contact? */
319 if (!(contact_domain = find_domain_from_name(name_domain))) {
320 DEBUG(3, ("Authentication for domain for [%s] -> [%s]\\[%s] failed as %s is not a trusted domain\n",
321 state->request.data.auth.user, name_domain, name_user, name_domain));
322 result = NT_STATUS_NO_SUCH_USER;
327 if (is_myname(name_domain)) {
328 DEBUG(3, ("Authentication for domain %s (local domain to this server) not supported at this stage\n", name_domain));
329 result = NT_STATUS_NO_SUCH_USER;
333 contact_domain = find_our_domain();
336 srv_name_slash = talloc_asprintf(state->mem_ctx, "\\\\%s",
337 contact_domain->dcname);
338 if (srv_name_slash == NULL) {
339 DEBUG(0, ("talloc_asprintf failed\n"));
340 return WINBINDD_ERROR;
343 /* check authentication loop */
349 ZERO_STRUCT(ret_creds);
352 result = cm_connect_netlogon(contact_domain, state->mem_ctx,
353 &pipe_cli, &session_key,
356 if (!NT_STATUS_IS_OK(result)) {
357 DEBUG(3, ("could not open handle to NETLOGON pipe\n"));
361 credentials->timestamp.time = time(NULL);
362 memcpy(&clnt_creds, credentials, sizeof(clnt_creds));
364 /* Calculate the new credentials. */
365 cred_create(session_key, &credentials->challenge,
366 clnt_creds.timestamp, &(clnt_creds.challenge));
368 result = rpccli_netlogon_sam_network_logon(pipe_cli,
381 /* We have to try a second time as cm_connect_netlogon
382 might not yet have noticed that the DC has killed
385 if (NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL)) {
390 /* if we get access denied, a possible cause was that we had
391 and open connection to the DC, but someone changed our
392 machine account password out from underneath us using 'net
393 rpc changetrustpw' */
395 if ( NT_STATUS_EQUAL(result, NT_STATUS_ACCESS_DENIED) ) {
396 DEBUG(3,("winbindd_pam_auth: sam_logon returned "
397 "ACCESS_DENIED. Maybe the trust account "
398 "password was changed and we didn't know it. "
399 "Killing connections to domain %s\n",
401 invalidate_cm_connection(&contact_domain->conn);
405 } while ( (attempts < 2) && retry );
407 /* Only check creds if we got a connection. */
408 if (contact_domain->conn.cli &&
409 !(NT_STATUS_EQUAL(result, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND) ||
410 NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL))) {
411 if (!clnt_deal_with_creds(session_key, credentials, &ret_creds)) {
412 DEBUG(3, ("DC %s sent wrong credentials\n",
413 pipe_cli->cli->srv_name_slash));
414 result = NT_STATUS_ACCESS_DENIED;
418 if (NT_STATUS_IS_OK(result)) {
419 /* Check if the user is in the right group */
421 if (!NT_STATUS_IS_OK(result = check_info3_in_group(state->mem_ctx, &info3, state->request.data.auth.require_membership_of_sid))) {
422 DEBUG(3, ("User %s is not in the required group (%s), so plaintext authentication is rejected\n",
423 state->request.data.auth.user,
424 state->request.data.auth.require_membership_of_sid));
429 /* give us a more useful (more correct?) error code */
430 if ((NT_STATUS_EQUAL(result, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND) || (NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL)))) {
431 result = NT_STATUS_NO_LOGON_SERVERS;
434 state->response.data.auth.nt_status = NT_STATUS_V(result);
435 fstrcpy(state->response.data.auth.nt_status_string, nt_errstr(result));
437 /* we might have given a more useful error above */
438 if (!*state->response.data.auth.error_string)
439 fstrcpy(state->response.data.auth.error_string, get_friendly_nt_error_msg(result));
440 state->response.data.auth.pam_error = nt_status_to_pam(result);
442 DEBUG(NT_STATUS_IS_OK(result) ? 5 : 2, ("Plain-text authentication for user %s returned %s (PAM: %d)\n",
443 state->request.data.auth.user,
444 state->response.data.auth.nt_status_string,
445 state->response.data.auth.pam_error));
447 if ( NT_STATUS_IS_OK(result) &&
448 (state->request.flags & WBFLAG_PAM_AFS_TOKEN) ) {
450 char *afsname = SMB_STRDUP(lp_afs_username_map());
453 if (afsname == NULL) goto no_token;
455 afsname = realloc_string_sub(afsname, "%D", name_domain);
456 afsname = realloc_string_sub(afsname, "%u", name_user);
457 afsname = realloc_string_sub(afsname, "%U", name_user);
463 sid_copy(&user_sid, &info3.dom_sid.sid);
464 sid_append_rid(&user_sid, info3.user_rid);
465 sid_to_string(sidstr, &user_sid);
466 afsname = realloc_string_sub(afsname, "%s", sidstr);
469 if (afsname == NULL) goto no_token;
473 DEBUG(10, ("Generating token for user %s\n", afsname));
475 cell = strchr(afsname, '@');
477 if (cell == NULL) goto no_token;
482 /* Append an AFS token string */
483 state->response.extra_data =
484 afs_createtoken_str(afsname, cell);
486 if (state->response.extra_data != NULL)
487 state->response.length +=
488 strlen(state->response.extra_data)+1;
494 return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
497 /**********************************************************************
498 Challenge Response Authentication Protocol
499 **********************************************************************/
501 void winbindd_pam_auth_crap(struct winbindd_cli_state *state)
503 struct winbindd_domain *domain = NULL;
504 const char *domain_name = NULL;
507 if (!state->privileged) {
508 char *error_string = NULL;
509 DEBUG(2, ("winbindd_pam_auth_crap: non-privileged access "
511 DEBUGADD(2, ("winbindd_pam_auth_crap: Ensure permissions "
512 "on %s are set correctly.\n",
513 get_winbind_priv_pipe_dir()));
514 /* send a better message than ACCESS_DENIED */
515 error_string = talloc_asprintf(state->mem_ctx,
516 "winbind client not authorized "
517 "to use winbindd_pam_auth_crap."
518 " Ensure permissions on %s "
519 "are set correctly.",
520 get_winbind_priv_pipe_dir());
521 fstrcpy(state->response.data.auth.error_string, error_string);
522 result = NT_STATUS_ACCESS_DENIED;
526 /* Ensure null termination */
527 state->request.data.auth_crap.user
528 [sizeof(state->request.data.auth_crap.user)-1]=0;
529 state->request.data.auth_crap.domain
530 [sizeof(state->request.data.auth_crap.domain)-1]=0;
532 DEBUG(3, ("[%5lu]: pam auth crap domain: [%s] user: %s\n",
533 (unsigned long)state->pid,
534 state->request.data.auth_crap.domain,
535 state->request.data.auth_crap.user));
537 if (*state->request.data.auth_crap.domain != '\0') {
538 domain_name = state->request.data.auth_crap.domain;
539 } else if (lp_winbind_use_default_domain()) {
540 domain_name = lp_workgroup();
543 if (domain_name != NULL)
544 domain = find_auth_domain(domain_name);
546 if (domain != NULL) {
547 sendto_domain(state, domain);
551 result = NT_STATUS_NO_SUCH_USER;
554 set_auth_errors(&state->response, result);
555 DEBUG(5, ("CRAP authentication for %s returned %s (PAM: %d)\n",
556 state->request.data.auth.user,
557 state->response.data.auth.nt_status_string,
558 state->response.data.auth.pam_error));
559 request_error(state);
564 enum winbindd_result winbindd_dual_pam_auth_crap(struct winbindd_domain *domain,
565 struct winbindd_cli_state *state)
568 const char *srv_name_slash;
569 NET_USER_INFO_3 info3;
570 unsigned char *session_key;
571 struct rpc_pipe_client *pipe_cli;
572 DOM_CRED *credentials;
573 const char *name_user = NULL;
574 const char *name_domain = NULL;
575 const char *workstation;
576 struct winbindd_domain *contact_domain;
581 DATA_BLOB lm_resp, nt_resp;
583 /* This is child-only, so no check for privileged access is needed
586 /* Ensure null termination */
587 state->request.data.auth_crap.user[sizeof(state->request.data.auth_crap.user)-1]=0;
588 state->request.data.auth_crap.domain[sizeof(state->request.data.auth_crap.domain)-1]=0;
590 name_user = state->request.data.auth_crap.user;
592 if (*state->request.data.auth_crap.domain) {
593 name_domain = state->request.data.auth_crap.domain;
594 } else if (lp_winbind_use_default_domain()) {
595 name_domain = lp_workgroup();
597 DEBUG(5,("no domain specified with username (%s) - failing auth\n",
599 result = NT_STATUS_NO_SUCH_USER;
603 DEBUG(3, ("[%5lu]: pam auth crap domain: %s user: %s\n", (unsigned long)state->pid,
604 name_domain, name_user));
606 if (*state->request.data.auth_crap.workstation) {
607 workstation = state->request.data.auth_crap.workstation;
609 workstation = global_myname();
612 if (state->request.data.auth_crap.lm_resp_len > sizeof(state->request.data.auth_crap.lm_resp)
613 || state->request.data.auth_crap.nt_resp_len > sizeof(state->request.data.auth_crap.nt_resp)) {
614 DEBUG(0, ("winbindd_pam_auth_crap: invalid password length %u/%u\n",
615 state->request.data.auth_crap.lm_resp_len,
616 state->request.data.auth_crap.nt_resp_len));
617 result = NT_STATUS_INVALID_PARAMETER;
621 lm_resp = data_blob_talloc(state->mem_ctx, state->request.data.auth_crap.lm_resp, state->request.data.auth_crap.lm_resp_len);
622 nt_resp = data_blob_talloc(state->mem_ctx, state->request.data.auth_crap.nt_resp, state->request.data.auth_crap.nt_resp_len);
625 /* what domain should we contact? */
628 if (!(contact_domain = find_domain_from_name(name_domain))) {
629 DEBUG(3, ("Authentication for domain for [%s] -> [%s]\\[%s] failed as %s is not a trusted domain\n",
630 state->request.data.auth_crap.user, name_domain, name_user, name_domain));
631 result = NT_STATUS_NO_SUCH_USER;
636 if (is_myname(name_domain)) {
637 DEBUG(3, ("Authentication for domain %s (local domain to this server) not supported at this stage\n", name_domain));
638 result = NT_STATUS_NO_SUCH_USER;
642 contact_domain = find_our_domain();
645 srv_name_slash = talloc_asprintf(state->mem_ctx, "\\\\%s",
646 contact_domain->dcname);
647 if (srv_name_slash == NULL) {
648 DEBUG(0, ("talloc_asprintf failed\n"));
649 return WINBINDD_ERROR;
655 ZERO_STRUCT(ret_creds);
658 result = cm_connect_netlogon(contact_domain, state->mem_ctx,
659 &pipe_cli, &session_key,
662 if (!NT_STATUS_IS_OK(result)) {
663 DEBUG(3, ("could not open handle to NETLOGON pipe (error: %s)\n",
668 credentials->timestamp.time = time(NULL);
669 memcpy(&clnt_creds, credentials, sizeof(clnt_creds));
671 /* Calculate the new credentials. */
672 cred_create(session_key, &credentials->challenge,
673 clnt_creds.timestamp, &(clnt_creds.challenge));
675 result = rpccli_netlogon_sam_network_logon(pipe_cli,
683 state->request.data.auth_crap.chal,
690 /* We have to try a second time as cm_connect_netlogon
691 might not yet have noticed that the DC has killed
694 if (NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL)) {
699 /* if we get access denied, a possible cause was that we had and open
700 connection to the DC, but someone changed our machine account password
701 out from underneath us using 'net rpc changetrustpw' */
703 if ( NT_STATUS_EQUAL(result, NT_STATUS_ACCESS_DENIED) ) {
704 DEBUG(3,("winbindd_pam_auth: sam_logon returned "
705 "ACCESS_DENIED. Maybe the trust account "
706 "password was changed and we didn't know it. "
707 "Killing connections to domain %s\n",
709 invalidate_cm_connection(&contact_domain->conn);
713 } while ( (attempts < 2) && retry );
715 /* Only check creds if we got a connection. */
716 if (contact_domain->conn.cli &&
717 !(NT_STATUS_EQUAL(result, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND) ||
718 (NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL)))) {
719 if (!clnt_deal_with_creds(session_key, credentials, &ret_creds)) {
720 DEBUG(3, ("DC %s sent wrong credentials\n",
721 pipe_cli->cli->srv_name_slash));
722 result = NT_STATUS_ACCESS_DENIED;
726 if (NT_STATUS_IS_OK(result)) {
727 if (!NT_STATUS_IS_OK(result = check_info3_in_group(state->mem_ctx, &info3, state->request.data.auth_crap.require_membership_of_sid))) {
728 DEBUG(3, ("User %s is not in the required group (%s), so plaintext authentication is rejected\n",
729 state->request.data.auth_crap.user,
730 state->request.data.auth_crap.require_membership_of_sid));
734 if (state->request.flags & WBFLAG_PAM_INFO3_NDR) {
735 result = append_info3_as_ndr(state->mem_ctx, state, &info3);
736 } else if (state->request.flags & WBFLAG_PAM_UNIX_NAME) {
737 /* ntlm_auth should return the unix username, per
738 'winbind use default domain' settings and the like */
740 fstring username_out;
741 const char *nt_username, *nt_domain;
742 if (!(nt_username = unistr2_tdup(state->mem_ctx, &(info3.uni_user_name)))) {
743 /* If the server didn't give us one, just use the one we sent them */
744 nt_username = name_user;
747 if (!(nt_domain = unistr2_tdup(state->mem_ctx, &(info3.uni_logon_dom)))) {
748 /* If the server didn't give us one, just use the one we sent them */
749 nt_domain = name_domain;
752 fill_domain_username(username_out, nt_domain, nt_username);
754 DEBUG(5, ("Setting unix username to [%s]\n", username_out));
756 state->response.extra_data = SMB_STRDUP(username_out);
757 if (!state->response.extra_data) {
758 result = NT_STATUS_NO_MEMORY;
761 state->response.length += strlen(state->response.extra_data)+1;
764 if (state->request.flags & WBFLAG_PAM_USER_SESSION_KEY) {
765 memcpy(state->response.data.auth.user_session_key, info3.user_sess_key, sizeof(state->response.data.auth.user_session_key) /* 16 */);
767 if (state->request.flags & WBFLAG_PAM_LMKEY) {
768 memcpy(state->response.data.auth.first_8_lm_hash, info3.lm_sess_key, sizeof(state->response.data.auth.first_8_lm_hash) /* 8 */);
773 /* give us a more useful (more correct?) error code */
774 if ((NT_STATUS_EQUAL(result, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND) || (NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL)))) {
775 result = NT_STATUS_NO_LOGON_SERVERS;
778 if (state->request.flags & WBFLAG_PAM_NT_STATUS_SQUASH) {
779 result = nt_status_squash(result);
782 state->response.data.auth.nt_status = NT_STATUS_V(result);
783 fstrcpy(state->response.data.auth.nt_status_string, nt_errstr(result));
785 /* we might have given a more useful error above */
786 if (!*state->response.data.auth.error_string)
787 fstrcpy(state->response.data.auth.error_string, get_friendly_nt_error_msg(result));
788 state->response.data.auth.pam_error = nt_status_to_pam(result);
790 DEBUG(NT_STATUS_IS_OK(result) ? 5 : 2,
791 ("NTLM CRAP authentication for user [%s]\\[%s] returned %s (PAM: %d)\n",
794 state->response.data.auth.nt_status_string,
795 state->response.data.auth.pam_error));
797 return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
800 /* Change a user password */
802 void winbindd_pam_chauthtok(struct winbindd_cli_state *state)
805 char *oldpass, *newpass;
806 fstring domain, user;
808 struct winbindd_domain *contact_domain;
809 struct rpc_pipe_client *cli;
811 DEBUG(3, ("[%5lu]: pam chauthtok %s\n", (unsigned long)state->pid,
812 state->request.data.chauthtok.user));
816 parse_domain_user(state->request.data.chauthtok.user, domain, user);
818 if (!(contact_domain = find_domain_from_name(domain))) {
819 DEBUG(3, ("Cannot change password for [%s] -> [%s]\\[%s] as %s is not a trusted domain\n",
820 state->request.data.chauthtok.user, domain, user, domain));
821 result = NT_STATUS_NO_SUCH_USER;
825 /* Change password */
827 oldpass = state->request.data.chauthtok.oldpass;
828 newpass = state->request.data.chauthtok.newpass;
832 result = cm_connect_sam(contact_domain, state->mem_ctx, &cli,
834 if (!NT_STATUS_IS_OK(result)) {
835 DEBUG(1, ("could not get SAM handle on DC for %s\n", domain));
839 result = rpccli_samr_chgpasswd_user(cli, state->mem_ctx, user, newpass,
843 state->response.data.auth.nt_status = NT_STATUS_V(result);
844 fstrcpy(state->response.data.auth.nt_status_string, nt_errstr(result));
845 fstrcpy(state->response.data.auth.error_string, nt_errstr(result));
846 state->response.data.auth.pam_error = nt_status_to_pam(result);
848 DEBUG(NT_STATUS_IS_OK(result) ? 5 : 2,
849 ("Password change for user [%s]\\[%s] returned %s (PAM: %d)\n",
852 state->response.data.auth.nt_status_string,
853 state->response.data.auth.pam_error));
855 if (NT_STATUS_IS_OK(result))
858 request_error(state);