1
0
mirror of https://github.com/samba-team/samba.git synced 2025-11-25 00:23:52 +03:00

r10914: moved the ldap time string functions into ldb so they can be used by

the time attribute handling functions
This commit is contained in:
Andrew Tridgell
2005-10-12 06:30:47 +00:00
committed by Gerald (Jerry) Carter
parent f6818daecc
commit 93c296d527
7 changed files with 52 additions and 59 deletions

View File

@@ -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);
}