svn commit: samba r10915 - in branches/SAMBA_4_0/source/lib/ldb: common include

tridge at samba.org tridge at samba.org
Wed Oct 12 07:54:16 GMT 2005


Author: tridge
Date: 2005-10-12 07:54:15 +0000 (Wed, 12 Oct 2005)
New Revision: 10915

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=10915

Log:

added a standard attribute handler for a ldap UTC time string

Modified:
   branches/SAMBA_4_0/source/lib/ldb/common/attrib_handlers.c
   branches/SAMBA_4_0/source/lib/ldb/common/ldb_attributes.c
   branches/SAMBA_4_0/source/lib/ldb/include/ldb.h


Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/common/attrib_handlers.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/attrib_handlers.c	2005-10-12 06:30:47 UTC (rev 10914)
+++ branches/SAMBA_4_0/source/lib/ldb/common/attrib_handlers.c	2005-10-12 07:54:15 UTC (rev 10915)
@@ -225,6 +225,33 @@
 }
 
 /*
+  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
 */
 static const struct ldb_attrib_handler ldb_standard_attribs[] = {
@@ -267,6 +294,14 @@
 		.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
 	}
 };
 

Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb_attributes.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/ldb_attributes.c	2005-10-12 06:30:47 UTC (rev 10914)
+++ branches/SAMBA_4_0/source/lib/ldb/common/ldb_attributes.c	2005-10-12 07:54:15 UTC (rev 10915)
@@ -138,6 +138,22 @@
 	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,19 +174,10 @@
 	};
 	int i;
 	for (i=0;i<ARRAY_SIZE(wellknown);i++) {
-		const struct ldb_attrib_handler *h = 
-			ldb_attrib_handler_syntax(ldb, wellknown[i].syntax);
-		struct ldb_attrib_handler h2;
-		if (h == NULL) {
-			ldb_debug(ldb, LDB_DEBUG_ERROR, "Unknown syntax '%s'\n",
-				  wellknown[i].syntax);
+		if (ldb_set_attrib_handler_syntax(ldb, wellknown[i].attr, 
+						  wellknown[i].syntax) != 0) {
 			return -1;
 		}
-		h2 = *h;
-		h2.attr = wellknown[i].attr;
-		if (ldb_set_attrib_handlers(ldb, &h2, 1) != 0) {
-			return -1;
-		}
 	}
 	return 0;
 }

Modified: branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/include/ldb.h	2005-10-12 06:30:47 UTC (rev 10914)
+++ branches/SAMBA_4_0/source/lib/ldb/include/ldb.h	2005-10-12 07:54:15 UTC (rev 10915)
@@ -251,6 +251,7 @@
 #define LDB_SYNTAX_DIRECTORY_STRING     "1.3.6.1.4.1.1466.115.121.1.15"
 #define LDB_SYNTAX_INTEGER              "1.3.6.1.4.1.1466.115.121.1.27"
 #define LDB_SYNTAX_OCTET_STRING         "1.3.6.1.4.1.1466.115.121.1.40"
+#define LDB_SYNTAX_UTC_TIME             "1.3.6.1.4.1.1466.115.121.1.53"
 #define LDB_SYNTAX_OBJECTCLASS          "LDB_SYNTAX_OBJECTCLASS"
 
 /*
@@ -452,6 +453,8 @@
 
 void ldb_msg_sort_elements(struct ldb_message *msg);
 
+struct ldb_message *ldb_msg_copy_shallow(TALLOC_CTX *mem_ctx, 
+					 const struct ldb_message *msg);
 struct ldb_message *ldb_msg_copy(void *mem_ctx, 
 				 const struct ldb_message *msg);
 



More information about the samba-cvs mailing list