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)
34 state->response.data.auth.info3.logon_time =
35 nt_time_to_unix(info3->logon_time);
36 state->response.data.auth.info3.logoff_time =
37 nt_time_to_unix(info3->logoff_time);
38 state->response.data.auth.info3.kickoff_time =
39 nt_time_to_unix(info3->kickoff_time);
40 state->response.data.auth.info3.pass_last_set_time =
41 nt_time_to_unix(info3->pass_last_set_time);
42 state->response.data.auth.info3.pass_can_change_time =
43 nt_time_to_unix(info3->pass_can_change_time);
44 state->response.data.auth.info3.pass_must_change_time =
45 nt_time_to_unix(info3->pass_must_change_time);
47 state->response.data.auth.info3.logon_count = info3->logon_count;
48 state->response.data.auth.info3.bad_pw_count = info3->bad_pw_count;
50 state->response.data.auth.info3.user_rid = info3->user_rid;
51 state->response.data.auth.info3.group_rid = info3->group_rid;
52 sid_to_fstring(state->response.data.auth.info3.dom_sid, &(info3->dom_sid.sid));
54 state->response.data.auth.info3.num_groups = info3->num_groups;
55 state->response.data.auth.info3.user_flgs = info3->user_flgs;
57 state->response.data.auth.info3.acct_flags = info3->acct_flags;
58 state->response.data.auth.info3.num_other_sids = info3->num_other_sids;
60 unistr2_to_ascii(state->response.data.auth.info3.user_name,
61 &info3->uni_user_name,
62 sizeof(state->response.data.auth.info3.user_name));
63 unistr2_to_ascii(state->response.data.auth.info3.full_name,
64 &info3->uni_full_name,
65 sizeof(state->response.data.auth.info3.full_name));
66 unistr2_to_ascii(state->response.data.auth.info3.logon_script,
67 &info3->uni_logon_script,
68 sizeof(state->response.data.auth.info3.logon_script));
69 unistr2_to_ascii(state->response.data.auth.info3.profile_path,
70 &info3->uni_profile_path,
71 sizeof(state->response.data.auth.info3.profile_path));
72 unistr2_to_ascii(state->response.data.auth.info3.home_dir,
74 sizeof(state->response.data.auth.info3.home_dir));
75 unistr2_to_ascii(state->response.data.auth.info3.dir_drive,
76 &info3->uni_dir_drive,
77 sizeof(state->response.data.auth.info3.dir_drive));
79 unistr2_to_ascii(state->response.data.auth.info3.logon_srv,
80 &info3->uni_logon_srv,
81 sizeof(state->response.data.auth.info3.logon_srv));
82 unistr2_to_ascii(state->response.data.auth.info3.logon_dom,
83 &info3->uni_logon_dom,
84 sizeof(state->response.data.auth.info3.logon_dom));
89 static NTSTATUS append_info3_as_ndr(TALLOC_CTX *mem_ctx,
90 struct winbindd_cli_state *state,
91 NET_USER_INFO_3 *info3)
95 if (!prs_init(&ps, 256 /* Random, non-zero number */, mem_ctx, MARSHALL)) {
96 return NT_STATUS_NO_MEMORY;
98 if (!net_io_user_info3("", info3, &ps, 1, 3, False)) {
100 return NT_STATUS_UNSUCCESSFUL;
103 size = prs_data_size(&ps);
104 SAFE_FREE(state->response.extra_data.data);
105 state->response.extra_data.data = SMB_MALLOC(size);
106 if (!state->response.extra_data.data) {
108 return NT_STATUS_NO_MEMORY;
110 memset( state->response.extra_data.data, '\0', size );
111 prs_copy_all_data_out((char *)state->response.extra_data.data, &ps);
112 state->response.length += size;
117 static NTSTATUS append_unix_username(TALLOC_CTX *mem_ctx,
118 struct winbindd_cli_state *state,
119 const NET_USER_INFO_3 *info3,
120 const char *name_domain,
121 const char *name_user)
123 /* We've been asked to return the unix username, per
124 'winbind use default domain' settings and the like */
126 fstring username_out;
127 const char *nt_username, *nt_domain;
129 if (!(nt_domain = unistr2_to_ascii_talloc(mem_ctx,
130 &info3->uni_logon_dom))) {
131 /* If the server didn't give us one, just use the one
133 nt_domain = name_domain;
136 if (!(nt_username = unistr2_to_ascii_talloc(mem_ctx,
137 &info3->uni_user_name))) {
138 /* If the server didn't give us one, just use the one
140 nt_username = name_user;
143 fill_domain_username(username_out, nt_domain, nt_username,
146 DEBUG(5,("Setting unix username to [%s]\n", username_out));
148 SAFE_FREE(state->response.extra_data.data);
149 state->response.extra_data.data = SMB_STRDUP(username_out);
150 if (!state->response.extra_data.data) {
151 return NT_STATUS_NO_MEMORY;
153 state->response.length +=
154 strlen((const char *)state->response.extra_data.data)+1;
159 static NTSTATUS append_afs_token(TALLOC_CTX *mem_ctx,
160 struct winbindd_cli_state *state,
161 const NET_USER_INFO_3 *info3,
162 const char *name_domain,
163 const char *name_user)
165 char *afsname = NULL;
168 afsname = talloc_strdup(mem_ctx, lp_afs_username_map());
169 if (afsname == NULL) {
170 return NT_STATUS_NO_MEMORY;
173 afsname = talloc_string_sub(mem_ctx,
174 lp_afs_username_map(),
176 afsname = talloc_string_sub(mem_ctx, afsname,
178 afsname = talloc_string_sub(mem_ctx, afsname,
185 sid_copy(&user_sid, &info3->dom_sid.sid);
186 sid_append_rid(&user_sid, info3->user_rid);
187 sid_to_fstring(sidstr, &user_sid);
188 afsname = talloc_string_sub(mem_ctx, afsname,
192 if (afsname == NULL) {
193 return NT_STATUS_NO_MEMORY;
198 DEBUG(10, ("Generating token for user %s\n", afsname));
200 cell = strchr(afsname, '@');
203 return NT_STATUS_NO_MEMORY;
209 /* Append an AFS token string */
210 SAFE_FREE(state->response.extra_data.data);
211 state->response.extra_data.data =
212 afs_createtoken_str(afsname, cell);
214 if (state->response.extra_data.data != NULL) {
215 state->response.length +=
216 strlen((const char *)state->response.extra_data.data)+1;
222 static NTSTATUS check_info3_in_group(TALLOC_CTX *mem_ctx,
223 NET_USER_INFO_3 *info3,
224 const char *group_sid)
226 * Check whether a user belongs to a group or list of groups.
228 * @param mem_ctx talloc memory context.
229 * @param info3 user information, including group membership info.
230 * @param group_sid One or more groups , separated by commas.
232 * @return NT_STATUS_OK on success,
233 * NT_STATUS_LOGON_FAILURE if the user does not belong,
234 * or other NT_STATUS_IS_ERR(status) for other kinds of failure.
237 DOM_SID *require_membership_of_sid;
238 size_t num_require_membership_of_sid;
243 struct nt_user_token *token;
244 TALLOC_CTX *frame = NULL;
247 /* Parse the 'required group' SID */
249 if (!group_sid || !group_sid[0]) {
250 /* NO sid supplied, all users may access */
254 if (!(token = TALLOC_ZERO_P(mem_ctx, struct nt_user_token))) {
255 DEBUG(0, ("talloc failed\n"));
256 return NT_STATUS_NO_MEMORY;
259 num_require_membership_of_sid = 0;
260 require_membership_of_sid = NULL;
264 frame = talloc_stackframe();
265 while (next_token_talloc(frame, &p, &req_sid, ",")) {
266 if (!string_to_sid(&sid, req_sid)) {
267 DEBUG(0, ("check_info3_in_group: could not parse %s "
268 "as a SID!", req_sid));
270 return NT_STATUS_INVALID_PARAMETER;
273 status = add_sid_to_array(mem_ctx, &sid,
274 &require_membership_of_sid,
275 &num_require_membership_of_sid);
276 if (!NT_STATUS_IS_OK(status)) {
277 DEBUG(0, ("add_sid_to_array failed\n"));
285 status = sid_array_from_info3(mem_ctx, info3,
289 if (!NT_STATUS_IS_OK(status)) {
293 if (!NT_STATUS_IS_OK(status = add_aliases(get_global_sam_sid(),
295 || !NT_STATUS_IS_OK(status = add_aliases(&global_sid_Builtin,
297 DEBUG(3, ("could not add aliases: %s\n",
302 debug_nt_user_token(DBGC_CLASS, 10, token);
304 for (i=0; i<num_require_membership_of_sid; i++) {
305 DEBUG(10, ("Checking SID %s\n", sid_string_dbg(
306 &require_membership_of_sid[i])));
307 if (nt_token_check_sid(&require_membership_of_sid[i],
309 DEBUG(10, ("Access ok\n"));
314 /* Do not distinguish this error from a wrong username/pw */
316 return NT_STATUS_LOGON_FAILURE;
319 struct winbindd_domain *find_auth_domain(struct winbindd_cli_state *state,
320 const char *domain_name)
322 struct winbindd_domain *domain;
325 domain = find_domain_from_name_noinit(domain_name);
326 if (domain == NULL) {
327 DEBUG(3, ("Authentication for domain [%s] refused"
328 "as it is not a trusted domain\n",
334 if (is_myname(domain_name)) {
335 DEBUG(3, ("Authentication for domain %s (local domain "
336 "to this server) not supported at this "
337 "stage\n", domain_name));
341 /* we can auth against trusted domains */
342 if (state->request.flags & WBFLAG_PAM_CONTACT_TRUSTDOM) {
343 domain = find_domain_from_name_noinit(domain_name);
344 if (domain == NULL) {
345 DEBUG(3, ("Authentication for domain [%s] skipped "
346 "as it is not a trusted domain\n",
353 return find_our_domain();
356 static void set_auth_errors(struct winbindd_response *resp, NTSTATUS result)
358 resp->data.auth.nt_status = NT_STATUS_V(result);
359 fstrcpy(resp->data.auth.nt_status_string, nt_errstr(result));
361 /* we might have given a more useful error above */
362 if (*resp->data.auth.error_string == '\0')
363 fstrcpy(resp->data.auth.error_string,
364 get_friendly_nt_error_msg(result));
365 resp->data.auth.pam_error = nt_status_to_pam(result);
368 static NTSTATUS fillup_password_policy(struct winbindd_domain *domain,
369 struct winbindd_cli_state *state)
371 struct winbindd_methods *methods;
372 NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
373 SAM_UNK_INFO_1 password_policy;
375 if ( !winbindd_can_contact_domain( domain ) ) {
376 DEBUG(5,("fillup_password_policy: No inbound trust to "
377 "contact domain %s\n", domain->name));
378 return NT_STATUS_NOT_SUPPORTED;
381 methods = domain->methods;
383 status = methods->password_policy(domain, state->mem_ctx, &password_policy);
384 if (NT_STATUS_IS_ERR(status)) {
388 state->response.data.auth.policy.min_length_password =
389 password_policy.min_length_password;
390 state->response.data.auth.policy.password_history =
391 password_policy.password_history;
392 state->response.data.auth.policy.password_properties =
393 password_policy.password_properties;
394 state->response.data.auth.policy.expire =
395 nt_time_to_unix_abs(&(password_policy.expire));
396 state->response.data.auth.policy.min_passwordage =
397 nt_time_to_unix_abs(&(password_policy.min_passwordage));
402 static NTSTATUS get_max_bad_attempts_from_lockout_policy(struct winbindd_domain *domain,
404 uint16 *max_allowed_bad_attempts)
406 struct winbindd_methods *methods;
407 NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
408 SAM_UNK_INFO_12 lockout_policy;
410 *max_allowed_bad_attempts = 0;
412 methods = domain->methods;
414 status = methods->lockout_policy(domain, mem_ctx, &lockout_policy);
415 if (NT_STATUS_IS_ERR(status)) {
419 *max_allowed_bad_attempts = lockout_policy.bad_attempt_lockout;
424 static NTSTATUS get_pwd_properties(struct winbindd_domain *domain,
426 uint32 *password_properties)
428 struct winbindd_methods *methods;
429 NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
430 SAM_UNK_INFO_1 password_policy;
432 *password_properties = 0;
434 methods = domain->methods;
436 status = methods->password_policy(domain, mem_ctx, &password_policy);
437 if (NT_STATUS_IS_ERR(status)) {
441 *password_properties = password_policy.password_properties;
448 static const char *generate_krb5_ccache(TALLOC_CTX *mem_ctx,
451 bool *internal_ccache)
453 /* accept FILE and WRFILE as krb5_cc_type from the client and then
454 * build the full ccname string based on the user's uid here -
457 const char *gen_cc = NULL;
459 *internal_ccache = True;
465 if (!type || type[0] == '\0') {
469 if (strequal(type, "FILE")) {
470 gen_cc = talloc_asprintf(mem_ctx, "FILE:/tmp/krb5cc_%d", uid);
471 } else if (strequal(type, "WRFILE")) {
472 gen_cc = talloc_asprintf(mem_ctx, "WRFILE:/tmp/krb5cc_%d", uid);
474 DEBUG(10,("we don't allow to set a %s type ccache\n", type));
478 *internal_ccache = False;
482 gen_cc = talloc_strdup(mem_ctx, "MEMORY:winbindd_pam_ccache");
485 if (gen_cc == NULL) {
486 DEBUG(0,("out of memory\n"));
490 DEBUG(10,("using ccache: %s %s\n", gen_cc, *internal_ccache ? "(internal)":""));
495 static void setup_return_cc_name(struct winbindd_cli_state *state, const char *cc)
497 const char *type = state->request.data.auth.krb5_cc_type;
499 state->response.data.auth.krb5ccname[0] = '\0';
501 if (type[0] == '\0') {
505 if (!strequal(type, "FILE") &&
506 !strequal(type, "WRFILE")) {
507 DEBUG(10,("won't return krbccname for a %s type ccache\n",
512 fstrcpy(state->response.data.auth.krb5ccname, cc);
517 static uid_t get_uid_from_state(struct winbindd_cli_state *state)
521 uid = state->request.data.auth.uid;
524 DEBUG(1,("invalid uid: '%d'\n", uid));
530 /**********************************************************************
531 Authenticate a user with a clear text password using Kerberos and fill up
533 **********************************************************************/
535 static NTSTATUS winbindd_raw_kerberos_login(struct winbindd_domain *domain,
536 struct winbindd_cli_state *state,
537 NET_USER_INFO_3 **info3)
540 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
541 krb5_error_code krb5_ret;
542 const char *cc = NULL;
543 const char *principal_s = NULL;
544 const char *service = NULL;
546 fstring name_domain, name_user;
547 time_t ticket_lifetime = 0;
548 time_t renewal_until = 0;
551 time_t time_offset = 0;
552 bool internal_ccache = True;
559 * prepare a krb5_cc_cache string for the user */
561 uid = get_uid_from_state(state);
563 DEBUG(0,("no valid uid\n"));
566 cc = generate_krb5_ccache(state->mem_ctx,
567 state->request.data.auth.krb5_cc_type,
568 state->request.data.auth.uid,
571 return NT_STATUS_NO_MEMORY;
576 * get kerberos properties */
578 if (domain->private_data) {
579 ads = (ADS_STRUCT *)domain->private_data;
580 time_offset = ads->auth.time_offset;
585 * do kerberos auth and setup ccache as the user */
587 parse_domain_user(state->request.data.auth.user, name_domain, name_user);
589 realm = domain->alt_name;
592 principal_s = talloc_asprintf(state->mem_ctx, "%s@%s", name_user, realm);
593 if (principal_s == NULL) {
594 return NT_STATUS_NO_MEMORY;
597 service = talloc_asprintf(state->mem_ctx, "%s/%s@%s", KRB5_TGS_NAME, realm, realm);
598 if (service == NULL) {
599 return NT_STATUS_NO_MEMORY;
602 /* if this is a user ccache, we need to act as the user to let the krb5
603 * library handle the chown, etc. */
605 /************************ ENTERING NON-ROOT **********************/
607 if (!internal_ccache) {
608 set_effective_uid(uid);
609 DEBUG(10,("winbindd_raw_kerberos_login: uid is %d\n", uid));
612 result = kerberos_return_info3_from_pac(state->mem_ctx,
614 state->request.data.auth.pass,
621 WINBINDD_PAM_AUTH_KRB5_RENEW_TIME,
623 if (!internal_ccache) {
624 gain_root_privilege();
627 /************************ RETURNED TO ROOT **********************/
629 if (!NT_STATUS_IS_OK(result)) {
633 DEBUG(10,("winbindd_raw_kerberos_login: winbindd validated ticket of %s\n",
636 /* if we had a user's ccache then return that string for the pam
639 if (!internal_ccache) {
641 setup_return_cc_name(state, cc);
643 result = add_ccache_to_list(principal_s,
646 state->request.data.auth.user,
654 if (!NT_STATUS_IS_OK(result)) {
655 DEBUG(10,("winbindd_raw_kerberos_login: failed to add ccache to list: %s\n",
660 /* need to delete the memory cred cache, it is not used anymore */
662 krb5_ret = ads_kdestroy(cc);
664 DEBUG(3,("winbindd_raw_kerberos_login: "
665 "could not destroy krb5 credential cache: "
666 "%s\n", error_message(krb5_ret)));
675 /* we could have created a new credential cache with a valid tgt in it
676 * but we werent able to get or verify the service ticket for this
677 * local host and therefor didn't get the PAC, we need to remove that
678 * cache entirely now */
680 krb5_ret = ads_kdestroy(cc);
682 DEBUG(3,("winbindd_raw_kerberos_login: "
683 "could not destroy krb5 credential cache: "
684 "%s\n", error_message(krb5_ret)));
687 if (!NT_STATUS_IS_OK(remove_ccache(state->request.data.auth.user))) {
688 DEBUG(3,("winbindd_raw_kerberos_login: "
689 "could not remove ccache for user %s\n",
690 state->request.data.auth.user));
695 return NT_STATUS_NOT_SUPPORTED;
696 #endif /* HAVE_KRB5 */
699 /****************************************************************
700 ****************************************************************/
702 static bool check_request_flags(uint32_t flags)
704 uint32_t flags_edata = WBFLAG_PAM_AFS_TOKEN |
705 WBFLAG_PAM_UNIX_NAME |
706 WBFLAG_PAM_INFO3_NDR;
708 if ( ( (flags & flags_edata) == WBFLAG_PAM_AFS_TOKEN) ||
709 ( (flags & flags_edata) == WBFLAG_PAM_INFO3_NDR) ||
710 ( (flags & flags_edata) == WBFLAG_PAM_UNIX_NAME) ||
711 !(flags & flags_edata) ) {
715 DEBUG(1,("check_request_flags: invalid request flags\n"));
720 /****************************************************************
721 ****************************************************************/
723 static NTSTATUS append_data(struct winbindd_cli_state *state,
724 NET_USER_INFO_3 *info3,
725 const char *name_domain,
726 const char *name_user)
729 uint32_t flags = state->request.flags;
731 if (flags & WBFLAG_PAM_USER_SESSION_KEY) {
732 memcpy(state->response.data.auth.user_session_key,
733 info3->user_sess_key,
734 sizeof(state->response.data.auth.user_session_key)
738 if (flags & WBFLAG_PAM_LMKEY) {
739 memcpy(state->response.data.auth.first_8_lm_hash,
741 sizeof(state->response.data.auth.first_8_lm_hash)
745 if (flags & WBFLAG_PAM_INFO3_TEXT) {
746 result = append_info3_as_txt(state->mem_ctx, state, info3);
747 if (!NT_STATUS_IS_OK(result)) {
748 DEBUG(10,("Failed to append INFO3 (TXT): %s\n",
754 /* currently, anything from here on potentially overwrites extra_data. */
756 if (flags & WBFLAG_PAM_INFO3_NDR) {
757 result = append_info3_as_ndr(state->mem_ctx, state, info3);
758 if (!NT_STATUS_IS_OK(result)) {
759 DEBUG(10,("Failed to append INFO3 (NDR): %s\n",
765 if (flags & WBFLAG_PAM_UNIX_NAME) {
766 result = append_unix_username(state->mem_ctx, state, info3,
767 name_domain, name_user);
768 if (!NT_STATUS_IS_OK(result)) {
769 DEBUG(10,("Failed to append Unix Username: %s\n",
775 if (flags & WBFLAG_PAM_AFS_TOKEN) {
776 result = append_afs_token(state->mem_ctx, state, info3,
777 name_domain, name_user);
778 if (!NT_STATUS_IS_OK(result)) {
779 DEBUG(10,("Failed to append AFS token: %s\n",
788 void winbindd_pam_auth(struct winbindd_cli_state *state)
790 struct winbindd_domain *domain;
791 fstring name_domain, name_user;
794 /* Ensure null termination */
795 state->request.data.auth.user
796 [sizeof(state->request.data.auth.user)-1]='\0';
798 /* Ensure null termination */
799 state->request.data.auth.pass
800 [sizeof(state->request.data.auth.pass)-1]='\0';
802 DEBUG(3, ("[%5lu]: pam auth %s\n", (unsigned long)state->pid,
803 state->request.data.auth.user));
805 if (!check_request_flags(state->request.flags)) {
806 result = NT_STATUS_INVALID_PARAMETER_MIX;
810 /* Parse domain and username */
812 ws_name_return( state->request.data.auth.user, WB_REPLACE_CHAR );
814 if (!canonicalize_username(state->request.data.auth.user,
815 name_domain, name_user)) {
816 result = NT_STATUS_NO_SUCH_USER;
820 domain = find_auth_domain(state, name_domain);
822 if (domain == NULL) {
823 result = NT_STATUS_NO_SUCH_USER;
827 sendto_domain(state, domain);
830 set_auth_errors(&state->response, result);
831 DEBUG(5, ("Plain text authentication for %s returned %s "
833 state->request.data.auth.user,
834 state->response.data.auth.nt_status_string,
835 state->response.data.auth.pam_error));
836 request_error(state);
839 NTSTATUS winbindd_dual_pam_auth_cached(struct winbindd_domain *domain,
840 struct winbindd_cli_state *state,
841 NET_USER_INFO_3 **info3)
843 NTSTATUS result = NT_STATUS_LOGON_FAILURE;
844 uint16 max_allowed_bad_attempts;
845 fstring name_domain, name_user;
847 enum lsa_SidType type;
848 uchar new_nt_pass[NT_HASH_LEN];
849 const uint8 *cached_nt_pass;
850 const uint8 *cached_salt;
851 NET_USER_INFO_3 *my_info3;
852 time_t kickoff_time, must_change_time;
853 bool password_good = False;
855 struct winbindd_tdc_domain *tdc_domain = NULL;
862 DEBUG(10,("winbindd_dual_pam_auth_cached\n"));
864 /* Parse domain and username */
866 parse_domain_user(state->request.data.auth.user, name_domain, name_user);
869 if (!lookup_cached_name(state->mem_ctx,
874 DEBUG(10,("winbindd_dual_pam_auth_cached: no such user in the cache\n"));
875 return NT_STATUS_NO_SUCH_USER;
878 if (type != SID_NAME_USER) {
879 DEBUG(10,("winbindd_dual_pam_auth_cached: not a user (%s)\n", sid_type_lookup(type)));
880 return NT_STATUS_LOGON_FAILURE;
883 result = winbindd_get_creds(domain,
889 if (!NT_STATUS_IS_OK(result)) {
890 DEBUG(10,("winbindd_dual_pam_auth_cached: failed to get creds: %s\n", nt_errstr(result)));
896 E_md4hash(state->request.data.auth.pass, new_nt_pass);
898 dump_data_pw("new_nt_pass", new_nt_pass, NT_HASH_LEN);
899 dump_data_pw("cached_nt_pass", cached_nt_pass, NT_HASH_LEN);
901 dump_data_pw("cached_salt", cached_salt, NT_HASH_LEN);
905 /* In this case we didn't store the nt_hash itself,
906 but the MD5 combination of salt + nt_hash. */
907 uchar salted_hash[NT_HASH_LEN];
908 E_md5hash(cached_salt, new_nt_pass, salted_hash);
910 password_good = (memcmp(cached_nt_pass, salted_hash, NT_HASH_LEN) == 0) ?
913 /* Old cached cred - direct store of nt_hash (bad bad bad !). */
914 password_good = (memcmp(cached_nt_pass, new_nt_pass, NT_HASH_LEN) == 0) ?
920 /* User *DOES* know the password, update logon_time and reset
923 my_info3->user_flgs |= NETLOGON_CACHED_ACCOUNT;
925 if (my_info3->acct_flags & ACB_AUTOLOCK) {
926 return NT_STATUS_ACCOUNT_LOCKED_OUT;
929 if (my_info3->acct_flags & ACB_DISABLED) {
930 return NT_STATUS_ACCOUNT_DISABLED;
933 if (my_info3->acct_flags & ACB_WSTRUST) {
934 return NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT;
937 if (my_info3->acct_flags & ACB_SVRTRUST) {
938 return NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT;
941 if (my_info3->acct_flags & ACB_DOMTRUST) {
942 return NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT;
945 if (!(my_info3->acct_flags & ACB_NORMAL)) {
946 DEBUG(0,("winbindd_dual_pam_auth_cached: whats wrong with that one?: 0x%08x\n",
947 my_info3->acct_flags));
948 return NT_STATUS_LOGON_FAILURE;
951 kickoff_time = nt_time_to_unix(my_info3->kickoff_time);
952 if (kickoff_time != 0 && time(NULL) > kickoff_time) {
953 return NT_STATUS_ACCOUNT_EXPIRED;
956 must_change_time = nt_time_to_unix(my_info3->pass_must_change_time);
957 if (must_change_time != 0 && must_change_time < time(NULL)) {
958 /* we allow grace logons when the password has expired */
959 my_info3->user_flgs |= NETLOGON_GRACE_LOGON;
960 /* return NT_STATUS_PASSWORD_EXPIRED; */
965 if ((state->request.flags & WBFLAG_PAM_KRB5) &&
966 ((tdc_domain = wcache_tdc_fetch_domain(state->mem_ctx, name_domain)) != NULL) &&
967 (tdc_domain->trust_type & DS_DOMAIN_TRUST_TYPE_UPLEVEL)) {
970 const char *cc = NULL;
972 const char *principal_s = NULL;
973 const char *service = NULL;
974 bool internal_ccache = False;
976 uid = get_uid_from_state(state);
978 DEBUG(0,("winbindd_dual_pam_auth_cached: invalid uid\n"));
979 return NT_STATUS_INVALID_PARAMETER;
982 cc = generate_krb5_ccache(state->mem_ctx,
983 state->request.data.auth.krb5_cc_type,
984 state->request.data.auth.uid,
987 return NT_STATUS_NO_MEMORY;
990 realm = domain->alt_name;
993 principal_s = talloc_asprintf(state->mem_ctx, "%s@%s", name_user, realm);
994 if (principal_s == NULL) {
995 return NT_STATUS_NO_MEMORY;
998 service = talloc_asprintf(state->mem_ctx, "%s/%s@%s", KRB5_TGS_NAME, realm, realm);
999 if (service == NULL) {
1000 return NT_STATUS_NO_MEMORY;
1003 if (!internal_ccache) {
1005 setup_return_cc_name(state, cc);
1007 result = add_ccache_to_list(principal_s,
1010 state->request.data.auth.user,
1014 time(NULL) + lp_winbind_cache_time(),
1015 time(NULL) + WINBINDD_PAM_AUTH_KRB5_RENEW_TIME,
1018 if (!NT_STATUS_IS_OK(result)) {
1019 DEBUG(10,("winbindd_dual_pam_auth_cached: failed "
1020 "to add ccache to list: %s\n",
1021 nt_errstr(result)));
1025 #endif /* HAVE_KRB5 */
1027 /* FIXME: we possibly should handle logon hours as well (does xp when
1028 * offline?) see auth/auth_sam.c:sam_account_ok for details */
1030 unix_to_nt_time(&my_info3->logon_time, time(NULL));
1031 my_info3->bad_pw_count = 0;
1033 result = winbindd_update_creds_by_info3(domain,
1035 state->request.data.auth.user,
1036 state->request.data.auth.pass,
1038 if (!NT_STATUS_IS_OK(result)) {
1039 DEBUG(1,("winbindd_dual_pam_auth_cached: failed to update creds: %s\n",
1040 nt_errstr(result)));
1044 return NT_STATUS_OK;
1048 /* User does *NOT* know the correct password, modify info3 accordingly */
1050 /* failure of this is not critical */
1051 result = get_max_bad_attempts_from_lockout_policy(domain, state->mem_ctx, &max_allowed_bad_attempts);
1052 if (!NT_STATUS_IS_OK(result)) {
1053 DEBUG(10,("winbindd_dual_pam_auth_cached: failed to get max_allowed_bad_attempts. "
1054 "Won't be able to honour account lockout policies\n"));
1057 /* increase counter */
1058 my_info3->bad_pw_count++;
1060 if (max_allowed_bad_attempts == 0) {
1065 if (my_info3->bad_pw_count >= max_allowed_bad_attempts) {
1067 uint32 password_properties;
1069 result = get_pwd_properties(domain, state->mem_ctx, &password_properties);
1070 if (!NT_STATUS_IS_OK(result)) {
1071 DEBUG(10,("winbindd_dual_pam_auth_cached: failed to get password properties.\n"));
1074 if ((my_info3->user_rid != DOMAIN_USER_RID_ADMIN) ||
1075 (password_properties & DOMAIN_PASSWORD_LOCKOUT_ADMINS)) {
1076 my_info3->acct_flags |= ACB_AUTOLOCK;
1081 result = winbindd_update_creds_by_info3(domain,
1083 state->request.data.auth.user,
1087 if (!NT_STATUS_IS_OK(result)) {
1088 DEBUG(0,("winbindd_dual_pam_auth_cached: failed to update creds %s\n",
1089 nt_errstr(result)));
1092 return NT_STATUS_LOGON_FAILURE;
1095 NTSTATUS winbindd_dual_pam_auth_kerberos(struct winbindd_domain *domain,
1096 struct winbindd_cli_state *state,
1097 NET_USER_INFO_3 **info3)
1099 struct winbindd_domain *contact_domain;
1100 fstring name_domain, name_user;
1103 DEBUG(10,("winbindd_dual_pam_auth_kerberos\n"));
1105 /* Parse domain and username */
1107 parse_domain_user(state->request.data.auth.user, name_domain, name_user);
1109 /* what domain should we contact? */
1112 if (!(contact_domain = find_domain_from_name(name_domain))) {
1113 DEBUG(3, ("Authentication for domain for [%s] -> [%s]\\[%s] failed as %s is not a trusted domain\n",
1114 state->request.data.auth.user, name_domain, name_user, name_domain));
1115 result = NT_STATUS_NO_SUCH_USER;
1120 if (is_myname(name_domain)) {
1121 DEBUG(3, ("Authentication for domain %s (local domain to this server) not supported at this stage\n", name_domain));
1122 result = NT_STATUS_NO_SUCH_USER;
1126 contact_domain = find_domain_from_name(name_domain);
1127 if (contact_domain == NULL) {
1128 DEBUG(3, ("Authentication for domain for [%s] -> [%s]\\[%s] failed as %s is not a trusted domain\n",
1129 state->request.data.auth.user, name_domain, name_user, name_domain));
1131 contact_domain = find_our_domain();
1135 if (contact_domain->initialized &&
1136 contact_domain->active_directory) {
1140 if (!contact_domain->initialized) {
1141 init_dc_connection(contact_domain);
1144 if (!contact_domain->active_directory) {
1145 DEBUG(3,("krb5 auth requested but domain is not Active Directory\n"));
1146 return NT_STATUS_INVALID_LOGON_TYPE;
1149 result = winbindd_raw_kerberos_login(contact_domain, state, info3);
1154 NTSTATUS winbindd_dual_pam_auth_samlogon(struct winbindd_domain *domain,
1155 struct winbindd_cli_state *state,
1156 NET_USER_INFO_3 **info3)
1159 struct rpc_pipe_client *netlogon_pipe;
1164 unsigned char local_lm_response[24];
1165 unsigned char local_nt_response[24];
1166 struct winbindd_domain *contact_domain;
1167 fstring name_domain, name_user;
1170 NET_USER_INFO_3 *my_info3;
1172 ZERO_STRUCTP(info3);
1176 my_info3 = TALLOC_ZERO_P(state->mem_ctx, NET_USER_INFO_3);
1177 if (my_info3 == NULL) {
1178 return NT_STATUS_NO_MEMORY;
1182 DEBUG(10,("winbindd_dual_pam_auth_samlogon\n"));
1184 /* Parse domain and username */
1186 parse_domain_user(state->request.data.auth.user, name_domain, name_user);
1188 /* do password magic */
1191 generate_random_buffer(chal, 8);
1192 if (lp_client_ntlmv2_auth()) {
1193 DATA_BLOB server_chal;
1194 DATA_BLOB names_blob;
1195 DATA_BLOB nt_response;
1196 DATA_BLOB lm_response;
1197 server_chal = data_blob_talloc(state->mem_ctx, chal, 8);
1199 /* note that the 'workgroup' here is a best guess - we don't know
1200 the server's domain at this point. The 'server name' is also
1203 names_blob = NTLMv2_generate_names_blob(global_myname(), lp_workgroup());
1205 if (!SMBNTLMv2encrypt(name_user, name_domain,
1206 state->request.data.auth.pass,
1209 &lm_response, &nt_response, NULL)) {
1210 data_blob_free(&names_blob);
1211 data_blob_free(&server_chal);
1212 DEBUG(0, ("winbindd_pam_auth: SMBNTLMv2encrypt() failed!\n"));
1213 result = NT_STATUS_NO_MEMORY;
1216 data_blob_free(&names_blob);
1217 data_blob_free(&server_chal);
1218 lm_resp = data_blob_talloc(state->mem_ctx, lm_response.data,
1219 lm_response.length);
1220 nt_resp = data_blob_talloc(state->mem_ctx, nt_response.data,
1221 nt_response.length);
1222 data_blob_free(&lm_response);
1223 data_blob_free(&nt_response);
1226 if (lp_client_lanman_auth()
1227 && SMBencrypt(state->request.data.auth.pass,
1229 local_lm_response)) {
1230 lm_resp = data_blob_talloc(state->mem_ctx,
1232 sizeof(local_lm_response));
1234 lm_resp = data_blob_null;
1236 SMBNTencrypt(state->request.data.auth.pass,
1240 nt_resp = data_blob_talloc(state->mem_ctx,
1242 sizeof(local_nt_response));
1245 /* what domain should we contact? */
1248 if (!(contact_domain = find_domain_from_name(name_domain))) {
1249 DEBUG(3, ("Authentication for domain for [%s] -> [%s]\\[%s] failed as %s is not a trusted domain\n",
1250 state->request.data.auth.user, name_domain, name_user, name_domain));
1251 result = NT_STATUS_NO_SUCH_USER;
1256 if (is_myname(name_domain)) {
1257 DEBUG(3, ("Authentication for domain %s (local domain to this server) not supported at this stage\n", name_domain));
1258 result = NT_STATUS_NO_SUCH_USER;
1262 contact_domain = find_our_domain();
1265 /* check authentication loop */
1269 ZERO_STRUCTP(my_info3);
1272 result = cm_connect_netlogon(contact_domain, &netlogon_pipe);
1274 if (!NT_STATUS_IS_OK(result)) {
1275 DEBUG(3, ("could not open handle to NETLOGON pipe\n"));
1279 result = rpccli_netlogon_sam_network_logon(netlogon_pipe,
1282 contact_domain->dcname, /* server name */
1283 name_user, /* user name */
1284 name_domain, /* target domain */
1285 global_myname(), /* workstation */
1292 /* We have to try a second time as cm_connect_netlogon
1293 might not yet have noticed that the DC has killed
1296 if (NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL)) {
1301 /* if we get access denied, a possible cause was that we had
1302 and open connection to the DC, but someone changed our
1303 machine account password out from underneath us using 'net
1304 rpc changetrustpw' */
1306 if ( NT_STATUS_EQUAL(result, NT_STATUS_ACCESS_DENIED) ) {
1307 DEBUG(3,("winbindd_pam_auth: sam_logon returned "
1308 "ACCESS_DENIED. Maybe the trust account "
1309 "password was changed and we didn't know it. "
1310 "Killing connections to domain %s\n",
1312 invalidate_cm_connection(&contact_domain->conn);
1316 } while ( (attempts < 2) && retry );
1318 /* handle the case where a NT4 DC does not fill in the acct_flags in
1319 * the samlogon reply info3. When accurate info3 is required by the
1320 * caller, we look up the account flags ourselve - gd */
1322 if ((state->request.flags & WBFLAG_PAM_INFO3_TEXT) &&
1323 (my_info3->acct_flags == 0) && NT_STATUS_IS_OK(result)) {
1325 struct rpc_pipe_client *samr_pipe;
1326 POLICY_HND samr_domain_handle, user_pol;
1327 SAM_USERINFO_CTR *user_ctr;
1328 NTSTATUS status_tmp;
1331 ZERO_STRUCT(user_ctr);
1333 status_tmp = cm_connect_sam(contact_domain, state->mem_ctx,
1334 &samr_pipe, &samr_domain_handle);
1336 if (!NT_STATUS_IS_OK(status_tmp)) {
1337 DEBUG(3, ("could not open handle to SAMR pipe: %s\n",
1338 nt_errstr(status_tmp)));
1342 status_tmp = rpccli_samr_open_user(samr_pipe, state->mem_ctx,
1343 &samr_domain_handle,
1344 MAXIMUM_ALLOWED_ACCESS,
1345 my_info3->user_rid, &user_pol);
1347 if (!NT_STATUS_IS_OK(status_tmp)) {
1348 DEBUG(3, ("could not open user handle on SAMR pipe: %s\n",
1349 nt_errstr(status_tmp)));
1353 status_tmp = rpccli_samr_query_userinfo(samr_pipe, state->mem_ctx,
1354 &user_pol, 16, &user_ctr);
1356 if (!NT_STATUS_IS_OK(status_tmp)) {
1357 DEBUG(3, ("could not query user info on SAMR pipe: %s\n",
1358 nt_errstr(status_tmp)));
1359 rpccli_samr_close(samr_pipe, state->mem_ctx, &user_pol);
1363 acct_flags = user_ctr->info.id16->acb_info;
1365 if (acct_flags == 0) {
1366 rpccli_samr_close(samr_pipe, state->mem_ctx, &user_pol);
1370 my_info3->acct_flags = acct_flags;
1372 DEBUG(10,("successfully retrieved acct_flags 0x%x\n", acct_flags));
1374 rpccli_samr_close(samr_pipe, state->mem_ctx, &user_pol);
1382 enum winbindd_result winbindd_dual_pam_auth(struct winbindd_domain *domain,
1383 struct winbindd_cli_state *state)
1385 NTSTATUS result = NT_STATUS_LOGON_FAILURE;
1386 NTSTATUS krb5_result = NT_STATUS_OK;
1387 fstring name_domain, name_user;
1388 NET_USER_INFO_3 *info3 = NULL;
1390 /* Ensure null termination */
1391 state->request.data.auth.user[sizeof(state->request.data.auth.user)-1]='\0';
1393 /* Ensure null termination */
1394 state->request.data.auth.pass[sizeof(state->request.data.auth.pass)-1]='\0';
1396 DEBUG(3, ("[%5lu]: dual pam auth %s\n", (unsigned long)state->pid,
1397 state->request.data.auth.user));
1399 if (!check_request_flags(state->request.flags)) {
1400 result = NT_STATUS_INVALID_PARAMETER_MIX;
1404 /* Parse domain and username */
1406 ws_name_return( state->request.data.auth.user, WB_REPLACE_CHAR );
1408 parse_domain_user(state->request.data.auth.user, name_domain, name_user);
1410 if (domain->online == False) {
1411 result = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
1412 if (domain->startup) {
1413 /* Logons are very important to users. If we're offline and
1414 we get a request within the first 30 seconds of startup,
1415 try very hard to find a DC and go online. */
1417 DEBUG(10,("winbindd_dual_pam_auth: domain: %s offline and auth "
1418 "request in startup mode.\n", domain->name ));
1420 winbindd_flush_negative_conn_cache(domain);
1421 result = init_dc_connection(domain);
1425 DEBUG(10,("winbindd_dual_pam_auth: domain: %s last was %s\n", domain->name, domain->online ? "online":"offline"));
1427 /* Check for Kerberos authentication */
1428 if (domain->online && (state->request.flags & WBFLAG_PAM_KRB5)) {
1430 result = winbindd_dual_pam_auth_kerberos(domain, state, &info3);
1431 /* save for later */
1432 krb5_result = result;
1435 if (NT_STATUS_IS_OK(result)) {
1436 DEBUG(10,("winbindd_dual_pam_auth_kerberos succeeded\n"));
1437 goto process_result;
1439 DEBUG(10,("winbindd_dual_pam_auth_kerberos failed: %s\n", nt_errstr(result)));
1442 if (NT_STATUS_EQUAL(result, NT_STATUS_NO_LOGON_SERVERS) ||
1443 NT_STATUS_EQUAL(result, NT_STATUS_IO_TIMEOUT) ||
1444 NT_STATUS_EQUAL(result, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND)) {
1445 DEBUG(10,("winbindd_dual_pam_auth_kerberos setting domain to offline\n"));
1446 set_domain_offline( domain );
1450 /* there are quite some NT_STATUS errors where there is no
1451 * point in retrying with a samlogon, we explictly have to take
1452 * care not to increase the bad logon counter on the DC */
1454 if (NT_STATUS_EQUAL(result, NT_STATUS_ACCOUNT_DISABLED) ||
1455 NT_STATUS_EQUAL(result, NT_STATUS_ACCOUNT_EXPIRED) ||
1456 NT_STATUS_EQUAL(result, NT_STATUS_ACCOUNT_LOCKED_OUT) ||
1457 NT_STATUS_EQUAL(result, NT_STATUS_INVALID_LOGON_HOURS) ||
1458 NT_STATUS_EQUAL(result, NT_STATUS_INVALID_WORKSTATION) ||
1459 NT_STATUS_EQUAL(result, NT_STATUS_LOGON_FAILURE) ||
1460 NT_STATUS_EQUAL(result, NT_STATUS_NO_SUCH_USER) ||
1461 NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_EXPIRED) ||
1462 NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_MUST_CHANGE) ||
1463 NT_STATUS_EQUAL(result, NT_STATUS_WRONG_PASSWORD)) {
1464 goto process_result;
1467 if (state->request.flags & WBFLAG_PAM_FALLBACK_AFTER_KRB5) {
1468 DEBUG(3,("falling back to samlogon\n"));
1476 /* Check for Samlogon authentication */
1477 if (domain->online) {
1478 result = winbindd_dual_pam_auth_samlogon(domain, state, &info3);
1480 if (NT_STATUS_IS_OK(result)) {
1481 DEBUG(10,("winbindd_dual_pam_auth_samlogon succeeded\n"));
1482 /* add the Krb5 err if we have one */
1483 if ( NT_STATUS_EQUAL(krb5_result, NT_STATUS_TIME_DIFFERENCE_AT_DC ) ) {
1484 info3->user_flgs |= LOGON_KRB5_FAIL_CLOCK_SKEW;
1486 goto process_result;
1489 DEBUG(10,("winbindd_dual_pam_auth_samlogon failed: %s\n",
1490 nt_errstr(result)));
1492 if (NT_STATUS_EQUAL(result, NT_STATUS_NO_LOGON_SERVERS) ||
1493 NT_STATUS_EQUAL(result, NT_STATUS_IO_TIMEOUT) ||
1494 NT_STATUS_EQUAL(result, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND))
1496 DEBUG(10,("winbindd_dual_pam_auth_samlogon setting domain to offline\n"));
1497 set_domain_offline( domain );
1501 if (domain->online) {
1502 /* We're still online - fail. */
1508 /* Check for Cached logons */
1509 if (!domain->online && (state->request.flags & WBFLAG_PAM_CACHED_LOGIN) &&
1510 lp_winbind_offline_logon()) {
1512 result = winbindd_dual_pam_auth_cached(domain, state, &info3);
1514 if (NT_STATUS_IS_OK(result)) {
1515 DEBUG(10,("winbindd_dual_pam_auth_cached succeeded\n"));
1516 goto process_result;
1518 DEBUG(10,("winbindd_dual_pam_auth_cached failed: %s\n", nt_errstr(result)));
1525 if (NT_STATUS_IS_OK(result)) {
1529 /* In all codepaths where result == NT_STATUS_OK info3 must have
1530 been initialized. */
1532 result = NT_STATUS_INTERNAL_ERROR;
1536 netsamlogon_cache_store(name_user, info3);
1537 wcache_invalidate_samlogon(find_domain_from_name(name_domain), info3);
1539 /* save name_to_sid info as early as possible (only if
1540 this is our primary domain so we don't invalidate
1541 the cache entry by storing the seq_num for the wrong
1543 if ( domain->primary ) {
1544 sid_compose(&user_sid, &info3->dom_sid.sid,
1546 cache_name2sid(domain, name_domain, name_user,
1547 SID_NAME_USER, &user_sid);
1550 /* Check if the user is in the right group */
1552 if (!NT_STATUS_IS_OK(result = check_info3_in_group(state->mem_ctx, info3,
1553 state->request.data.auth.require_membership_of_sid))) {
1554 DEBUG(3, ("User %s is not in the required group (%s), so plaintext authentication is rejected\n",
1555 state->request.data.auth.user,
1556 state->request.data.auth.require_membership_of_sid));
1560 result = append_data(state, info3, name_domain, name_user);
1561 if (!NT_STATUS_IS_OK(result)) {
1565 if ((state->request.flags & WBFLAG_PAM_CACHED_LOGIN)) {
1567 /* Store in-memory creds for single-signon using ntlm_auth. */
1568 result = winbindd_add_memory_creds(state->request.data.auth.user,
1569 get_uid_from_state(state),
1570 state->request.data.auth.pass);
1572 if (!NT_STATUS_IS_OK(result)) {
1573 DEBUG(10,("Failed to store memory creds: %s\n", nt_errstr(result)));
1577 if (lp_winbind_offline_logon()) {
1578 result = winbindd_store_creds(domain,
1580 state->request.data.auth.user,
1581 state->request.data.auth.pass,
1583 if (!NT_STATUS_IS_OK(result)) {
1585 /* Release refcount. */
1586 winbindd_delete_memory_creds(state->request.data.auth.user);
1588 DEBUG(10,("Failed to store creds: %s\n", nt_errstr(result)));
1595 if (state->request.flags & WBFLAG_PAM_GET_PWD_POLICY) {
1596 result = fillup_password_policy(domain, state);
1598 if (!NT_STATUS_IS_OK(result)
1599 && !NT_STATUS_EQUAL(result, NT_STATUS_NOT_SUPPORTED) )
1601 DEBUG(10,("Failed to get password policies: %s\n", nt_errstr(result)));
1606 result = NT_STATUS_OK;
1610 /* give us a more useful (more correct?) error code */
1611 if ((NT_STATUS_EQUAL(result, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND) ||
1612 (NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL)))) {
1613 result = NT_STATUS_NO_LOGON_SERVERS;
1616 state->response.data.auth.nt_status = NT_STATUS_V(result);
1617 fstrcpy(state->response.data.auth.nt_status_string, nt_errstr(result));
1619 /* we might have given a more useful error above */
1620 if (!*state->response.data.auth.error_string)
1621 fstrcpy(state->response.data.auth.error_string, get_friendly_nt_error_msg(result));
1622 state->response.data.auth.pam_error = nt_status_to_pam(result);
1624 DEBUG(NT_STATUS_IS_OK(result) ? 5 : 2, ("Plain-text authentication for user %s returned %s (PAM: %d)\n",
1625 state->request.data.auth.user,
1626 state->response.data.auth.nt_status_string,
1627 state->response.data.auth.pam_error));
1629 return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
1633 /**********************************************************************
1634 Challenge Response Authentication Protocol
1635 **********************************************************************/
1637 void winbindd_pam_auth_crap(struct winbindd_cli_state *state)
1639 struct winbindd_domain *domain = NULL;
1640 const char *domain_name = NULL;
1643 if (!check_request_flags(state->request.flags)) {
1644 result = NT_STATUS_INVALID_PARAMETER_MIX;
1648 if (!state->privileged) {
1649 char *error_string = NULL;
1650 DEBUG(2, ("winbindd_pam_auth_crap: non-privileged access "
1652 DEBUGADD(2, ("winbindd_pam_auth_crap: Ensure permissions "
1653 "on %s are set correctly.\n",
1654 get_winbind_priv_pipe_dir()));
1655 /* send a better message than ACCESS_DENIED */
1656 error_string = talloc_asprintf(state->mem_ctx,
1657 "winbind client not authorized "
1658 "to use winbindd_pam_auth_crap."
1659 " Ensure permissions on %s "
1660 "are set correctly.",
1661 get_winbind_priv_pipe_dir());
1662 fstrcpy(state->response.data.auth.error_string, error_string);
1663 result = NT_STATUS_ACCESS_DENIED;
1667 /* Ensure null termination */
1668 state->request.data.auth_crap.user
1669 [sizeof(state->request.data.auth_crap.user)-1]=0;
1670 state->request.data.auth_crap.domain
1671 [sizeof(state->request.data.auth_crap.domain)-1]=0;
1673 DEBUG(3, ("[%5lu]: pam auth crap domain: [%s] user: %s\n",
1674 (unsigned long)state->pid,
1675 state->request.data.auth_crap.domain,
1676 state->request.data.auth_crap.user));
1678 if (*state->request.data.auth_crap.domain != '\0') {
1679 domain_name = state->request.data.auth_crap.domain;
1680 } else if (lp_winbind_use_default_domain()) {
1681 domain_name = lp_workgroup();
1684 if (domain_name != NULL)
1685 domain = find_auth_domain(state, domain_name);
1687 if (domain != NULL) {
1688 sendto_domain(state, domain);
1692 result = NT_STATUS_NO_SUCH_USER;
1695 set_auth_errors(&state->response, result);
1696 DEBUG(5, ("CRAP authentication for %s\\%s returned %s (PAM: %d)\n",
1697 state->request.data.auth_crap.domain,
1698 state->request.data.auth_crap.user,
1699 state->response.data.auth.nt_status_string,
1700 state->response.data.auth.pam_error));
1701 request_error(state);
1706 enum winbindd_result winbindd_dual_pam_auth_crap(struct winbindd_domain *domain,
1707 struct winbindd_cli_state *state)
1710 NET_USER_INFO_3 info3;
1711 struct rpc_pipe_client *netlogon_pipe;
1712 const char *name_user = NULL;
1713 const char *name_domain = NULL;
1714 const char *workstation;
1715 struct winbindd_domain *contact_domain;
1719 DATA_BLOB lm_resp, nt_resp;
1721 /* This is child-only, so no check for privileged access is needed
1724 /* Ensure null termination */
1725 state->request.data.auth_crap.user[sizeof(state->request.data.auth_crap.user)-1]=0;
1726 state->request.data.auth_crap.domain[sizeof(state->request.data.auth_crap.domain)-1]=0;
1728 if (!check_request_flags(state->request.flags)) {
1729 result = NT_STATUS_INVALID_PARAMETER_MIX;
1733 name_user = state->request.data.auth_crap.user;
1735 if (*state->request.data.auth_crap.domain) {
1736 name_domain = state->request.data.auth_crap.domain;
1737 } else if (lp_winbind_use_default_domain()) {
1738 name_domain = lp_workgroup();
1740 DEBUG(5,("no domain specified with username (%s) - failing auth\n",
1742 result = NT_STATUS_NO_SUCH_USER;
1746 DEBUG(3, ("[%5lu]: pam auth crap domain: %s user: %s\n", (unsigned long)state->pid,
1747 name_domain, name_user));
1749 if (*state->request.data.auth_crap.workstation) {
1750 workstation = state->request.data.auth_crap.workstation;
1752 workstation = global_myname();
1755 if (state->request.data.auth_crap.lm_resp_len > sizeof(state->request.data.auth_crap.lm_resp)
1756 || state->request.data.auth_crap.nt_resp_len > sizeof(state->request.data.auth_crap.nt_resp)) {
1757 DEBUG(0, ("winbindd_pam_auth_crap: invalid password length %u/%u\n",
1758 state->request.data.auth_crap.lm_resp_len,
1759 state->request.data.auth_crap.nt_resp_len));
1760 result = NT_STATUS_INVALID_PARAMETER;
1764 lm_resp = data_blob_talloc(state->mem_ctx, state->request.data.auth_crap.lm_resp,
1765 state->request.data.auth_crap.lm_resp_len);
1766 nt_resp = data_blob_talloc(state->mem_ctx, state->request.data.auth_crap.nt_resp,
1767 state->request.data.auth_crap.nt_resp_len);
1769 /* what domain should we contact? */
1772 if (!(contact_domain = find_domain_from_name(name_domain))) {
1773 DEBUG(3, ("Authentication for domain for [%s] -> [%s]\\[%s] failed as %s is not a trusted domain\n",
1774 state->request.data.auth_crap.user, name_domain, name_user, name_domain));
1775 result = NT_STATUS_NO_SUCH_USER;
1779 if (is_myname(name_domain)) {
1780 DEBUG(3, ("Authentication for domain %s (local domain to this server) not supported at this stage\n", name_domain));
1781 result = NT_STATUS_NO_SUCH_USER;
1784 contact_domain = find_our_domain();
1791 netlogon_pipe = NULL;
1792 result = cm_connect_netlogon(contact_domain, &netlogon_pipe);
1794 if (!NT_STATUS_IS_OK(result)) {
1795 DEBUG(3, ("could not open handle to NETLOGON pipe (error: %s)\n",
1796 nt_errstr(result)));
1800 result = rpccli_netlogon_sam_network_logon(netlogon_pipe,
1802 state->request.data.auth_crap.logon_parameters,
1803 contact_domain->dcname,
1806 /* Bug #3248 - found by Stefan Burkei. */
1807 workstation, /* We carefully set this above so use it... */
1808 state->request.data.auth_crap.chal,
1815 /* We have to try a second time as cm_connect_netlogon
1816 might not yet have noticed that the DC has killed
1819 if (NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL)) {
1824 /* if we get access denied, a possible cause was that we had and open
1825 connection to the DC, but someone changed our machine account password
1826 out from underneath us using 'net rpc changetrustpw' */
1828 if ( NT_STATUS_EQUAL(result, NT_STATUS_ACCESS_DENIED) ) {
1829 DEBUG(3,("winbindd_pam_auth: sam_logon returned "
1830 "ACCESS_DENIED. Maybe the trust account "
1831 "password was changed and we didn't know it. "
1832 "Killing connections to domain %s\n",
1834 invalidate_cm_connection(&contact_domain->conn);
1838 } while ( (attempts < 2) && retry );
1840 if (NT_STATUS_IS_OK(result)) {
1842 netsamlogon_cache_store(name_user, &info3);
1843 wcache_invalidate_samlogon(find_domain_from_name(name_domain), &info3);
1845 /* Check if the user is in the right group */
1847 if (!NT_STATUS_IS_OK(result = check_info3_in_group(state->mem_ctx, &info3,
1848 state->request.data.auth_crap.require_membership_of_sid))) {
1849 DEBUG(3, ("User %s is not in the required group (%s), so "
1850 "crap authentication is rejected\n",
1851 state->request.data.auth_crap.user,
1852 state->request.data.auth_crap.require_membership_of_sid));
1856 result = append_data(state, &info3, name_domain, name_user);
1857 if (!NT_STATUS_IS_OK(result)) {
1864 /* give us a more useful (more correct?) error code */
1865 if ((NT_STATUS_EQUAL(result, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND) ||
1866 (NT_STATUS_EQUAL(result, NT_STATUS_UNSUCCESSFUL)))) {
1867 result = NT_STATUS_NO_LOGON_SERVERS;
1870 if (state->request.flags & WBFLAG_PAM_NT_STATUS_SQUASH) {
1871 result = nt_status_squash(result);
1874 state->response.data.auth.nt_status = NT_STATUS_V(result);
1875 fstrcpy(state->response.data.auth.nt_status_string, nt_errstr(result));
1877 /* we might have given a more useful error above */
1878 if (!*state->response.data.auth.error_string) {
1879 fstrcpy(state->response.data.auth.error_string, get_friendly_nt_error_msg(result));
1881 state->response.data.auth.pam_error = nt_status_to_pam(result);
1883 DEBUG(NT_STATUS_IS_OK(result) ? 5 : 2,
1884 ("NTLM CRAP authentication for user [%s]\\[%s] returned %s (PAM: %d)\n",
1887 state->response.data.auth.nt_status_string,
1888 state->response.data.auth.pam_error));
1890 return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
1893 /* Change a user password */
1895 void winbindd_pam_chauthtok(struct winbindd_cli_state *state)
1897 fstring domain, user;
1898 struct winbindd_domain *contact_domain;
1900 DEBUG(3, ("[%5lu]: pam chauthtok %s\n", (unsigned long)state->pid,
1901 state->request.data.chauthtok.user));
1905 ws_name_return( state->request.data.auth.user, WB_REPLACE_CHAR );
1907 if (!canonicalize_username(state->request.data.chauthtok.user, domain, user)) {
1908 set_auth_errors(&state->response, NT_STATUS_NO_SUCH_USER);
1909 DEBUG(5, ("winbindd_pam_chauthtok: canonicalize_username %s failed with %s"
1911 state->request.data.auth.user,
1912 state->response.data.auth.nt_status_string,
1913 state->response.data.auth.pam_error));
1914 request_error(state);
1918 contact_domain = find_domain_from_name(domain);
1919 if (!contact_domain) {
1920 set_auth_errors(&state->response, NT_STATUS_NO_SUCH_USER);
1921 DEBUG(3, ("Cannot change password for [%s] -> [%s]\\[%s] as %s is not a trusted domain\n",
1922 state->request.data.chauthtok.user, domain, user, domain));
1923 request_error(state);
1927 sendto_domain(state, contact_domain);
1930 enum winbindd_result winbindd_dual_pam_chauthtok(struct winbindd_domain *contact_domain,
1931 struct winbindd_cli_state *state)
1934 char *newpass = NULL;
1936 struct rpc_pipe_client *cli;
1937 bool got_info = False;
1938 SAM_UNK_INFO_1 info;
1939 SAMR_CHANGE_REJECT reject;
1940 NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
1941 fstring domain, user;
1943 DEBUG(3, ("[%5lu]: dual pam chauthtok %s\n", (unsigned long)state->pid,
1944 state->request.data.auth.user));
1946 if (!parse_domain_user(state->request.data.chauthtok.user, domain, user)) {
1950 /* Change password */
1952 oldpass = state->request.data.chauthtok.oldpass;
1953 newpass = state->request.data.chauthtok.newpass;
1955 /* Initialize reject reason */
1956 state->response.data.auth.reject_reason = Undefined;
1958 /* Get sam handle */
1960 result = cm_connect_sam(contact_domain, state->mem_ctx, &cli,
1962 if (!NT_STATUS_IS_OK(result)) {
1963 DEBUG(1, ("could not get SAM handle on DC for %s\n", domain));
1967 result = rpccli_samr_chgpasswd3(cli, state->mem_ctx, user, newpass, oldpass, &info, &reject);
1969 /* Windows 2003 returns NT_STATUS_PASSWORD_RESTRICTION */
1971 if (NT_STATUS_EQUAL(result, NT_STATUS_PASSWORD_RESTRICTION) ) {
1972 state->response.data.auth.policy.min_length_password =
1973 info.min_length_password;
1974 state->response.data.auth.policy.password_history =
1975 info.password_history;
1976 state->response.data.auth.policy.password_properties =
1977 info.password_properties;
1978 state->response.data.auth.policy.expire =
1979 nt_time_to_unix_abs(&info.expire);
1980 state->response.data.auth.policy.min_passwordage =
1981 nt_time_to_unix_abs(&info.min_passwordage);
1983 state->response.data.auth.reject_reason =
1984 reject.reject_reason;
1989 /* only fallback when the chgpasswd3 call is not supported */
1990 if ((NT_STATUS_EQUAL(result, NT_STATUS(DCERPC_FAULT_OP_RNG_ERROR))) ||
1991 (NT_STATUS_EQUAL(result, NT_STATUS_NOT_SUPPORTED)) ||
1992 (NT_STATUS_EQUAL(result, NT_STATUS_NOT_IMPLEMENTED))) {
1994 DEBUG(10,("Password change with chgpasswd3 failed with: %s, retrying chgpasswd_user\n",
1995 nt_errstr(result)));
1997 result = rpccli_samr_chgpasswd_user(cli, state->mem_ctx, user, newpass, oldpass);
1999 /* Windows 2000 returns NT_STATUS_ACCOUNT_RESTRICTION.
2000 Map to the same status code as Windows 2003. */
2002 if ( NT_STATUS_EQUAL(NT_STATUS_ACCOUNT_RESTRICTION, result ) ) {
2003 result = NT_STATUS_PASSWORD_RESTRICTION;
2009 if (NT_STATUS_IS_OK(result) && (state->request.flags & WBFLAG_PAM_CACHED_LOGIN)) {
2011 /* Update the single sign-on memory creds. */
2012 result = winbindd_replace_memory_creds(state->request.data.chauthtok.user,
2015 if (!NT_STATUS_IS_OK(result)) {
2016 DEBUG(10,("Failed to replace memory creds: %s\n", nt_errstr(result)));
2017 goto process_result;
2020 if (lp_winbind_offline_logon()) {
2021 result = winbindd_update_creds_by_name(contact_domain,
2022 state->mem_ctx, user,
2024 if (!NT_STATUS_IS_OK(result)) {
2025 DEBUG(10,("Failed to store creds: %s\n", nt_errstr(result)));
2026 goto process_result;
2031 if (!NT_STATUS_IS_OK(result) && !got_info && contact_domain) {
2033 NTSTATUS policy_ret;
2035 policy_ret = fillup_password_policy(contact_domain, state);
2037 /* failure of this is non critical, it will just provide no
2038 * additional information to the client why the change has
2039 * failed - Guenther */
2041 if (!NT_STATUS_IS_OK(policy_ret)) {
2042 DEBUG(10,("Failed to get password policies: %s\n", nt_errstr(policy_ret)));
2043 goto process_result;
2049 state->response.data.auth.nt_status = NT_STATUS_V(result);
2050 fstrcpy(state->response.data.auth.nt_status_string, nt_errstr(result));
2051 fstrcpy(state->response.data.auth.error_string, get_friendly_nt_error_msg(result));
2052 state->response.data.auth.pam_error = nt_status_to_pam(result);
2054 DEBUG(NT_STATUS_IS_OK(result) ? 5 : 2,
2055 ("Password change for user [%s]\\[%s] returned %s (PAM: %d)\n",
2058 state->response.data.auth.nt_status_string,
2059 state->response.data.auth.pam_error));
2061 return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
2064 void winbindd_pam_logoff(struct winbindd_cli_state *state)
2066 struct winbindd_domain *domain;
2067 fstring name_domain, user;
2068 uid_t caller_uid = (uid_t)-1;
2069 uid_t request_uid = state->request.data.logoff.uid;
2071 DEBUG(3, ("[%5lu]: pam logoff %s\n", (unsigned long)state->pid,
2072 state->request.data.logoff.user));
2074 /* Ensure null termination */
2075 state->request.data.logoff.user
2076 [sizeof(state->request.data.logoff.user)-1]='\0';
2078 state->request.data.logoff.krb5ccname
2079 [sizeof(state->request.data.logoff.krb5ccname)-1]='\0';
2081 if (request_uid == (gid_t)-1) {
2085 if (!canonicalize_username(state->request.data.logoff.user, name_domain, user)) {
2089 if ((domain = find_auth_domain(state, name_domain)) == NULL) {
2093 if ((sys_getpeereid(state->sock, &caller_uid)) != 0) {
2094 DEBUG(1,("winbindd_pam_logoff: failed to check peerid: %s\n",
2099 switch (caller_uid) {
2103 /* root must be able to logoff any user - gd */
2104 state->request.data.logoff.uid = request_uid;
2107 if (caller_uid != request_uid) {
2108 DEBUG(1,("winbindd_pam_logoff: caller requested invalid uid\n"));
2111 state->request.data.logoff.uid = caller_uid;
2115 sendto_domain(state, domain);
2119 set_auth_errors(&state->response, NT_STATUS_NO_SUCH_USER);
2120 DEBUG(5, ("Pam Logoff for %s returned %s "
2122 state->request.data.logoff.user,
2123 state->response.data.auth.nt_status_string,
2124 state->response.data.auth.pam_error));
2125 request_error(state);
2129 enum winbindd_result winbindd_dual_pam_logoff(struct winbindd_domain *domain,
2130 struct winbindd_cli_state *state)
2132 NTSTATUS result = NT_STATUS_NOT_SUPPORTED;
2134 DEBUG(3, ("[%5lu]: pam dual logoff %s\n", (unsigned long)state->pid,
2135 state->request.data.logoff.user));
2137 if (!(state->request.flags & WBFLAG_PAM_KRB5)) {
2138 result = NT_STATUS_OK;
2139 goto process_result;
2142 if (state->request.data.logoff.krb5ccname[0] == '\0') {
2143 result = NT_STATUS_OK;
2144 goto process_result;
2149 if (state->request.data.logoff.uid < 0) {
2150 DEBUG(0,("winbindd_pam_logoff: invalid uid\n"));
2151 goto process_result;
2154 /* what we need here is to find the corresponding krb5 ccache name *we*
2155 * created for a given username and destroy it */
2157 if (!ccache_entry_exists(state->request.data.logoff.user)) {
2158 result = NT_STATUS_OK;
2159 DEBUG(10,("winbindd_pam_logoff: no entry found.\n"));
2160 goto process_result;
2163 if (!ccache_entry_identical(state->request.data.logoff.user,
2164 state->request.data.logoff.uid,
2165 state->request.data.logoff.krb5ccname)) {
2166 DEBUG(0,("winbindd_pam_logoff: cached entry differs.\n"));
2167 goto process_result;
2170 result = remove_ccache(state->request.data.logoff.user);
2171 if (!NT_STATUS_IS_OK(result)) {
2172 DEBUG(0,("winbindd_pam_logoff: failed to remove ccache: %s\n",
2173 nt_errstr(result)));
2174 goto process_result;
2178 result = NT_STATUS_NOT_SUPPORTED;
2183 winbindd_delete_memory_creds(state->request.data.logoff.user);
2185 state->response.data.auth.nt_status = NT_STATUS_V(result);
2186 fstrcpy(state->response.data.auth.nt_status_string, nt_errstr(result));
2187 fstrcpy(state->response.data.auth.error_string, get_friendly_nt_error_msg(result));
2188 state->response.data.auth.pam_error = nt_status_to_pam(result);
2190 return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;
2193 /* Change user password with auth crap*/
2195 void winbindd_pam_chng_pswd_auth_crap(struct winbindd_cli_state *state)
2197 struct winbindd_domain *domain = NULL;
2198 const char *domain_name = NULL;
2200 /* Ensure null termination */
2201 state->request.data.chng_pswd_auth_crap.user[
2202 sizeof(state->request.data.chng_pswd_auth_crap.user)-1]=0;
2203 state->request.data.chng_pswd_auth_crap.domain[
2204 sizeof(state->request.data.chng_pswd_auth_crap.domain)-1]=0;
2206 DEBUG(3, ("[%5lu]: pam change pswd auth crap domain: %s user: %s\n",
2207 (unsigned long)state->pid,
2208 state->request.data.chng_pswd_auth_crap.domain,
2209 state->request.data.chng_pswd_auth_crap.user));
2211 if (*state->request.data.chng_pswd_auth_crap.domain != '\0') {
2212 domain_name = state->request.data.chng_pswd_auth_crap.domain;
2213 } else if (lp_winbind_use_default_domain()) {
2214 domain_name = lp_workgroup();
2217 if (domain_name != NULL)
2218 domain = find_domain_from_name(domain_name);
2220 if (domain != NULL) {
2221 DEBUG(7, ("[%5lu]: pam auth crap changing pswd in domain: "
2222 "%s\n", (unsigned long)state->pid,domain->name));
2223 sendto_domain(state, domain);
2227 set_auth_errors(&state->response, NT_STATUS_NO_SUCH_USER);
2228 DEBUG(5, ("CRAP change password for %s\\%s returned %s (PAM: %d)\n",
2229 state->request.data.chng_pswd_auth_crap.domain,
2230 state->request.data.chng_pswd_auth_crap.user,
2231 state->response.data.auth.nt_status_string,
2232 state->response.data.auth.pam_error));
2233 request_error(state);
2237 enum winbindd_result winbindd_dual_pam_chng_pswd_auth_crap(struct winbindd_domain *domainSt, struct winbindd_cli_state *state)
2240 DATA_BLOB new_nt_password;
2241 DATA_BLOB old_nt_hash_enc;
2242 DATA_BLOB new_lm_password;
2243 DATA_BLOB old_lm_hash_enc;
2244 fstring domain,user;
2246 struct winbindd_domain *contact_domain = domainSt;
2247 struct rpc_pipe_client *cli;
2249 /* Ensure null termination */
2250 state->request.data.chng_pswd_auth_crap.user[
2251 sizeof(state->request.data.chng_pswd_auth_crap.user)-1]=0;
2252 state->request.data.chng_pswd_auth_crap.domain[
2253 sizeof(state->request.data.chng_pswd_auth_crap.domain)-1]=0;
2257 DEBUG(3, ("[%5lu]: pam change pswd auth crap domain: %s user: %s\n",
2258 (unsigned long)state->pid,
2259 state->request.data.chng_pswd_auth_crap.domain,
2260 state->request.data.chng_pswd_auth_crap.user));
2262 if (lp_winbind_offline_logon()) {
2263 DEBUG(0,("Refusing password change as winbind offline logons are enabled. "));
2264 DEBUGADD(0,("Changing passwords here would risk inconsistent logons\n"));
2265 result = NT_STATUS_ACCESS_DENIED;
2269 if (*state->request.data.chng_pswd_auth_crap.domain) {
2270 fstrcpy(domain,state->request.data.chng_pswd_auth_crap.domain);
2272 parse_domain_user(state->request.data.chng_pswd_auth_crap.user,
2276 DEBUG(3,("no domain specified with username (%s) - "
2278 state->request.data.chng_pswd_auth_crap.user));
2279 result = NT_STATUS_NO_SUCH_USER;
2284 if (!*domain && lp_winbind_use_default_domain()) {
2285 fstrcpy(domain,(char *)lp_workgroup());
2289 fstrcpy(user, state->request.data.chng_pswd_auth_crap.user);
2292 DEBUG(3, ("[%5lu]: pam auth crap domain: %s user: %s\n",
2293 (unsigned long)state->pid, domain, user));
2295 /* Change password */
2296 new_nt_password = data_blob_talloc(
2298 state->request.data.chng_pswd_auth_crap.new_nt_pswd,
2299 state->request.data.chng_pswd_auth_crap.new_nt_pswd_len);
2301 old_nt_hash_enc = data_blob_talloc(
2303 state->request.data.chng_pswd_auth_crap.old_nt_hash_enc,
2304 state->request.data.chng_pswd_auth_crap.old_nt_hash_enc_len);
2306 if(state->request.data.chng_pswd_auth_crap.new_lm_pswd_len > 0) {
2307 new_lm_password = data_blob_talloc(
2309 state->request.data.chng_pswd_auth_crap.new_lm_pswd,
2310 state->request.data.chng_pswd_auth_crap.new_lm_pswd_len);
2312 old_lm_hash_enc = data_blob_talloc(
2314 state->request.data.chng_pswd_auth_crap.old_lm_hash_enc,
2315 state->request.data.chng_pswd_auth_crap.old_lm_hash_enc_len);
2317 new_lm_password.length = 0;
2318 old_lm_hash_enc.length = 0;
2321 /* Get sam handle */
2323 result = cm_connect_sam(contact_domain, state->mem_ctx, &cli, &dom_pol);
2324 if (!NT_STATUS_IS_OK(result)) {
2325 DEBUG(1, ("could not get SAM handle on DC for %s\n", domain));
2329 result = rpccli_samr_chng_pswd_auth_crap(
2330 cli, state->mem_ctx, user, new_nt_password, old_nt_hash_enc,
2331 new_lm_password, old_lm_hash_enc);
2334 state->response.data.auth.nt_status = NT_STATUS_V(result);
2335 fstrcpy(state->response.data.auth.nt_status_string, nt_errstr(result));
2336 fstrcpy(state->response.data.auth.error_string,
2337 get_friendly_nt_error_msg(result));
2338 state->response.data.auth.pam_error = nt_status_to_pam(result);
2340 DEBUG(NT_STATUS_IS_OK(result) ? 5 : 2,
2341 ("Password change for user [%s]\\[%s] returned %s (PAM: %d)\n",
2343 state->response.data.auth.nt_status_string,
2344 state->response.data.auth.pam_error));
2346 return NT_STATUS_IS_OK(result) ? WINBINDD_OK : WINBINDD_ERROR;