From 49cc13a8f0fbc4f68e14720b733329ce45135cec Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 12 Oct 2005 07:54:15 +0000 Subject: r10915: added a standard attribute handler for a ldap UTC time string (This used to be commit efd7dd1a775c06f21924f35760f7768b4e8db449) --- source4/lib/ldb/common/attrib_handlers.c | 35 ++++++++++++++++++++++++++++++++ source4/lib/ldb/common/ldb_attributes.c | 29 ++++++++++++++++---------- source4/lib/ldb/include/ldb.h | 3 +++ 3 files changed, 56 insertions(+), 11 deletions(-) (limited to 'source4/lib/ldb') diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c index d073203b3c..4a6e3e3c79 100644 --- a/source4/lib/ldb/common/attrib_handlers.c +++ b/source4/lib/ldb/common/attrib_handlers.c @@ -224,6 +224,33 @@ static int ldb_comparison_objectclass(struct ldb_context *ldb, void *mem_ctx, return ret; } +/* + compare two utc time values. 1 second resolution +*/ +static int ldb_comparison_utctime(struct ldb_context *ldb, void *mem_ctx, + const struct ldb_val *v1, const struct ldb_val *v2) +{ + time_t t1, t2; + t1 = ldb_string_to_time((char *)v1->data); + t1 = ldb_string_to_time((char *)v1->data); + return (int)t2 - (int)t1; +} + +/* + canonicalise a utc time +*/ +static int ldb_canonicalise_utctime(struct ldb_context *ldb, void *mem_ctx, + const struct ldb_val *in, struct ldb_val *out) +{ + time_t t = ldb_string_to_time((char *)in->data); + out->data = (uint8_t *)ldb_timestring(mem_ctx, t); + if (out->data == NULL) { + return -1; + } + out->length = strlen((char *)out->data); + return 0; +} + /* table of standard attribute handlers */ @@ -267,6 +294,14 @@ static const struct ldb_attrib_handler ldb_standard_attribs[] = { .ldif_write_fn = ldb_handler_copy, .canonicalise_fn = ldb_handler_fold, .comparison_fn = ldb_comparison_objectclass + }, + { + .attr = LDB_SYNTAX_UTC_TIME, + .flags = 0, + .ldif_read_fn = ldb_handler_copy, + .ldif_write_fn = ldb_handler_copy, + .canonicalise_fn = ldb_canonicalise_utctime, + .comparison_fn = ldb_comparison_utctime } }; diff --git a/source4/lib/ldb/common/ldb_attributes.c b/source4/lib/ldb/common/ldb_attributes.c index 47b4b1788b..bf955ece3d 100644 --- a/source4/lib/ldb/common/ldb_attributes.c +++ b/source4/lib/ldb/common/ldb_attributes.c @@ -138,6 +138,22 @@ void ldb_remove_attrib_handler(struct ldb_context *ldb, const char *attrib) ldb->schema.num_attrib_handlers--; } +/* + setup a attribute handler using a standard syntax +*/ +int ldb_set_attrib_handler_syntax(struct ldb_context *ldb, + const char *attr, const char *syntax) +{ + const struct ldb_attrib_handler *h = ldb_attrib_handler_syntax(ldb, syntax); + struct ldb_attrib_handler h2; + if (h == NULL) { + ldb_debug(ldb, LDB_DEBUG_ERROR, "Unknown syntax '%s'\n", syntax); + return -1; + } + h2 = *h; + h2.attr = attr; + return ldb_set_attrib_handlers(ldb, &h2, 1); +} /* setup the attribute handles for well known attributes @@ -158,17 +174,8 @@ int ldb_setup_wellknown_attributes(struct ldb_context *ldb) }; int i; for (i=0;i