summaryrefslogtreecommitdiff
path: root/source4/lib/ldb
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-10-12 06:30:47 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:39:42 -0500
commit33da2fabe6c3b1e20a955d72e1ebd0e850751df0 (patch)
tree4ea80e8517186e41515011b97b0dd7d77b5554c7 /source4/lib/ldb
parenta599edf04cbdeef9014923ba0d3713b8ff84f266 (diff)
downloadsamba-33da2fabe6c3b1e20a955d72e1ebd0e850751df0.tar.gz
samba-33da2fabe6c3b1e20a955d72e1ebd0e850751df0.tar.bz2
samba-33da2fabe6c3b1e20a955d72e1ebd0e850751df0.zip
r10914: moved the ldap time string functions into ldb so they can be used by
the time attribute handling functions (This used to be commit 93c296d52718e77f8b702e1721b548eaadc56c76)
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r--source4/lib/ldb/common/ldb_msg.c43
-rw-r--r--source4/lib/ldb/include/ldb.h3
2 files changed, 46 insertions, 0 deletions
diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c
index 01941f5728..2aef7acc42 100644
--- a/source4/lib/ldb/common/ldb_msg.c
+++ b/source4/lib/ldb/common/ldb_msg.c
@@ -36,6 +36,7 @@
#include "ldb/include/ldb.h"
#include "ldb/include/ldb_errors.h"
#include "ldb/include/ldb_private.h"
+#include <time.h>
/*
create a new ldb_message in a given memory context (NULL for top level)
@@ -594,3 +595,45 @@ int ldb_msg_copy_attr(struct ldb_message *msg, const char *attr, const char *rep
return 0;
}
+
+/*
+ return a LDAP formatted time string
+*/
+char *ldb_timestring(TALLOC_CTX *mem_ctx, time_t t)
+{
+ struct tm *tm = gmtime(&t);
+
+ if (!tm) {
+ return NULL;
+ }
+
+ /* formatted like: 20040408072012.0Z */
+ return talloc_asprintf(mem_ctx,
+ "%04u%02u%02u%02u%02u%02u.0Z",
+ tm->tm_year+1900, tm->tm_mon+1,
+ tm->tm_mday, tm->tm_hour, tm->tm_min,
+ tm->tm_sec);
+}
+
+
+/*
+ convert a LDAP time string to a time_t. Return 0 if unable to convert
+*/
+time_t ldb_string_to_time(const char *s)
+{
+ struct tm tm;
+
+ if (s == NULL) return 0;
+
+ ZERO_STRUCT(tm);
+ if (sscanf(s, "%04u%02u%02u%02u%02u%02u.0Z",
+ &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
+ &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
+ return 0;
+ }
+ tm.tm_year -= 1900;
+ tm.tm_mon -= 1;
+
+ return timegm(&tm);
+}
+
diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h
index d75ca4fe86..0af88f8427 100644
--- a/source4/lib/ldb/include/ldb.h
+++ b/source4/lib/ldb/include/ldb.h
@@ -497,4 +497,7 @@ void ldb_parse_tree_attr_replace(struct ldb_parse_tree *tree,
void ldb_msg_rename_attr(struct ldb_message *msg, const char *attr, const char *replace);
int ldb_msg_copy_attr(struct ldb_message *msg, const char *attr, const char *replace);
+char *ldb_timestring(TALLOC_CTX *mem_ctx, time_t t);
+time_t ldb_string_to_time(const char *s);
+
#endif