]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4:kdc: Fix ldb_msg_find_krb5time_ldap_time()
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Wed, 20 Sep 2023 19:32:30 +0000 (07:32 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 27 Sep 2023 02:43:28 +0000 (02:43 +0000)
strptime() will fail to parse the LDAP ‘whenCreated’ time string,
because the format string is wrong: it will expect to get a time like
“20230920043849Z”, but the time string seems to be actually formatted
20230920043849.0Z” — like a GeneralizedTime.

Fix this by delegating to ldb_val_to_time().

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/kdc/db-glue.c

index 0295be5840f75c6727313f6b1db5337129662485..a9d8bc557db58f5b0d99bf3a91e90464d1f43713 100644 (file)
@@ -133,20 +133,17 @@ static void auth_sam_trigger_repl_secret(TALLOC_CTX *mem_ctx,
 
 static time_t ldb_msg_find_krb5time_ldap_time(struct ldb_message *msg, const char *attr, time_t default_val)
 {
-    const char *tmp;
-    const char *gentime;
-    struct tm tm = {};
+    const struct ldb_val *gentime = NULL;
+    time_t t;
+    int ret;
 
-    gentime = ldb_msg_find_attr_as_string(msg, attr, NULL);
-    if (!gentime)
-       return default_val;
-
-    tmp = strptime(gentime, "%Y%m%d%H%M%SZ", &tm);
-    if (tmp == NULL) {
+    gentime = ldb_msg_find_ldb_val(msg, attr);
+    ret = ldb_val_to_time(gentime, &t);
+    if (ret) {
            return default_val;
     }
 
-    return timegm(&tm);
+    return t;
 }
 
 static struct SDBFlags uf2SDBFlags(krb5_context context, uint32_t userAccountControl, enum samba_kdc_ent_type ent_type)