2 Unix SMB/CIFS implementation.
3 Password and authentication handling
4 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2001-2010
5 Copyright (C) Gerald Carter 2003
6 Copyright (C) Stefan Metzmacher 2005
7 Copyright (C) Matthias Dieter Wallnöfer 2009
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "system/time.h"
25 #include "auth/auth.h"
27 #include "dsdb/samdb/samdb.h"
28 #include "libcli/security/security.h"
29 #include "auth/auth_sam.h"
30 #include "dsdb/common/util.h"
31 #include "libcli/ldap/ldap_ndr.h"
32 #include "param/param.h"
34 #define KRBTGT_ATTRS \
35 /* required for the krb5 kdc */ \
38 "userPrincipalName", \
39 "servicePrincipalName", \
40 "msDS-KeyVersionNumber", \
41 "msDS-SecondaryKrbTgtNumber", \
42 "msDS-SupportedEncryptionTypes", \
43 "supplementalCredentials", \
44 "msDS-AllowedToDelegateTo", \
50 "userAccountControl", \
51 "msDS-User-Account-Control-Computed", \
57 const char *krbtgt_attrs
[] = {
61 const char *server_attrs
[] = {
65 const char *user_attrs
[] = {
71 * To allow us to zero the badPwdCount and lockoutTime on
72 * successful logon, without database churn
76 /* check 'allowed workstations' */
79 /* required for user_info_dc, not access control: */
98 /****************************************************************************
99 Check if a user is allowed to logon at this time. Note this is the
100 servers local time, as logon hours are just specified as a weekly
102 ****************************************************************************/
104 static bool logon_hours_ok(struct ldb_message
*msg
, const char *name_for_logs
)
106 /* In logon hours first bit is Sunday from 12AM to 1AM */
107 const struct ldb_val
*hours
;
111 uint8_t bitmask
, bitpos
;
113 hours
= ldb_msg_find_ldb_val(msg
, "logonHours");
115 DEBUG(5,("logon_hours_ok: No hours restrictions for user %s\n", name_for_logs
));
119 if (hours
->length
!= 168/8) {
120 DEBUG(5,("logon_hours_ok: malformed logon hours restrictions for user %s\n", name_for_logs
));
124 lasttime
= time(NULL
);
125 utctime
= gmtime(&lasttime
);
127 DEBUG(1, ("logon_hours_ok: failed to get gmtime. Failing logon for user %s\n",
132 /* find the corresponding byte and bit */
133 bitpos
= (utctime
->tm_wday
* 24 + utctime
->tm_hour
) % 168;
134 bitmask
= 1 << (bitpos
% 8);
136 if (! (hours
->data
[bitpos
/8] & bitmask
)) {
137 struct tm
*t
= localtime(&lasttime
);
139 asct
= "INVALID TIME";
143 asct
= "INVALID TIME";
147 DEBUG(1, ("logon_hours_ok: Account for user %s not allowed to "
148 "logon at this time (%s).\n",
149 name_for_logs
, asct
));
153 asct
= asctime(utctime
);
154 DEBUG(5,("logon_hours_ok: user %s allowed to logon at this time (%s)\n",
155 name_for_logs
, asct
? asct
: "UNKNOWN TIME" ));
160 /****************************************************************************
161 Do a specific test for a SAM_ACCOUNT being valid for this connection
162 (ie not disabled, expired and the like).
163 ****************************************************************************/
164 _PUBLIC_ NTSTATUS
authsam_account_ok(TALLOC_CTX
*mem_ctx
,
165 struct ldb_context
*sam_ctx
,
166 uint32_t logon_parameters
,
167 struct ldb_dn
*domain_dn
,
168 struct ldb_message
*msg
,
169 const char *logon_workstation
,
170 const char *name_for_logs
,
171 bool allow_domain_trust
,
172 bool password_change
)
175 const char *workstation_list
;
177 NTTIME must_change_time
;
178 struct timeval tv_now
= timeval_current();
179 NTTIME now
= timeval_to_nttime(&tv_now
);
181 DEBUG(4,("authsam_account_ok: Checking SMB password for user %s\n", name_for_logs
));
183 acct_flags
= samdb_result_acct_flags(msg
, "msDS-User-Account-Control-Computed");
185 acct_expiry
= samdb_result_account_expires(msg
);
187 /* Check for when we must change this password, taking the
188 * userAccountControl flags into account */
189 must_change_time
= samdb_result_force_password_change(sam_ctx
, mem_ctx
,
192 workstation_list
= ldb_msg_find_attr_as_string(msg
, "userWorkstations", NULL
);
194 /* Quit if the account was disabled. */
195 if (acct_flags
& ACB_DISABLED
) {
196 DEBUG(2,("authsam_account_ok: Account for user '%s' was disabled.\n", name_for_logs
));
197 return NT_STATUS_ACCOUNT_DISABLED
;
200 /* Quit if the account was locked out. */
201 if (acct_flags
& ACB_AUTOLOCK
) {
202 DEBUG(2,("authsam_account_ok: Account for user %s was locked out.\n", name_for_logs
));
203 return NT_STATUS_ACCOUNT_LOCKED_OUT
;
206 /* Test account expire time */
207 if (now
> acct_expiry
) {
208 DEBUG(2,("authsam_account_ok: Account for user '%s' has expired.\n", name_for_logs
));
209 DEBUG(3,("authsam_account_ok: Account expired at '%s'.\n",
210 nt_time_string(mem_ctx
, acct_expiry
)));
211 return NT_STATUS_ACCOUNT_EXPIRED
;
214 /* check for immediate expiry "must change at next logon" (but not if this is a password change request) */
215 if ((must_change_time
== 0) && !password_change
) {
216 DEBUG(2,("sam_account_ok: Account for user '%s' password must change!.\n",
218 return NT_STATUS_PASSWORD_MUST_CHANGE
;
221 /* check for expired password (but not if this is a password change request) */
222 if ((must_change_time
< now
) && !password_change
) {
223 DEBUG(2,("sam_account_ok: Account for user '%s' password expired!.\n",
225 DEBUG(2,("sam_account_ok: Password expired at '%s' unix time.\n",
226 nt_time_string(mem_ctx
, must_change_time
)));
227 return NT_STATUS_PASSWORD_EXPIRED
;
230 /* Test workstation. Workstation list is comma separated. */
231 if (logon_workstation
&& workstation_list
&& *workstation_list
) {
232 bool invalid_ws
= true;
234 char **workstations
= str_list_make(mem_ctx
, workstation_list
, ",");
236 for (i
= 0; workstations
&& workstations
[i
]; i
++) {
237 DEBUG(10,("sam_account_ok: checking for workstation match '%s' and '%s'\n",
238 workstations
[i
], logon_workstation
));
240 if (strequal(workstations
[i
], logon_workstation
)) {
246 talloc_free(workstations
);
249 return NT_STATUS_INVALID_WORKSTATION
;
253 if (!logon_hours_ok(msg
, name_for_logs
)) {
254 return NT_STATUS_INVALID_LOGON_HOURS
;
257 if (!allow_domain_trust
) {
258 if (acct_flags
& ACB_DOMTRUST
) {
259 DEBUG(2,("sam_account_ok: Domain trust account %s denied by server\n", name_for_logs
));
260 return NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT
;
263 if (!(logon_parameters
& MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT
)) {
264 if (acct_flags
& ACB_SVRTRUST
) {
265 DEBUG(2,("sam_account_ok: Server trust account %s denied by server\n", name_for_logs
));
266 return NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT
;
269 if (!(logon_parameters
& MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
)) {
270 /* TODO: this fails with current solaris client. We
271 need to work with Gordon to work out why */
272 if (acct_flags
& ACB_WSTRUST
) {
273 DEBUG(4,("sam_account_ok: Wksta trust account %s denied by server\n", name_for_logs
));
274 return NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT
;
281 _PUBLIC_ NTSTATUS
authsam_make_user_info_dc(TALLOC_CTX
*mem_ctx
,
282 struct ldb_context
*sam_ctx
,
283 const char *netbios_name
,
284 const char *domain_name
,
285 struct ldb_dn
*domain_dn
,
286 struct ldb_message
*msg
,
287 DATA_BLOB user_sess_key
,
288 DATA_BLOB lm_sess_key
,
289 struct auth_user_info_dc
**_user_info_dc
)
292 struct auth_user_info_dc
*user_info_dc
;
293 struct auth_user_info
*info
;
294 const char *str
, *filter
;
295 /* SIDs for the account and his primary group */
296 struct dom_sid
*account_sid
;
297 const char *primary_group_string
;
298 const char *primary_group_dn
;
299 DATA_BLOB primary_group_blob
;
300 /* SID structures for the expanded group memberships */
301 struct dom_sid
*sids
= NULL
;
302 unsigned int num_sids
= 0, i
;
303 struct dom_sid
*domain_sid
;
305 struct ldb_message_element
*el
;
307 user_info_dc
= talloc(mem_ctx
, struct auth_user_info_dc
);
308 NT_STATUS_HAVE_NO_MEMORY(user_info_dc
);
310 tmp_ctx
= talloc_new(user_info_dc
);
311 if (user_info_dc
== NULL
) {
312 TALLOC_FREE(user_info_dc
);
313 return NT_STATUS_NO_MEMORY
;
316 sids
= talloc_array(user_info_dc
, struct dom_sid
, 2);
318 TALLOC_FREE(user_info_dc
);
319 return NT_STATUS_NO_MEMORY
;
324 account_sid
= samdb_result_dom_sid(user_info_dc
, msg
, "objectSid");
325 if (account_sid
== NULL
) {
326 TALLOC_FREE(user_info_dc
);
327 return NT_STATUS_NO_MEMORY
;
330 status
= dom_sid_split_rid(tmp_ctx
, account_sid
, &domain_sid
, NULL
);
331 if (!NT_STATUS_IS_OK(status
)) {
332 talloc_free(user_info_dc
);
336 sids
[PRIMARY_USER_SID_INDEX
] = *account_sid
;
337 sids
[PRIMARY_GROUP_SID_INDEX
] = *domain_sid
;
338 sid_append_rid(&sids
[PRIMARY_GROUP_SID_INDEX
], ldb_msg_find_attr_as_uint(msg
, "primaryGroupID", ~0));
340 /* Filter out builtin groups from this token. We will search
341 * for builtin groups later, and not include them in the PAC
342 * on SamLogon validation info */
343 filter
= talloc_asprintf(tmp_ctx
, "(&(objectClass=group)(!(groupType:1.2.840.113556.1.4.803:=%u))(groupType:1.2.840.113556.1.4.803:=%u))", GROUP_TYPE_BUILTIN_LOCAL_GROUP
, GROUP_TYPE_SECURITY_ENABLED
);
344 if (filter
== NULL
) {
345 TALLOC_FREE(user_info_dc
);
346 return NT_STATUS_NO_MEMORY
;
349 primary_group_string
= dom_sid_string(tmp_ctx
, &sids
[PRIMARY_GROUP_SID_INDEX
]);
350 if (primary_group_string
== NULL
) {
351 TALLOC_FREE(user_info_dc
);
352 return NT_STATUS_NO_MEMORY
;
355 primary_group_dn
= talloc_asprintf(tmp_ctx
, "<SID=%s>", primary_group_string
);
356 if (primary_group_dn
== NULL
) {
357 TALLOC_FREE(user_info_dc
);
358 return NT_STATUS_NO_MEMORY
;
361 primary_group_blob
= data_blob_string_const(primary_group_dn
);
363 /* Expands the primary group - this function takes in
364 * memberOf-like values, so we fake one up with the
365 * <SID=S-...> format of DN and then let it expand
366 * them, as long as they meet the filter - so only
367 * domain groups, not builtin groups
369 * The primary group is still treated specially, so we set the
370 * 'only childs' flag to true
372 status
= dsdb_expand_nested_groups(sam_ctx
, &primary_group_blob
, true, filter
,
373 user_info_dc
, &sids
, &num_sids
);
374 if (!NT_STATUS_IS_OK(status
)) {
375 talloc_free(user_info_dc
);
379 /* Expands the additional groups */
380 el
= ldb_msg_find_element(msg
, "memberOf");
381 for (i
= 0; el
&& i
< el
->num_values
; i
++) {
382 /* This function takes in memberOf values and expands
383 * them, as long as they meet the filter - so only
384 * domain groups, not builtin groups */
385 status
= dsdb_expand_nested_groups(sam_ctx
, &el
->values
[i
], false, filter
,
386 user_info_dc
, &sids
, &num_sids
);
387 if (!NT_STATUS_IS_OK(status
)) {
388 talloc_free(user_info_dc
);
393 user_info_dc
->sids
= sids
;
394 user_info_dc
->num_sids
= num_sids
;
396 user_info_dc
->info
= info
= talloc_zero(user_info_dc
, struct auth_user_info
);
397 NT_STATUS_HAVE_NO_MEMORY(user_info_dc
->info
);
399 info
->account_name
= talloc_steal(info
,
400 ldb_msg_find_attr_as_string(msg
, "sAMAccountName", NULL
));
402 info
->domain_name
= talloc_strdup(info
, domain_name
);
403 if (info
->domain_name
== NULL
) {
404 TALLOC_FREE(user_info_dc
);
405 return NT_STATUS_NO_MEMORY
;
408 str
= ldb_msg_find_attr_as_string(msg
, "displayName", "");
409 info
->full_name
= talloc_strdup(info
, str
);
410 if (info
->full_name
== NULL
) {
411 TALLOC_FREE(user_info_dc
);
412 return NT_STATUS_NO_MEMORY
;
415 str
= ldb_msg_find_attr_as_string(msg
, "scriptPath", "");
416 info
->logon_script
= talloc_strdup(info
, str
);
417 if (info
->logon_script
== NULL
) {
418 TALLOC_FREE(user_info_dc
);
419 return NT_STATUS_NO_MEMORY
;
422 str
= ldb_msg_find_attr_as_string(msg
, "profilePath", "");
423 info
->profile_path
= talloc_strdup(info
, str
);
424 if (info
->profile_path
== NULL
) {
425 TALLOC_FREE(user_info_dc
);
426 return NT_STATUS_NO_MEMORY
;
429 str
= ldb_msg_find_attr_as_string(msg
, "homeDirectory", "");
430 info
->home_directory
= talloc_strdup(info
, str
);
431 if (info
->home_directory
== NULL
) {
432 TALLOC_FREE(user_info_dc
);
433 return NT_STATUS_NO_MEMORY
;
436 str
= ldb_msg_find_attr_as_string(msg
, "homeDrive", "");
437 info
->home_drive
= talloc_strdup(info
, str
);
438 if (info
->home_drive
== NULL
) {
439 TALLOC_FREE(user_info_dc
);
440 return NT_STATUS_NO_MEMORY
;
443 info
->logon_server
= talloc_strdup(info
, netbios_name
);
444 if (info
->logon_server
== NULL
) {
445 TALLOC_FREE(user_info_dc
);
446 return NT_STATUS_NO_MEMORY
;
449 info
->last_logon
= samdb_result_nttime(msg
, "lastLogon", 0);
450 info
->last_logoff
= samdb_result_last_logoff(msg
);
451 info
->acct_expiry
= samdb_result_account_expires(msg
);
452 info
->last_password_change
= samdb_result_nttime(msg
,
454 info
->allow_password_change
455 = samdb_result_allow_password_change(sam_ctx
, mem_ctx
,
456 domain_dn
, msg
, "pwdLastSet");
457 info
->force_password_change
458 = samdb_result_force_password_change(sam_ctx
, mem_ctx
,
460 info
->logon_count
= ldb_msg_find_attr_as_uint(msg
, "logonCount", 0);
461 info
->bad_password_count
= ldb_msg_find_attr_as_uint(msg
, "badPwdCount",
464 info
->acct_flags
= samdb_result_acct_flags(msg
, "msDS-User-Account-Control-Computed");
466 user_info_dc
->user_session_key
= data_blob_talloc(user_info_dc
,
468 user_sess_key
.length
);
469 if (user_sess_key
.data
) {
470 if (user_info_dc
->user_session_key
.data
== NULL
) {
471 TALLOC_FREE(user_info_dc
);
472 return NT_STATUS_NO_MEMORY
;
475 user_info_dc
->lm_session_key
= data_blob_talloc(user_info_dc
,
478 if (lm_sess_key
.data
) {
479 if (user_info_dc
->lm_session_key
.data
== NULL
) {
480 TALLOC_FREE(user_info_dc
);
481 return NT_STATUS_NO_MEMORY
;
485 if (info
->acct_flags
& ACB_SVRTRUST
) {
486 /* the SID_NT_ENTERPRISE_DCS SID gets added into the
488 user_info_dc
->sids
= talloc_realloc(user_info_dc
,
491 user_info_dc
->num_sids
+1);
492 if (user_info_dc
->sids
== NULL
) {
493 TALLOC_FREE(user_info_dc
);
494 return NT_STATUS_NO_MEMORY
;
496 user_info_dc
->sids
[user_info_dc
->num_sids
] = global_sid_Enterprise_DCs
;
497 user_info_dc
->num_sids
++;
500 if ((info
->acct_flags
& (ACB_PARTIAL_SECRETS_ACCOUNT
| ACB_WSTRUST
)) ==
501 (ACB_PARTIAL_SECRETS_ACCOUNT
| ACB_WSTRUST
)) {
502 /* the DOMAIN_RID_ENTERPRISE_READONLY_DCS PAC */
503 user_info_dc
->sids
= talloc_realloc(user_info_dc
,
506 user_info_dc
->num_sids
+1);
507 if (user_info_dc
->sids
== NULL
) {
508 TALLOC_FREE(user_info_dc
);
509 return NT_STATUS_NO_MEMORY
;
511 user_info_dc
->sids
[user_info_dc
->num_sids
] = *domain_sid
;
512 sid_append_rid(&user_info_dc
->sids
[user_info_dc
->num_sids
],
513 DOMAIN_RID_ENTERPRISE_READONLY_DCS
);
514 user_info_dc
->num_sids
++;
517 info
->authenticated
= true;
519 talloc_free(tmp_ctx
);
520 *_user_info_dc
= user_info_dc
;
525 NTSTATUS
sam_get_results_principal(struct ldb_context
*sam_ctx
,
526 TALLOC_CTX
*mem_ctx
, const char *principal
,
528 struct ldb_dn
**domain_dn
,
529 struct ldb_message
**msg
)
531 struct ldb_dn
*user_dn
;
533 TALLOC_CTX
*tmp_ctx
= talloc_new(mem_ctx
);
537 return NT_STATUS_NO_MEMORY
;
540 nt_status
= crack_user_principal_name(sam_ctx
, tmp_ctx
, principal
,
541 &user_dn
, domain_dn
);
542 if (!NT_STATUS_IS_OK(nt_status
)) {
543 talloc_free(tmp_ctx
);
547 /* pull the user attributes */
548 ret
= dsdb_search_one(sam_ctx
, tmp_ctx
, msg
, user_dn
,
549 LDB_SCOPE_BASE
, attrs
,
550 DSDB_SEARCH_SHOW_EXTENDED_DN
| DSDB_SEARCH_NO_GLOBAL_CATALOG
,
552 if (ret
!= LDB_SUCCESS
) {
553 talloc_free(tmp_ctx
);
554 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
556 talloc_steal(mem_ctx
, *msg
);
557 talloc_steal(mem_ctx
, *domain_dn
);
558 talloc_free(tmp_ctx
);
563 /* Used in the gensec_gssapi and gensec_krb5 server-side code, where the PAC isn't available, and for tokenGroups in the DSDB stack.
565 Supply either a principal or a DN
567 NTSTATUS
authsam_get_user_info_dc_principal(TALLOC_CTX
*mem_ctx
,
568 struct loadparm_context
*lp_ctx
,
569 struct ldb_context
*sam_ctx
,
570 const char *principal
,
571 struct ldb_dn
*user_dn
,
572 struct auth_user_info_dc
**user_info_dc
)
575 DATA_BLOB user_sess_key
= data_blob(NULL
, 0);
576 DATA_BLOB lm_sess_key
= data_blob(NULL
, 0);
578 struct ldb_message
*msg
;
579 struct ldb_dn
*domain_dn
;
581 TALLOC_CTX
*tmp_ctx
= talloc_new(mem_ctx
);
583 return NT_STATUS_NO_MEMORY
;
587 nt_status
= sam_get_results_principal(sam_ctx
, tmp_ctx
, principal
,
588 user_attrs
, &domain_dn
, &msg
);
589 if (!NT_STATUS_IS_OK(nt_status
)) {
590 talloc_free(tmp_ctx
);
593 } else if (user_dn
) {
594 struct dom_sid
*user_sid
, *domain_sid
;
596 /* pull the user attributes */
597 ret
= dsdb_search_one(sam_ctx
, tmp_ctx
, &msg
, user_dn
,
598 LDB_SCOPE_BASE
, user_attrs
,
599 DSDB_SEARCH_SHOW_EXTENDED_DN
| DSDB_SEARCH_NO_GLOBAL_CATALOG
,
601 if (ret
== LDB_ERR_NO_SUCH_OBJECT
) {
602 talloc_free(tmp_ctx
);
603 return NT_STATUS_NO_SUCH_USER
;
604 } else if (ret
!= LDB_SUCCESS
) {
605 talloc_free(tmp_ctx
);
606 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
609 user_sid
= samdb_result_dom_sid(msg
, msg
, "objectSid");
611 nt_status
= dom_sid_split_rid(tmp_ctx
, user_sid
, &domain_sid
, NULL
);
612 if (!NT_STATUS_IS_OK(nt_status
)) {
616 domain_dn
= samdb_search_dn(sam_ctx
, mem_ctx
, NULL
,
617 "(&(objectSid=%s)(objectClass=domain))",
618 ldap_encode_ndr_dom_sid(tmp_ctx
, domain_sid
));
620 DEBUG(3, ("authsam_get_user_info_dc_principal: Failed to find domain with: SID %s\n",
621 dom_sid_string(tmp_ctx
, domain_sid
)));
622 return NT_STATUS_NO_SUCH_USER
;
626 return NT_STATUS_INVALID_PARAMETER
;
629 nt_status
= authsam_make_user_info_dc(tmp_ctx
, sam_ctx
,
630 lpcfg_netbios_name(lp_ctx
),
631 lpcfg_workgroup(lp_ctx
),
634 user_sess_key
, lm_sess_key
,
636 if (!NT_STATUS_IS_OK(nt_status
)) {
637 talloc_free(tmp_ctx
);
641 talloc_steal(mem_ctx
, *user_info_dc
);
642 talloc_free(tmp_ctx
);
647 NTSTATUS
authsam_update_bad_pwd_count(struct ldb_context
*sam_ctx
,
648 struct ldb_message
*msg
,
649 struct ldb_dn
*domain_dn
)
651 const char *attrs
[] = { "lockoutThreshold",
652 "lockOutObservationWindow",
658 struct ldb_result
*domain_res
;
659 struct ldb_message
*msg_mod
= NULL
;
662 mem_ctx
= talloc_new(msg
);
663 if (mem_ctx
== NULL
) {
664 return NT_STATUS_NO_MEMORY
;
667 ret
= dsdb_search_dn(sam_ctx
, mem_ctx
, &domain_res
, domain_dn
, attrs
, 0);
668 if (ret
!= LDB_SUCCESS
) {
669 TALLOC_FREE(mem_ctx
);
670 return NT_STATUS_INTERNAL_DB_CORRUPTION
;
673 status
= dsdb_update_bad_pwd_count(mem_ctx
, sam_ctx
,
674 msg
, domain_res
->msgs
[0], &msg_mod
);
675 if (!NT_STATUS_IS_OK(status
)) {
676 TALLOC_FREE(mem_ctx
);
680 if (msg_mod
!= NULL
) {
681 ret
= dsdb_modify(sam_ctx
, msg_mod
, 0);
682 if (ret
!= LDB_SUCCESS
) {
683 DEBUG(0, ("Failed to update badPwdCount, badPasswordTime or set lockoutTime on %s: %s\n",
684 ldb_dn_get_linearized(msg_mod
->dn
), ldb_errstring(sam_ctx
)));
685 TALLOC_FREE(mem_ctx
);
686 return NT_STATUS_INTERNAL_ERROR
;
690 TALLOC_FREE(mem_ctx
);
694 NTSTATUS
authsam_zero_bad_pwd_count(struct ldb_context
*sam_ctx
,
695 const struct ldb_message
*msg
)
700 struct ldb_message
*msg_mod
;
703 lockoutTime
= ldb_msg_find_attr_as_int64(msg
, "lockoutTime", 0);
704 badPwdCount
= ldb_msg_find_attr_as_int(msg
, "badPwdCount", 0);
705 if (lockoutTime
== 0 && badPwdCount
== 0) {
709 mem_ctx
= talloc_new(msg
);
710 if (mem_ctx
== NULL
) {
711 return NT_STATUS_NO_MEMORY
;
713 msg_mod
= ldb_msg_new(mem_ctx
);
714 if (msg_mod
== NULL
) {
715 TALLOC_FREE(mem_ctx
);
716 return NT_STATUS_NO_MEMORY
;
718 msg_mod
->dn
= msg
->dn
;
720 if (lockoutTime
!= 0) {
722 * This implies "badPwdCount" = 0, see samldb_lockout_time()
724 ret
= samdb_msg_add_int(sam_ctx
, msg_mod
, msg_mod
, "lockoutTime", 0);
725 if (ret
!= LDB_SUCCESS
) {
726 TALLOC_FREE(mem_ctx
);
727 return NT_STATUS_NO_MEMORY
;
730 ret
= samdb_msg_add_int(sam_ctx
, msg_mod
, msg_mod
, "badPwdCount", 0);
731 if (ret
!= LDB_SUCCESS
) {
732 TALLOC_FREE(mem_ctx
);
733 return NT_STATUS_NO_MEMORY
;
737 ret
= dsdb_replace(sam_ctx
, msg_mod
, 0);
738 if (ret
!= LDB_SUCCESS
) {
739 DEBUG(0, ("Failed to set badPwdCount and lockoutTime to 0 on %s: %s\n",
740 ldb_dn_get_linearized(msg_mod
->dn
), ldb_errstring(sam_ctx
)));
741 TALLOC_FREE(mem_ctx
);
742 return NT_STATUS_INTERNAL_ERROR
;
745 TALLOC_FREE(mem_ctx
);