diff options
Diffstat (limited to 'source4')
-rw-r--r-- | source4/dsdb/samdb/samdb.c | 13 | ||||
-rw-r--r-- | source4/ldap_server/ldap_rootdse.c | 4 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb_msg.c | 43 | ||||
-rw-r--r-- | source4/lib/ldb/include/ldb.h | 3 | ||||
-rw-r--r-- | source4/lib/time.c | 41 | ||||
-rw-r--r-- | source4/nbt_server/wins/winsdb.c | 4 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls_sys.c | 3 |
7 files changed, 52 insertions, 59 deletions
diff --git a/source4/dsdb/samdb/samdb.c b/source4/dsdb/samdb/samdb.c index 6afa83e1aa..2e1ce9ecb5 100644 --- a/source4/dsdb/samdb/samdb.c +++ b/source4/dsdb/samdb/samdb.c @@ -909,19 +909,6 @@ int samdb_msg_set_string(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struc } /* - set a ldaptime element in a message -*/ -int samdb_msg_set_ldaptime(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, - const char *attr_name, time_t t) -{ - char *str = ldap_timestring(mem_ctx, t); - if (!str) { - return -1; - } - return samdb_msg_set_string(sam_ldb, mem_ctx, msg, attr_name, str); -} - -/* add a record */ int samdb_add(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg) diff --git a/source4/ldap_server/ldap_rootdse.c b/source4/ldap_server/ldap_rootdse.c index 93d39fa155..81a9626f14 100644 --- a/source4/ldap_server/ldap_rootdse.c +++ b/source4/ldap_server/ldap_rootdse.c @@ -90,7 +90,7 @@ static NTSTATUS fill_dynamic_values(void *mem_ctx, struct ldb_message_element *a { int num_currentTime = 1; DATA_BLOB *currentTime = talloc_array(mem_ctx, DATA_BLOB, num_currentTime); - char *str = ldap_timestring(mem_ctx, time(NULL)); + char *str = ldb_timestring(mem_ctx, time(NULL)); NT_STATUS_HAVE_NO_MEMORY(str); currentTime[0].data = (uint8_t *)str; currentTime[0].length = strlen(str); @@ -316,7 +316,7 @@ static NTSTATUS rootdse_Search(struct ldapsrv_partition *partition, struct ldaps for (j=0; j < ent->num_attributes; j++) { if (ent->attributes[j].num_values == 1 && ent->attributes[j].values[0].length >= 9 && - strncmp(ent->attributes[j].values[0].data, "_DYNAMIC_", 9) == 0) { + strncmp((char *)ent->attributes[j].values[0].data, "_DYNAMIC_", 9) == 0) { status = fill_dynamic_values(ent->attributes, &(ent->attributes[j])); if (!NT_STATUS_IS_OK(status)) { return status; 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 diff --git a/source4/lib/time.c b/source4/lib/time.c index 5de9046c8d..c9cf0b9630 100644 --- a/source4/lib/time.c +++ b/source4/lib/time.c @@ -301,47 +301,6 @@ char *http_timestring(TALLOC_CTX *mem_ctx, time_t t) return buf; } -/* - return a LDAP time string -*/ -char *ldap_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 ldap_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); -} - /**************************************************************************** Return the date and time as a string ****************************************************************************/ diff --git a/source4/nbt_server/wins/winsdb.c b/source4/nbt_server/wins/winsdb.c index ea56fece1d..e719ef0968 100644 --- a/source4/nbt_server/wins/winsdb.c +++ b/source4/nbt_server/wins/winsdb.c @@ -136,7 +136,7 @@ struct winsdb_record *winsdb_load(struct wins_server *winssrv, rec->name = name; rec->state = ldb_msg_find_int(res[0], "active", WINS_REC_RELEASED); rec->nb_flags = ldb_msg_find_int(res[0], "nbFlags", 0); - rec->expire_time = ldap_string_to_time(ldb_msg_find_string(res[0], "expires", NULL)); + rec->expire_time = ldb_string_to_time(ldb_msg_find_string(res[0], "expires", NULL)); rec->registered_by = ldb_msg_find_string(res[0], "registeredBy", NULL); rec->version = ldb_msg_find_uint64(res[0], "version", 0); talloc_steal(rec, rec->registered_by); @@ -187,7 +187,7 @@ static struct ldb_message *winsdb_message(struct wins_server *winssrv, ret |= ldb_msg_add_fmt(msg, "nbFlags", "0x%04x", rec->nb_flags); ret |= ldb_msg_add_string(msg, "registeredBy", rec->registered_by); ret |= ldb_msg_add_string(msg, "expires", - ldap_timestring(msg, rec->expire_time)); + ldb_timestring(msg, rec->expire_time)); ret |= ldb_msg_add_fmt(msg, "version", "%llu", rec->version); for (i=0;rec->addresses[i];i++) { ret |= ldb_msg_add_string(msg, "address", rec->addresses[i]); diff --git a/source4/scripting/ejs/smbcalls_sys.c b/source4/scripting/ejs/smbcalls_sys.c index f32605c3d5..340671cf0b 100644 --- a/source4/scripting/ejs/smbcalls_sys.c +++ b/source4/scripting/ejs/smbcalls_sys.c @@ -23,6 +23,7 @@ #include "includes.h" #include "scripting/ejs/smbcalls.h" #include "lib/appweb/ejs/ejs.h" +#include "lib/ldb/include/ldb.h" #include "system/time.h" /* @@ -111,7 +112,7 @@ static int ejs_sys_ldaptime(MprVarHandle eid, int argc, struct MprVar **argv) return -1; } t = nt_time_to_unix(mprVarToNumber(argv[0])); - s = ldap_timestring(mprMemCtx(), t); + s = ldb_timestring(mprMemCtx(), t); mpr_Return(eid, mprString(s)); talloc_free(s); return 0; |