r9229: merge from trunk:
authorGünther Deschner <gd@samba.org>
Wed, 10 Aug 2005 16:02:32 +0000 (16:02 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 16:00:28 +0000 (11:00 -0500)
allow admins to uncheck the "User must change Password at next Logon"
checkbox in Usermanager.

Guenther
(This used to be commit b1e4b72c1c36869c4dfc5ed284be24edc99f6774)

source3/rpc_server/srv_samr_util.c

index 66cf1cc46dc961fb312cf11f423b29fb48fd50db..24869d5d2bd07a07665055fa66e3871ce059f379 100644 (file)
@@ -286,7 +286,25 @@ void copy_id21_to_sam_passwd(SAM_ACCOUNT *to, SAM_USER_INFO_21 *from)
 
        DEBUG(10,("INFO_21 PASS_MUST_CHANGE_AT_NEXT_LOGON: %02X\n",from->passmustchange));
        if (from->passmustchange==PASS_MUST_CHANGE_AT_NEXT_LOGON) {
-               pdb_set_pass_must_change_time(to,0, PDB_CHANGED);               
+               pdb_set_pass_must_change_time(to,0, PDB_CHANGED);
+       } else {
+               uint32 expire;
+               time_t new_time;
+               if (pdb_get_pass_must_change_time(to) == 0) {
+                       if (!account_policy_get(AP_MAX_PASSWORD_AGE, &expire)
+                           || expire == (uint32)-1) {
+                               new_time = get_time_t_max();
+                       } else {
+                               time_t old_time = pdb_get_pass_last_set_time(to);
+                               new_time = old_time + expire;
+                               if ((new_time) < time(0)) {
+                                       new_time = time(0) + expire;
+                               }
+                       }
+                       if (!pdb_set_pass_must_change_time (to, new_time, PDB_CHANGED)) {
+                               DEBUG (0, ("pdb_set_pass_must_change_time failed!\n"));
+                       }
+               }
        }
 
        DEBUG(10,("INFO_21 PADDING_2: %02X\n",from->padding2));
@@ -490,7 +508,6 @@ void copy_id23_to_sam_passwd(SAM_ACCOUNT *to, SAM_USER_INFO_23 *from)
                DEBUG(15,("INFO_23 LOGON_HRS.HOURS: %s -> %s\n",pdb_get_hours(to),from->logon_hrs.hours));
                /* Fix me: only update if it changes --metze */
                pdb_set_hours(to, from->logon_hrs.hours, PDB_CHANGED);
-
        }
 
        if (from->fields_present & ACCT_BAD_PWD_COUNT) {
@@ -510,6 +527,24 @@ void copy_id23_to_sam_passwd(SAM_ACCOUNT *to, SAM_USER_INFO_23 *from)
        DEBUG(10,("INFO_23 PASS_MUST_CHANGE_AT_NEXT_LOGON: %02X\n",from->passmustchange));
        if (from->passmustchange==PASS_MUST_CHANGE_AT_NEXT_LOGON) {
                pdb_set_pass_must_change_time(to,0, PDB_CHANGED);               
+       } else {
+               uint32 expire;
+               time_t new_time;
+               if (pdb_get_pass_must_change_time(to) == 0) {
+                       if (!account_policy_get(AP_MAX_PASSWORD_AGE, &expire)
+                           || expire == (uint32)-1) {
+                               new_time = get_time_t_max();
+                       } else {
+                               time_t old_time = pdb_get_pass_last_set_time(to);
+                               new_time = old_time + expire;
+                               if ((new_time) < time(0)) {
+                                       new_time = time(0) + expire;
+                               }
+                       }
+                       if (!pdb_set_pass_must_change_time (to, new_time, PDB_CHANGED)) {
+                               DEBUG (0, ("pdb_set_pass_must_change_time failed!\n"));
+                       }
+               }
        }
 
        DEBUG(10,("INFO_23 PADDING_2: %02X\n",from->padding2));