secrets: Add function to fetch only password change timestamp
authorChristof Schmitt <cs@samba.org>
Thu, 30 Jul 2015 22:47:54 +0000 (15:47 -0700)
committerJeremy Allison <jra@samba.org>
Sat, 1 Aug 2015 08:55:21 +0000 (10:55 +0200)
Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/include/secrets.h
source3/passdb/machine_account_secrets.c

index 350bdc6b5fa91d9006f9680345f1a82b2646619c..f397129b128c4cba274570cd73ce33742590585c 100644 (file)
@@ -113,6 +113,7 @@ bool secrets_delete_machine_password_ex(const char *domain);
 bool secrets_delete_domain_sid(const char *domain);
 bool secrets_store_machine_password(const char *pass, const char *domain, enum netr_SchannelType sec_channel);
 char *secrets_fetch_prev_machine_password(const char *domain);
+time_t secrets_fetch_pass_last_set_time(const char *domain);
 char *secrets_fetch_machine_password(const char *domain,
                                     time_t *pass_last_set_time,
                                     enum netr_SchannelType *channel);
index 717eaa1a09b0b8129ea8ef3a6565dcde3f3286e1..3f097ab4055691cb6ee627768284f6a94f96b4b0 100644 (file)
@@ -564,6 +564,28 @@ char *secrets_fetch_prev_machine_password(const char *domain)
        return (char *)secrets_fetch(machine_prev_password_keystr(domain), NULL);
 }
 
+/************************************************************************
+ Routine to fetch the last change time of the machine account password
+  for a realm
+************************************************************************/
+
+time_t secrets_fetch_pass_last_set_time(const char *domain)
+{
+       uint32_t *last_set_time;
+       time_t pass_last_set_time;
+
+       last_set_time = secrets_fetch(machine_last_change_time_keystr(domain),
+                                     NULL);
+       if (last_set_time) {
+               pass_last_set_time = IVAL(last_set_time,0);
+               SAFE_FREE(last_set_time);
+       } else {
+               pass_last_set_time = 0;
+       }
+
+       return pass_last_set_time;
+}
+
 /************************************************************************
  Routine to fetch the plaintext machine account password for a realm
  the password is assumed to be a null terminated ascii string.
@@ -577,15 +599,7 @@ char *secrets_fetch_machine_password(const char *domain,
        ret = (char *)secrets_fetch(machine_password_keystr(domain), NULL);
 
        if (pass_last_set_time) {
-               size_t size;
-               uint32_t *last_set_time;
-               last_set_time = (unsigned int *)secrets_fetch(machine_last_change_time_keystr(domain), &size);
-               if (last_set_time) {
-                       *pass_last_set_time = IVAL(last_set_time,0);
-                       SAFE_FREE(last_set_time);
-               } else {
-                       *pass_last_set_time = 0;
-               }
+               *pass_last_set_time = secrets_fetch_pass_last_set_time(domain);
        }
 
        if (channel) {