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>
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)