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 enum winbindd_result
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 return WINBINDD_ERROR
;
221 async_domain_request(state
->mem_ctx
, domain
,
222 &state
->request
, &state
->response
,
223 request_finished_cont
, state
);
224 return WINBINDD_PENDING
;
227 enum winbindd_result
winbindd_dual_pam_auth(struct winbindd_domain
*domain
,
228 struct winbindd_cli_state
*state
)
231 fstring name_domain
, name_user
;
232 const char *srv_name_slash
;
233 NET_USER_INFO_3 info3
;
234 unsigned char *session_key
;
235 struct rpc_pipe_client
*pipe_cli
;
240 DOM_CRED
*credentials
;
242 unsigned char local_lm_response
[24];
243 unsigned char local_nt_response
[24];
244 struct winbindd_domain
*contact_domain
;
247 /* Ensure null termination */
248 state
->request
.data
.auth
.user
[sizeof(state
->request
.data
.auth
.user
)-1]='\0';
250 /* Ensure null termination */
251 state
->request
.data
.auth
.pass
[sizeof(state
->request
.data
.auth
.pass
)-1]='\0';
253 DEBUG(3, ("[%5lu]: pam auth %s\n", (unsigned long)state
->pid
,
254 state
->request
.data
.auth
.user
));
256 /* Parse domain and username */
258 parse_domain_user(state
->request
.data
.auth
.user
, name_domain
, name_user
);
260 /* do password magic */
263 generate_random_buffer(chal
, 8);
264 if (lp_client_ntlmv2_auth()) {
265 DATA_BLOB server_chal
;
266 DATA_BLOB names_blob
;
267 DATA_BLOB nt_response
;
268 DATA_BLOB lm_response
;
269 server_chal
= data_blob_talloc(state
->mem_ctx
, chal
, 8);
271 /* note that the 'workgroup' here is a best guess - we don't know
272 the server's domain at this point. The 'server name' is also
275 names_blob
= NTLMv2_generate_names_blob(global_myname(), lp_workgroup());
277 if (!SMBNTLMv2encrypt(name_user
, name_domain
,
278 state
->request
.data
.auth
.pass
,
281 &lm_response
, &nt_response
, NULL
)) {
282 data_blob_free(&names_blob
);
283 data_blob_free(&server_chal
);
284 DEBUG(0, ("winbindd_pam_auth: SMBNTLMv2encrypt() failed!\n"));
285 result
= NT_STATUS_NO_MEMORY
;
288 data_blob_free(&names_blob
);
289 data_blob_free(&server_chal
);
290 lm_resp
= data_blob_talloc(state
->mem_ctx
, lm_response
.data
,
292 nt_resp
= data_blob_talloc(state
->mem_ctx
, nt_response
.data
,
294 data_blob_free(&lm_response
);
295 data_blob_free(&nt_response
);
298 if (lp_client_lanman_auth()
299 && SMBencrypt(state
->request
.data
.auth
.pass
,
301 local_lm_response
)) {
302 lm_resp
= data_blob_talloc(state
->mem_ctx
,
304 sizeof(local_lm_response
));
306 lm_resp
= data_blob(NULL
, 0);
308 SMBNTencrypt(state
->request
.data
.auth
.pass
,
312 nt_resp
= data_blob_talloc(state
->mem_ctx
,
314 sizeof(local_nt_response
));
318 /* what domain should we contact? */
321 if (!(contact_domain
= find_domain_from_name(name_domain
))) {
322 DEBUG(3, ("Authentication for domain for [%s] -> [%s]\\[%s] failed as %s is not a trusted domain\n",
323 state
->request
.data
.auth
.user
, name_domain
, name_user
, name_domain
));
324 result
= NT_STATUS_NO_SUCH_USER
;
329 if (is_myname(name_domain
)) {
330 DEBUG(3, ("Authentication for domain %s (local domain to this server) not supported at this stage\n", name_domain
));
331 result
= NT_STATUS_NO_SUCH_USER
;
335 contact_domain
= find_our_domain();
338 srv_name_slash
= talloc_asprintf(state
->mem_ctx
, "\\\\%s",
339 contact_domain
->dcname
);
340 if (srv_name_slash
== NULL
) {
341 DEBUG(0, ("talloc_asprintf failed\n"));
342 return WINBINDD_ERROR
;
345 /* check authentication loop */
351 ZERO_STRUCT(ret_creds
);
354 result
= cm_connect_netlogon(contact_domain
, state
->mem_ctx
,
355 &pipe_cli
, &session_key
,
358 if (!NT_STATUS_IS_OK(result
)) {
359 DEBUG(3, ("could not open handle to NETLOGON pipe\n"));
363 credentials
->timestamp
.time
= time(NULL
);
364 memcpy(&clnt_creds
, credentials
, sizeof(clnt_creds
));
366 /* Calculate the new credentials. */
367 cred_create(session_key
, &credentials
->challenge
,
368 clnt_creds
.timestamp
, &(clnt_creds
.challenge
));
370 result
= rpccli_netlogon_sam_network_logon(pipe_cli
,
383 /* We have to try a second time as cm_connect_netlogon
384 might not yet have noticed that the DC has killed
387 if (NT_STATUS_EQUAL(result
, NT_STATUS_UNSUCCESSFUL
)) {
392 /* if we get access denied, a possible cause was that we had
393 and open connection to the DC, but someone changed our
394 machine account password out from underneath us using 'net
395 rpc changetrustpw' */
397 if ( NT_STATUS_EQUAL(result
, NT_STATUS_ACCESS_DENIED
) ) {
398 DEBUG(3,("winbindd_pam_auth: sam_logon returned "
399 "ACCESS_DENIED. Maybe the trust account "
400 "password was changed and we didn't know it. "
401 "Killing connections to domain %s\n",
403 invalidate_cm_connection(&contact_domain
->conn
);
407 } while ( (attempts
< 2) && retry
);
409 if (NT_STATUS_IS_OK(result
) &&
410 (!clnt_deal_with_creds(session_key
, credentials
,
412 DEBUG(3, ("DC %s sent wrong credentials\n",
413 pipe_cli
->cli
->srv_name_slash
));
414 result
= NT_STATUS_ACCESS_DENIED
;
417 if (NT_STATUS_IS_OK(result
)) {
418 netsamlogon_cache_store(state
->mem_ctx
, name_user
, &info3
);
419 wcache_invalidate_samlogon(find_domain_from_name(name_domain
), &info3
);
421 /* Check if the user is in the right group */
423 if (!NT_STATUS_IS_OK(result
= check_info3_in_group(state
->mem_ctx
, &info3
, state
->request
.data
.auth
.require_membership_of_sid
))) {
424 DEBUG(3, ("User %s is not in the required group (%s), so plaintext authentication is rejected\n",
425 state
->request
.data
.auth
.user
,
426 state
->request
.data
.auth
.require_membership_of_sid
));
431 /* give us a more useful (more correct?) error code */
432 if ((NT_STATUS_EQUAL(result
, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
) || (NT_STATUS_EQUAL(result
, NT_STATUS_UNSUCCESSFUL
)))) {
433 result
= NT_STATUS_NO_LOGON_SERVERS
;
436 state
->response
.data
.auth
.nt_status
= NT_STATUS_V(result
);
437 fstrcpy(state
->response
.data
.auth
.nt_status_string
, nt_errstr(result
));
439 /* we might have given a more useful error above */
440 if (!*state
->response
.data
.auth
.error_string
)
441 fstrcpy(state
->response
.data
.auth
.error_string
, get_friendly_nt_error_msg(result
));
442 state
->response
.data
.auth
.pam_error
= nt_status_to_pam(result
);
444 DEBUG(NT_STATUS_IS_OK(result
) ? 5 : 2, ("Plain-text authentication for user %s returned %s (PAM: %d)\n",
445 state
->request
.data
.auth
.user
,
446 state
->response
.data
.auth
.nt_status_string
,
447 state
->response
.data
.auth
.pam_error
));
449 if ( NT_STATUS_IS_OK(result
) &&
450 (state
->request
.flags
& WBFLAG_PAM_AFS_TOKEN
) ) {
452 char *afsname
= SMB_STRDUP(lp_afs_username_map());
455 if (afsname
== NULL
) goto no_token
;
457 afsname
= realloc_string_sub(afsname
, "%D", name_domain
);
458 afsname
= realloc_string_sub(afsname
, "%u", name_user
);
459 afsname
= realloc_string_sub(afsname
, "%U", name_user
);
465 sid_copy(&user_sid
, &info3
.dom_sid
.sid
);
466 sid_append_rid(&user_sid
, info3
.user_rid
);
467 sid_to_string(sidstr
, &user_sid
);
468 afsname
= realloc_string_sub(afsname
, "%s", sidstr
);
471 if (afsname
== NULL
) goto no_token
;
475 DEBUG(10, ("Generating token for user %s\n", afsname
));
477 cell
= strchr(afsname
, '@');
479 if (cell
== NULL
) goto no_token
;
484 /* Append an AFS token string */
485 state
->response
.extra_data
=
486 afs_createtoken_str(afsname
, cell
);
488 if (state
->response
.extra_data
!= NULL
)
489 state
->response
.length
+=
490 strlen(state
->response
.extra_data
)+1;
496 return NT_STATUS_IS_OK(result
) ? WINBINDD_OK
: WINBINDD_ERROR
;
499 /**********************************************************************
500 Challenge Response Authentication Protocol
501 **********************************************************************/
503 enum winbindd_result
winbindd_crap_auth(struct winbindd_cli_state
*state
)
505 struct winbindd_domain
*domain
= NULL
;
506 const char *domain_name
= NULL
;
509 if (!state
->privileged
) {
510 char *error_string
= NULL
;
511 DEBUG(2, ("winbindd_pam_auth_crap: non-privileged access "
513 DEBUGADD(2, ("winbindd_pam_auth_crap: Ensure permissions "
514 "on %s are set correctly.\n",
515 get_winbind_priv_pipe_dir()));
516 /* send a better message than ACCESS_DENIED */
517 error_string
= talloc_asprintf(state
->mem_ctx
,
518 "winbind client not authorized "
519 "to use winbindd_pam_auth_crap."
520 " Ensure permissions on %s "
521 "are set correctly.",
522 get_winbind_priv_pipe_dir());
523 fstrcpy(state
->response
.data
.auth
.error_string
, error_string
);
524 result
= NT_STATUS_ACCESS_DENIED
;
528 /* Ensure null termination */
529 state
->request
.data
.auth_crap
.user
530 [sizeof(state
->request
.data
.auth_crap
.user
)-1]=0;
531 state
->request
.data
.auth_crap
.domain
532 [sizeof(state
->request
.data
.auth_crap
.domain
)-1]=0;
534 DEBUG(3, ("[%5lu]: pam auth crap domain: [%s] user: %s\n",
535 (unsigned long)state
->pid
,
536 state
->request
.data
.auth_crap
.domain
,
537 state
->request
.data
.auth_crap
.user
));
539 if (*state
->request
.data
.auth_crap
.domain
!= '\0') {
540 domain_name
= state
->request
.data
.auth_crap
.domain
;
541 } else if (lp_winbind_use_default_domain()) {
542 domain_name
= lp_workgroup();
545 if (domain_name
!= NULL
)
546 domain
= find_auth_domain(domain_name
);
548 if (domain
!= NULL
) {
549 async_domain_request(state
->mem_ctx
, domain
,
550 &state
->request
, &state
->response
,
551 request_finished_cont
, state
);
552 return WINBINDD_PENDING
;
555 result
= NT_STATUS_NO_SUCH_USER
;
558 set_auth_errors(&state
->response
, result
);
559 DEBUG(5, ("CRAP authentication for %s returned %s (PAM: %d)\n",
560 state
->request
.data
.auth
.user
,
561 state
->response
.data
.auth
.nt_status_string
,
562 state
->response
.data
.auth
.pam_error
));
563 return WINBINDD_ERROR
;
567 enum winbindd_result
winbindd_dual_pam_auth_crap(struct winbindd_domain
*domain
,
568 struct winbindd_cli_state
*state
)
571 const char *srv_name_slash
;
572 NET_USER_INFO_3 info3
;
573 unsigned char *session_key
;
574 struct rpc_pipe_client
*pipe_cli
;
575 DOM_CRED
*credentials
;
576 const char *name_user
= NULL
;
577 const char *name_domain
= NULL
;
578 const char *workstation
;
579 struct winbindd_domain
*contact_domain
;
584 DATA_BLOB lm_resp
, nt_resp
;
586 /* This is child-only, so no check for privileged access is needed
589 /* Ensure null termination */
590 state
->request
.data
.auth_crap
.user
[sizeof(state
->request
.data
.auth_crap
.user
)-1]=0;
591 state
->request
.data
.auth_crap
.domain
[sizeof(state
->request
.data
.auth_crap
.domain
)-1]=0;
593 name_user
= state
->request
.data
.auth_crap
.user
;
595 if (*state
->request
.data
.auth_crap
.domain
) {
596 name_domain
= state
->request
.data
.auth_crap
.domain
;
597 } else if (lp_winbind_use_default_domain()) {
598 name_domain
= lp_workgroup();
600 DEBUG(5,("no domain specified with username (%s) - failing auth\n",
602 result
= NT_STATUS_NO_SUCH_USER
;
606 DEBUG(3, ("[%5lu]: pam auth crap domain: %s user: %s\n", (unsigned long)state
->pid
,
607 name_domain
, name_user
));
609 if (*state
->request
.data
.auth_crap
.workstation
) {
610 workstation
= state
->request
.data
.auth_crap
.workstation
;
612 workstation
= global_myname();
615 if (state
->request
.data
.auth_crap
.lm_resp_len
> sizeof(state
->request
.data
.auth_crap
.lm_resp
)
616 || state
->request
.data
.auth_crap
.nt_resp_len
> sizeof(state
->request
.data
.auth_crap
.nt_resp
)) {
617 DEBUG(0, ("winbindd_pam_auth_crap: invalid password length %u/%u\n",
618 state
->request
.data
.auth_crap
.lm_resp_len
,
619 state
->request
.data
.auth_crap
.nt_resp_len
));
620 result
= NT_STATUS_INVALID_PARAMETER
;
624 lm_resp
= data_blob_talloc(state
->mem_ctx
, state
->request
.data
.auth_crap
.lm_resp
, state
->request
.data
.auth_crap
.lm_resp_len
);
625 nt_resp
= data_blob_talloc(state
->mem_ctx
, state
->request
.data
.auth_crap
.nt_resp
, state
->request
.data
.auth_crap
.nt_resp_len
);
628 /* what domain should we contact? */
631 if (!(contact_domain
= find_domain_from_name(name_domain
))) {
632 DEBUG(3, ("Authentication for domain for [%s] -> [%s]\\[%s] failed as %s is not a trusted domain\n",
633 state
->request
.data
.auth_crap
.user
, name_domain
, name_user
, name_domain
));
634 result
= NT_STATUS_NO_SUCH_USER
;
639 if (is_myname(name_domain
)) {
640 DEBUG(3, ("Authentication for domain %s (local domain to this server) not supported at this stage\n", name_domain
));
641 result
= NT_STATUS_NO_SUCH_USER
;
645 contact_domain
= find_our_domain();
648 srv_name_slash
= talloc_asprintf(state
->mem_ctx
, "\\\\%s",
649 contact_domain
->dcname
);
650 if (srv_name_slash
== NULL
) {
651 DEBUG(0, ("talloc_asprintf failed\n"));
652 return WINBINDD_ERROR
;
658 ZERO_STRUCT(ret_creds
);
661 result
= cm_connect_netlogon(contact_domain
, state
->mem_ctx
,
662 &pipe_cli
, &session_key
,
665 if (!NT_STATUS_IS_OK(result
)) {
666 DEBUG(3, ("could not open handle to NETLOGON pipe (error: %s)\n",
671 credentials
->timestamp
.time
= time(NULL
);
672 memcpy(&clnt_creds
, credentials
, sizeof(clnt_creds
));
674 /* Calculate the new credentials. */
675 cred_create(session_key
, &credentials
->challenge
,
676 clnt_creds
.timestamp
, &(clnt_creds
.challenge
));
678 result
= rpccli_netlogon_sam_network_logon(pipe_cli
,
686 state
->request
.data
.auth_crap
.chal
,
693 /* We have to try a second time as cm_connect_netlogon
694 might not yet have noticed that the DC has killed
697 if (NT_STATUS_EQUAL(result
, NT_STATUS_UNSUCCESSFUL
)) {
702 /* if we get access denied, a possible cause was that we had and open
703 connection to the DC, but someone changed our machine account password
704 out from underneath us using 'net rpc changetrustpw' */
706 if ( NT_STATUS_EQUAL(result
, NT_STATUS_ACCESS_DENIED
) ) {
707 DEBUG(3,("winbindd_pam_auth: sam_logon returned "
708 "ACCESS_DENIED. Maybe the trust account "
709 "password was changed and we didn't know it. "
710 "Killing connections to domain %s\n",
712 invalidate_cm_connection(&contact_domain
->conn
);
716 } while ( (attempts
< 2) && retry
);
718 if (NT_STATUS_IS_OK(result
) &&
719 (!clnt_deal_with_creds(session_key
, credentials
,
721 DEBUG(3, ("DC %s sent wrong credentials\n",
722 pipe_cli
->cli
->srv_name_slash
));
723 result
= NT_STATUS_ACCESS_DENIED
;
726 if (NT_STATUS_IS_OK(result
)) {
727 netsamlogon_cache_store( state
->mem_ctx
, name_user
, &info3
);
728 wcache_invalidate_samlogon(find_domain_from_name(name_domain
), &info3
);
730 if (!NT_STATUS_IS_OK(result
= check_info3_in_group(state
->mem_ctx
, &info3
, state
->request
.data
.auth_crap
.require_membership_of_sid
))) {
731 DEBUG(3, ("User %s is not in the required group (%s), so plaintext authentication is rejected\n",
732 state
->request
.data
.auth_crap
.user
,
733 state
->request
.data
.auth_crap
.require_membership_of_sid
));
737 if (state
->request
.flags
& WBFLAG_PAM_INFO3_NDR
) {
738 result
= append_info3_as_ndr(state
->mem_ctx
, state
, &info3
);
739 } else if (state
->request
.flags
& WBFLAG_PAM_UNIX_NAME
) {
740 /* ntlm_auth should return the unix username, per
741 'winbind use default domain' settings and the like */
743 fstring username_out
;
744 const char *nt_username
, *nt_domain
;
745 if (!(nt_username
= unistr2_tdup(state
->mem_ctx
, &(info3
.uni_user_name
)))) {
746 /* If the server didn't give us one, just use the one we sent them */
747 nt_username
= name_user
;
750 if (!(nt_domain
= unistr2_tdup(state
->mem_ctx
, &(info3
.uni_logon_dom
)))) {
751 /* If the server didn't give us one, just use the one we sent them */
752 nt_domain
= name_domain
;
755 fill_domain_username(username_out
, nt_domain
, nt_username
);
757 DEBUG(5, ("Setting unix username to [%s]\n", username_out
));
759 state
->response
.extra_data
= SMB_STRDUP(username_out
);
760 if (!state
->response
.extra_data
) {
761 result
= NT_STATUS_NO_MEMORY
;
764 state
->response
.length
+= strlen(state
->response
.extra_data
)+1;
767 if (state
->request
.flags
& WBFLAG_PAM_USER_SESSION_KEY
) {
768 memcpy(state
->response
.data
.auth
.user_session_key
, info3
.user_sess_key
, sizeof(state
->response
.data
.auth
.user_session_key
) /* 16 */);
770 if (state
->request
.flags
& WBFLAG_PAM_LMKEY
) {
771 memcpy(state
->response
.data
.auth
.first_8_lm_hash
, info3
.lm_sess_key
, sizeof(state
->response
.data
.auth
.first_8_lm_hash
) /* 8 */);
776 /* give us a more useful (more correct?) error code */
777 if ((NT_STATUS_EQUAL(result
, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
) || (NT_STATUS_EQUAL(result
, NT_STATUS_UNSUCCESSFUL
)))) {
778 result
= NT_STATUS_NO_LOGON_SERVERS
;
781 if (state
->request
.flags
& WBFLAG_PAM_NT_STATUS_SQUASH
) {
782 result
= nt_status_squash(result
);
785 state
->response
.data
.auth
.nt_status
= NT_STATUS_V(result
);
786 fstrcpy(state
->response
.data
.auth
.nt_status_string
, nt_errstr(result
));
788 /* we might have given a more useful error above */
789 if (!*state
->response
.data
.auth
.error_string
)
790 fstrcpy(state
->response
.data
.auth
.error_string
, get_friendly_nt_error_msg(result
));
791 state
->response
.data
.auth
.pam_error
= nt_status_to_pam(result
);
793 DEBUG(NT_STATUS_IS_OK(result
) ? 5 : 2,
794 ("NTLM CRAP authentication for user [%s]\\[%s] returned %s (PAM: %d)\n",
797 state
->response
.data
.auth
.nt_status_string
,
798 state
->response
.data
.auth
.pam_error
));
800 return NT_STATUS_IS_OK(result
) ? WINBINDD_OK
: WINBINDD_ERROR
;
803 /* Change a user password */
805 enum winbindd_result
winbindd_pam_chauthtok(struct winbindd_cli_state
*state
)
808 char *oldpass
, *newpass
;
809 fstring domain
, user
;
811 struct winbindd_domain
*contact_domain
;
812 struct rpc_pipe_client
*cli
;
814 DEBUG(3, ("[%5lu]: pam chauthtok %s\n", (unsigned long)state
->pid
,
815 state
->request
.data
.chauthtok
.user
));
820 return WINBINDD_ERROR
;
822 parse_domain_user(state
->request
.data
.chauthtok
.user
, domain
, user
);
824 if (!(contact_domain
= find_domain_from_name(domain
))) {
825 DEBUG(3, ("Cannot change password for [%s] -> [%s]\\[%s] as %s is not a trusted domain\n",
826 state
->request
.data
.chauthtok
.user
, domain
, user
, domain
));
827 result
= NT_STATUS_NO_SUCH_USER
;
831 /* Change password */
833 oldpass
= state
->request
.data
.chauthtok
.oldpass
;
834 newpass
= state
->request
.data
.chauthtok
.newpass
;
838 result
= cm_connect_sam(contact_domain
, state
->mem_ctx
, &cli
,
840 if (!NT_STATUS_IS_OK(result
)) {
841 DEBUG(1, ("could not get SAM handle on DC for %s\n", domain
));
845 result
= rpccli_samr_chgpasswd_user(cli
, state
->mem_ctx
, user
, newpass
,
849 state
->response
.data
.auth
.nt_status
= NT_STATUS_V(result
);
850 fstrcpy(state
->response
.data
.auth
.nt_status_string
, nt_errstr(result
));
851 fstrcpy(state
->response
.data
.auth
.error_string
, nt_errstr(result
));
852 state
->response
.data
.auth
.pam_error
= nt_status_to_pam(result
);
854 DEBUG(NT_STATUS_IS_OK(result
) ? 5 : 2,
855 ("Password change for user [%s]\\[%s] returned %s (PAM: %d)\n",
858 state
->response
.data
.auth
.nt_status_string
,
859 state
->response
.data
.auth
.pam_error
));
861 return NT_STATUS_IS_OK(result
) ? WINBINDD_OK
: WINBINDD_ERROR
;