From 487119d741b5e7a5d0805b785248b40f2b4548c8 Mon Sep 17 00:00:00 2001 From: Christof Schmitt Date: Thu, 30 Jul 2015 15:47:54 -0700 Subject: [PATCH] secrets: Add function to fetch only password change timestamp Signed-off-by: Christof Schmitt Reviewed-by: Jeremy Allison --- source3/include/secrets.h | 1 + source3/passdb/machine_account_secrets.c | 32 +++++++++++++++++------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/source3/include/secrets.h b/source3/include/secrets.h index 350bdc6b5fa..f397129b128 100644 --- a/source3/include/secrets.h +++ b/source3/include/secrets.h @@ -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); diff --git a/source3/passdb/machine_account_secrets.c b/source3/passdb/machine_account_secrets.c index 717eaa1a09b..3f097ab4055 100644 --- a/source3/passdb/machine_account_secrets.c +++ b/source3/passdb/machine_account_secrets.c @@ -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) { -- 2.47.2