svn commit: samba r7804 - in branches/SAMBA_4_0/source/lib/ldb: . common include samba tools

tridge at samba.org tridge at samba.org
Tue Jun 21 07:52:01 GMT 2005


Author: tridge
Date: 2005-06-21 07:52:00 +0000 (Tue, 21 Jun 2005)
New Revision: 7804

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

Log:
added the samba specific ldif handlers into the tree, but don't enable
them just yet. I have tested them, and they work fine, but enabling
them will break code in rpc_server/ and samdb, so we need to fix that
first

Added:
   branches/SAMBA_4_0/source/lib/ldb/samba/
   branches/SAMBA_4_0/source/lib/ldb/samba/README
   branches/SAMBA_4_0/source/lib/ldb/samba/ldif_handlers.c
Modified:
   branches/SAMBA_4_0/source/lib/ldb/common/ldb_ldif.c
   branches/SAMBA_4_0/source/lib/ldb/config.mk
   branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
   branches/SAMBA_4_0/source/lib/ldb/tools/cmdline.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb_ldif.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/ldb_ldif.c	2005-06-21 06:35:55 UTC (rev 7803)
+++ branches/SAMBA_4_0/source/lib/ldb/common/ldb_ldif.c	2005-06-21 07:52:00 UTC (rev 7804)
@@ -41,7 +41,31 @@
 #include "ldb/include/ldb_private.h"
 #include <ctype.h>
 
