summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/lib/ldb/common/ldb_ldif.c28
-rw-r--r--source4/lib/ldb/config.mk10
-rw-r--r--source4/lib/ldb/include/ldb.h3
-rw-r--r--source4/lib/ldb/samba/README7
-rw-r--r--source4/lib/ldb/samba/ldif_handlers.c95
-rw-r--r--source4/lib/ldb/tools/cmdline.c8
6 files changed, 146 insertions, 5 deletions
diff --git a/source4/lib/ldb/common/ldb_ldif.c b/source4/lib/ldb/common/ldb_ldif.c
index 88ef9fae45..94109ce224 100644
--- a/source4/lib/ldb/common/ldb_ldif.c
+++ b/source4/lib/ldb/common/ldb_ldif.c
@@ -41,6 +41,30 @@
#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
*/
@@ -59,7 +83,7 @@ static ldb_ldif_handler_t ldb_ldif_read_fn(struct ldb_context *ldb, const char *
{
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 @@ static ldb_ldif_handler_t ldb_ldif_write_fn(struct ldb_context *ldb, const char
{
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;
}
}
diff --git a/source4/lib/ldb/config.mk b/source4/lib/ldb/config.mk
index 9206ac1081..00568aeda8 100644
--- a/source4/lib/ldb/config.mk
+++ b/source4/lib/ldb/config.mk
@@ -91,11 +91,19 @@ REQUIRED_SUBSYSTEMS = \
################################################
################################################
+# 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
################################################
diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h
index 48290beb92..3102676327 100644
--- a/source4/lib/ldb/include/ldb.h
+++ b/source4/lib/ldb/include/ldb.h
@@ -285,6 +285,9 @@ struct ldb_ldif *ldb_ldif_read_string(struct ldb_context *ldb, const char *s);
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 */
diff --git a/source4/lib/ldb/samba/README b/source4/lib/ldb/samba/README
new file mode 100644
index 0000000000..3fa47159ca
--- /dev/null
+++ b/source4/lib/ldb/samba/README
@@ -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.
diff --git a/source4/lib/ldb/samba/ldif_handlers.c b/source4/lib/ldb/samba/ldif_handlers.c
new file mode 100644
index 0000000000..7252d081f1
--- /dev/null
+++ b/source4/lib/ldb/samba/ldif_handlers.c
@@ -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
+}
diff --git a/source4/lib/ldb/tools/cmdline.c b/source4/lib/ldb/tools/cmdline.c
index 1f4a7544a5..31d3f2662a 100644
--- a/source4/lib/ldb/tools/cmdline.c
+++ b/source4/lib/ldb/tools/cmdline.c
@@ -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 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const
#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);