summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2007-01-02 10:59:38 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:35:52 -0500
commit71bc79caab7f9510151b31846755cc4db7b81ec0 (patch)
tree581ae742af0a88514f0ad9e6a185d4c43724de8f /source4/lib/ldb/common
parentaf384475056d3cdbf9a31b9a02782e1afd9e641f (diff)
downloadsamba-71bc79caab7f9510151b31846755cc4db7b81ec0.tar.gz
samba-71bc79caab7f9510151b31846755cc4db7b81ec0.tar.bz2
samba-71bc79caab7f9510151b31846755cc4db7b81ec0.zip
r20462: add functions to handle UTCTime strings
metze (This used to be commit 49c7da812c290e23bb65b98a2710fb90c4a0ece2)
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r--source4/lib/ldb/common/ldb_msg.c59
1 files changed, 56 insertions, 3 deletions
diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c
index 9efd3d4d52..bed3647d3a 100644
--- a/source4/lib/ldb/common/ldb_msg.c
+++ b/source4/lib/ldb/common/ldb_msg.c
@@ -757,7 +757,7 @@ void ldb_msg_remove_element(struct ldb_message *msg, struct ldb_message_element
}
/*
- return a LDAP formatted time string
+ return a LDAP formatted GeneralizedTime string
*/
char *ldb_timestring(TALLOC_CTX *mem_ctx, time_t t)
{
@@ -787,9 +787,8 @@ char *ldb_timestring(TALLOC_CTX *mem_ctx, time_t t)
return ts;
}
-
/*
- convert a LDAP time string to a time_t. Return 0 if unable to convert
+ convert a LDAP GeneralizedTime string to a time_t. Return 0 if unable to convert
*/
time_t ldb_string_to_time(const char *s)
{
@@ -809,6 +808,60 @@ time_t ldb_string_to_time(const char *s)
return timegm(&tm);
}
+/*
+ return a LDAP formatted UTCTime string
+*/
+char *ldb_timestring_utc(TALLOC_CTX *mem_ctx, time_t t)
+{
+ struct tm *tm = gmtime(&t);
+ char *ts;
+ int r;
+
+ if (!tm) {
+ return NULL;
+ }
+
+ /* we now excatly how long this string will be */
+ ts = talloc_array(mem_ctx, char, 14);
+
+ /* formatted like: 20040408072012.0Z => 040408072012Z */
+ r = snprintf(ts, 14,
+ "%02u%02u%02u%02u%02u%02uZ",
+ (tm->tm_year+1900)%100, tm->tm_mon+1,
+ tm->tm_mday, tm->tm_hour, tm->tm_min,
+ tm->tm_sec);
+
+ if (r != 13) {
+ talloc_free(ts);
+ return NULL;
+ }
+
+ return ts;
+}
+
+/*
+ convert a LDAP UTCTime string to a time_t. Return 0 if unable to convert
+*/
+time_t ldb_string_utc_to_time(const char *s)
+{
+ struct tm tm;
+
+ if (s == NULL) return 0;
+
+ memset(&tm, 0, sizeof(tm));
+ if (sscanf(s, "%02u%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 0;
+ }
+ if (tm.tm_year < 50) {
+ tm.tm_year += 100;
+ }
+ tm.tm_mon -= 1;
+
+ return timegm(&tm);
+}
+
/*
dump a set of results to a file. Useful from within gdb