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
9 Copyright (C) Guenther Deschner 2005
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 3 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, see <http://www.gnu.org/licenses/>.
28 #define DBGC_CLASS DBGC_WINBIND
30 static NTSTATUS
append_info3_as_txt(TALLOC_CTX
*mem_ctx
,
31 struct winbindd_cli_state
*state
,
32 NET_USER_INFO_3
*info3
)
36 state
->response
.data
.auth
.info3
.logon_time
=
37 nt_time_to_unix(info3
->logon_time
);
38 state
->response
.data
.auth
.info3
.logoff_time
=
39 nt_time_to_unix(info3
->logoff_time
);
40 state
->response
.data
.auth
.info3
.kickoff_time
=
41 nt_time_to_unix(info3
->kickoff_time
);
42 state
->response
.data
.auth
.info3
.pass_last_set_time
=
43 nt_time_to_unix(info3
->pass_last_set_time
);
44 state
->response
.data
.auth
.info3
.pass_can_change_time
=
45 nt_time_to_unix(info3
->pass_can_change_time
);
46 state
->response
.data
.auth
.info3
.pass_must_change_time
=
47 nt_time_to_unix(info3
->pass_must_change_time
);
49 state
->response
.data
.auth
.info3
.logon_count
= info3
->logon_count
;
50 state
->response
.data
.auth
.info3
.bad_pw_count
= info3
->bad_pw_count
;
52 state
->response
.data
.auth
.info3
.user_rid
= info3
->user_rid
;
53 state
->response
.data
.auth
.info3
.group_rid
= info3
->group_rid
;
54 sid_to_string(str_sid
, &(info3
->dom_sid
.sid
));
55 fstrcpy(state
->response
.data
.auth
.info3
.dom_sid
, str_sid
);
57 state
->response
.data
.auth
.info3
.num_groups
= info3
->num_groups
;
58 state
->response
.data
.auth
.info3
.user_flgs
= info3
->user_flgs
;
60 state
->response
.data
.auth
.info3
.acct_flags
= info3
->acct_flags
;
61 state
->response
.data
.auth
.info3
.num_other_sids
= info3
->num_other_sids
;
63 unistr2_to_ascii(state
->response
.data
.auth
.info3
.user_name
,
64 &info3
->uni_user_name
, sizeof(fstring
));
65 unistr2_to_ascii(state
->response
.data
.auth
.info3
.full_name
,
66 &info3
->uni_full_name
, sizeof(fstring
));
67 unistr2_to_ascii(state
->response
.data
.auth
.info3
.logon_script
,
68 &info3
->uni_logon_script
, sizeof(fstring
));
69 unistr2_to_ascii(state
->response
.data
.auth
.info3
.profile_path
,
70 &info3
->uni_profile_path
, sizeof(fstring
));
71 unistr2_to_ascii(state
->response
.data
.auth
.info3
.home_dir
,
72 &info3
->uni_home_dir
, sizeof(fstring
));
73 unistr2_to_ascii(state
->response
.data
.auth
.info3
.dir_drive
,
74 &info3
->uni_dir_drive
, sizeof(fstring
));
76 unistr2_to_ascii(state
->response
.data
.auth
.info3
.logon_srv
,
77 &info3
->uni_logon_srv
, sizeof(fstring
));
78 unistr2_to_ascii(state
->response
.data
.auth
.info3
.logon_dom
,
79 &info3
->uni_logon_dom
, sizeof(fstring
));
84 static NTSTATUS
append_info3_as_ndr(TALLOC_CTX
*mem_ctx
,
85 struct winbindd_cli_state
*state
,
86 NET_USER_INFO_3
*info3
)
90 if (!prs_init(&ps
, 256 /* Random, non-zero number */, mem_ctx
, MARSHALL
)) {
91 return NT_STATUS_NO_MEMORY
;
93 if (!net_io_user_info3("", info3
, &ps
, 1, 3, False
)) {
95 return NT_STATUS_UNSUCCESSFUL
;
98 size
= prs_data_size(&ps
);
99 SAFE_FREE(state
->response
.extra_data
.data
);
100 state
->response
.extra_data
.data
= SMB_MALLOC(size
);
101 if (!state
->response
.extra_data
.data
) {
103 return NT_STATUS_NO_MEMORY
;
105 memset( state
->response
.extra_data
.data
, '\0', size
);
106 prs_copy_all_data_out((char *)state
->response
.extra_data
.data
, &ps
);
107 state
->response
.length
+= size
;
112 static NTSTATUS
append_unix_username(TALLOC_CTX
*mem_ctx
,
113 struct winbindd_cli_state
*state
,
114 const NET_USER_INFO_3
*info3
,
115 const char *name_domain
,
116 const char *name_user
)
118 /* We've been asked to return the unix username, per
119 'winbind use default domain' settings and the like */
121 fstring username_out
;
122 const char *nt_username
, *nt_domain
;
124 if (!(nt_domain
= unistr2_tdup(mem_ctx
,
125 &info3
->uni_logon_dom
))) {
126 /* If the server didn't give us one, just use the one
128 nt_domain
= name_domain
;
131 if (!(nt_username
= unistr2_tdup(mem_ctx
,
132 &info3
->uni_user_name
))) {
133 /* If the server didn't give us one, just use the one
135 nt_username
= name_user
;
138 fill_domain_username(username_out
, nt_domain
, nt_username
,
141 DEBUG(5,("Setting unix username to [%s]\n", username_out
));
143 SAFE_FREE(state
->response
.extra_data
.data
);
144 state
->response
.extra_data
.data
= SMB_STRDUP(username_out
);
145 if (!state
->response
.extra_data
.data
) {
146 return NT_STATUS_NO_MEMORY
;
148 state
->response
.length
+=
149 strlen((const char *)state
->response
.extra_data
.data
)+1;
154 static NTSTATUS
append_afs_token(TALLOC_CTX
*mem_ctx
,
155 struct winbindd_cli_state
*state
,
156 const NET_USER_INFO_3
*info3
,
157 const char *name_domain
,
158 const char *name_user
)
160 char *afsname
= NULL
;
163 afsname
= talloc_strdup(mem_ctx
, lp_afs_username_map());
164 if (afsname
== NULL
) {
165 return NT_STATUS_NO_MEMORY
;
168 afsname
= talloc_string_sub(mem_ctx
,
169 lp_afs_username_map(),
171 afsname
= talloc_string_sub(mem_ctx
, afsname
,
173 afsname
= talloc_string_sub(mem_ctx
, afsname
,
180 sid_copy(&user_sid
, &info3
->dom_sid
.sid
);
181 sid_append_rid(&user_sid
, info3
->user_rid
);
182 sid_to_string(sidstr
, &user_sid
);
183 afsname
= talloc_string_sub(mem_ctx
, afsname
,
187 if (afsname
== NULL
) {
188 return NT_STATUS_NO_MEMORY
;
193 DEBUG(10, ("Generating token for user %s\n", afsname
));
195 cell
= strchr(afsname
, '@');
198 return NT_STATUS_NO_MEMORY
;
204 /* Append an AFS token string */
205 SAFE_FREE(state
->response
.extra_data
.data
);
206 state
->response
.extra_data
.data
=
207 afs_createtoken_str(afsname
, cell
);
209 if (state
->response
.extra_data
.data
!= NULL
) {
210 state
->response
.length
+=
211 strlen((const char *)state
->response
.extra_data
.data
)+1;
217 static NTSTATUS
check_info3_in_group(TALLOC_CTX
*mem_ctx
,
218 NET_USER_INFO_3
*info3
,
219 const char *group_sid
)
221 * Check whether a user belongs to a group or list of groups.
223 * @param mem_ctx talloc memory context.
224 * @param info3 user information, including group membership info.
225 * @param group_sid One or more groups , separated by commas.
227 * @return NT_STATUS_OK on success,
228 * NT_STATUS_LOGON_FAILURE if the user does not belong,
229 * or other NT_STATUS_IS_ERR(status) for other kinds of failure.
232 DOM_SID
*require_membership_of_sid
;
233 size_t num_require_membership_of_sid
;
238 struct nt_user_token
*token
;
241 /* Parse the 'required group' SID */
243 if (!group_sid
|| !group_sid
[0]) {
244 /* NO sid supplied, all users may access */
248 if (!(token
= TALLOC_ZERO_P(mem_ctx
, struct nt_user_token
))) {
249 DEBUG(0, ("talloc failed\n"));
250 return NT_STATUS_NO_MEMORY
;
253 num_require_membership_of_sid
= 0;
254 require_membership_of_sid
= NULL
;
258 while (next_token(&p
, req_sid
, ",", sizeof(req_sid
))) {
259 if (!string_to_sid(&sid
, req_sid
)) {
260 DEBUG(0, ("check_info3_in_group: could not parse %s "
261 "as a SID!", req_sid
));
262 return NT_STATUS_INVALID_PARAMETER
;
265 if (!add_sid_to_array(mem_ctx
, &sid
,
266 &require_membership_of_sid
,
267 &num_require_membership_of_sid
)) {
268 DEBUG(0, ("add_sid_to_array failed\n"));
269 return NT_STATUS_NO_MEMORY
;
273 status
= sid_array_from_info3(mem_ctx
, info3
,
277 if (!NT_STATUS_IS_OK(status
)) {
281 if (!NT_STATUS_IS_OK(status
= add_aliases(get_global_sam_sid(),
283 || !NT_STATUS_IS_OK(status
= add_aliases(&global_sid_Builtin
,
285 DEBUG(3, ("could not add aliases: %s\n",
290 debug_nt_user_token(DBGC_CLASS
, 10, token
);
292 for (i
=0; i
<num_require_membership_of_sid
; i
++) {
293 DEBUG(10, ("Checking SID %s\n", sid_string_static(
294 &require_membership_of_sid
[i
])));
295 if (nt_token_check_sid(&require_membership_of_sid
[i
],
297 DEBUG(10, ("Access ok\n"));
302 /* Do not distinguish this error from a wrong username/pw */
304 return NT_STATUS_LOGON_FAILURE
;
307 struct winbindd_domain
*find_auth_domain(struct winbindd_cli_state
*state
,
308 const char *domain_name
)
310 struct winbindd_domain
*domain
;
313 domain
= find_domain_from_name_noinit(domain_name
);
314 if (domain
== NULL
) {
315 DEBUG(3, ("Authentication for domain [%s] refused"
316 "as it is not a trusted domain\n",
322 if (is_myname(domain_name
)) {
323 DEBUG(3, ("Authentication for domain %s (local domain "
324 "to this server) not supported at this "
325 "stage\n", domain_name
));
329 /* we can auth against trusted domains */
330 if (state
->request
.flags
& WBFLAG_PAM_CONTACT_TRUSTDOM
) {
331 domain
= find_domain_from_name_noinit(domain_name
);
332 if (domain
== NULL
) {
333 DEBUG(3, ("Authentication for domain [%s] skipped "
334 "as it is not a trusted domain\n",
341 return find_our_domain();
344 static void set_auth_errors(struct winbindd_response
*resp
, NTSTATUS result
)
346 resp
->data
.auth
.nt_status
= NT_STATUS_V(result
);
347 fstrcpy(resp
->data
.auth
.nt_status_string
, nt_errstr(result
));
349 /* we might have given a more useful error above */
350 if (*resp
->data
.auth
.error_string
== '\0')
351 fstrcpy(resp
->data
.auth
.error_string
,
352 get_friendly_nt_error_msg(result
));
353 resp
->data
.auth
.pam_error
= nt_status_to_pam(result
);
356 static NTSTATUS
fillup_password_policy(struct winbindd_domain
*domain
,
357 struct winbindd_cli_state
*state
)
359 struct winbindd_methods
*methods
;
360 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
361 SAM_UNK_INFO_1 password_policy
;
363 if ( !winbindd_can_contact_domain( domain
) ) {
364 DEBUG(5,("fillup_password_policy: No inbound trust to "
365 "contact domain %s\n", domain
->name
));
366 return NT_STATUS_NOT_SUPPORTED
;
369 methods
= domain
->methods
;
371 status
= methods
->password_policy(domain
, state
->mem_ctx
, &password_policy
);
372 if (NT_STATUS_IS_ERR(status
)) {
376 state
->response
.data
.auth
.policy
.min_length_password
=
377 password_policy
.min_length_password
;
378 state
->response
.data
.auth
.policy
.password_history
=
379 password_policy
.password_history
;
380 state
->response
.data
.auth
.policy
.password_properties
=
381 password_policy
.password_properties
;
382 state
->response
.data
.auth
.policy
.expire
=
383 nt_time_to_unix_abs(&(password_policy
.expire
));
384 state
->response
.data
.auth
.policy
.min_passwordage
=
385 nt_time_to_unix_abs(&(password_policy
.min_passwordage
));
390 static NTSTATUS
get_max_bad_attempts_from_lockout_policy(struct winbindd_domain
*domain
,
392 uint16
*max_allowed_bad_attempts
)
394 struct winbindd_methods
*methods
;
395 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
396 SAM_UNK_INFO_12 lockout_policy
;
398 *max_allowed_bad_attempts
= 0;
400 methods
= domain
->methods
;
402 status
= methods
->lockout_policy(domain
, mem_ctx
, &lockout_policy
);
403 if (NT_STATUS_IS_ERR(status
)) {
407 *max_allowed_bad_attempts
= lockout_policy
.bad_attempt_lockout
;
412 static NTSTATUS
get_pwd_properties(struct winbindd_domain
*domain
,
414 uint32
*password_properties
)
416 struct winbindd_methods
*methods
;
417 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
;
418 SAM_UNK_INFO_1 password_policy
;
420 *password_properties
= 0;
422 methods
= domain
->methods
;
424 status
= methods
->password_policy(domain
, mem_ctx
, &password_policy
);
425 if (NT_STATUS_IS_ERR(status
)) {
429 *password_properties
= password_policy
.password_properties
;
436 static const char *generate_krb5_ccache(TALLOC_CTX
*mem_ctx
,
439 BOOL
*internal_ccache
)
441 /* accept FILE and WRFILE as krb5_cc_type from the client and then
442 * build the full ccname string based on the user's uid here -
445 const char *gen_cc
= NULL
;
447 *internal_ccache
= True
;
453 if (!type
|| type
[0] == '\0') {
457 if (strequal(type
, "FILE")) {
458 gen_cc
= talloc_asprintf(mem_ctx
, "FILE:/tmp/krb5cc_%d", uid
);
459 } else if (strequal(type
, "WRFILE")) {
460 gen_cc
= talloc_asprintf(mem_ctx
, "WRFILE:/tmp/krb5cc_%d", uid
);
462 DEBUG(10,("we don't allow to set a %s type ccache\n", type
));
466 *internal_ccache
= False
;
470 gen_cc
= talloc_strdup(mem_ctx
, "MEMORY:winbindd_pam_ccache");
473 if (gen_cc
== NULL
) {
474 DEBUG(0,("out of memory\n"));
478 DEBUG(10,("using ccache: %s %s\n", gen_cc
, *internal_ccache
? "(internal)":""));
483 static void setup_return_cc_name(struct winbindd_cli_state
*state
, const char *cc
)
485 const char *type
= state
->request
.data
.auth
.krb5_cc_type
;
487 state
->response
.data
.auth
.krb5ccname
[0] = '\0';
489 if (type
[0] == '\0') {
493 if (!strequal(type
, "FILE") &&
494 !strequal(type
, "WRFILE")) {
495 DEBUG(10,("won't return krbccname for a %s type ccache\n",
500 fstrcpy(state
->response
.data
.auth
.krb5ccname
, cc
);
505 static uid_t
get_uid_from_state(struct winbindd_cli_state
*state
)
509 uid
= state
->request
.data
.auth
.uid
;
512 DEBUG(1,("invalid uid: '%d'\n", uid
));
518 /**********************************************************************
519 Authenticate a user with a clear text password using Kerberos and fill up
521 **********************************************************************/
523 static NTSTATUS
winbindd_raw_kerberos_login(struct winbindd_domain
*domain
,
524 struct winbindd_cli_state
*state
,
525 NET_USER_INFO_3
**info3
)
528 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
529 krb5_error_code krb5_ret
;
530 const char *cc
= NULL
;
531 const char *principal_s
= NULL
;
532 const char *service
= NULL
;
534 fstring name_domain
, name_user
;
535 time_t ticket_lifetime
= 0;
536 time_t renewal_until
= 0;
539 time_t time_offset
= 0;
540 BOOL internal_ccache
= True
;
547 * prepare a krb5_cc_cache string for the user */
549 uid
= get_uid_from_state(state
);
551 DEBUG(0,("no valid uid\n"));
554 cc
= generate_krb5_ccache(state
->mem_ctx
,
555 state
->request
.data
.auth
.krb5_cc_type
,
556 state
->request
.data
.auth
.uid
,
559 return NT_STATUS_NO_MEMORY
;
564 * get kerberos properties */
566 if (domain
->private_data
) {
567 ads
= (ADS_STRUCT
*)domain
->private_data
;
568 time_offset
= ads
->auth
.time_offset
;
573 * do kerberos auth and setup ccache as the user */
575 parse_domain_user(state
->request
.data
.auth
.user
, name_domain
, name_user
);
577 realm
= domain
->alt_name
;
580 principal_s
= talloc_asprintf(state
->mem_ctx
, "%s@%s", name_user
, realm
);
581 if (principal_s
== NULL
) {
582 return NT_STATUS_NO_MEMORY
;
585 service
= talloc_asprintf(state
->mem_ctx
, "%s/%s@%s", KRB5_TGS_NAME
, realm
, realm
);
586 if (service
== NULL
) {
587 return NT_STATUS_NO_MEMORY
;
590 /* if this is a user ccache, we need to act as the user to let the krb5
591 * library handle the chown, etc. */
593 /************************ ENTERING NON-ROOT **********************/
595 if (!internal_ccache
) {
596 set_effective_uid(uid
);
597 DEBUG(10,("winbindd_raw_kerberos_login: uid is %d\n", uid
));
600 result
= kerberos_return_info3_from_pac(state
->mem_ctx
,
602 state
->request
.data
.auth
.pass
,
609 WINBINDD_PAM_AUTH_KRB5_RENEW_TIME
,
611 if (!internal_ccache
) {
612 gain_root_privilege();
615 /************************ RETURNED TO ROOT **********************/
617 if (!NT_STATUS_IS_OK(result
)) {
621 DEBUG(10,("winbindd_raw_kerberos_login: winbindd validated ticket of %s\n",
624 /* if we had a user's ccache then return that string for the pam
627 if (!internal_ccache
) {
629 setup_return_cc_name(state
, cc
);
631 result
= add_ccache_to_list(principal_s
,
634 state
->request
.data
.auth
.user
,
642 if (!NT_STATUS_IS_OK(result
)) {
643 DEBUG(10,("winbindd_raw_kerberos_login: failed to add ccache to list: %s\n",
648 /* need to delete the memory cred cache, it is not used anymore */
650 krb5_ret
= ads_kdestroy(cc
);
652 DEBUG(3,("winbindd_raw_kerberos_login: "
653 "could not destroy krb5 credential cache: "
654 "%s\n", error_message(krb5_ret
)));
663 /* we could have created a new credential cache with a valid tgt in it
664 * but we werent able to get or verify the service ticket for this
665 * local host and therefor didn't get the PAC, we need to remove that
666 * cache entirely now */
668 krb5_ret
= ads_kdestroy(cc
);
670 DEBUG(3,("winbindd_raw_kerberos_login: "
671 "could not destroy krb5 credential cache: "
672 "%s\n", error_message(krb5_ret
)));
675 if (!NT_STATUS_IS_OK(remove_ccache(state
->request
.data
.auth
.user
))) {
676 DEBUG(3,("winbindd_raw_kerberos_login: "
677 "could not remove ccache for user %s\n",
678 state
->request
.data
.auth
.user
));
683 return NT_STATUS_NOT_SUPPORTED
;
684 #endif /* HAVE_KRB5 */
687 /****************************************************************
688 ****************************************************************/
690 static BOOL
check_request_flags(uint32_t flags
)
692 uint32_t flags_edata
= WBFLAG_PAM_AFS_TOKEN
|
693 WBFLAG_PAM_UNIX_NAME
|
694 WBFLAG_PAM_INFO3_NDR
;
696 if ( ( (flags
& flags_edata
) == WBFLAG_PAM_AFS_TOKEN
) ||
697 ( (flags
& flags_edata
) == WBFLAG_PAM_INFO3_NDR
) ||
698 ( (flags
& flags_edata
) == WBFLAG_PAM_UNIX_NAME
) ||
699 !(flags
& flags_edata
) ) {
703 DEBUG(1,("check_request_flags: invalid request flags\n"));
708 /****************************************************************
709 ****************************************************************/
711 static NTSTATUS
append_data(struct winbindd_cli_state
*state
,
712 NET_USER_INFO_3
*info3
,
713 const char *name_domain
,
714 const char *name_user
)
717 uint32_t flags
= state
->request
.flags
;
719 if (flags
& WBFLAG_PAM_USER_SESSION_KEY
) {
720 memcpy(state
->response
.data
.auth
.user_session_key
,
721 info3
->user_sess_key
,
722 sizeof(state
->response
.data
.auth
.user_session_key
)
726 if (flags
& WBFLAG_PAM_LMKEY
) {
727 memcpy(state
->response
.data
.auth
.first_8_lm_hash
,
729 sizeof(state
->response
.data
.auth
.first_8_lm_hash
)
733 if (flags
& WBFLAG_PAM_INFO3_TEXT
) {
734 result
= append_info3_as_txt(state
->mem_ctx
, state
, info3
);
735 if (!NT_STATUS_IS_OK(result
)) {
736 DEBUG(10,("Failed to append INFO3 (TXT): %s\n",
742 /* currently, anything from here on potentially overwrites extra_data. */
744 if (flags
& WBFLAG_PAM_INFO3_NDR
) {
745 result
= append_info3_as_ndr(state
->mem_ctx
, state
, info3
);
746 if (!NT_STATUS_IS_OK(result
)) {
747 DEBUG(10,("Failed to append INFO3 (NDR): %s\n",
753 if (flags
& WBFLAG_PAM_UNIX_NAME
) {
754 result
= append_unix_username(state
->mem_ctx
, state
, info3
,
755 name_domain
, name_user
);
756 if (!NT_STATUS_IS_OK(result
)) {
757 DEBUG(10,("Failed to append Unix Username: %s\n",
763 if (flags
& WBFLAG_PAM_AFS_TOKEN
) {
764 result
= append_afs_token(state
->mem_ctx
, state
, info3
,
765 name_domain
, name_user
);
766 if (!NT_STATUS_IS_OK(result
)) {
767 DEBUG(10,("Failed to append AFS token: %s\n",
776 void winbindd_pam_auth(struct winbindd_cli_state
*state
)
778 struct winbindd_domain
*domain
;
779 fstring name_domain
, name_user
;
782 /* Ensure null termination */
783 state
->request
.data
.auth
.user
784 [sizeof(state
->request
.data
.auth
.user
)-1]='\0';
786 /* Ensure null termination */
787 state
->request
.data
.auth
.pass
788 [sizeof(state
->request
.data
.auth
.pass
)-1]='\0';
790 DEBUG(3, ("[%5lu]: pam auth %s\n", (unsigned long)state
->pid
,
791 state
->request
.data
.auth
.user
));
793 if (!check_request_flags(state
->request
.flags
)) {
794 result
= NT_STATUS_INVALID_PARAMETER_MIX
;
798 /* Parse domain and username */
800 ws_name_return( state
->request
.data
.auth
.user
, WB_REPLACE_CHAR
);
802 if (!canonicalize_username(state
->request
.data
.auth
.user
,
803 name_domain
, name_user
)) {
804 result
= NT_STATUS_NO_SUCH_USER
;
808 domain
= find_auth_domain(state
, name_domain
);
810 if (domain
== NULL
) {
811 result
= NT_STATUS_NO_SUCH_USER
;
815 sendto_domain(state
, domain
);
818 set_auth_errors(&state
->response
, result
);
819 DEBUG(5, ("Plain text authentication for %s returned %s "
821 state
->request
.data
.auth
.user
,
822 state
->response
.data
.auth
.nt_status_string
,
823 state
->response
.data
.auth
.pam_error
));
824 request_error(state
);
827 NTSTATUS
winbindd_dual_pam_auth_cached(struct winbindd_domain
*domain
,
828 struct winbindd_cli_state
*state
,
829 NET_USER_INFO_3
**info3
)
831 NTSTATUS result
= NT_STATUS_LOGON_FAILURE
;
832 uint16 max_allowed_bad_attempts
;
833 fstring name_domain
, name_user
;
835 enum lsa_SidType type
;
836 uchar new_nt_pass
[NT_HASH_LEN
];
837 const uint8
*cached_nt_pass
;
838 const uint8
*cached_salt
;
839 NET_USER_INFO_3
*my_info3
;
840 time_t kickoff_time
, must_change_time
;
841 BOOL password_good
= False
;
843 struct winbindd_tdc_domain
*tdc_domain
= NULL
;
850 DEBUG(10,("winbindd_dual_pam_auth_cached\n"));
852 /* Parse domain and username */
854 parse_domain_user(state
->request
.data
.auth
.user
, name_domain
, name_user
);
857 if (!lookup_cached_name(state
->mem_ctx
,
862 DEBUG(10,("winbindd_dual_pam_auth_cached: no such user in the cache\n"));
863 return NT_STATUS_NO_SUCH_USER
;
866 if (type
!= SID_NAME_USER
) {
867 DEBUG(10,("winbindd_dual_pam_auth_cached: not a user (%s)\n", sid_type_lookup(type
)));
868 return NT_STATUS_LOGON_FAILURE
;
871 result
= winbindd_get_creds(domain
,
877 if (!NT_STATUS_IS_OK(result
)) {
878 DEBUG(10,("winbindd_dual_pam_auth_cached: failed to get creds: %s\n", nt_errstr(result
)));
884 E_md4hash(state
->request
.data
.auth
.pass
, new_nt_pass
);
886 dump_data_pw("new_nt_pass", new_nt_pass
, NT_HASH_LEN
);
887 dump_data_pw("cached_nt_pass", cached_nt_pass
, NT_HASH_LEN
);
889 dump_data_pw("cached_salt", cached_salt
, NT_HASH_LEN
);
893 /* In this case we didn't store the nt_hash itself,
894 but the MD5 combination of salt + nt_hash. */
895 uchar salted_hash
[NT_HASH_LEN
];
896 E_md5hash(cached_salt
, new_nt_pass
, salted_hash
);
898 password_good
= (memcmp(cached_nt_pass
, salted_hash
, NT_HASH_LEN
) == 0) ?
901 /* Old cached cred - direct store of nt_hash (bad bad bad !). */
902 password_good
= (memcmp(cached_nt_pass
, new_nt_pass
, NT_HASH_LEN
) == 0) ?
908 /* User *DOES* know the password, update logon_time and reset
911 my_info3
->user_flgs
|= LOGON_CACHED_ACCOUNT
;
913 if (my_info3
->acct_flags
& ACB_AUTOLOCK
) {
914 return NT_STATUS_ACCOUNT_LOCKED_OUT
;
917 if (my_info3
->acct_flags
& ACB_DISABLED
) {
918 return NT_STATUS_ACCOUNT_DISABLED
;
921 if (my_info3
->acct_flags
& ACB_WSTRUST
) {
922 return NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT
;
925 if (my_info3
->acct_flags
& ACB_SVRTRUST
) {
926 return NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT
;
929 if (my_info3
->acct_flags
& ACB_DOMTRUST
) {
930 return NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
;
933 if (!(my_info3
->acct_flags
& ACB_NORMAL
)) {
934 DEBUG(0,("winbindd_dual_pam_auth_cached: whats wrong with that one?: 0x%08x\n",
935 my_info3
->acct_flags
));
936 return NT_STATUS_LOGON_FAILURE
;
939 kickoff_time
= nt_time_to_unix(my_info3
->kickoff_time
);
940 if (kickoff_time
!= 0 && time(NULL
) > kickoff_time
) {
941 return NT_STATUS_ACCOUNT_EXPIRED
;
944 must_change_time
= nt_time_to_unix(my_info3
->pass_must_change_time
);
945 if (must_change_time
!= 0 && must_change_time
< time(NULL
)) {
946 /* we allow grace logons when the password has expired */
947 my_info3
->user_flgs
|= LOGON_GRACE_LOGON
;
948 /* return NT_STATUS_PASSWORD_EXPIRED; */
953 if ((state
->request
.flags
& WBFLAG_PAM_KRB5
) &&
954 ((tdc_domain
= wcache_tdc_fetch_domain(state
->mem_ctx
, name_domain
)) != NULL
) &&
955 (tdc_domain
->trust_type
& DS_DOMAIN_TRUST_TYPE_UPLEVEL
)) {
958 const char *cc
= NULL
;
960 const char *principal_s
= NULL
;
961 const char *service
= NULL
;
962 BOOL internal_ccache
= False
;
964 uid
= get_uid_from_state(state
);
966 DEBUG(0,("winbindd_dual_pam_auth_cached: invalid uid\n"));
967 return NT_STATUS_INVALID_PARAMETER
;
970 cc
= generate_krb5_ccache(state
->mem_ctx
,
971 state
->request
.data
.auth
.krb5_cc_type
,
972 state
->request
.data
.auth
.uid
,
975 return NT_STATUS_NO_MEMORY
;
978 realm
= domain
->alt_name
;
981 principal_s
= talloc_asprintf(state
->mem_ctx
, "%s@%s", name_user
, realm
);
982 if (principal_s
== NULL
) {
983 return NT_STATUS_NO_MEMORY
;
986 service
= talloc_asprintf(state
->mem_ctx
, "%s/%s@%s", KRB5_TGS_NAME
, realm
, realm
);
987 if (service
== NULL
) {
988 return NT_STATUS_NO_MEMORY
;
991 if (!internal_ccache
) {
993 setup_return_cc_name(state
, cc
);
995 result
= add_ccache_to_list(principal_s
,
998 state
->request
.data
.auth
.user
,
1002 time(NULL
) + lp_winbind_cache_time(),
1003 time(NULL
) + WINBINDD_PAM_AUTH_KRB5_RENEW_TIME
,
1006 if (!NT_STATUS_IS_OK(result
)) {
1007 DEBUG(10,("winbindd_dual_pam_auth_cached: failed "
1008 "to add ccache to list: %s\n",
1009 nt_errstr(result
)));
1013 #endif /* HAVE_KRB5 */
1015 /* FIXME: we possibly should handle logon hours as well (does xp when
1016 * offline?) see auth/auth_sam.c:sam_account_ok for details */
1018 unix_to_nt_time(&my_info3
->logon_time
, time(NULL
));
1019 my_info3
->bad_pw_count
= 0;
1021 result
= winbindd_update_creds_by_info3(domain
,
1023 state
->request
.data
.auth
.user
,
1024 state
->request
.data
.auth
.pass
,
1026 if (!NT_STATUS_IS_OK(result
)) {
1027 DEBUG(1,("winbindd_dual_pam_auth_cached: failed to update creds: %s\n",
1028 nt_errstr(result
)));
1032 return NT_STATUS_OK
;
1036 /* User does *NOT* know the correct password, modify info3 accordingly */
1038 /* failure of this is not critical */
1039 result
= get_max_bad_attempts_from_lockout_policy(domain
, state
->mem_ctx
, &max_allowed_bad_attempts
);
1040 if (!NT_STATUS_IS_OK(result
)) {
1041 DEBUG(10,("winbindd_dual_pam_auth_cached: failed to get max_allowed_bad_attempts. "
1042 "Won't be able to honour account lockout policies\n"));
1045 /* increase counter */
1046 my_info3
->bad_pw_count
++;
1048 if (max_allowed_bad_attempts
== 0) {
1053 if (my_info3
->bad_pw_count
>= max_allowed_bad_attempts
) {
1055 uint32 password_properties
;
1057 result
= get_pwd_properties(domain
, state
->mem_ctx
, &password_properties
);
1058 if (!NT_STATUS_IS_OK(result
)) {
1059 DEBUG(10,("winbindd_dual_pam_auth_cached: failed to get password properties.\n"));
1062 if ((my_info3
->user_rid
!= DOMAIN_USER_RID_ADMIN
) ||
1063 (password_properties
& DOMAIN_LOCKOUT_ADMINS
)) {
1064 my_info3
->acct_flags
|= ACB_AUTOLOCK
;
1069 result
= winbindd_update_creds_by_info3(domain
,
1071 state
->request
.data
.auth
.user
,
1075 if (!NT_STATUS_IS_OK(result
)) {
1076 DEBUG(0,("winbindd_dual_pam_auth_cached: failed to update creds %s\n",
1077 nt_errstr(result
)));
1080 return NT_STATUS_LOGON_FAILURE
;
1083 NTSTATUS
winbindd_dual_pam_auth_kerberos(struct winbindd_domain
*domain
,
1084 struct winbindd_cli_state
*state
,
1085 NET_USER_INFO_3
**info3
)
1087 struct winbindd_domain
*contact_domain
;
1088 fstring name_domain
, name_user
;
1091 DEBUG(10,("winbindd_dual_pam_auth_kerberos\n"));
1093 /* Parse domain and username */
1095 parse_domain_user(state
->request
.data
.auth
.user
, name_domain
, name_user
);
1097 /* what domain should we contact? */
1100 if (!(contact_domain
= find_domain_from_name(name_domain
))) {
1101 DEBUG(3, ("Authentication for domain for [%s] -> [%s]\\[%s] failed as %s is not a trusted domain\n",
1102 state
->request
.data
.auth
.user
, name_domain
, name_user
, name_domain
));
1103 result
= NT_STATUS_NO_SUCH_USER
;
1108 if (is_myname(name_domain
)) {
1109 DEBUG(3, ("Authentication for domain %s (local domain to this server) not supported at this stage\n", name_domain
));
1110 result
= NT_STATUS_NO_SUCH_USER
;
1114 contact_domain
= find_domain_from_name(name_domain
);
1115 if (contact_domain
== NULL
) {
1116 DEBUG(3, ("Authentication for domain for [%s] -> [%s]\\[%s] failed as %s is not a trusted domain\n",
1117 state
->request
.data
.auth
.user
, name_domain
, name_user
, name_domain
));
1119 contact_domain
= find_our_domain();
1123 if (contact_domain
->initialized
&&
1124 contact_domain
->active_directory
) {
1128 if (!contact_domain
->initialized
) {
1129 init_dc_connection(contact_domain
);
1132 if (!contact_domain
->active_directory
) {
1133 DEBUG(3,("krb5 auth requested but domain is not Active Directory\n"));
1134 return NT_STATUS_INVALID_LOGON_TYPE
;
1137 result
= winbindd_raw_kerberos_login(contact_domain
, state
, info3
);
1142 NTSTATUS
winbindd_dual_pam_auth_samlogon(struct winbindd_domain
*domain
,
1143 struct winbindd_cli_state
*state
,
1144 NET_USER_INFO_3
**info3
)
1147 struct rpc_pipe_client
*netlogon_pipe
;
1152 unsigned char local_lm_response
[24];
1153 unsigned char local_nt_response
[24];
1154 struct winbindd_domain
*contact_domain
;
1155 fstring name_domain
, name_user
;
1158 NET_USER_INFO_3
*my_info3
;
1160 ZERO_STRUCTP(info3
);
1164 my_info3
= TALLOC_ZERO_P(state
->mem_ctx
, NET_USER_INFO_3
);
1165 if (my_info3
== NULL
) {
1166 return NT_STATUS_NO_MEMORY
;
1170 DEBUG(10,("winbindd_dual_pam_auth_samlogon\n"));
1172 /* Parse domain and username */
1174 parse_domain_user(state
->request
.data
.auth
.user
, name_domain
, name_user
);
1176 /* do password magic */
1179 generate_random_buffer(chal
, 8);
1180 if (lp_client_ntlmv2_auth()) {
1181 DATA_BLOB server_chal
;
1182 DATA_BLOB names_blob
;
1183 DATA_BLOB nt_response
;
1184 DATA_BLOB lm_response
;
1185 server_chal
= data_blob_talloc(state
->mem_ctx
, chal
, 8);
1187 /* note that the 'workgroup' here is a best guess - we don't know
1188 the server's domain at this point. The 'server name' is also
1191 names_blob
= NTLMv2_generate_names_blob(global_myname(), lp_workgroup());
1193 if (!SMBNTLMv2encrypt(name_user
, name_domain
,
1194 state
->request
.data
.auth
.pass
,
1197 &lm_response
, &nt_response
, NULL
)) {
1198 data_blob_free(&names_blob
);
1199 data_blob_free(&server_chal
);
1200 DEBUG(0, ("winbindd_pam_auth: SMBNTLMv2encrypt() failed!\n"));
1201 result
= NT_STATUS_NO_MEMORY
;
1204 data_blob_free(&names_blob
);
1205 data_blob_free(&server_chal
);
1206 lm_resp
= data_blob_talloc(state
->mem_ctx
, lm_response
.data
,
1207 lm_response
.length
);
1208 nt_resp
= data_blob_talloc(state
->mem_ctx
, nt_response
.data
,
1209 nt_response
.length
);
1210 data_blob_free(&lm_response
);
1211 data_blob_free(&nt_response
);
1214 if (lp_client_lanman_auth()
1215 && SMBencrypt(state
->request
.data
.auth
.pass
,
1217 local_lm_response
)) {
1218 lm_resp
= data_blob_talloc(state
->mem_ctx
,
1220 sizeof(local_lm_response
));
1222 lm_resp
= data_blob_null
;
1224 SMBNTencrypt(state
->request
.data
.auth
.pass
,
1228 nt_resp
= data_blob_talloc(state
->mem_ctx
,
1230 sizeof(local_nt_response
));
1233 /* what domain should we contact? */
1236 if (!(contact_domain
= find_domain_from_name(name_domain
))) {
1237 DEBUG(3, ("Authentication for domain for [%s] -> [%s]\\[%s] failed as %s is not a trusted domain\n",
1238 state
->request
.data
.auth
.user
, name_domain
, name_user
, name_domain
));
1239 result
= NT_STATUS_NO_SUCH_USER
;
1244 if (is_myname(name_domain
)) {
1245 DEBUG(3, ("Authentication for domain %s (local domain to this server) not supported at this stage\n", name_domain
));
1246 result
= NT_STATUS_NO_SUCH_USER
;
1250 contact_domain
= find_our_domain();
1253 /* check authentication loop */
1256 NTSTATUS (*logon_fn
)(struct rpc_pipe_client
1257 *cli
, TALLOC_CTX
*mem_ctx
,
1258 uint32 logon_parameters
,
1260 const char *username
,
1262 const char *workstation
,
1263 const uint8 chal
[8],
1264 DATA_BLOB lm_response
,
1265 DATA_BLOB nt_response
,
1266 NET_USER_INFO_3
*info3
);
1268 ZERO_STRUCTP(my_info3
);
1271 result
= cm_connect_netlogon(contact_domain
, &netlogon_pipe
);
1273 if (!NT_STATUS_IS_OK(result
)) {
1274 DEBUG(3, ("could not open handle to NETLOGON pipe\n"));
1278 logon_fn
= contact_domain
->can_do_samlogon_ex
1279 ? rpccli_netlogon_sam_network_logon_ex
1280 : rpccli_netlogon_sam_network_logon
;
1282 result
= logon_fn(netlogon_pipe
,
1285 contact_domain
->dcname
, /* server name */
1286 name_user
, /* user name */
1287 name_domain
, /* target domain */
1288 global_myname(), /* workstation */
1294 if ((NT_STATUS_V(result
) == DCERPC_FAULT_OP_RNG_ERROR
)
1295 && contact_domain
->can_do_samlogon_ex
) {
1296 DEBUG(3, ("Got a DC that can not do NetSamLogonEx, "
1297 "retrying with NetSamLogon\n"));
1298 contact_domain
->can_do_samlogon_ex
= False
;
1305 /* We have to try a second time as cm_connect_netlogon
1306 might not yet have noticed that the DC has killed
1309 if (NT_STATUS_EQUAL(result
, NT_STATUS_UNSUCCESSFUL
)) {
1314 /* if we get access denied, a possible cause was that we had
1315 and open connection to the DC, but someone changed our
1316 machine account password out from underneath us using 'net
1317 rpc changetrustpw' */
1319 if ( NT_STATUS_EQUAL(result
, NT_STATUS_ACCESS_DENIED
) ) {
1320 DEBUG(3,("winbindd_pam_auth: sam_logon returned "
1321 "ACCESS_DENIED. Maybe the trust account "
1322 "password was changed and we didn't know it. "
1323 "Killing connections to domain %s\n",
1325 invalidate_cm_connection(&contact_domain
->conn
);
1329 } while ( (attempts
< 2) && retry
);
1331 /* handle the case where a NT4 DC does not fill in the acct_flags in
1332 * the samlogon reply info3. When accurate info3 is required by the
1333 * caller, we look up the account flags ourselve - gd */
1335 if ((state
->request
.flags
& WBFLAG_PAM_INFO3_TEXT
) &&
1336 (my_info3
->acct_flags
== 0) && NT_STATUS_IS_OK(result
)) {
1338 struct rpc_pipe_client
*samr_pipe
;
1339 POLICY_HND samr_domain_handle
, user_pol
;
1340 SAM_USERINFO_CTR
*user_ctr
;
1341 NTSTATUS status_tmp
;
1344 ZERO_STRUCT(user_ctr
);
1346 status_tmp
= cm_connect_sam(contact_domain
, state
->mem_ctx
,
1347 &samr_pipe
, &samr_domain_handle
);
1349 if (!NT_STATUS_IS_OK(status_tmp
)) {
1350 DEBUG(3, ("could not open handle to SAMR pipe: %s\n",
1351 nt_errstr(status_tmp
)));
1355 status_tmp
= rpccli_samr_open_user(samr_pipe
, state
->mem_ctx
,
1356 &samr_domain_handle
,
1357 MAXIMUM_ALLOWED_ACCESS
,
1358 my_info3
->user_rid
, &user_pol
);
1360 if (!NT_STATUS_IS_OK(status_tmp
)) {
1361 DEBUG(3, ("could not open user handle on SAMR pipe: %s\n",
1362 nt_errstr(status_tmp
)));
1366 status_tmp
= rpccli_samr_query_userinfo(samr_pipe
, state
->mem_ctx
,
1367 &user_pol
, 16, &user_ctr
);
1369 if (!NT_STATUS_IS_OK(status_tmp
)) {
1370 DEBUG(3, ("could not query user info on SAMR pipe: %s\n",
1371 nt_errstr(status_tmp
)));
1372 rpccli_samr_close(samr_pipe
, state
->mem_ctx
, &user_pol
);
1376 acct_flags
= user_ctr
->info
.id16
->acb_info
;
1378 if (acct_flags
== 0) {
1379 rpccli_samr_close(samr_pipe
, state
->mem_ctx
, &user_pol
);
1383 my_info3
->acct_flags
= acct_flags
;
1385 DEBUG(10,("successfully retrieved acct_flags 0x%x\n", acct_flags
));
1387 rpccli_samr_close(samr_pipe
, state
->mem_ctx
, &user_pol
);
1395 enum winbindd_result
winbindd_dual_pam_auth(struct winbindd_domain
*domain
,
1396 struct winbindd_cli_state
*state
)
1398 NTSTATUS result
= NT_STATUS_LOGON_FAILURE
;
1399 NTSTATUS krb5_result
= NT_STATUS_OK
;
1400 fstring name_domain
, name_user
;
1401 NET_USER_INFO_3
*info3
= NULL
;
1403 /* Ensure null termination */
1404 state
->request
.data
.auth
.user
[sizeof(state
->request
.data
.auth
.user
)-1]='\0';
1406 /* Ensure null termination */
1407 state
->request
.data
.auth
.pass
[sizeof(state
->request
.data
.auth
.pass
)-1]='\0';
1409 DEBUG(3, ("[%5lu]: dual pam auth %s\n", (unsigned long)state
->pid
,
1410 state
->request
.data
.auth
.user
));
1412 if (!check_request_flags(state
->request
.flags
)) {
1413 result
= NT_STATUS_INVALID_PARAMETER_MIX
;
1417 /* Parse domain and username */
1419 ws_name_return( state
->request
.data
.auth
.user
, WB_REPLACE_CHAR
);
1421 parse_domain_user(state
->request
.data
.auth
.user
, name_domain
, name_user
);
1423 if (domain
->online
== False
) {
1424 result
= NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
;
1425 if (domain
->startup
) {
1426 /* Logons are very important to users. If we're offline and
1427 we get a request within the first 30 seconds of startup,
1428 try very hard to find a DC and go online. */
1430 DEBUG(10,("winbindd_dual_pam_auth: domain: %s offline and auth "
1431 "request in startup mode.\n", domain
->name
));
1433 winbindd_flush_negative_conn_cache(domain
);
1434 result
= init_dc_connection(domain
);
1438 DEBUG(10,("winbindd_dual_pam_auth: domain: %s last was %s\n", domain
->name
, domain
->online
? "online":"offline"));
1440 /* Check for Kerberos authentication */
1441 if (domain
->online
&& (state
->request
.flags
& WBFLAG_PAM_KRB5
)) {
1443 result
= winbindd_dual_pam_auth_kerberos(domain
, state
, &info3
);
1444 /* save for later */
1445 krb5_result
= result
;
1448 if (NT_STATUS_IS_OK(result
)) {
1449 DEBUG(10,("winbindd_dual_pam_auth_kerberos succeeded\n"));
1450 goto process_result
;
1452 DEBUG(10,("winbindd_dual_pam_auth_kerberos failed: %s\n", nt_errstr(result
)));
1455 if (NT_STATUS_EQUAL(result
, NT_STATUS_NO_LOGON_SERVERS
) ||
1456 NT_STATUS_EQUAL(result
, NT_STATUS_IO_TIMEOUT
) ||
1457 NT_STATUS_EQUAL(result
, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
)) {
1458 DEBUG(10,("winbindd_dual_pam_auth_kerberos setting domain to offline\n"));
1459 set_domain_offline( domain
);
1463 /* there are quite some NT_STATUS errors where there is no
1464 * point in retrying with a samlogon, we explictly have to take
1465 * care not to increase the bad logon counter on the DC */
1467 if (NT_STATUS_EQUAL(result
, NT_STATUS_ACCOUNT_DISABLED
) ||
1468 NT_STATUS_EQUAL(result
, NT_STATUS_ACCOUNT_EXPIRED
) ||
1469 NT_STATUS_EQUAL(result
, NT_STATUS_ACCOUNT_LOCKED_OUT
) ||
1470 NT_STATUS_EQUAL(result
, NT_STATUS_INVALID_LOGON_HOURS
) ||
1471 NT_STATUS_EQUAL(result
, NT_STATUS_INVALID_WORKSTATION
) ||
1472 NT_STATUS_EQUAL(result
, NT_STATUS_LOGON_FAILURE
) ||
1473 NT_STATUS_EQUAL(result
, NT_STATUS_NO_SUCH_USER
) ||
1474 NT_STATUS_EQUAL(result
, NT_STATUS_PASSWORD_EXPIRED
) ||
1475 NT_STATUS_EQUAL(result
, NT_STATUS_PASSWORD_MUST_CHANGE
) ||
1476 NT_STATUS_EQUAL(result
, NT_STATUS_WRONG_PASSWORD
)) {
1477 goto process_result
;
1480 if (state
->request
.flags
& WBFLAG_PAM_FALLBACK_AFTER_KRB5
) {
1481 DEBUG(3,("falling back to samlogon\n"));
1489 /* Check for Samlogon authentication */
1490 if (domain
->online
) {
1491 result
= winbindd_dual_pam_auth_samlogon(domain
, state
, &info3
);
1493 if (NT_STATUS_IS_OK(result
)) {
1494 DEBUG(10,("winbindd_dual_pam_auth_samlogon succeeded\n"));
1495 /* add the Krb5 err if we have one */
1496 if ( NT_STATUS_EQUAL(krb5_result
, NT_STATUS_TIME_DIFFERENCE_AT_DC
) ) {
1497 info3
->user_flgs
|= LOGON_KRB5_FAIL_CLOCK_SKEW
;
1499 goto process_result
;
1502 DEBUG(10,("winbindd_dual_pam_auth_samlogon failed: %s\n",
1503 nt_errstr(result
)));
1505 if (NT_STATUS_EQUAL(result
, NT_STATUS_NO_LOGON_SERVERS
) ||
1506 NT_STATUS_EQUAL(result
, NT_STATUS_IO_TIMEOUT
) ||
1507 NT_STATUS_EQUAL(result
, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
))
1509 DEBUG(10,("winbindd_dual_pam_auth_samlogon setting domain to offline\n"));
1510 set_domain_offline( domain
);
1514 if (domain
->online
) {
1515 /* We're still online - fail. */
1521 /* Check for Cached logons */
1522 if (!domain
->online
&& (state
->request
.flags
& WBFLAG_PAM_CACHED_LOGIN
) &&
1523 lp_winbind_offline_logon()) {
1525 result
= winbindd_dual_pam_auth_cached(domain
, state
, &info3
);
1527 if (NT_STATUS_IS_OK(result
)) {
1528 DEBUG(10,("winbindd_dual_pam_auth_cached succeeded\n"));
1529 goto process_result
;
1531 DEBUG(10,("winbindd_dual_pam_auth_cached failed: %s\n", nt_errstr(result
)));
1538 if (NT_STATUS_IS_OK(result
)) {
1542 /* In all codepaths where result == NT_STATUS_OK info3 must have
1543 been initialized. */
1545 result
= NT_STATUS_INTERNAL_ERROR
;
1549 netsamlogon_cache_store(name_user
, info3
);
1550 wcache_invalidate_samlogon(find_domain_from_name(name_domain
), info3
);
1552 /* save name_to_sid info as early as possible (only if
1553 this is our primary domain so we don't invalidate
1554 the cache entry by storing the seq_num for the wrong
1556 if ( domain
->primary
) {
1557 sid_compose(&user_sid
, &info3
->dom_sid
.sid
,
1559 cache_name2sid(domain
, name_domain
, name_user
,
1560 SID_NAME_USER
, &user_sid
);
1563 /* Check if the user is in the right group */
1565 if (!NT_STATUS_IS_OK(result
= check_info3_in_group(state
->mem_ctx
, info3
,
1566 state
->request
.data
.auth
.require_membership_of_sid
))) {
1567 DEBUG(3, ("User %s is not in the required group (%s), so plaintext authentication is rejected\n",
1568 state
->request
.data
.auth
.user
,
1569 state
->request
.data
.auth
.require_membership_of_sid
));
1573 result
= append_data(state
, info3
, name_domain
, name_user
);
1574 if (!NT_STATUS_IS_OK(result
)) {
1578 if ((state
->request
.flags
& WBFLAG_PAM_CACHED_LOGIN
)) {
1580 /* Store in-memory creds for single-signon using ntlm_auth. */
1581 result
= winbindd_add_memory_creds(state
->request
.data
.auth
.user
,
1582 get_uid_from_state(state
),
1583 state
->request
.data
.auth
.pass
);
1585 if (!NT_STATUS_IS_OK(result
)) {
1586 DEBUG(10,("Failed to store memory creds: %s\n", nt_errstr(result
)));
1590 if (lp_winbind_offline_logon()) {
1591 result
= winbindd_store_creds(domain
,
1593 state
->request
.data
.auth
.user
,
1594 state
->request
.data
.auth
.pass
,
1596 if (!NT_STATUS_IS_OK(result
)) {
1598 /* Release refcount. */
1599 winbindd_delete_memory_creds(state
->request
.data
.auth
.user
);
1601 DEBUG(10,("Failed to store creds: %s\n", nt_errstr(result
)));
1607 result
= fillup_password_policy(domain
, state
);
1609 if (!NT_STATUS_IS_OK(result
)
1610 && !NT_STATUS_EQUAL(result
, NT_STATUS_NOT_SUPPORTED
) )
1612 DEBUG(10,("Failed to get password policies: %s\n", nt_errstr(result
)));
1616 result
= NT_STATUS_OK
;
1620 /* give us a more useful (more correct?) error code */
1621 if ((NT_STATUS_EQUAL(result
, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
) ||
1622 (NT_STATUS_EQUAL(result
, NT_STATUS_UNSUCCESSFUL
)))) {
1623 result
= NT_STATUS_NO_LOGON_SERVERS
;
1626 state
->response
.data
.auth
.nt_status
= NT_STATUS_V(result
);
1627 fstrcpy(state
->response
.data
.auth
.nt_status_string
, nt_errstr(result
));
1629 /* we might have given a more useful error above */
1630 if (!*state
->response
.data
.auth
.error_string
)
1631 fstrcpy(state
->response
.data
.auth
.error_string
, get_friendly_nt_error_msg(result
));
1632 state
->response
.data
.auth
.pam_error
= nt_status_to_pam(result
);
1634 DEBUG(NT_STATUS_IS_OK(result
) ? 5 : 2, ("Plain-text authentication for user %s returned %s (PAM: %d)\n",
1635 state
->request
.data
.auth
.user
,
1636 state
->response
.data
.auth
.nt_status_string
,
1637 state
->response
.data
.auth
.pam_error
));
1639 return NT_STATUS_IS_OK(result
) ? WINBINDD_OK
: WINBINDD_ERROR
;
1643 /**********************************************************************
1644 Challenge Response Authentication Protocol
1645 **********************************************************************/
1647 void winbindd_pam_auth_crap(struct winbindd_cli_state
*state
)
1649 struct winbindd_domain
*domain
= NULL
;
1650 const char *domain_name
= NULL
;
1653 if (!check_request_flags(state
->request
.flags
)) {
1654 result
= NT_STATUS_INVALID_PARAMETER_MIX
;
1658 if (!state
->privileged
) {
1659 char *error_string
= NULL
;
1660 DEBUG(2, ("winbindd_pam_auth_crap: non-privileged access "
1662 DEBUGADD(2, ("winbindd_pam_auth_crap: Ensure permissions "
1663 "on %s are set correctly.\n",
1664 get_winbind_priv_pipe_dir()));
1665 /* send a better message than ACCESS_DENIED */
1666 error_string
= talloc_asprintf(state
->mem_ctx
,
1667 "winbind client not authorized "
1668 "to use winbindd_pam_auth_crap."
1669 " Ensure permissions on %s "
1670 "are set correctly.",
1671 get_winbind_priv_pipe_dir());
1672 fstrcpy(state
->response
.data
.auth
.error_string
, error_string
);
1673 result
= NT_STATUS_ACCESS_DENIED
;
1677 /* Ensure null termination */
1678 state
->request
.data
.auth_crap
.user
1679 [sizeof(state
->request
.data
.auth_crap
.user
)-1]=0;
1680 state
->request
.data
.auth_crap
.domain
1681 [sizeof(state
->request
.data
.auth_crap
.domain
)-1]=0;
1683 DEBUG(3, ("[%5lu]: pam auth crap domain: [%s] user: %s\n",
1684 (unsigned long)state
->pid
,
1685 state
->request
.data
.auth_crap
.domain
,
1686 state
->request
.data
.auth_crap
.user
));
1688 if (*state
->request
.data
.auth_crap
.domain
!= '\0') {
1689 domain_name
= state
->request
.data
.auth_crap
.domain
;
1690 } else if (lp_winbind_use_default_domain()) {
1691 domain_name
= lp_workgroup();
1694 if (domain_name
!= NULL
)
1695 domain
= find_auth_domain(state
, domain_name
);
1697 if (domain
!= NULL
) {
1698 sendto_domain(state
, domain
);
1702 result
= NT_STATUS_NO_SUCH_USER
;
1705 set_auth_errors(&state
->response
, result
);
1706 DEBUG(5, ("CRAP authentication for %s\\%s returned %s (PAM: %d)\n",
1707 state
->request
.data
.auth_crap
.domain
,
1708 state
->request
.data
.auth_crap
.user
,
1709 state
->response
.data
.auth
.nt_status_string
,
1710 state
->response
.data
.auth
.pam_error
));
1711 request_error(state
);
1716 enum winbindd_result
winbindd_dual_pam_auth_crap(struct winbindd_domain
*domain
,
1717 struct winbindd_cli_state
*state
)
1720 NET_USER_INFO_3 info3
;
1721 struct rpc_pipe_client
*netlogon_pipe
;
1722 const char *name_user
= NULL
;
1723 const char *name_domain
= NULL
;
1724 const char *workstation
;
1725 struct winbindd_domain
*contact_domain
;
1729 DATA_BLOB lm_resp
, nt_resp
;
1731 /* This is child-only, so no check for privileged access is needed
1734 /* Ensure null termination */
1735 state
->request
.data
.auth_crap
.user
[sizeof(state
->request
.data
.auth_crap
.user
)-1]=0;
1736 state
->request
.data
.auth_crap
.domain
[sizeof(state
->request
.data
.auth_crap
.domain
)-1]=0;
1738 if (!check_request_flags(state
->request
.flags
)) {
1739 result
= NT_STATUS_INVALID_PARAMETER_MIX
;
1743 name_user
= state
->request
.data
.auth_crap
.user
;
1745 if (*state
->request
.data
.auth_crap
.domain
) {
1746 name_domain
= state
->request
.data
.auth_crap
.domain
;
1747 } else if (lp_winbind_use_default_domain()) {
1748 name_domain
= lp_workgroup();
1750 DEBUG(5,("no domain specified with username (%s) - failing auth\n",
1752 result
= NT_STATUS_NO_SUCH_USER
;
1756 DEBUG(3, ("[%5lu]: pam auth crap domain: %s user: %s\n", (unsigned long)state
->pid
,
1757 name_domain
, name_user
));
1759 if (*state
->request
.data
.auth_crap
.workstation
) {
1760 workstation
= state
->request
.data
.auth_crap
.workstation
;
1762 workstation
= global_myname();
1765 if (state
->request
.data
.auth_crap
.lm_resp_len
> sizeof(state
->request
.data
.auth_crap
.lm_resp
)
1766 || state
->request
.data
.auth_crap
.nt_resp_len
> sizeof(state
->request
.data
.auth_crap
.nt_resp
)) {
1767 DEBUG(0, ("winbindd_pam_auth_crap: invalid password length %u/%u\n",
1768 state
->request
.data
.auth_crap
.lm_resp_len
,
1769 state
->request
.data
.auth_crap
.nt_resp_len
));
1770 result
= NT_STATUS_INVALID_PARAMETER
;
1774 lm_resp
= data_blob_talloc(state
->mem_ctx
, state
->request
.data
.auth_crap
.lm_resp
,
1775 state
->request
.data
.auth_crap
.lm_resp_len
);
1776 nt_resp
= data_blob_talloc(state
->mem_ctx
, state
->request
.data
.auth_crap
.nt_resp
,
1777 state
->request
.data
.auth_crap
.nt_resp_len
);
1779 /* what domain should we contact? */
1782 if (!(contact_domain
= find_domain_from_name(name_domain
))) {
1783 DEBUG(3, ("Authentication for domain for [%s] -> [%s]\\[%s] failed as %s is not a trusted domain\n",
1784 state
->request
.data
.auth_crap
.user
, name_domain
, name_user
, name_domain
));
1785 result
= NT_STATUS_NO_SUCH_USER
;
1789 if (is_myname(name_domain
)) {
1790 DEBUG(3, ("Authentication for domain %s (local domain to this server) not supported at this stage\n", name_domain
));
1791 result
= NT_STATUS_NO_SUCH_USER
;
1794 contact_domain
= find_our_domain();
1798 NTSTATUS (*logon_fn
)(struct rpc_pipe_client
1799 *cli
, TALLOC_CTX
*mem_ctx
,
1800 uint32 logon_parameters
,
1802 const char *username
,
1804 const char *workstation
,
1805 const uint8 chal
[8],
1806 DATA_BLOB lm_response
,
1807 DATA_BLOB nt_response
,
1808 NET_USER_INFO_3
*info3
);
1813 netlogon_pipe
= NULL
;
1814 result
= cm_connect_netlogon(contact_domain
, &netlogon_pipe
);
1816 if (!NT_STATUS_IS_OK(result
)) {
1817 DEBUG(3, ("could not open handle to NETLOGON pipe (error: %s)\n",
1818 nt_errstr(result
)));
1822 logon_fn
= contact_domain
->can_do_samlogon_ex
1823 ? rpccli_netlogon_sam_network_logon_ex
1824 : rpccli_netlogon_sam_network_logon
;
1826 result
= logon_fn(netlogon_pipe
,
1828 state
->request
.data
.auth_crap
.logon_parameters
,
1829 contact_domain
->dcname
,
1832 /* Bug #3248 - found by Stefan Burkei. */
1833 workstation
, /* We carefully set this above so use it... */
1834 state
->request
.data
.auth_crap
.chal
,
1839 if ((NT_STATUS_V(result
) == DCERPC_FAULT_OP_RNG_ERROR
)
1840 && contact_domain
->can_do_samlogon_ex
) {
1841 DEBUG(3, ("Got a DC that can not do NetSamLogonEx, "
1842 "retrying with NetSamLogon\n"));
1843 contact_domain
->can_do_samlogon_ex
= False
;
1850 /* We have to try a second time as cm_connect_netlogon
1851 might not yet have noticed that the DC has killed
1854 if (NT_STATUS_EQUAL(result
, NT_STATUS_UNSUCCESSFUL
)) {
1859 /* if we get access denied, a possible cause was that we had and open
1860 connection to the DC, but someone changed our machine account password
1861 out from underneath us using 'net rpc changetrustpw' */
1863 if ( NT_STATUS_EQUAL(result
, NT_STATUS_ACCESS_DENIED
) ) {
1864 DEBUG(3,("winbindd_pam_auth: sam_logon returned "
1865 "ACCESS_DENIED. Maybe the trust account "
1866 "password was changed and we didn't know it. "
1867 "Killing connections to domain %s\n",
1869 invalidate_cm_connection(&contact_domain
->conn
);
1873 } while ( (attempts
< 2) && retry
);
1875 if (NT_STATUS_IS_OK(result
)) {
1877 netsamlogon_cache_store(name_user
, &info3
);
1878 wcache_invalidate_samlogon(find_domain_from_name(name_domain
), &info3
);
1880 /* Check if the user is in the right group */
1882 if (!NT_STATUS_IS_OK(result
= check_info3_in_group(state
->mem_ctx
, &info3
,
1883 state
->request
.data
.auth_crap
.require_membership_of_sid
))) {
1884 DEBUG(3, ("User %s is not in the required group (%s), so "
1885 "crap authentication is rejected\n",
1886 state
->request
.data
.auth_crap
.user
,
1887 state
->request
.data
.auth_crap
.require_membership_of_sid
));
1891 result
= append_data(state
, &info3
, name_domain
, name_user
);
1892 if (!NT_STATUS_IS_OK(result
)) {
1899 /* give us a more useful (more correct?) error code */
1900 if ((NT_STATUS_EQUAL(result
, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
) ||
1901 (NT_STATUS_EQUAL(result
, NT_STATUS_UNSUCCESSFUL
)))) {
1902 result
= NT_STATUS_NO_LOGON_SERVERS
;
1905 if (state
->request
.flags
& WBFLAG_PAM_NT_STATUS_SQUASH
) {
1906 result
= nt_status_squash(result
);
1909 state
->response
.data
.auth
.nt_status
= NT_STATUS_V(result
);
1910 fstrcpy(state
->response
.data
.auth
.nt_status_string
, nt_errstr(result
));
1912 /* we might have given a more useful error above */
1913 if (!*state
->response
.data
.auth
.error_string
) {
1914 fstrcpy(state
->response
.data
.auth
.error_string
, get_friendly_nt_error_msg(result
));
1916 state
->response
.data
.auth
.pam_error
= nt_status_to_pam(result
);
1918 DEBUG(NT_STATUS_IS_OK(result
) ? 5 : 2,
1919 ("NTLM CRAP authentication for user [%s]\\[%s] returned %s (PAM: %d)\n",
1922 state
->response
.data
.auth
.nt_status_string
,
1923 state
->response
.data
.auth
.pam_error
));
1925 return NT_STATUS_IS_OK(result
) ? WINBINDD_OK
: WINBINDD_ERROR
;
1928 /* Change a user password */
1930 void winbindd_pam_chauthtok(struct winbindd_cli_state
*state
)
1932 fstring domain
, user
;
1933 struct winbindd_domain
*contact_domain
;
1935 DEBUG(3, ("[%5lu]: pam chauthtok %s\n", (unsigned long)state
->pid
,
1936 state
->request
.data
.chauthtok
.user
));
1940 ws_name_return( state
->request
.data
.auth
.user
, WB_REPLACE_CHAR
);
1942 if (!canonicalize_username(state
->request
.data
.chauthtok
.user
, domain
, user
)) {
1943 set_auth_errors(&state
->response
, NT_STATUS_NO_SUCH_USER
);
1944 DEBUG(5, ("winbindd_pam_chauthtok: canonicalize_username %s failed with %s"
1946 state
->request
.data
.auth
.user
,
1947 state
->response
.data
.auth
.nt_status_string
,
1948 state
->response
.data
.auth
.pam_error
));
1949 request_error(state
);
1953 contact_domain
= find_domain_from_name(domain
);
1954 if (!contact_domain
) {
1955 set_auth_errors(&state
->response
, NT_STATUS_NO_SUCH_USER
);
1956 DEBUG(3, ("Cannot change password for [%s] -> [%s]\\[%s] as %s is not a trusted domain\n",
1957 state
->request
.data
.chauthtok
.user
, domain
, user
, domain
));
1958 request_error(state
);
1962 sendto_domain(state
, contact_domain
);
1965 enum winbindd_result
winbindd_dual_pam_chauthtok(struct winbindd_domain
*contact_domain
,
1966 struct winbindd_cli_state
*state
)
1969 char *newpass
= NULL
;
1971 struct rpc_pipe_client
*cli
;
1972 BOOL got_info
= False
;
1973 SAM_UNK_INFO_1 info
;
1974 SAMR_CHANGE_REJECT reject
;
1975 NTSTATUS result
= NT_STATUS_UNSUCCESSFUL
;
1976 fstring domain
, user
;
1978 DEBUG(3, ("[%5lu]: dual pam chauthtok %s\n", (unsigned long)state
->pid
,
1979 state
->request
.data
.auth
.user
));
1981 if (!parse_domain_user(state
->request
.data
.chauthtok
.user
, domain
, user
)) {
1985 /* Change password */
1987 oldpass
= state
->request
.data
.chauthtok
.oldpass
;
1988 newpass
= state
->request
.data
.chauthtok
.newpass
;
1990 /* Initialize reject reason */
1991 state
->response
.data
.auth
.reject_reason
= Undefined
;
1993 /* Get sam handle */
1995 result
= cm_connect_sam(contact_domain
, state
->mem_ctx
, &cli
,
1997 if (!NT_STATUS_IS_OK(result
)) {
1998 DEBUG(1, ("could not get SAM handle on DC for %s\n", domain
));
2002 result
= rpccli_samr_chgpasswd3(cli
, state
->mem_ctx
, user
, newpass
, oldpass
, &info
, &reject
);
2004 /* Windows 2003 returns NT_STATUS_PASSWORD_RESTRICTION */
2006 if (NT_STATUS_EQUAL(result
, NT_STATUS_PASSWORD_RESTRICTION
) ) {
2007 state
->response
.data
.auth
.policy
.min_length_password
=
2008 info
.min_length_password
;
2009 state
->response
.data
.auth
.policy
.password_history
=
2010 info
.password_history
;
2011 state
->response
.data
.auth
.policy
.password_properties
=
2012 info
.password_properties
;
2013 state
->response
.data
.auth
.policy
.expire
=
2014 nt_time_to_unix_abs(&info
.expire
);
2015 state
->response
.data
.auth
.policy
.min_passwordage
=
2016 nt_time_to_unix_abs(&info
.min_passwordage
);
2018 state
->response
.data
.auth
.reject_reason
=
2019 reject
.reject_reason
;
2024 /* only fallback when the chgpasswd3 call is not supported */
2025 if ((NT_STATUS_EQUAL(result
, NT_STATUS(DCERPC_FAULT_OP_RNG_ERROR
))) ||
2026 (NT_STATUS_EQUAL(result
, NT_STATUS_NOT_SUPPORTED
)) ||
2027 (NT_STATUS_EQUAL(result
, NT_STATUS_NOT_IMPLEMENTED
))) {
2029 DEBUG(10,("Password change with chgpasswd3 failed with: %s, retrying chgpasswd_user\n",
2030 nt_errstr(result
)));
2032 result
= rpccli_samr_chgpasswd_user(cli
, state
->mem_ctx
, user
, newpass
, oldpass
);
2034 /* Windows 2000 returns NT_STATUS_ACCOUNT_RESTRICTION.
2035 Map to the same status code as Windows 2003. */
2037 if ( NT_STATUS_EQUAL(NT_STATUS_ACCOUNT_RESTRICTION
, result
) ) {
2038 result
= NT_STATUS_PASSWORD_RESTRICTION
;
2044 if (NT_STATUS_IS_OK(result
) && (state
->request
.flags
& WBFLAG_PAM_CACHED_LOGIN
)) {
2046 /* Update the single sign-on memory creds. */
2047 result
= winbindd_replace_memory_creds(state
->request
.data
.chauthtok
.user
,
2050 if (!NT_STATUS_IS_OK(result
)) {
2051 DEBUG(10,("Failed to replace memory creds: %s\n", nt_errstr(result
)));
2052 goto process_result
;
2055 if (lp_winbind_offline_logon()) {
2056 result
= winbindd_update_creds_by_name(contact_domain
,
2057 state
->mem_ctx
, user
,
2059 if (!NT_STATUS_IS_OK(result
)) {
2060 DEBUG(10,("Failed to store creds: %s\n", nt_errstr(result
)));
2061 goto process_result
;
2066 if (!NT_STATUS_IS_OK(result
) && !got_info
&& contact_domain
) {
2068 NTSTATUS policy_ret
;
2070 policy_ret
= fillup_password_policy(contact_domain
, state
);
2072 /* failure of this is non critical, it will just provide no
2073 * additional information to the client why the change has
2074 * failed - Guenther */
2076 if (!NT_STATUS_IS_OK(policy_ret
)) {
2077 DEBUG(10,("Failed to get password policies: %s\n", nt_errstr(policy_ret
)));
2078 goto process_result
;
2084 state
->response
.data
.auth
.nt_status
= NT_STATUS_V(result
);
2085 fstrcpy(state
->response
.data
.auth
.nt_status_string
, nt_errstr(result
));
2086 fstrcpy(state
->response
.data
.auth
.error_string
, get_friendly_nt_error_msg(result
));
2087 state
->response
.data
.auth
.pam_error
= nt_status_to_pam(result
);
2089 DEBUG(NT_STATUS_IS_OK(result
) ? 5 : 2,
2090 ("Password change for user [%s]\\[%s] returned %s (PAM: %d)\n",
2093 state
->response
.data
.auth
.nt_status_string
,
2094 state
->response
.data
.auth
.pam_error
));
2096 return NT_STATUS_IS_OK(result
) ? WINBINDD_OK
: WINBINDD_ERROR
;
2099 void winbindd_pam_logoff(struct winbindd_cli_state
*state
)
2101 struct winbindd_domain
*domain
;
2102 fstring name_domain
, user
;
2103 uid_t caller_uid
= (uid_t
)-1;
2104 uid_t request_uid
= state
->request
.data
.logoff
.uid
;
2106 DEBUG(3, ("[%5lu]: pam logoff %s\n", (unsigned long)state
->pid
,
2107 state
->request
.data
.logoff
.user
));
2109 /* Ensure null termination */
2110 state
->request
.data
.logoff
.user
2111 [sizeof(state
->request
.data
.logoff
.user
)-1]='\0';
2113 state
->request
.data
.logoff
.krb5ccname
2114 [sizeof(state
->request
.data
.logoff
.krb5ccname
)-1]='\0';
2116 if (request_uid
== (gid_t
)-1) {
2120 if (!canonicalize_username(state
->request
.data
.logoff
.user
, name_domain
, user
)) {
2124 if ((domain
= find_auth_domain(state
, name_domain
)) == NULL
) {
2128 if ((sys_getpeereid(state
->sock
, &caller_uid
)) != 0) {
2129 DEBUG(1,("winbindd_pam_logoff: failed to check peerid: %s\n",
2134 switch (caller_uid
) {
2138 /* root must be able to logoff any user - gd */
2139 state
->request
.data
.logoff
.uid
= request_uid
;
2142 if (caller_uid
!= request_uid
) {
2143 DEBUG(1,("winbindd_pam_logoff: caller requested invalid uid\n"));
2146 state
->request
.data
.logoff
.uid
= caller_uid
;
2150 sendto_domain(state
, domain
);
2154 set_auth_errors(&state
->response
, NT_STATUS_NO_SUCH_USER
);
2155 DEBUG(5, ("Pam Logoff for %s returned %s "
2157 state
->request
.data
.logoff
.user
,
2158 state
->response
.data
.auth
.nt_status_string
,
2159 state
->response
.data
.auth
.pam_error
));
2160 request_error(state
);
2164 enum winbindd_result
winbindd_dual_pam_logoff(struct winbindd_domain
*domain
,
2165 struct winbindd_cli_state
*state
)
2167 NTSTATUS result
= NT_STATUS_NOT_SUPPORTED
;
2169 DEBUG(3, ("[%5lu]: pam dual logoff %s\n", (unsigned long)state
->pid
,
2170 state
->request
.data
.logoff
.user
));
2172 if (!(state
->request
.flags
& WBFLAG_PAM_KRB5
)) {
2173 result
= NT_STATUS_OK
;
2174 goto process_result
;
2177 if (state
->request
.data
.logoff
.krb5ccname
[0] == '\0') {
2178 result
= NT_STATUS_OK
;
2179 goto process_result
;
2184 if (state
->request
.data
.logoff
.uid
< 0) {
2185 DEBUG(0,("winbindd_pam_logoff: invalid uid\n"));
2186 goto process_result
;
2189 /* what we need here is to find the corresponding krb5 ccache name *we*
2190 * created for a given username and destroy it */
2192 if (!ccache_entry_exists(state
->request
.data
.logoff
.user
)) {
2193 result
= NT_STATUS_OK
;
2194 DEBUG(10,("winbindd_pam_logoff: no entry found.\n"));
2195 goto process_result
;
2198 if (!ccache_entry_identical(state
->request
.data
.logoff
.user
,
2199 state
->request
.data
.logoff
.uid
,
2200 state
->request
.data
.logoff
.krb5ccname
)) {
2201 DEBUG(0,("winbindd_pam_logoff: cached entry differs.\n"));
2202 goto process_result
;
2205 result
= remove_ccache(state
->request
.data
.logoff
.user
);
2206 if (!NT_STATUS_IS_OK(result
)) {
2207 DEBUG(0,("winbindd_pam_logoff: failed to remove ccache: %s\n",
2208 nt_errstr(result
)));
2209 goto process_result
;
2213 result
= NT_STATUS_NOT_SUPPORTED
;
2218 winbindd_delete_memory_creds(state
->request
.data
.logoff
.user
);
2220 state
->response
.data
.auth
.nt_status
= NT_STATUS_V(result
);
2221 fstrcpy(state
->response
.data
.auth
.nt_status_string
, nt_errstr(result
));
2222 fstrcpy(state
->response
.data
.auth
.error_string
, get_friendly_nt_error_msg(result
));
2223 state
->response
.data
.auth
.pam_error
= nt_status_to_pam(result
);
2225 return NT_STATUS_IS_OK(result
) ? WINBINDD_OK
: WINBINDD_ERROR
;
2228 /* Change user password with auth crap*/
2230 void winbindd_pam_chng_pswd_auth_crap(struct winbindd_cli_state
*state
)
2232 struct winbindd_domain
*domain
= NULL
;
2233 const char *domain_name
= NULL
;
2235 /* Ensure null termination */
2236 state
->request
.data
.chng_pswd_auth_crap
.user
[
2237 sizeof(state
->request
.data
.chng_pswd_auth_crap
.user
)-1]=0;
2238 state
->request
.data
.chng_pswd_auth_crap
.domain
[
2239 sizeof(state
->request
.data
.chng_pswd_auth_crap
.domain
)-1]=0;
2241 DEBUG(3, ("[%5lu]: pam change pswd auth crap domain: %s user: %s\n",
2242 (unsigned long)state
->pid
,
2243 state
->request
.data
.chng_pswd_auth_crap
.domain
,
2244 state
->request
.data
.chng_pswd_auth_crap
.user
));
2246 if (*state
->request
.data
.chng_pswd_auth_crap
.domain
!= '\0') {
2247 domain_name
= state
->request
.data
.chng_pswd_auth_crap
.domain
;
2248 } else if (lp_winbind_use_default_domain()) {
2249 domain_name
= lp_workgroup();
2252 if (domain_name
!= NULL
)
2253 domain
= find_domain_from_name(domain_name
);
2255 if (domain
!= NULL
) {
2256 DEBUG(7, ("[%5lu]: pam auth crap changing pswd in domain: "
2257 "%s\n", (unsigned long)state
->pid
,domain
->name
));
2258 sendto_domain(state
, domain
);
2262 set_auth_errors(&state
->response
, NT_STATUS_NO_SUCH_USER
);
2263 DEBUG(5, ("CRAP change password for %s\\%s returned %s (PAM: %d)\n",
2264 state
->request
.data
.chng_pswd_auth_crap
.domain
,
2265 state
->request
.data
.chng_pswd_auth_crap
.user
,
2266 state
->response
.data
.auth
.nt_status_string
,
2267 state
->response
.data
.auth
.pam_error
));
2268 request_error(state
);
2272 enum winbindd_result
winbindd_dual_pam_chng_pswd_auth_crap(struct winbindd_domain
*domainSt
, struct winbindd_cli_state
*state
)
2275 DATA_BLOB new_nt_password
;
2276 DATA_BLOB old_nt_hash_enc
;
2277 DATA_BLOB new_lm_password
;
2278 DATA_BLOB old_lm_hash_enc
;
2279 fstring domain
,user
;
2281 struct winbindd_domain
*contact_domain
= domainSt
;
2282 struct rpc_pipe_client
*cli
;
2284 /* Ensure null termination */
2285 state
->request
.data
.chng_pswd_auth_crap
.user
[
2286 sizeof(state
->request
.data
.chng_pswd_auth_crap
.user
)-1]=0;
2287 state
->request
.data
.chng_pswd_auth_crap
.domain
[
2288 sizeof(state
->request
.data
.chng_pswd_auth_crap
.domain
)-1]=0;
2292 DEBUG(3, ("[%5lu]: pam change pswd auth crap domain: %s user: %s\n",
2293 (unsigned long)state
->pid
,
2294 state
->request
.data
.chng_pswd_auth_crap
.domain
,
2295 state
->request
.data
.chng_pswd_auth_crap
.user
));
2297 if (lp_winbind_offline_logon()) {
2298 DEBUG(0,("Refusing password change as winbind offline logons are enabled. "));
2299 DEBUGADD(0,("Changing passwords here would risk inconsistent logons\n"));
2300 result
= NT_STATUS_ACCESS_DENIED
;
2304 if (*state
->request
.data
.chng_pswd_auth_crap
.domain
) {
2305 fstrcpy(domain
,state
->request
.data
.chng_pswd_auth_crap
.domain
);
2307 parse_domain_user(state
->request
.data
.chng_pswd_auth_crap
.user
,
2311 DEBUG(3,("no domain specified with username (%s) - "
2313 state
->request
.data
.chng_pswd_auth_crap
.user
));
2314 result
= NT_STATUS_NO_SUCH_USER
;
2319 if (!*domain
&& lp_winbind_use_default_domain()) {
2320 fstrcpy(domain
,(char *)lp_workgroup());
2324 fstrcpy(user
, state
->request
.data
.chng_pswd_auth_crap
.user
);
2327 DEBUG(3, ("[%5lu]: pam auth crap domain: %s user: %s\n",
2328 (unsigned long)state
->pid
, domain
, user
));
2330 /* Change password */
2331 new_nt_password
= data_blob_talloc(
2333 state
->request
.data
.chng_pswd_auth_crap
.new_nt_pswd
,
2334 state
->request
.data
.chng_pswd_auth_crap
.new_nt_pswd_len
);
2336 old_nt_hash_enc
= data_blob_talloc(
2338 state
->request
.data
.chng_pswd_auth_crap
.old_nt_hash_enc
,
2339 state
->request
.data
.chng_pswd_auth_crap
.old_nt_hash_enc_len
);
2341 if(state
->request
.data
.chng_pswd_auth_crap
.new_lm_pswd_len
> 0) {
2342 new_lm_password
= data_blob_talloc(
2344 state
->request
.data
.chng_pswd_auth_crap
.new_lm_pswd
,
2345 state
->request
.data
.chng_pswd_auth_crap
.new_lm_pswd_len
);
2347 old_lm_hash_enc
= data_blob_talloc(
2349 state
->request
.data
.chng_pswd_auth_crap
.old_lm_hash_enc
,
2350 state
->request
.data
.chng_pswd_auth_crap
.old_lm_hash_enc_len
);
2352 new_lm_password
.length
= 0;
2353 old_lm_hash_enc
.length
= 0;
2356 /* Get sam handle */
2358 result
= cm_connect_sam(contact_domain
, state
->mem_ctx
, &cli
, &dom_pol
);
2359 if (!NT_STATUS_IS_OK(result
)) {
2360 DEBUG(1, ("could not get SAM handle on DC for %s\n", domain
));
2364 result
= rpccli_samr_chng_pswd_auth_crap(
2365 cli
, state
->mem_ctx
, user
, new_nt_password
, old_nt_hash_enc
,
2366 new_lm_password
, old_lm_hash_enc
);
2369 state
->response
.data
.auth
.nt_status
= NT_STATUS_V(result
);
2370 fstrcpy(state
->response
.data
.auth
.nt_status_string
, nt_errstr(result
));
2371 fstrcpy(state
->response
.data
.auth
.error_string
,
2372 get_friendly_nt_error_msg(result
));
2373 state
->response
.data
.auth
.pam_error
= nt_status_to_pam(result
);
2375 DEBUG(NT_STATUS_IS_OK(result
) ? 5 : 2,
2376 ("Password change for user [%s]\\[%s] returned %s (PAM: %d)\n",
2378 state
->response
.data
.auth
.nt_status_string
,
2379 state
->response
.data
.auth
.pam_error
));
2381 return NT_STATUS_IS_OK(result
) ? WINBINDD_OK
: WINBINDD_ERROR
;