+
 /*
+  add to the list of ldif handlers for this ldb context
+*/
+int ldb_ldif_add_handlers(struct ldb_context *ldb, 
+			  const struct ldb_ldif_handler *handlers, 
+			  unsigned num_handlers)
+{
+	struct ldb_ldif_handler *h;
+	h = talloc_realloc(ldb, ldb->ldif_handlers,
+			   struct ldb_ldif_handler,
+			   ldb->ldif_num_handlers + num_handlers);
+	if (h == NULL) {
+		ldb_oom(ldb);
+		return -1;
+	}
+	ldb->ldif_handlers = h;
+	memcpy(h + ldb->ldif_num_handlers, 
+	       handlers, sizeof(*h) * num_handlers);
+	ldb->ldif_num_handlers += num_handlers;
+	return 0;
+}
+			  
+
+/*
   default function for ldif read/write
 */
 static int ldb_ldif_default(struct ldb_context *ldb, const struct ldb_val *in, 
@@ -59,7 +83,7 @@
 {
 	int i;
 	for (i=0;i<ldb->ldif_num_handlers;i++) {
-		if (strcmp(attr, ldb->ldif_handlers[i].attr) == 0) {
+		if (ldb_attr_cmp(attr, ldb->ldif_handlers[i].attr) == 0) {
 			return ldb->ldif_handlers[i].read_fn;
 		}
 	}
@@ -73,7 +97,7 @@
 {
 	int i;
 	for (i=0;i<ldb->ldif_num_handlers;i++) {
-		if (strcmp(attr, ldb->ldif_handlers[i].attr) == 0) {
+		if (ldb_attr_cmp(attr, ldb->ldif_handlers[i].attr) == 0) {
 			return ldb->ldif_handlers[i].write_fn;
 		}
 	}

Modified: branches/SAMBA_4_0/source/lib/ldb/config.mk
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/config.mk	2005-06-21 06:35:55 UTC (rev 7803)
+++ branches/SAMBA_4_0/source/lib/ldb/config.mk	2005-06-21 07:52:00 UTC (rev 7804)
@@ -91,11 +91,19 @@
 ################################################
 
 ################################################
+# Start SUBSYSTEM LDBSAMBA
+[SUBSYSTEM::LDBSAMBA]
+OBJ_FILES = \
+		lib/ldb/samba/ldif_handlers.o
+# End SUBSYSTEM LDBSAMBA
+################################################
+
+################################################
 # Start SUBSYSTEM LIBLDB_CMDLINE
 [SUBSYSTEM::LIBLDB_CMDLINE]
 OBJ_FILES= \
 		lib/ldb/tools/cmdline.o
-REQUIRED_SUBSYSTEMS = LIBLDB LIBCMDLINE LIBBASIC
+REQUIRED_SUBSYSTEMS = LIBLDB LIBCMDLINE LIBBASIC LDBSAMBA
 # End SUBSYSTEM LIBLDB_CMDLINE
 ################################################
 

Modified: branches/SAMBA_4_0/source/lib/ldb/include/ldb.h
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/include/ldb.h	2005-06-21 06:35:55 UTC (rev 7803)
+++ branches/SAMBA_4_0/source/lib/ldb/include/ldb.h	2005-06-21 07:52:00 UTC (rev 7804)
@@ -285,6 +285,9 @@
 int ldb_ldif_write_file(struct ldb_context *ldb, FILE *f, const struct ldb_ldif *msg);
 char *ldb_base64_encode(void *mem_ctx, const char *buf, int len);
 int ldb_base64_decode(char *s);
+int ldb_ldif_add_handlers(struct ldb_context *ldb, 
+			  const struct ldb_ldif_handler *handlers, 
+			  unsigned num_handlers);
 
 
 /* useful functions for ldb_message structure manipulation */

Added: branches/SAMBA_4_0/source/lib/ldb/samba/README
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/samba/README	2005-06-21 06:35:55 UTC (rev 7803)
+++ branches/SAMBA_4_0/source/lib/ldb/samba/README	2005-06-21 07:52:00 UTC (rev 7804)
@@ -0,0 +1,7 @@
+This directory contains Samba specific extensions to ldb. It also
+serves as example code on how to extend ldb for your own application.
+
+The main extension Samba uses is to provide ldif encode/decode
+routines for specific attributes, so users can get nice pretty
+printing of attributes in ldbedit, while the attributes are stored in
+the standard NDR format in the database.

Added: branches/SAMBA_4_0/source/lib/ldb/samba/ldif_handlers.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/samba/ldif_handlers.c	2005-06-21 06:35:55 UTC (rev 7803)
+++ branches/SAMBA_4_0/source/lib/ldb/samba/ldif_handlers.c	2005-06-21 07:52:00 UTC (rev 7804)
@@ -0,0 +1,95 @@
+/* 
+   ldb database library - ldif handlers for Samba
+
+   Copyright (C) Andrew Tridgell  2005
+
+     ** NOTE! The following LGPL license applies to the ldb
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
+   
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include "includes.h"
+#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_private.h"
+#include "librpc/gen_ndr/ndr_security.h"
+
+/*
+  convert a ldif formatted objectSid to a NDR formatted blob
+*/
+static int ldif_read_objectSid(struct ldb_context *ldb, const struct ldb_val *in,
+			       struct ldb_val *out)
+{
+	struct dom_sid *sid;
+	NTSTATUS status;
+	sid = dom_sid_parse_talloc(ldb, in->data);
+	if (sid == NULL) {
+		return -1;
+	}
+	status = ndr_push_struct_blob(out, ldb, sid, 
+				      (ndr_push_flags_fn_t)ndr_push_dom_sid);
+	talloc_free(sid);
+	if (!NT_STATUS_IS_OK(status)) {
+		return -1;
+	}
+	return 0;
+}
+
+/*
+  convert a NDR formatted blob to a ldif formatted objectSid
+*/
+static int ldif_write_objectSid(struct ldb_context *ldb, const struct ldb_val *in,
+			       struct ldb_val *out)
+{
+	struct dom_sid *sid;
+	NTSTATUS status;
+	sid = talloc(ldb, struct dom_sid);
+	if (sid == NULL) {
+		return -1;
+	}
+	status = ndr_pull_struct_blob(in, sid, sid, 
+				      (ndr_pull_flags_fn_t)ndr_pull_dom_sid);
+	if (!NT_STATUS_IS_OK(status)) {
+		talloc_free(sid);
+		return -1;
+	}
+	out->data = dom_sid_string(ldb, sid);
+	talloc_free(sid);
+	if (out->data == NULL) {
+		return -1;
+	}
+	out->length = strlen(out->data);
+	return 0;
+}
+
+
+static const struct ldb_ldif_handler samba_handlers[] = {
+	{ "objectSid", ldif_read_objectSid, ldif_write_objectSid }
+};
+
+/*
+  register the samba ldif handlers
+*/
+int ldb_register_samba_handlers(struct ldb_context *ldb)
+{
+#if 0
+	/* we can't enable this until we fix the sam code to handle
+	   non-string elements */
+	return ldb_ldif_add_handlers(ldb, samba_handlers, ARRAY_SIZE(samba_handlers));
+#else
+	return 0;
+#endif
+}

Modified: branches/SAMBA_4_0/source/lib/ldb/tools/cmdline.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/tools/cmdline.c	2005-06-21 06:35:55 UTC (rev 7803)
+++ branches/SAMBA_4_0/source/lib/ldb/tools/cmdline.c	2005-06-21 07:52:00 UTC (rev 7804)
@@ -36,9 +36,9 @@
 struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const char **argv,
 					void (*usage)(void))
 {
-	struct ldb_cmdline options, *ret;
+	struct ldb_cmdline options, *ret=NULL;
 	poptContext pc;
-	int num_options = 0;
+	int r, num_options = 0;
 	char opt;
 	struct poptOption popt_options[] = {
 		POPT_AUTOHELP
@@ -65,6 +65,10 @@
 
 #ifdef _SAMBA_BUILD_
 	ldbsearch_init_subsystems;
+	r = ldb_register_samba_handlers(ldb);
+	if (r != 0) {
+		goto failed;
+	}
 #endif
 
 	ret = talloc_zero(ldb, struct ldb_cmdline);



More information about the samba-cvs mailing list