Fix bug #7072 - Accounts can't be unlocked from ldap.
[ira/wip.git] / source3 / passdb / login_cache.c
index 2a6350045be730ce690bcd31b80ad9b567942f46..5e1c9775cdf19c09d5372484dd779955cfbbdb5c 100644 (file)
@@ -68,6 +68,7 @@ LOGIN_CACHE * login_cache_read(struct samu *sampass)
        char *keystr;
        TDB_DATA databuf;
        LOGIN_CACHE *entry;
        char *keystr;
        TDB_DATA databuf;
        LOGIN_CACHE *entry;
+       uint32_t entry_timestamp = 0, bad_password_time = 0;
 
        if (!login_cache_init())
                return NULL;
 
        if (!login_cache_init())
                return NULL;
@@ -92,17 +93,22 @@ LOGIN_CACHE * login_cache_read(struct samu *sampass)
                SAFE_FREE(databuf.dptr);
                return NULL;
        }
                SAFE_FREE(databuf.dptr);
                return NULL;
        }
+       ZERO_STRUCTP(entry);
 
        if (tdb_unpack (databuf.dptr, databuf.dsize, SAM_CACHE_FORMAT,
                        &entry->entry_timestamp, &entry->acct_ctrl, 
 
        if (tdb_unpack (databuf.dptr, databuf.dsize, SAM_CACHE_FORMAT,
                        &entry->entry_timestamp, &entry->acct_ctrl, 
-                       &entry->bad_password_count, 
-                       &entry->bad_password_time) == -1) {
+                       &entry->bad_password_count,
+                       &bad_password_time) == -1) {
                DEBUG(7, ("No cache entry found\n"));
                SAFE_FREE(entry);
                SAFE_FREE(databuf.dptr);
                return NULL;
        }
 
                DEBUG(7, ("No cache entry found\n"));
                SAFE_FREE(entry);
                SAFE_FREE(databuf.dptr);
                return NULL;
        }
 
+       /* Deal with possible 64-bit time_t. */
+       entry->entry_timestamp = (time_t)entry_timestamp;
+       entry->bad_password_time = (time_t)bad_password_time;
+
        SAFE_FREE(databuf.dptr);
 
        DEBUG(5, ("Found login cache entry: timestamp %12u, flags 0x%x, count %d, time %12u\n",
        SAFE_FREE(databuf.dptr);
 
        DEBUG(5, ("Found login cache entry: timestamp %12u, flags 0x%x, count %d, time %12u\n",
@@ -116,6 +122,8 @@ bool login_cache_write(const struct samu *sampass, LOGIN_CACHE entry)
        char *keystr;
        TDB_DATA databuf;
        bool ret;
        char *keystr;
        TDB_DATA databuf;
        bool ret;
+       uint32_t entry_timestamp;
+       uint32_t bad_password_time = (uint32_t)entry.bad_password_time;
 
        if (!login_cache_init())
                return False;
 
        if (!login_cache_init())
                return False;
@@ -130,14 +138,14 @@ bool login_cache_write(const struct samu *sampass, LOGIN_CACHE entry)
                return False;
        }
 
                return False;
        }
 
-       entry.entry_timestamp = time(NULL);
+       entry_timestamp = (uint32_t)time(NULL);
 
        databuf.dsize = 
                tdb_pack(NULL, 0, SAM_CACHE_FORMAT,
 
        databuf.dsize = 
                tdb_pack(NULL, 0, SAM_CACHE_FORMAT,
-                        entry.entry_timestamp,
+                        entry_timestamp,
                         entry.acct_ctrl,
                         entry.bad_password_count,
                         entry.acct_ctrl,
                         entry.bad_password_count,
-                        entry.bad_password_time);
+                        bad_password_time);
        databuf.dptr = SMB_MALLOC_ARRAY(uint8, databuf.dsize);
        if (!databuf.dptr) {
                SAFE_FREE(keystr);
        databuf.dptr = SMB_MALLOC_ARRAY(uint8, databuf.dsize);
        if (!databuf.dptr) {
                SAFE_FREE(keystr);
@@ -145,10 +153,10 @@ bool login_cache_write(const struct samu *sampass, LOGIN_CACHE entry)
        }
                         
        if (tdb_pack(databuf.dptr, databuf.dsize, SAM_CACHE_FORMAT,
        }
                         
        if (tdb_pack(databuf.dptr, databuf.dsize, SAM_CACHE_FORMAT,
-                        entry.entry_timestamp,
+                        entry_timestamp,
                         entry.acct_ctrl,
                         entry.bad_password_count,
                         entry.acct_ctrl,
                         entry.bad_password_count,
-                        entry.bad_password_time)
+                        bad_password_time)
            != databuf.dsize) {
                SAFE_FREE(keystr);
                SAFE_FREE(databuf.dptr);
            != databuf.dsize) {
                SAFE_FREE(keystr);
                SAFE_FREE(databuf.dptr);