summaryrefslogtreecommitdiff
path: root/lib/ldb/common
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ldb/common')
-rw-r--r--lib/ldb/common/attrib_handlers.c28
-rw-r--r--lib/ldb/common/ldb_msg.c18
2 files changed, 41 insertions, 5 deletions
diff --git a/lib/ldb/common/attrib_handlers.c b/lib/ldb/common/attrib_handlers.c
index 73e1705593..daeb422aca 100644
--- a/lib/ldb/common/attrib_handlers.c
+++ b/lib/ldb/common/attrib_handlers.c
@@ -387,6 +387,27 @@ static int ldb_canonicalise_utctime(struct ldb_context *ldb, void *mem_ctx,
if (ret != LDB_SUCCESS) {
return ret;
}
+ out->data = (uint8_t *)ldb_timestring_utc(mem_ctx, t);
+ if (out->data == NULL) {
+ ldb_oom(ldb);
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+ out->length = strlen((char *)out->data);
+ return 0;
+}
+
+/*
+ canonicalise a generalized time
+*/
+static int ldb_canonicalise_generalizedtime(struct ldb_context *ldb, void *mem_ctx,
+ const struct ldb_val *in, struct ldb_val *out)
+{
+ time_t t;
+ int ret;
+ ret = ldb_val_to_time(in, &t);
+ if (ret != LDB_SUCCESS) {
+ return ret;
+ }
out->data = (uint8_t *)ldb_timestring(mem_ctx, t);
if (out->data == NULL) {
ldb_oom(ldb);
@@ -443,6 +464,13 @@ static const struct ldb_schema_syntax ldb_standard_syntaxes[] = {
.comparison_fn = ldb_comparison_utctime
},
{
+ .name = LDB_SYNTAX_GENERALIZED_TIME,
+ .ldif_read_fn = ldb_handler_copy,
+ .ldif_write_fn = ldb_handler_copy,
+ .canonicalise_fn = ldb_canonicalise_generalizedtime,
+ .comparison_fn = ldb_comparison_utctime
+ },
+ {
.name = LDB_SYNTAX_BOOLEAN,
.ldif_read_fn = ldb_handler_copy,
.ldif_write_fn = ldb_handler_copy,
diff --git a/lib/ldb/common/ldb_msg.c b/lib/ldb/common/ldb_msg.c
index 35c568a077..809e3af819 100644
--- a/lib/ldb/common/ldb_msg.c
+++ b/lib/ldb/common/ldb_msg.c
@@ -1092,16 +1092,24 @@ int ldb_val_to_time(const struct ldb_val *v, time_t *t)
{
struct tm tm;
- if (v == NULL || !v->data || v->length < 17) {
+ if (v == NULL || !v->data || (v->length != 17 && v->length != 13)) {
return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
}
memset(&tm, 0, sizeof(tm));
- if (sscanf((char *)v->data, "%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 LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
+ if (v->length == 13) {
+ if (sscanf((char *)v->data, "%02u%02u%02u%02u%02u%02uZ",
+ &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
+ &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
+ return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
+ }
+ } else {
+ if (sscanf((char *)v->data, "%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 LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
+ }
}
tm.tm_year -= 1900;
tm.tm_mon -= 1;