diff options
author | Andrew Tridgell <tridge@samba.org> | 2009-12-29 11:36:37 +1100 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2010-01-02 08:16:55 +1100 |
commit | baae6ef9d24a59f794a8cbc9aa0ccdbbeb2ed369 (patch) | |
tree | 6aa22c7344c7fa8b022103854c4269e49d893742 /source4/lib/ldb/common | |
parent | e3cf818c277f90df37cab8a2ecbf93e6a92d8cb2 (diff) | |
download | samba-baae6ef9d24a59f794a8cbc9aa0ccdbbeb2ed369.tar.gz samba-baae6ef9d24a59f794a8cbc9aa0ccdbbeb2ed369.tar.bz2 samba-baae6ef9d24a59f794a8cbc9aa0ccdbbeb2ed369.zip |
s4-ldb: added ldb_val_to_time()
This is intended as a replacement for ldb_string_to_time() for ldb_val
inputs. This ensures it is length limited and includes additional
validity checks
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r-- | source4/lib/ldb/common/ldb_msg.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c index fbf49fbb23..9b33d7e351 100644 --- a/source4/lib/ldb/common/ldb_msg.c +++ b/source4/lib/ldb/common/ldb_msg.c @@ -832,6 +832,33 @@ time_t ldb_string_to_time(const char *s) } /* + convert a LDAP GeneralizedTime string in ldb_val format to a + time_t. +*/ +int ldb_val_to_time(const struct ldb_val *v, time_t *t) +{ + struct tm tm; + + if (v == NULL || !v->data || v->length < 14) { + return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX; + } + + memset(&tm, 0, sizeof(tm)); + + if (sscanf((char *)v->data, "%04u%02u%02u%02u%02u%02u", + &tm.tm_year, &tm.tm_mon, &tm.tm_mday, + &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) { + return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX; + } + tm.tm_year -= 1900; + tm.tm_mon -= 1; + + *t = timegm(&tm); + + return LDB_SUCCESS; +} + +/* return a LDAP formatted UTCTime string */ char *ldb_timestring_utc(TALLOC_CTX *mem_ctx, time_t t) |