diff options
233 files changed, 26 insertions, 68826 deletions
@@ -2,6 +2,20 @@ Very Quick Guide to build sssd components ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Use the following instructions to build the libraries and the binaries. + +sssd depends on 4 libraries originated in the samba project: +talloc, tdb, tevent, ldb + +They are now available in major distribution development branches. + +If you have these libraries installed skip to <<Compiling sssd with system +installed libraries>> + +If you want to build them from source download the latest samba master branch +and use the following instructions + +Compiling libraries yourself +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ NOTE: these instructions are temporary and will most likely change agt some point but so far the process I describe here is the best one to get something up and working while developing this project. @@ -17,10 +31,13 @@ its finally system library directory (ie build as user). I use the following steps to build all pieces. export LD_LIBRARY_PATH=/tmp/foo/lib -pushd talloc; ./autogen.sh && ./configure --with-shared-build-dir=/tmp/foo && make shared-build; popd -pushd tdb; ./autogen.sh && ./configure --with-shared-build-dir=/tmp/foo && make shared-build; popd -pushd tevent; ./autogen.sh && ./configure --with-shared-build-dir=/tmp/foo && make shared-build; popd -pushd ldb; ./autogen.sh && ./configure --with-shared-build-dir=/tmp/foo && make shared-build; popd +pushd lib/talloc; ./autogen.sh && ./configure --with-shared-build-dir=/tmp/foo && make shared-build; popd +pushd lib/tdb; ./autogen.sh && ./configure --with-shared-build-dir=/tmp/foo && make shared-build; popd +pushd lib/tevent; ./autogen.sh && ./configure --with-shared-build-dir=/tmp/foo && make shared-build; popd +pushd source4/lib/ldb; ./autogen.sh && ./configure --with-shared-build-dir=/tmp/foo && make shared-build; popd + +Compiling sssd using shared-build +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ pushd server; ./autogen.sh && ./configure --with-shared-build-dir=/tmp/foo && make; popd At this point you can start testing the sssd daemon this way: @@ -31,7 +48,12 @@ export LD_LIBRARY_PATH=/tmp/foo/lib This will start the sssd daemon in interactive mode. +Compiling sssd with system installed libraries +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +pushd server; ./autogen.sh && ./configure && make; popd +Compiling client libraries +~~~~~~~~~~~~~~~~~~~~~~~~~~ The nss and pam client doesn't need any dependency nor supports the shared-build option. diff --git a/ldb/Doxyfile b/ldb/Doxyfile deleted file mode 100644 index 07b12b516..000000000 --- a/ldb/Doxyfile +++ /dev/null @@ -1,26 +0,0 @@ -PROJECT_NAME = LDB -OUTPUT_DIRECTORY = apidocs -REPEAT_BRIEF = YES -OPTIMIZE_OUTPUT_FOR_C = YES -SORT_MEMBER_DOCS = YES -SORT_BRIEF_DOCS = NO -GENERATE_TODOLIST = YES -GENERATE_BUGLIST = YES -GENERATE_DEPRECATEDLIST= YES -SHOW_USED_FILES = NO -SHOW_DIRECTORIES = NO -WARNINGS = YES -WARN_IF_UNDOCUMENTED = YES -WARN_IF_DOC_ERROR = YES -WARN_NO_PARAMDOC = NO -WARN_FORMAT = "$file:$line: $text" -INPUT = include . -FILE_PATTERNS = *.h *.dox -EXCLUDE = include/config.h include/dlinklist.h \ - include/includes.h -EXAMPLE_PATH = examples -GENERATE_HTML = YES -HTML_OUTPUT = html -GENERATE_MAN = YES -ALWAYS_DETAILED_SEC = YES -JAVADOC_AUTOBRIEF = YES diff --git a/ldb/Makefile.in b/ldb/Makefile.in deleted file mode 100644 index c8724df3a..000000000 --- a/ldb/Makefile.in +++ /dev/null @@ -1,186 +0,0 @@ -#!gmake -# -CC = @CC@ -GCOV = @GCOV@ -XSLTPROC = @XSLTPROC@ -DOXYGEN = @DOXYGEN@ -prefix = @prefix@ -exec_prefix = @exec_prefix@ -datarootdir = @datarootdir@ -includedir = @includedir@ -libdir = @libdir@ -bindir = @bindir@ -mandir = @mandir@ -VPATH = @srcdir@:@libreplacedir@ -srcdir = @srcdir@ -builddir = @builddir@ -sharedbuilddir = @sharedbuilddir@ -INSTALLCMD = @INSTALL@ -SLAPD = @SLAPD@ -EXTRA_OBJ=@EXTRA_OBJ@ -TESTS=test-tdb.sh @TESTS@ -PACKAGE_VERSION = @PACKAGE_VERSION@ -PYTHON = @PYTHON@ -PYTHON_CONFIG = @PYTHON_CONFIG@ -ldbdir = $(srcdir) - -LDB_MODULESDIR = @LDB_MODULESDIR@ - -TALLOC_LIBS = @TALLOC_LIBS@ -TALLOC_CFLAGS = @TALLOC_CFLAGS@ -TALLOC_OBJ = @TALLOC_OBJ@ - -TDB_LIBS = @TDB_LIBS@ -TDB_CFLAGS = @TDB_CFLAGS@ -TDB_OBJ = @TDB_OBJ@ - -EVENTS_LIBS = @EVENTS_LIBS@ -EVENTS_CFLAGS = @EVENTS_CFLAGS@ -EVENTS_OBJ = @EVENTS_OBJ@ - -POPT_LIBS = @POPT_LIBS@ -POPT_CFLAGS = @POPT_CFLAGS@ -POPT_OBJ = @POPT_OBJ@ - -LDAP_LIBS = @LDAP_LIBS@ - -LIBDL = @LIBDL@ - -SHLIBEXT = @SHLIBEXT@ - -LD_EXPORT_DYNAMIC = @LD_EXPORT_DYNAMIC@ -SHLD = @SHLD@ -SHLD_FLAGS = @SHLD_FLAGS@ - -LDFLAGS += @LDFLAGS@ -LIBS = @LIBS@ - -PICFLAG = @PICFLAG@ -CFLAGS += -I$(srcdir)/include -Iinclude -I$(srcdir) -I$(srcdir)/.. \ - $(POPT_CFLAGS) $(TALLOC_CFLAGS) $(TDB_CFLAGS) $(EVENTS_CFLAGS) \ - -DLIBDIR=\"$(libdir)\" -DSHLIBEXT=\"$(SHLIBEXT)\" -DUSE_MMAP=1 \ - -DLDB_MODULESDIR=\"$(LDB_MODULESDIR)\" \ - @CFLAGS@ - -MDLD = @MDLD@ -MDLD_FLAGS = @MDLD_FLAGS@ - -OBJS = $(MODULES_OBJ) $(COMMON_OBJ) $(LDB_TDB_OBJ) $(TDB_OBJ) $(EVENTS_OBJ) $(TALLOC_OBJ) $(POPT_OBJ) $(LDB_MAP_OBJ) @LIBREPLACEOBJ@ $(EXTRA_OBJ) - -headers = $(srcdir)/include/ldb.h $(srcdir)/include/ldb_errors.h $(srcdir)/include/ldb_handlers.h - -BINS = bin/ldbadd bin/ldbsearch bin/ldbdel bin/ldbmodify bin/ldbedit bin/ldbrename bin/ldbtest - -EXAMPLES = examples/ldbreader examples/ldifreader - -DIRS = lib bin common ldb_tdb ldb_ldap ldb_sqlite3 modules tools examples - -default: all - -include $(ldbdir)/rules.mk - -nss: nssdir all $(NSS_LIB) - -nssdir: - @mkdir -p $(NSSDIR) - -SONAME = libldb.$(SHLIBEXT).0 -SOLIB = libldb.$(SHLIBEXT).$(PACKAGE_VERSION) -LIBSOLIB = lib/$(SOLIB) -STATICLIB = lib/libldb.a - -lib/$(SONAME): $(LIBSOLIB) - ln -fs libldb.$(SHLIBEXT).$(PACKAGE_VERSION) $@ - -lib/libldb.$(SHLIBEXT): $(LIBSOLIB) - ln -fs libldb.$(SHLIBEXT).$(PACKAGE_VERSION) $@ - -lib/libnss_ldb.$(SHLIBEXT).2: $(NSS_OBJ) $(LIBSOLIB) - $(SHLD) $(SHLD_FLAGS) -o $@ $(NSS_OBJ) $(LDFLAGS) $(LIBSOLIB) @SONAMEFLAG@libnss_ldb.$(SHLIBEXT).2 - -$(LIBSOLIB): $(OBJS) - $(SHLD) $(SHLD_FLAGS) -o $@ $(OBJS) $(LDFLAGS) $(LIBS) $(TALLOC_LIBS) $(TDB_LIBS) $(EVENTS_LIBS) $(LIBDL) $(LDAP_LIBS) @SONAMEFLAG@$(SONAME) - ln -sf libldb.$(SHLIBEXT).$(PACKAGE_VERSION) lib/libldb.$(SHLIBEXT) - -all: showflags dirs $(OBJS) $(STATICLIB) $(LIBSOLIB) $(BINS) $(EXAMPLES) manpages \ - @PYTHON_BUILD_TARGET@ - -shared-build: all - ${INSTALLCMD} -d $(sharedbuilddir)/lib - ${INSTALLCMD} -m 644 $(STATICLIB) $(sharedbuilddir)/lib - ${INSTALLCMD} -m 755 $(LIBSOLIB) $(sharedbuilddir)/lib - ln -sf $(SOLIB) $(sharedbuilddir)/lib/$(SONAME) - ln -sf $(SOLIB) $(sharedbuilddir)/lib/libldb.so - ${INSTALLCMD} -d $(sharedbuilddir)/include - ${INSTALLCMD} -m 644 $(srcdir)/include/ldb.h $(sharedbuilddir)/include - ${INSTALLCMD} -m 644 $(srcdir)/include/ldb_errors.h $(sharedbuilddir)/include - ${INSTALLCMD} -m 644 $(srcdir)/include/ldb_handlers.h $(sharedbuilddir)/include - -dirs: - @mkdir -p $(DIRS) - -manpages:: - @$(srcdir)/docs/builddocs.sh "$(XSLTPROC)" "$(srcdir)" - -doxygen:: - test -z "$(DOXYGEN)" || (cd $(srcdir) && "$(DOXYGEN)") - -clean:: - rm -f *.o */*.o *.gcov */*.gc?? tdbtest.ldb* - rm -f $(BINS) $(TDB_OBJ) $(TALLOC_OBJ) $(STATICLIB) $(NSS_LIB) $(LIBSOLIB) - rm -f $(POPT_OBJ) - rm -f man/*.1 man/*.3 man/*.html - rm -f $(EXAMPLES) - rm -rf apidocs/ - rm -rf tests/schema/ - -distclean:: clean - rm -rf bin lib - rm -f config.log config.status config.cache include/config.h - rm -f ldb.pc - rm -f Makefile - -realdistclean:: distclean - rm -f configure include/config.h.in - -check:: test @PYTHON_CHECK_TARGET@ - -check-soloading: sample.$(SHLIBEXT) - LDB_MODULES_PATH=$(builddir) $(srcdir)/tests/test-soloading.sh - -test:: all check-soloading - for t in $(TESTS); do echo STARTING $${t}; $(srcdir)/tests/$${t} || exit 1; done - -valgrindtest:: all - for t in $(TESTS); do echo STARTING $${t}; VALGRIND="valgrind -q --db-attach=yes --num-callers=30" $(srcdir)/tests/$${t} || exit 1; done - -installcheck:: install test - -install:: all installdirs installheaders installlibs installbin installdocs \ - @PYTHON_INSTALL_TARGET@ - -installdirs:: - mkdir -p $(DESTDIR)$(includedir) $(DESTDIR)$(libdir) $(DESTDIR)$(bindir) $(DESTDIR)$(libdir)/pkgconfig - -installheaders:: installdirs - cp $(headers) $(DESTDIR)$(includedir) - -installlibs:: installdirs - cp $(STATICLIB) $(LIBSOLIB) $(DESTDIR)$(libdir) - cp ldb.pc $(DESTDIR)$(libdir)/pkgconfig - -installbin:: installdirs - cp $(BINS) $(DESTDIR)$(bindir) - -installdocs:: installdirs - $(srcdir)/docs/installdocs.sh $(DESTDIR)$(mandir) - -gcov:: - $(GCOV) -po ldb_sqlite3 $(srcdir)/ldb_sqlite3/*.c 2| tee ldb_sqlite3.report.gcov - $(GCOV) -po ldb_ldap $(srcdir)/ldb_ldap/*.c 2| tee ldb_ldap.report.gcov - $(GCOV) -po ldb_tdb $(srcdir)/ldb_tdb/*.c 2| tee ldb_tdb.report.gcov - $(GCOV) -po common $(srcdir)/common/*.c 2| tee common.report.gcov - $(GCOV) -po modules $(srcdir)/modules/*.c 2| tee modules.report.gcov - $(GCOV) -po tools $(srcdir)/tools/*.c 2| tee tools.report.gcov - -include $(ldbdir)/ldb.mk diff --git a/ldb/README_gcov.txt b/ldb/README_gcov.txt deleted file mode 100644 index 2abd9378f..000000000 --- a/ldb/README_gcov.txt +++ /dev/null @@ -1,29 +0,0 @@ -Here is how to use gcov to test code coverage in ldb. - -Step 1: build ldb with gcov enabled - - make clean all WITH_GCOV=1 - -Step 3: run the test suite - make test-tdb - -Step 4: produce the gcov report - make gcov - -Step 5: read the summary reports - less *.report.gcov - -Step 6: examine the per-file reports - less ldb_tdb\#ldb_tdb.c.gcov - -You can also combine steps 2 to 4 like this: - - make clean all test-tdb gcov WITH_GCOV=1 - -Note that you should not expect 100% coverage, as some error paths -(such as memory allocation failures) are very hard to trigger. There -are ways of working around this, but they are quite tricky (they -involve allocation wrappers that "fork and fail on malloc"). - -The lines to look for in the per-file reports are the ones starting -with "#####". Those are lines that are never executed. diff --git a/ldb/aclocal.m4 b/ldb/aclocal.m4 deleted file mode 100644 index 5605e476b..000000000 --- a/ldb/aclocal.m4 +++ /dev/null @@ -1 +0,0 @@ -m4_include(libreplace.m4) diff --git a/ldb/autogen.sh b/ldb/autogen.sh deleted file mode 100755 index e4d367dc1..000000000 --- a/ldb/autogen.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -rm -rf autom4te.cache -rm -f configure config.h.in - -IPATHS="-I libreplace -I lib/replace -I ../libreplace -I ../replace -I ../../../lib/replace" -IPATHS="$IPATHS -I ./external" - -autoheader $IPATHS || exit 1 -autoconf $IPATHS || exit 1 - -rm -rf autom4te.cache - -echo "Now run ./configure and then make." -exit 0 - diff --git a/ldb/build_macros.m4 b/ldb/build_macros.m4 deleted file mode 100644 index c036668cd..000000000 --- a/ldb/build_macros.m4 +++ /dev/null @@ -1,14 +0,0 @@ -AC_DEFUN(BUILD_WITH_SHARED_BUILD_DIR, - [ AC_ARG_WITH([shared-build-dir], - [AC_HELP_STRING([--with-shared-build-dir=DIR], - [temporary build directory where libraries are installed [$srcdir/sharedbuild]])]) - - sharedbuilddir="$srcdir/sharedbuild" - if test x"$with_shared_build_dir" != x; then - sharedbuilddir=$with_shared_build_dir - CFLAGS="$CFLAGS -I$with_shared_build_dir/include" - LDFLAGS="$LDFLAGS -L$with_shared_build_dir/lib" - fi - AC_SUBST(sharedbuilddir) - ]) - diff --git a/ldb/common/attrib_handlers.c b/ldb/common/attrib_handlers.c deleted file mode 100644 index 5ec86b5b8..000000000 --- a/ldb/common/attrib_handlers.c +++ /dev/null @@ -1,378 +0,0 @@ -/* - ldb database library - - 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 3 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, see <http://www.gnu.org/licenses/>. -*/ -/* - attribute handlers for well known attribute types, selected by syntax OID - see rfc2252 -*/ - -#include "ldb_includes.h" -#include "system/locale.h" -#include "ldb_handlers.h" - -/* - default handler that just copies a ldb_val. -*/ -int ldb_handler_copy(struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *in, struct ldb_val *out) -{ - *out = ldb_val_dup(mem_ctx, in); - if (in->length > 0 && out->data == NULL) { - ldb_oom(ldb); - return -1; - } - return 0; -} - -/* - a case folding copy handler, removing leading and trailing spaces and - multiple internal spaces - - We exploit the fact that utf8 never uses the space octet except for - the space itself -*/ -int ldb_handler_fold(struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *in, struct ldb_val *out) -{ - char *s, *t; - int l; - - if (!in || !out || !(in->data)) { - return -1; - } - - out->data = (uint8_t *)ldb_casefold(ldb, mem_ctx, (const char *)(in->data), in->length); - if (out->data == NULL) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb_handler_fold: unable to casefold string [%s]", in->data); - return -1; - } - - s = (char *)(out->data); - - /* remove trailing spaces if any */ - l = strlen(s); - while (l > 0 && s[l - 1] == ' ') l--; - s[l] = '\0'; - - /* remove leading spaces if any */ - if (*s == ' ') { - for (t = s; *s == ' '; s++) ; - - /* remove leading spaces by moving down the string */ - memmove(t, s, l); - - s = t; - } - - /* check middle spaces */ - while ((t = strchr(s, ' ')) != NULL) { - for (s = t; *s == ' '; s++) ; - - if ((s - t) > 1) { - l = strlen(s); - - /* remove all spaces but one by moving down the string */ - memmove(t + 1, s, l); - } - } - - out->length = strlen((char *)out->data); - return 0; -} - - - -/* - canonicalise a ldap Integer - rfc2252 specifies it should be in decimal form -*/ -int ldb_canonicalise_Integer(struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *in, struct ldb_val *out) -{ - char *end; - long long i = strtoll((char *)in->data, &end, 0); - if (*end != 0) { - return -1; - } - out->data = (uint8_t *)talloc_asprintf(mem_ctx, "%lld", i); - if (out->data == NULL) { - return -1; - } - out->length = strlen((char *)out->data); - return 0; -} - -/* - compare two Integers -*/ -int ldb_comparison_Integer(struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *v1, const struct ldb_val *v2) -{ - return strtoll((char *)v1->data, NULL, 0) - strtoll((char *)v2->data, NULL, 0); -} - -/* - compare two binary blobs -*/ -int ldb_comparison_binary(struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *v1, const struct ldb_val *v2) -{ - if (v1->length != v2->length) { - return v1->length - v2->length; - } - return memcmp(v1->data, v2->data, v1->length); -} - -/* - compare two case insensitive strings, ignoring multiple whitespaces - and leading and trailing whitespaces - see rfc2252 section 8.1 - - try to optimize for the ascii case, - but if we find out an utf8 codepoint revert to slower but correct function -*/ -int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *v1, const struct ldb_val *v2) -{ - const char *s1=(const char *)v1->data, *s2=(const char *)v2->data; - size_t n1 = v1->length, n2 = v2->length; - const char *u1, *u2; - char *b1, *b2; - int ret; - while (*s1 == ' ' && n1) { s1++; n1--; }; - while (*s2 == ' ' && n2) { s2++; n2--; }; - /* TODO: make utf8 safe, possibly with helper function from application */ - while (*s1 && *s2 && n1 && n2) { - /* the first 127 (0x7F) chars are ascii and utf8 guarantes they - * never appear in multibyte sequences */ - if (((unsigned char)s1[0]) & 0x80) goto utf8str; - if (((unsigned char)s2[0]) & 0x80) goto utf8str; - if (toupper((unsigned char)*s1) != toupper((unsigned char)*s2)) - break; - if (*s1 == ' ') { - while (s1[0] == s1[1] && n1) { s1++; n1--; } - while (s2[0] == s2[1] && n2) { s2++; n2--; } - } - s1++; s2++; - n1--; n2--; - } - if (! (*s1 && *s2)) { - /* check for trailing spaces only if one of the pointers - * has reached the end of the strings otherwise we - * can mistakenly match. - * ex. "domain users" <-> "domainUpdates" - */ - while (*s1 == ' ') { s1++; n1--; } - while (*s2 == ' ') { s2++; n2--; } - } - if (n1 != n2) { - return n1 - n2; - } - return (int)(toupper(*s1)) - (int)(toupper(*s2)); - -utf8str: - /* no need to recheck from the start, just from the first utf8 char found */ - b1 = ldb_casefold(ldb, mem_ctx, s1, n1); - b2 = ldb_casefold(ldb, mem_ctx, s2, n2); - - if (b1 && b2) { - /* Both strings converted correctly */ - - u1 = b1; - u2 = b2; - } else { - /* One of the strings was not UTF8, so we have no options but to do a binary compare */ - - u1 = s1; - u2 = s2; - } - - while (*u1 & *u2) { - if (*u1 != *u2) - break; - if (*u1 == ' ') { - while (u1[0] == u1[1]) u1++; - while (u2[0] == u2[1]) u2++; - } - u1++; u2++; - } - if (! (*u1 && *u2)) { - while (*u1 == ' ') u1++; - while (*u2 == ' ') u2++; - } - ret = (int)(*u1 - *u2); - - talloc_free(b1); - talloc_free(b2); - - return ret; -} - - -/* - canonicalise a attribute in DN format -*/ -int ldb_canonicalise_dn(struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *in, struct ldb_val *out) -{ - struct ldb_dn *dn; - int ret = -1; - - out->length = 0; - out->data = NULL; - - dn = ldb_dn_from_ldb_val(ldb, mem_ctx, in); - if ( ! ldb_dn_validate(dn)) { - return LDB_ERR_INVALID_DN_SYNTAX; - } - - out->data = (uint8_t *)ldb_dn_alloc_casefold(mem_ctx, dn); - if (out->data == NULL) { - goto done; - } - out->length = strlen((char *)out->data); - - ret = 0; - -done: - talloc_free(dn); - - return ret; -} - -/* - compare two dns -*/ -int ldb_comparison_dn(struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *v1, const struct ldb_val *v2) -{ - struct ldb_dn *dn1 = NULL, *dn2 = NULL; - int ret; - - dn1 = ldb_dn_from_ldb_val(ldb, mem_ctx, v1); - if ( ! ldb_dn_validate(dn1)) return -1; - - dn2 = ldb_dn_from_ldb_val(ldb, mem_ctx, v2); - if ( ! ldb_dn_validate(dn2)) { - talloc_free(dn1); - return -1; - } - - ret = ldb_dn_compare(dn1, dn2); - - talloc_free(dn1); - talloc_free(dn2); - return ret; -} - -/* - compare two utc time values. 1 second resolution -*/ -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); - t2 = ldb_string_to_time((char *)v2->data); - return (int)t2 - (int)t1; -} - -/* - canonicalise a utc time -*/ -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_schema_syntax ldb_standard_syntaxes[] = { - { - .name = LDB_SYNTAX_INTEGER, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_canonicalise_Integer, - .comparison_fn = ldb_comparison_Integer - }, - { - .name = LDB_SYNTAX_OCTET_STRING, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_handler_copy, - .comparison_fn = ldb_comparison_binary - }, - { - .name = LDB_SYNTAX_DIRECTORY_STRING, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_handler_fold, - .comparison_fn = ldb_comparison_fold - }, - { - .name = LDB_SYNTAX_DN, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_canonicalise_dn, - .comparison_fn = ldb_comparison_dn - }, - { - .name = LDB_SYNTAX_OBJECTCLASS, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_handler_fold, - .comparison_fn = ldb_comparison_fold - }, - { - .name = LDB_SYNTAX_UTC_TIME, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_canonicalise_utctime, - .comparison_fn = ldb_comparison_utctime - } -}; - - -/* - return the attribute handlers for a given syntax name -*/ -const struct ldb_schema_syntax *ldb_standard_syntax_by_name(struct ldb_context *ldb, - const char *syntax) -{ - int i; - unsigned num_handlers = sizeof(ldb_standard_syntaxes)/sizeof(ldb_standard_syntaxes[0]); - /* TODO: should be replaced with a binary search */ - for (i=0;i<num_handlers;i++) { - if (strcmp(ldb_standard_syntaxes[i].name, syntax) == 0) { - return &ldb_standard_syntaxes[i]; - } - } - return NULL; -} diff --git a/ldb/common/ldb.c b/ldb/common/ldb.c deleted file mode 100644 index c013565da..000000000 --- a/ldb/common/ldb.c +++ /dev/null @@ -1,1359 +0,0 @@ -/* - ldb database library - - Copyright (C) Andrew Tridgell 2004 - Copyright (C) Simo Sorce 2005-2008 - - ** 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -/* - * Name: ldb - * - * Component: ldb core API - * - * Description: core API routines interfacing to ldb backends - * - * Author: Andrew Tridgell - */ - -#include "ldb_includes.h" - -/* - initialise a ldb context - The mem_ctx is required - The event_ctx is required -*/ -struct ldb_context *ldb_init(TALLOC_CTX *mem_ctx, struct event_context *ev_ctx) -{ - struct ldb_context *ldb; - int ret; - - ldb = talloc_zero(mem_ctx, struct ldb_context); - /* FIXME: Hack a new event context so that CMD line utilities work - * until we have them all converted */ - if (ev_ctx == NULL) { - ev_ctx = event_context_init(talloc_autofree_context()); - } - - ret = ldb_setup_wellknown_attributes(ldb); - if (ret != 0) { - talloc_free(ldb); - return NULL; - } - - ldb_set_utf8_default(ldb); - ldb_set_create_perms(ldb, 0666); - ldb_set_modules_dir(ldb, LDB_MODULESDIR); - ldb_set_event_context(ldb, ev_ctx); - - /* TODO: get timeout from options if available there */ - ldb->default_timeout = 300; /* set default to 5 minutes */ - - return ldb; -} - -/* - try to autodetect a basedn if none specified. This fixes one of my - pet hates about ldapsearch, which is that you have to get a long, - complex basedn right to make any use of it. -*/ -void ldb_set_default_dns(struct ldb_context *ldb) -{ - TALLOC_CTX *tmp_ctx; - int ret; - struct ldb_result *res; - struct ldb_dn *tmp_dn=NULL; - static const char *attrs[] = { - "rootDomainNamingContext", - "configurationNamingContext", - "schemaNamingContext", - "defaultNamingContext", - NULL - }; - - tmp_ctx = talloc_new(ldb); - ret = ldb_search(ldb, tmp_ctx, &res, ldb_dn_new(tmp_ctx, ldb, NULL), - LDB_SCOPE_BASE, attrs, "(objectClass=*)"); - if (ret != LDB_SUCCESS) { - talloc_free(tmp_ctx); - return; - } - - if (res->count != 1) { - talloc_free(tmp_ctx); - return; - } - - if (!ldb_get_opaque(ldb, "rootDomainNamingContext")) { - tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0], - "rootDomainNamingContext"); - ldb_set_opaque(ldb, "rootDomainNamingContext", tmp_dn); - } - - if (!ldb_get_opaque(ldb, "configurationNamingContext")) { - tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0], - "configurationNamingContext"); - ldb_set_opaque(ldb, "configurationNamingContext", tmp_dn); - } - - if (!ldb_get_opaque(ldb, "schemaNamingContext")) { - tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0], - "schemaNamingContext"); - ldb_set_opaque(ldb, "schemaNamingContext", tmp_dn); - } - - if (!ldb_get_opaque(ldb, "defaultNamingContext")) { - tmp_dn = ldb_msg_find_attr_as_dn(ldb, ldb, res->msgs[0], - "defaultNamingContext"); - ldb_set_opaque(ldb, "defaultNamingContext", tmp_dn); - } - - talloc_free(tmp_ctx); -} - -struct ldb_dn *ldb_get_root_basedn(struct ldb_context *ldb) -{ - void *opaque = ldb_get_opaque(ldb, "rootDomainNamingContext"); - return talloc_get_type(opaque, struct ldb_dn); -} - -struct ldb_dn *ldb_get_config_basedn(struct ldb_context *ldb) -{ - void *opaque = ldb_get_opaque(ldb, "configurationNamingContext"); - return talloc_get_type(opaque, struct ldb_dn); -} - -struct ldb_dn *ldb_get_schema_basedn(struct ldb_context *ldb) -{ - void *opaque = ldb_get_opaque(ldb, "schemaNamingContext"); - return talloc_get_type(opaque, struct ldb_dn); -} - -struct ldb_dn *ldb_get_default_basedn(struct ldb_context *ldb) -{ - void *opaque = ldb_get_opaque(ldb, "defaultNamingContext"); - return talloc_get_type(opaque, struct ldb_dn); -} - -/* - connect to a database. The URL can either be one of the following forms - ldb://path - ldapi://path - - flags is made up of LDB_FLG_* - - the options are passed uninterpreted to the backend, and are - backend specific -*/ -int ldb_connect(struct ldb_context *ldb, const char *url, - unsigned int flags, const char *options[]) -{ - int ret; - const char *url2; - /* We seem to need to do this here, or else some utilities don't - * get ldb backends */ - - ldb->flags = flags; - - url2 = talloc_strdup(ldb, url); - if (!url2) { - ldb_oom(ldb); - return LDB_ERR_OPERATIONS_ERROR; - } - ret = ldb_set_opaque(ldb, "ldb_url", talloc_strdup(ldb, url2)); - if (ret != LDB_SUCCESS) { - return ret; - } - - ret = ldb_connect_backend(ldb, url, options, &ldb->modules); - if (ret != LDB_SUCCESS) { - return ret; - } - - if (ldb_load_modules(ldb, options) != LDB_SUCCESS) { - ldb_debug(ldb, LDB_DEBUG_FATAL, - "Unable to load modules for %s: %s\n", - url, ldb_errstring(ldb)); - return LDB_ERR_OTHER; - } - - /* set the default base dn */ - ldb_set_default_dns(ldb); - - return LDB_SUCCESS; -} - -void ldb_set_errstring(struct ldb_context *ldb, const char *err_string) -{ - if (ldb->err_string) { - talloc_free(ldb->err_string); - } - ldb->err_string = talloc_strdup(ldb, err_string); -} - -void ldb_asprintf_errstring(struct ldb_context *ldb, const char *format, ...) -{ - va_list ap; - char *old_string = NULL; - - if (ldb->err_string) { - old_string = ldb->err_string; - } - - va_start(ap, format); - ldb->err_string = talloc_vasprintf(ldb, format, ap); - va_end(ap); - talloc_free(old_string); -} - -void ldb_reset_err_string(struct ldb_context *ldb) -{ - if (ldb->err_string) { - talloc_free(ldb->err_string); - ldb->err_string = NULL; - } -} - -#define FIRST_OP(ldb, op) do { \ - module = ldb->modules; \ - while (module && module->ops->op == NULL) module = module->next; \ - if (module == NULL) { \ - ldb_asprintf_errstring(ldb, "unable to find module or backend to handle operation: " #op); \ - return LDB_ERR_OPERATIONS_ERROR; \ - } \ -} while (0) - -/* - start a transaction -*/ -static int ldb_transaction_start_internal(struct ldb_context *ldb) -{ - struct ldb_module *module; - int status; - FIRST_OP(ldb, start_transaction); - - ldb_reset_err_string(ldb); - - status = module->ops->start_transaction(module); - if (status != LDB_SUCCESS) { - if (ldb->err_string == NULL) { - /* no error string was setup by the backend */ - ldb_asprintf_errstring(ldb, - "ldb transaction start: %s (%d)", - ldb_strerror(status), - status); - } - } - return status; -} - -/* - commit a transaction -*/ -static int ldb_transaction_commit_internal(struct ldb_context *ldb) -{ - struct ldb_module *module; - int status; - FIRST_OP(ldb, end_transaction); - - ldb_reset_err_string(ldb); - - status = module->ops->end_transaction(module); - if (status != LDB_SUCCESS) { - if (ldb->err_string == NULL) { - /* no error string was setup by the backend */ - ldb_asprintf_errstring(ldb, - "ldb transaction commit: %s (%d)", - ldb_strerror(status), - status); - } - } - return status; -} - -/* - cancel a transaction -*/ -static int ldb_transaction_cancel_internal(struct ldb_context *ldb) -{ - struct ldb_module *module; - int status; - FIRST_OP(ldb, del_transaction); - - status = module->ops->del_transaction(module); - if (status != LDB_SUCCESS) { - if (ldb->err_string == NULL) { - /* no error string was setup by the backend */ - ldb_asprintf_errstring(ldb, - "ldb transaction cancel: %s (%d)", - ldb_strerror(status), - status); - } - } - return status; -} - -int ldb_transaction_start(struct ldb_context *ldb) -{ - /* disable autotransactions */ - ldb->transaction_active++; - - return ldb_transaction_start_internal(ldb); -} - -int ldb_transaction_commit(struct ldb_context *ldb) -{ - /* renable autotransactions (when we reach 0) */ - if (ldb->transaction_active > 0) - ldb->transaction_active--; - - return ldb_transaction_commit_internal(ldb); -} - -int ldb_transaction_cancel(struct ldb_context *ldb) -{ - /* renable autotransactions (when we reach 0) */ - if (ldb->transaction_active > 0) - ldb->transaction_active--; - - return ldb_transaction_cancel_internal(ldb); -} - -static int ldb_autotransaction_start(struct ldb_context *ldb) -{ - /* explicit transaction active, ignore autotransaction request */ - if (ldb->transaction_active) - return LDB_SUCCESS; - - return ldb_transaction_start_internal(ldb); -} - -static int ldb_autotransaction_commit(struct ldb_context *ldb) -{ - /* explicit transaction active, ignore autotransaction request */ - if (ldb->transaction_active) - return LDB_SUCCESS; - - return ldb_transaction_commit_internal(ldb); -} - -static int ldb_autotransaction_cancel(struct ldb_context *ldb) -{ - /* explicit transaction active, ignore autotransaction request */ - if (ldb->transaction_active) - return LDB_SUCCESS; - - return ldb_transaction_cancel_internal(ldb); -} - -/* autostarts a transacion if none active */ -static int ldb_autotransaction_request(struct ldb_context *ldb, - struct ldb_request *req) -{ - int ret; - - ret = ldb_autotransaction_start(ldb); - if (ret != LDB_SUCCESS) { - return ret; - } - - ret = ldb_request(ldb, req); - if (ret == LDB_SUCCESS) { - ret = ldb_wait(req->handle, LDB_WAIT_ALL); - } - - if (ret == LDB_SUCCESS) { - return ldb_autotransaction_commit(ldb); - } - ldb_autotransaction_cancel(ldb); - - if (ldb->err_string == NULL) { - /* no error string was setup by the backend */ - ldb_asprintf_errstring(ldb, "%s (%d)", ldb_strerror(ret), ret); - } - - return ret; -} - -int ldb_wait(struct ldb_handle *handle, enum ldb_wait_type type) -{ - struct event_context *ev; - - if (!handle) { - return LDB_ERR_UNAVAILABLE; - } - - if (handle->state == LDB_ASYNC_DONE) { - return handle->status; - } - - ev = ldb_get_event_context(handle->ldb); - if (NULL == ev) { - return LDB_ERR_OPERATIONS_ERROR; - } - - switch (type) { - case LDB_WAIT_NONE: - event_loop_once(ev); - if (handle->state == LDB_ASYNC_DONE || - handle->status != LDB_SUCCESS) { - return handle->status; - } - break; - - case LDB_WAIT_ALL: - while (handle->state != LDB_ASYNC_DONE) { - event_loop_once(ev); - if (handle->status != LDB_SUCCESS) { - return handle->status; - } - } - return handle->status; - } - - return LDB_SUCCESS; -} - -/* set the specified timeout or, if timeout is 0 set the default timeout */ -int ldb_set_timeout(struct ldb_context *ldb, - struct ldb_request *req, - int timeout) -{ - if (req == NULL) return LDB_ERR_OPERATIONS_ERROR; - - if (timeout != 0) { - req->timeout = timeout; - } else { - req->timeout = ldb->default_timeout; - } - req->starttime = time(NULL); - - return LDB_SUCCESS; -} - -/* calculates the new timeout based on the previous starttime and timeout */ -int ldb_set_timeout_from_prev_req(struct ldb_context *ldb, - struct ldb_request *oldreq, - struct ldb_request *newreq) -{ - if (newreq == NULL) return LDB_ERR_OPERATIONS_ERROR; - - if (oldreq == NULL) { - return ldb_set_timeout(ldb, newreq, 0); - } - - newreq->starttime = oldreq->starttime; - newreq->timeout = oldreq->timeout; - - return LDB_SUCCESS; -} - - -/* - set the permissions for new files to be passed to open() in - backends that use local files - */ -void ldb_set_create_perms(struct ldb_context *ldb, unsigned int perms) -{ - ldb->create_perms = perms; -} - -void ldb_set_event_context(struct ldb_context *ldb, struct event_context *ev) -{ - ldb->ev_ctx = ev; -} - -struct event_context * ldb_get_event_context(struct ldb_context *ldb) -{ - return ldb->ev_ctx; -} - -/* - start an ldb request - NOTE: the request must be a talloc context. - returns LDB_ERR_* on errors. -*/ -int ldb_request(struct ldb_context *ldb, struct ldb_request *req) -{ - struct ldb_module *module; - int ret; - - if (req->callback == NULL) { - ldb_set_errstring(ldb, "Requests MUST define callbacks"); - return LDB_ERR_UNWILLING_TO_PERFORM; - } - - ldb_reset_err_string(ldb); - - /* call the first module in the chain */ - switch (req->operation) { - case LDB_SEARCH: - FIRST_OP(ldb, search); - ret = module->ops->search(module, req); - break; - case LDB_ADD: - FIRST_OP(ldb, add); - ret = module->ops->add(module, req); - break; - case LDB_MODIFY: - FIRST_OP(ldb, modify); - ret = module->ops->modify(module, req); - break; - case LDB_DELETE: - FIRST_OP(ldb, del); - ret = module->ops->del(module, req); - break; - case LDB_RENAME: - FIRST_OP(ldb, rename); - ret = module->ops->rename(module, req); - break; - case LDB_EXTENDED: - FIRST_OP(ldb, extended); - ret = module->ops->extended(module, req); - break; - default: - FIRST_OP(ldb, request); - ret = module->ops->request(module, req); - break; - } - - return ret; -} - -int ldb_request_done(struct ldb_request *req, int status) -{ - req->handle->state = LDB_ASYNC_DONE; - req->handle->status = status; - return status; -} - -/* - search the database given a LDAP-like search expression - - returns an LDB error code - - Use talloc_free to free the ldb_message returned in 'res', if successful - -*/ -int ldb_search_default_callback(struct ldb_request *req, - struct ldb_reply *ares) -{ - struct ldb_result *res; - int n; - - res = talloc_get_type(req->context, struct ldb_result); - - if (!ares) { - return ldb_request_done(req, LDB_ERR_OPERATIONS_ERROR); - } - if (ares->error != LDB_SUCCESS) { - return ldb_request_done(req, ares->error); - } - - switch (ares->type) { - case LDB_REPLY_ENTRY: - res->msgs = talloc_realloc(res, res->msgs, - struct ldb_message *, res->count + 2); - if (! res->msgs) { - return ldb_request_done(req, LDB_ERR_OPERATIONS_ERROR); - } - - res->msgs[res->count + 1] = NULL; - - res->msgs[res->count] = talloc_move(res->msgs, &ares->message); - res->count++; - break; - - case LDB_REPLY_REFERRAL: - if (res->refs) { - for (n = 0; res->refs[n]; n++) /*noop*/ ; - } else { - n = 0; - } - - res->refs = talloc_realloc(res, res->refs, char *, n + 2); - if (! res->refs) { - return ldb_request_done(req, LDB_ERR_OPERATIONS_ERROR); - } - - res->refs[n] = talloc_move(res->refs, &ares->referral); - res->refs[n + 1] = NULL; - break; - - case LDB_REPLY_DONE: - /* TODO: we should really support controls on entries - * and referrals too! */ - res->controls = talloc_move(res, &ares->controls); - - /* this is the last message, and means the request is done */ - /* we have to signal and eventual ldb_wait() waiting that the - * async request operation was completed */ - return ldb_request_done(req, LDB_SUCCESS); - } - - talloc_free(ares); - return LDB_SUCCESS; -} - -int ldb_op_default_callback(struct ldb_request *req, struct ldb_reply *ares) -{ - int ret; - - if (!ares) { - return ldb_request_done(req, LDB_ERR_OPERATIONS_ERROR); - } - - if (ares->error != LDB_SUCCESS) { - ret = ares->error; - talloc_free(ares); - return ldb_request_done(req, ret); - } - - if (ares->type != LDB_REPLY_DONE) { - talloc_free(ares); - ldb_set_errstring(req->handle->ldb, "Invalid reply type!"); - return ldb_request_done(req, LDB_ERR_OPERATIONS_ERROR); - } - - talloc_free(ares); - return ldb_request_done(req, LDB_SUCCESS); -} - -int ldb_build_search_req_ex(struct ldb_request **ret_req, - struct ldb_context *ldb, - void *mem_ctx, - struct ldb_dn *base, - enum ldb_scope scope, - struct ldb_parse_tree *tree, - const char * const *attrs, - struct ldb_control **controls, - void *context, - ldb_request_callback_t callback, - struct ldb_request *parent) -{ - struct ldb_request *req; - - *ret_req = NULL; - - req = talloc(mem_ctx, struct ldb_request); - if (req == NULL) { - ldb_oom(ldb); - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_SEARCH; - if (base == NULL) { - req->op.search.base = ldb_dn_new(req, ldb, NULL); - } else { - req->op.search.base = base; - } - req->op.search.scope = scope; - - req->op.search.tree = tree; - if (req->op.search.tree == NULL) { - ldb_set_errstring(ldb, "'tree' can't be NULL"); - talloc_free(req); - return LDB_ERR_OPERATIONS_ERROR; - } - - req->op.search.attrs = attrs; - req->controls = controls; - req->context = context; - req->callback = callback; - - ldb_set_timeout_from_prev_req(ldb, parent, req); - - req->handle = ldb_handle_new(req, ldb); - if (req->handle == NULL) { - ldb_oom(ldb); - return LDB_ERR_OPERATIONS_ERROR; - } - - *ret_req = req; - return LDB_SUCCESS; -} - -int ldb_build_search_req(struct ldb_request **ret_req, - struct ldb_context *ldb, - void *mem_ctx, - struct ldb_dn *base, - enum ldb_scope scope, - const char *expression, - const char * const *attrs, - struct ldb_control **controls, - void *context, - ldb_request_callback_t callback, - struct ldb_request *parent) -{ - struct ldb_parse_tree *tree; - int ret; - - tree = ldb_parse_tree(mem_ctx, expression); - if (tree == NULL) { - ldb_set_errstring(ldb, "Unable to parse search expression"); - return LDB_ERR_OPERATIONS_ERROR; - } - - ret = ldb_build_search_req_ex(ret_req, ldb, mem_ctx, base, - scope, tree, attrs, controls, - context, callback, parent); - if (ret == LDB_SUCCESS) { - talloc_steal(*ret_req, tree); - } - return ret; -} - -int ldb_build_add_req(struct ldb_request **ret_req, - struct ldb_context *ldb, - void *mem_ctx, - const struct ldb_message *message, - struct ldb_control **controls, - void *context, - ldb_request_callback_t callback, - struct ldb_request *parent) -{ - struct ldb_request *req; - - *ret_req = NULL; - - req = talloc(mem_ctx, struct ldb_request); - if (req == NULL) { - ldb_set_errstring(ldb, "Out of Memory"); - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_ADD; - req->op.add.message = message; - req->controls = controls; - req->context = context; - req->callback = callback; - - ldb_set_timeout_from_prev_req(ldb, parent, req); - - req->handle = ldb_handle_new(req, ldb); - if (req->handle == NULL) { - ldb_oom(ldb); - return LDB_ERR_OPERATIONS_ERROR; - } - - *ret_req = req; - - return LDB_SUCCESS; -} - -int ldb_build_mod_req(struct ldb_request **ret_req, - struct ldb_context *ldb, - void *mem_ctx, - const struct ldb_message *message, - struct ldb_control **controls, - void *context, - ldb_request_callback_t callback, - struct ldb_request *parent) -{ - struct ldb_request *req; - - *ret_req = NULL; - - req = talloc(mem_ctx, struct ldb_request); - if (req == NULL) { - ldb_set_errstring(ldb, "Out of Memory"); - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_MODIFY; - req->op.mod.message = message; - req->controls = controls; - req->context = context; - req->callback = callback; - - ldb_set_timeout_from_prev_req(ldb, parent, req); - - req->handle = ldb_handle_new(req, ldb); - if (req->handle == NULL) { - ldb_oom(ldb); - return LDB_ERR_OPERATIONS_ERROR; - } - - *ret_req = req; - - return LDB_SUCCESS; -} - -int ldb_build_del_req(struct ldb_request **ret_req, - struct ldb_context *ldb, - void *mem_ctx, - struct ldb_dn *dn, - struct ldb_control **controls, - void *context, - ldb_request_callback_t callback, - struct ldb_request *parent) -{ - struct ldb_request *req; - - *ret_req = NULL; - - req = talloc(mem_ctx, struct ldb_request); - if (req == NULL) { - ldb_set_errstring(ldb, "Out of Memory"); - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_DELETE; - req->op.del.dn = dn; - req->controls = controls; - req->context = context; - req->callback = callback; - - ldb_set_timeout_from_prev_req(ldb, parent, req); - - req->handle = ldb_handle_new(req, ldb); - if (req->handle == NULL) { - ldb_oom(ldb); - return LDB_ERR_OPERATIONS_ERROR; - } - - *ret_req = req; - - return LDB_SUCCESS; -} - -int ldb_build_rename_req(struct ldb_request **ret_req, - struct ldb_context *ldb, - void *mem_ctx, - struct ldb_dn *olddn, - struct ldb_dn *newdn, - struct ldb_control **controls, - void *context, - ldb_request_callback_t callback, - struct ldb_request *parent) -{ - struct ldb_request *req; - - *ret_req = NULL; - - req = talloc(mem_ctx, struct ldb_request); - if (req == NULL) { - ldb_set_errstring(ldb, "Out of Memory"); - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_RENAME; - req->op.rename.olddn = olddn; - req->op.rename.newdn = newdn; - req->controls = controls; - req->context = context; - req->callback = callback; - - ldb_set_timeout_from_prev_req(ldb, parent, req); - - req->handle = ldb_handle_new(req, ldb); - if (req->handle == NULL) { - ldb_oom(ldb); - return LDB_ERR_OPERATIONS_ERROR; - } - - *ret_req = req; - - return LDB_SUCCESS; -} - -int ldb_extended_default_callback(struct ldb_request *req, - struct ldb_reply *ares) -{ - struct ldb_result *res; - - res = talloc_get_type(req->context, struct ldb_result); - - if (!ares) { - return ldb_request_done(req, LDB_ERR_OPERATIONS_ERROR); - } - if (ares->error != LDB_SUCCESS) { - return ldb_request_done(req, ares->error); - } - - if (ares->type == LDB_REPLY_DONE) { - - /* TODO: we should really support controls on entries and referrals too! */ - res->extended = talloc_move(res, &ares->response); - res->controls = talloc_move(res, &ares->controls); - - talloc_free(ares); - return ldb_request_done(req, LDB_SUCCESS); - } - - talloc_free(ares); - ldb_set_errstring(req->handle->ldb, "Invalid reply type!"); - return ldb_request_done(req, LDB_ERR_OPERATIONS_ERROR); -} - -int ldb_build_extended_req(struct ldb_request **ret_req, - struct ldb_context *ldb, - void *mem_ctx, - const char *oid, - void *data, - struct ldb_control **controls, - void *context, - ldb_request_callback_t callback, - struct ldb_request *parent) -{ - struct ldb_request *req; - - *ret_req = NULL; - - req = talloc(mem_ctx, struct ldb_request); - if (req == NULL) { - ldb_set_errstring(ldb, "Out of Memory"); - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_EXTENDED; - req->op.extended.oid = oid; - req->op.extended.data = data; - req->controls = controls; - req->context = context; - req->callback = callback; - - ldb_set_timeout_from_prev_req(ldb, parent, req); - - req->handle = ldb_handle_new(req, ldb); - if (req->handle == NULL) { - ldb_oom(ldb); - return LDB_ERR_OPERATIONS_ERROR; - } - - *ret_req = req; - - return LDB_SUCCESS; -} - -int ldb_extended(struct ldb_context *ldb, - const char *oid, - void *data, - struct ldb_result **_res) -{ - struct ldb_request *req; - int ret; - struct ldb_result *res; - - *_res = NULL; - - res = talloc_zero(ldb, struct ldb_result); - if (!res) { - return LDB_ERR_OPERATIONS_ERROR; - } - - ret = ldb_build_extended_req(&req, ldb, ldb, - oid, data, NULL, - res, ldb_extended_default_callback, - NULL); - if (ret != LDB_SUCCESS) goto done; - - ldb_set_timeout(ldb, req, 0); /* use default timeout */ - - ret = ldb_request(ldb, req); - - if (ret == LDB_SUCCESS) { - ret = ldb_wait(req->handle, LDB_WAIT_ALL); - } - - talloc_free(req); - -done: - if (ret != LDB_SUCCESS) { - talloc_free(res); - } - - *_res = res; - return ret; -} - -/* - note that ldb_search() will automatically replace a NULL 'base' value - with the defaultNamingContext from the rootDSE if available. -*/ -int ldb_search(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, - struct ldb_result **result, struct ldb_dn *base, - enum ldb_scope scope, const char * const *attrs, - const char *exp_fmt, ...) -{ - struct ldb_request *req; - struct ldb_result *res; - char *expression; - va_list ap; - int ret; - - expression = NULL; - *result = NULL; - req = NULL; - - res = talloc_zero(mem_ctx, struct ldb_result); - if (!res) { - return LDB_ERR_OPERATIONS_ERROR; - } - - if (exp_fmt) { - va_start(ap, exp_fmt); - expression = talloc_vasprintf(mem_ctx, exp_fmt, ap); - va_end(ap); - - if (!expression) { - talloc_free(res); - return LDB_ERR_OPERATIONS_ERROR; - } - } - - ret = ldb_build_search_req(&req, ldb, mem_ctx, - base?base:ldb_get_default_basedn(ldb), - scope, - expression, - attrs, - NULL, - res, - ldb_search_default_callback, - NULL); - - if (ret != LDB_SUCCESS) goto done; - - ret = ldb_request(ldb, req); - - if (ret == LDB_SUCCESS) { - ret = ldb_wait(req->handle, LDB_WAIT_ALL); - } - -done: - if (ret != LDB_SUCCESS) { - talloc_free(res); - res = NULL; - } - - talloc_free(expression); - talloc_free(req); - - *result = res; - return ret; -} - -/* - add a record to the database. Will fail if a record with the given class - and key already exists -*/ -int ldb_add(struct ldb_context *ldb, - const struct ldb_message *message) -{ - struct ldb_request *req; - int ret; - - ret = ldb_msg_sanity_check(ldb, message); - if (ret != LDB_SUCCESS) { - return ret; - } - - ret = ldb_build_add_req(&req, ldb, ldb, - message, - NULL, - NULL, - ldb_op_default_callback, - NULL); - - if (ret != LDB_SUCCESS) return ret; - - /* do request and autostart a transaction */ - ret = ldb_autotransaction_request(ldb, req); - - talloc_free(req); - return ret; -} - -/* - modify the specified attributes of a record -*/ -int ldb_modify(struct ldb_context *ldb, - const struct ldb_message *message) -{ - struct ldb_request *req; - int ret; - - ret = ldb_msg_sanity_check(ldb, message); - if (ret != LDB_SUCCESS) { - return ret; - } - - ret = ldb_build_mod_req(&req, ldb, ldb, - message, - NULL, - NULL, - ldb_op_default_callback, - NULL); - - if (ret != LDB_SUCCESS) return ret; - - /* do request and autostart a transaction */ - ret = ldb_autotransaction_request(ldb, req); - - talloc_free(req); - return ret; -} - - -/* - delete a record from the database -*/ -int ldb_delete(struct ldb_context *ldb, struct ldb_dn *dn) -{ - struct ldb_request *req; - int ret; - - ret = ldb_build_del_req(&req, ldb, ldb, - dn, - NULL, - NULL, - ldb_op_default_callback, - NULL); - - if (ret != LDB_SUCCESS) return ret; - - /* do request and autostart a transaction */ - ret = ldb_autotransaction_request(ldb, req); - - talloc_free(req); - return ret; -} - -/* - rename a record in the database -*/ -int ldb_rename(struct ldb_context *ldb, - struct ldb_dn *olddn, struct ldb_dn *newdn) -{ - struct ldb_request *req; - int ret; - - ret = ldb_build_rename_req(&req, ldb, ldb, - olddn, - newdn, - NULL, - NULL, - ldb_op_default_callback, - NULL); - - if (ret != LDB_SUCCESS) return ret; - - /* do request and autostart a transaction */ - ret = ldb_autotransaction_request(ldb, req); - - talloc_free(req); - return ret; -} - - -/* - return the global sequence number -*/ -int ldb_sequence_number(struct ldb_context *ldb, - enum ldb_sequence_type type, uint64_t *seq_num) -{ - struct ldb_seqnum_request *seq; - struct ldb_seqnum_result *seqr; - struct ldb_result *res; - TALLOC_CTX *tmp_ctx; - int ret; - - *seq_num = 0; - - tmp_ctx = talloc_zero(ldb, struct ldb_request); - if (tmp_ctx == NULL) { - ldb_set_errstring(ldb, "Out of Memory"); - return LDB_ERR_OPERATIONS_ERROR; - } - seq = talloc_zero(tmp_ctx, struct ldb_seqnum_request); - if (seq == NULL) { - ldb_set_errstring(ldb, "Out of Memory"); - ret = LDB_ERR_OPERATIONS_ERROR; - goto done; - } - seq->type = type; - - ret = ldb_extended(ldb, LDB_EXTENDED_SEQUENCE_NUMBER, seq, &res); - if (ret != LDB_SUCCESS) { - goto done; - } - talloc_steal(tmp_ctx, res); - - if (strcmp(LDB_EXTENDED_SEQUENCE_NUMBER, res->extended->oid) != 0) { - ldb_set_errstring(ldb, "Invalid OID in reply"); - ret = LDB_ERR_OPERATIONS_ERROR; - goto done; - } - seqr = talloc_get_type(res->extended->data, - struct ldb_seqnum_result); - *seq_num = seqr->seq_num; - -done: - talloc_free(tmp_ctx); - return ret; -} - -/* - return extended error information -*/ -const char *ldb_errstring(struct ldb_context *ldb) -{ - if (ldb->err_string) { - return ldb->err_string; - } - - return NULL; -} - -/* - return a string explaining what a ldb error constant meancs -*/ -const char *ldb_strerror(int ldb_err) -{ - switch (ldb_err) { - case LDB_SUCCESS: - return "Success"; - case LDB_ERR_OPERATIONS_ERROR: - return "Operations error"; - case LDB_ERR_PROTOCOL_ERROR: - return "Protocol error"; - case LDB_ERR_TIME_LIMIT_EXCEEDED: - return "Time limit exceeded"; - case LDB_ERR_SIZE_LIMIT_EXCEEDED: - return "Size limit exceeded"; - case LDB_ERR_COMPARE_FALSE: - return "Compare false"; - case LDB_ERR_COMPARE_TRUE: - return "Compare true"; - case LDB_ERR_AUTH_METHOD_NOT_SUPPORTED: - return "Auth method not supported"; - case LDB_ERR_STRONG_AUTH_REQUIRED: - return "Strong auth required"; -/* 9 RESERVED */ - case LDB_ERR_REFERRAL: - return "Referral error"; - case LDB_ERR_ADMIN_LIMIT_EXCEEDED: - return "Admin limit exceeded"; - case LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION: - return "Unsupported critical extension"; - case LDB_ERR_CONFIDENTIALITY_REQUIRED: - return "Confidentiality required"; - case LDB_ERR_SASL_BIND_IN_PROGRESS: - return "SASL bind in progress"; - case LDB_ERR_NO_SUCH_ATTRIBUTE: - return "No such attribute"; - case LDB_ERR_UNDEFINED_ATTRIBUTE_TYPE: - return "Undefined attribute type"; - case LDB_ERR_INAPPROPRIATE_MATCHING: - return "Inappropriate matching"; - case LDB_ERR_CONSTRAINT_VIOLATION: - return "Constraint violation"; - case LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS: - return "Attribute or value exists"; - case LDB_ERR_INVALID_ATTRIBUTE_SYNTAX: - return "Invalid attribute syntax"; -/* 22-31 unused */ - case LDB_ERR_NO_SUCH_OBJECT: - return "No such object"; - case LDB_ERR_ALIAS_PROBLEM: - return "Alias problem"; - case LDB_ERR_INVALID_DN_SYNTAX: - return "Invalid DN syntax"; -/* 35 RESERVED */ - case LDB_ERR_ALIAS_DEREFERENCING_PROBLEM: - return "Alias dereferencing problem"; -/* 37-47 unused */ - case LDB_ERR_INAPPROPRIATE_AUTHENTICATION: - return "Inappropriate authentication"; - case LDB_ERR_INVALID_CREDENTIALS: - return "Invalid credentials"; - case LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS: - return "insufficient access rights"; - case LDB_ERR_BUSY: - return "Busy"; - case LDB_ERR_UNAVAILABLE: - return "Unavailable"; - case LDB_ERR_UNWILLING_TO_PERFORM: - return "Unwilling to perform"; - case LDB_ERR_LOOP_DETECT: - return "Loop detect"; -/* 55-63 unused */ - case LDB_ERR_NAMING_VIOLATION: - return "Naming violation"; - case LDB_ERR_OBJECT_CLASS_VIOLATION: - return "Object class violation"; - case LDB_ERR_NOT_ALLOWED_ON_NON_LEAF: - return "Not allowed on non-leaf"; - case LDB_ERR_NOT_ALLOWED_ON_RDN: - return "Not allowed on RDN"; - case LDB_ERR_ENTRY_ALREADY_EXISTS: - return "Entry already exists"; - case LDB_ERR_OBJECT_CLASS_MODS_PROHIBITED: - return "Object class mods prohibited"; -/* 70 RESERVED FOR CLDAP */ - case LDB_ERR_AFFECTS_MULTIPLE_DSAS: - return "Affects multiple DSAs"; -/* 72-79 unused */ - case LDB_ERR_OTHER: - return "Other"; - } - - return "Unknown error"; -} - -/* - set backend specific opaque parameters -*/ -int ldb_set_opaque(struct ldb_context *ldb, const char *name, void *value) -{ - struct ldb_opaque *o; - - /* allow updating an existing value */ - for (o=ldb->opaque;o;o=o->next) { - if (strcmp(o->name, name) == 0) { - o->value = value; - return LDB_SUCCESS; - } - } - - o = talloc(ldb, struct ldb_opaque); - if (o == NULL) { - ldb_oom(ldb); - return LDB_ERR_OTHER; - } - o->next = ldb->opaque; - o->name = name; - o->value = value; - ldb->opaque = o; - return LDB_SUCCESS; -} - -/* - get a previously set opaque value -*/ -void *ldb_get_opaque(struct ldb_context *ldb, const char *name) -{ - struct ldb_opaque *o; - for (o=ldb->opaque;o;o=o->next) { - if (strcmp(o->name, name) == 0) { - return o->value; - } - } - return NULL; -} diff --git a/ldb/common/ldb_attributes.c b/ldb/common/ldb_attributes.c deleted file mode 100644 index 001bc45ee..000000000 --- a/ldb/common/ldb_attributes.c +++ /dev/null @@ -1,274 +0,0 @@ -/* - ldb database library - - 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 3 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, see <http://www.gnu.org/licenses/>. -*/ -/* - register handlers for specific attributes and objectclass relationships - - this allows a backend to store its schema information in any format - it likes (or to not have any schema information at all) while keeping the - message matching logic generic -*/ - -#include "ldb_includes.h" - -/* - add a attribute to the ldb_schema - - if flags contains LDB_ATTR_FLAG_ALLOCATED - the attribute name string will be copied using - talloc_strdup(), otherwise it needs to be a static const - string at least with a lifetime longer than the ldb struct! - - the ldb_schema_syntax structure should be a pointer - to a static const struct or at least it needs to be - a struct with a longer lifetime than the ldb context! - -*/ -int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb, - const char *attribute, - unsigned flags, - const struct ldb_schema_syntax *syntax) -{ - int i, n; - struct ldb_schema_attribute *a; - - if (!syntax) { - return LDB_ERR_OPERATIONS_ERROR; - } - - n = ldb->schema.num_attributes + 1; - - a = talloc_realloc(ldb, ldb->schema.attributes, - struct ldb_schema_attribute, n); - if (a == NULL) { - ldb_oom(ldb); - return -1; - } - ldb->schema.attributes = a; - - for (i = 0; i < ldb->schema.num_attributes; i++) { - int cmp = ldb_attr_cmp(attribute, a[i].name); - if (cmp == 0) { - /* silently ignore attempts to overwrite fixed attributes */ - if (a[i].flags & LDB_ATTR_FLAG_FIXED) { - return 0; - } - if (a[i].flags & LDB_ATTR_FLAG_ALLOCATED) { - talloc_free(discard_const_p(char, a[i].name)); - } - /* To cancel out increment below */ - ldb->schema.num_attributes--; - break; - } else if (cmp < 0) { - memmove(a+i+1, a+i, sizeof(*a) * (ldb->schema.num_attributes-i)); - break; - } - } - ldb->schema.num_attributes++; - - a[i].name = attribute; - a[i].flags = flags; - a[i].syntax = syntax; - - if (a[i].flags & LDB_ATTR_FLAG_ALLOCATED) { - a[i].name = talloc_strdup(a, a[i].name); - if (a[i].name == NULL) { - ldb_oom(ldb); - return -1; - } - } - - return 0; -} - -static const struct ldb_schema_syntax ldb_syntax_default = { - .name = LDB_SYNTAX_OCTET_STRING, - .ldif_read_fn = ldb_handler_copy, - .ldif_write_fn = ldb_handler_copy, - .canonicalise_fn = ldb_handler_copy, - .comparison_fn = ldb_comparison_binary -}; - -static const struct ldb_schema_attribute ldb_attribute_default = { - .name = NULL, - .flags = 0, - .syntax = &ldb_syntax_default -}; - -/* - return the attribute handlers for a given attribute -*/ -const struct ldb_schema_attribute *ldb_schema_attribute_by_name(struct ldb_context *ldb, - const char *name) -{ - int i, e, b = 0, r; - const struct ldb_schema_attribute *def = &ldb_attribute_default; - - /* as handlers are sorted, '*' must be the first if present */ - if (strcmp(ldb->schema.attributes[0].name, "*") == 0) { - def = &ldb->schema.attributes[0]; - b = 1; - } - - /* do a binary search on the array */ - e = ldb->schema.num_attributes - 1; - - while (b <= e) { - - i = (b + e) / 2; - - r = ldb_attr_cmp(name, ldb->schema.attributes[i].name); - if (r == 0) { - return &ldb->schema.attributes[i]; - } - if (r < 0) { - e = i - 1; - } else { - b = i + 1; - } - - } - - return def; -} - - -/* - add to the list of ldif handlers for this ldb context -*/ -void ldb_schema_attribute_remove(struct ldb_context *ldb, const char *name) -{ - const struct ldb_schema_attribute *a; - int i; - - a = ldb_schema_attribute_by_name(ldb, name); - if (a == NULL || a->name == NULL) { - return; - } - - /* FIXED attributes are never removed */ - if (a->flags & LDB_ATTR_FLAG_FIXED) { - return; - } - - if (a->flags & LDB_ATTR_FLAG_ALLOCATED) { - talloc_free(discard_const_p(char, a->name)); - } - - i = a - ldb->schema.attributes; - if (i < ldb->schema.num_attributes - 1) { - memmove(&ldb->schema.attributes[i], - a+1, sizeof(*a) * (ldb->schema.num_attributes-(i+1))); - } - - ldb->schema.num_attributes--; -} - -/* - setup a attribute handler using a standard syntax -*/ -int ldb_schema_attribute_add(struct ldb_context *ldb, - const char *attribute, - unsigned flags, - const char *syntax) -{ - const struct ldb_schema_syntax *s = ldb_standard_syntax_by_name(ldb, syntax); - return ldb_schema_attribute_add_with_syntax(ldb, attribute, flags, s); -} - -/* - setup the attribute handles for well known attributes -*/ -int ldb_setup_wellknown_attributes(struct ldb_context *ldb) -{ - const struct { - const char *attr; - const char *syntax; - } wellknown[] = { - { "dn", LDB_SYNTAX_DN }, - { "distinguishedName", LDB_SYNTAX_DN }, - { "cn", LDB_SYNTAX_DIRECTORY_STRING }, - { "dc", LDB_SYNTAX_DIRECTORY_STRING }, - { "ou", LDB_SYNTAX_DIRECTORY_STRING }, - { "objectClass", LDB_SYNTAX_OBJECTCLASS } - }; - int i; - int ret; - - for (i=0;i<ARRAY_SIZE(wellknown);i++) { - ret = ldb_schema_attribute_add(ldb, wellknown[i].attr, 0, - wellknown[i].syntax); - if (ret != LDB_SUCCESS) { - return ret; - } - } - - return LDB_SUCCESS; -} - - -/* - add a extended dn syntax to the ldb_schema -*/ -int ldb_dn_extended_add_syntax(struct ldb_context *ldb, - unsigned flags, - const struct ldb_dn_extended_syntax *syntax) -{ - int n; - struct ldb_dn_extended_syntax *a; - - if (!syntax) { - return LDB_ERR_OPERATIONS_ERROR; - } - - n = ldb->schema.num_dn_extended_syntax + 1; - - a = talloc_realloc(ldb, ldb->schema.dn_extended_syntax, - struct ldb_dn_extended_syntax, n); - - if (!a) { - return LDB_ERR_OPERATIONS_ERROR; - } - - a[ldb->schema.num_dn_extended_syntax] = *syntax; - ldb->schema.dn_extended_syntax = a; - - ldb->schema.num_dn_extended_syntax = n; - - return LDB_SUCCESS; -} - -/* - return the extended dn syntax for a given name -*/ -const struct ldb_dn_extended_syntax *ldb_dn_extended_syntax_by_name(struct ldb_context *ldb, - const char *name) -{ - int i; - for (i=0; i < ldb->schema.num_dn_extended_syntax; i++) { - if (ldb_attr_cmp(ldb->schema.dn_extended_syntax[i].name, name) == 0) { - return &ldb->schema.dn_extended_syntax[i]; - } - } - return NULL; -} - diff --git a/ldb/common/ldb_controls.c b/ldb/common/ldb_controls.c deleted file mode 100644 index 6fad5012b..000000000 --- a/ldb/common/ldb_controls.c +++ /dev/null @@ -1,597 +0,0 @@ -/* - ldb database library - - Copyright (C) Simo Sorce 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -/* - * Name: ldb_controls.c - * - * Component: ldb controls utility functions - * - * Description: helper functions for control modules - * - * Author: Simo Sorce - */ - -#include "ldb_includes.h" - -/* check if a control with the specified "oid" exist and return it */ -/* returns NULL if not found */ -struct ldb_control *ldb_request_get_control(struct ldb_request *req, const char *oid) -{ - int i; - - /* check if there's a paged request control */ - if (req->controls != NULL) { - for (i = 0; req->controls[i]; i++) { - if (strcmp(oid, req->controls[i]->oid) == 0) { - break; - } - } - - return req->controls[i]; - } - - return NULL; -} - -/* check if a control with the specified "oid" exist and return it */ -/* returns NULL if not found */ -struct ldb_control *ldb_reply_get_control(struct ldb_reply *rep, const char *oid) -{ - int i; - - /* check if there's a paged request control */ - if (rep->controls != NULL) { - for (i = 0; rep->controls[i]; i++) { - if (strcmp(oid, rep->controls[i]->oid) == 0) { - break; - } - } - - return rep->controls[i]; - } - - return NULL; -} - -/* saves the current controls list into the "saver" and replace the one in req with a new one excluding -the "exclude" control */ -/* returns False on error */ -int save_controls(struct ldb_control *exclude, struct ldb_request *req, struct ldb_control ***saver) -{ - struct ldb_control **lcs; - int i, j; - - *saver = req->controls; - for (i = 0; req->controls[i]; i++); - if (i == 1) { - req->controls = NULL; - return 1; - } - - lcs = talloc_array(req, struct ldb_control *, i); - if (!lcs) { - return 0; - } - - for (i = 0, j = 0; (*saver)[i]; i++) { - if (exclude == (*saver)[i]) continue; - lcs[j] = (*saver)[i]; - j++; - } - lcs[j] = NULL; - - req->controls = lcs; - return 1; -} - -/* check if there's any control marked as critical in the list */ -/* return True if any, False if none */ -int check_critical_controls(struct ldb_control **controls) -{ - int i; - - if (controls == NULL) { - return 0; - } - - for (i = 0; controls[i]; i++) { - if (controls[i]->critical) { - return 1; - } - } - - return 0; -} - -int ldb_request_add_control(struct ldb_request *req, const char *oid, bool critical, void *data) -{ - unsigned n; - struct ldb_control **ctrls; - struct ldb_control *ctrl; - - for (n=0; req->controls && req->controls[n];) { n++; } - - ctrls = talloc_realloc(req, req->controls, - struct ldb_control *, - n + 2); - if (!ctrls) return LDB_ERR_OPERATIONS_ERROR; - req->controls = ctrls; - ctrls[n] = NULL; - ctrls[n+1] = NULL; - - ctrl = talloc(ctrls, struct ldb_control); - if (!ctrl) return LDB_ERR_OPERATIONS_ERROR; - - ctrl->oid = talloc_strdup(ctrl, oid); - if (!ctrl->oid) return LDB_ERR_OPERATIONS_ERROR; - ctrl->critical = critical; - ctrl->data = data; - - ctrls[n] = ctrl; - return LDB_SUCCESS; -} - -/* Parse controls from the format used on the command line and in ejs */ - -struct ldb_control **ldb_parse_control_strings(struct ldb_context *ldb, void *mem_ctx, const char **control_strings) -{ - int i; - struct ldb_control **ctrl; - - char *error_string = NULL; - - if (control_strings == NULL || control_strings[0] == NULL) - return NULL; - - for (i = 0; control_strings[i]; i++); - - ctrl = talloc_array(mem_ctx, struct ldb_control *, i + 1); - - for (i = 0; control_strings[i]; i++) { - if (strncmp(control_strings[i], "vlv:", 4) == 0) { - struct ldb_vlv_req_control *control; - const char *p; - char attr[1024]; - char ctxid[1024]; - int crit, bc, ac, os, cc, ret; - - attr[0] = '\0'; - ctxid[0] = '\0'; - p = &(control_strings[i][4]); - ret = sscanf(p, "%d:%d:%d:%d:%d:%1023[^$]", &crit, &bc, &ac, &os, &cc, ctxid); - if (ret < 5) { - ret = sscanf(p, "%d:%d:%d:%1023[^:]:%1023[^$]", &crit, &bc, &ac, attr, ctxid); - } - - if ((ret < 4) || (crit < 0) || (crit > 1)) { - error_string = talloc_asprintf(mem_ctx, "invalid server_sort control syntax\n"); - error_string = talloc_asprintf_append(error_string, " syntax: crit(b):bc(n):ac(n):<os(n):cc(n)|attr(s)>[:ctxid(o)]\n"); - error_string = talloc_asprintf_append(error_string, " note: b = boolean, n = number, s = string, o = b64 binary blob"); - ldb_set_errstring(ldb, error_string); - talloc_free(error_string); - return NULL; - } - if (!(ctrl[i] = talloc(ctrl, struct ldb_control))) { - ldb_oom(ldb); - return NULL; - } - ctrl[i]->oid = LDB_CONTROL_VLV_REQ_OID; - ctrl[i]->critical = crit; - if (!(control = talloc(ctrl[i], - struct ldb_vlv_req_control))) { - ldb_oom(ldb); - return NULL; - } - control->beforeCount = bc; - control->afterCount = ac; - if (attr[0]) { - control->type = 1; - control->match.gtOrEq.value = talloc_strdup(control, attr); - control->match.gtOrEq.value_len = strlen(attr); - } else { - control->type = 0; - control->match.byOffset.offset = os; - control->match.byOffset.contentCount = cc; - } - if (ctxid[0]) { - control->ctxid_len = ldb_base64_decode(ctxid); - control->contextId = (char *)talloc_memdup(control, ctxid, control->ctxid_len); - } else { - control->ctxid_len = 0; - control->contextId = NULL; - } - ctrl[i]->data = control; - - continue; - } - - if (strncmp(control_strings[i], "dirsync:", 8) == 0) { - struct ldb_dirsync_control *control; - const char *p; - char cookie[1024]; - int crit, flags, max_attrs, ret; - - cookie[0] = '\0'; - p = &(control_strings[i][8]); - ret = sscanf(p, "%d:%d:%d:%1023[^$]", &crit, &flags, &max_attrs, cookie); - - if ((ret < 3) || (crit < 0) || (crit > 1) || (flags < 0) || (max_attrs < 0)) { - error_string = talloc_asprintf(mem_ctx, "invalid dirsync control syntax\n"); - error_string = talloc_asprintf_append(error_string, " syntax: crit(b):flags(n):max_attrs(n)[:cookie(o)]\n"); - error_string = talloc_asprintf_append(error_string, " note: b = boolean, n = number, o = b64 binary blob"); - ldb_set_errstring(ldb, error_string); - talloc_free(error_string); - return NULL; - } - - /* w2k3 seems to ignore the parameter, - * but w2k sends a wrong cookie when this value is to small - * this would cause looping forever, while getting - * the same data and same cookie forever - */ - if (max_attrs == 0) max_attrs = 0x0FFFFFFF; - - ctrl[i] = talloc(ctrl, struct ldb_control); - ctrl[i]->oid = LDB_CONTROL_DIRSYNC_OID; - ctrl[i]->critical = crit; - control = talloc(ctrl[i], struct ldb_dirsync_control); - control->flags = flags; - control->max_attributes = max_attrs; - if (*cookie) { - control->cookie_len = ldb_base64_decode(cookie); - control->cookie = (char *)talloc_memdup(control, cookie, control->cookie_len); - } else { - control->cookie = NULL; - control->cookie_len = 0; - } - ctrl[i]->data = control; - - continue; - } - - if (strncmp(control_strings[i], "asq:", 4) == 0) { - struct ldb_asq_control *control; - const char *p; - char attr[256]; - int crit, ret; - - attr[0] = '\0'; - p = &(control_strings[i][4]); - ret = sscanf(p, "%d:%255[^$]", &crit, attr); - if ((ret != 2) || (crit < 0) || (crit > 1) || (attr[0] == '\0')) { - error_string = talloc_asprintf(mem_ctx, "invalid asq control syntax\n"); - error_string = talloc_asprintf_append(error_string, " syntax: crit(b):attr(s)\n"); - error_string = talloc_asprintf_append(error_string, " note: b = boolean, s = string"); - ldb_set_errstring(ldb, error_string); - talloc_free(error_string); - return NULL; - } - - ctrl[i] = talloc(ctrl, struct ldb_control); - if (!ctrl[i]) { - ldb_oom(ldb); - return NULL; - } - ctrl[i]->oid = LDB_CONTROL_ASQ_OID; - ctrl[i]->critical = crit; - control = talloc(ctrl[i], struct ldb_asq_control); - control->request = 1; - control->source_attribute = talloc_strdup(control, attr); - control->src_attr_len = strlen(attr); - ctrl[i]->data = control; - - continue; - } - - if (strncmp(control_strings[i], "extended_dn:", 12) == 0) { - struct ldb_extended_dn_control *control; - const char *p; - int crit, type, ret; - - p = &(control_strings[i][12]); - ret = sscanf(p, "%d:%d", &crit, &type); - if ((ret != 2) || (crit < 0) || (crit > 1) || (type < 0) || (type > 1)) { - ret = sscanf(p, "%d", &crit); - if ((ret != 1) || (crit < 0) || (crit > 1)) { - error_string = talloc_asprintf(mem_ctx, "invalid extended_dn control syntax\n"); - error_string = talloc_asprintf_append(error_string, " syntax: crit(b)[:type(i)]\n"); - error_string = talloc_asprintf_append(error_string, " note: b = boolean\n"); - error_string = talloc_asprintf_append(error_string, " i = integer\n"); - error_string = talloc_asprintf_append(error_string, " valid values are: 0 - hexadecimal representation\n"); - error_string = talloc_asprintf_append(error_string, " 1 - normal string representation"); - ldb_set_errstring(ldb, error_string); - talloc_free(error_string); - return NULL; - } - control = NULL; - } else { - control = talloc(ctrl, struct ldb_extended_dn_control); - control->type = type; - } - - ctrl[i] = talloc(ctrl, struct ldb_control); - if (!ctrl[i]) { - ldb_oom(ldb); - return NULL; - } - ctrl[i]->oid = LDB_CONTROL_EXTENDED_DN_OID; - ctrl[i]->critical = crit; - ctrl[i]->data = talloc_steal(ctrl[i], control); - - continue; - } - - if (strncmp(control_strings[i], "sd_flags:", 9) == 0) { - struct ldb_sd_flags_control *control; - const char *p; - int crit, ret; - unsigned secinfo_flags; - - p = &(control_strings[i][9]); - ret = sscanf(p, "%d:%u", &crit, &secinfo_flags); - if ((ret != 2) || (crit < 0) || (crit > 1) || (secinfo_flags < 0) || (secinfo_flags > 0xF)) { - error_string = talloc_asprintf(mem_ctx, "invalid sd_flags control syntax\n"); - error_string = talloc_asprintf_append(error_string, " syntax: crit(b):secinfo_flags(n)\n"); - error_string = talloc_asprintf_append(error_string, " note: b = boolean, n = number"); - ldb_set_errstring(ldb, error_string); - talloc_free(error_string); - return NULL; - } - - ctrl[i] = talloc(ctrl, struct ldb_control); - if (!ctrl[i]) { - ldb_oom(ldb); - return NULL; - } - ctrl[i]->oid = LDB_CONTROL_SD_FLAGS_OID; - ctrl[i]->critical = crit; - control = talloc(ctrl[i], struct ldb_sd_flags_control); - control->secinfo_flags = secinfo_flags; - ctrl[i]->data = control; - - continue; - } - - if (strncmp(control_strings[i], "search_options:", 15) == 0) { - struct ldb_search_options_control *control; - const char *p; - int crit, ret; - unsigned search_options; - - p = &(control_strings[i][15]); - ret = sscanf(p, "%d:%u", &crit, &search_options); - if ((ret != 2) || (crit < 0) || (crit > 1) || (search_options < 0) || (search_options > 0xF)) { - error_string = talloc_asprintf(mem_ctx, "invalid search_options control syntax\n"); - error_string = talloc_asprintf_append(error_string, " syntax: crit(b):search_options(n)\n"); - error_string = talloc_asprintf_append(error_string, " note: b = boolean, n = number"); - ldb_set_errstring(ldb, error_string); - talloc_free(error_string); - return NULL; - } - - ctrl[i] = talloc(ctrl, struct ldb_control); - if (!ctrl[i]) { - ldb_oom(ldb); - return NULL; - } - ctrl[i]->oid = LDB_CONTROL_SEARCH_OPTIONS_OID; - ctrl[i]->critical = crit; - control = talloc(ctrl[i], struct ldb_search_options_control); - control->search_options = search_options; - ctrl[i]->data = control; - - continue; - } - - if (strncmp(control_strings[i], "domain_scope:", 13) == 0) { - const char *p; - int crit, ret; - - p = &(control_strings[i][13]); - ret = sscanf(p, "%d", &crit); - if ((ret != 1) || (crit < 0) || (crit > 1)) { - error_string = talloc_asprintf(mem_ctx, "invalid domain_scope control syntax\n"); - error_string = talloc_asprintf_append(error_string, " syntax: crit(b)\n"); - error_string = talloc_asprintf_append(error_string, " note: b = boolean"); - ldb_set_errstring(ldb, error_string); - talloc_free(error_string); - return NULL; - } - - ctrl[i] = talloc(ctrl, struct ldb_control); - if (!ctrl[i]) { - ldb_oom(ldb); - return NULL; - } - ctrl[i]->oid = LDB_CONTROL_DOMAIN_SCOPE_OID; - ctrl[i]->critical = crit; - ctrl[i]->data = NULL; - - continue; - } - - if (strncmp(control_strings[i], "paged_results:", 14) == 0) { - struct ldb_paged_control *control; - const char *p; - int crit, size, ret; - - p = &(control_strings[i][14]); - ret = sscanf(p, "%d:%d", &crit, &size); - - if ((ret != 2) || (crit < 0) || (crit > 1) || (size < 0)) { - error_string = talloc_asprintf(mem_ctx, "invalid paged_results control syntax\n"); - error_string = talloc_asprintf_append(error_string, " syntax: crit(b):size(n)\n"); - error_string = talloc_asprintf_append(error_string, " note: b = boolean, n = number"); - ldb_set_errstring(ldb, error_string); - talloc_free(error_string); - return NULL; - } - - ctrl[i] = talloc(ctrl, struct ldb_control); - if (!ctrl[i]) { - ldb_oom(ldb); - return NULL; - } - ctrl[i]->oid = LDB_CONTROL_PAGED_RESULTS_OID; - ctrl[i]->critical = crit; - control = talloc(ctrl[i], struct ldb_paged_control); - control->size = size; - control->cookie = NULL; - control->cookie_len = 0; - ctrl[i]->data = control; - - continue; - } - - if (strncmp(control_strings[i], "server_sort:", 12) == 0) { - struct ldb_server_sort_control **control; - const char *p; - char attr[256]; - char rule[128]; - int crit, rev, ret; - - attr[0] = '\0'; - rule[0] = '\0'; - p = &(control_strings[i][12]); - ret = sscanf(p, "%d:%d:%255[^:]:%127[^:]", &crit, &rev, attr, rule); - if ((ret < 3) || (crit < 0) || (crit > 1) || (rev < 0 ) || (rev > 1) ||attr[0] == '\0') { - error_string = talloc_asprintf(mem_ctx, "invalid server_sort control syntax\n"); - error_string = talloc_asprintf_append(error_string, " syntax: crit(b):rev(b):attr(s)[:rule(s)]\n"); - error_string = talloc_asprintf_append(error_string, " note: b = boolean, s = string"); - ldb_set_errstring(ldb, error_string); - talloc_free(error_string); - return NULL; - } - ctrl[i] = talloc(ctrl, struct ldb_control); - if (!ctrl[i]) { - ldb_oom(ldb); - return NULL; - } - ctrl[i]->oid = LDB_CONTROL_SERVER_SORT_OID; - ctrl[i]->critical = crit; - control = talloc_array(ctrl[i], struct ldb_server_sort_control *, 2); - control[0] = talloc(control, struct ldb_server_sort_control); - control[0]->attributeName = talloc_strdup(control, attr); - if (rule[0]) - control[0]->orderingRule = talloc_strdup(control, rule); - else - control[0]->orderingRule = NULL; - control[0]->reverse = rev; - control[1] = NULL; - ctrl[i]->data = control; - - continue; - } - - if (strncmp(control_strings[i], "notification:", 13) == 0) { - const char *p; - int crit, ret; - - p = &(control_strings[i][13]); - ret = sscanf(p, "%d", &crit); - if ((ret != 1) || (crit < 0) || (crit > 1)) { - error_string = talloc_asprintf(mem_ctx, "invalid notification control syntax\n"); - error_string = talloc_asprintf_append(error_string, " syntax: crit(b)\n"); - error_string = talloc_asprintf_append(error_string, " note: b = boolean"); - ldb_set_errstring(ldb, error_string); - talloc_free(error_string); - return NULL; - } - - ctrl[i] = talloc(ctrl, struct ldb_control); - if (!ctrl[i]) { - ldb_oom(ldb); - return NULL; - } - ctrl[i]->oid = LDB_CONTROL_NOTIFICATION_OID; - ctrl[i]->critical = crit; - ctrl[i]->data = NULL; - - continue; - } - - if (strncmp(control_strings[i], "show_deleted:", 13) == 0) { - const char *p; - int crit, ret; - - p = &(control_strings[i][13]); - ret = sscanf(p, "%d", &crit); - if ((ret != 1) || (crit < 0) || (crit > 1)) { - error_string = talloc_asprintf(mem_ctx, "invalid show_deleted control syntax\n"); - error_string = talloc_asprintf_append(error_string, " syntax: crit(b)\n"); - error_string = talloc_asprintf_append(error_string, " note: b = boolean"); - ldb_set_errstring(ldb, error_string); - talloc_free(error_string); - return NULL; - } - - ctrl[i] = talloc(ctrl, struct ldb_control); - if (!ctrl[i]) { - ldb_oom(ldb); - return NULL; - } - ctrl[i]->oid = LDB_CONTROL_SHOW_DELETED_OID; - ctrl[i]->critical = crit; - ctrl[i]->data = NULL; - - continue; - } - - if (strncmp(control_strings[i], "permissive_modify:", 18) == 0) { - const char *p; - int crit, ret; - - p = &(control_strings[i][18]); - ret = sscanf(p, "%d", &crit); - if ((ret != 1) || (crit < 0) || (crit > 1)) { - error_string = talloc_asprintf(mem_ctx, "invalid permissive_modify control syntax\n"); - error_string = talloc_asprintf_append(error_string, " syntax: crit(b)\n"); - error_string = talloc_asprintf_append(error_string, " note: b = boolean"); - ldb_set_errstring(ldb, error_string); - talloc_free(error_string); - return NULL; - } - - ctrl[i] = talloc(ctrl, struct ldb_control); - if (!ctrl[i]) { - ldb_oom(ldb); - return NULL; - } - ctrl[i]->oid = LDB_CONTROL_PERMISSIVE_MODIFY_OID; - ctrl[i]->critical = crit; - ctrl[i]->data = NULL; - - continue; - } - - /* no controls matched, throw an error */ - ldb_asprintf_errstring(ldb, "Invalid control name: '%s'", control_strings[i]); - return NULL; - } - - ctrl[i] = NULL; - - return ctrl; -} - - diff --git a/ldb/common/ldb_debug.c b/ldb/common/ldb_debug.c deleted file mode 100644 index 0f78e37c1..000000000 --- a/ldb/common/ldb_debug.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - ldb database library - - Copyright (C) Andrew Tridgell 2004 - - ** 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -/* - * Name: ldb - * - * Component: ldb debug - * - * Description: functions for printing debug messages - * - * Author: Andrew Tridgell - */ - -#include "ldb_includes.h" - -/* - this allows the user to choose their own debug function -*/ -int ldb_set_debug(struct ldb_context *ldb, - void (*debug)(void *context, enum ldb_debug_level level, - const char *fmt, va_list ap), - void *context) -{ - ldb->debug_ops.debug = debug; - ldb->debug_ops.context = context; - return 0; -} - -/* - debug function for ldb_set_debug_stderr -*/ -static void ldb_debug_stderr(void *context, enum ldb_debug_level level, - const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0); -static void ldb_debug_stderr(void *context, enum ldb_debug_level level, - const char *fmt, va_list ap) -{ - if (level <= LDB_DEBUG_WARNING) { - vfprintf(stderr, fmt, ap); - } -} - -/* - convenience function to setup debug messages on stderr - messages of level LDB_DEBUG_WARNING and higher are printed -*/ -int ldb_set_debug_stderr(struct ldb_context *ldb) -{ - return ldb_set_debug(ldb, ldb_debug_stderr, ldb); -} - -/* - log a message -*/ -void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...) -{ - va_list ap; - if (ldb->debug_ops.debug == NULL) { - ldb_set_debug_stderr(ldb); - } - va_start(ap, fmt); - ldb->debug_ops.debug(ldb->debug_ops.context, level, fmt, ap); - va_end(ap); -} - - -/* - log a message, and set the ldb error string to the same message -*/ -void ldb_debug_set(struct ldb_context *ldb, enum ldb_debug_level level, - const char *fmt, ...) -{ - va_list ap; - char *msg; - va_start(ap, fmt); - msg = talloc_vasprintf(ldb, fmt, ap); - va_end(ap); - if (msg != NULL) { - ldb_set_errstring(ldb, msg); - ldb_debug(ldb, level, "%s", msg); - } - talloc_free(msg); -} - diff --git a/ldb/common/ldb_dn.c b/ldb/common/ldb_dn.c deleted file mode 100644 index 02e21a2b2..000000000 --- a/ldb/common/ldb_dn.c +++ /dev/null @@ -1,1800 +0,0 @@ -/* - ldb database library - - Copyright (C) Simo Sorce 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -/* - * Name: ldb - * - * Component: ldb dn creation and manipulation utility functions - * - * Description: - explode a dn into it's own basic elements - * and put them in a structure (only if necessary) - * - manipulate ldb_dn structures - * - * Author: Simo Sorce - */ - -#include "ldb_includes.h" -#include <ctype.h> - -#define LDB_DN_NULL_FAILED(x) if (!(x)) goto failed - -#define LDB_FREE(x) do { talloc_free(x); x = NULL; } while(0) - -/** - internal ldb exploded dn structures -*/ -struct ldb_dn_component { - - char *name; - struct ldb_val value; - - char *cf_name; - struct ldb_val cf_value; -}; - -struct ldb_dn_extended_component { - - char *name; - struct ldb_val value; -}; - -struct ldb_dn { - - struct ldb_context *ldb; - - /* Special DNs are always linearized */ - bool special; - bool invalid; - - bool valid_case; - - char *linearized; - char *extended_linearized; - char *casefold; - - unsigned int comp_num; - struct ldb_dn_component *components; - - unsigned int extended_comp_num; - struct ldb_dn_extended_component *extended_components; -}; - -/* strdn may be NULL */ -struct ldb_dn *ldb_dn_from_ldb_val(void *mem_ctx, struct ldb_context *ldb, const struct ldb_val *strdn) -{ - struct ldb_dn *dn; - - if (! ldb) return NULL; - - dn = talloc_zero(mem_ctx, struct ldb_dn); - LDB_DN_NULL_FAILED(dn); - - dn->ldb = ldb; - - if (strdn->data && strdn->length) { - if (strdn->data[0] == '@') { - dn->special = true; - } - dn->extended_linearized = talloc_strndup(dn, (const char *)strdn->data, strdn->length); - LDB_DN_NULL_FAILED(dn->extended_linearized); - - if (strdn->data[0] == '<') { - const char *p_save, *p = dn->extended_linearized; - do { - p_save = p; - p = strstr(p, ">;"); - if (p) { - p = p + 2; - } - } while (p); - - if (p_save == dn->extended_linearized) { - dn->linearized = talloc_strdup(dn, ""); - } else { - dn->linearized = talloc_strdup(dn, p_save); - } - LDB_DN_NULL_FAILED(dn->linearized); - } else { - dn->linearized = dn->extended_linearized; - dn->extended_linearized = NULL; - } - } else { - dn->linearized = talloc_strdup(dn, ""); - LDB_DN_NULL_FAILED(dn->linearized); - } - - return dn; - -failed: - talloc_free(dn); - return NULL; -} - -/* strdn may be NULL */ -struct ldb_dn *ldb_dn_new(void *mem_ctx, struct ldb_context *ldb, const char *strdn) -{ - struct ldb_val blob; - blob.data = strdn; - blob.length = strdn ? strlen(strdn) : 0; - return ldb_dn_from_ldb_val(mem_ctx, ldb, &blob); -} - -struct ldb_dn *ldb_dn_new_fmt(void *mem_ctx, struct ldb_context *ldb, const char *new_fmt, ...) -{ - char *strdn; - va_list ap; - - if ( (! mem_ctx) || (! ldb)) return NULL; - - va_start(ap, new_fmt); - strdn = talloc_vasprintf(mem_ctx, new_fmt, ap); - va_end(ap); - - if (strdn) { - struct ldb_dn *dn = ldb_dn_new(mem_ctx, ldb, strdn); - talloc_free(strdn); - return dn; - } - - return NULL; -} - -static int ldb_dn_escape_internal(char *dst, const char *src, int len) -{ - const char *p, *s; - char *d; - int l; - - p = s = src; - d = dst; - - while (p - src < len) { - - p += strcspn(p, ",=\n+<>#;\\\""); - - if (p - src == len) /* found no escapable chars */ - break; - - memcpy(d, s, p - s); /* copy the part of the string before the stop */ - d += (p - s); /* move to current position */ - - if (*p) { /* it is a normal escapable character */ - *d++ = '\\'; - *d++ = *p++; - } else { /* we have a zero byte in the string */ - strncpy(d, "\00", 3); /* escape the zero */ - d += 3; - p++; /* skip the zero */ - } - s = p; /* move forward */ - } - - /* copy the last part (with zero) and return */ - l = len - (s - src); - memcpy(d, s, l + 1); - - /* return the length of the resulting string */ - return (l + (d - dst)); -} - -char *ldb_dn_escape_value(void *mem_ctx, struct ldb_val value) -{ - char *dst; - - if (!value.length) - return NULL; - - /* allocate destination string, it will be at most 3 times the source */ - dst = talloc_array(mem_ctx, char, value.length * 3 + 1); - if ( ! dst) { - talloc_free(dst); - return NULL; - } - - ldb_dn_escape_internal(dst, (const char *)value.data, value.length); - - dst = talloc_realloc(mem_ctx, dst, char, strlen(dst) + 1); - - return dst; -} - -/* - explode a DN string into a ldb_dn structure - based on RFC4514 except that we don't support multiple valued RDNs -*/ -static bool ldb_dn_explode(struct ldb_dn *dn) -{ - char *p, *ex_name, *ex_value, *data, *d, *dt, *t; - bool trim = false; - bool in_extended = false; - bool in_ex_name = false; - bool in_ex_value = false; - bool in_attr = false; - bool in_value = false; - bool in_quote = false; - bool is_oid = false; - bool escape = false; - unsigned x; - int l, ret; - char *parse_dn; - - if ( ! dn || dn->invalid) return false; - - if (dn->components) { - return true; - } - - if (dn->extended_linearized) { - parse_dn = dn->extended_linearized; - } else { - parse_dn = dn->linearized; - } - - if ( ! parse_dn ) { - return false; - } - - /* Empty DNs */ - if (parse_dn[0] == '\0') { - return true; - } - - /* Special DNs case */ - if (dn->special) { - return true; - } - - /* make sure we free this if alloced previously before replacing */ - talloc_free(dn->components); - - talloc_free(dn->extended_components); - dn->extended_components = NULL; - - /* in the common case we have 3 or more components */ - /* make sure all components are zeroed, other functions depend on this */ - dn->components = talloc_zero_array(dn, struct ldb_dn_component, 3); - if ( ! dn->components) { - return false; - } - dn->comp_num = 0; - - /* Components data space is allocated here once */ - data = talloc_array(dn->components, char, strlen(parse_dn) + 1); - if (!data) { - return false; - } - - p = parse_dn; - in_extended = true; - in_ex_name = false; - in_ex_value = false; - trim = true; - t = NULL; - d = dt = data; - - while (*p) { - if (in_extended) { - - if (!in_ex_name && !in_ex_value) { - - if (p[0] == '<') { - p++; - ex_name = d; - in_ex_name = true; - continue; - } else if (p[0] == '\0') { - p++; - continue; - } else { - in_extended = false; - in_attr = true; - dt = d; - - continue; - } - } - - if (in_ex_name && *p == '=') { - *d++ = '\0'; - p++; - ex_value = d; - in_ex_name = false; - in_ex_value = true; - continue; - } - - if (in_ex_value && *p == '>') { - const struct ldb_dn_extended_syntax *extended_syntax; - struct ldb_val ex_val = { - .data = ex_value, - .length = d - ex_value - }; - - *d++ = '\0'; - p++; - in_ex_value = false; - - /* Process name and ex_value */ - - dn->extended_components = talloc_realloc(dn, - dn->extended_components, - struct ldb_dn_extended_component, - dn->extended_comp_num + 1); - if ( ! dn->extended_components) { - /* ouch ! */ - goto failed; - } - - extended_syntax = ldb_dn_extended_syntax_by_name(dn->ldb, ex_name); - if (!extended_syntax) { - /* We don't know about this type of extended DN */ - goto failed; - } - - dn->extended_components[dn->extended_comp_num].name = talloc_strdup(dn->extended_components, ex_name); - if (!dn->extended_components[dn->extended_comp_num].name) { - /* ouch */ - goto failed; - } - ret = extended_syntax->read_fn(dn->ldb, dn->extended_components, - &ex_val, &dn->extended_components[dn->extended_comp_num].value); - if (ret != LDB_SUCCESS) { - dn->invalid = true; - goto failed; - } - - dn->extended_comp_num++; - - if (*p == '\0') { - /* We have reached the end (extended component only)! */ - talloc_free(data); - return true; - - } else if (*p == ';') { - p++; - continue; - } else { - dn->invalid = true; - goto failed; - } - } - - *d++ = *p++; - continue; - } - if (in_attr) { - if (trim) { - if (*p == ' ') { - p++; - continue; - } - - /* first char */ - trim = false; - - if (!isascii(*p)) { - /* attr names must be ascii only */ - dn->invalid = true; - goto failed; - } - - if (isdigit(*p)) { - is_oid = true; - } else - if ( ! isalpha(*p)) { - /* not a digit nor an alpha, invalid attribute name */ - dn->invalid = true; - goto failed; - } - - /* Copy this character across from parse_dn, now we have trimmed out spaces */ - *d++ = *p++; - continue; - } - - if (*p == ' ') { - p++; - /* valid only if we are at the end */ - trim = true; - continue; - } - - if (trim && (*p != '=')) { - /* spaces/tabs are not allowed in attribute names */ - dn->invalid = true; - goto failed; - } - - if (*p == '=') { - /* attribute terminated */ - in_attr = false; - in_value = true; - trim = true; - l = 0; - - /* Terminate this string in d (which is a copy of parse_dn with spaces trimmed) */ - *d++ = '\0'; - dn->components[dn->comp_num].name = talloc_strdup(dn->components, dt); - if ( ! dn->components[dn->comp_num].name) { - /* ouch */ - goto failed; - } - - dt = d; - - p++; - continue; - } - - if (!isascii(*p)) { - /* attr names must be ascii only */ - dn->invalid = true; - goto failed; - } - - if (is_oid && ( ! (isdigit(*p) || (*p == '.')))) { - /* not a digit nor a dot, invalid attribute oid */ - dn->invalid = true; - goto failed; - } else - if ( ! (isalpha(*p) || isdigit(*p) || (*p == '-'))) { - /* not ALPHA, DIGIT or HYPHEN */ - dn->invalid = true; - goto failed; - } - - *d++ = *p++; - continue; - } - - if (in_value) { - if (in_quote) { - if (*p == '\"') { - if (p[-1] != '\\') { - p++; - in_quote = false; - continue; - } - } - *d++ = *p++; - l++; - continue; - } - - if (trim) { - if (*p == ' ') { - p++; - continue; - } - - /* first char */ - trim = false; - - if (*p == '\"') { - in_quote = true; - p++; - continue; - } - } - - switch (*p) { - - /* TODO: support ber encoded values - case '#': - */ - - case ',': - if (escape) { - *d++ = *p++; - l++; - escape = false; - continue; - } - /* ok found value terminator */ - - if ( t ) { - /* trim back */ - d -= (p - t); - l -= (p - t); - } - - in_attr = true; - in_value = false; - trim = true; - - p++; - *d++ = '\0'; - dn->components[dn->comp_num].value.data = (uint8_t *)talloc_strdup(dn->components, dt); - dn->components[dn->comp_num].value.length = l; - if ( ! dn->components[dn->comp_num].value.data) { - /* ouch ! */ - goto failed; - } - - dt = d; - - dn->comp_num++; - if (dn->comp_num > 2) { - dn->components = talloc_realloc(dn, - dn->components, - struct ldb_dn_component, - dn->comp_num + 1); - if ( ! dn->components) { - /* ouch ! */ - goto failed; - } - /* make sure all components are zeroed, other functions depend on this */ - memset(&dn->components[dn->comp_num], '\0', sizeof(struct ldb_dn_component)); - } - - continue; - - case '=': - case '\n': - case '+': - case '<': - case '>': - case '#': - case ';': - case '\"': - /* a string with not escaped specials is invalid (tested) */ - if ( ! escape) { - dn->invalid = true; - goto failed; - } - escape = false; - - *d++ = *p++; - l++; - - if ( t ) t = NULL; - break; - - case '\\': - if ( ! escape) { - escape = true; - p++; - continue; - } - escape = false; - - *d++ = *p++; - l++; - - if ( t ) t = NULL; - break; - - default: - if (escape) { - if (sscanf(p, "%02x", &x) != 1) { - /* invalid escaping sequence */ - dn->invalid = true; - goto failed; - } - escape = false; - - p += 2; - *d++ = (unsigned char)x; - l++; - - if ( t ) t = NULL; - break; - } - - if (*p == ' ') { - if ( ! t) t = p; - } else { - if ( t ) t = NULL; - } - - *d++ = *p++; - l++; - - break; - } - - } - } - - if (in_attr || in_quote) { - /* invalid dn */ - dn->invalid = true; - goto failed; - } - - /* save last element */ - if ( t ) { - /* trim back */ - d -= (p - t); - l -= (p - t); - } - - *d++ = '\0'; - dn->components[dn->comp_num].value.data = (uint8_t *)talloc_strdup(dn->components, dt); - dn->components[dn->comp_num].value.length = l; - - if ( ! dn->components[dn->comp_num].value.data) { - /* ouch */ - goto failed; - } - - dn->comp_num++; - - talloc_free(data); - return true; - -failed: - dn->comp_num = 0; - talloc_free(dn->components); - return false; -} - -bool ldb_dn_validate(struct ldb_dn *dn) -{ - return ldb_dn_explode(dn); -} - -const char *ldb_dn_get_linearized(struct ldb_dn *dn) -{ - int i, len; - char *d, *n; - - if ( ! dn || ( dn->invalid)) return NULL; - - if (dn->linearized) return dn->linearized; - - if ( ! dn->components) { - dn->invalid = true; - return NULL; - } - - if (dn->comp_num == 0) { - dn->linearized = talloc_strdup(dn, ""); - if ( ! dn->linearized) return NULL; - return dn->linearized; - } - - /* calculate maximum possible length of DN */ - for (len = 0, i = 0; i < dn->comp_num; i++) { - len += strlen(dn->components[i].name); /* name len */ - len += (dn->components[i].value.length * 3); /* max escaped data len */ - len += 2; /* '=' and ',' */ - } - dn->linearized = talloc_array(dn, char, len); - if ( ! dn->linearized) return NULL; - - d = dn->linearized; - - for (i = 0; i < dn->comp_num; i++) { - - /* copy the name */ - n = dn->components[i].name; - while (*n) *d++ = *n++; - - *d++ = '='; - - /* and the value */ - d += ldb_dn_escape_internal( d, - (char *)dn->components[i].value.data, - dn->components[i].value.length); - *d++ = ','; - } - - *(--d) = '\0'; - - /* don't waste more memory than necessary */ - dn->linearized = talloc_realloc(dn, dn->linearized, char, (d - dn->linearized + 1)); - - return dn->linearized; -} - -char *ldb_dn_get_extended_linearized(void *mem_ctx, struct ldb_dn *dn, int mode) -{ - const char *linearized = ldb_dn_get_linearized(dn); - char *p; - int i; - - if (!linearized) { - return NULL; - } - - if (!ldb_dn_has_extended(dn)) { - return talloc_strdup(mem_ctx, linearized); - } - - if (!ldb_dn_validate(dn)) { - return NULL; - } - - for (i=0; i < dn->extended_comp_num; i++) { - struct ldb_val val; - int ret; - const struct ldb_dn_extended_syntax *extended_syntax; - const char *name = dn->extended_components[i].name; - - extended_syntax = ldb_dn_extended_syntax_by_name(dn->ldb, name); - - if (mode == 1) { - ret = extended_syntax->write_clear_fn(dn->ldb, mem_ctx, - &dn->extended_components[i].value, - &val); - } else if (mode == 0) { - ret = extended_syntax->write_hex_fn(dn->ldb, mem_ctx, - &dn->extended_components[i].value, - &val); - } else { - ret = -1; - } - - if (ret != LDB_SUCCESS) { - return NULL; - } - - if (i == 0) { - p = talloc_asprintf(mem_ctx, "<%s=%s>", dn->extended_components[i].name, val.data); - } else { - p = talloc_asprintf_append(p, ";<%s=%s>", dn->extended_components[i].name, val.data); - } - - talloc_free(val.data); - - if (!p) { - return NULL; - } - } - - if (dn->extended_comp_num && *linearized) { - p = talloc_asprintf_append(p, ";%s", linearized); - } - - if (!p) { - return NULL; - } - - return p; -} - - - -char *ldb_dn_alloc_linearized(void *mem_ctx, struct ldb_dn *dn) -{ - return talloc_strdup(mem_ctx, ldb_dn_get_linearized(dn)); -} - -/* - casefold a dn. We need to casefold the attribute names, and canonicalize - attribute values of case insensitive attributes. -*/ - -static bool ldb_dn_casefold_internal(struct ldb_dn *dn) -{ - int i, ret; - - if ( ! dn || dn->invalid) return false; - - if (dn->valid_case) return true; - - if (( ! dn->components) && ( ! ldb_dn_explode(dn))) { - return false; - } - - for (i = 0; i < dn->comp_num; i++) { - const struct ldb_schema_attribute *a; - - dn->components[i].cf_name = ldb_attr_casefold(dn->components, dn->components[i].name); - if (!dn->components[i].cf_name) { - goto failed; - } - - a = ldb_schema_attribute_by_name(dn->ldb, dn->components[i].cf_name); - ret = a->syntax->canonicalise_fn(dn->ldb, dn->components, - &(dn->components[i].value), - &(dn->components[i].cf_value)); - if (ret != 0) { - goto failed; - } - } - - dn->valid_case = true; - - return true; - -failed: - for (i = 0; i < dn->comp_num; i++) { - LDB_FREE(dn->components[i].cf_name); - LDB_FREE(dn->components[i].cf_value.data); - } - return false; -} - -const char *ldb_dn_get_casefold(struct ldb_dn *dn) -{ - int i, len; - char *d, *n; - - if (dn->casefold) return dn->casefold; - - if (dn->special) { - dn->casefold = talloc_strdup(dn, dn->linearized); - if (!dn->casefold) return NULL; - dn->valid_case = true; - return dn->casefold; - } - - if ( ! ldb_dn_casefold_internal(dn)) { - return NULL; - } - - if (dn->comp_num == 0) { - if (dn->linearized && dn->linearized[0] == '\0') { - /* hmm a NULL dn, should we faild casefolding ? */ - dn->casefold = talloc_strdup(dn, ""); - return dn->casefold; - } - /* A DN must be NULL, special, or have components */ - dn->invalid = true; - return NULL; - } - - /* calculate maximum possible length of DN */ - for (len = 0, i = 0; i < dn->comp_num; i++) { - len += strlen(dn->components[i].cf_name); /* name len */ - len += (dn->components[i].cf_value.length * 3); /* max escaped data len */ - len += 2; /* '=' and ',' */ - } - dn->casefold = talloc_array(dn, char, len); - if ( ! dn->casefold) return NULL; - - d = dn->casefold; - - for (i = 0; i < dn->comp_num; i++) { - - /* copy the name */ - n = dn->components[i].cf_name; - while (*n) *d++ = *n++; - - *d++ = '='; - - /* and the value */ - d += ldb_dn_escape_internal( d, - (char *)dn->components[i].cf_value.data, - dn->components[i].cf_value.length); - *d++ = ','; - } - *(--d) = '\0'; - - /* don't waste more memory than necessary */ - dn->casefold = talloc_realloc(dn, dn->casefold, char, strlen(dn->casefold) + 1); - - return dn->casefold; -} - -char *ldb_dn_alloc_casefold(void *mem_ctx, struct ldb_dn *dn) -{ - return talloc_strdup(mem_ctx, ldb_dn_get_casefold(dn)); -} - -/* Determine if dn is below base, in the ldap tree. Used for - * evaluating a subtree search. - * 0 if they match, otherwise non-zero - */ - -int ldb_dn_compare_base(struct ldb_dn *base, struct ldb_dn *dn) -{ - int ret; - int n_base, n_dn; - - if ( ! base || base->invalid) return 1; - if ( ! dn || dn->invalid) return -1; - - if (( ! base->valid_case) || ( ! dn->valid_case)) { - if (base->linearized && dn->linearized) { - /* try with a normal compare first, if we are lucky - * we will avoid exploding and casfolding */ - int dif; - dif = strlen(dn->linearized) - strlen(base->linearized); - if (dif < 0) return dif; - if (strcmp(base->linearized, &dn->linearized[dif]) == 0) return 0; - } - - if ( ! ldb_dn_casefold_internal(base)) { - return 1; - } - - if ( ! ldb_dn_casefold_internal(dn)) { - return -1; - } - - } - - /* if base has more components, - * they don't have the same base */ - if (base->comp_num > dn->comp_num) { - return (dn->comp_num - base->comp_num); - } - - if (dn->comp_num == 0) { - if (dn->special && base->special) { - return strcmp(base->linearized, dn->linearized); - } else if (dn->special) { - return -1; - } else if (base->special) { - return 1; - } else { - return 0; - } - } - - n_base = base->comp_num - 1; - n_dn = dn->comp_num - 1; - - while (n_base >= 0) { - /* compare attr names */ - ret = strcmp(base->components[n_base].cf_name, dn->components[n_dn].cf_name); - if (ret != 0) return ret; - - /* compare attr.cf_value. */ - if (base->components[n_base].cf_value.length != dn->components[n_dn].cf_value.length) { - return base->components[n_base].cf_value.length - dn->components[n_dn].cf_value.length; - } - ret = strcmp((char *)base->components[n_base].cf_value.data, (char *)dn->components[n_dn].cf_value.data); - if (ret != 0) return ret; - - n_base--; - n_dn--; - } - - return 0; -} - -/* compare DNs using casefolding compare functions. - - If they match, then return 0 - */ - -int ldb_dn_compare(struct ldb_dn *dn0, struct ldb_dn *dn1) -{ - int i, ret; - - if (( ! dn0) || dn0->invalid || ! dn1 || dn1->invalid) return -1; - - if (( ! dn0->valid_case) || ( ! dn1->valid_case)) { - if (dn0->linearized && dn1->linearized) { - /* try with a normal compare first, if we are lucky - * we will avoid exploding and casfolding */ - if (strcmp(dn0->linearized, dn1->linearized) == 0) return 0; - } - - if ( ! ldb_dn_casefold_internal(dn0)) { - return 1; - } - - if ( ! ldb_dn_casefold_internal(dn1)) { - return -1; - } - - } - - if (dn0->comp_num != dn1->comp_num) { - return (dn1->comp_num - dn0->comp_num); - } - - if (dn0->comp_num == 0) { - if (dn0->special && dn1->special) { - return strcmp(dn0->linearized, dn1->linearized); - } else if (dn0->special) { - return 1; - } else if (dn1->special) { - return -1; - } else { - return 0; - } - } - - for (i = 0; i < dn0->comp_num; i++) { - /* compare attr names */ - ret = strcmp(dn0->components[i].cf_name, dn1->components[i].cf_name); - if (ret != 0) return ret; - - /* compare attr.cf_value. */ - if (dn0->components[i].cf_value.length != dn1->components[i].cf_value.length) { - return dn0->components[i].cf_value.length - dn1->components[i].cf_value.length; - } - ret = strcmp((char *)dn0->components[i].cf_value.data, (char *)dn1->components[i].cf_value.data); - if (ret != 0) return ret; - } - - return 0; -} - -static struct ldb_dn_component ldb_dn_copy_component(void *mem_ctx, struct ldb_dn_component *src) -{ - struct ldb_dn_component dst; - - memset(&dst, 0, sizeof(dst)); - - if (src == NULL) { - return dst; - } - - dst.value = ldb_val_dup(mem_ctx, &(src->value)); - if (dst.value.data == NULL) { - return dst; - } - - dst.name = talloc_strdup(mem_ctx, src->name); - if (dst.name == NULL) { - LDB_FREE(dst.value.data); - return dst; - } - - if (src->cf_value.data) { - dst.cf_value = ldb_val_dup(mem_ctx, &(src->cf_value)); - if (dst.cf_value.data == NULL) { - LDB_FREE(dst.value.data); - LDB_FREE(dst.name); - return dst; - } - - dst.cf_name = talloc_strdup(mem_ctx, src->cf_name); - if (dst.cf_name == NULL) { - LDB_FREE(dst.cf_name); - LDB_FREE(dst.value.data); - LDB_FREE(dst.name); - return dst; - } - } else { - dst.cf_value.data = NULL; - dst.cf_name = NULL; - } - - return dst; -} - -static struct ldb_dn_extended_component ldb_dn_extended_copy_component(void *mem_ctx, struct ldb_dn_extended_component *src) -{ - struct ldb_dn_extended_component dst; - - memset(&dst, 0, sizeof(dst)); - - if (src == NULL) { - return dst; - } - - dst.value = ldb_val_dup(mem_ctx, &(src->value)); - if (dst.value.data == NULL) { - return dst; - } - - dst.name = talloc_strdup(mem_ctx, src->name); - if (dst.name == NULL) { - LDB_FREE(dst.value.data); - return dst; - } - - return dst; -} - -struct ldb_dn *ldb_dn_copy(void *mem_ctx, struct ldb_dn *dn) -{ - struct ldb_dn *new_dn; - - if (!dn || dn->invalid) { - return NULL; - } - - new_dn = talloc_zero(mem_ctx, struct ldb_dn); - if ( !new_dn) { - return NULL; - } - - *new_dn = *dn; - - if (dn->components) { - int i; - - new_dn->components = talloc_zero_array(new_dn, struct ldb_dn_component, dn->comp_num); - if ( ! new_dn->components) { - talloc_free(new_dn); - return NULL; - } - - for (i = 0; i < dn->comp_num; i++) { - new_dn->components[i] = ldb_dn_copy_component(new_dn->components, &dn->components[i]); - if ( ! new_dn->components[i].value.data) { - talloc_free(new_dn); - return NULL; - } - } - } - - if (dn->extended_components) { - int i; - - new_dn->extended_components = talloc_zero_array(new_dn, struct ldb_dn_extended_component, dn->extended_comp_num); - if ( ! new_dn->extended_components) { - talloc_free(new_dn); - return NULL; - } - - for (i = 0; i < dn->extended_comp_num; i++) { - new_dn->extended_components[i] = ldb_dn_extended_copy_component(new_dn->extended_components, &dn->extended_components[i]); - if ( ! new_dn->extended_components[i].value.data) { - talloc_free(new_dn); - return NULL; - } - } - } - - if (dn->casefold) { - new_dn->casefold = talloc_strdup(new_dn, dn->casefold); - if ( ! new_dn->casefold) { - talloc_free(new_dn); - return NULL; - } - } - - if (dn->linearized) { - new_dn->linearized = talloc_strdup(new_dn, dn->linearized); - if ( ! new_dn->linearized) { - talloc_free(new_dn); - return NULL; - } - } - - if (dn->extended_linearized) { - new_dn->extended_linearized = talloc_strdup(new_dn, dn->extended_linearized); - if ( ! new_dn->extended_linearized) { - talloc_free(new_dn); - return NULL; - } - } - - return new_dn; -} - -/* modify the given dn by adding a base. - * - * return true if successful and false if not - * if false is returned the dn may be marked invalid - */ -bool ldb_dn_add_base(struct ldb_dn *dn, struct ldb_dn *base) -{ - const char *s; - char *t; - - if ( !base || base->invalid || !dn || dn->invalid) { - return false; - } - - if (dn->components) { - int i; - - if ( ! ldb_dn_validate(base)) { - return false; - } - - s = NULL; - if (dn->valid_case) { - if ( ! (s = ldb_dn_get_casefold(base))) { - return false; - } - } - - dn->components = talloc_realloc(dn, - dn->components, - struct ldb_dn_component, - dn->comp_num + base->comp_num); - if ( ! dn->components) { - dn->invalid = true; - return false; - } - - for (i = 0; i < base->comp_num; dn->comp_num++, i++) { - dn->components[dn->comp_num] = ldb_dn_copy_component(dn->components, &base->components[i]); - if (dn->components[dn->comp_num].value.data == NULL) { - dn->invalid = true; - return false; - } - } - - if (dn->casefold && s) { - if (*dn->casefold) { - t = talloc_asprintf(dn, "%s,%s", dn->casefold, s); - } else { - t = talloc_strdup(dn, s); - } - LDB_FREE(dn->casefold); - dn->casefold = t; - } - } - - if (dn->linearized) { - - s = ldb_dn_get_linearized(base); - if ( ! s) { - return false; - } - - if (*dn->linearized) { - t = talloc_asprintf(dn, "%s,%s", dn->linearized, s); - } else { - t = talloc_strdup(dn, s); - } - if ( ! t) { - dn->invalid = true; - return false; - } - LDB_FREE(dn->linearized); - dn->linearized = t; - } - - /* Wipe the extended_linearized DN, as the GUID and SID are almost certainly no longer valid */ - if (dn->extended_linearized) { - LDB_FREE(dn->extended_linearized); - } - - LDB_FREE(dn->extended_components); - dn->extended_comp_num = 0; - return true; -} - -/* modify the given dn by adding a base. - * - * return true if successful and false if not - * if false is returned the dn may be marked invalid - */ -bool ldb_dn_add_base_fmt(struct ldb_dn *dn, const char *base_fmt, ...) -{ - struct ldb_dn *base; - char *base_str; - va_list ap; - bool ret; - - if ( !dn || dn->invalid) { - return false; - } - - va_start(ap, base_fmt); - base_str = talloc_vasprintf(dn, base_fmt, ap); - va_end(ap); - - if (base_str == NULL) { - return false; - } - - base = ldb_dn_new(base_str, dn->ldb, base_str); - - ret = ldb_dn_add_base(dn, base); - - talloc_free(base_str); - - return ret; -} - -/* modify the given dn by adding children elements. - * - * return true if successful and false if not - * if false is returned the dn may be marked invalid - */ -bool ldb_dn_add_child(struct ldb_dn *dn, struct ldb_dn *child) -{ - const char *s; - char *t; - - if ( !child || child->invalid || !dn || dn->invalid) { - return false; - } - - if (dn->components) { - int n, i, j; - - if ( ! ldb_dn_validate(child)) { - return false; - } - - s = NULL; - if (dn->valid_case) { - if ( ! (s = ldb_dn_get_casefold(child))) { - return false; - } - } - - n = dn->comp_num + child->comp_num; - - dn->components = talloc_realloc(dn, - dn->components, - struct ldb_dn_component, - n); - if ( ! dn->components) { - dn->invalid = true; - return false; - } - - for (i = dn->comp_num - 1, j = n - 1; i >= 0; i--, j--) { - dn->components[j] = dn->components[i]; - } - - for (i = 0; i < child->comp_num; i++) { - dn->components[i] = ldb_dn_copy_component(dn->components, &child->components[i]); - if (dn->components[i].value.data == NULL) { - dn->invalid = true; - return false; - } - } - - dn->comp_num = n; - - if (dn->casefold && s) { - t = talloc_asprintf(dn, "%s,%s", s, dn->casefold); - LDB_FREE(dn->casefold); - dn->casefold = t; - } - } - - if (dn->linearized) { - - s = ldb_dn_get_linearized(child); - if ( ! s) { - return false; - } - - t = talloc_asprintf(dn, "%s,%s", s, dn->linearized); - if ( ! t) { - dn->invalid = true; - return false; - } - LDB_FREE(dn->linearized); - dn->linearized = t; - } - - /* Wipe the extended_linearized DN, as the GUID and SID are almost certainly no longer valid */ - LDB_FREE(dn->extended_linearized); - - LDB_FREE(dn->extended_components); - dn->extended_comp_num = 0; - - return true; -} - -/* modify the given dn by adding children elements. - * - * return true if successful and false if not - * if false is returned the dn may be marked invalid - */ -bool ldb_dn_add_child_fmt(struct ldb_dn *dn, const char *child_fmt, ...) -{ - struct ldb_dn *child; - char *child_str; - va_list ap; - bool ret; - - if ( !dn || dn->invalid) { - return false; - } - - va_start(ap, child_fmt); - child_str = talloc_vasprintf(dn, child_fmt, ap); - va_end(ap); - - if (child_str == NULL) { - return false; - } - - child = ldb_dn_new(child_str, dn->ldb, child_str); - - ret = ldb_dn_add_child(dn, child); - - talloc_free(child_str); - - return ret; -} - -bool ldb_dn_remove_base_components(struct ldb_dn *dn, unsigned int num) -{ - int i; - - if ( ! ldb_dn_validate(dn)) { - return false; - } - - if (dn->comp_num < num) { - return false; - } - - /* free components */ - for (i = num; i > 0; i--) { - LDB_FREE(dn->components[dn->comp_num - i].name); - LDB_FREE(dn->components[dn->comp_num - i].value.data); - LDB_FREE(dn->components[dn->comp_num - i].cf_name); - LDB_FREE(dn->components[dn->comp_num - i].cf_value.data); - } - - dn->comp_num -= num; - - if (dn->valid_case) { - for (i = 0; i < dn->comp_num; i++) { - LDB_FREE(dn->components[i].cf_name); - LDB_FREE(dn->components[i].cf_value.data); - } - dn->valid_case = false; - } - - LDB_FREE(dn->casefold); - LDB_FREE(dn->linearized); - - /* Wipe the extended_linearized DN, as the GUID and SID are almost certainly no longer valid */ - LDB_FREE(dn->extended_linearized); - - LDB_FREE(dn->extended_components); - dn->extended_comp_num = 0; - - return true; -} - -bool ldb_dn_remove_child_components(struct ldb_dn *dn, unsigned int num) -{ - int i, j; - - if ( ! ldb_dn_validate(dn)) { - return false; - } - - if (dn->comp_num < num) { - return false; - } - - for (i = 0, j = num; j < dn->comp_num; i++, j++) { - if (i < num) { - LDB_FREE(dn->components[i].name); - LDB_FREE(dn->components[i].value.data); - LDB_FREE(dn->components[i].cf_name); - LDB_FREE(dn->components[i].cf_value.data); - } - dn->components[i] = dn->components[j]; - } - - dn->comp_num -= num; - - if (dn->valid_case) { - for (i = 0; i < dn->comp_num; i++) { - LDB_FREE(dn->components[i].cf_name); - LDB_FREE(dn->components[i].cf_value.data); - } - dn->valid_case = false; - } - - LDB_FREE(dn->casefold); - LDB_FREE(dn->linearized); - - /* Wipe the extended_linearized DN, as the GUID and SID are almost certainly no longer valid */ - LDB_FREE(dn->extended_linearized); - - LDB_FREE(dn->extended_components); - dn->extended_comp_num = 0; - return true; -} - -struct ldb_dn *ldb_dn_get_parent(void *mem_ctx, struct ldb_dn *dn) -{ - struct ldb_dn *new_dn; - - new_dn = ldb_dn_copy(mem_ctx, dn); - if ( !new_dn ) { - return NULL; - } - - if ( ! ldb_dn_remove_child_components(new_dn, 1)) { - talloc_free(new_dn); - return NULL; - } - - /* Wipe the extended_linearized DN, as the GUID and SID are almost certainly no longer valid */ - LDB_FREE(dn->extended_linearized); - - LDB_FREE(dn->extended_components); - dn->extended_comp_num = 0; - return new_dn; -} - -/* Create a 'canonical name' string from a DN: - - ie dc=samba,dc=org -> samba.org/ - uid=administrator,ou=users,dc=samba,dc=org = samba.org/users/administrator - - There are two formats, the EX format has the last / replaced with a newline (\n). - -*/ -static char *ldb_dn_canonical(void *mem_ctx, struct ldb_dn *dn, int ex_format) { - int i; - TALLOC_CTX *tmpctx; - char *cracked = NULL; - const char *format = (ex_format ? "\n" : "/" ); - - if ( ! ldb_dn_validate(dn)) { - return NULL; - } - - tmpctx = talloc_new(mem_ctx); - - /* Walk backwards down the DN, grabbing 'dc' components at first */ - for (i = dn->comp_num - 1 ; i >= 0; i--) { - if (ldb_attr_cmp(dn->components[i].name, "dc") != 0) { - break; - } - if (cracked) { - cracked = talloc_asprintf(tmpctx, "%s.%s", - ldb_dn_escape_value(tmpctx, dn->components[i].value), - cracked); - } else { - cracked = ldb_dn_escape_value(tmpctx, dn->components[i].value); - } - if (!cracked) { - goto done; - } - } - - /* Only domain components? Finish here */ - if (i < 0) { - cracked = talloc_strdup_append_buffer(cracked, format); - talloc_steal(mem_ctx, cracked); - goto done; - } - - /* Now walk backwards appending remaining components */ - for (; i > 0; i--) { - cracked = talloc_asprintf_append_buffer(cracked, "/%s", - ldb_dn_escape_value(tmpctx, dn->components[i].value)); - if (!cracked) { - goto done; - } - } - - /* Last one, possibly a newline for the 'ex' format */ - cracked = talloc_asprintf_append_buffer(cracked, "%s%s", format, - ldb_dn_escape_value(tmpctx, dn->components[i].value)); - - talloc_steal(mem_ctx, cracked); -done: - talloc_free(tmpctx); - return cracked; -} - -/* Wrapper functions for the above, for the two different string formats */ -char *ldb_dn_canonical_string(void *mem_ctx, struct ldb_dn *dn) { - return ldb_dn_canonical(mem_ctx, dn, 0); - -} - -char *ldb_dn_canonical_ex_string(void *mem_ctx, struct ldb_dn *dn) { - return ldb_dn_canonical(mem_ctx, dn, 1); -} - -int ldb_dn_get_comp_num(struct ldb_dn *dn) -{ - if ( ! ldb_dn_validate(dn)) { - return -1; - } - return dn->comp_num; -} - -const char *ldb_dn_get_component_name(struct ldb_dn *dn, unsigned int num) -{ - if ( ! ldb_dn_validate(dn)) { - return NULL; - } - if (num >= dn->comp_num) return NULL; - return dn->components[num].name; -} - -const struct ldb_val *ldb_dn_get_component_val(struct ldb_dn *dn, unsigned int num) -{ - if ( ! ldb_dn_validate(dn)) { - return NULL; - } - if (num >= dn->comp_num) return NULL; - return &dn->components[num].value; -} - -const char *ldb_dn_get_rdn_name(struct ldb_dn *dn) -{ - if ( ! ldb_dn_validate(dn)) { - return NULL; - } - if (dn->comp_num == 0) return NULL; - return dn->components[0].name; -} - -const struct ldb_val *ldb_dn_get_rdn_val(struct ldb_dn *dn) -{ - if ( ! ldb_dn_validate(dn)) { - return NULL; - } - if (dn->comp_num == 0) return NULL; - return &dn->components[0].value; -} - -int ldb_dn_set_component(struct ldb_dn *dn, int num, const char *name, const struct ldb_val val) -{ - char *n; - struct ldb_val v; - - if ( ! ldb_dn_validate(dn)) { - return LDB_ERR_OTHER; - } - - if (num >= dn->comp_num) { - return LDB_ERR_OTHER; - } - - n = talloc_strdup(dn, name); - if ( ! n) { - return LDB_ERR_OTHER; - } - - v.length = val.length; - v.data = (uint8_t *)talloc_memdup(dn, val.data, v.length+1); - if ( ! v.data) { - talloc_free(n); - return LDB_ERR_OTHER; - } - - talloc_free(dn->components[num].name); - talloc_free(dn->components[num].value.data); - dn->components[num].name = n; - dn->components[num].value = v; - - if (dn->valid_case) { - int i; - for (i = 0; i < dn->comp_num; i++) { - LDB_FREE(dn->components[i].cf_name); - LDB_FREE(dn->components[i].cf_value.data); - } - dn->valid_case = false; - } - LDB_FREE(dn->casefold); - LDB_FREE(dn->linearized); - - /* Wipe the extended_linearized DN, as the GUID and SID are almost certainly no longer valid */ - LDB_FREE(dn->extended_linearized); - - dn->extended_comp_num = 0; - LDB_FREE(dn->extended_components); - return LDB_SUCCESS; -} - -const struct ldb_val *ldb_dn_get_extended_component(struct ldb_dn *dn, const char *name) -{ - int i; - if ( ! ldb_dn_validate(dn)) { - return NULL; - } - for (i=0; i < dn->extended_comp_num; i++) { - if (ldb_attr_cmp(dn->extended_components[i].name, name) == 0) { - return &dn->extended_components[i].value; - } - } - return NULL; -} - -int ldb_dn_set_extended_component(struct ldb_dn *dn, const char *name, const struct ldb_val *val) -{ - struct ldb_dn_extended_component *p; - int i; - - if ( ! ldb_dn_validate(dn)) { - return LDB_ERR_OTHER; - } - - for (i=0; i < dn->extended_comp_num; i++) { - if (ldb_attr_cmp(dn->extended_components[i].name, name) == 0) { - if (val) { - dn->extended_components[i].value = ldb_val_dup(dn->extended_components, val); - - dn->extended_components[i].name = talloc_strdup(dn->extended_components, name); - if (!dn->extended_components[i].name || !dn->extended_components[i].value.data) { - dn->invalid = true; - return LDB_ERR_OPERATIONS_ERROR; - } - - } else { - if (i != (dn->extended_comp_num - 1)) { - memmove(&dn->extended_components[i], &dn->extended_components[i+1], - ((dn->extended_comp_num-1) - i)*sizeof(*dn->extended_components)); - } - dn->extended_comp_num--; - - dn->extended_components = talloc_realloc(dn, - dn->extended_components, - struct ldb_dn_extended_component, - dn->extended_comp_num); - if (!dn->extended_components) { - dn->invalid = true; - return LDB_ERR_OPERATIONS_ERROR; - } - return LDB_SUCCESS; - } - } - } - - p = dn->extended_components - = talloc_realloc(dn, - dn->extended_components, - struct ldb_dn_extended_component, - dn->extended_comp_num + 1); - if (!dn->extended_components) { - dn->invalid = true; - return LDB_ERR_OPERATIONS_ERROR; - } - - p[dn->extended_comp_num].value = ldb_val_dup(dn->extended_components, val); - p[dn->extended_comp_num].name = talloc_strdup(p, name); - - if (!dn->extended_components[i].name || !dn->extended_components[i].value.data) { - dn->invalid = true; - return LDB_ERR_OPERATIONS_ERROR; - } - dn->extended_components = p; - dn->extended_comp_num++; - - return LDB_SUCCESS; -} - -void ldb_dn_remove_extended_components(struct ldb_dn *dn) -{ - dn->extended_comp_num = 0; - LDB_FREE(dn->extended_components); -} - -bool ldb_dn_is_valid(struct ldb_dn *dn) -{ - if ( ! dn) return false; - return ! dn->invalid; -} - -bool ldb_dn_is_special(struct ldb_dn *dn) -{ - if ( ! dn || dn->invalid) return false; - return dn->special; -} - -bool ldb_dn_has_extended(struct ldb_dn *dn) -{ - if ( ! dn || dn->invalid) return false; - if (dn->extended_linearized && (dn->extended_linearized[0] == '<')) return true; - return dn->extended_comp_num != 0; -} - -bool ldb_dn_check_special(struct ldb_dn *dn, const char *check) -{ - if ( ! dn || dn->invalid) return false; - return ! strcmp(dn->linearized, check); -} - -bool ldb_dn_is_null(struct ldb_dn *dn) -{ - if ( ! dn || dn->invalid) return false; - if (ldb_dn_has_extended(dn)) return false; - if (dn->linearized && (dn->linearized[0] == '\0')) return true; - return false; -} diff --git a/ldb/common/ldb_ldif.c b/ldb/common/ldb_ldif.c deleted file mode 100644 index 619c10e11..000000000 --- a/ldb/common/ldb_ldif.c +++ /dev/null @@ -1,761 +0,0 @@ -/* - ldb database library - - Copyright (C) Andrew Tridgell 2004 - - ** 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -/* - * Name: ldb - * - * Component: ldif routines - * - * Description: ldif pack/unpack routines - * - * Author: Andrew Tridgell - */ - -/* - see RFC2849 for the LDIF format definition -*/ - -#include "ldb_includes.h" -#include "system/locale.h" - -/* - -*/ -static int ldb_read_data_file(void *mem_ctx, struct ldb_val *value) -{ - struct stat statbuf; - char *buf; - int count, size, bytes; - int ret; - int f; - const char *fname = (const char *)value->data; - - if (strncmp(fname, "file://", 7) != 0) { - return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX; - } - fname += 7; - - f = open(fname, O_RDONLY); - if (f == -1) { - return -1; - } - - if (fstat(f, &statbuf) != 0) { - ret = -1; - goto done; - } - - if (statbuf.st_size == 0) { - ret = -1; - goto done; - } - - value->data = (uint8_t *)talloc_size(mem_ctx, statbuf.st_size + 1); - if (value->data == NULL) { - ret = -1; - goto done; - } - value->data[statbuf.st_size] = 0; - - count = 0; - size = statbuf.st_size; - buf = (char *)value->data; - while (count < statbuf.st_size) { - bytes = read(f, buf, size); - if (bytes == -1) { - talloc_free(value->data); - ret = -1; - goto done; - } - count += bytes; - buf += bytes; - size -= bytes; - } - - value->length = statbuf.st_size; - ret = statbuf.st_size; - -done: - close(f); - return ret; -} - -/* - this base64 decoder was taken from jitterbug (written by tridge). - we might need to replace it with a new version -*/ -int ldb_base64_decode(char *s) -{ - const char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - int bit_offset=0, byte_offset, idx, i, n; - uint8_t *d = (uint8_t *)s; - char *p=NULL; - - n=i=0; - - while (*s && (p=strchr(b64,*s))) { - idx = (int)(p - b64); - byte_offset = (i*6)/8; - bit_offset = (i*6)%8; - d[byte_offset] &= ~((1<<(8-bit_offset))-1); - if (bit_offset < 3) { - d[byte_offset] |= (idx << (2-bit_offset)); - n = byte_offset+1; - } else { - d[byte_offset] |= (idx >> (bit_offset-2)); - d[byte_offset+1] = 0; - d[byte_offset+1] |= (idx << (8-(bit_offset-2))) & 0xFF; - n = byte_offset+2; - } - s++; i++; - } - if (bit_offset >= 3) { - n--; - } - - if (*s && !p) { - /* the only termination allowed */ - if (*s != '=') { - return -1; - } - } - - /* null terminate */ - d[n] = 0; - return n; -} - - -/* - encode as base64 - caller frees -*/ -char *ldb_base64_encode(void *mem_ctx, const char *buf, int len) -{ - const char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - int bit_offset, byte_offset, idx, i; - const uint8_t *d = (const uint8_t *)buf; - int bytes = (len*8 + 5)/6, pad_bytes = (bytes % 4) ? 4 - (bytes % 4) : 0; - char *out; - - out = talloc_array(mem_ctx, char, bytes+pad_bytes+1); - if (!out) return NULL; - - for (i=0;i<bytes;i++) { - byte_offset = (i*6)/8; - bit_offset = (i*6)%8; - if (bit_offset < 3) { - idx = (d[byte_offset] >> (2-bit_offset)) & 0x3F; - } else { - idx = (d[byte_offset] << (bit_offset-2)) & 0x3F; - if (byte_offset+1 < len) { - idx |= (d[byte_offset+1] >> (8-(bit_offset-2))); - } - } - out[i] = b64[idx]; - } - - for (;i<bytes+pad_bytes;i++) - out[i] = '='; - out[i] = 0; - - return out; -} - -/* - see if a buffer should be base64 encoded -*/ -int ldb_should_b64_encode(const struct ldb_val *val) -{ - unsigned int i; - uint8_t *p = val->data; - - if (val->length == 0) { - return 0; - } - - if (p[0] == ' ' || p[0] == ':') { - return 1; - } - - for (i=0; i<val->length; i++) { - if (!isprint(p[i]) || p[i] == '\n') { - return 1; - } - } - return 0; -} - -/* this macro is used to handle the return checking on fprintf_fn() */ -#define CHECK_RET do { if (ret < 0) return ret; total += ret; } while (0) - -/* - write a line folded string onto a file -*/ -static int fold_string(int (*fprintf_fn)(void *, const char *, ...), void *private_data, - const char *buf, size_t length, int start_pos) -{ - unsigned int i; - int total=0, ret; - - for (i=0;i<length;i++) { - ret = fprintf_fn(private_data, "%c", buf[i]); - CHECK_RET; - if (i != (length-1) && (i + start_pos) % 77 == 0) { - ret = fprintf_fn(private_data, "\n "); - CHECK_RET; - } - } - - return total; -} - -#undef CHECK_RET - -/* - encode as base64 to a file -*/ -static int base64_encode_f(struct ldb_context *ldb, - int (*fprintf_fn)(void *, const char *, ...), - void *private_data, - const char *buf, int len, int start_pos) -{ - char *b = ldb_base64_encode(ldb, buf, len); - int ret; - - if (!b) { - return -1; - } - - ret = fold_string(fprintf_fn, private_data, b, strlen(b), start_pos); - - talloc_free(b); - return ret; -} - - -static const struct { - const char *name; - enum ldb_changetype changetype; -} ldb_changetypes[] = { - {"add", LDB_CHANGETYPE_ADD}, - {"delete", LDB_CHANGETYPE_DELETE}, - {"modify", LDB_CHANGETYPE_MODIFY}, - {NULL, 0} -}; - -/* this macro is used to handle the return checking on fprintf_fn() */ -#define CHECK_RET do { if (ret < 0) { talloc_free(mem_ctx); return ret; } total += ret; } while (0) - -/* - write to ldif, using a caller supplied write method -*/ -int ldb_ldif_write(struct ldb_context *ldb, - int (*fprintf_fn)(void *, const char *, ...), - void *private_data, - const struct ldb_ldif *ldif) -{ - TALLOC_CTX *mem_ctx; - unsigned int i, j; - int total=0, ret; - char *p; - const struct ldb_message *msg; - - mem_ctx = talloc_named_const(NULL, 0, "ldb_ldif_write"); - - msg = ldif->msg; - p = ldb_dn_get_extended_linearized(mem_ctx, msg->dn, 1); - ret = fprintf_fn(private_data, "dn: %s\n", p); - talloc_free(p); - CHECK_RET; - - if (ldif->changetype != LDB_CHANGETYPE_NONE) { - for (i=0;ldb_changetypes[i].name;i++) { - if (ldb_changetypes[i].changetype == ldif->changetype) { - break; - } - } - if (!ldb_changetypes[i].name) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "Error: Invalid ldif changetype %d\n", - ldif->changetype); - talloc_free(mem_ctx); - return -1; - } - ret = fprintf_fn(private_data, "changetype: %s\n", ldb_changetypes[i].name); - CHECK_RET; - } - - for (i=0;i<msg->num_elements;i++) { - const struct ldb_schema_attribute *a; - - a = ldb_schema_attribute_by_name(ldb, msg->elements[i].name); - - if (ldif->changetype == LDB_CHANGETYPE_MODIFY) { - switch (msg->elements[i].flags & LDB_FLAG_MOD_MASK) { - case LDB_FLAG_MOD_ADD: - fprintf_fn(private_data, "add: %s\n", - msg->elements[i].name); - break; - case LDB_FLAG_MOD_DELETE: - fprintf_fn(private_data, "delete: %s\n", - msg->elements[i].name); - break; - case LDB_FLAG_MOD_REPLACE: - fprintf_fn(private_data, "replace: %s\n", - msg->elements[i].name); - break; - } - } - - for (j=0;j<msg->elements[i].num_values;j++) { - struct ldb_val v; - ret = a->syntax->ldif_write_fn(ldb, mem_ctx, &msg->elements[i].values[j], &v); - if (ret != LDB_SUCCESS) { - v = msg->elements[i].values[j]; - } - if (ret != LDB_SUCCESS || ldb_should_b64_encode(&v)) { - ret = fprintf_fn(private_data, "%s:: ", - msg->elements[i].name); - CHECK_RET; - ret = base64_encode_f(ldb, fprintf_fn, private_data, - (char *)v.data, v.length, - strlen(msg->elements[i].name)+3); - CHECK_RET; - ret = fprintf_fn(private_data, "\n"); - CHECK_RET; - } else { - ret = fprintf_fn(private_data, "%s: ", msg->elements[i].name); - CHECK_RET; - ret = fold_string(fprintf_fn, private_data, - (char *)v.data, v.length, - strlen(msg->elements[i].name)+2); - CHECK_RET; - ret = fprintf_fn(private_data, "\n"); - CHECK_RET; - } - if (v.data != msg->elements[i].values[j].data) { - talloc_free(v.data); - } - } - if (ldif->changetype == LDB_CHANGETYPE_MODIFY) { - fprintf_fn(private_data, "-\n"); - } - } - ret = fprintf_fn(private_data,"\n"); - CHECK_RET; - - return total; -} - -#undef CHECK_RET - - -/* - pull a ldif chunk, which is defined as a piece of data ending in \n\n or EOF - this routine removes any RFC2849 continuations and comments - - caller frees -*/ -static char *next_chunk(struct ldb_context *ldb, - int (*fgetc_fn)(void *), void *private_data) -{ - size_t alloc_size=0, chunk_size = 0; - char *chunk = NULL; - int c; - int in_comment = 0; - - while ((c = fgetc_fn(private_data)) != EOF) { - if (chunk_size+1 >= alloc_size) { - char *c2; - alloc_size += 1024; - c2 = talloc_realloc(ldb, chunk, char, alloc_size); - if (!c2) { - talloc_free(chunk); - errno = ENOMEM; - return NULL; - } - chunk = c2; - } - - if (in_comment) { - if (c == '\n') { - in_comment = 0; - } - continue; - } - - /* handle continuation lines - see RFC2849 */ - if (c == ' ' && chunk_size > 1 && chunk[chunk_size-1] == '\n') { - chunk_size--; - continue; - } - - /* chunks are terminated by a double line-feed */ - if (c == '\n' && chunk_size > 0 && chunk[chunk_size-1] == '\n') { - chunk[chunk_size-1] = 0; - return chunk; - } - - if (c == '#' && (chunk_size == 0 || chunk[chunk_size-1] == '\n')) { - in_comment = 1; - continue; - } - - /* ignore leading blank lines */ - if (chunk_size == 0 && c == '\n') { - continue; - } - - chunk[chunk_size++] = c; - } - - if (chunk) { - chunk[chunk_size] = 0; - } - - return chunk; -} - - -/* simple ldif attribute parser */ -static int next_attr(void *mem_ctx, char **s, const char **attr, struct ldb_val *value) -{ - char *p; - int base64_encoded = 0; - int binary_file = 0; - - if (strncmp(*s, "-\n", 2) == 0) { - value->length = 0; - *attr = "-"; - *s += 2; - return 0; - } - - p = strchr(*s, ':'); - if (!p) { - return -1; - } - - *p++ = 0; - - if (*p == ':') { - base64_encoded = 1; - p++; - } - - if (*p == '<') { - binary_file = 1; - p++; - } - - *attr = *s; - - while (*p == ' ' || *p == '\t') { - p++; - } - - value->data = (uint8_t *)p; - - p = strchr(p, '\n'); - - if (!p) { - value->length = strlen((char *)value->data); - *s = ((char *)value->data) + value->length; - } else { - value->length = p - (char *)value->data; - *s = p+1; - *p = 0; - } - - if (base64_encoded) { - int len = ldb_base64_decode((char *)value->data); - if (len == -1) { - /* it wasn't valid base64 data */ - return -1; - } - value->length = len; - } - - if (binary_file) { - int len = ldb_read_data_file(mem_ctx, value); - if (len == -1) { - /* an error occured hile trying to retrieve the file */ - return -1; - } - } - - return 0; -} - - -/* - free a message from a ldif_read -*/ -void ldb_ldif_read_free(struct ldb_context *ldb, struct ldb_ldif *ldif) -{ - talloc_free(ldif); -} - -/* - read from a LDIF source, creating a ldb_message -*/ -struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb, - int (*fgetc_fn)(void *), void *private_data) -{ - struct ldb_ldif *ldif; - struct ldb_message *msg; - const char *attr=NULL; - char *chunk=NULL, *s; - struct ldb_val value; - unsigned flags = 0; - - value.data = NULL; - - ldif = talloc(ldb, struct ldb_ldif); - if (!ldif) return NULL; - - ldif->msg = talloc(ldif, struct ldb_message); - if (ldif->msg == NULL) { - talloc_free(ldif); - return NULL; - } - - ldif->changetype = LDB_CHANGETYPE_NONE; - msg = ldif->msg; - - msg->dn = NULL; - msg->elements = NULL; - msg->num_elements = 0; - - chunk = next_chunk(ldb, fgetc_fn, private_data); - if (!chunk) { - goto failed; - } - talloc_steal(ldif, chunk); - - s = chunk; - - if (next_attr(ldif, &s, &attr, &value) != 0) { - goto failed; - } - - /* first line must be a dn */ - if (ldb_attr_cmp(attr, "dn") != 0) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "Error: First line of ldif must be a dn not '%s'\n", - attr); - goto failed; - } - - msg->dn = ldb_dn_from_ldb_val(msg, ldb, &value); - - if ( ! ldb_dn_validate(msg->dn)) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "Error: Unable to parse dn '%s'\n", - (char *)value.data); - goto failed; - } - - while (next_attr(ldif, &s, &attr, &value) == 0) { - const struct ldb_schema_attribute *a; - struct ldb_message_element *el; - int ret, empty = 0; - - if (ldb_attr_cmp(attr, "changetype") == 0) { - int i; - for (i=0;ldb_changetypes[i].name;i++) { - if (ldb_attr_cmp((char *)value.data, ldb_changetypes[i].name) == 0) { - ldif->changetype = ldb_changetypes[i].changetype; - break; - } - } - if (!ldb_changetypes[i].name) { - ldb_debug(ldb, LDB_DEBUG_ERROR, - "Error: Bad ldif changetype '%s'\n",(char *)value.data); - } - flags = 0; - continue; - } - - if (ldb_attr_cmp(attr, "add") == 0) { - flags = LDB_FLAG_MOD_ADD; - empty = 1; - } - if (ldb_attr_cmp(attr, "delete") == 0) { - flags = LDB_FLAG_MOD_DELETE; - empty = 1; - } - if (ldb_attr_cmp(attr, "replace") == 0) { - flags = LDB_FLAG_MOD_REPLACE; - empty = 1; - } - if (ldb_attr_cmp(attr, "-") == 0) { - flags = 0; - continue; - } - - if (empty) { - if (ldb_msg_add_empty(msg, (char *)value.data, flags, NULL) != 0) { - goto failed; - } - continue; - } - - el = &msg->elements[msg->num_elements-1]; - - a = ldb_schema_attribute_by_name(ldb, attr); - - if (msg->num_elements > 0 && ldb_attr_cmp(attr, el->name) == 0 && - flags == el->flags) { - /* its a continuation */ - el->values = - talloc_realloc(msg->elements, el->values, - struct ldb_val, el->num_values+1); - if (!el->values) { - goto failed; - } - ret = a->syntax->ldif_read_fn(ldb, ldif, &value, &el->values[el->num_values]); - if (ret != 0) { - goto failed; - } - if (value.length == 0) { - ldb_debug(ldb, LDB_DEBUG_ERROR, - "Error: Attribute value cannot be empty for attribute '%s'\n", el->name); - goto failed; - } - if (value.data != el->values[el->num_values].data) { - talloc_steal(el->values, el->values[el->num_values].data); - } - el->num_values++; - } else { - /* its a new attribute */ - msg->elements = talloc_realloc(ldif, msg->elements, - struct ldb_message_element, - msg->num_elements+1); - if (!msg->elements) { - goto failed; - } - el = &msg->elements[msg->num_elements]; - el->flags = flags; - el->name = talloc_strdup(msg->elements, attr); - el->values = talloc(msg->elements, struct ldb_val); - if (!el->values || !el->name) { - goto failed; - } - el->num_values = 1; - ret = a->syntax->ldif_read_fn(ldb, ldif, &value, &el->values[0]); - if (ret != 0) { - goto failed; - } - if (value.data != el->values[0].data) { - talloc_steal(el->values, el->values[0].data); - } - msg->num_elements++; - } - } - - return ldif; - -failed: - talloc_free(ldif); - return NULL; -} - - - -/* - a wrapper around ldif_read() for reading from FILE* -*/ -struct ldif_read_file_state { - FILE *f; -}; - -static int fgetc_file(void *private_data) -{ - struct ldif_read_file_state *state = - (struct ldif_read_file_state *)private_data; - return fgetc(state->f); -} - -struct ldb_ldif *ldb_ldif_read_file(struct ldb_context *ldb, FILE *f) -{ - struct ldif_read_file_state state; - state.f = f; - return ldb_ldif_read(ldb, fgetc_file, &state); -} - - -/* - a wrapper around ldif_read() for reading from const char* -*/ -struct ldif_read_string_state { - const char *s; -}; - -static int fgetc_string(void *private_data) -{ - struct ldif_read_string_state *state = - (struct ldif_read_string_state *)private_data; - if (state->s[0] != 0) { - return *state->s++; - } - return EOF; -} - -struct ldb_ldif *ldb_ldif_read_string(struct ldb_context *ldb, const char **s) -{ - struct ldif_read_string_state state; - struct ldb_ldif *ldif; - state.s = *s; - ldif = ldb_ldif_read(ldb, fgetc_string, &state); - *s = state.s; - return ldif; -} - - -/* - wrapper around ldif_write() for a file -*/ -struct ldif_write_file_state { - FILE *f; -}; - -static int fprintf_file(void *private_data, const char *fmt, ...) PRINTF_ATTRIBUTE(2, 3); - -static int fprintf_file(void *private_data, const char *fmt, ...) -{ - struct ldif_write_file_state *state = - (struct ldif_write_file_state *)private_data; - int ret; - va_list ap; - - va_start(ap, fmt); - ret = vfprintf(state->f, fmt, ap); - va_end(ap); - return ret; -} - -int ldb_ldif_write_file(struct ldb_context *ldb, FILE *f, const struct ldb_ldif *ldif) -{ - struct ldif_write_file_state state; - state.f = f; - return ldb_ldif_write(ldb, fprintf_file, &state, ldif); -} diff --git a/ldb/common/ldb_match.c b/ldb/common/ldb_match.c deleted file mode 100644 index 4cde739d6..000000000 --- a/ldb/common/ldb_match.c +++ /dev/null @@ -1,428 +0,0 @@ -/* - ldb database library - - Copyright (C) Andrew Tridgell 2004-2005 - Copyright (C) Simo Sorce 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -/* - * Name: ldb - * - * Component: ldb expression matching - * - * Description: ldb expression matching - * - * Author: Andrew Tridgell - */ - -#include "ldb_includes.h" - -/* - check if the scope matches in a search result -*/ -static int ldb_match_scope(struct ldb_context *ldb, - struct ldb_dn *base, - struct ldb_dn *dn, - enum ldb_scope scope) -{ - int ret = 0; - - if (base == NULL || dn == NULL) { - return 1; - } - - switch (scope) { - case LDB_SCOPE_BASE: - if (ldb_dn_compare(base, dn) == 0) { - ret = 1; - } - break; - - case LDB_SCOPE_ONELEVEL: - if (ldb_dn_get_comp_num(dn) == (ldb_dn_get_comp_num(base) + 1)) { - if (ldb_dn_compare_base(base, dn) == 0) { - ret = 1; - } - } - break; - - case LDB_SCOPE_SUBTREE: - default: - if (ldb_dn_compare_base(base, dn) == 0) { - ret = 1; - } - break; - } - - return ret; -} - - -/* - match if node is present -*/ -static int ldb_match_present(struct ldb_context *ldb, - const struct ldb_message *msg, - const struct ldb_parse_tree *tree, - enum ldb_scope scope) -{ - if (ldb_attr_dn(tree->u.present.attr) == 0) { - return 1; - } - - if (ldb_msg_find_element(msg, tree->u.present.attr)) { - return 1; - } - - return 0; -} - -static int ldb_match_comparison(struct ldb_context *ldb, - const struct ldb_message *msg, - const struct ldb_parse_tree *tree, - enum ldb_scope scope, - enum ldb_parse_op comp_op) -{ - unsigned int i; - struct ldb_message_element *el; - const struct ldb_schema_attribute *a; - int ret; - - /* FIXME: APPROX comparison not handled yet */ - if (comp_op == LDB_OP_APPROX) return 0; - - el = ldb_msg_find_element(msg, tree->u.comparison.attr); - if (el == NULL) { - return 0; - } - - a = ldb_schema_attribute_by_name(ldb, el->name); - - for (i = 0; i < el->num_values; i++) { - ret = a->syntax->comparison_fn(ldb, ldb, &el->values[i], &tree->u.comparison.value); - - if (ret == 0) { - return 1; - } - if (ret > 0 && comp_op == LDB_OP_GREATER) { - return 1; - } - if (ret < 0 && comp_op == LDB_OP_LESS) { - return 1; - } - } - - return 0; -} - -/* - match a simple leaf node -*/ -static int ldb_match_equality(struct ldb_context *ldb, - const struct ldb_message *msg, - const struct ldb_parse_tree *tree, - enum ldb_scope scope) -{ - unsigned int i; - struct ldb_message_element *el; - const struct ldb_schema_attribute *a; - struct ldb_dn *valuedn; - int ret; - - if (ldb_attr_dn(tree->u.equality.attr) == 0) { - valuedn = ldb_dn_from_ldb_val(ldb, ldb, &tree->u.equality.value); - if (valuedn == NULL) { - return 0; - } - - ret = ldb_dn_compare(msg->dn, valuedn); - - talloc_free(valuedn); - - if (ret == 0) return 1; - return 0; - } - - /* TODO: handle the "*" case derived from an extended search - operation without the attibute type defined */ - el = ldb_msg_find_element(msg, tree->u.equality.attr); - if (el == NULL) { - return 0; - } - - a = ldb_schema_attribute_by_name(ldb, el->name); - - for (i=0;i<el->num_values;i++) { - if (a->syntax->comparison_fn(ldb, ldb, &tree->u.equality.value, - &el->values[i]) == 0) { - return 1; - } - } - - return 0; -} - -static int ldb_wildcard_compare(struct ldb_context *ldb, - const struct ldb_parse_tree *tree, - const struct ldb_val value) -{ - const struct ldb_schema_attribute *a; - struct ldb_val val; - struct ldb_val cnk; - struct ldb_val *chunk; - char *p, *g; - uint8_t *save_p = NULL; - int c = 0; - - a = ldb_schema_attribute_by_name(ldb, tree->u.substring.attr); - - if(a->syntax->canonicalise_fn(ldb, ldb, &value, &val) != 0) - return -1; - - save_p = val.data; - cnk.data = NULL; - - if ( ! tree->u.substring.start_with_wildcard ) { - - chunk = tree->u.substring.chunks[c]; - if(a->syntax->canonicalise_fn(ldb, ldb, chunk, &cnk) != 0) goto failed; - - /* This deals with wildcard prefix searches on binary attributes (eg objectGUID) */ - if (cnk.length > val.length) { - goto failed; - } - if (memcmp((char *)val.data, (char *)cnk.data, cnk.length) != 0) goto failed; - val.length -= cnk.length; - val.data += cnk.length; - c++; - talloc_free(cnk.data); - cnk.data = NULL; - } - - while (tree->u.substring.chunks[c]) { - - chunk = tree->u.substring.chunks[c]; - if(a->syntax->canonicalise_fn(ldb, ldb, chunk, &cnk) != 0) goto failed; - - /* FIXME: case of embedded nulls */ - p = strstr((char *)val.data, (char *)cnk.data); - if (p == NULL) goto failed; - if ( (! tree->u.substring.chunks[c + 1]) && (! tree->u.substring.end_with_wildcard) ) { - do { /* greedy */ - g = strstr((char *)p + cnk.length, (char *)cnk.data); - if (g) p = g; - } while(g); - } - val.length = val.length - (p - (char *)(val.data)) - cnk.length; - val.data = (uint8_t *)(p + cnk.length); - c++; - talloc_free(cnk.data); - cnk.data = NULL; - } - - if ( (! tree->u.substring.end_with_wildcard) && (*(val.data) != 0) ) goto failed; /* last chunk have not reached end of string */ - talloc_free(save_p); - return 1; - -failed: - talloc_free(save_p); - talloc_free(cnk.data); - return 0; -} - -/* - match a simple leaf node -*/ -static int ldb_match_substring(struct ldb_context *ldb, - const struct ldb_message *msg, - const struct ldb_parse_tree *tree, - enum ldb_scope scope) -{ - unsigned int i; - struct ldb_message_element *el; - - el = ldb_msg_find_element(msg, tree->u.substring.attr); - if (el == NULL) { - return 0; - } - - for (i = 0; i < el->num_values; i++) { - if (ldb_wildcard_compare(ldb, tree, el->values[i]) == 1) { - return 1; - } - } - - return 0; -} - - -/* - bitwise-and comparator -*/ -static int ldb_comparator_and(const struct ldb_val *v1, const struct ldb_val *v2) -{ - uint64_t i1, i2; - i1 = strtoull((char *)v1->data, NULL, 0); - i2 = strtoull((char *)v2->data, NULL, 0); - return ((i1 & i2) == i2); -} - -/* - bitwise-or comparator -*/ -static int ldb_comparator_or(const struct ldb_val *v1, const struct ldb_val *v2) -{ - uint64_t i1, i2; - i1 = strtoull((char *)v1->data, NULL, 0); - i2 = strtoull((char *)v2->data, NULL, 0); - return ((i1 & i2) != 0); -} - - -/* - extended match, handles things like bitops -*/ -static int ldb_match_extended(struct ldb_context *ldb, - const struct ldb_message *msg, - const struct ldb_parse_tree *tree, - enum ldb_scope scope) -{ - int i; - const struct { - const char *oid; - int (*comparator)(const struct ldb_val *, const struct ldb_val *); - } rules[] = { - { LDB_OID_COMPARATOR_AND, ldb_comparator_and}, - { LDB_OID_COMPARATOR_OR, ldb_comparator_or} - }; - int (*comp)(const struct ldb_val *, const struct ldb_val *) = NULL; - struct ldb_message_element *el; - - if (tree->u.extended.dnAttributes) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb: dnAttributes extended match not supported yet"); - return -1; - } - if (tree->u.extended.rule_id == NULL) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb: no-rule extended matches not supported yet"); - return -1; - } - if (tree->u.extended.attr == NULL) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb: no-attribute extended matches not supported yet"); - return -1; - } - - for (i=0;i<ARRAY_SIZE(rules);i++) { - if (strcmp(rules[i].oid, tree->u.extended.rule_id) == 0) { - comp = rules[i].comparator; - break; - } - } - if (comp == NULL) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "ldb: unknown extended rule_id %s\n", - tree->u.extended.rule_id); - return -1; - } - - /* find the message element */ - el = ldb_msg_find_element(msg, tree->u.extended.attr); - if (el == NULL) { - return 0; - } - - for (i=0;i<el->num_values;i++) { - int ret = comp(&el->values[i], &tree->u.extended.value); - if (ret == -1 || ret == 1) return ret; - } - - return 0; -} - -/* - return 0 if the given parse tree matches the given message. Assumes - the message is in sorted order - - return 1 if it matches, and 0 if it doesn't match - - this is a recursive function, and does short-circuit evaluation - */ -static int ldb_match_message(struct ldb_context *ldb, - const struct ldb_message *msg, - const struct ldb_parse_tree *tree, - enum ldb_scope scope) -{ - unsigned int i; - int v; - - switch (tree->operation) { - case LDB_OP_AND: - for (i=0;i<tree->u.list.num_elements;i++) { - v = ldb_match_message(ldb, msg, tree->u.list.elements[i], scope); - if (!v) return 0; - } - return 1; - - case LDB_OP_OR: - for (i=0;i<tree->u.list.num_elements;i++) { - v = ldb_match_message(ldb, msg, tree->u.list.elements[i], scope); - if (v) return 1; - } - return 0; - - case LDB_OP_NOT: - return ! ldb_match_message(ldb, msg, tree->u.isnot.child, scope); - - case LDB_OP_EQUALITY: - return ldb_match_equality(ldb, msg, tree, scope); - - case LDB_OP_SUBSTRING: - return ldb_match_substring(ldb, msg, tree, scope); - - case LDB_OP_GREATER: - return ldb_match_comparison(ldb, msg, tree, scope, LDB_OP_GREATER); - - case LDB_OP_LESS: - return ldb_match_comparison(ldb, msg, tree, scope, LDB_OP_LESS); - - case LDB_OP_PRESENT: - return ldb_match_present(ldb, msg, tree, scope); - - case LDB_OP_APPROX: - return ldb_match_comparison(ldb, msg, tree, scope, LDB_OP_APPROX); - - case LDB_OP_EXTENDED: - return ldb_match_extended(ldb, msg, tree, scope); - - } - - return 0; -} - -int ldb_match_msg(struct ldb_context *ldb, - const struct ldb_message *msg, - const struct ldb_parse_tree *tree, - struct ldb_dn *base, - enum ldb_scope scope) -{ - if ( ! ldb_match_scope(ldb, base, msg->dn, scope) ) { - return 0; - } - - return ldb_match_message(ldb, msg, tree, scope); -} diff --git a/ldb/common/ldb_modules.c b/ldb/common/ldb_modules.c deleted file mode 100644 index 0fcdf937c..000000000 --- a/ldb/common/ldb_modules.c +++ /dev/null @@ -1,777 +0,0 @@ -/* - ldb database library - - Copyright (C) Simo Sorce 2004-2008 - - ** 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -/* - * Name: ldb - * - * Component: ldb modules core - * - * Description: core modules routines - * - * Author: Simo Sorce - */ - -#include "ldb_includes.h" - -#if (_SAMBA_BUILD_ >= 4) -#include "includes.h" -#endif - -#define LDB_MODULE_PREFIX "modules:" -#define LDB_MODULE_PREFIX_LEN 8 - -static void *ldb_dso_load_symbol(struct ldb_context *ldb, const char *name, - const char *symbol); - -void ldb_set_modules_dir(struct ldb_context *ldb, const char *path) -{ - talloc_free(ldb->modules_dir); - ldb->modules_dir = talloc_strdup(ldb, path); -} - -static char *ldb_modules_strdup_no_spaces(TALLOC_CTX *mem_ctx, const char *string) -{ - int i, len; - char *trimmed; - - trimmed = talloc_strdup(mem_ctx, string); - if (!trimmed) { - return NULL; - } - - len = strlen(trimmed); - for (i = 0; trimmed[i] != '\0'; i++) { - switch (trimmed[i]) { - case ' ': - case '\t': - case '\n': - memmove(&trimmed[i], &trimmed[i + 1], len -i -1); - break; - } - } - - return trimmed; -} - - -/* modules are called in inverse order on the stack. - Lets place them as an admin would think the right order is. - Modules order is important */ -const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *string) -{ - char **modules = NULL; - const char **m; - char *modstr, *p; - int i; - - /* spaces not admitted */ - modstr = ldb_modules_strdup_no_spaces(mem_ctx, string); - if ( ! modstr) { - ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in ldb_modules_strdup_no_spaces()\n"); - return NULL; - } - - modules = talloc_realloc(mem_ctx, modules, char *, 2); - if ( ! modules ) { - ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in ldb_modules_list_from_string()\n"); - talloc_free(modstr); - return NULL; - } - talloc_steal(modules, modstr); - - i = 0; - /* The str*r*chr walks backwards: This is how we get the inverse order mentioned above */ - while ((p = strrchr(modstr, ',')) != NULL) { - *p = '\0'; - p++; - modules[i] = p; - - i++; - modules = talloc_realloc(mem_ctx, modules, char *, i + 2); - if ( ! modules ) { - ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in ldb_modules_list_from_string()\n"); - return NULL; - } - - } - modules[i] = modstr; - - modules[i + 1] = NULL; - - m = (const char **)modules; - - return m; -} - -static struct backends_list_entry { - struct ldb_backend_ops *ops; - struct backends_list_entry *prev, *next; -} *ldb_backends = NULL; - -static struct ops_list_entry { - const struct ldb_module_ops *ops; - struct ops_list_entry *next; -} *registered_modules = NULL; - -static const struct ldb_builtins { - const struct ldb_backend_ops *backend_ops; - const struct ldb_module_ops *module_ops; -} builtins[]; - -static ldb_connect_fn ldb_find_backend(const char *url) -{ - struct backends_list_entry *backend; - int i; - - for (i = 0; builtins[i].backend_ops || builtins[i].module_ops; i++) { - if (builtins[i].backend_ops == NULL) continue; - - if (strncmp(builtins[i].backend_ops->name, url, - strlen(builtins[i].backend_ops->name)) == 0) { - return builtins[i].backend_ops->connect_fn; - } - } - - for (backend = ldb_backends; backend; backend = backend->next) { - if (strncmp(backend->ops->name, url, - strlen(backend->ops->name)) == 0) { - return backend->ops->connect_fn; - } - } - - return NULL; -} - -/* - register a new ldb backend -*/ -int ldb_register_backend(const char *url_prefix, ldb_connect_fn connectfn) -{ - struct ldb_backend_ops *backend; - struct backends_list_entry *entry; - - backend = talloc(talloc_autofree_context(), struct ldb_backend_ops); - if (!backend) return LDB_ERR_OPERATIONS_ERROR; - - entry = talloc(talloc_autofree_context(), struct backends_list_entry); - if (!entry) { - talloc_free(backend); - return LDB_ERR_OPERATIONS_ERROR; - } - - if (ldb_find_backend(url_prefix)) { - return LDB_SUCCESS; - } - - /* Maybe check for duplicity here later on? */ - - backend->name = talloc_strdup(backend, url_prefix); - backend->connect_fn = connectfn; - entry->ops = backend; - DLIST_ADD(ldb_backends, entry); - - return LDB_SUCCESS; -} - -/* - Return the ldb module form of a database. - The URL can either be one of the following forms - ldb://path - ldapi://path - - flags is made up of LDB_FLG_* - - the options are passed uninterpreted to the backend, and are - backend specific. - - This allows modules to get at only the backend module, for example where a - module may wish to direct certain requests at a particular backend. -*/ -int ldb_connect_backend(struct ldb_context *ldb, - const char *url, - const char *options[], - struct ldb_module **backend_module) -{ - int ret; - char *backend; - ldb_connect_fn fn; - - if (strchr(url, ':') != NULL) { - backend = talloc_strndup(ldb, url, strchr(url, ':')-url); - } else { - /* Default to tdb */ - backend = talloc_strdup(ldb, "tdb"); - } - - fn = ldb_find_backend(backend); - - if (fn == NULL) { - struct ldb_backend_ops *ops; - char *symbol_name = talloc_asprintf(ldb, "ldb_%s_backend_ops", backend); - if (symbol_name == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - ops = ldb_dso_load_symbol(ldb, backend, symbol_name); - if (ops != NULL) { - fn = ops->connect_fn; - } - talloc_free(symbol_name); - } - - talloc_free(backend); - - if (fn == NULL) { - ldb_debug(ldb, LDB_DEBUG_FATAL, - "Unable to find backend for '%s'\n", url); - return LDB_ERR_OTHER; - } - - ret = fn(ldb, url, ldb->flags, options, backend_module); - - if (ret != LDB_SUCCESS) { - ldb_debug(ldb, LDB_DEBUG_ERROR, - "Failed to connect to '%s'\n", url); - return ret; - } - return ret; -} - -static const struct ldb_module_ops *ldb_find_module_ops(const char *name) -{ - struct ops_list_entry *e; - int i; - - for (i = 0; builtins[i].backend_ops || builtins[i].module_ops; i++) { - if (builtins[i].module_ops == NULL) continue; - - if (strcmp(builtins[i].module_ops->name, name) == 0) - return builtins[i].module_ops; - } - - for (e = registered_modules; e; e = e->next) { - if (strcmp(e->ops->name, name) == 0) - return e->ops; - } - - return NULL; -} - - -int ldb_register_module(const struct ldb_module_ops *ops) -{ - struct ops_list_entry *entry = talloc(talloc_autofree_context(), struct ops_list_entry); - - if (ldb_find_module_ops(ops->name) != NULL) - return -1; - - if (entry == NULL) - return -1; - - entry->ops = ops; - entry->next = registered_modules; - registered_modules = entry; - - return 0; -} - -static void *ldb_dso_load_symbol(struct ldb_context *ldb, const char *name, - const char *symbol) -{ - char *path; - void *handle; - void *sym; - - if (ldb->modules_dir == NULL) - return NULL; - - path = talloc_asprintf(ldb, "%s/%s.%s", ldb->modules_dir, name, - SHLIBEXT); - - ldb_debug(ldb, LDB_DEBUG_TRACE, "trying to load %s from %s\n", name, path); - - handle = dlopen(path, RTLD_NOW); - if (handle == NULL) { - ldb_debug(ldb, LDB_DEBUG_WARNING, "unable to load %s from %s: %s\n", name, path, dlerror()); - return NULL; - } - - sym = (int (*)(void))dlsym(handle, symbol); - - if (sym == NULL) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "no symbol `%s' found in %s: %s\n", symbol, path, dlerror()); - return NULL; - } - - talloc_free(path); - - return sym; -} - -int ldb_load_modules_list(struct ldb_context *ldb, const char **module_list, struct ldb_module *backend, struct ldb_module **out) -{ - struct ldb_module *module; - int i; - - module = backend; - - for (i = 0; module_list[i] != NULL; i++) { - struct ldb_module *current; - const struct ldb_module_ops *ops; - - if (strcmp(module_list[i], "") == 0) { - continue; - } - - ops = ldb_find_module_ops(module_list[i]); - if (ops == NULL) { - char *symbol_name = talloc_asprintf(ldb, "ldb_%s_module_ops", - module_list[i]); - if (symbol_name == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - ops = ldb_dso_load_symbol(ldb, module_list[i], symbol_name); - talloc_free(symbol_name); - } - - if (ops == NULL) { - ldb_debug(ldb, LDB_DEBUG_WARNING, "WARNING: Module [%s] not found\n", - module_list[i]); - continue; - } - - current = talloc_zero(ldb, struct ldb_module); - if (current == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - talloc_set_name(current, "ldb_module: %s", module_list[i]); - - current->ldb = ldb; - current->ops = ops; - - DLIST_ADD(module, current); - } - *out = module; - return LDB_SUCCESS; -} - -int ldb_init_module_chain(struct ldb_context *ldb, struct ldb_module *module) -{ - while (module && module->ops->init_context == NULL) - module = module->next; - - /* init is different in that it is not an error if modules - * do not require initialization */ - - if (module) { - int ret = module->ops->init_context(module); - if (ret != LDB_SUCCESS) { - ldb_debug(ldb, LDB_DEBUG_FATAL, "module %s initialization failed\n", module->ops->name); - return ret; - } - } - - return LDB_SUCCESS; -} - -int ldb_load_modules(struct ldb_context *ldb, const char *options[]) -{ - const char **modules = NULL; - int i; - int ret; - TALLOC_CTX *mem_ctx = talloc_new(ldb); - if (!mem_ctx) { - return LDB_ERR_OPERATIONS_ERROR; - } - - /* find out which modules we are requested to activate */ - - /* check if we have a custom module list passd as ldb option */ - if (options) { - for (i = 0; options[i] != NULL; i++) { - if (strncmp(options[i], LDB_MODULE_PREFIX, LDB_MODULE_PREFIX_LEN) == 0) { - modules = ldb_modules_list_from_string(ldb, mem_ctx, &options[i][LDB_MODULE_PREFIX_LEN]); - } - } - } - - /* if not overloaded by options and the backend is not ldap try to load the modules list from ldb */ - if ((modules == NULL) && (strcmp("ldap", ldb->modules->ops->name) != 0)) { - const char * const attrs[] = { "@LIST" , NULL}; - struct ldb_result *res = NULL; - struct ldb_dn *mods_dn; - - mods_dn = ldb_dn_new(mem_ctx, ldb, "@MODULES"); - if (mods_dn == NULL) { - talloc_free(mem_ctx); - return -1; - } - - ret = ldb_search(ldb, mods_dn, &res, mods_dn, LDB_SCOPE_BASE, attrs, "@LIST=*"); - - if (ret == LDB_ERR_NO_SUCH_OBJECT) { - ldb_debug(ldb, LDB_DEBUG_TRACE, "no modules required by the db"); - } else if (ret != LDB_SUCCESS) { - ldb_debug(ldb, LDB_DEBUG_FATAL, "ldb error (%s) occurred searching for modules, bailing out\n", ldb_errstring(ldb)); - talloc_free(mem_ctx); - return ret; - } else { - const char *module_list; - if (res->count == 0) { - ldb_debug(ldb, LDB_DEBUG_TRACE, "no modules required by the db"); - } else if (res->count > 1) { - ldb_debug(ldb, LDB_DEBUG_FATAL, "Too many records found (%d), bailing out\n", res->count); - talloc_free(mem_ctx); - return -1; - } else { - module_list = ldb_msg_find_attr_as_string(res->msgs[0], "@LIST", NULL); - if (!module_list) { - ldb_debug(ldb, LDB_DEBUG_TRACE, "no modules required by the db"); - } - modules = ldb_modules_list_from_string(ldb, mem_ctx, - module_list); - } - } - - talloc_free(mods_dn); - } - - if (modules != NULL) { - ret = ldb_load_modules_list(ldb, modules, ldb->modules, &ldb->modules); - if (ret != LDB_SUCCESS) { - talloc_free(mem_ctx); - return ret; - } - } else { - ldb_debug(ldb, LDB_DEBUG_TRACE, "No modules specified for this database"); - } - - ret = ldb_init_module_chain(ldb, ldb->modules); - talloc_free(mem_ctx); - return ret; -} - -/* - by using this we allow ldb modules to only implement the functions they care about, - which makes writing a module simpler, and makes it more likely to keep working - when ldb is extended -*/ -#define FIND_OP(module, op) do { \ - struct ldb_context *ldb = module->ldb; \ - module = module->next; \ - while (module && module->ops->op == NULL) module = module->next; \ - if (module == NULL) { \ - ldb_asprintf_errstring(ldb, "Unable to find backend operation for " #op ); \ - return LDB_ERR_OPERATIONS_ERROR; \ - } \ -} while (0) - - - -struct ldb_context *ldb_module_get_ctx(struct ldb_module *module) -{ - return module->ldb; -} - -/* - helper functions to call the next module in chain -*/ - -int ldb_next_request(struct ldb_module *module, struct ldb_request *request) -{ - int ret; - - if (request->callback == NULL) { - ldb_set_errstring(module->ldb, "Requests MUST define callbacks"); - return LDB_ERR_UNWILLING_TO_PERFORM; - } - - switch (request->operation) { - case LDB_SEARCH: - FIND_OP(module, search); - ret = module->ops->search(module, request); - break; - case LDB_ADD: - FIND_OP(module, add); - ret = module->ops->add(module, request); - break; - case LDB_MODIFY: - FIND_OP(module, modify); - ret = module->ops->modify(module, request); - break; - case LDB_DELETE: - FIND_OP(module, del); - ret = module->ops->del(module, request); - break; - case LDB_RENAME: - FIND_OP(module, rename); - ret = module->ops->rename(module, request); - break; - case LDB_EXTENDED: - FIND_OP(module, extended); - ret = module->ops->extended(module, request); - break; - default: - FIND_OP(module, request); - ret = module->ops->request(module, request); - break; - } - if (ret == LDB_SUCCESS) { - return ret; - } - if (!ldb_errstring(module->ldb)) { - /* Set a default error string, to place the blame somewhere */ - ldb_asprintf_errstring(module->ldb, "error in module %s: %s (%d)", module->ops->name, ldb_strerror(ret), ret); - } - return ret; -} - -int ldb_next_init(struct ldb_module *module) -{ - module = module->next; - - return ldb_init_module_chain(module->ldb, module); -} - -int ldb_next_start_trans(struct ldb_module *module) -{ - FIND_OP(module, start_transaction); - return module->ops->start_transaction(module); -} - -int ldb_next_end_trans(struct ldb_module *module) -{ - FIND_OP(module, end_transaction); - return module->ops->end_transaction(module); -} - -int ldb_next_del_trans(struct ldb_module *module) -{ - FIND_OP(module, del_transaction); - return module->ops->del_transaction(module); -} - -struct ldb_handle *ldb_handle_new(TALLOC_CTX *mem_ctx, struct ldb_context *ldb) -{ - struct ldb_handle *h; - - h = talloc_zero(mem_ctx, struct ldb_handle); - if (h == NULL) { - ldb_set_errstring(ldb, "Out of Memory"); - return NULL; - } - - h->status = LDB_SUCCESS; - h->state = LDB_ASYNC_INIT; - h->ldb = ldb; - - return h; -} - -/* calls the request callback to send an entry - * - * params: - * req: the original request passed to your module - * msg: reply message (must be a talloc pointer, and it will be stolen - * on the ldb_reply that is sent to the callback) - * ctrls: controls to send in the reply (must be a talloc pointer, and it will be stolen - * on the ldb_reply that is sent to the callback) - */ - -int ldb_module_send_entry(struct ldb_request *req, - struct ldb_message *msg, - struct ldb_control **ctrls) -{ - struct ldb_reply *ares; - - ares = talloc_zero(req, struct ldb_reply); - if (!ares) { - ldb_oom(req->handle->ldb); - req->callback(req, NULL); - return LDB_ERR_OPERATIONS_ERROR; - } - ares->type = LDB_REPLY_ENTRY; - ares->message = talloc_steal(ares, msg); - ares->controls = talloc_steal(ares, ctrls); - ares->error = LDB_SUCCESS; - - return req->callback(req, ares); -} - -/* calls the request callback to send an referrals - * - * params: - * req: the original request passed to your module - * ref: referral string (must be a talloc pointeri, steal) - */ - -int ldb_module_send_referral(struct ldb_request *req, - char *ref) -{ - struct ldb_reply *ares; - - ares = talloc_zero(req, struct ldb_reply); - if (!ares) { - ldb_oom(req->handle->ldb); - req->callback(req, NULL); - return LDB_ERR_OPERATIONS_ERROR; - } - ares->type = LDB_REPLY_REFERRAL; - ares->referral = talloc_steal(ares, ref); - ares->error = LDB_SUCCESS; - - return req->callback(req, ares); -} - -/* calls the original request callback - * - * params: - * req: the original request passed to your module - * ctrls: controls to send in the reply (must be a talloc pointer, steal) - * response: results for extended request (steal) - * error: LDB_SUCCESS for a succesful return - * any other ldb error otherwise - */ -int ldb_module_done(struct ldb_request *req, - struct ldb_control **ctrls, - struct ldb_extended *response, - int error) -{ - struct ldb_reply *ares; - - ares = talloc_zero(req, struct ldb_reply); - if (!ares) { - ldb_oom(req->handle->ldb); - req->callback(req, NULL); - return LDB_ERR_OPERATIONS_ERROR; - } - ares->type = LDB_REPLY_DONE; - ares->controls = talloc_steal(ares, ctrls); - ares->response = talloc_steal(ares, response); - ares->error = error; - - req->callback(req, ares); - return error; -} - -/* to be used *only* in modules init functions. - * this function i synchronous and will register - * the requested OID in the rootdse module if present - * otherwise it will return an error */ -int ldb_mod_register_control(struct ldb_module *module, const char *oid) -{ - struct ldb_request *req; - int ret; - - req = talloc_zero(module, struct ldb_request); - if (req == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req->operation = LDB_REQ_REGISTER_CONTROL; - req->op.reg_control.oid = oid; - req->callback = ldb_op_default_callback; - - ldb_set_timeout(module->ldb, req, 0); - - req->handle = ldb_handle_new(req, module->ldb); - if (req->handle == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - - ret = ldb_request(module->ldb, req); - if (ret == LDB_SUCCESS) { - ret = ldb_wait(req->handle, LDB_WAIT_ALL); - } - talloc_free(req); - - return ret; -} - -#ifndef STATIC_LIBLDB_MODULES - -#ifdef HAVE_LDB_LDAP -#define LDAP_BACKEND LDB_BACKEND(ldap), LDB_BACKEND(ldapi), LDB_BACKEND(ldaps), -#else -#define LDAP_BACKEND -#endif - -#ifdef HAVE_LDB_SQLITE3 -#define SQLITE3_BACKEND LDB_BACKEND(sqlite3), -#else -#define SQLITE3_BACKEND -#endif - -#define STATIC_LIBLDB_MODULES \ - LDB_BACKEND(tdb), \ - LDAP_BACKEND \ - SQLITE3_BACKEND \ - LDB_MODULE(operational), \ - LDB_MODULE(rdn_name), \ - LDB_MODULE(paged_results), \ - LDB_MODULE(server_sort), \ - LDB_MODULE(asq), \ - NULL -#endif - -/* - * this is a bit hacked, as STATIC_LIBLDB_MODULES contains ',' - * between the elements and we want to autogenerate the - * extern struct declarations, so we do some hacks and let the - * ',' appear in an unused function prototype. - */ -#undef NULL -#define NULL LDB_MODULE(NULL), - -#define LDB_BACKEND(name) \ - int); \ - extern const struct ldb_backend_ops ldb_ ## name ## _backend_ops;\ - extern void ldb_noop ## name (int -#define LDB_MODULE(name) \ - int); \ - extern const struct ldb_module_ops ldb_ ## name ## _module_ops;\ - extern void ldb_noop ## name (int - -extern void ldb_start_noop(int, -STATIC_LIBLDB_MODULES -int); - -#undef NULL -#define NULL { \ - .backend_ops = (void *)0, \ - .module_ops = (void *)0 \ -} - -#undef LDB_BACKEND -#define LDB_BACKEND(name) { \ - .backend_ops = &ldb_ ## name ## _backend_ops, \ - .module_ops = (void *)0 \ -} -#undef LDB_MODULE -#define LDB_MODULE(name) { \ - .backend_ops = (void *)0, \ - .module_ops = &ldb_ ## name ## _module_ops \ -} - -static const struct ldb_builtins builtins[] = { - STATIC_LIBLDB_MODULES -}; diff --git a/ldb/common/ldb_msg.c b/ldb/common/ldb_msg.c deleted file mode 100644 index 2f5fe1d18..000000000 --- a/ldb/common/ldb_msg.c +++ /dev/null @@ -1,899 +0,0 @@ -/* - ldb database library - - Copyright (C) Andrew Tridgell 2004 - - ** 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -/* - * Name: ldb - * - * Component: ldb message component utility functions - * - * Description: functions for manipulating ldb_message structures - * - * Author: Andrew Tridgell - */ - -#include "ldb_includes.h" - -/* - create a new ldb_message in a given memory context (NULL for top level) -*/ -struct ldb_message *ldb_msg_new(void *mem_ctx) -{ - return talloc_zero(mem_ctx, struct ldb_message); -} - -/* - find an element in a message by attribute name -*/ -struct ldb_message_element *ldb_msg_find_element(const struct ldb_message *msg, - const char *attr_name) -{ - unsigned int i; - for (i=0;i<msg->num_elements;i++) { - if (ldb_attr_cmp(msg->elements[i].name, attr_name) == 0) { - return &msg->elements[i]; - } - } - return NULL; -} - -/* - see if two ldb_val structures contain exactly the same data - return 1 for a match, 0 for a mis-match -*/ -int ldb_val_equal_exact(const struct ldb_val *v1, const struct ldb_val *v2) -{ - if (v1->length != v2->length) return 0; - - if (v1->length == 0) return 1; - - if (memcmp(v1->data, v2->data, v1->length) == 0) { - return 1; - } - - return 0; -} - -/* - find a value in an element - assumes case sensitive comparison -*/ -struct ldb_val *ldb_msg_find_val(const struct ldb_message_element *el, - struct ldb_val *val) -{ - unsigned int i; - for (i=0;i<el->num_values;i++) { - if (ldb_val_equal_exact(val, &el->values[i])) { - return &el->values[i]; - } - } - return NULL; -} - -/* - duplicate a ldb_val structure -*/ -struct ldb_val ldb_val_dup(void *mem_ctx, const struct ldb_val *v) -{ - struct ldb_val v2; - v2.length = v->length; - if (v->data == NULL) { - v2.data = NULL; - return v2; - } - - /* the +1 is to cope with buggy C library routines like strndup - that look one byte beyond */ - v2.data = talloc_array(mem_ctx, uint8_t, v->length+1); - if (!v2.data) { - v2.length = 0; - return v2; - } - - memcpy(v2.data, v->data, v->length); - ((char *)v2.data)[v->length] = 0; - return v2; -} - -/* - add an empty element to a message -*/ -int ldb_msg_add_empty( struct ldb_message *msg, - const char *attr_name, - int flags, - struct ldb_message_element **return_el) -{ - struct ldb_message_element *els; - - els = talloc_realloc(msg, msg->elements, - struct ldb_message_element, msg->num_elements+1); - if (!els) { - errno = ENOMEM; - return LDB_ERR_OPERATIONS_ERROR; - } - - els[msg->num_elements].values = NULL; - els[msg->num_elements].num_values = 0; - els[msg->num_elements].flags = flags; - els[msg->num_elements].name = talloc_strdup(els, attr_name); - if (!els[msg->num_elements].name) { - errno = ENOMEM; - return LDB_ERR_OPERATIONS_ERROR; - } - - msg->elements = els; - msg->num_elements++; - - if (return_el) { - *return_el = &els[msg->num_elements-1]; - } - - return LDB_SUCCESS; -} - -/* - add an empty element to a message -*/ -int ldb_msg_add(struct ldb_message *msg, - const struct ldb_message_element *el, - int flags) -{ - /* We have to copy this, just in case *el is a pointer into - * what ldb_msg_add_empty() is about to realloc() */ - struct ldb_message_element el_copy = *el; - if (ldb_msg_add_empty(msg, el->name, flags, NULL) != 0) { - return LDB_ERR_OPERATIONS_ERROR; - } - - msg->elements[msg->num_elements-1] = el_copy; - msg->elements[msg->num_elements-1].flags = flags; - - return LDB_SUCCESS; -} - -/* - add a value to a message -*/ -int ldb_msg_add_value(struct ldb_message *msg, - const char *attr_name, - const struct ldb_val *val, - struct ldb_message_element **return_el) -{ - struct ldb_message_element *el; - struct ldb_val *vals; - int ret; - - el = ldb_msg_find_element(msg, attr_name); - if (!el) { - ret = ldb_msg_add_empty(msg, attr_name, 0, &el); - if (ret != LDB_SUCCESS) { - return ret; - } - } - - vals = talloc_realloc(msg, el->values, struct ldb_val, el->num_values+1); - if (!vals) { - errno = ENOMEM; - return LDB_ERR_OPERATIONS_ERROR; - } - el->values = vals; - el->values[el->num_values] = *val; - el->num_values++; - - if (return_el) { - *return_el = el; - } - - return LDB_SUCCESS; -} - - -/* - add a value to a message, stealing it into the 'right' place -*/ -int ldb_msg_add_steal_value(struct ldb_message *msg, - const char *attr_name, - struct ldb_val *val) -{ - int ret; - struct ldb_message_element *el; - - ret = ldb_msg_add_value(msg, attr_name, val, &el); - if (ret == LDB_SUCCESS) { - talloc_steal(el->values, val->data); - } - return ret; -} - - -/* - add a string element to a message -*/ -int ldb_msg_add_string(struct ldb_message *msg, - const char *attr_name, const char *str) -{ - struct ldb_val val; - - val.data = discard_const_p(uint8_t, str); - val.length = strlen(str); - - if (val.length == 0) { - /* allow empty strings as non-existant attributes */ - return LDB_SUCCESS; - } - - return ldb_msg_add_value(msg, attr_name, &val, NULL); -} - -/* - add a string element to a message, stealing it into the 'right' place -*/ -int ldb_msg_add_steal_string(struct ldb_message *msg, - const char *attr_name, char *str) -{ - struct ldb_val val; - - val.data = (uint8_t *)str; - val.length = strlen(str); - - return ldb_msg_add_steal_value(msg, attr_name, &val); -} - -/* - add a printf formatted element to a message -*/ -int ldb_msg_add_fmt(struct ldb_message *msg, - const char *attr_name, const char *fmt, ...) -{ - struct ldb_val val; - va_list ap; - char *str; - - va_start(ap, fmt); - str = talloc_vasprintf(msg, fmt, ap); - va_end(ap); - - if (str == NULL) return LDB_ERR_OPERATIONS_ERROR; - - val.data = (uint8_t *)str; - val.length = strlen(str); - - return ldb_msg_add_steal_value(msg, attr_name, &val); -} - -/* - compare two ldb_message_element structures - assumes case senistive comparison -*/ -int ldb_msg_element_compare(struct ldb_message_element *el1, - struct ldb_message_element *el2) -{ - unsigned int i; - - if (el1->num_values != el2->num_values) { - return el1->num_values - el2->num_values; - } - - for (i=0;i<el1->num_values;i++) { - if (!ldb_msg_find_val(el2, &el1->values[i])) { - return -1; - } - } - - return 0; -} - -/* - compare two ldb_message_element structures - comparing by element name -*/ -int ldb_msg_element_compare_name(struct ldb_message_element *el1, - struct ldb_message_element *el2) -{ - return ldb_attr_cmp(el1->name, el2->name); -} - -/* - convenience functions to return common types from a message - these return the first value if the attribute is multi-valued -*/ -const struct ldb_val *ldb_msg_find_ldb_val(const struct ldb_message *msg, - const char *attr_name) -{ - struct ldb_message_element *el = ldb_msg_find_element(msg, attr_name); - if (!el || el->num_values == 0) { - return NULL; - } - return &el->values[0]; -} - -int ldb_msg_find_attr_as_int(const struct ldb_message *msg, - const char *attr_name, - int default_value) -{ - const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr_name); - if (!v || !v->data) { - return default_value; - } - return strtol((const char *)v->data, NULL, 0); -} - -unsigned int ldb_msg_find_attr_as_uint(const struct ldb_message *msg, - const char *attr_name, - unsigned int default_value) -{ - const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr_name); - if (!v || !v->data) { - return default_value; - } - return strtoul((const char *)v->data, NULL, 0); -} - -int64_t ldb_msg_find_attr_as_int64(const struct ldb_message *msg, - const char *attr_name, - int64_t default_value) -{ - const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr_name); - if (!v || !v->data) { - return default_value; - } - return strtoll((const char *)v->data, NULL, 0); -} - -uint64_t ldb_msg_find_attr_as_uint64(const struct ldb_message *msg, - const char *attr_name, - uint64_t default_value) -{ - const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr_name); - if (!v || !v->data) { - return default_value; - } - return strtoull((const char *)v->data, NULL, 0); -} - -double ldb_msg_find_attr_as_double(const struct ldb_message *msg, - const char *attr_name, - double default_value) -{ - const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr_name); - if (!v || !v->data) { - return default_value; - } - return strtod((const char *)v->data, NULL); -} - -int ldb_msg_find_attr_as_bool(const struct ldb_message *msg, - const char *attr_name, - int default_value) -{ - const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr_name); - if (!v || !v->data) { - return default_value; - } - if (v->length == 5 && strncasecmp((const char *)v->data, "FALSE", 5) == 0) { - return 0; - } - if (v->length == 4 && strncasecmp((const char *)v->data, "TRUE", 4) == 0) { - return 1; - } - return default_value; -} - -const char *ldb_msg_find_attr_as_string(const struct ldb_message *msg, - const char *attr_name, - const char *default_value) -{ - const struct ldb_val *v = ldb_msg_find_ldb_val(msg, attr_name); - if (!v || !v->data) { - return default_value; - } - return (const char *)v->data; -} - -struct ldb_dn *ldb_msg_find_attr_as_dn(struct ldb_context *ldb, - void *mem_ctx, - const struct ldb_message *msg, - const char *attr_name) -{ - struct ldb_dn *res_dn; - const struct ldb_val *v; - - v = ldb_msg_find_ldb_val(msg, attr_name); - if (!v || !v->data) { - return NULL; - } - res_dn = ldb_dn_from_ldb_val(mem_ctx, ldb, v); - if ( ! ldb_dn_validate(res_dn)) { - talloc_free(res_dn); - return NULL; - } - return res_dn; -} - -/* - sort the elements of a message by name -*/ -void ldb_msg_sort_elements(struct ldb_message *msg) -{ - qsort(msg->elements, msg->num_elements, sizeof(struct ldb_message_element), - (comparison_fn_t)ldb_msg_element_compare_name); -} - -/* - shallow copy a message - copying only the elements array so that the caller - can safely add new elements without changing the message -*/ -struct ldb_message *ldb_msg_copy_shallow(TALLOC_CTX *mem_ctx, - const struct ldb_message *msg) -{ - struct ldb_message *msg2; - int i; - - msg2 = talloc(mem_ctx, struct ldb_message); - if (msg2 == NULL) return NULL; - - *msg2 = *msg; - - msg2->elements = talloc_array(msg2, struct ldb_message_element, - msg2->num_elements); - if (msg2->elements == NULL) goto failed; - - for (i=0;i<msg2->num_elements;i++) { - msg2->elements[i] = msg->elements[i]; - } - - return msg2; - -failed: - talloc_free(msg2); - return NULL; -} - - -/* - copy a message, allocating new memory for all parts -*/ -struct ldb_message *ldb_msg_copy(TALLOC_CTX *mem_ctx, - const struct ldb_message *msg) -{ - struct ldb_message *msg2; - int i, j; - - msg2 = ldb_msg_copy_shallow(mem_ctx, msg); - if (msg2 == NULL) return NULL; - - msg2->dn = ldb_dn_copy(msg2, msg2->dn); - if (msg2->dn == NULL) goto failed; - - for (i=0;i<msg2->num_elements;i++) { - struct ldb_message_element *el = &msg2->elements[i]; - struct ldb_val *values = el->values; - el->name = talloc_strdup(msg2->elements, el->name); - if (el->name == NULL) goto failed; - el->values = talloc_array(msg2->elements, struct ldb_val, el->num_values); - for (j=0;j<el->num_values;j++) { - el->values[j] = ldb_val_dup(el->values, &values[j]); - if (el->values[j].data == NULL && values[j].length != 0) { - goto failed; - } - } - } - - return msg2; - -failed: - talloc_free(msg2); - return NULL; -} - - -/* - canonicalise a message, merging elements of the same name -*/ -struct ldb_message *ldb_msg_canonicalize(struct ldb_context *ldb, - const struct ldb_message *msg) -{ - int i; - struct ldb_message *msg2; - - msg2 = ldb_msg_copy(ldb, msg); - if (msg2 == NULL) return NULL; - - ldb_msg_sort_elements(msg2); - - for (i=1;i<msg2->num_elements;i++) { - struct ldb_message_element *el1 = &msg2->elements[i-1]; - struct ldb_message_element *el2 = &msg2->elements[i]; - if (ldb_msg_element_compare_name(el1, el2) == 0) { - el1->values = talloc_realloc(msg2->elements, el1->values, struct ldb_val, - el1->num_values + el2->num_values); - if (el1->values == NULL) { - return NULL; - } - memcpy(el1->values + el1->num_values, - el2->values, - sizeof(struct ldb_val) * el2->num_values); - el1->num_values += el2->num_values; - talloc_free(discard_const_p(char, el2->name)); - if (i+1<msg2->num_elements) { - memmove(el2, el2+1, sizeof(struct ldb_message_element) * - (msg2->num_elements - (i+1))); - } - msg2->num_elements--; - i--; - } - } - - return msg2; -} - - -/* - return a ldb_message representing the differences between msg1 and msg2. If you - then use this in a ldb_modify() call it can be used to save edits to a message -*/ -struct ldb_message *ldb_msg_diff(struct ldb_context *ldb, - struct ldb_message *msg1, - struct ldb_message *msg2) -{ - struct ldb_message *mod; - struct ldb_message_element *el; - unsigned int i; - - mod = ldb_msg_new(ldb); - - mod->dn = msg1->dn; - mod->num_elements = 0; - mod->elements = NULL; - - msg2 = ldb_msg_canonicalize(ldb, msg2); - if (msg2 == NULL) { - return NULL; - } - - /* look in msg2 to find elements that need to be added - or modified */ - for (i=0;i<msg2->num_elements;i++) { - el = ldb_msg_find_element(msg1, msg2->elements[i].name); - - if (el && ldb_msg_element_compare(el, &msg2->elements[i]) == 0) { - continue; - } - - if (ldb_msg_add(mod, - &msg2->elements[i], - el?LDB_FLAG_MOD_REPLACE:LDB_FLAG_MOD_ADD) != 0) { - return NULL; - } - } - - /* look in msg1 to find elements that need to be deleted */ - for (i=0;i<msg1->num_elements;i++) { - el = ldb_msg_find_element(msg2, msg1->elements[i].name); - if (!el) { - if (ldb_msg_add_empty(mod, - msg1->elements[i].name, - LDB_FLAG_MOD_DELETE, NULL) != 0) { - return NULL; - } - } - } - - return mod; -} - -int ldb_msg_sanity_check(struct ldb_context *ldb, - const struct ldb_message *msg) -{ - int i, j; - - /* basic check on DN */ - if (msg->dn == NULL) { - /* TODO: return also an error string */ - ldb_set_errstring(ldb, "ldb message lacks a DN!"); - return LDB_ERR_INVALID_DN_SYNTAX; - } - - /* basic syntax checks */ - for (i = 0; i < msg->num_elements; i++) { - for (j = 0; j < msg->elements[i].num_values; j++) { - if (msg->elements[i].values[j].length == 0) { - TALLOC_CTX *mem_ctx = talloc_new(ldb); - /* an attribute cannot be empty */ - /* TODO: return also an error string */ - ldb_asprintf_errstring(ldb, "Element %s has empty attribute in ldb message (%s)!", - msg->elements[i].name, - ldb_dn_get_linearized(msg->dn)); - talloc_free(mem_ctx); - return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX; - } - } - } - - return LDB_SUCCESS; -} - - - - -/* - copy an attribute list. This only copies the array, not the elements - (ie. the elements are left as the same pointers) -*/ -const char **ldb_attr_list_copy(TALLOC_CTX *mem_ctx, const char * const *attrs) -{ - const char **ret; - int i; - for (i=0;attrs[i];i++) /* noop */ ; - ret = talloc_array(mem_ctx, const char *, i+1); - if (ret == NULL) { - return NULL; - } - for (i=0;attrs[i];i++) { - ret[i] = attrs[i]; - } - ret[i] = attrs[i]; - return ret; -} - - -/* - copy an attribute list. This only copies the array, not the elements - (ie. the elements are left as the same pointers). The new attribute is added to the list. -*/ -const char **ldb_attr_list_copy_add(TALLOC_CTX *mem_ctx, const char * const *attrs, const char *new_attr) -{ - const char **ret; - int i; - bool found = false; - for (i=0;attrs[i];i++) { - if (ldb_attr_cmp(attrs[i], new_attr) == 0) { - found = true; - } - } - if (found) { - return ldb_attr_list_copy(mem_ctx, attrs); - } - ret = talloc_array(mem_ctx, const char *, i+2); - if (ret == NULL) { - return NULL; - } - for (i=0;attrs[i];i++) { - ret[i] = attrs[i]; - } - ret[i] = new_attr; - ret[i+1] = NULL; - return ret; -} - - -/* - return 1 if an attribute is in a list of attributes, or 0 otherwise -*/ -int ldb_attr_in_list(const char * const *attrs, const char *attr) -{ - int i; - for (i=0;attrs && attrs[i];i++) { - if (ldb_attr_cmp(attrs[i], attr) == 0) { - return 1; - } - } - return 0; -} - - -/* - rename the specified attribute in a search result -*/ -int ldb_msg_rename_attr(struct ldb_message *msg, const char *attr, const char *replace) -{ - struct ldb_message_element *el = ldb_msg_find_element(msg, attr); - if (el == NULL) { - return LDB_SUCCESS; - } - el->name = talloc_strdup(msg->elements, replace); - if (el->name == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - return LDB_SUCCESS; -} - - -/* - copy the specified attribute in a search result to a new attribute -*/ -int ldb_msg_copy_attr(struct ldb_message *msg, const char *attr, const char *replace) -{ - struct ldb_message_element *el = ldb_msg_find_element(msg, attr); - if (el == NULL) { - return LDB_SUCCESS; - } - if (ldb_msg_add(msg, el, 0) != 0) { - return LDB_ERR_OPERATIONS_ERROR; - } - return ldb_msg_rename_attr(msg, attr, replace); -} - -/* - remove the specified element in a search result -*/ -void ldb_msg_remove_element(struct ldb_message *msg, struct ldb_message_element *el) -{ - int n = (el - msg->elements); - if (n != msg->num_elements-1) { - memmove(el, el+1, ((msg->num_elements-1) - n)*sizeof(*el)); - } - msg->num_elements--; -} - - -/* - remove the specified attribute in a search result -*/ -void ldb_msg_remove_attr(struct ldb_message *msg, const char *attr) -{ - struct ldb_message_element *el = ldb_msg_find_element(msg, attr); - if (el) { - ldb_msg_remove_element(msg, el); - } -} - -/* - return a LDAP formatted GeneralizedTime string -*/ -char *ldb_timestring(TALLOC_CTX *mem_ctx, time_t t) -{ - struct tm *tm = gmtime(&t); - char *ts; - int r; - - if (!tm) { - return NULL; - } - - /* we now excatly how long this string will be */ - ts = talloc_array(mem_ctx, char, 18); - - /* formatted like: 20040408072012.0Z */ - r = snprintf(ts, 18, - "%04u%02u%02u%02u%02u%02u.0Z", - tm->tm_year+1900, tm->tm_mon+1, - tm->tm_mday, tm->tm_hour, tm->tm_min, - tm->tm_sec); - - if (r != 17) { - talloc_free(ts); - return NULL; - } - - return ts; -} - -/* - convert a LDAP GeneralizedTime string to a time_t. Return 0 if unable to convert -*/ -time_t ldb_string_to_time(const char *s) -{ - struct tm tm; - - if (s == NULL) return 0; - - memset(&tm, 0, sizeof(tm)); - if (sscanf(s, "%04u%02u%02u%02u%02u%02u", - &tm.tm_year, &tm.tm_mon, &tm.tm_mday, - &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) { - return 0; - } - tm.tm_year -= 1900; - tm.tm_mon -= 1; - - return timegm(&tm); -} - -/* - return a LDAP formatted UTCTime string -*/ -char *ldb_timestring_utc(TALLOC_CTX *mem_ctx, time_t t) -{ - struct tm *tm = gmtime(&t); - char *ts; - int r; - - if (!tm) { - return NULL; - } - - /* we now excatly how long this string will be */ - ts = talloc_array(mem_ctx, char, 14); - - /* formatted like: 20040408072012.0Z => 040408072012Z */ - r = snprintf(ts, 14, - "%02u%02u%02u%02u%02u%02uZ", - (tm->tm_year+1900)%100, tm->tm_mon+1, - tm->tm_mday, tm->tm_hour, tm->tm_min, - tm->tm_sec); - - if (r != 13) { - talloc_free(ts); - return NULL; - } - - return ts; -} - -/* - convert a LDAP UTCTime string to a time_t. Return 0 if unable to convert -*/ -time_t ldb_string_utc_to_time(const char *s) -{ - struct tm tm; - - if (s == NULL) return 0; - - memset(&tm, 0, sizeof(tm)); - if (sscanf(s, "%02u%02u%02u%02u%02u%02u", - &tm.tm_year, &tm.tm_mon, &tm.tm_mday, - &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) { - return 0; - } - if (tm.tm_year < 50) { - tm.tm_year += 100; - } - tm.tm_mon -= 1; - - return timegm(&tm); -} - - -/* - dump a set of results to a file. Useful from within gdb -*/ -void ldb_dump_results(struct ldb_context *ldb, struct ldb_result *result, FILE *f) -{ - int i; - - for (i = 0; i < result->count; i++) { - struct ldb_ldif ldif; - fprintf(f, "# record %d\n", i+1); - ldif.changetype = LDB_CHANGETYPE_NONE; - ldif.msg = result->msgs[i]; - ldb_ldif_write_file(ldb, f, &ldif); - } -} - -int ldb_msg_check_string_attribute(const struct ldb_message *msg, const char *name, const char *value) -{ - struct ldb_message_element *el; - struct ldb_val val; - - el = ldb_msg_find_element(msg, name); - if (el == NULL) - return 0; - - val.data = discard_const_p(uint8_t, value); - val.length = strlen(value); - - if (ldb_msg_find_val(el, &val)) - return 1; - - return 0; -} diff --git a/ldb/common/ldb_parse.c b/ldb/common/ldb_parse.c deleted file mode 100644 index b23397522..000000000 --- a/ldb/common/ldb_parse.c +++ /dev/null @@ -1,819 +0,0 @@ -/* - ldb database library - - Copyright (C) Andrew Tridgell 2004 - - ** 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -/* - * Name: ldb - * - * Component: ldb expression parsing - * - * Description: parse LDAP-like search expressions - * - * Author: Andrew Tridgell - */ - -/* - TODO: - - add RFC2254 binary string handling - - possibly add ~=, <= and >= handling - - expand the test suite - - add better parse error handling - -*/ - -#include "ldb_includes.h" -#include "system/locale.h" - -/* -a filter is defined by: - <filter> ::= '(' <filtercomp> ')' - <filtercomp> ::= <and> | <or> | <not> | <simple> - <and> ::= '&' <filterlist> - <or> ::= '|' <filterlist> - <not> ::= '!' <filter> - <filterlist> ::= <filter> | <filter> <filterlist> - <simple> ::= <attributetype> <filtertype> <attributevalue> - <filtertype> ::= '=' | '~=' | '<=' | '>=' -*/ - -/* - decode a RFC2254 binary string representation of a buffer. - Used in LDAP filters. -*/ -struct ldb_val ldb_binary_decode(void *mem_ctx, const char *str) -{ - int i, j; - struct ldb_val ret; - int slen = str?strlen(str):0; - - ret.data = (uint8_t *)talloc_size(mem_ctx, slen+1); - ret.length = 0; - if (ret.data == NULL) return ret; - - for (i=j=0;i<slen;i++) { - if (str[i] == '\\') { - unsigned c; - if (sscanf(&str[i+1], "%02X", &c) != 1) { - talloc_free(ret.data); - memset(&ret, 0, sizeof(ret)); - return ret; - } - ((uint8_t *)ret.data)[j++] = c; - i += 2; - } else { - ((uint8_t *)ret.data)[j++] = str[i]; - } - } - ret.length = j; - ((uint8_t *)ret.data)[j] = 0; - - return ret; -} - - -/* - encode a blob as a RFC2254 binary string, escaping any - non-printable or '\' characters -*/ -char *ldb_binary_encode(void *mem_ctx, struct ldb_val val) -{ - int i; - char *ret; - int len = val.length; - unsigned char *buf = val.data; - - for (i=0;i<val.length;i++) { - if (!isprint(buf[i]) || strchr(" *()\\&|!\"", buf[i])) { - len += 2; - } - } - ret = talloc_array(mem_ctx, char, len+1); - if (ret == NULL) return NULL; - - len = 0; - for (i=0;i<val.length;i++) { - if (!isprint(buf[i]) || strchr(" *()\\&|!\"", buf[i])) { - snprintf(ret+len, 4, "\\%02X", buf[i]); - len += 3; - } else { - ret[len++] = buf[i]; - } - } - - ret[len] = 0; - - return ret; -} - -/* - encode a string as a RFC2254 binary string, escaping any - non-printable or '\' characters. This routine is suitable for use - in escaping user data in ldap filters. -*/ -char *ldb_binary_encode_string(void *mem_ctx, const char *string) -{ - struct ldb_val val; - val.data = discard_const_p(uint8_t, string); - val.length = strlen(string); - return ldb_binary_encode(mem_ctx, val); -} - -/* find the first matching wildcard */ -static char *ldb_parse_find_wildcard(char *value) -{ - while (*value) { - value = strpbrk(value, "\\*"); - if (value == NULL) return NULL; - - if (value[0] == '\\') { - if (value[1] == '\0') return NULL; - value += 2; - continue; - } - - if (value[0] == '*') return value; - } - - return NULL; -} - -/* return a NULL terminated list of binary strings representing the value - chunks separated by wildcards that makes the value portion of the filter -*/ -static struct ldb_val **ldb_wildcard_decode(void *mem_ctx, const char *string) -{ - struct ldb_val **ret = NULL; - int val = 0; - char *wc, *str; - - wc = talloc_strdup(mem_ctx, string); - if (wc == NULL) return NULL; - - while (wc && *wc) { - str = wc; - wc = ldb_parse_find_wildcard(str); - if (wc && *wc) { - if (wc == str) { - wc++; - continue; - } - *wc = 0; - wc++; - } - - ret = talloc_realloc(mem_ctx, ret, struct ldb_val *, val + 2); - if (ret == NULL) return NULL; - - ret[val] = talloc(mem_ctx, struct ldb_val); - if (ret[val] == NULL) return NULL; - - *(ret[val]) = ldb_binary_decode(mem_ctx, str); - if ((ret[val])->data == NULL) return NULL; - - val++; - } - - if (ret != NULL) { - ret[val] = NULL; - } - - return ret; -} - -static struct ldb_parse_tree *ldb_parse_filter(void *mem_ctx, const char **s); - - -/* - parse an extended match - - possible forms: - (attr:oid:=value) - (attr:dn:oid:=value) - (attr:dn:=value) - (:dn:oid:=value) - - the ':dn' part sets the dnAttributes boolean if present - the oid sets the rule_id string - -*/ -static struct ldb_parse_tree *ldb_parse_extended(struct ldb_parse_tree *ret, - char *attr, char *value) -{ - char *p1, *p2; - - ret->operation = LDB_OP_EXTENDED; - ret->u.extended.value = ldb_binary_decode(ret, value); - if (ret->u.extended.value.data == NULL) goto failed; - - p1 = strchr(attr, ':'); - if (p1 == NULL) goto failed; - p2 = strchr(p1+1, ':'); - - *p1 = 0; - if (p2) *p2 = 0; - - ret->u.extended.attr = attr; - if (strcmp(p1+1, "dn") == 0) { - ret->u.extended.dnAttributes = 1; - if (p2) { - ret->u.extended.rule_id = talloc_strdup(ret, p2+1); - if (ret->u.extended.rule_id == NULL) goto failed; - } else { - ret->u.extended.rule_id = NULL; - } - } else { - ret->u.extended.dnAttributes = 0; - ret->u.extended.rule_id = talloc_strdup(ret, p1+1); - if (ret->u.extended.rule_id == NULL) goto failed; - } - - return ret; - -failed: - talloc_free(ret); - return NULL; -} - -static enum ldb_parse_op ldb_parse_filtertype(void *mem_ctx, char **type, char **value, const char **s) -{ - enum ldb_parse_op filter = 0; - char *name, *val, *k; - const char *p = *s; - const char *t, *t1; - - /* retrieve attributetype name */ - t = p; - - if (*p == '@') { /* for internal attributes the first char can be @ */ - p++; - } - - while ((isascii(*p) && isalnum((unsigned char)*p)) || (*p == '-')) { /* attribute names can only be alphanums */ - p++; - } - - if (*p == ':') { /* but extended searches have : and . chars too */ - p = strstr(p, ":="); - if (p == NULL) { /* malformed attribute name */ - return 0; - } - } - - t1 = p; - - while (isspace((unsigned char)*p)) p++; - - if (!strchr("=<>~:", *p)) { - return 0; - } - - /* save name */ - name = (char *)talloc_memdup(mem_ctx, t, t1 - t + 1); - if (name == NULL) return 0; - name[t1 - t] = '\0'; - - /* retrieve filtertype */ - - if (*p == '=') { - filter = LDB_OP_EQUALITY; - } else if (*(p + 1) == '=') { - switch (*p) { - case '<': - filter = LDB_OP_LESS; - p++; - break; - case '>': - filter = LDB_OP_GREATER; - p++; - break; - case '~': - filter = LDB_OP_APPROX; - p++; - break; - case ':': - filter = LDB_OP_EXTENDED; - p++; - break; - } - } - if (!filter) { - talloc_free(name); - return filter; - } - p++; - - while (isspace((unsigned char)*p)) p++; - - /* retrieve value */ - t = p; - - while (*p && ((*p != ')') || ((*p == ')') && (*(p - 1) == '\\')))) p++; - - val = (char *)talloc_memdup(mem_ctx, t, p - t + 1); - if (val == NULL) { - talloc_free(name); - return 0; - } - val[p - t] = '\0'; - - k = &(val[p - t]); - - /* remove trailing spaces from value */ - while ((k > val) && (isspace((unsigned char)*(k - 1)))) k--; - *k = '\0'; - - *type = name; - *value = val; - *s = p; - return filter; -} - -/* - <simple> ::= <attributetype> <filtertype> <attributevalue> -*/ -static struct ldb_parse_tree *ldb_parse_simple(void *mem_ctx, const char **s) -{ - char *attr, *value; - struct ldb_parse_tree *ret; - enum ldb_parse_op filtertype; - - ret = talloc(mem_ctx, struct ldb_parse_tree); - if (!ret) { - errno = ENOMEM; - return NULL; - } - - filtertype = ldb_parse_filtertype(ret, &attr, &value, s); - if (!filtertype) { - talloc_free(ret); - return NULL; - } - - switch (filtertype) { - - case LDB_OP_PRESENT: - ret->operation = LDB_OP_PRESENT; - ret->u.present.attr = attr; - break; - - case LDB_OP_EQUALITY: - - if (strcmp(value, "*") == 0) { - ret->operation = LDB_OP_PRESENT; - ret->u.present.attr = attr; - break; - } - - if (ldb_parse_find_wildcard(value) != NULL) { - ret->operation = LDB_OP_SUBSTRING; - ret->u.substring.attr = attr; - ret->u.substring.start_with_wildcard = 0; - ret->u.substring.end_with_wildcard = 0; - ret->u.substring.chunks = ldb_wildcard_decode(ret, value); - if (ret->u.substring.chunks == NULL){ - talloc_free(ret); - return NULL; - } - if (value[0] == '*') - ret->u.substring.start_with_wildcard = 1; - if (value[strlen(value) - 1] == '*') - ret->u.substring.end_with_wildcard = 1; - talloc_free(value); - - break; - } - - ret->operation = LDB_OP_EQUALITY; - ret->u.equality.attr = attr; - ret->u.equality.value = ldb_binary_decode(ret, value); - if (ret->u.equality.value.data == NULL) { - talloc_free(ret); - return NULL; - } - talloc_free(value); - break; - - case LDB_OP_GREATER: - ret->operation = LDB_OP_GREATER; - ret->u.comparison.attr = attr; - ret->u.comparison.value = ldb_binary_decode(ret, value); - if (ret->u.comparison.value.data == NULL) { - talloc_free(ret); - return NULL; - } - talloc_free(value); - break; - - case LDB_OP_LESS: - ret->operation = LDB_OP_LESS; - ret->u.comparison.attr = attr; - ret->u.comparison.value = ldb_binary_decode(ret, value); - if (ret->u.comparison.value.data == NULL) { - talloc_free(ret); - return NULL; - } - talloc_free(value); - break; - - case LDB_OP_APPROX: - ret->operation = LDB_OP_APPROX; - ret->u.comparison.attr = attr; - ret->u.comparison.value = ldb_binary_decode(ret, value); - if (ret->u.comparison.value.data == NULL) { - talloc_free(ret); - return NULL; - } - talloc_free(value); - break; - - case LDB_OP_EXTENDED: - - ret = ldb_parse_extended(ret, attr, value); - break; - - default: - talloc_free(ret); - return NULL; - } - - return ret; -} - - -/* - parse a filterlist - <and> ::= '&' <filterlist> - <or> ::= '|' <filterlist> - <filterlist> ::= <filter> | <filter> <filterlist> -*/ -static struct ldb_parse_tree *ldb_parse_filterlist(void *mem_ctx, const char **s) -{ - struct ldb_parse_tree *ret, *next; - enum ldb_parse_op op; - const char *p = *s; - - switch (*p) { - case '&': - op = LDB_OP_AND; - break; - case '|': - op = LDB_OP_OR; - break; - default: - return NULL; - } - p++; - - while (isspace((unsigned char)*p)) p++; - - ret = talloc(mem_ctx, struct ldb_parse_tree); - if (!ret) { - errno = ENOMEM; - return NULL; - } - - ret->operation = op; - ret->u.list.num_elements = 1; - ret->u.list.elements = talloc(ret, struct ldb_parse_tree *); - if (!ret->u.list.elements) { - errno = ENOMEM; - talloc_free(ret); - return NULL; - } - - ret->u.list.elements[0] = ldb_parse_filter(ret->u.list.elements, &p); - if (!ret->u.list.elements[0]) { - talloc_free(ret); - return NULL; - } - - while (isspace((unsigned char)*p)) p++; - - while (*p && (next = ldb_parse_filter(ret->u.list.elements, &p))) { - struct ldb_parse_tree **e; - e = talloc_realloc(ret, ret->u.list.elements, - struct ldb_parse_tree *, - ret->u.list.num_elements + 1); - if (!e) { - errno = ENOMEM; - talloc_free(ret); - return NULL; - } - ret->u.list.elements = e; - ret->u.list.elements[ret->u.list.num_elements] = next; - ret->u.list.num_elements++; - while (isspace((unsigned char)*p)) p++; - } - - *s = p; - - return ret; -} - - -/* - <not> ::= '!' <filter> -*/ -static struct ldb_parse_tree *ldb_parse_not(void *mem_ctx, const char **s) -{ - struct ldb_parse_tree *ret; - const char *p = *s; - - if (*p != '!') { - return NULL; - } - p++; - - ret = talloc(mem_ctx, struct ldb_parse_tree); - if (!ret) { - errno = ENOMEM; - return NULL; - } - - ret->operation = LDB_OP_NOT; - ret->u.isnot.child = ldb_parse_filter(ret, &p); - if (!ret->u.isnot.child) { - talloc_free(ret); - return NULL; - } - - *s = p; - - return ret; -} - -/* - parse a filtercomp - <filtercomp> ::= <and> | <or> | <not> | <simple> -*/ -static struct ldb_parse_tree *ldb_parse_filtercomp(void *mem_ctx, const char **s) -{ - struct ldb_parse_tree *ret; - const char *p = *s; - - while (isspace((unsigned char)*p)) p++; - - switch (*p) { - case '&': - ret = ldb_parse_filterlist(mem_ctx, &p); - break; - - case '|': - ret = ldb_parse_filterlist(mem_ctx, &p); - break; - - case '!': - ret = ldb_parse_not(mem_ctx, &p); - break; - - case '(': - case ')': - return NULL; - - default: - ret = ldb_parse_simple(mem_ctx, &p); - - } - - *s = p; - return ret; -} - - -/* - <filter> ::= '(' <filtercomp> ')' -*/ -static struct ldb_parse_tree *ldb_parse_filter(void *mem_ctx, const char **s) -{ - struct ldb_parse_tree *ret; - const char *p = *s; - - if (*p != '(') { - return NULL; - } - p++; - - ret = ldb_parse_filtercomp(mem_ctx, &p); - - if (*p != ')') { - return NULL; - } - p++; - - while (isspace((unsigned char)*p)) { - p++; - } - - *s = p; - - return ret; -} - - -/* - main parser entry point. Takes a search string and returns a parse tree - - expression ::= <simple> | <filter> -*/ -struct ldb_parse_tree *ldb_parse_tree(void *mem_ctx, const char *s) -{ - if (s == NULL || *s == 0) { - s = "(|(objectClass=*)(distinguishedName=*))"; - } - - while (isspace((unsigned char)*s)) s++; - - if (*s == '(') { - return ldb_parse_filter(mem_ctx, &s); - } - - return ldb_parse_simple(mem_ctx, &s); -} - - -/* - construct a ldap parse filter given a parse tree -*/ -char *ldb_filter_from_tree(void *mem_ctx, struct ldb_parse_tree *tree) -{ - char *s, *s2, *ret; - int i; - - if (tree == NULL) { - return NULL; - } - - switch (tree->operation) { - case LDB_OP_AND: - case LDB_OP_OR: - ret = talloc_asprintf(mem_ctx, "(%c", tree->operation==LDB_OP_AND?'&':'|'); - if (ret == NULL) return NULL; - for (i=0;i<tree->u.list.num_elements;i++) { - s = ldb_filter_from_tree(mem_ctx, tree->u.list.elements[i]); - if (s == NULL) { - talloc_free(ret); - return NULL; - } - s2 = talloc_asprintf_append(ret, "%s", s); - talloc_free(s); - if (s2 == NULL) { - talloc_free(ret); - return NULL; - } - ret = s2; - } - s = talloc_asprintf_append(ret, ")"); - if (s == NULL) { - talloc_free(ret); - return NULL; - } - return s; - case LDB_OP_NOT: - s = ldb_filter_from_tree(mem_ctx, tree->u.isnot.child); - if (s == NULL) return NULL; - - ret = talloc_asprintf(mem_ctx, "(!%s)", s); - talloc_free(s); - return ret; - case LDB_OP_EQUALITY: - s = ldb_binary_encode(mem_ctx, tree->u.equality.value); - if (s == NULL) return NULL; - ret = talloc_asprintf(mem_ctx, "(%s=%s)", - tree->u.equality.attr, s); - talloc_free(s); - return ret; - case LDB_OP_SUBSTRING: - ret = talloc_asprintf(mem_ctx, "(%s=%s", tree->u.substring.attr, - tree->u.substring.start_with_wildcard?"*":""); - if (ret == NULL) return NULL; - for (i = 0; tree->u.substring.chunks[i]; i++) { - s2 = ldb_binary_encode(mem_ctx, *(tree->u.substring.chunks[i])); - if (s2 == NULL) { - talloc_free(ret); - return NULL; - } - if (tree->u.substring.chunks[i+1] || - tree->u.substring.end_with_wildcard) { - s = talloc_asprintf_append(ret, "%s*", s2); - } else { - s = talloc_asprintf_append(ret, "%s", s2); - } - if (s == NULL) { - talloc_free(ret); - return NULL; - } - ret = s; - } - s = talloc_asprintf_append(ret, ")"); - if (s == NULL) { - talloc_free(ret); - return NULL; - } - ret = s; - return ret; - case LDB_OP_GREATER: - s = ldb_binary_encode(mem_ctx, tree->u.equality.value); - if (s == NULL) return NULL; - ret = talloc_asprintf(mem_ctx, "(%s>=%s)", - tree->u.equality.attr, s); - talloc_free(s); - return ret; - case LDB_OP_LESS: - s = ldb_binary_encode(mem_ctx, tree->u.equality.value); - if (s == NULL) return NULL; - ret = talloc_asprintf(mem_ctx, "(%s<=%s)", - tree->u.equality.attr, s); - talloc_free(s); - return ret; - case LDB_OP_PRESENT: - ret = talloc_asprintf(mem_ctx, "(%s=*)", tree->u.present.attr); - return ret; - case LDB_OP_APPROX: - s = ldb_binary_encode(mem_ctx, tree->u.equality.value); - if (s == NULL) return NULL; - ret = talloc_asprintf(mem_ctx, "(%s~=%s)", - tree->u.equality.attr, s); - talloc_free(s); - return ret; - case LDB_OP_EXTENDED: - s = ldb_binary_encode(mem_ctx, tree->u.extended.value); - if (s == NULL) return NULL; - ret = talloc_asprintf(mem_ctx, "(%s%s%s%s:=%s)", - tree->u.extended.attr?tree->u.extended.attr:"", - tree->u.extended.dnAttributes?":dn":"", - tree->u.extended.rule_id?":":"", - tree->u.extended.rule_id?tree->u.extended.rule_id:"", - s); - talloc_free(s); - return ret; - } - - return NULL; -} - - -/* - replace any occurances of an attribute name in the parse tree with a - new name -*/ -void ldb_parse_tree_attr_replace(struct ldb_parse_tree *tree, - const char *attr, - const char *replace) -{ - int i; - switch (tree->operation) { - case LDB_OP_AND: - case LDB_OP_OR: - for (i=0;i<tree->u.list.num_elements;i++) { - ldb_parse_tree_attr_replace(tree->u.list.elements[i], - attr, replace); - } - break; - case LDB_OP_NOT: - ldb_parse_tree_attr_replace(tree->u.isnot.child, attr, replace); - break; - case LDB_OP_EQUALITY: - case LDB_OP_GREATER: - case LDB_OP_LESS: - case LDB_OP_APPROX: - if (ldb_attr_cmp(tree->u.equality.attr, attr) == 0) { - tree->u.equality.attr = replace; - } - break; - case LDB_OP_SUBSTRING: - if (ldb_attr_cmp(tree->u.substring.attr, attr) == 0) { - tree->u.substring.attr = replace; - } - break; - case LDB_OP_PRESENT: - if (ldb_attr_cmp(tree->u.present.attr, attr) == 0) { - tree->u.present.attr = replace; - } - break; - case LDB_OP_EXTENDED: - if (tree->u.extended.attr && - ldb_attr_cmp(tree->u.extended.attr, attr) == 0) { - tree->u.extended.attr = replace; - } - break; - } -} diff --git a/ldb/common/ldb_utf8.c b/ldb/common/ldb_utf8.c deleted file mode 100644 index 69ee2b696..000000000 --- a/ldb/common/ldb_utf8.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - ldb database library - - Copyright (C) Andrew Tridgell 2004 - - ** 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -/* - * Name: ldb - * - * Component: ldb utf8 handling - * - * Description: case folding and case comparison for UTF8 strings - * - * Author: Andrew Tridgell - */ - -#include "ldb_includes.h" -#include "system/locale.h" - - -/* - this allow the user to pass in a caseless comparison - function to handle utf8 caseless comparisons - */ -void ldb_set_utf8_fns(struct ldb_context *ldb, - void *context, - char *(*casefold)(void *, void *, const char *, size_t)) -{ - if (context) - ldb->utf8_fns.context = context; - if (casefold) - ldb->utf8_fns.casefold = casefold; -} - -/* - a simple case folding function - NOTE: does not handle UTF8 -*/ -char *ldb_casefold_default(void *context, void *mem_ctx, const char *s, size_t n) -{ - int i; - char *ret = talloc_strndup(mem_ctx, s, n); - if (!s) { - errno = ENOMEM; - return NULL; - } - for (i=0;ret[i];i++) { - ret[i] = toupper((unsigned char)ret[i]); - } - return ret; -} - -void ldb_set_utf8_default(struct ldb_context *ldb) -{ - ldb_set_utf8_fns(ldb, NULL, ldb_casefold_default); -} - -char *ldb_casefold(struct ldb_context *ldb, void *mem_ctx, const char *s, size_t n) -{ - return ldb->utf8_fns.casefold(ldb->utf8_fns.context, mem_ctx, s, n); -} - -/* - check the attribute name is valid according to rfc2251 - returns 1 if the name is ok - */ - -int ldb_valid_attr_name(const char *s) -{ - int i; - - if (!s || !s[0]) - return 0; - - /* handle special ldb_tdb wildcard */ - if (strcmp(s, "*") == 0) return 1; - - for (i = 0; s[i]; i++) { - if (! isascii(s[i])) { - return 0; - } - if (i == 0) { /* first char must be an alpha (or our special '@' identifier) */ - if (! (isalpha(s[i]) || (s[i] == '@'))) { - return 0; - } - } else { - if (! (isalnum(s[i]) || (s[i] == '-'))) { - return 0; - } - } - } - return 1; -} - -char *ldb_attr_casefold(void *mem_ctx, const char *s) -{ - int i; - char *ret = talloc_strdup(mem_ctx, s); - if (!ret) { - errno = ENOMEM; - return NULL; - } - for (i = 0; ret[i]; i++) { - ret[i] = toupper((unsigned char)ret[i]); - } - return ret; -} - -/* - we accept either 'dn' or 'distinguishedName' for a distinguishedName -*/ -int ldb_attr_dn(const char *attr) -{ - if (ldb_attr_cmp(attr, "dn") == 0 || - ldb_attr_cmp(attr, "distinguishedName") == 0) { - return 0; - } - return -1; -} diff --git a/ldb/common/qsort.c b/ldb/common/qsort.c deleted file mode 100644 index 0fa76d3b4..000000000 --- a/ldb/common/qsort.c +++ /dev/null @@ -1,251 +0,0 @@ -/* Copyright (C) 1991,1992,1996,1997,1999,2004 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Written by Douglas C. Schmidt (schmidt@ics.uci.edu). - - The GNU C 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.1 of the License, or (at your option) any later version. - - The GNU C 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 the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ - -/* If you consider tuning this algorithm, you should consult first: - Engineering a sort function; Jon Bentley and M. Douglas McIlroy; - Software - Practice and Experience; Vol. 23 (11), 1249-1265, 1993. */ - -/* Modified to be used in samba4 by - * Simo Sorce <idra@samba.org> 2005 - */ - -#include "ldb_includes.h" - -/* Byte-wise swap two items of size SIZE. */ -#define SWAP(a, b, size) \ - do \ - { \ - register size_t __size = (size); \ - register char *__a = (a), *__b = (b); \ - do \ - { \ - char __tmp = *__a; \ - *__a++ = *__b; \ - *__b++ = __tmp; \ - } while (--__size > 0); \ - } while (0) - -/* Discontinue quicksort algorithm when partition gets below this size. - This particular magic number was chosen to work best on a Sun 4/260. */ -#define MAX_THRESH 4 - -/* Stack node declarations used to store unfulfilled partition obligations. */ -typedef struct - { - char *lo; - char *hi; - } stack_node; - -/* The next 4 #defines implement a very fast in-line stack abstraction. */ -/* The stack needs log (total_elements) entries (we could even subtract - log(MAX_THRESH)). Since total_elements has type size_t, we get as - upper bound for log (total_elements): - bits per byte (CHAR_BIT) * sizeof(size_t). */ -#ifndef CHAR_BIT -#define CHAR_BIT 8 -#endif -#define STACK_SIZE (CHAR_BIT * sizeof(size_t)) -#define PUSH(low, high) ((void) ((top->lo = (low)), (top->hi = (high)), ++top)) -#define POP(low, high) ((void) (--top, (low = top->lo), (high = top->hi))) -#define STACK_NOT_EMPTY (stack < top) - - -/* Order size using quicksort. This implementation incorporates - four optimizations discussed in Sedgewick: - - 1. Non-recursive, using an explicit stack of pointer that store the - next array partition to sort. To save time, this maximum amount - of space required to store an array of SIZE_MAX is allocated on the - stack. Assuming a 32-bit (64 bit) integer for size_t, this needs - only 32 * sizeof(stack_node) == 256 bytes (for 64 bit: 1024 bytes). - Pretty cheap, actually. - - 2. Chose the pivot element using a median-of-three decision tree. - This reduces the probability of selecting a bad pivot value and - eliminates certain extraneous comparisons. - - 3. Only quicksorts TOTAL_ELEMS / MAX_THRESH partitions, leaving - insertion sort to order the MAX_THRESH items within each partition. - This is a big win, since insertion sort is faster for small, mostly - sorted array segments. - - 4. The larger of the two sub-partitions is always pushed onto the - stack first, with the algorithm then concentrating on the - smaller partition. This *guarantees* no more than log (total_elems) - stack size is needed (actually O(1) in this case)! */ - -void ldb_qsort (void *const pbase, size_t total_elems, size_t size, - void *opaque, ldb_qsort_cmp_fn_t cmp) -{ - register char *base_ptr = (char *) pbase; - - const size_t max_thresh = MAX_THRESH * size; - - if (total_elems == 0) - /* Avoid lossage with unsigned arithmetic below. */ - return; - - if (total_elems > MAX_THRESH) - { - char *lo = base_ptr; - char *hi = &lo[size * (total_elems - 1)]; - stack_node stack[STACK_SIZE]; - stack_node *top = stack; - - PUSH (NULL, NULL); - - while (STACK_NOT_EMPTY) - { - char *left_ptr; - char *right_ptr; - - /* Select median value from among LO, MID, and HI. Rearrange - LO and HI so the three values are sorted. This lowers the - probability of picking a pathological pivot value and - skips a comparison for both the LEFT_PTR and RIGHT_PTR in - the while loops. */ - - char *mid = lo + size * ((hi - lo) / size >> 1); - - if ((*cmp) ((void *) mid, (void *) lo, opaque) < 0) - SWAP (mid, lo, size); - if ((*cmp) ((void *) hi, (void *) mid, opaque) < 0) - SWAP (mid, hi, size); - else - goto jump_over; - if ((*cmp) ((void *) mid, (void *) lo, opaque) < 0) - SWAP (mid, lo, size); - jump_over:; - - left_ptr = lo + size; - right_ptr = hi - size; - - /* Here's the famous ``collapse the walls'' section of quicksort. - Gotta like those tight inner loops! They are the main reason - that this algorithm runs much faster than others. */ - do - { - while ((*cmp) ((void *) left_ptr, (void *) mid, opaque) < 0) - left_ptr += size; - - while ((*cmp) ((void *) mid, (void *) right_ptr, opaque) < 0) - right_ptr -= size; - - if (left_ptr < right_ptr) - { - SWAP (left_ptr, right_ptr, size); - if (mid == left_ptr) - mid = right_ptr; - else if (mid == right_ptr) - mid = left_ptr; - left_ptr += size; - right_ptr -= size; - } - else if (left_ptr == right_ptr) - { - left_ptr += size; - right_ptr -= size; - break; - } - } - while (left_ptr <= right_ptr); - - /* Set up pointers for next iteration. First determine whether - left and right partitions are below the threshold size. If so, - ignore one or both. Otherwise, push the larger partition's - bounds on the stack and continue sorting the smaller one. */ - - if ((size_t) (right_ptr - lo) <= max_thresh) - { - if ((size_t) (hi - left_ptr) <= max_thresh) - /* Ignore both small partitions. */ - POP (lo, hi); - else - /* Ignore small left partition. */ - lo = left_ptr; - } - else if ((size_t) (hi - left_ptr) <= max_thresh) - /* Ignore small right partition. */ - hi = right_ptr; - else if ((right_ptr - lo) > (hi - left_ptr)) - { - /* Push larger left partition indices. */ - PUSH (lo, right_ptr); - lo = left_ptr; - } - else - { - /* Push larger right partition indices. */ - PUSH (left_ptr, hi); - hi = right_ptr; - } - } - } - - /* Once the BASE_PTR array is partially sorted by quicksort the rest - is completely sorted using insertion sort, since this is efficient - for partitions below MAX_THRESH size. BASE_PTR points to the beginning - of the array to sort, and END_PTR points at the very last element in - the array (*not* one beyond it!). */ - -#define min(x, y) ((x) < (y) ? (x) : (y)) - - { - char *const end_ptr = &base_ptr[size * (total_elems - 1)]; - char *tmp_ptr = base_ptr; - char *thresh = min(end_ptr, base_ptr + max_thresh); - register char *run_ptr; - - /* Find smallest element in first threshold and place it at the - array's beginning. This is the smallest array element, - and the operation speeds up insertion sort's inner loop. */ - - for (run_ptr = tmp_ptr + size; run_ptr <= thresh; run_ptr += size) - if ((*cmp) ((void *) run_ptr, (void *) tmp_ptr, opaque) < 0) - tmp_ptr = run_ptr; - - if (tmp_ptr != base_ptr) - SWAP (tmp_ptr, base_ptr, size); - - /* Insertion sort, running from left-hand-side up to right-hand-side. */ - - run_ptr = base_ptr + size; - while ((run_ptr += size) <= end_ptr) - { - tmp_ptr = run_ptr - size; - while ((*cmp) ((void *) run_ptr, (void *) tmp_ptr, opaque) < 0) - tmp_ptr -= size; - - tmp_ptr += size; - if (tmp_ptr != run_ptr) - { - char *trav; - - trav = run_ptr + size; - while (--trav >= run_ptr) - { - char c = *trav; - char *hi, *lo; - - for (hi = lo = trav; (lo -= size) >= tmp_ptr; hi = lo) - *hi = *lo; - *hi = c; - } - } - } - } -} diff --git a/ldb/config.guess b/ldb/config.guess deleted file mode 100755 index 354dbe175..000000000 --- a/ldb/config.guess +++ /dev/null @@ -1,1464 +0,0 @@ -#! /bin/sh -# Attempt to guess a canonical system name. -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -timestamp='2005-08-03' - -# This file is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program 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 -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, see <http://www.gnu.org/licenses/>. -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - - -# Originally written by Per Bothner <per@bothner.com>. -# Please send patches to <config-patches@gnu.org>. Submit a context -# diff and a properly formatted ChangeLog entry. -# -# This script attempts to guess a canonical system name similar to -# config.sub. If it succeeds, it prints the system name on stdout, and -# exits with 0. Otherwise, it exits with 1. -# -# The plan is that this can be called by configure scripts if you -# don't specify an explicit build system type. - -me=`echo "$0" | sed -e 's,.*/,,'` - -usage="\ -Usage: $0 [OPTION] - -Output the configuration name of the system \`$me' is run on. - -Operation modes: - -h, --help print this help, then exit - -t, --time-stamp print date of last modification, then exit - -v, --version print version number, then exit - -Report bugs and patches to <config-patches@gnu.org>." - -version="\ -GNU config.guess ($timestamp) - -Originally written by Per Bothner. -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 -Free Software Foundation, Inc. - -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - -help=" -Try \`$me --help' for more information." - -# Parse command line -while test $# -gt 0 ; do - case $1 in - --time-stamp | --time* | -t ) - echo "$timestamp" ; exit ;; - --version | -v ) - echo "$version" ; exit ;; - --help | --h* | -h ) - echo "$usage"; exit ;; - -- ) # Stop option processing - shift; break ;; - - ) # Use stdin as input. - break ;; - -* ) - echo "$me: invalid option $1$help" >&2 - exit 1 ;; - * ) - break ;; - esac -done - -if test $# != 0; then - echo "$me: too many arguments$help" >&2 - exit 1 -fi - -trap 'exit 1' 1 2 15 - -# CC_FOR_BUILD -- compiler used by this script. Note that the use of a -# compiler to aid in system detection is discouraged as it requires -# temporary files to be created and, as you can see below, it is a -# headache to deal with in a portable fashion. - -# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still -# use `HOST_CC' if defined, but it is deprecated. - -# Portable tmp directory creation inspired by the Autoconf team. - -set_cc_for_build=' -trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ; -trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ; -: ${TMPDIR=/tmp} ; - { tmp=`(umask 077 && mktemp -d -q "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } || - { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } || - { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } || - { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ; -dummy=$tmp/dummy ; -tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ; -case $CC_FOR_BUILD,$HOST_CC,$CC in - ,,) echo "int x;" > $dummy.c ; - for c in cc gcc c89 c99 ; do - if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then - CC_FOR_BUILD="$c"; break ; - fi ; - done ; - if test x"$CC_FOR_BUILD" = x ; then - CC_FOR_BUILD=no_compiler_found ; - fi - ;; - ,,*) CC_FOR_BUILD=$CC ;; - ,*,*) CC_FOR_BUILD=$HOST_CC ;; -esac ; set_cc_for_build= ;' - -# This is needed to find uname on a Pyramid OSx when run in the BSD universe. -# (ghazi@noc.rutgers.edu 1994-08-24) -if (test -f /.attbin/uname) >/dev/null 2>&1 ; then - PATH=$PATH:/.attbin ; export PATH -fi - -UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown -UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown -UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown -UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown - -# Note: order is significant - the case branches are not exclusive. - -case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in - *:NetBSD:*:*) - # NetBSD (nbsd) targets should (where applicable) match one or - # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, - # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently - # switched to ELF, *-*-netbsd* would select the old - # object file format. This provides both forward - # compatibility and a consistent mechanism for selecting the - # object file format. - # - # Note: NetBSD doesn't particularly care about the vendor - # portion of the name. We always set it to "unknown". - sysctl="sysctl -n hw.machine_arch" - UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ - /usr/sbin/$sysctl 2>/dev/null || echo unknown)` - case "${UNAME_MACHINE_ARCH}" in - armeb) machine=armeb-unknown ;; - arm*) machine=arm-unknown ;; - sh3el) machine=shl-unknown ;; - sh3eb) machine=sh-unknown ;; - *) machine=${UNAME_MACHINE_ARCH}-unknown ;; - esac - # The Operating System including object format, if it has switched - # to ELF recently, or will in the future. - case "${UNAME_MACHINE_ARCH}" in - arm*|i386|m68k|ns32k|sh3*|sparc|vax) - eval $set_cc_for_build - if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ - | grep __ELF__ >/dev/null - then - # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). - # Return netbsd for either. FIX? - os=netbsd - else - os=netbsdelf - fi - ;; - *) - os=netbsd - ;; - esac - # The OS release - # Debian GNU/NetBSD machines have a different userland, and - # thus, need a distinct triplet. However, they do not need - # kernel version information, so it can be replaced with a - # suitable tag, in the style of linux-gnu. - case "${UNAME_VERSION}" in - Debian*) - release='-gnu' - ;; - *) - release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` - ;; - esac - # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: - # contains redundant information, the shorter form: - # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. - echo "${machine}-${os}${release}" - exit ;; - *:OpenBSD:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` - echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} - exit ;; - *:ekkoBSD:*:*) - echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} - exit ;; - macppc:MirBSD:*:*) - echo powerppc-unknown-mirbsd${UNAME_RELEASE} - exit ;; - *:MirBSD:*:*) - echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} - exit ;; - alpha:OSF1:*:*) - case $UNAME_RELEASE in - *4.0) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` - ;; - *5.*) - UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'` - ;; - esac - # According to Compaq, /usr/sbin/psrinfo has been available on - # OSF/1 and Tru64 systems produced since 1995. I hope that - # covers most systems running today. This code pipes the CPU - # types through head -n 1, so we only detect the type of CPU 0. - ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` - case "$ALPHA_CPU_TYPE" in - "EV4 (21064)") - UNAME_MACHINE="alpha" ;; - "EV4.5 (21064)") - UNAME_MACHINE="alpha" ;; - "LCA4 (21066/21068)") - UNAME_MACHINE="alpha" ;; - "EV5 (21164)") - UNAME_MACHINE="alphaev5" ;; - "EV5.6 (21164A)") - UNAME_MACHINE="alphaev56" ;; - "EV5.6 (21164PC)") - UNAME_MACHINE="alphapca56" ;; - "EV5.7 (21164PC)") - UNAME_MACHINE="alphapca57" ;; - "EV6 (21264)") - UNAME_MACHINE="alphaev6" ;; - "EV6.7 (21264A)") - UNAME_MACHINE="alphaev67" ;; - "EV6.8CB (21264C)") - UNAME_MACHINE="alphaev68" ;; - "EV6.8AL (21264B)") - UNAME_MACHINE="alphaev68" ;; - "EV6.8CX (21264D)") - UNAME_MACHINE="alphaev68" ;; - "EV6.9A (21264/EV69A)") - UNAME_MACHINE="alphaev69" ;; - "EV7 (21364)") - UNAME_MACHINE="alphaev7" ;; - "EV7.9 (21364A)") - UNAME_MACHINE="alphaev79" ;; - esac - # A Pn.n version is a patched version. - # A Vn.n version is a released version. - # A Tn.n version is a released field test version. - # A Xn.n version is an unreleased experimental baselevel. - # 1.2 uses "1.2" for uname -r. - echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - exit ;; - Alpha\ *:Windows_NT*:*) - # How do we know it's Interix rather than the generic POSIX subsystem? - # Should we change UNAME_MACHINE based on the output of uname instead - # of the specific Alpha model? - echo alpha-pc-interix - exit ;; - 21064:Windows_NT:50:3) - echo alpha-dec-winnt3.5 - exit ;; - Amiga*:UNIX_System_V:4.0:*) - echo m68k-unknown-sysv4 - exit ;; - *:[Aa]miga[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-unknown-amigaos - exit ;; - *:[Mm]orph[Oo][Ss]:*:*) - echo ${UNAME_MACHINE}-unknown-morphos - exit ;; - *:OS/390:*:*) - echo i370-ibm-openedition - exit ;; - *:z/VM:*:*) - echo s390-ibm-zvmoe - exit ;; - *:OS400:*:*) - echo powerpc-ibm-os400 - exit ;; - arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) - echo arm-acorn-riscix${UNAME_RELEASE} - exit ;; - arm:riscos:*:*|arm:RISCOS:*:*) - echo arm-unknown-riscos - exit ;; - SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) - echo hppa1.1-hitachi-hiuxmpp - exit ;; - Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) - # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. - if test "`(/bin/universe) 2>/dev/null`" = att ; then - echo pyramid-pyramid-sysv3 - else - echo pyramid-pyramid-bsd - fi - exit ;; - NILE*:*:*:dcosx) - echo pyramid-pyramid-svr4 - exit ;; - DRS?6000:unix:4.0:6*) - echo sparc-icl-nx6 - exit ;; - DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*) - case `/usr/bin/uname -p` in - sparc) echo sparc-icl-nx7; exit ;; - esac ;; - sun4H:SunOS:5.*:*) - echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) - echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - i86pc:SunOS:5.*:*) - echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4*:SunOS:6*:*) - # According to config.sub, this is the proper way to canonicalize - # SunOS6. Hard to guess exactly what SunOS6 will be like, but - # it's likely to be more like Solaris than SunOS4. - echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - sun4*:SunOS:*:*) - case "`/usr/bin/arch -k`" in - Series*|S4*) - UNAME_RELEASE=`uname -v` - ;; - esac - # Japanese Language versions have a version number like `4.1.3-JL'. - echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` - exit ;; - sun3*:SunOS:*:*) - echo m68k-sun-sunos${UNAME_RELEASE} - exit ;; - sun*:*:4.2BSD:*) - UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` - test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 - case "`/bin/arch`" in - sun3) - echo m68k-sun-sunos${UNAME_RELEASE} - ;; - sun4) - echo sparc-sun-sunos${UNAME_RELEASE} - ;; - esac - exit ;; - aushp:SunOS:*:*) - echo sparc-auspex-sunos${UNAME_RELEASE} - exit ;; - # The situation for MiNT is a little confusing. The machine name - # can be virtually everything (everything which is not - # "atarist" or "atariste" at least should have a processor - # > m68000). The system name ranges from "MiNT" over "FreeMiNT" - # to the lowercase version "mint" (or "freemint"). Finally - # the system name "TOS" denotes a system which is actually not - # MiNT. But MiNT is downward compatible to TOS, so this should - # be no problem. - atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; - atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; - *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) - echo m68k-atari-mint${UNAME_RELEASE} - exit ;; - milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) - echo m68k-milan-mint${UNAME_RELEASE} - exit ;; - hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) - echo m68k-hades-mint${UNAME_RELEASE} - exit ;; - *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) - echo m68k-unknown-mint${UNAME_RELEASE} - exit ;; - m68k:machten:*:*) - echo m68k-apple-machten${UNAME_RELEASE} - exit ;; - powerpc:machten:*:*) - echo powerpc-apple-machten${UNAME_RELEASE} - exit ;; - RISC*:Mach:*:*) - echo mips-dec-mach_bsd4.3 - exit ;; - RISC*:ULTRIX:*:*) - echo mips-dec-ultrix${UNAME_RELEASE} - exit ;; - VAX*:ULTRIX*:*:*) - echo vax-dec-ultrix${UNAME_RELEASE} - exit ;; - 2020:CLIX:*:* | 2430:CLIX:*:*) - echo clipper-intergraph-clix${UNAME_RELEASE} - exit ;; - mips:*:*:UMIPS | mips:*:*:RISCos) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c -#ifdef __cplusplus -#include <stdio.h> /* for printf() prototype */ - int main (int argc, char *argv[]) { -#else - int main (argc, argv) int argc; char *argv[]; { -#endif - #if defined (host_mips) && defined (MIPSEB) - #if defined (SYSTYPE_SYSV) - printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); - #endif - #if defined (SYSTYPE_SVR4) - printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); - #endif - #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) - printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); - #endif - #endif - exit (-1); - } -EOF - $CC_FOR_BUILD -o $dummy $dummy.c && - dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` && - SYSTEM_NAME=`$dummy $dummyarg` && - { echo "$SYSTEM_NAME"; exit; } - echo mips-mips-riscos${UNAME_RELEASE} - exit ;; - Motorola:PowerMAX_OS:*:*) - echo powerpc-motorola-powermax - exit ;; - Motorola:*:4.3:PL8-*) - echo powerpc-harris-powermax - exit ;; - Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*) - echo powerpc-harris-powermax - exit ;; - Night_Hawk:Power_UNIX:*:*) - echo powerpc-harris-powerunix - exit ;; - m88k:CX/UX:7*:*) - echo m88k-harris-cxux7 - exit ;; - m88k:*:4*:R4*) - echo m88k-motorola-sysv4 - exit ;; - m88k:*:3*:R3*) - echo m88k-motorola-sysv3 - exit ;; - AViiON:dgux:*:*) - # DG/UX returns AViiON for all architectures - UNAME_PROCESSOR=`/usr/bin/uname -p` - if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] - then - if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ - [ ${TARGET_BINARY_INTERFACE}x = x ] - then - echo m88k-dg-dgux${UNAME_RELEASE} - else - echo m88k-dg-dguxbcs${UNAME_RELEASE} - fi - else - echo i586-dg-dgux${UNAME_RELEASE} - fi - exit ;; - M88*:DolphinOS:*:*) # DolphinOS (SVR3) - echo m88k-dolphin-sysv3 - exit ;; - M88*:*:R3*:*) - # Delta 88k system running SVR3 - echo m88k-motorola-sysv3 - exit ;; - XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) - echo m88k-tektronix-sysv3 - exit ;; - Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) - echo m68k-tektronix-bsd - exit ;; - *:IRIX*:*:*) - echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` - exit ;; - ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. - echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id - exit ;; # Note that: echo "'`uname -s`'" gives 'AIX ' - i*86:AIX:*:*) - echo i386-ibm-aix - exit ;; - ia64:AIX:*:*) - if [ -x /usr/bin/oslevel ] ; then - IBM_REV=`/usr/bin/oslevel` - else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} - fi - echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} - exit ;; - *:AIX:2:3) - if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include <sys/systemcfg.h> - - main() - { - if (!__power_pc()) - exit(1); - puts("powerpc-ibm-aix3.2.5"); - exit(0); - } -EOF - if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` - then - echo "$SYSTEM_NAME" - else - echo rs6000-ibm-aix3.2.5 - fi - elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then - echo rs6000-ibm-aix3.2.4 - else - echo rs6000-ibm-aix3.2 - fi - exit ;; - *:AIX:*:[45]) - IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` - if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then - IBM_ARCH=rs6000 - else - IBM_ARCH=powerpc - fi - if [ -x /usr/bin/oslevel ] ; then - IBM_REV=`/usr/bin/oslevel` - else - IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} - fi - echo ${IBM_ARCH}-ibm-aix${IBM_REV} - exit ;; - *:AIX:*:*) - echo rs6000-ibm-aix - exit ;; - ibmrt:4.4BSD:*|romp-ibm:BSD:*) - echo romp-ibm-bsd4.4 - exit ;; - ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and - echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to - exit ;; # report: romp-ibm BSD 4.3 - *:BOSX:*:*) - echo rs6000-bull-bosx - exit ;; - DPX/2?00:B.O.S.:*:*) - echo m68k-bull-sysv3 - exit ;; - 9000/[34]??:4.3bsd:1.*:*) - echo m68k-hp-bsd - exit ;; - hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) - echo m68k-hp-bsd4.4 - exit ;; - 9000/[34678]??:HP-UX:*:*) - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` - case "${UNAME_MACHINE}" in - 9000/31? ) HP_ARCH=m68000 ;; - 9000/[34]?? ) HP_ARCH=m68k ;; - 9000/[678][0-9][0-9]) - if [ -x /usr/bin/getconf ]; then - sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` - sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` - case "${sc_cpu_version}" in - 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 - 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 - 532) # CPU_PA_RISC2_0 - case "${sc_kernel_bits}" in - 32) HP_ARCH="hppa2.0n" ;; - 64) HP_ARCH="hppa2.0w" ;; - '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 - esac ;; - esac - fi - if [ "${HP_ARCH}" = "" ]; then - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - - #define _HPUX_SOURCE - #include <stdlib.h> - #include <unistd.h> - - int main () - { - #if defined(_SC_KERNEL_BITS) - long bits = sysconf(_SC_KERNEL_BITS); - #endif - long cpu = sysconf (_SC_CPU_VERSION); - - switch (cpu) - { - case CPU_PA_RISC1_0: puts ("hppa1.0"); break; - case CPU_PA_RISC1_1: puts ("hppa1.1"); break; - case CPU_PA_RISC2_0: - #if defined(_SC_KERNEL_BITS) - switch (bits) - { - case 64: puts ("hppa2.0w"); break; - case 32: puts ("hppa2.0n"); break; - default: puts ("hppa2.0"); break; - } break; - #else /* !defined(_SC_KERNEL_BITS) */ - puts ("hppa2.0"); break; - #endif - default: puts ("hppa1.0"); break; - } - exit (0); - } -EOF - (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` - test -z "$HP_ARCH" && HP_ARCH=hppa - fi ;; - esac - if [ ${HP_ARCH} = "hppa2.0w" ] - then - eval $set_cc_for_build - - # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating - # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler - # generating 64-bit code. GNU and HP use different nomenclature: - # - # $ CC_FOR_BUILD=cc ./config.guess - # => hppa2.0w-hp-hpux11.23 - # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess - # => hppa64-hp-hpux11.23 - - if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | - grep __LP64__ >/dev/null - then - HP_ARCH="hppa2.0w" - else - HP_ARCH="hppa64" - fi - fi - echo ${HP_ARCH}-hp-hpux${HPUX_REV} - exit ;; - ia64:HP-UX:*:*) - HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` - echo ia64-hp-hpux${HPUX_REV} - exit ;; - 3050*:HI-UX:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include <unistd.h> - int - main () - { - long cpu = sysconf (_SC_CPU_VERSION); - /* The order matters, because CPU_IS_HP_MC68K erroneously returns - true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct - results, however. */ - if (CPU_IS_PA_RISC (cpu)) - { - switch (cpu) - { - case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; - case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; - case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; - default: puts ("hppa-hitachi-hiuxwe2"); break; - } - } - else if (CPU_IS_HP_MC68K (cpu)) - puts ("m68k-hitachi-hiuxwe2"); - else puts ("unknown-hitachi-hiuxwe2"); - exit (0); - } -EOF - $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` && - { echo "$SYSTEM_NAME"; exit; } - echo unknown-hitachi-hiuxwe2 - exit ;; - 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) - echo hppa1.1-hp-bsd - exit ;; - 9000/8??:4.3bsd:*:*) - echo hppa1.0-hp-bsd - exit ;; - *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) - echo hppa1.0-hp-mpeix - exit ;; - hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) - echo hppa1.1-hp-osf - exit ;; - hp8??:OSF1:*:*) - echo hppa1.0-hp-osf - exit ;; - i*86:OSF1:*:*) - if [ -x /usr/sbin/sysversion ] ; then - echo ${UNAME_MACHINE}-unknown-osf1mk - else - echo ${UNAME_MACHINE}-unknown-osf1 - fi - exit ;; - parisc*:Lites*:*:*) - echo hppa1.1-hp-lites - exit ;; - C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) - echo c1-convex-bsd - exit ;; - C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) - if getsysinfo -f scalar_acc - then echo c32-convex-bsd - else echo c2-convex-bsd - fi - exit ;; - C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) - echo c34-convex-bsd - exit ;; - C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) - echo c38-convex-bsd - exit ;; - C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) - echo c4-convex-bsd - exit ;; - CRAY*Y-MP:*:*:*) - echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*[A-Z]90:*:*:*) - echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ - | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ - -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ - -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*TS:*:*:*) - echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*T3E:*:*:*) - echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - CRAY*SV1:*:*:*) - echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - *:UNICOS/mp:*:*) - echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' - exit ;; - F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) - FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` - echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; - 5000:UNIX_System_V:4.*:*) - FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` - echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" - exit ;; - i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) - echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} - exit ;; - sparc*:BSD/OS:*:*) - echo sparc-unknown-bsdi${UNAME_RELEASE} - exit ;; - *:BSD/OS:*:*) - echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} - exit ;; - *:FreeBSD:*:*) - echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` - exit ;; - i*:CYGWIN*:*) - echo ${UNAME_MACHINE}-pc-cygwin - exit ;; - i*:MINGW*:*) - echo ${UNAME_MACHINE}-pc-mingw32 - exit ;; - i*:windows32*:*) - # uname -m includes "-pc" on this system. - echo ${UNAME_MACHINE}-mingw32 - exit ;; - i*:PW*:*) - echo ${UNAME_MACHINE}-pc-pw32 - exit ;; - x86:Interix*:[34]*) - echo i586-pc-interix${UNAME_RELEASE}|sed -e 's/\..*//' - exit ;; - [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*) - echo i${UNAME_MACHINE}-pc-mks - exit ;; - i*:Windows_NT*:* | Pentium*:Windows_NT*:*) - # How do we know it's Interix rather than the generic POSIX subsystem? - # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we - # UNAME_MACHINE based on the output of uname instead of i386? - echo i586-pc-interix - exit ;; - i*:UWIN*:*) - echo ${UNAME_MACHINE}-pc-uwin - exit ;; - amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*) - echo x86_64-unknown-cygwin - exit ;; - p*:CYGWIN*:*) - echo powerpcle-unknown-cygwin - exit ;; - prep*:SunOS:5.*:*) - echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` - exit ;; - *:GNU:*:*) - # the GNU system - echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` - exit ;; - *:GNU/*:*:*) - # other systems with GNU libc and userland - echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu - exit ;; - i*86:Minix:*:*) - echo ${UNAME_MACHINE}-pc-minix - exit ;; - arm*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - cris:Linux:*:*) - echo cris-axis-linux-gnu - exit ;; - crisv32:Linux:*:*) - echo crisv32-axis-linux-gnu - exit ;; - frv:Linux:*:*) - echo frv-unknown-linux-gnu - exit ;; - ia64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - m32r*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - m68*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - mips:Linux:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #undef CPU - #undef mips - #undef mipsel - #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - CPU=mipsel - #else - #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - CPU=mips - #else - CPU= - #endif - #endif -EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=` - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } - ;; - mips64:Linux:*:*) - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #undef CPU - #undef mips64 - #undef mips64el - #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) - CPU=mips64el - #else - #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) - CPU=mips64 - #else - CPU= - #endif - #endif -EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=` - test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; } - ;; - or32:Linux:*:*) - echo or32-unknown-linux-gnu - exit ;; - ppc:Linux:*:*) - echo powerpc-unknown-linux-gnu - exit ;; - ppc64:Linux:*:*) - echo powerpc64-unknown-linux-gnu - exit ;; - alpha:Linux:*:*) - case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in - EV5) UNAME_MACHINE=alphaev5 ;; - EV56) UNAME_MACHINE=alphaev56 ;; - PCA56) UNAME_MACHINE=alphapca56 ;; - PCA57) UNAME_MACHINE=alphapca56 ;; - EV6) UNAME_MACHINE=alphaev6 ;; - EV67) UNAME_MACHINE=alphaev67 ;; - EV68*) UNAME_MACHINE=alphaev68 ;; - esac - objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null - if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi - echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} - exit ;; - parisc:Linux:*:* | hppa:Linux:*:*) - # Look for CPU level - case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in - PA7*) echo hppa1.1-unknown-linux-gnu ;; - PA8*) echo hppa2.0-unknown-linux-gnu ;; - *) echo hppa-unknown-linux-gnu ;; - esac - exit ;; - parisc64:Linux:*:* | hppa64:Linux:*:*) - echo hppa64-unknown-linux-gnu - exit ;; - s390:Linux:*:* | s390x:Linux:*:*) - echo ${UNAME_MACHINE}-ibm-linux - exit ;; - sh64*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - sh*:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - sparc:Linux:*:* | sparc64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-gnu - exit ;; - x86_64:Linux:*:*) - echo x86_64-unknown-linux-gnu - exit ;; - i*86:Linux:*:*) - # The BFD linker knows what the default object file format is, so - # first see if it will tell us. cd to the root directory to prevent - # problems with other programs or directories called `ld' in the path. - # Set LC_ALL=C to ensure ld outputs messages in English. - ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \ - | sed -ne '/supported targets:/!d - s/[ ][ ]*/ /g - s/.*supported targets: *// - s/ .*// - p'` - case "$ld_supported_targets" in - elf32-i386) - TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" - ;; - a.out-i386-linux) - echo "${UNAME_MACHINE}-pc-linux-gnuaout" - exit ;; - coff-i386) - echo "${UNAME_MACHINE}-pc-linux-gnucoff" - exit ;; - "") - # Either a pre-BFD a.out linker (linux-gnuoldld) or - # one that does not give us useful --help. - echo "${UNAME_MACHINE}-pc-linux-gnuoldld" - exit ;; - esac - # Determine whether the default compiler is a.out or elf - eval $set_cc_for_build - sed 's/^ //' << EOF >$dummy.c - #include <features.h> - #ifdef __ELF__ - # ifdef __GLIBC__ - # if __GLIBC__ >= 2 - LIBC=gnu - # else - LIBC=gnulibc1 - # endif - # else - LIBC=gnulibc1 - # endif - #else - #ifdef __INTEL_COMPILER - LIBC=gnu - #else - LIBC=gnuaout - #endif - #endif - #ifdef __dietlibc__ - LIBC=dietlibc - #endif -EOF - eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` - test x"${LIBC}" != x && { - echo "${UNAME_MACHINE}-pc-linux-${LIBC}" - exit - } - test x"${TENTATIVE}" != x && { echo "${TENTATIVE}"; exit; } - ;; - i*86:DYNIX/ptx:4*:*) - # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. - # earlier versions are messed up and put the nodename in both - # sysname and nodename. - echo i386-sequent-sysv4 - exit ;; - i*86:UNIX_SV:4.2MP:2.*) - # Unixware is an offshoot of SVR4, but it has its own version - # number series starting with 2... - # I am not positive that other SVR4 systems won't match this, - # I just have to hope. -- rms. - # Use sysv4.2uw... so that sysv4* matches it. - echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} - exit ;; - i*86:OS/2:*:*) - # If we were able to find `uname', then EMX Unix compatibility - # is probably installed. - echo ${UNAME_MACHINE}-pc-os2-emx - exit ;; - i*86:XTS-300:*:STOP) - echo ${UNAME_MACHINE}-unknown-stop - exit ;; - i*86:atheos:*:*) - echo ${UNAME_MACHINE}-unknown-atheos - exit ;; - i*86:syllable:*:*) - echo ${UNAME_MACHINE}-pc-syllable - exit ;; - i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) - echo i386-unknown-lynxos${UNAME_RELEASE} - exit ;; - i*86:*DOS:*:*) - echo ${UNAME_MACHINE}-pc-msdosdjgpp - exit ;; - i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) - UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` - if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then - echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} - else - echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} - fi - exit ;; - i*86:*:5:[678]*) - # UnixWare 7.x, OpenUNIX and OpenServer 6. - case `/bin/uname -X | grep "^Machine"` in - *486*) UNAME_MACHINE=i486 ;; - *Pentium) UNAME_MACHINE=i586 ;; - *Pent*|*Celeron) UNAME_MACHINE=i686 ;; - esac - echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} - exit ;; - i*86:*:3.2:*) - if test -f /usr/options/cb.name; then - UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name` - echo ${UNAME_MACHINE}-pc-isc$UNAME_REL - elif /bin/uname -X 2>/dev/null >/dev/null ; then - UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` - (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 - (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ - && UNAME_MACHINE=i586 - (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ - && UNAME_MACHINE=i686 - (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ - && UNAME_MACHINE=i686 - echo ${UNAME_MACHINE}-pc-sco$UNAME_REL - else - echo ${UNAME_MACHINE}-pc-sysv32 - fi - exit ;; - pc:*:*:*) - # Left here for compatibility: - # uname -m prints for DJGPP always 'pc', but it prints nothing about - # the processor, so we play safe by assuming i386. - echo i386-pc-msdosdjgpp - exit ;; - Intel:Mach:3*:*) - echo i386-pc-mach3 - exit ;; - paragon:*:*:*) - echo i860-intel-osf1 - exit ;; - i860:*:4.*:*) # i860-SVR4 - if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then - echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 - else # Add other i860-SVR4 vendors below as they are discovered. - echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 - fi - exit ;; - mini*:CTIX:SYS*5:*) - # "miniframe" - echo m68010-convergent-sysv - exit ;; - mc68k:UNIX:SYSTEM5:3.51m) - echo m68k-convergent-sysv - exit ;; - M680?0:D-NIX:5.3:*) - echo m68k-diab-dnix - exit ;; - M68*:*:R3V[5678]*:*) - test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;; - 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0) - OS_REL='' - test -r /etc/.relid \ - && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4.3${OS_REL}; exit; } - /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ - && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;; - 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) - /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ - && { echo i486-ncr-sysv4; exit; } ;; - m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) - echo m68k-unknown-lynxos${UNAME_RELEASE} - exit ;; - mc68030:UNIX_System_V:4.*:*) - echo m68k-atari-sysv4 - exit ;; - TSUNAMI:LynxOS:2.*:*) - echo sparc-unknown-lynxos${UNAME_RELEASE} - exit ;; - rs6000:LynxOS:2.*:*) - echo rs6000-unknown-lynxos${UNAME_RELEASE} - exit ;; - PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) - echo powerpc-unknown-lynxos${UNAME_RELEASE} - exit ;; - SM[BE]S:UNIX_SV:*:*) - echo mips-dde-sysv${UNAME_RELEASE} - exit ;; - RM*:ReliantUNIX-*:*:*) - echo mips-sni-sysv4 - exit ;; - RM*:SINIX-*:*:*) - echo mips-sni-sysv4 - exit ;; - *:SINIX-*:*:*) - if uname -p 2>/dev/null >/dev/null ; then - UNAME_MACHINE=`(uname -p) 2>/dev/null` - echo ${UNAME_MACHINE}-sni-sysv4 - else - echo ns32k-sni-sysv - fi - exit ;; - PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort - # says <Richard.M.Bartel@ccMail.Census.GOV> - echo i586-unisys-sysv4 - exit ;; - *:UNIX_System_V:4*:FTX*) - # From Gerald Hewes <hewes@openmarket.com>. - # How about differentiating between stratus architectures? -djm - echo hppa1.1-stratus-sysv4 - exit ;; - *:*:*:FTX*) - # From seanf@swdc.stratus.com. - echo i860-stratus-sysv4 - exit ;; - i*86:VOS:*:*) - # From Paul.Green@stratus.com. - echo ${UNAME_MACHINE}-stratus-vos - exit ;; - *:VOS:*:*) - # From Paul.Green@stratus.com. - echo hppa1.1-stratus-vos - exit ;; - mc68*:A/UX:*:*) - echo m68k-apple-aux${UNAME_RELEASE} - exit ;; - news*:NEWS-OS:6*:*) - echo mips-sony-newsos6 - exit ;; - R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) - if [ -d /usr/nec ]; then - echo mips-nec-sysv${UNAME_RELEASE} - else - echo mips-unknown-sysv${UNAME_RELEASE} - fi - exit ;; - BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. - echo powerpc-be-beos - exit ;; - BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. - echo powerpc-apple-beos - exit ;; - BePC:BeOS:*:*) # BeOS running on Intel PC compatible. - echo i586-pc-beos - exit ;; - SX-4:SUPER-UX:*:*) - echo sx4-nec-superux${UNAME_RELEASE} - exit ;; - SX-5:SUPER-UX:*:*) - echo sx5-nec-superux${UNAME_RELEASE} - exit ;; - SX-6:SUPER-UX:*:*) - echo sx6-nec-superux${UNAME_RELEASE} - exit ;; - Power*:Rhapsody:*:*) - echo powerpc-apple-rhapsody${UNAME_RELEASE} - exit ;; - *:Rhapsody:*:*) - echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} - exit ;; - *:Darwin:*:*) - UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown - case $UNAME_PROCESSOR in - *86) UNAME_PROCESSOR=i686 ;; - unknown) UNAME_PROCESSOR=powerpc ;; - esac - echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE} - exit ;; - *:procnto*:*:* | *:QNX:[0123456789]*:*) - UNAME_PROCESSOR=`uname -p` - if test "$UNAME_PROCESSOR" = "x86"; then - UNAME_PROCESSOR=i386 - UNAME_MACHINE=pc - fi - echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} - exit ;; - *:QNX:*:4*) - echo i386-pc-qnx - exit ;; - NSE-?:NONSTOP_KERNEL:*:*) - echo nse-tandem-nsk${UNAME_RELEASE} - exit ;; - NSR-?:NONSTOP_KERNEL:*:*) - echo nsr-tandem-nsk${UNAME_RELEASE} - exit ;; - *:NonStop-UX:*:*) - echo mips-compaq-nonstopux - exit ;; - BS2000:POSIX*:*:*) - echo bs2000-siemens-sysv - exit ;; - DS/*:UNIX_System_V:*:*) - echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} - exit ;; - *:Plan9:*:*) - # "uname -m" is not consistent, so use $cputype instead. 386 - # is converted to i386 for consistency with other x86 - # operating systems. - if test "$cputype" = "386"; then - UNAME_MACHINE=i386 - else - UNAME_MACHINE="$cputype" - fi - echo ${UNAME_MACHINE}-unknown-plan9 - exit ;; - *:TOPS-10:*:*) - echo pdp10-unknown-tops10 - exit ;; - *:TENEX:*:*) - echo pdp10-unknown-tenex - exit ;; - KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) - echo pdp10-dec-tops20 - exit ;; - XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) - echo pdp10-xkl-tops20 - exit ;; - *:TOPS-20:*:*) - echo pdp10-unknown-tops20 - exit ;; - *:ITS:*:*) - echo pdp10-unknown-its - exit ;; - SEI:*:*:SEIUX) - echo mips-sei-seiux${UNAME_RELEASE} - exit ;; - *:DragonFly:*:*) - echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` - exit ;; - *:*VMS:*:*) - UNAME_MACHINE=`(uname -p) 2>/dev/null` - case "${UNAME_MACHINE}" in - A*) echo alpha-dec-vms ; exit ;; - I*) echo ia64-dec-vms ; exit ;; - V*) echo vax-dec-vms ; exit ;; - esac ;; - *:XENIX:*:SysV) - echo i386-pc-xenix - exit ;; - i*86:skyos:*:*) - echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' - exit ;; -esac - -#echo '(No uname command or uname output not recognized.)' 1>&2 -#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 - -eval $set_cc_for_build -cat >$dummy.c <<EOF -#ifdef _SEQUENT_ -# include <sys/types.h> -# include <sys/utsname.h> -#endif -main () -{ -#if defined (sony) -#if defined (MIPSEB) - /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, - I don't know.... */ - printf ("mips-sony-bsd\n"); exit (0); -#else -#include <sys/param.h> - printf ("m68k-sony-newsos%s\n", -#ifdef NEWSOS4 - "4" -#else - "" -#endif - ); exit (0); -#endif -#endif - -#if defined (__arm) && defined (__acorn) && defined (__unix) - printf ("arm-acorn-riscix\n"); exit (0); -#endif - -#if defined (hp300) && !defined (hpux) - printf ("m68k-hp-bsd\n"); exit (0); -#endif - -#if defined (NeXT) -#if !defined (__ARCHITECTURE__) -#define __ARCHITECTURE__ "m68k" -#endif - int version; - version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; - if (version < 4) - printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); - else - printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); - exit (0); -#endif - -#if defined (MULTIMAX) || defined (n16) -#if defined (UMAXV) - printf ("ns32k-encore-sysv\n"); exit (0); -#else -#if defined (CMU) - printf ("ns32k-encore-mach\n"); exit (0); -#else - printf ("ns32k-encore-bsd\n"); exit (0); -#endif -#endif -#endif - -#if defined (__386BSD__) - printf ("i386-pc-bsd\n"); exit (0); -#endif - -#if defined (sequent) -#if defined (i386) - printf ("i386-sequent-dynix\n"); exit (0); -#endif -#if defined (ns32000) - printf ("ns32k-sequent-dynix\n"); exit (0); -#endif -#endif - -#if defined (_SEQUENT_) - struct utsname un; - - uname(&un); - - if (strncmp(un.version, "V2", 2) == 0) { - printf ("i386-sequent-ptx2\n"); exit (0); - } - if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ - printf ("i386-sequent-ptx1\n"); exit (0); - } - printf ("i386-sequent-ptx\n"); exit (0); - -#endif - -#if defined (vax) -# if !defined (ultrix) -# include <sys/param.h> -# if defined (BSD) -# if BSD == 43 - printf ("vax-dec-bsd4.3\n"); exit (0); -# else -# if BSD == 199006 - printf ("vax-dec-bsd4.3reno\n"); exit (0); -# else - printf ("vax-dec-bsd\n"); exit (0); -# endif -# endif -# else - printf ("vax-dec-bsd\n"); exit (0); -# endif -# else - printf ("vax-dec-ultrix\n"); exit (0); -# endif -#endif - -#if defined (alliant) && defined (i860) - printf ("i860-alliant-bsd\n"); exit (0); -#endif - - exit (1); -} -EOF - -$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` && - { echo "$SYSTEM_NAME"; exit; } - -# Apollos put the system type in the environment. - -test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; } - -# Convex versions that predate uname can use getsysinfo(1) - -if [ -x /usr/convex/getsysinfo ] -then - case `getsysinfo -f cpu_type` in - c1*) - echo c1-convex-bsd - exit ;; - c2*) - if getsysinfo -f scalar_acc - then echo c32-convex-bsd - else echo c2-convex-bsd - fi - exit ;; - c34*) - echo c34-convex-bsd - exit ;; - c38*) - echo c38-convex-bsd - exit ;; - c4*) - echo c4-convex-bsd - exit ;; - esac -fi - -cat >&2 <<EOF -$0: unable to guess system type - -This script, last modified $timestamp, has failed to recognize -the operating system you are using. It is advised that you -download the most up to date version of the config scripts from - - http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.guess -and - http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.sub - -If the version you run ($0) is already up to date, please -send the following data and any information you think might be -pertinent to <config-patches@gnu.org> in order to provide the needed -information to handle your system. - -config.guess timestamp = $timestamp - -uname -m = `(uname -m) 2>/dev/null || echo unknown` -uname -r = `(uname -r) 2>/dev/null || echo unknown` -uname -s = `(uname -s) 2>/dev/null || echo unknown` -uname -v = `(uname -v) 2>/dev/null || echo unknown` - -/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` -/bin/uname -X = `(/bin/uname -X) 2>/dev/null` - -hostinfo = `(hostinfo) 2>/dev/null` -/bin/universe = `(/bin/universe) 2>/dev/null` -/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` -/bin/arch = `(/bin/arch) 2>/dev/null` -/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` -/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` - -UNAME_MACHINE = ${UNAME_MACHINE} -UNAME_RELEASE = ${UNAME_RELEASE} -UNAME_SYSTEM = ${UNAME_SYSTEM} -UNAME_VERSION = ${UNAME_VERSION} -EOF - -exit 1 - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "timestamp='" -# time-stamp-format: "%:y-%02m-%02d" -# time-stamp-end: "'" -# End: diff --git a/ldb/config.mk b/ldb/config.mk deleted file mode 100644 index fe3b71d1d..000000000 --- a/ldb/config.mk +++ /dev/null @@ -1,151 +0,0 @@ -################################################ -# Start MODULE ldb_asq -[MODULE::ldb_asq] -PRIVATE_DEPENDENCIES = LIBTALLOC LIBEVENTS -CFLAGS = -I$(ldbsrcdir)/include -INIT_FUNCTION = LDB_MODULE(asq) -SUBSYSTEM = LIBLDB - -ldb_asq_OBJ_FILES = $(ldbsrcdir)/modules/asq.o -# End MODULE ldb_asq -################################################ - -################################################ -# Start MODULE ldb_server_sort -[MODULE::ldb_server_sort] -PRIVATE_DEPENDENCIES = LIBTALLOC LIBEVENTS -CFLAGS = -I$(ldbsrcdir)/include -INIT_FUNCTION = LDB_MODULE(server_sort) -SUBSYSTEM = LIBLDB - -# End MODULE ldb_sort -################################################ -ldb_server_sort_OBJ_FILES = $(ldbsrcdir)/modules/sort.o - -################################################ -# Start MODULE ldb_paged_results -[MODULE::ldb_paged_results] -INIT_FUNCTION = LDB_MODULE(paged_results) -CFLAGS = -I$(ldbsrcdir)/include -PRIVATE_DEPENDENCIES = LIBTALLOC LIBEVENTS -SUBSYSTEM = LIBLDB -# End MODULE ldb_paged_results -################################################ - -ldb_paged_results_OBJ_FILES = $(ldbsrcdir)/modules/paged_results.o - -################################################ -# Start MODULE ldb_paged_results -[MODULE::ldb_paged_searches] -INIT_FUNCTION = LDB_MODULE(paged_searches) -CFLAGS = -I$(ldbsrcdir)/include -PRIVATE_DEPENDENCIES = LIBTALLOC LIBEVENTS -SUBSYSTEM = LIBLDB -# End MODULE ldb_paged_results -################################################ - -ldb_paged_searches_OBJ_FILES = $(ldbsrcdir)/modules/paged_searches.o - -################################################ -# Start MODULE ldb_operational -[MODULE::ldb_operational] -SUBSYSTEM = LIBLDB -CFLAGS = -I$(ldbsrcdir)/include -PRIVATE_DEPENDENCIES = LIBTALLOC LIBEVENTS -INIT_FUNCTION = LDB_MODULE(operational) -# End MODULE ldb_operational -################################################ - -ldb_operational_OBJ_FILES = $(ldbsrcdir)/modules/operational.o - -################################################ -# Start MODULE ldb_rdn_name -[MODULE::ldb_rdn_name] -SUBSYSTEM = LIBLDB -CFLAGS = -I$(ldbsrcdir)/include -PRIVATE_DEPENDENCIES = LIBTALLOC LIBEVENTS -INIT_FUNCTION = LDB_MODULE(rdn_name) -# End MODULE ldb_rdn_name -################################################ - -ldb_rdn_name_OBJ_FILES = $(ldbsrcdir)/modules/rdn_name.o - -ldb_map_OBJ_FILES = $(addprefix $(ldbsrcdir)/ldb_map/, ldb_map_inbound.o ldb_map_outbound.o ldb_map.o) - -$(ldb_map_OBJ_FILES): CFLAGS+=-I$(ldbsrcdir)/ldb_map - -################################################ -# Start MODULE ldb_skel -[MODULE::ldb_skel] -SUBSYSTEM = LIBLDB -CFLAGS = -I$(ldbsrcdir)/include -PRIVATE_DEPENDENCIES = LIBTALLOC LIBEVENTS -INIT_FUNCTION = LDB_MODULE(skel) -# End MODULE ldb_skel -################################################ - -ldb_skel_OBJ_FILES = $(ldbsrcdir)/modules/skel.o - -################################################ -# Start MODULE ldb_sqlite3 -[MODULE::ldb_sqlite3] -SUBSYSTEM = LIBLDB -CFLAGS = -I$(ldbsrcdir)/include -PRIVATE_DEPENDENCIES = LIBTALLOC SQLITE3 LIBEVENTS -INIT_FUNCTION = LDB_BACKEND(sqlite3) -# End MODULE ldb_sqlite3 -################################################ - -ldb_sqlite3_OBJ_FILES = $(ldbsrcdir)/ldb_sqlite3/ldb_sqlite3.o - -################################################ -# Start MODULE ldb_tdb -[MODULE::ldb_tdb] -SUBSYSTEM = LIBLDB -CFLAGS = -I$(ldbsrcdir)/include -I$(ldbsrcdir)/ldb_tdb -PRIVATE_DEPENDENCIES = \ - LIBTDB LIBTALLOC LIBEVENTS -INIT_FUNCTION = LDB_BACKEND(tdb) -# End MODULE ldb_tdb -################################################ - -ldb_tdb_OBJ_FILES = $(addprefix $(ldbsrcdir)/ldb_tdb/, ldb_tdb.o ldb_search.o ldb_pack.o ldb_index.o ldb_cache.o ldb_tdb_wrap.o) - - -################################################ -# Start SUBSYSTEM ldb -[LIBRARY::LIBLDB] -CFLAGS = -I$(ldbsrcdir)/include -PUBLIC_DEPENDENCIES = \ - LIBTALLOC LIBEVENTS -PRIVATE_DEPENDENCIES = \ - SOCKET_WRAPPER - -PC_FILES += $(ldbsrcdir)/ldb.pc -# -# End SUBSYSTEM ldb -################################################ - -LIBLDB_VERSION = 0.0.1 -LIBLDB_SOVERSION = 0 - -LIBLDB_OBJ_FILES = $(addprefix $(ldbsrcdir)/common/, ldb.o ldb_ldif.o ldb_parse.o ldb_msg.o ldb_utf8.o ldb_debug.o ldb_modules.o ldb_match.o ldb_attributes.o attrib_handlers.o ldb_dn.o ldb_controls.o qsort.o) $(ldb_map_OBJ_FILES) - -$(LIBLDB_OBJ_FILES): CFLAGS+=-I$(ldbsrcdir)/include - -PUBLIC_HEADERS += $(ldbsrcdir)/include/ldb.h $(ldbsrcdir)/include/ldb_errors.h - -MANPAGES += $(ldbsrcdir)/man/ldb.3 - -################################################ -# Start BINARY ldbtest -[BINARY::ldbtest] -PRIVATE_DEPENDENCIES = \ - LIBLDB_CMDLINE -# End BINARY ldbtest -################################################ - -ldbtest_OBJ_FILES = $(ldbsrcdir)/tools/ldbtest.o - -mkinclude tools/config.mk -mkinclude ldb_ildap/config.mk diff --git a/ldb/config.sub b/ldb/config.sub deleted file mode 100755 index 23cd6fd75..000000000 --- a/ldb/config.sub +++ /dev/null @@ -1,1577 +0,0 @@ -#! /bin/sh -# Configuration validation subroutine script. -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, -# 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. - -timestamp='2005-07-08' - -# This file is (in principle) common to ALL GNU software. -# The presence of a machine in this file suggests that SOME GNU software -# can handle that machine. It does not imply ALL GNU software can. -# -# This file is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program 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 General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, see <http://www.gnu.org/licenses/>. -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - - -# Please send patches to <config-patches@gnu.org>. Submit a context -# diff and a properly formatted ChangeLog entry. -# -# Configuration subroutine to validate and canonicalize a configuration type. -# Supply the specified configuration type as an argument. -# If it is invalid, we print an error message on stderr and exit with code 1. -# Otherwise, we print the canonical config type on stdout and succeed. - -# This file is supposed to be the same for all GNU packages -# and recognize all the CPU types, system types and aliases -# that are meaningful with *any* GNU software. -# Each package is responsible for reporting which valid configurations -# it does not support. The user should be able to distinguish -# a failure to support a valid configuration from a meaningless -# configuration. - -# The goal of this file is to map all the various variations of a given -# machine specification into a single specification in the form: -# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM -# or in some cases, the newer four-part form: -# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM -# It is wrong to echo any other type of specification. - -me=`echo "$0" | sed -e 's,.*/,,'` - -usage="\ -Usage: $0 [OPTION] CPU-MFR-OPSYS - $0 [OPTION] ALIAS - -Canonicalize a configuration name. - -Operation modes: - -h, --help print this help, then exit - -t, --time-stamp print date of last modification, then exit - -v, --version print version number, then exit - -Report bugs and patches to <config-patches@gnu.org>." - -version="\ -GNU config.sub ($timestamp) - -Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 -Free Software Foundation, Inc. - -This is free software; see the source for copying conditions. There is NO -warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - -help=" -Try \`$me --help' for more information." - -# Parse command line -while test $# -gt 0 ; do - case $1 in - --time-stamp | --time* | -t ) - echo "$timestamp" ; exit ;; - --version | -v ) - echo "$version" ; exit ;; - --help | --h* | -h ) - echo "$usage"; exit ;; - -- ) # Stop option processing - shift; break ;; - - ) # Use stdin as input. - break ;; - -* ) - echo "$me: invalid option $1$help" - exit 1 ;; - - *local*) - # First pass through any local machine types. - echo $1 - exit ;; - - * ) - break ;; - esac -done - -case $# in - 0) echo "$me: missing argument$help" >&2 - exit 1;; - 1) ;; - *) echo "$me: too many arguments$help" >&2 - exit 1;; -esac - -# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). -# Here we must recognize all the valid KERNEL-OS combinations. -maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` -case $maybe_os in - nto-qnx* | linux-gnu* | linux-dietlibc | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | \ - kfreebsd*-gnu* | knetbsd*-gnu* | netbsd*-gnu* | storm-chaos* | os2-emx* | rtmk-nova*) - os=-$maybe_os - basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` - ;; - *) - basic_machine=`echo $1 | sed 's/-[^-]*$//'` - if [ $basic_machine != $1 ] - then os=`echo $1 | sed 's/.*-/-/'` - else os=; fi - ;; -esac - -### Let's recognize common machines as not being operating systems so -### that things like config.sub decstation-3100 work. We also -### recognize some manufacturers as not being operating systems, so we -### can provide default operating systems below. -case $os in - -sun*os*) - # Prevent following clause from handling this invalid input. - ;; - -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ - -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ - -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ - -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ - -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ - -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ - -apple | -axis | -knuth | -cray) - os= - basic_machine=$1 - ;; - -sim | -cisco | -oki | -wec | -winbond) - os= - basic_machine=$1 - ;; - -scout) - ;; - -wrs) - os=-vxworks - basic_machine=$1 - ;; - -chorusos*) - os=-chorusos - basic_machine=$1 - ;; - -chorusrdb) - os=-chorusrdb - basic_machine=$1 - ;; - -hiux*) - os=-hiuxwe2 - ;; - -sco5) - os=-sco3.2v5 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco4) - os=-sco3.2v4 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco3.2.[4-9]*) - os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco3.2v[4-9]*) - # Don't forget version if it is 3.2v4 or newer. - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -sco*) - os=-sco3.2v2 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -udk*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -isc) - os=-isc2.2 - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -clix*) - basic_machine=clipper-intergraph - ;; - -isc*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` - ;; - -lynx*) - os=-lynxos - ;; - -ptx*) - basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` - ;; - -windowsnt*) - os=`echo $os | sed -e 's/windowsnt/winnt/'` - ;; - -psos*) - os=-psos - ;; - -mint | -mint[0-9]*) - basic_machine=m68k-atari - os=-mint - ;; -esac - -# Decode aliases for certain CPU-COMPANY combinations. -case $basic_machine in - # Recognize the basic CPU types without company name. - # Some are omitted here because they have special meanings below. - 1750a | 580 \ - | a29k \ - | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ - | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ - | am33_2.0 \ - | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \ - | bfin \ - | c4x | clipper \ - | d10v | d30v | dlx | dsp16xx \ - | fr30 | frv \ - | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ - | i370 | i860 | i960 | ia64 \ - | ip2k | iq2000 \ - | m32r | m32rle | m68000 | m68k | m88k | maxq | mcore \ - | mips | mipsbe | mipseb | mipsel | mipsle \ - | mips16 \ - | mips64 | mips64el \ - | mips64vr | mips64vrel \ - | mips64orion | mips64orionel \ - | mips64vr4100 | mips64vr4100el \ - | mips64vr4300 | mips64vr4300el \ - | mips64vr5000 | mips64vr5000el \ - | mips64vr5900 | mips64vr5900el \ - | mipsisa32 | mipsisa32el \ - | mipsisa32r2 | mipsisa32r2el \ - | mipsisa64 | mipsisa64el \ - | mipsisa64r2 | mipsisa64r2el \ - | mipsisa64sb1 | mipsisa64sb1el \ - | mipsisa64sr71k | mipsisa64sr71kel \ - | mipstx39 | mipstx39el \ - | mn10200 | mn10300 \ - | ms1 \ - | msp430 \ - | ns16k | ns32k \ - | or32 \ - | pdp10 | pdp11 | pj | pjl \ - | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ - | pyramid \ - | sh | sh[1234] | sh[24]a | sh[23]e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \ - | sh64 | sh64le \ - | sparc | sparc64 | sparc64b | sparc86x | sparclet | sparclite \ - | sparcv8 | sparcv9 | sparcv9b \ - | strongarm \ - | tahoe | thumb | tic4x | tic80 | tron \ - | v850 | v850e \ - | we32k \ - | x86 | xscale | xscalee[bl] | xstormy16 | xtensa \ - | z8k) - basic_machine=$basic_machine-unknown - ;; - m32c) - basic_machine=$basic_machine-unknown - ;; - m6811 | m68hc11 | m6812 | m68hc12) - # Motorola 68HC11/12. - basic_machine=$basic_machine-unknown - os=-none - ;; - m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) - ;; - - # We use `pc' rather than `unknown' - # because (1) that's what they normally are, and - # (2) the word "unknown" tends to confuse beginning users. - i*86 | x86_64) - basic_machine=$basic_machine-pc - ;; - # Object if more than one company name word. - *-*-*) - echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 - exit 1 - ;; - # Recognize the basic CPU types with company name. - 580-* \ - | a29k-* \ - | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ - | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ - | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ - | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ - | avr-* \ - | bfin-* | bs2000-* \ - | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* | c55x-* | c6x-* \ - | clipper-* | craynv-* | cydra-* \ - | d10v-* | d30v-* | dlx-* \ - | elxsi-* \ - | f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \ - | h8300-* | h8500-* \ - | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ - | i*86-* | i860-* | i960-* | ia64-* \ - | ip2k-* | iq2000-* \ - | m32r-* | m32rle-* \ - | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ - | m88110-* | m88k-* | maxq-* | mcore-* \ - | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ - | mips16-* \ - | mips64-* | mips64el-* \ - | mips64vr-* | mips64vrel-* \ - | mips64orion-* | mips64orionel-* \ - | mips64vr4100-* | mips64vr4100el-* \ - | mips64vr4300-* | mips64vr4300el-* \ - | mips64vr5000-* | mips64vr5000el-* \ - | mips64vr5900-* | mips64vr5900el-* \ - | mipsisa32-* | mipsisa32el-* \ - | mipsisa32r2-* | mipsisa32r2el-* \ - | mipsisa64-* | mipsisa64el-* \ - | mipsisa64r2-* | mipsisa64r2el-* \ - | mipsisa64sb1-* | mipsisa64sb1el-* \ - | mipsisa64sr71k-* | mipsisa64sr71kel-* \ - | mipstx39-* | mipstx39el-* \ - | mmix-* \ - | ms1-* \ - | msp430-* \ - | none-* | np1-* | ns16k-* | ns32k-* \ - | orion-* \ - | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ - | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ - | pyramid-* \ - | romp-* | rs6000-* \ - | sh-* | sh[1234]-* | sh[24]a-* | sh[23]e-* | sh[34]eb-* | shbe-* \ - | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ - | sparc-* | sparc64-* | sparc64b-* | sparc86x-* | sparclet-* \ - | sparclite-* \ - | sparcv8-* | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \ - | tahoe-* | thumb-* \ - | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ - | tron-* \ - | v850-* | v850e-* | vax-* \ - | we32k-* \ - | x86-* | x86_64-* | xps100-* | xscale-* | xscalee[bl]-* \ - | xstormy16-* | xtensa-* \ - | ymp-* \ - | z8k-*) - ;; - m32c-*) - ;; - # Recognize the various machine names and aliases which stand - # for a CPU type and a company and sometimes even an OS. - 386bsd) - basic_machine=i386-unknown - os=-bsd - ;; - 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) - basic_machine=m68000-att - ;; - 3b*) - basic_machine=we32k-att - ;; - a29khif) - basic_machine=a29k-amd - os=-udi - ;; - abacus) - basic_machine=abacus-unknown - ;; - adobe68k) - basic_machine=m68010-adobe - os=-scout - ;; - alliant | fx80) - basic_machine=fx80-alliant - ;; - altos | altos3068) - basic_machine=m68k-altos - ;; - am29k) - basic_machine=a29k-none - os=-bsd - ;; - amd64) - basic_machine=x86_64-pc - ;; - amd64-*) - basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - amdahl) - basic_machine=580-amdahl - os=-sysv - ;; - amiga | amiga-*) - basic_machine=m68k-unknown - ;; - amigaos | amigados) - basic_machine=m68k-unknown - os=-amigaos - ;; - amigaunix | amix) - basic_machine=m68k-unknown - os=-sysv4 - ;; - apollo68) - basic_machine=m68k-apollo - os=-sysv - ;; - apollo68bsd) - basic_machine=m68k-apollo - os=-bsd - ;; - aux) - basic_machine=m68k-apple - os=-aux - ;; - balance) - basic_machine=ns32k-sequent - os=-dynix - ;; - c90) - basic_machine=c90-cray - os=-unicos - ;; - convex-c1) - basic_machine=c1-convex - os=-bsd - ;; - convex-c2) - basic_machine=c2-convex - os=-bsd - ;; - convex-c32) - basic_machine=c32-convex - os=-bsd - ;; - convex-c34) - basic_machine=c34-convex - os=-bsd - ;; - convex-c38) - basic_machine=c38-convex - os=-bsd - ;; - cray | j90) - basic_machine=j90-cray - os=-unicos - ;; - craynv) - basic_machine=craynv-cray - os=-unicosmp - ;; - cr16c) - basic_machine=cr16c-unknown - os=-elf - ;; - crds | unos) - basic_machine=m68k-crds - ;; - crisv32 | crisv32-* | etraxfs*) - basic_machine=crisv32-axis - ;; - cris | cris-* | etrax*) - basic_machine=cris-axis - ;; - crx) - basic_machine=crx-unknown - os=-elf - ;; - da30 | da30-*) - basic_machine=m68k-da30 - ;; - decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) - basic_machine=mips-dec - ;; - decsystem10* | dec10*) - basic_machine=pdp10-dec - os=-tops10 - ;; - decsystem20* | dec20*) - basic_machine=pdp10-dec - os=-tops20 - ;; - delta | 3300 | motorola-3300 | motorola-delta \ - | 3300-motorola | delta-motorola) - basic_machine=m68k-motorola - ;; - delta88) - basic_machine=m88k-motorola - os=-sysv3 - ;; - djgpp) - basic_machine=i586-pc - os=-msdosdjgpp - ;; - dpx20 | dpx20-*) - basic_machine=rs6000-bull - os=-bosx - ;; - dpx2* | dpx2*-bull) - basic_machine=m68k-bull - os=-sysv3 - ;; - ebmon29k) - basic_machine=a29k-amd - os=-ebmon - ;; - elxsi) - basic_machine=elxsi-elxsi - os=-bsd - ;; - encore | umax | mmax) - basic_machine=ns32k-encore - ;; - es1800 | OSE68k | ose68k | ose | OSE) - basic_machine=m68k-ericsson - os=-ose - ;; - fx2800) - basic_machine=i860-alliant - ;; - genix) - basic_machine=ns32k-ns - ;; - gmicro) - basic_machine=tron-gmicro - os=-sysv - ;; - go32) - basic_machine=i386-pc - os=-go32 - ;; - h3050r* | hiux*) - basic_machine=hppa1.1-hitachi - os=-hiuxwe2 - ;; - h8300hms) - basic_machine=h8300-hitachi - os=-hms - ;; - h8300xray) - basic_machine=h8300-hitachi - os=-xray - ;; - h8500hms) - basic_machine=h8500-hitachi - os=-hms - ;; - harris) - basic_machine=m88k-harris - os=-sysv3 - ;; - hp300-*) - basic_machine=m68k-hp - ;; - hp300bsd) - basic_machine=m68k-hp - os=-bsd - ;; - hp300hpux) - basic_machine=m68k-hp - os=-hpux - ;; - hp3k9[0-9][0-9] | hp9[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hp9k2[0-9][0-9] | hp9k31[0-9]) - basic_machine=m68000-hp - ;; - hp9k3[2-9][0-9]) - basic_machine=m68k-hp - ;; - hp9k6[0-9][0-9] | hp6[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hp9k7[0-79][0-9] | hp7[0-79][0-9]) - basic_machine=hppa1.1-hp - ;; - hp9k78[0-9] | hp78[0-9]) - # FIXME: really hppa2.0-hp - basic_machine=hppa1.1-hp - ;; - hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) - # FIXME: really hppa2.0-hp - basic_machine=hppa1.1-hp - ;; - hp9k8[0-9][13679] | hp8[0-9][13679]) - basic_machine=hppa1.1-hp - ;; - hp9k8[0-9][0-9] | hp8[0-9][0-9]) - basic_machine=hppa1.0-hp - ;; - hppa-next) - os=-nextstep3 - ;; - hppaosf) - basic_machine=hppa1.1-hp - os=-osf - ;; - hppro) - basic_machine=hppa1.1-hp - os=-proelf - ;; - i370-ibm* | ibm*) - basic_machine=i370-ibm - ;; -# I'm not sure what "Sysv32" means. Should this be sysv3.2? - i*86v32) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv32 - ;; - i*86v4*) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv4 - ;; - i*86v) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-sysv - ;; - i*86sol2) - basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` - os=-solaris2 - ;; - i386mach) - basic_machine=i386-mach - os=-mach - ;; - i386-vsta | vsta) - basic_machine=i386-unknown - os=-vsta - ;; - iris | iris4d) - basic_machine=mips-sgi - case $os in - -irix*) - ;; - *) - os=-irix4 - ;; - esac - ;; - isi68 | isi) - basic_machine=m68k-isi - os=-sysv - ;; - m88k-omron*) - basic_machine=m88k-omron - ;; - magnum | m3230) - basic_machine=mips-mips - os=-sysv - ;; - merlin) - basic_machine=ns32k-utek - os=-sysv - ;; - mingw32) - basic_machine=i386-pc - os=-mingw32 - ;; - miniframe) - basic_machine=m68000-convergent - ;; - *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) - basic_machine=m68k-atari - os=-mint - ;; - mips3*-*) - basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` - ;; - mips3*) - basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown - ;; - monitor) - basic_machine=m68k-rom68k - os=-coff - ;; - morphos) - basic_machine=powerpc-unknown - os=-morphos - ;; - msdos) - basic_machine=i386-pc - os=-msdos - ;; - mvs) - basic_machine=i370-ibm - os=-mvs - ;; - ncr3000) - basic_machine=i486-ncr - os=-sysv4 - ;; - netbsd386) - basic_machine=i386-unknown - os=-netbsd - ;; - netwinder) - basic_machine=armv4l-rebel - os=-linux - ;; - news | news700 | news800 | news900) - basic_machine=m68k-sony - os=-newsos - ;; - news1000) - basic_machine=m68030-sony - os=-newsos - ;; - news-3600 | risc-news) - basic_machine=mips-sony - os=-newsos - ;; - necv70) - basic_machine=v70-nec - os=-sysv - ;; - next | m*-next ) - basic_machine=m68k-next - case $os in - -nextstep* ) - ;; - -ns2*) - os=-nextstep2 - ;; - *) - os=-nextstep3 - ;; - esac - ;; - nh3000) - basic_machine=m68k-harris - os=-cxux - ;; - nh[45]000) - basic_machine=m88k-harris - os=-cxux - ;; - nindy960) - basic_machine=i960-intel - os=-nindy - ;; - mon960) - basic_machine=i960-intel - os=-mon960 - ;; - nonstopux) - basic_machine=mips-compaq - os=-nonstopux - ;; - np1) - basic_machine=np1-gould - ;; - nsr-tandem) - basic_machine=nsr-tandem - ;; - op50n-* | op60c-*) - basic_machine=hppa1.1-oki - os=-proelf - ;; - openrisc | openrisc-*) - basic_machine=or32-unknown - ;; - os400) - basic_machine=powerpc-ibm - os=-os400 - ;; - OSE68000 | ose68000) - basic_machine=m68000-ericsson - os=-ose - ;; - os68k) - basic_machine=m68k-none - os=-os68k - ;; - pa-hitachi) - basic_machine=hppa1.1-hitachi - os=-hiuxwe2 - ;; - paragon) - basic_machine=i860-intel - os=-osf - ;; - pbd) - basic_machine=sparc-tti - ;; - pbb) - basic_machine=m68k-tti - ;; - pc532 | pc532-*) - basic_machine=ns32k-pc532 - ;; - pentium | p5 | k5 | k6 | nexgen | viac3) - basic_machine=i586-pc - ;; - pentiumpro | p6 | 6x86 | athlon | athlon_*) - basic_machine=i686-pc - ;; - pentiumii | pentium2 | pentiumiii | pentium3) - basic_machine=i686-pc - ;; - pentium4) - basic_machine=i786-pc - ;; - pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) - basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentiumpro-* | p6-* | 6x86-* | athlon-*) - basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*) - basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pentium4-*) - basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - pn) - basic_machine=pn-gould - ;; - power) basic_machine=power-ibm - ;; - ppc) basic_machine=powerpc-unknown - ;; - ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppcle | powerpclittle | ppc-le | powerpc-little) - basic_machine=powerpcle-unknown - ;; - ppcle-* | powerpclittle-*) - basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppc64) basic_machine=powerpc64-unknown - ;; - ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ppc64le | powerpc64little | ppc64-le | powerpc64-little) - basic_machine=powerpc64le-unknown - ;; - ppc64le-* | powerpc64little-*) - basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` - ;; - ps2) - basic_machine=i386-ibm - ;; - pw32) - basic_machine=i586-unknown - os=-pw32 - ;; - rom68k) - basic_machine=m68k-rom68k - os=-coff - ;; - rm[46]00) - basic_machine=mips-siemens - ;; - rtpc | rtpc-*) - basic_machine=romp-ibm - ;; - s390 | s390-*) - basic_machine=s390-ibm - ;; - s390x | s390x-*) - basic_machine=s390x-ibm - ;; - sa29200) - basic_machine=a29k-amd - os=-udi - ;; - sb1) - basic_machine=mipsisa64sb1-unknown - ;; - sb1el) - basic_machine=mipsisa64sb1el-unknown - ;; - sei) - basic_machine=mips-sei - os=-seiux - ;; - sequent) - basic_machine=i386-sequent - ;; - sh) - basic_machine=sh-hitachi - os=-hms - ;; - sh64) - basic_machine=sh64-unknown - ;; - sparclite-wrs | simso-wrs) - basic_machine=sparclite-wrs - os=-vxworks - ;; - sps7) - basic_machine=m68k-bull - os=-sysv2 - ;; - spur) - basic_machine=spur-unknown - ;; - st2000) - basic_machine=m68k-tandem - ;; - stratus) - basic_machine=i860-stratus - os=-sysv4 - ;; - sun2) - basic_machine=m68000-sun - ;; - sun2os3) - basic_machine=m68000-sun - os=-sunos3 - ;; - sun2os4) - basic_machine=m68000-sun - os=-sunos4 - ;; - sun3os3) - basic_machine=m68k-sun - os=-sunos3 - ;; - sun3os4) - basic_machine=m68k-sun - os=-sunos4 - ;; - sun4os3) - basic_machine=sparc-sun - os=-sunos3 - ;; - sun4os4) - basic_machine=sparc-sun - os=-sunos4 - ;; - sun4sol2) - basic_machine=sparc-sun - os=-solaris2 - ;; - sun3 | sun3-*) - basic_machine=m68k-sun - ;; - sun4) - basic_machine=sparc-sun - ;; - sun386 | sun386i | roadrunner) - basic_machine=i386-sun - ;; - sv1) - basic_machine=sv1-cray - os=-unicos - ;; - symmetry) - basic_machine=i386-sequent - os=-dynix - ;; - t3e) - basic_machine=alphaev5-cray - os=-unicos - ;; - t90) - basic_machine=t90-cray - os=-unicos - ;; - tic54x | c54x*) - basic_machine=tic54x-unknown - os=-coff - ;; - tic55x | c55x*) - basic_machine=tic55x-unknown - os=-coff - ;; - tic6x | c6x*) - basic_machine=tic6x-unknown - os=-coff - ;; - tx39) - basic_machine=mipstx39-unknown - ;; - tx39el) - basic_machine=mipstx39el-unknown - ;; - toad1) - basic_machine=pdp10-xkl - os=-tops20 - ;; - tower | tower-32) - basic_machine=m68k-ncr - ;; - tpf) - basic_machine=s390x-ibm - os=-tpf - ;; - udi29k) - basic_machine=a29k-amd - os=-udi - ;; - ultra3) - basic_machine=a29k-nyu - os=-sym1 - ;; - v810 | necv810) - basic_machine=v810-nec - os=-none - ;; - vaxv) - basic_machine=vax-dec - os=-sysv - ;; - vms) - basic_machine=vax-dec - os=-vms - ;; - vpp*|vx|vx-*) - basic_machine=f301-fujitsu - ;; - vxworks960) - basic_machine=i960-wrs - os=-vxworks - ;; - vxworks68) - basic_machine=m68k-wrs - os=-vxworks - ;; - vxworks29k) - basic_machine=a29k-wrs - os=-vxworks - ;; - w65*) - basic_machine=w65-wdc - os=-none - ;; - w89k-*) - basic_machine=hppa1.1-winbond - os=-proelf - ;; - xbox) - basic_machine=i686-pc - os=-mingw32 - ;; - xps | xps100) - basic_machine=xps100-honeywell - ;; - ymp) - basic_machine=ymp-cray - os=-unicos - ;; - z8k-*-coff) - basic_machine=z8k-unknown - os=-sim - ;; - none) - basic_machine=none-none - os=-none - ;; - -# Here we handle the default manufacturer of certain CPU types. It is in -# some cases the only manufacturer, in others, it is the most popular. - w89k) - basic_machine=hppa1.1-winbond - ;; - op50n) - basic_machine=hppa1.1-oki - ;; - op60c) - basic_machine=hppa1.1-oki - ;; - romp) - basic_machine=romp-ibm - ;; - mmix) - basic_machine=mmix-knuth - ;; - rs6000) - basic_machine=rs6000-ibm - ;; - vax) - basic_machine=vax-dec - ;; - pdp10) - # there are many clones, so DEC is not a safe bet - basic_machine=pdp10-unknown - ;; - pdp11) - basic_machine=pdp11-dec - ;; - we32k) - basic_machine=we32k-att - ;; - sh[1234] | sh[24]a | sh[34]eb | sh[1234]le | sh[23]ele) - basic_machine=sh-unknown - ;; - sparc | sparcv8 | sparcv9 | sparcv9b) - basic_machine=sparc-sun - ;; - cydra) - basic_machine=cydra-cydrome - ;; - orion) - basic_machine=orion-highlevel - ;; - orion105) - basic_machine=clipper-highlevel - ;; - mac | mpw | mac-mpw) - basic_machine=m68k-apple - ;; - pmac | pmac-mpw) - basic_machine=powerpc-apple - ;; - *-unknown) - # Make sure to match an already-canonicalized machine name. - ;; - *) - echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 - exit 1 - ;; -esac - -# Here we canonicalize certain aliases for manufacturers. -case $basic_machine in - *-digital*) - basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` - ;; - *-commodore*) - basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` - ;; - *) - ;; -esac - -# Decode manufacturer-specific aliases for certain operating systems. - -if [ x"$os" != x"" ] -then -case $os in - # First match some system type aliases - # that might get confused with valid system types. - # -solaris* is a basic system type, with this one exception. - -solaris1 | -solaris1.*) - os=`echo $os | sed -e 's|solaris1|sunos4|'` - ;; - -solaris) - os=-solaris2 - ;; - -svr4*) - os=-sysv4 - ;; - -unixware*) - os=-sysv4.2uw - ;; - -gnu/linux*) - os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` - ;; - # First accept the basic system types. - # The portable systems comes first. - # Each alternative MUST END IN A *, to match a version number. - # -sysv* is not here because it comes later, after sysvr4. - -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ - | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ - | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ - | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ - | -aos* \ - | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ - | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ - | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* | -openbsd* \ - | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ - | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ - | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ - | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ - | -chorusos* | -chorusrdb* \ - | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ - | -mingw32* | -linux-gnu* | -linux-uclibc* | -uxpv* | -beos* | -mpeix* | -udk* \ - | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ - | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ - | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ - | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ - | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ - | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ - | -skyos* | -haiku*) - # Remember, each alternative MUST END IN *, to match a version number. - ;; - -qnx*) - case $basic_machine in - x86-* | i*86-*) - ;; - *) - os=-nto$os - ;; - esac - ;; - -nto-qnx*) - ;; - -nto*) - os=`echo $os | sed -e 's|nto|nto-qnx|'` - ;; - -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ - | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \ - | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) - ;; - -mac*) - os=`echo $os | sed -e 's|mac|macos|'` - ;; - -linux-dietlibc) - os=-linux-dietlibc - ;; - -linux*) - os=`echo $os | sed -e 's|linux|linux-gnu|'` - ;; - -sunos5*) - os=`echo $os | sed -e 's|sunos5|solaris2|'` - ;; - -sunos6*) - os=`echo $os | sed -e 's|sunos6|solaris3|'` - ;; - -opened*) - os=-openedition - ;; - -os400*) - os=-os400 - ;; - -wince*) - os=-wince - ;; - -osfrose*) - os=-osfrose - ;; - -osf*) - os=-osf - ;; - -utek*) - os=-bsd - ;; - -dynix*) - os=-bsd - ;; - -acis*) - os=-aos - ;; - -atheos*) - os=-atheos - ;; - -syllable*) - os=-syllable - ;; - -386bsd) - os=-bsd - ;; - -ctix* | -uts*) - os=-sysv - ;; - -nova*) - os=-rtmk-nova - ;; - -ns2 ) - os=-nextstep2 - ;; - -nsk*) - os=-nsk - ;; - # Preserve the version number of sinix5. - -sinix5.*) - os=`echo $os | sed -e 's|sinix|sysv|'` - ;; - -sinix*) - os=-sysv4 - ;; - -tpf*) - os=-tpf - ;; - -triton*) - os=-sysv3 - ;; - -oss*) - os=-sysv3 - ;; - -svr4) - os=-sysv4 - ;; - -svr3) - os=-sysv3 - ;; - -sysvr4) - os=-sysv4 - ;; - # This must come after -sysvr4. - -sysv*) - ;; - -ose*) - os=-ose - ;; - -es1800*) - os=-ose - ;; - -xenix) - os=-xenix - ;; - -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) - os=-mint - ;; - -aros*) - os=-aros - ;; - -kaos*) - os=-kaos - ;; - -zvmoe) - os=-zvmoe - ;; - -none) - ;; - *) - # Get rid of the `-' at the beginning of $os. - os=`echo $os | sed 's/[^-]*-//'` - echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 - exit 1 - ;; -esac -else - -# Here we handle the default operating systems that come with various machines. -# The value should be what the vendor currently ships out the door with their -# machine or put another way, the most popular os provided with the machine. - -# Note that if you're going to try to match "-MANUFACTURER" here (say, -# "-sun"), then you have to tell the case statement up towards the top -# that MANUFACTURER isn't an operating system. Otherwise, code above -# will signal an error saying that MANUFACTURER isn't an operating -# system, and we'll never get to this point. - -case $basic_machine in - *-acorn) - os=-riscix1.2 - ;; - arm*-rebel) - os=-linux - ;; - arm*-semi) - os=-aout - ;; - c4x-* | tic4x-*) - os=-coff - ;; - # This must come before the *-dec entry. - pdp10-*) - os=-tops20 - ;; - pdp11-*) - os=-none - ;; - *-dec | vax-*) - os=-ultrix4.2 - ;; - m68*-apollo) - os=-domain - ;; - i386-sun) - os=-sunos4.0.2 - ;; - m68000-sun) - os=-sunos3 - # This also exists in the configure program, but was not the - # default. - # os=-sunos4 - ;; - m68*-cisco) - os=-aout - ;; - mips*-cisco) - os=-elf - ;; - mips*-*) - os=-elf - ;; - or32-*) - os=-coff - ;; - *-tti) # must be before sparc entry or we get the wrong os. - os=-sysv3 - ;; - sparc-* | *-sun) - os=-sunos4.1.1 - ;; - *-be) - os=-beos - ;; - *-haiku) - os=-haiku - ;; - *-ibm) - os=-aix - ;; - *-knuth) - os=-mmixware - ;; - *-wec) - os=-proelf - ;; - *-winbond) - os=-proelf - ;; - *-oki) - os=-proelf - ;; - *-hp) - os=-hpux - ;; - *-hitachi) - os=-hiux - ;; - i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) - os=-sysv - ;; - *-cbm) - os=-amigaos - ;; - *-dg) - os=-dgux - ;; - *-dolphin) - os=-sysv3 - ;; - m68k-ccur) - os=-rtu - ;; - m88k-omron*) - os=-luna - ;; - *-next ) - os=-nextstep - ;; - *-sequent) - os=-ptx - ;; - *-crds) - os=-unos - ;; - *-ns) - os=-genix - ;; - i370-*) - os=-mvs - ;; - *-next) - os=-nextstep3 - ;; - *-gould) - os=-sysv - ;; - *-highlevel) - os=-bsd - ;; - *-encore) - os=-bsd - ;; - *-sgi) - os=-irix - ;; - *-siemens) - os=-sysv4 - ;; - *-masscomp) - os=-rtu - ;; - f30[01]-fujitsu | f700-fujitsu) - os=-uxpv - ;; - *-rom68k) - os=-coff - ;; - *-*bug) - os=-coff - ;; - *-apple) - os=-macos - ;; - *-atari*) - os=-mint - ;; - *) - os=-none - ;; -esac -fi - -# Here we handle the case where we know the os, and the CPU type, but not the -# manufacturer. We pick the logical manufacturer. -vendor=unknown -case $basic_machine in - *-unknown) - case $os in - -riscix*) - vendor=acorn - ;; - -sunos*) - vendor=sun - ;; - -aix*) - vendor=ibm - ;; - -beos*) - vendor=be - ;; - -hpux*) - vendor=hp - ;; - -mpeix*) - vendor=hp - ;; - -hiux*) - vendor=hitachi - ;; - -unos*) - vendor=crds - ;; - -dgux*) - vendor=dg - ;; - -luna*) - vendor=omron - ;; - -genix*) - vendor=ns - ;; - -mvs* | -opened*) - vendor=ibm - ;; - -os400*) - vendor=ibm - ;; - -ptx*) - vendor=sequent - ;; - -tpf*) - vendor=ibm - ;; - -vxsim* | -vxworks* | -windiss*) - vendor=wrs - ;; - -aux*) - vendor=apple - ;; - -hms*) - vendor=hitachi - ;; - -mpw* | -macos*) - vendor=apple - ;; - -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) - vendor=atari - ;; - -vos*) - vendor=stratus - ;; - esac - basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` - ;; -esac - -echo $basic_machine$os -exit - -# Local variables: -# eval: (add-hook 'write-file-hooks 'time-stamp) -# time-stamp-start: "timestamp='" -# time-stamp-format: "%:y-%02m-%02d" -# time-stamp-end: "'" -# End: diff --git a/ldb/configure.ac b/ldb/configure.ac deleted file mode 100644 index 7bc081cfe..000000000 --- a/ldb/configure.ac +++ /dev/null @@ -1,102 +0,0 @@ -AC_PREREQ(2.50) -AC_DEFUN([AC_CHECK_LIB_EXT], [ - AC_CHECK_LIB([$1],[$3],[$4],[$5],[$7]) - ac_cv_lib_ext_$1_$3=$ac_cv_lib_$1_$3 -]) -AC_DEFUN([AC_CHECK_FUNC_EXT], [ - AC_CHECK_FUNC([$1],[$3],[$4]) - ac_cv_func_ext_$1=$ac_cv_func_$1 -]) -AC_DEFUN([SMB_MODULE_DEFAULT], [echo -n ""]) -AC_DEFUN([SMB_LIBRARY_ENABLE], [echo -n ""]) -AC_DEFUN([SMB_EXT_LIB], [echo -n ""]) -AC_DEFUN([SMB_ENABLE], [echo -n ""]) -AC_INIT(ldb, 0.9.2) -AC_CONFIG_SRCDIR([common/ldb.c]) - -AC_LIBREPLACE_ALL_CHECKS - -if test "$ac_cv_prog_gcc" = yes; then - CFLAGS="$CFLAGS -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings" -fi - -WITH_GCOV=0 -AC_ARG_ENABLE(gcov, - AS_HELP_STRING([--enable-gcov],[enable GCOV code coverage tests]), - [ WITH_GCOV=1]) -AC_SUBST(WITH_GCOV) -if test x"$with_gcov_support" = x"yes"; then - CFLAGS="$CFLAGS -ftest-coverage -fprofile-arcs" - LIBS="$LIBS -lgcov" -fi - -AC_PATH_PROG(XSLTPROC,xsltproc) -AC_PATH_PROG(DOXYGEN,doxygen) -AC_PATH_PROG(GCOV,gcov) -AC_PATH_PROG(SLAPD,slapd) -AC_CHECK_HEADERS(stdint.h dlfcn.h) -AC_CONFIG_HEADER(include/config.h) - -LDB_MODULESDIR="${libdir}/ldb" -AC_SUBST(LDB_MODULESDIR) - -TESTS="" -EXTRA_OBJ="" - -m4_include(build_macros.m4) -BUILD_WITH_SHARED_BUILD_DIR - -m4_include(pkg.m4) -m4_include(libpopt.m4) -m4_include(libtalloc.m4) -m4_include(libtdb.m4) -m4_include(libevents.m4) - -m4_include(ldap.m4) -if test x"$with_ldap_support" = x"yes"; then - CFLAGS="$CFLAGS -DHAVE_LDB_LDAP=1" - EXTRA_OBJ="$EXTRA_OBJ ldb_ldap/ldb_ldap.o" - LDAP_LIBS="-llber -lldap" - AC_SUBST(LDAP_LIBS) - TESTS="$TESTS test-ldap.sh" -fi - -m4_include(sqlite3.m4) -if test x"$with_sqlite3_support" = x"yes"; then - LIBS="$LIBS -lsqlite3" - CFLAGS="$CFLAGS -DHAVE_LDB_SQLITE3=1" - EXTRA_OBJ="$EXTRA_OBJ ldb_sqlite3/ldb_sqlite3.o" - TESTS="$TESTS test-sqlite3.sh" -fi - -AC_SUBST(TESTS) -AC_SUBST(EXTRA_OBJ) - -AC_LD_EXPORT_DYNAMIC -AC_LD_PICFLAG -AC_LD_SHLIBEXT -AC_LD_SONAMEFLAG -AC_LIBREPLACE_SHLD -AC_LIBREPLACE_SHLD_FLAGS -AC_LIBREPLACE_MDLD -AC_LIBREPLACE_MDLD_FLAGS -AC_LIBREPLACE_RUNTIME_LIB_PATH_VAR - -AC_PATH_PROGS([PYTHON_CONFIG], [python2.6-config python2.5-config python2.4-config python-config]) -AC_PATH_PROGS([PYTHON], [python2.6 python2.5 python2.4 python]) - -PYTHON_BUILD_TARGET="build-python" -PYTHON_INSTALL_TARGET="install-python" -PYTHON_CHECK_TARGET="check-python" -AC_SUBST(PYTHON_BUILD_TARGET) -AC_SUBST(PYTHON_INSTALL_TARGET) -AC_SUBST(PYTHON_CHECK_TARGET) - -if test -z "$PYTHON_CONFIG"; then - PYTHON_BUILD_TARGET="" - PYTHON_CHECK_TARGET="" - PYTHON_INSTALL_TARGET="" -fi - -m4_include(libldb.m4) -AC_OUTPUT(Makefile ldb.pc) diff --git a/ldb/docs/builddocs.sh b/ldb/docs/builddocs.sh deleted file mode 100755 index 449dcb268..000000000 --- a/ldb/docs/builddocs.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/sh -# build ldb docs -# tridge@samba.org August 2006 - -XSLTPROC="$1" -SRCDIR="$2" - -if [ -z "$XSLTPROC" ] || [ ! -x "$XSLTPROC" ]; then - echo "xsltproc not installed" - exit 0 -fi - -MANXSL="http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl" -HTMLXSL="http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl" - -mkdir -p man - -for f in $SRCDIR/man/*.xml; do - base=`basename $f .xml` - out=man/"`basename $base`" - if [ ! -f "$out" ] || [ "$f" -nt "$out" ]; then - echo Processing manpage $f - $XSLTPROC --nonet -o "$out" "$MANXSL" $f - ret=$? - if [ "$ret" = "4" ]; then - echo "ignoring stylesheet error 4 for $MANXSL" - exit 0 - fi - if [ "$ret" != "0" ]; then - echo "xsltproc failed with error $ret" - exit $ret - fi - fi -done - -for f in $SRCDIR/man/*.xml; do - base=`basename $f .xml` - out=man/"`basename $base`".html - if [ ! -f "$out" ] || [ "$f" -nt "$out" ]; then - echo Processing html $f - $XSLTPROC --nonet -o "$out" "$HTMLXSL" $f - ret=$? - if [ "$ret" = "4" ]; then - echo "ignoring stylesheet error 4 for $HTMLXSL" - exit 0 - fi - if [ "$ret" != "0" ]; then - echo "xsltproc failed with error $ret" - exit $ret - fi - fi -done diff --git a/ldb/docs/design.txt b/ldb/docs/design.txt deleted file mode 100644 index 0bb278b5b..000000000 --- a/ldb/docs/design.txt +++ /dev/null @@ -1,41 +0,0 @@ -The list of indexed fields --------------------------- - -dn=@INDEXLIST - list of field names that are indexed - - contains fields of type @IDXATTR which contain attriute names - of indexed fields - - -Data records ------------- - -for each user record in the db there is: - main record - key: DN=dn - data: packed attribute/value list - - a index record for each indexed field in the record - - -Index Records -------------- - -The index records contain the list of dn's that contain records -matching the index key - -All index records are of the form: - dn=@INDEX:field:value - -and contain fields of type @IDX which are the dns of the records -that have that value for some attribute - - -Search Expressions ------------------- - -Very similar to LDAP search expressions, but does not allow ~=, <= or >= - - attrib0 := (field=value) - attrib := attrib0 | (attrib&&attrib) | (attrib||attrib) | !attrib diff --git a/ldb/docs/installdocs.sh b/ldb/docs/installdocs.sh deleted file mode 100755 index 6cc7b74ad..000000000 --- a/ldb/docs/installdocs.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh -# install ldb docs -# tridge@samba.org August 2006 - -MANDIR="$1" - -MAN1="`/bin/ls man/*.1`" -MAN3="`/bin/ls man/*.3`" - -if [ -z "$MAN1" ] && [ -z "$MAN3" ]; then - echo "No manpages have been built" - exit 0 -fi - -mkdir -p "$MANDIR/man1" "$MANDIR/man3" -cp $MAN1 "$MANDIR/man1/" || exit 1 -cp $MAN3 "$MANDIR/man3/" || exit 1 diff --git a/ldb/examples.dox b/ldb/examples.dox deleted file mode 100644 index ef4b4f0a4..000000000 --- a/ldb/examples.dox +++ /dev/null @@ -1,16 +0,0 @@ -/** \example ldbreader.c - -The code below shows a simple LDB application. - -It lists / dumps the records in a LDB database to standard output. - -*/ - - -/** \example ldifreader.c - -The code below shows a simple LDB application. - -It lists / dumps the entries in an LDIF file to standard output. - -*/ diff --git a/ldb/examples/ldbreader.c b/ldb/examples/ldbreader.c deleted file mode 100644 index e48b3d338..000000000 --- a/ldb/examples/ldbreader.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - example code for the ldb database library - - Copyright (C) Brad Hards (bradh@frogmouth.net) 2005-2006 - - ** 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -/** \example ldbreader.c - -The code below shows a simple LDB application. - -It lists / dumps the records in a LDB database to standard output. - -*/ - -#include "ldb_includes.h" -#include "ldb.h" -#include "ldb_errors.h" - -/* - ldb_ldif_write takes a function pointer to a custom output - function. This version is about as simple as the output function can - be. In a more complex example, you'd likely be doing something with - the private data function (e.g. holding a file handle). -*/ -static int vprintf_fn(void *private_data, const char *fmt, ...) -{ - int retval; - va_list ap; - - va_start(ap, fmt); - /* We just write to standard output */ - retval = vprintf(fmt, ap); - va_end(ap); - /* Note that the function should return the number of - bytes written, or a negative error code */ - return retval; -} - -int main(int argc, const char **argv) -{ - struct ldb_context *ldb; - const char *expression = "(dn=*)"; - struct ldb_result *resultMsg; - int i; - - /* - This is the always the first thing you want to do in an LDB - application - initialise up the context structure. - - Note that you can use the context structure as a parent - for talloc allocations as well - */ - ldb = ldb_init(NULL, NULL); - - /* - We now open the database. In this example we just hard code the connection path. - - Also note that the database is being opened read-only. This means that the - call will fail unless the database already exists. - */ - if (LDB_SUCCESS != ldb_connect(ldb, "tdb://tdbtest.ldb", LDB_FLG_RDONLY, NULL) ){ - printf("Problem on connection\n"); - exit(-1); - } - - /* - At this stage we have an open database, and can start using it. It is opened - read-only, so a query is possible. - - We construct a search that just returns all the (sensible) contents. You can do - quite fine grained results with the LDAP search syntax, however it is a bit - confusing to start with. See RFC2254. - */ - if (LDB_SUCCESS != ldb_search(ldb, ldb, &resultMsg, - NULL, LDB_SCOPE_DEFAULT, NULL, - "%s", expression)) { - printf("Problem in search\n"); - exit(-1); - } - - printf("%i records returned\n", resultMsg->count); - - /* - We can now iterate through the results, writing them out - (to standard output) with our custom output routine as defined - at the top of this file - */ - for (i = 0; i < resultMsg->count; ++i) { - struct ldb_ldif ldifMsg; - - printf("Message: %i\n", i+1); - - ldifMsg.changetype = LDB_CHANGETYPE_NONE; - ldifMsg.msg = resultMsg->msgs[i]; - ldb_ldif_write(ldb, vprintf_fn, NULL, &ldifMsg); - } - - /* - There are two objects to clean up - the result from the - ldb_search() query, and the original ldb context. - */ - talloc_free(resultMsg); - - talloc_free(ldb); - - return 0; -} diff --git a/ldb/examples/ldifreader.c b/ldb/examples/ldifreader.c deleted file mode 100644 index 12e7a1a6f..000000000 --- a/ldb/examples/ldifreader.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - example code for the ldb database library - - Copyright (C) Brad Hards (bradh@frogmouth.net) 2005-2006 - - ** 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -/** \example ldifreader.c - -The code below shows a simple LDB application. - -It lists / dumps the entries in an LDIF file to standard output. - -*/ - -#include "ldb_includes.h" -#include "ldb.h" -#include "ldb_errors.h" - -/* - ldb_ldif_write takes a function pointer to a custom output - function. This version is about as simple as the output function can - be. In a more complex example, you'd likely be doing something with - the private data function (e.g. holding a file handle). -*/ -static int vprintf_fn(void *private_data, const char *fmt, ...) -{ - int retval; - va_list ap; - - va_start(ap, fmt); - /* We just write to standard output */ - retval = vprintf(fmt, ap); - va_end(ap); - /* Note that the function should return the number of - bytes written, or a negative error code */ - return retval; -} - -int main(int argc, const char **argv) -{ - struct ldb_context *ldb; - FILE *fileStream; - struct ldb_ldif *ldifMsg; - - if (argc != 2) { - printf("Usage %s filename.ldif\n", argv[0]); - exit(1); - } - - /* - This is the always the first thing you want to do in an LDB - application - initialise up the context structure. - - Note that you can use the context structure as a parent - for talloc allocations as well - */ - ldb = ldb_init(NULL, NULL); - - fileStream = fopen(argv[1], "r"); - if (0 == fileStream) { - perror(argv[1]); - exit(1); - } - - /* - We now work through the filestream to get each entry. - */ - while ( (ldifMsg = ldb_ldif_read_file(ldb, fileStream)) ) { - /* - Each message has a particular change type. For Add, - Modify and Delete, this will also appear in the - output listing (as changetype: add, changetype: - modify or changetype:delete, respectively). - */ - switch (ldifMsg->changetype) { - case LDB_CHANGETYPE_NONE: - printf("ChangeType: None\n"); - break; - case LDB_CHANGETYPE_ADD: - printf("ChangeType: Add\n"); - break; - case LDB_CHANGETYPE_MODIFY: - printf("ChangeType: Modify\n"); - break; - case LDB_CHANGETYPE_DELETE: - printf("ChangeType: Delete\n"); - break; - default: - printf("ChangeType: Unknown\n"); - } - - /* - We can now write out the results, using our custom - output routine as defined at the top of this file. - */ - ldb_ldif_write(ldb, vprintf_fn, NULL, ldifMsg); - - /* - Clean up the message - */ - ldb_ldif_read_free(ldb, ldifMsg); - } - - /* - Clean up the context - */ - talloc_free(ldb); - - return 0; -} diff --git a/ldb/external/libevents.m4 b/ldb/external/libevents.m4 deleted file mode 100644 index 2aabb06d5..000000000 --- a/ldb/external/libevents.m4 +++ /dev/null @@ -1,7 +0,0 @@ -AC_SUBST(EVENTS_OBJ) -AC_SUBST(EVENTS_CFLAGS) -AC_SUBST(EVENTS_LIBS) - -AC_CHECK_HEADER(tevent.h, - [AC_CHECK_LIB(tevent, event_context_init, [EVENTS_LIBS="-ltevent"]) ], - [PKG_CHECK_MODULES(EVENTS, tevent)]) diff --git a/ldb/external/libpopt.m4 b/ldb/external/libpopt.m4 deleted file mode 100644 index c5d12550a..000000000 --- a/ldb/external/libpopt.m4 +++ /dev/null @@ -1,7 +0,0 @@ -POPT_OBJ="" -AC_SUBST(POPT_OBJ) -AC_SUBST(POPT_LIBS) -AC_SUBST(POPT_CFLAGS) - -AC_CHECK_HEADERS(popt.h) -AC_CHECK_LIB(popt, poptGetContext, [ POPT_LIBS="-lpopt" ]) diff --git a/ldb/external/libtalloc.m4 b/ldb/external/libtalloc.m4 deleted file mode 100644 index a4c5b8a9d..000000000 --- a/ldb/external/libtalloc.m4 +++ /dev/null @@ -1,7 +0,0 @@ -AC_SUBST(TALLOC_OBJ) -AC_SUBST(TALLOC_CFLAGS) -AC_SUBST(TALLOC_LIBS) - -AC_CHECK_HEADER(talloc.h, - [AC_CHECK_LIB(talloc, talloc_init, [TALLOC_LIBS="-ltalloc"]) ], - [PKG_CHECK_MODULES(TALLOC, talloc)]) diff --git a/ldb/external/libtdb.m4 b/ldb/external/libtdb.m4 deleted file mode 100644 index 8c2cab702..000000000 --- a/ldb/external/libtdb.m4 +++ /dev/null @@ -1,7 +0,0 @@ -AC_SUBST(TDB_OBJ) -AC_SUBST(TDB_CFLAGS) -AC_SUBST(TDB_LIBS) - -AC_CHECK_HEADER(tdb.h, - [AC_CHECK_LIB(tdb, tdb_open, [TDB_LIBS="-ltdb"]) ], - [PKG_CHECK_MODULES(TDB, tdb >= 1.1.0)]) diff --git a/ldb/external/pkg.m4 b/ldb/external/pkg.m4 deleted file mode 100644 index a8b3d06c8..000000000 --- a/ldb/external/pkg.m4 +++ /dev/null @@ -1,156 +0,0 @@ -# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*- -# -# Copyright © 2004 Scott James Remnant <scott@netsplit.com>. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# This program 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 -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, see <http://www.gnu.org/licenses/>. -# -# As a special exception to the GNU General Public License, if you -# distribute this file as part of a program that contains a -# configuration script generated by Autoconf, you may include it under -# the same distribution terms that you use for the rest of that program. - -# PKG_PROG_PKG_CONFIG([MIN-VERSION]) -# ---------------------------------- -AC_DEFUN([PKG_PROG_PKG_CONFIG], -[m4_pattern_forbid([^_?PKG_[A-Z_]+$]) -m4_pattern_allow([^PKG_CONFIG(_PATH)?$]) -AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])dnl -if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then - AC_PATH_TOOL([PKG_CONFIG], [pkg-config]) -fi -if test -n "$PKG_CONFIG"; then - _pkg_min_version=m4_default([$1], [0.9.0]) - AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version]) - if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then - AC_MSG_RESULT([yes]) - else - AC_MSG_RESULT([no]) - PKG_CONFIG="" - fi - -fi[]dnl -])# PKG_PROG_PKG_CONFIG - -# PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) -# -# Check to see whether a particular set of modules exists. Similar -# to PKG_CHECK_MODULES(), but does not set variables or print errors. -# -# -# Similar to PKG_CHECK_MODULES, make sure that the first instance of -# this or PKG_CHECK_MODULES is called, or make sure to call -# PKG_CHECK_EXISTS manually -# -------------------------------------------------------------- -AC_DEFUN([PKG_CHECK_EXISTS], -[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl -if test -n "$PKG_CONFIG" && \ - AC_RUN_LOG([$PKG_CONFIG --exists --print-errors "$1"]); then - m4_ifval([$2], [$2], [:]) -m4_ifvaln([$3], [else - $3])dnl -fi]) - - -# _PKG_CONFIG([VARIABLE], [COMMAND], [MODULES]) -# --------------------------------------------- -m4_define([_PKG_CONFIG], -[if test -n "$PKG_CONFIG"; then - if test -n "$$1"; then - pkg_cv_[]$1="$$1" - else - PKG_CHECK_EXISTS([$3], - [pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`], - [pkg_failed=yes]) - fi -else - pkg_failed=untried -fi[]dnl -])# _PKG_CONFIG - -# _PKG_SHORT_ERRORS_SUPPORTED -# ----------------------------- -AC_DEFUN([_PKG_SHORT_ERRORS_SUPPORTED], -[AC_REQUIRE([PKG_PROG_PKG_CONFIG]) -if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then - _pkg_short_errors_supported=yes -else - _pkg_short_errors_supported=no -fi[]dnl -])# _PKG_SHORT_ERRORS_SUPPORTED - - -# PKG_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND], -# [ACTION-IF-NOT-FOUND]) -# -# -# Note that if there is a possibility the first call to -# PKG_CHECK_MODULES might not happen, you should be sure to include an -# explicit call to PKG_PROG_PKG_CONFIG in your configure.ac -# -# -# -------------------------------------------------------------- -AC_DEFUN([PKG_CHECK_MODULES], -[AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl -AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl -AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl - -pkg_failed=no -AC_MSG_CHECKING([for $1]) - -_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2]) -_PKG_CONFIG([$1][_LIBS], [libs], [$2]) - -m4_define([_PKG_TEXT], [Alternatively, you may set the environment variables $1[]_CFLAGS -and $1[]_LIBS to avoid the need to call pkg-config. -See the pkg-config man page for more details.]) - -if test $pkg_failed = yes; then - _PKG_SHORT_ERRORS_SUPPORTED - if test $_pkg_short_errors_supported = yes; then - $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "$2"` - else - $1[]_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"` - fi - # Put the nasty error message in config.log where it belongs - echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD - - ifelse([$4], , [AC_MSG_ERROR(dnl -[Package requirements ($2) were not met: - -$$1_PKG_ERRORS - -Consider adjusting the PKG_CONFIG_PATH environment variable if you -installed software in a non-standard prefix. - -_PKG_TEXT -])], - [AC_MSG_RESULT([no]) - $4]) -elif test $pkg_failed = untried; then - ifelse([$4], , [AC_MSG_FAILURE(dnl -[The pkg-config script could not be found or is too old. Make sure it -is in your PATH or set the PKG_CONFIG environment variable to the full -path to pkg-config. - -_PKG_TEXT - -To get pkg-config, see <http://www.freedesktop.org/software/pkgconfig>.])], - [$4]) -else - $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS - $1[]_LIBS=$pkg_cv_[]$1[]_LIBS - AC_MSG_RESULT([yes]) - ifelse([$3], , :, [$3]) -fi[]dnl -])# PKG_CHECK_MODULES diff --git a/ldb/include/dlinklist.h b/ldb/include/dlinklist.h deleted file mode 100644 index d3252751d..000000000 --- a/ldb/include/dlinklist.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - Unix SMB/CIFS implementation. - some simple double linked list macros - Copyright (C) Andrew Tridgell 1998 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -/* To use these macros you must have a structure containing a next and - prev pointer */ - - -/* hook into the front of the list */ -#define DLIST_ADD(list, p) \ -do { \ - if (!(list)) { \ - (list) = (p); \ - (p)->next = (p)->prev = NULL; \ - } else { \ - (list)->prev = (p); \ - (p)->next = (list); \ - (p)->prev = NULL; \ - (list) = (p); \ - }\ -} while (0) - -/* remove an element from a list - element doesn't have to be in list. */ -#ifndef DLIST_REMOVE -#define DLIST_REMOVE(list, p) \ -do { \ - if ((p) == (list)) { \ - (list) = (p)->next; \ - if (list) (list)->prev = NULL; \ - } else { \ - if ((p)->prev) (p)->prev->next = (p)->next; \ - if ((p)->next) (p)->next->prev = (p)->prev; \ - } \ - if ((p) && ((p) != (list))) (p)->next = (p)->prev = NULL; \ -} while (0) -#endif - -/* promote an element to the top of the list */ -#define DLIST_PROMOTE(list, p) \ -do { \ - DLIST_REMOVE(list, p); \ - DLIST_ADD(list, p); \ -} while (0) - -/* hook into the end of the list - needs a tmp pointer */ -#define DLIST_ADD_END(list, p, type) \ -do { \ - if (!(list)) { \ - (list) = (p); \ - (p)->next = (p)->prev = NULL; \ - } else { \ - type tmp; \ - for (tmp = (list); tmp->next; tmp = tmp->next) ; \ - tmp->next = (p); \ - (p)->next = NULL; \ - (p)->prev = tmp; \ - } \ -} while (0) - -/* insert 'p' after the given element 'el' in a list. If el is NULL then - this is the same as a DLIST_ADD() */ -#define DLIST_ADD_AFTER(list, p, el) \ -do { \ - if (!(list) || !(el)) { \ - DLIST_ADD(list, p); \ - } else { \ - p->prev = el; \ - p->next = el->next; \ - el->next = p; \ - if (p->next) p->next->prev = p; \ - }\ -} while (0) - -/* demote an element to the end of the list, needs a tmp pointer */ -#define DLIST_DEMOTE(list, p, tmp) \ -do { \ - DLIST_REMOVE(list, p); \ - DLIST_ADD_END(list, p, tmp); \ -} while (0) - -/* concatenate two lists - putting all elements of the 2nd list at the - end of the first list */ -#define DLIST_CONCATENATE(list1, list2, type) \ -do { \ - if (!(list1)) { \ - (list1) = (list2); \ - } else { \ - type tmp; \ - for (tmp = (list1); tmp->next; tmp = tmp->next) ; \ - tmp->next = (list2); \ - if (list2) { \ - (list2)->prev = tmp; \ - } \ - } \ -} while (0) diff --git a/ldb/include/ldb.h b/ldb/include/ldb.h deleted file mode 100644 index cb42e8a66..000000000 --- a/ldb/include/ldb.h +++ /dev/null @@ -1,1829 +0,0 @@ -/* - ldb database library - - Copyright (C) Andrew Tridgell 2004 - Copyright (C) Stefan Metzmacher 2004 - Copyright (C) Simo Sorce 2005-2006 - - ** 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -/* - * Name: ldb - * - * Component: ldb header - * - * Description: defines for base ldb API - * - * Author: Andrew Tridgell - * Author: Stefan Metzmacher - */ - -/** - \file ldb.h Samba's ldb database - - This header file provides the main API for ldb. -*/ - -#ifndef _LDB_H_ - -/*! \cond DOXYGEN_IGNORE */ -#define _LDB_H_ 1 -/*! \endcond */ - -#include <stdbool.h> -#include <talloc.h> -#include <tevent.h> - -/* - major restrictions as compared to normal LDAP: - - - no async calls. - - each record must have a unique key field - - the key must be representable as a NULL terminated C string and may not - contain a comma or braces - - major restrictions as compared to tdb: - - - no explicit locking calls - UPDATE: we have transactions now, better than locking --SSS. - -*/ - -#ifndef ldb_val -/** - Result value - - An individual lump of data in a result comes in this format. The - pointer will usually be to a UTF-8 string if the application is - sensible, but it can be to anything you like, including binary data - blobs of arbitrary size. - - \note the data is null (0x00) terminated, but the length does not - include the terminator. -*/ -struct ldb_val { - uint8_t *data; /*!< result data */ - size_t length; /*!< length of data */ -}; -#endif - -/*! \cond DOXYGEN_IGNORE */ -#ifndef PRINTF_ATTRIBUTE -#define PRINTF_ATTRIBUTE(a,b) -#endif -/*! \endcond */ - -/* opaque ldb_dn structures, see ldb_dn.c for internals */ -struct ldb_dn_component; -struct ldb_dn; - -/** - There are a number of flags that are used with ldap_modify() in - ldb_message_element.flags fields. The LDA_FLAGS_MOD_ADD, - LDA_FLAGS_MOD_DELETE and LDA_FLAGS_MOD_REPLACE flags are used in - ldap_modify() calls to specify whether attributes are being added, - deleted or modified respectively. -*/ -#define LDB_FLAG_MOD_MASK 0x3 - -/** - Flag value used in ldap_modify() to indicate that attributes are - being added. - - \sa LDB_FLAG_MOD_MASK -*/ -#define LDB_FLAG_MOD_ADD 1 - -/** - Flag value used in ldap_modify() to indicate that attributes are - being replaced. - - \sa LDB_FLAG_MOD_MASK -*/ -#define LDB_FLAG_MOD_REPLACE 2 - -/** - Flag value used in ldap_modify() to indicate that attributes are - being deleted. - - \sa LDB_FLAG_MOD_MASK -*/ -#define LDB_FLAG_MOD_DELETE 3 - -/** - OID for logic AND comaprison. - - This is the well known object ID for a logical AND comparitor. -*/ -#define LDB_OID_COMPARATOR_AND "1.2.840.113556.1.4.803" - -/** - OID for logic OR comparison. - - This is the well known object ID for a logical OR comparitor. -*/ -#define LDB_OID_COMPARATOR_OR "1.2.840.113556.1.4.804" - -/** - results are given back as arrays of ldb_message_element -*/ -struct ldb_message_element { - unsigned int flags; - const char *name; - unsigned int num_values; - struct ldb_val *values; -}; - - -/** - a ldb_message represents all or part of a record. It can contain an arbitrary - number of elements. -*/ -struct ldb_message { - struct ldb_dn *dn; - unsigned int num_elements; - struct ldb_message_element *elements; -}; - -enum ldb_changetype { - LDB_CHANGETYPE_NONE=0, - LDB_CHANGETYPE_ADD, - LDB_CHANGETYPE_DELETE, - LDB_CHANGETYPE_MODIFY -}; - -/** - LDIF record - - This structure contains a LDIF record, as returned from ldif_read() - and equivalent functions. -*/ -struct ldb_ldif { - enum ldb_changetype changetype; /*!< The type of change */ - struct ldb_message *msg; /*!< The changes */ -}; - -enum ldb_scope {LDB_SCOPE_DEFAULT=-1, - LDB_SCOPE_BASE=0, - LDB_SCOPE_ONELEVEL=1, - LDB_SCOPE_SUBTREE=2}; - -struct ldb_context; -struct event_context; - -/* debugging uses one of the following levels */ -enum ldb_debug_level {LDB_DEBUG_FATAL, LDB_DEBUG_ERROR, - LDB_DEBUG_WARNING, LDB_DEBUG_TRACE}; - -/** - the user can optionally supply a debug function. The function - is based on the vfprintf() style of interface, but with the addition - of a severity level -*/ -struct ldb_debug_ops { - void (*debug)(void *context, enum ldb_debug_level level, - const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0); - void *context; -}; - -/** - The user can optionally supply a custom utf8 functions, - to handle comparisons and casefolding. -*/ -struct ldb_utf8_fns { - void *context; - char *(*casefold)(void *context, TALLOC_CTX *mem_ctx, const char *s, size_t n); -}; - -/** - Flag value for database connection mode. - - If LDB_FLG_RDONLY is used in ldb_connect, then the database will be - opened read-only, if possible. -*/ -#define LDB_FLG_RDONLY 1 - -/** - Flag value for database connection mode. - - If LDB_FLG_NOSYNC is used in ldb_connect, then the database will be - opened without synchronous operations, if possible. -*/ -#define LDB_FLG_NOSYNC 2 - -/** - Flag value to specify autoreconnect mode. - - If LDB_FLG_RECONNECT is used in ldb_connect, then the backend will - be opened in a way that makes it try to auto reconnect if the - connection is dropped (actually make sense only with ldap). -*/ -#define LDB_FLG_RECONNECT 4 - -/** - Flag to tell backends not to use mmap -*/ -#define LDB_FLG_NOMMAP 8 - -/* - structures for ldb_parse_tree handling code -*/ -enum ldb_parse_op { LDB_OP_AND=1, LDB_OP_OR=2, LDB_OP_NOT=3, - LDB_OP_EQUALITY=4, LDB_OP_SUBSTRING=5, - LDB_OP_GREATER=6, LDB_OP_LESS=7, LDB_OP_PRESENT=8, - LDB_OP_APPROX=9, LDB_OP_EXTENDED=10 }; - -struct ldb_parse_tree { - enum ldb_parse_op operation; - union { - struct { - struct ldb_parse_tree *child; - } isnot; - struct { - const char *attr; - struct ldb_val value; - } equality; - struct { - const char *attr; - int start_with_wildcard; - int end_with_wildcard; - struct ldb_val **chunks; - } substring; - struct { - const char *attr; - } present; - struct { - const char *attr; - struct ldb_val value; - } comparison; - struct { - const char *attr; - int dnAttributes; - char *rule_id; - struct ldb_val value; - } extended; - struct { - unsigned int num_elements; - struct ldb_parse_tree **elements; - } list; - } u; -}; - -struct ldb_parse_tree *ldb_parse_tree(TALLOC_CTX *mem_ctx, const char *s); -char *ldb_filter_from_tree(TALLOC_CTX *mem_ctx, struct ldb_parse_tree *tree); - -/** - Encode a binary blob - - This function encodes a binary blob using the encoding rules in RFC - 2254 (Section 4). This function also escapes any non-printable - characters. - - \param mem_ctx the memory context to allocate the return string in. - \param val the (potentially) binary data to be encoded - - \return the encoded data as a null terminated string - - \sa <a href="http://www.ietf.org/rfc/rfc2252.txt">RFC 2252</a>. -*/ -char *ldb_binary_encode(TALLOC_CTX *mem_ctx, struct ldb_val val); - -/** - Encode a string - - This function encodes a string using the encoding rules in RFC 2254 - (Section 4). This function also escapes any non-printable - characters. - - \param mem_ctx the memory context to allocate the return string in. - \param string the string to be encoded - - \return the encoded data as a null terminated string - - \sa <a href="http://www.ietf.org/rfc/rfc2252.txt">RFC 2252</a>. -*/ -char *ldb_binary_encode_string(TALLOC_CTX *mem_ctx, const char *string); - -/* - functions for controlling attribute handling -*/ -typedef int (*ldb_attr_handler_t)(struct ldb_context *, TALLOC_CTX *mem_ctx, const struct ldb_val *, struct ldb_val *); -typedef int (*ldb_attr_comparison_t)(struct ldb_context *, TALLOC_CTX *mem_ctx, const struct ldb_val *, const struct ldb_val *); - -/* - attribute handler structure - - attr -> The attribute name - ldif_read_fn -> convert from ldif to binary format - ldif_write_fn -> convert from binary to ldif format - canonicalise_fn -> canonicalise a value, for use by indexing and dn construction - comparison_fn -> compare two values -*/ - -struct ldb_schema_syntax { - const char *name; - ldb_attr_handler_t ldif_read_fn; - ldb_attr_handler_t ldif_write_fn; - ldb_attr_handler_t canonicalise_fn; - ldb_attr_comparison_t comparison_fn; -}; - -struct ldb_schema_attribute { - const char *name; - unsigned flags; - const struct ldb_schema_syntax *syntax; -}; - -const struct ldb_schema_attribute *ldb_schema_attribute_by_name(struct ldb_context *ldb, - const char *name); - -struct ldb_dn_extended_syntax { - const char *name; - ldb_attr_handler_t read_fn; - ldb_attr_handler_t write_clear_fn; - ldb_attr_handler_t write_hex_fn; -}; - -const struct ldb_dn_extended_syntax *ldb_dn_extended_syntax_by_name(struct ldb_context *ldb, - const char *name); - -/** - The attribute is not returned by default -*/ -#define LDB_ATTR_FLAG_HIDDEN (1<<0) - -/* the attribute handler name should be freed when released */ -#define LDB_ATTR_FLAG_ALLOCATED (1<<1) - -/** - The attribute is supplied by the application and should not be removed -*/ -#define LDB_ATTR_FLAG_FIXED (1<<2) - -/** - LDAP attribute syntax for a DN - - This is the well-known LDAP attribute syntax for a DN. - - See <a href="http://www.ietf.org/rfc/rfc2252.txt">RFC 2252</a>, Section 4.3.2 -*/ -#define LDB_SYNTAX_DN "1.3.6.1.4.1.1466.115.121.1.12" - -/** - LDAP attribute syntax for a Directory String - - This is the well-known LDAP attribute syntax for a Directory String. - - \sa <a href="http://www.ietf.org/rfc/rfc2252.txt">RFC 2252</a>, Section 4.3.2 -*/ -#define LDB_SYNTAX_DIRECTORY_STRING "1.3.6.1.4.1.1466.115.121.1.15" - -/** - LDAP attribute syntax for an integer - - This is the well-known LDAP attribute syntax for an integer. - - See <a href="http://www.ietf.org/rfc/rfc2252.txt">RFC 2252</a>, Section 4.3.2 -*/ -#define LDB_SYNTAX_INTEGER "1.3.6.1.4.1.1466.115.121.1.27" - -/** - LDAP attribute syntax for an octet string - - This is the well-known LDAP attribute syntax for an octet string. - - See <a href="http://www.ietf.org/rfc/rfc2252.txt">RFC 2252</a>, Section 4.3.2 -*/ -#define LDB_SYNTAX_OCTET_STRING "1.3.6.1.4.1.1466.115.121.1.40" - -/** - LDAP attribute syntax for UTC time. - - This is the well-known LDAP attribute syntax for a UTC time. - - See <a href="http://www.ietf.org/rfc/rfc2252.txt">RFC 2252</a>, Section 4.3.2 -*/ -#define LDB_SYNTAX_UTC_TIME "1.3.6.1.4.1.1466.115.121.1.53" - -#define LDB_SYNTAX_OBJECTCLASS "LDB_SYNTAX_OBJECTCLASS" - -/* sorting helpers */ -typedef int (*ldb_qsort_cmp_fn_t) (void *v1, void *v2, void *opaque); - -/** - OID for the paged results control. This control is included in the - searchRequest and searchResultDone messages as part of the controls - field of the LDAPMessage, as defined in Section 4.1.12 of - LDAP v3. - - \sa <a href="http://www.ietf.org/rfc/rfc2696.txt">RFC 2696</a>. -*/ -#define LDB_CONTROL_PAGED_RESULTS_OID "1.2.840.113556.1.4.319" - -/** - OID for specifying the returned elements of the ntSecurityDescriptor - - \sa <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_sd_flags_oid.asp">Microsoft documentation of this OID</a> -*/ -#define LDB_CONTROL_SD_FLAGS_OID "1.2.840.113556.1.4.801" - -/** - OID for specifying an advanced scope for the search (one partition) - - \sa <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_domain_scope_oid.asp">Microsoft documentation of this OID</a> -*/ -#define LDB_CONTROL_DOMAIN_SCOPE_OID "1.2.840.113556.1.4.1339" - -/** - OID for specifying an advanced scope for a search - - \sa <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_search_options_oid.asp">Microsoft documentation of this OID</a> -*/ -#define LDB_CONTROL_SEARCH_OPTIONS_OID "1.2.840.113556.1.4.1340" - -/** - OID for notification - - \sa <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_notification_oid.asp">Microsoft documentation of this OID</a> -*/ -#define LDB_CONTROL_NOTIFICATION_OID "1.2.840.113556.1.4.528" - -/** - OID for getting deleted objects - - \sa <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_show_deleted_oid.asp">Microsoft documentation of this OID</a> -*/ -#define LDB_CONTROL_SHOW_DELETED_OID "1.2.840.113556.1.4.417" - -/** - OID for extended DN - - \sa <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_extended_dn_oid.asp">Microsoft documentation of this OID</a> -*/ -#define LDB_CONTROL_EXTENDED_DN_OID "1.2.840.113556.1.4.529" - -/** - OID for LDAP server sort result extension. - - This control is included in the searchRequest message as part of - the controls field of the LDAPMessage, as defined in Section 4.1.12 - of LDAP v3. The controlType is set to - "1.2.840.113556.1.4.473". The criticality MAY be either TRUE or - FALSE (where absent is also equivalent to FALSE) at the client's - option. - - \sa <a href="http://www.ietf.org/rfc/rfc2891.txt">RFC 2891</a>. -*/ -#define LDB_CONTROL_SERVER_SORT_OID "1.2.840.113556.1.4.473" - -/** - OID for LDAP server sort result response extension. - - This control is included in the searchResultDone message as part of - the controls field of the LDAPMessage, as defined in Section 4.1.12 of - LDAP v3. - - \sa <a href="http://www.ietf.org/rfc/rfc2891.txt">RFC 2891</a>. -*/ -#define LDB_CONTROL_SORT_RESP_OID "1.2.840.113556.1.4.474" - -/** - OID for LDAP Attribute Scoped Query extension. - - This control is included in SearchRequest or SearchResponse - messages as part of the controls field of the LDAPMessage. -*/ -#define LDB_CONTROL_ASQ_OID "1.2.840.113556.1.4.1504" - -/** - OID for LDAP Directory Sync extension. - - This control is included in SearchRequest or SearchResponse - messages as part of the controls field of the LDAPMessage. -*/ -#define LDB_CONTROL_DIRSYNC_OID "1.2.840.113556.1.4.841" - - -/** - OID for LDAP Virtual List View Request extension. - - This control is included in SearchRequest messages - as part of the controls field of the LDAPMessage. -*/ -#define LDB_CONTROL_VLV_REQ_OID "2.16.840.1.113730.3.4.9" - -/** - OID for LDAP Virtual List View Response extension. - - This control is included in SearchResponse messages - as part of the controls field of the LDAPMessage. -*/ -#define LDB_CONTROL_VLV_RESP_OID "2.16.840.1.113730.3.4.10" - -/** - OID to let modifies don't give an error when adding an existing - attribute with the same value or deleting an nonexisting one attribute - - \sa <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ldap/ldap/ldap_server_permissive_modify_oid.asp">Microsoft documentation of this OID</a> -*/ -#define LDB_CONTROL_PERMISSIVE_MODIFY_OID "1.2.840.113556.1.4.1413" - -/** - OID for LDAP Extended Operation START_TLS. - - This Extended operation is used to start a new TLS - channel on top of a clear text channel. -*/ -#define LDB_EXTENDED_START_TLS_OID "1.3.6.1.4.1.1466.20037" - -/** -*/ -#define LDB_EXTENDED_DYNAMIC_OID "1.3.6.1.4.1.1466.101.119.1" - -/** -*/ -#define LDB_EXTENDED_FAST_BIND_OID "1.2.840.113556.1.4.1781" - -struct ldb_sd_flags_control { - /* - * request the owner 0x00000001 - * request the group 0x00000002 - * request the DACL 0x00000004 - * request the SACL 0x00000008 - */ - unsigned secinfo_flags; -}; - -/* - * DOMAIN_SCOPE 0x00000001 - * this limits the search to one partition, - * and no referrals will be returned. - * (Note this doesn't limit the entries by there - * objectSid belonging to a domain! Builtin and Foreign Sids - * are still returned) - * - * PHANTOM_ROOT 0x00000002 - * this search on the whole tree on a domain controller - * over multiple partitions without referrals. - * (This is the default behavior on the Global Catalog Port) - */ - -#define LDB_SEARCH_OPTION_DOMAIN_SCOPE 0x00000001 -#define LDB_SEARCH_OPTION_PHANTOM_ROOT 0x00000002 - -struct ldb_search_options_control { - unsigned search_options; -}; - -struct ldb_paged_control { - int size; - int cookie_len; - char *cookie; -}; - -struct ldb_extended_dn_control { - int type; -}; - -struct ldb_server_sort_control { - char *attributeName; - char *orderingRule; - int reverse; -}; - -struct ldb_sort_resp_control { - int result; - char *attr_desc; -}; - -struct ldb_asq_control { - int request; - char *source_attribute; - int src_attr_len; - int result; -}; - -struct ldb_dirsync_control { - int flags; - int max_attributes; - int cookie_len; - char *cookie; -}; - -struct ldb_vlv_req_control { - int beforeCount; - int afterCount; - int type; - union { - struct { - int offset; - int contentCount; - } byOffset; - struct { - int value_len; - char *value; - } gtOrEq; - } match; - int ctxid_len; - char *contextId; -}; - -struct ldb_vlv_resp_control { - int targetPosition; - int contentCount; - int vlv_result; - int ctxid_len; - char *contextId; -}; - -struct ldb_control { - const char *oid; - int critical; - void *data; -}; - -enum ldb_request_type { - LDB_SEARCH, - LDB_ADD, - LDB_MODIFY, - LDB_DELETE, - LDB_RENAME, - LDB_EXTENDED, - LDB_REQ_REGISTER_CONTROL, - LDB_REQ_REGISTER_PARTITION -}; - -enum ldb_reply_type { - LDB_REPLY_ENTRY, - LDB_REPLY_REFERRAL, - LDB_REPLY_DONE -}; - -enum ldb_wait_type { - LDB_WAIT_ALL, - LDB_WAIT_NONE -}; - -enum ldb_state { - LDB_ASYNC_INIT, - LDB_ASYNC_PENDING, - LDB_ASYNC_DONE -}; - -struct ldb_extended { - const char *oid; - void *data; /* NULL or a valid talloc pointer! talloc_get_type() will be used on it */ -}; - -#define LDB_EXTENDED_SEQUENCE_NUMBER "1.3.6.1.4.1.7165.4.4.3" - -enum ldb_sequence_type { - LDB_SEQ_HIGHEST_SEQ, - LDB_SEQ_HIGHEST_TIMESTAMP, - LDB_SEQ_NEXT -}; - -struct ldb_seqnum_request { - enum ldb_sequence_type type; -}; - -struct ldb_seqnum_result { - uint64_t seq_num; - uint32_t flags; -}; - -struct ldb_result { - unsigned int count; - struct ldb_message **msgs; - struct ldb_extended *extended; - struct ldb_control **controls; - char **refs; -}; - -struct ldb_reply { - int error; - enum ldb_reply_type type; - struct ldb_message *message; - struct ldb_extended *response; - struct ldb_control **controls; - char *referral; -}; - -struct ldb_request; -struct ldb_handle; - -struct ldb_search { - struct ldb_dn *base; - enum ldb_scope scope; - struct ldb_parse_tree *tree; - const char * const *attrs; - struct ldb_result *res; -}; - -struct ldb_add { - const struct ldb_message *message; -}; - -struct ldb_modify { - const struct ldb_message *message; -}; - -struct ldb_delete { - struct ldb_dn *dn; -}; - -struct ldb_rename { - struct ldb_dn *olddn; - struct ldb_dn *newdn; -}; - -struct ldb_register_control { - const char *oid; -}; - -struct ldb_register_partition { - struct ldb_dn *dn; -}; - -typedef int (*ldb_request_callback_t)(struct ldb_request *, struct ldb_reply *); - -struct ldb_request { - - enum ldb_request_type operation; - - union { - struct ldb_search search; - struct ldb_add add; - struct ldb_modify mod; - struct ldb_delete del; - struct ldb_rename rename; - struct ldb_extended extended; - struct ldb_register_control reg_control; - struct ldb_register_partition reg_partition; - } op; - - struct ldb_control **controls; - - void *context; - ldb_request_callback_t callback; - - int timeout; - time_t starttime; - struct ldb_handle *handle; -}; - -int ldb_request(struct ldb_context *ldb, struct ldb_request *request); -int ldb_request_done(struct ldb_request *req, int status); -bool ldb_request_is_done(struct ldb_request *req); - -int ldb_modules_wait(struct ldb_handle *handle); -int ldb_wait(struct ldb_handle *handle, enum ldb_wait_type type); - -int ldb_set_timeout(struct ldb_context *ldb, struct ldb_request *req, int timeout); -int ldb_set_timeout_from_prev_req(struct ldb_context *ldb, struct ldb_request *oldreq, struct ldb_request *newreq); -void ldb_set_create_perms(struct ldb_context *ldb, unsigned int perms); -void ldb_set_modules_dir(struct ldb_context *ldb, const char *path); -struct event_context; -void ldb_set_event_context(struct ldb_context *ldb, struct event_context *ev); -struct event_context * ldb_get_event_context(struct ldb_context *ldb); - -/** - Initialise ldbs' global information - - This is required before any other LDB call - - \return 0 if initialisation succeeded, -1 otherwise -*/ -int ldb_global_init(void); - -/** - Initialise an ldb context - - This is required before any other LDB call. - - \param mem_ctx pointer to a talloc memory context. Pass NULL if there is - no suitable context available. - - \return pointer to ldb_context that should be free'd (using talloc_free()) - at the end of the program. -*/ -struct ldb_context *ldb_init(TALLOC_CTX *mem_ctx, struct event_context *ev_ctx); - -/** - Connect to a database. - - This is typically called soon after ldb_init(), and is required prior to - any search or database modification operations. - - The URL can be one of the following forms: - - tdb://path - - ldapi://path - - ldap://host - - sqlite://path - - \param ldb the context associated with the database (from ldb_init()) - \param url the URL of the database to connect to, as noted above - \param flags a combination of LDB_FLG_* to modify the connection behaviour - \param options backend specific options - passed uninterpreted to the backend - - \return result code (LDB_SUCCESS on success, or a failure code) - - \note It is an error to connect to a database that does not exist in readonly mode - (that is, with LDB_FLG_RDONLY). However in read-write mode, the database will be - created if it does not exist. -*/ - -typedef void (*ldb_async_timeout_fn) (void *); -typedef bool (*ldb_async_callback_fn) (void *); -typedef int (*ldb_async_ctx_add_op_fn)(void *, time_t, void *, ldb_async_timeout_fn, ldb_async_callback_fn); -typedef int (*ldb_async_ctx_wait_op_fn)(void *); - -void ldb_async_ctx_set_private_data(struct ldb_context *ldb, - void *private_data); -void ldb_async_ctx_set_add_op(struct ldb_context *ldb, - ldb_async_ctx_add_op_fn add_op); -void ldb_async_ctx_set_wait_op(struct ldb_context *ldb, - ldb_async_ctx_wait_op_fn wait_op); - -int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[]); - -/* - return an automatic basedn from the rootDomainNamingContext of the rootDSE - This value have been set in an opaque pointer at connection time -*/ -struct ldb_dn *ldb_get_root_basedn(struct ldb_context *ldb); - -/* - return an automatic basedn from the configurationNamingContext of the rootDSE - This value have been set in an opaque pointer at connection time -*/ -struct ldb_dn *ldb_get_config_basedn(struct ldb_context *ldb); - -/* - return an automatic basedn from the schemaNamingContext of the rootDSE - This value have been set in an opaque pointer at connection time -*/ -struct ldb_dn *ldb_get_schema_basedn(struct ldb_context *ldb); - -/* - return an automatic baseDN from the defaultNamingContext of the rootDSE - This value have been set in an opaque pointer at connection time -*/ -struct ldb_dn *ldb_get_default_basedn(struct ldb_context *ldb); - -/** - The default async search callback function - - \param req the request we are callback of - \param ares a single reply from the async core - - \return result code (LDB_SUCCESS on success, or a failure code) - - \note this function expects req->context to always be an struct ldb_result pointer - AND a talloc context, this function will steal on the context each message - from the ares reply passed on by the async core so that in the end all the - messages will be in the context (ldb_result) memory tree. - Freeing the passed context (ldb_result tree) will free all the resources - (the request need to be freed separately and the result doe not depend on the - request that can be freed as sson as the search request is finished) -*/ - -int ldb_search_default_callback(struct ldb_request *req, struct ldb_reply *ares); - -/** - The default async extended operation callback function - - \param req the request we are callback of - \param ares a single reply from the async core - - \return result code (LDB_SUCCESS on success, or a failure code) -*/ -int ldb_op_default_callback(struct ldb_request *req, struct ldb_reply *ares); - - -/** - Helper function to build a search request - - \param ret_req the request structure is returned here (talloced on mem_ctx) - \param ldb the context associated with the database (from ldb_init()) - \param mem_ctx a talloc memory context (used as parent of ret_req) - \param base the Base Distinguished Name for the query (use ldb_dn_new() for an empty one) - \param scope the search scope for the query - \param expression the search expression to use for this query - \param attrs the search attributes for the query (pass NULL if none required) - \param controls an array of controls - \param context the callback function context - \param the callback function to handle the async replies - \param the parent request if any - - \return result code (LDB_SUCCESS on success, or a failure code) -*/ - -int ldb_build_search_req(struct ldb_request **ret_req, - struct ldb_context *ldb, - TALLOC_CTX *mem_ctx, - struct ldb_dn *base, - enum ldb_scope scope, - const char *expression, - const char * const *attrs, - struct ldb_control **controls, - void *context, - ldb_request_callback_t callback, - struct ldb_request *parent); - -int ldb_build_search_req_ex(struct ldb_request **ret_req, - struct ldb_context *ldb, - TALLOC_CTX *mem_ctx, - struct ldb_dn *base, - enum ldb_scope scope, - struct ldb_parse_tree *tree, - const char * const *attrs, - struct ldb_control **controls, - void *context, - ldb_request_callback_t callback, - struct ldb_request *parent); - -/** - Helper function to build an add request - - \param ret_req the request structure is returned here (talloced on mem_ctx) - \param ldb the context associated with the database (from ldb_init()) - \param mem_ctx a talloc memory context (used as parent of ret_req) - \param message contains the entry to be added - \param controls an array of controls - \param context the callback function context - \param the callback function to handle the async replies - \param the parent request if any - - \return result code (LDB_SUCCESS on success, or a failure code) -*/ - -int ldb_build_add_req(struct ldb_request **ret_req, - struct ldb_context *ldb, - TALLOC_CTX *mem_ctx, - const struct ldb_message *message, - struct ldb_control **controls, - void *context, - ldb_request_callback_t callback, - struct ldb_request *parent); - -/** - Helper function to build a modify request - - \param ret_req the request structure is returned here (talloced on mem_ctx) - \param ldb the context associated with the database (from ldb_init()) - \param mem_ctx a talloc memory context (used as parent of ret_req) - \param message contains the entry to be modified - \param controls an array of controls - \param context the callback function context - \param the callback function to handle the async replies - \param the parent request if any - - \return result code (LDB_SUCCESS on success, or a failure code) -*/ - -int ldb_build_mod_req(struct ldb_request **ret_req, - struct ldb_context *ldb, - TALLOC_CTX *mem_ctx, - const struct ldb_message *message, - struct ldb_control **controls, - void *context, - ldb_request_callback_t callback, - struct ldb_request *parent); - -/** - Helper function to build a delete request - - \param ret_req the request structure is returned here (talloced on mem_ctx) - \param ldb the context associated with the database (from ldb_init()) - \param mem_ctx a talloc memory context (used as parent of ret_req) - \param dn the DN to be deleted - \param controls an array of controls - \param context the callback function context - \param the callback function to handle the async replies - \param the parent request if any - - \return result code (LDB_SUCCESS on success, or a failure code) -*/ - -int ldb_build_del_req(struct ldb_request **ret_req, - struct ldb_context *ldb, - TALLOC_CTX *mem_ctx, - struct ldb_dn *dn, - struct ldb_control **controls, - void *context, - ldb_request_callback_t callback, - struct ldb_request *parent); - -/** - Helper function to build a rename request - - \param ret_req the request structure is returned here (talloced on mem_ctx) - \param ldb the context associated with the database (from ldb_init()) - \param mem_ctx a talloc memory context (used as parent of ret_req) - \param olddn the old DN - \param newdn the new DN - \param controls an array of controls - \param context the callback function context - \param the callback function to handle the async replies - \param the parent request if any - - \return result code (LDB_SUCCESS on success, or a failure code) -*/ - -int ldb_build_rename_req(struct ldb_request **ret_req, - struct ldb_context *ldb, - TALLOC_CTX *mem_ctx, - struct ldb_dn *olddn, - struct ldb_dn *newdn, - struct ldb_control **controls, - void *context, - ldb_request_callback_t callback, - struct ldb_request *parent); - -/** - Add a ldb_control to a ldb_request - - \param req the request struct where to add the control - \param oid the object identifier of the control as string - \param critical whether the control should be critical or not - \param data a talloc pointer to the control specific data - - \return result code (LDB_SUCCESS on success, or a failure code) -*/ -int ldb_request_add_control(struct ldb_request *req, const char *oid, bool critical, void *data); - -/** - check if a control with the specified "oid" exist and return it - \param req the request struct where to add the control - \param oid the object identifier of the control as string - - \return the control, NULL if not found -*/ -struct ldb_control *ldb_request_get_control(struct ldb_request *req, const char *oid); - -/** - check if a control with the specified "oid" exist and return it - \param rep the reply struct where to add the control - \param oid the object identifier of the control as string - - \return the control, NULL if not found -*/ -struct ldb_control *ldb_reply_get_control(struct ldb_reply *rep, const char *oid); - -/** - Search the database - - This function searches the database, and returns - records that match an LDAP-like search expression - - \param ldb the context associated with the database (from ldb_init()) - \param mem_ctx the memory context to use for the request and the results - \param result the return result - \param base the Base Distinguished Name for the query (use ldb_dn_new() for an empty one) - \param scope the search scope for the query - \param attrs the search attributes for the query (pass NULL if none required) - \param exp_fmt the search expression to use for this query (printf like) - - \return result code (LDB_SUCCESS on success, or a failure code) - - \note use talloc_free() to free the ldb_result returned -*/ -int ldb_search(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, - struct ldb_result **result, struct ldb_dn *base, - enum ldb_scope scope, const char * const *attrs, - const char *exp_fmt, ...) PRINTF_ATTRIBUTE(7,8); - -/** - Add a record to the database. - - This function adds a record to the database. This function will fail - if a record with the specified class and key already exists in the - database. - - \param ldb the context associated with the database (from - ldb_init()) - \param message the message containing the record to add. - - \return result code (LDB_SUCCESS if the record was added, otherwise - a failure code) -*/ -int ldb_add(struct ldb_context *ldb, - const struct ldb_message *message); - -/** - Modify the specified attributes of a record - - This function modifies a record that is in the database. - - \param ldb the context associated with the database (from - ldb_init()) - \param message the message containing the changes required. - - \return result code (LDB_SUCCESS if the record was modified as - requested, otherwise a failure code) -*/ -int ldb_modify(struct ldb_context *ldb, - const struct ldb_message *message); - -/** - Rename a record in the database - - This function renames a record in the database. - - \param ldb the context associated with the database (from - ldb_init()) - \param olddn the DN for the record to be renamed. - \param newdn the new DN - - \return result code (LDB_SUCCESS if the record was renamed as - requested, otherwise a failure code) -*/ -int ldb_rename(struct ldb_context *ldb, struct ldb_dn *olddn, struct ldb_dn *newdn); - -/** - Delete a record from the database - - This function deletes a record from the database. - - \param ldb the context associated with the database (from - ldb_init()) - \param dn the DN for the record to be deleted. - - \return result code (LDB_SUCCESS if the record was deleted, - otherwise a failure code) -*/ -int ldb_delete(struct ldb_context *ldb, struct ldb_dn *dn); - -/** - The default async extended operation callback function - - \param req the request we are callback of - \param ares a single reply from the async core - - \return result code (LDB_SUCCESS on success, or a failure code) - - \note this function expects req->context to always be an struct ldb_result pointer - AND a talloc context, this function will steal on the context each message - from the ares reply passed on by the async core so that in the end all the - messages will be in the context (ldb_result) memory tree. - Freeing the passed context (ldb_result tree) will free all the resources - (the request need to be freed separately and the result doe not depend on the - request that can be freed as sson as the search request is finished) -*/ - -int ldb_extended_default_callback(struct ldb_request *req, struct ldb_reply *ares); - - -/** - Helper function to build a extended request - - \param ret_req the request structure is returned here (talloced on mem_ctx) - \param ldb the context associated with the database (from ldb_init()) - \param mem_ctx a talloc memory context (used as parent of ret_req) - \param oid the OID of the extended operation. - \param data a void pointer a the extended operation specific parameters, - it needs to be NULL or a valid talloc pointer! talloc_get_type() will be used on it - \param controls an array of controls - \param context the callback function context - \param the callback function to handle the async replies - \param the parent request if any - - \return result code (LDB_SUCCESS on success, or a failure code) -*/ -int ldb_build_extended_req(struct ldb_request **ret_req, - struct ldb_context *ldb, - TALLOC_CTX *mem_ctx, - const char *oid, - void *data,/* NULL or a valid talloc pointer! talloc_get_type() will be used on it */ - struct ldb_control **controls, - void *context, - ldb_request_callback_t callback, - struct ldb_request *parent); - -/** - call an extended operation - - This function deletes a record from the database. - - \param ldb the context associated with the database (from ldb_init()) - \param oid the OID of the extended operation. - \param data a void pointer a the extended operation specific parameters, - it needs to be NULL or a valid talloc pointer! talloc_get_type() will be used on it - \param res the result of the extended operation - - \return result code (LDB_SUCCESS if the extended operation returned fine, - otherwise a failure code) -*/ -int ldb_extended(struct ldb_context *ldb, - const char *oid, - void *data,/* NULL or a valid talloc pointer! talloc_get_type() will be used on it */ - struct ldb_result **res); - -/** - start a transaction -*/ -int ldb_transaction_start(struct ldb_context *ldb); - -/** - commit a transaction -*/ -int ldb_transaction_commit(struct ldb_context *ldb); - -/** - cancel a transaction -*/ -int ldb_transaction_cancel(struct ldb_context *ldb); - - -/** - return extended error information from the last call -*/ -const char *ldb_errstring(struct ldb_context *ldb); - -/** - return a string explaining what a ldb error constant meancs -*/ -const char *ldb_strerror(int ldb_err); - -/** - setup the default utf8 functions - FIXME: these functions do not yet handle utf8 -*/ -void ldb_set_utf8_default(struct ldb_context *ldb); - -/** - Casefold a string - - \param ldb the ldb context - \param mem_ctx the memory context to allocate the result string - memory from. - \param s the string that is to be folded - \return a copy of the string, converted to upper case - - \note The default function is not yet UTF8 aware. Provide your own - set of functions through ldb_set_utf8_fns() -*/ -char *ldb_casefold(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *s, size_t n); - -/** - Check the attribute name is valid according to rfc2251 - \param s the string to check - - \return 1 if the name is ok -*/ -int ldb_valid_attr_name(const char *s); - -/* - ldif manipulation functions -*/ - -/** - Write an LDIF message - - This function writes an LDIF message using a caller supplied write - function. - - \param ldb the ldb context (from ldb_init()) - \param fprintf_fn a function pointer for the write function. This must take - a private data pointer, followed by a format string, and then a variable argument - list. - \param private_data pointer that will be provided back to the write - function. This is useful for maintaining state or context. - \param ldif the message to write out - - \return the total number of bytes written, or an error code as returned - from the write function. - - \sa ldb_ldif_write_file for a more convenient way to write to a - file stream. - - \sa ldb_ldif_read for the reader equivalent to this function. -*/ -int ldb_ldif_write(struct ldb_context *ldb, - int (*fprintf_fn)(void *, const char *, ...) PRINTF_ATTRIBUTE(2,3), - void *private_data, - const struct ldb_ldif *ldif); - -/** - Clean up an LDIF message - - This function cleans up a LDIF message read using ldb_ldif_read() - or related functions (such as ldb_ldif_read_string() and - ldb_ldif_read_file(). - - \param ldb the ldb context (from ldb_init()) - \param msg the message to clean up and free - -*/ -void ldb_ldif_read_free(struct ldb_context *ldb, struct ldb_ldif *msg); - -/** - Read an LDIF message - - This function creates an LDIF message using a caller supplied read - function. - - \param ldb the ldb context (from ldb_init()) - \param fgetc_fn a function pointer for the read function. This must - take a private data pointer, and must return a pointer to an - integer corresponding to the next byte read (or EOF if there is no - more data to be read). - \param private_data pointer that will be provided back to the read - function. This is udeful for maintaining state or context. - - \return the LDIF message that has been read in - - \note You must free the LDIF message when no longer required, using - ldb_ldif_read_free(). - - \sa ldb_ldif_read_file for a more convenient way to read from a - file stream. - - \sa ldb_ldif_read_string for a more convenient way to read from a - string (char array). - - \sa ldb_ldif_write for the writer equivalent to this function. -*/ -struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb, - int (*fgetc_fn)(void *), void *private_data); - -/** - Read an LDIF message from a file - - This function reads the next LDIF message from the contents of a - file stream. If you want to get all of the LDIF messages, you will - need to repeatedly call this function, until it returns NULL. - - \param ldb the ldb context (from ldb_init()) - \param f the file stream to read from (typically from fdopen()) - - \sa ldb_ldif_read_string for an equivalent function that will read - from a string (char array). - - \sa ldb_ldif_write_file for the writer equivalent to this function. - -*/ -struct ldb_ldif *ldb_ldif_read_file(struct ldb_context *ldb, FILE *f); - -/** - Read an LDIF message from a string - - This function reads the next LDIF message from the contents of a char - array. If you want to get all of the LDIF messages, you will need - to repeatedly call this function, until it returns NULL. - - \param ldb the ldb context (from ldb_init()) - \param s pointer to the char array to read from - - \sa ldb_ldif_read_file for an equivalent function that will read - from a file stream. - - \sa ldb_ldif_write for a more general (arbitrary read function) - version of this function. -*/ -struct ldb_ldif *ldb_ldif_read_string(struct ldb_context *ldb, const char **s); - -/** - Write an LDIF message to a file - - \param ldb the ldb context (from ldb_init()) - \param f the file stream to write to (typically from fdopen()) - \param msg the message to write out - - \return the total number of bytes written, or a negative error code - - \sa ldb_ldif_read_file for the reader equivalent to this function. -*/ -int ldb_ldif_write_file(struct ldb_context *ldb, FILE *f, const struct ldb_ldif *msg); - -/** - Base64 encode a buffer - - \param mem_ctx the memory context that the result is allocated - from. - \param buf pointer to the array that is to be encoded - \param len the number of elements in the array to be encoded - - \return pointer to an array containing the encoded data - - \note The caller is responsible for freeing the result -*/ -char *ldb_base64_encode(TALLOC_CTX *mem_ctx, const char *buf, int len); - -/** - Base64 decode a buffer - - This function decodes a base64 encoded string in place. - - \param s the string to decode. - - \return the length of the returned (decoded) string. - - \note the string is null terminated, but the null terminator is not - included in the length. -*/ -int ldb_base64_decode(char *s); - -/* The following definitions come from lib/ldb/common/ldb_dn.c */ - -/** - Get the linear form of a DN (without any extended components) - - \param dn The DN to linearize -*/ - -const char *ldb_dn_get_linearized(struct ldb_dn *dn); - -/** - Allocate a copy of the linear form of a DN (without any extended components) onto the supplied memory context - - \param dn The DN to linearize - \param mem_ctx TALLOC context to return result on -*/ - -char *ldb_dn_alloc_linearized(TALLOC_CTX *mem_ctx, struct ldb_dn *dn); - -/** - Get the linear form of a DN (with any extended components) - - \param mem_ctx TALLOC context to return result on - \param dn The DN to linearize - \param mode Style of extended DN to return (0 is HEX representation of binary form, 1 is a string form) -*/ -char *ldb_dn_get_extended_linearized(void *mem_ctx, struct ldb_dn *dn, int mode); -const struct ldb_val *ldb_dn_get_extended_component(struct ldb_dn *dn, const char *name); -int ldb_dn_set_extended_component(struct ldb_dn *dn, const char *name, const struct ldb_val *val); - -void ldb_dn_remove_extended_components(struct ldb_dn *dn); -bool ldb_dn_has_extended(struct ldb_dn *dn); - -int ldb_dn_extended_add_syntax(struct ldb_context *ldb, - unsigned flags, - const struct ldb_dn_extended_syntax *syntax); - -/** - Allocate a new DN from a string - - \param mem_ctx TALLOC context to return resulting ldb_dn structure on - \param dn The new DN - - \note The DN will not be parsed at this time. Use ldb_dn_validate to tell if the DN is syntacticly correct -*/ - -struct ldb_dn *ldb_dn_new(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, const char *dn); -/** - Allocate a new DN from a printf style format string and arguments - - \param mem_ctx TALLOC context to return resulting ldb_dn structure on - \param new_fms The new DN as a format string (plus arguments) - - \note The DN will not be parsed at this time. Use ldb_dn_validate to tell if the DN is syntacticly correct -*/ - -struct ldb_dn *ldb_dn_new_fmt(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, const char *new_fmt, ...) PRINTF_ATTRIBUTE(3,4); -/** - Allocate a new DN from a struct ldb_val (useful to avoid buffer overrun) - - \param mem_ctx TALLOC context to return resulting ldb_dn structure on - \param dn The new DN - - \note The DN will not be parsed at this time. Use ldb_dn_validate to tell if the DN is syntacticly correct -*/ - -struct ldb_dn *ldb_dn_from_ldb_val(void *mem_ctx, struct ldb_context *ldb, const struct ldb_val *strdn); - -/** - Determine if this DN is syntactically valid - - \param dn The DN to validate -*/ - -bool ldb_dn_validate(struct ldb_dn *dn); - -char *ldb_dn_escape_value(TALLOC_CTX *mem_ctx, struct ldb_val value); -const char *ldb_dn_get_casefold(struct ldb_dn *dn); -char *ldb_dn_alloc_casefold(TALLOC_CTX *mem_ctx, struct ldb_dn *dn); - -int ldb_dn_compare_base(struct ldb_dn *base, struct ldb_dn *dn); -int ldb_dn_compare(struct ldb_dn *edn0, struct ldb_dn *edn1); - -bool ldb_dn_add_base(struct ldb_dn *dn, struct ldb_dn *base); -bool ldb_dn_add_base_fmt(struct ldb_dn *dn, const char *base_fmt, ...) PRINTF_ATTRIBUTE(2,3); -bool ldb_dn_add_child(struct ldb_dn *dn, struct ldb_dn *child); -bool ldb_dn_add_child_fmt(struct ldb_dn *dn, const char *child_fmt, ...) PRINTF_ATTRIBUTE(2,3); -bool ldb_dn_remove_base_components(struct ldb_dn *dn, unsigned int num); -bool ldb_dn_remove_child_components(struct ldb_dn *dn, unsigned int num); - -struct ldb_dn *ldb_dn_copy(TALLOC_CTX *mem_ctx, struct ldb_dn *dn); -struct ldb_dn *ldb_dn_get_parent(TALLOC_CTX *mem_ctx, struct ldb_dn *dn); -char *ldb_dn_canonical_string(TALLOC_CTX *mem_ctx, struct ldb_dn *dn); -char *ldb_dn_canonical_ex_string(TALLOC_CTX *mem_ctx, struct ldb_dn *dn); -int ldb_dn_get_comp_num(struct ldb_dn *dn); -const char *ldb_dn_get_component_name(struct ldb_dn *dn, unsigned int num); -const struct ldb_val *ldb_dn_get_component_val(struct ldb_dn *dn, unsigned int num); -const char *ldb_dn_get_rdn_name(struct ldb_dn *dn); -const struct ldb_val *ldb_dn_get_rdn_val(struct ldb_dn *dn); -int ldb_dn_set_component(struct ldb_dn *dn, int num, const char *name, const struct ldb_val val); - -bool ldb_dn_is_valid(struct ldb_dn *dn); -bool ldb_dn_is_special(struct ldb_dn *dn); -bool ldb_dn_check_special(struct ldb_dn *dn, const char *check); -bool ldb_dn_is_null(struct ldb_dn *dn); - - -/** - Compare two attributes - - This function compares to attribute names. Note that this is a - case-insensitive comparison. - - \param a the first attribute name to compare - \param b the second attribute name to compare - - \return 0 if the attribute names are the same, or only differ in - case; non-zero if there are any differences - - attribute names are restricted by rfc2251 so using - strcasecmp and toupper here is ok. - return 0 for match -*/ -#define ldb_attr_cmp(a, b) strcasecmp(a, b) -char *ldb_attr_casefold(TALLOC_CTX *mem_ctx, const char *s); -int ldb_attr_dn(const char *attr); - -/** - Create an empty message - - \param mem_ctx the memory context to create in. You can pass NULL - to get the top level context, however the ldb context (from - ldb_init()) may be a better choice -*/ -struct ldb_message *ldb_msg_new(TALLOC_CTX *mem_ctx); - -/** - Find an element within an message -*/ -struct ldb_message_element *ldb_msg_find_element(const struct ldb_message *msg, - const char *attr_name); - -/** - Compare two ldb_val values - - \param v1 first ldb_val structure to be tested - \param v2 second ldb_val structure to be tested - - \return 1 for a match, 0 if there is any difference -*/ -int ldb_val_equal_exact(const struct ldb_val *v1, const struct ldb_val *v2); - -/** - find a value within an ldb_message_element - - \param el the element to search - \param val the value to search for - - \note This search is case sensitive -*/ -struct ldb_val *ldb_msg_find_val(const struct ldb_message_element *el, - struct ldb_val *val); - -/** - add a new empty element to a ldb_message -*/ -int ldb_msg_add_empty(struct ldb_message *msg, - const char *attr_name, - int flags, - struct ldb_message_element **return_el); - -/** - add a element to a ldb_message -*/ -int ldb_msg_add(struct ldb_message *msg, - const struct ldb_message_element *el, - int flags); -int ldb_msg_add_value(struct ldb_message *msg, - const char *attr_name, - const struct ldb_val *val, - struct ldb_message_element **return_el); -int ldb_msg_add_steal_value(struct ldb_message *msg, - const char *attr_name, - struct ldb_val *val); -int ldb_msg_add_steal_string(struct ldb_message *msg, - const char *attr_name, char *str); -int ldb_msg_add_string(struct ldb_message *msg, - const char *attr_name, const char *str); -int ldb_msg_add_fmt(struct ldb_message *msg, - const char *attr_name, const char *fmt, ...) PRINTF_ATTRIBUTE(3,4); - -/** - compare two message elements - return 0 on match -*/ -int ldb_msg_element_compare(struct ldb_message_element *el1, - struct ldb_message_element *el2); - -/** - Find elements in a message. - - This function finds elements and converts to a specific type, with - a give default value if not found. Assumes that elements are - single valued. -*/ -const struct ldb_val *ldb_msg_find_ldb_val(const struct ldb_message *msg, const char *attr_name); -int ldb_msg_find_attr_as_int(const struct ldb_message *msg, - const char *attr_name, - int default_value); -unsigned int ldb_msg_find_attr_as_uint(const struct ldb_message *msg, - const char *attr_name, - unsigned int default_value); -int64_t ldb_msg_find_attr_as_int64(const struct ldb_message *msg, - const char *attr_name, - int64_t default_value); -uint64_t ldb_msg_find_attr_as_uint64(const struct ldb_message *msg, - const char *attr_name, - uint64_t default_value); -double ldb_msg_find_attr_as_double(const struct ldb_message *msg, - const char *attr_name, - double default_value); -int ldb_msg_find_attr_as_bool(const struct ldb_message *msg, - const char *attr_name, - int default_value); -const char *ldb_msg_find_attr_as_string(const struct ldb_message *msg, - const char *attr_name, - const char *default_value); - -struct ldb_dn *ldb_msg_find_attr_as_dn(struct ldb_context *ldb, - TALLOC_CTX *mem_ctx, - const struct ldb_message *msg, - const char *attr_name); - -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(TALLOC_CTX *mem_ctx, - const struct ldb_message *msg); - -struct ldb_message *ldb_msg_canonicalize(struct ldb_context *ldb, - const struct ldb_message *msg); - - -struct ldb_message *ldb_msg_diff(struct ldb_context *ldb, - struct ldb_message *msg1, - struct ldb_message *msg2); - -int ldb_msg_check_string_attribute(const struct ldb_message *msg, - const char *name, - const char *value); - -/** - Integrity check an ldb_message - - This function performs basic sanity / integrity checks on an - ldb_message. - - \param ldb context in which to perform the checks - \param msg the message to check - - \return LDB_SUCCESS if the message is OK, or a non-zero error code - (one of LDB_ERR_INVALID_DN_SYNTAX, LDB_ERR_ENTRY_ALREADY_EXISTS or - LDB_ERR_INVALID_ATTRIBUTE_SYNTAX) if there is a problem with a - message. -*/ -int ldb_msg_sanity_check(struct ldb_context *ldb, - const struct ldb_message *msg); - -/** - Duplicate an ldb_val structure - - This function copies an ldb value structure. - - \param mem_ctx the memory context that the duplicated value will be - allocated from - \param v the ldb_val to be duplicated. - - \return the duplicated ldb_val structure. -*/ -struct ldb_val ldb_val_dup(TALLOC_CTX *mem_ctx, const struct ldb_val *v); - -/** - this allows the user to set a debug function for error reporting -*/ -int ldb_set_debug(struct ldb_context *ldb, - void (*debug)(void *context, enum ldb_debug_level level, - const char *fmt, va_list ap) PRINTF_ATTRIBUTE(3,0), - void *context); - -/** - this allows the user to set custom utf8 function for error reporting -*/ -void ldb_set_utf8_fns(struct ldb_context *ldb, - void *context, - char *(*casefold)(void *, void *, const char *, size_t n)); - -/** - this sets up debug to print messages on stderr -*/ -int ldb_set_debug_stderr(struct ldb_context *ldb); - -/* control backend specific opaque values */ -int ldb_set_opaque(struct ldb_context *ldb, const char *name, void *value); -void *ldb_get_opaque(struct ldb_context *ldb, const char *name); - -const char **ldb_attr_list_copy(TALLOC_CTX *mem_ctx, const char * const *attrs); -const char **ldb_attr_list_copy_add(TALLOC_CTX *mem_ctx, const char * const *attrs, const char *new_attr); -int ldb_attr_in_list(const char * const *attrs, const char *attr); - - -void ldb_parse_tree_attr_replace(struct ldb_parse_tree *tree, - const char *attr, - const char *replace); - -int ldb_msg_rename_attr(struct ldb_message *msg, const char *attr, const char *replace); -int ldb_msg_copy_attr(struct ldb_message *msg, const char *attr, const char *replace); -void ldb_msg_remove_attr(struct ldb_message *msg, const char *attr); - -/** - Convert a time structure to a string - - This function converts a time_t structure to an LDAP formatted - GeneralizedTime string. - - \param mem_ctx the memory context to allocate the return string in - \param t the time structure to convert - - \return the formatted string, or NULL if the time structure could - not be converted -*/ -char *ldb_timestring(TALLOC_CTX *mem_ctx, time_t t); - -/** - Convert a string to a time structure - - This function converts an LDAP formatted GeneralizedTime string - to a time_t structure. - - \param s the string to convert - - \return the time structure, or 0 if the string cannot be converted -*/ -time_t ldb_string_to_time(const char *s); - -/** - Convert a time structure to a string - - This function converts a time_t structure to an LDAP formatted - UTCTime string. - - \param mem_ctx the memory context to allocate the return string in - \param t the time structure to convert - - \return the formatted string, or NULL if the time structure could - not be converted -*/ -char *ldb_timestring_utc(TALLOC_CTX *mem_ctx, time_t t); - -/** - Convert a string to a time structure - - This function converts an LDAP formatted UTCTime string - to a time_t structure. - - \param s the string to convert - - \return the time structure, or 0 if the string cannot be converted -*/ -time_t ldb_string_utc_to_time(const char *s); - - -void ldb_qsort (void *const pbase, size_t total_elems, size_t size, void *opaque, ldb_qsort_cmp_fn_t cmp); - - -/** - Convert an array of string represention of a control into an array of ldb_control structures - - \param ldb LDB context - \param mem_ctx TALLOC context to return result on, and to allocate error_string on - \param control_strings Array of string-formatted controls - - \return array of ldb_control elements -*/ -struct ldb_control **ldb_parse_control_strings(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char **control_strings); - -#endif diff --git a/ldb/include/ldb_errors.h b/ldb/include/ldb_errors.h deleted file mode 100644 index 9362233fd..000000000 --- a/ldb/include/ldb_errors.h +++ /dev/null @@ -1,310 +0,0 @@ -/* - ldb database library - - Copyright (C) Simo Sorce 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -/* - * Name: ldb - * - * Component: ldb header - * - * Description: defines error codes following RFC 2251 ldap error codes - * - * Author: Simo Sorce - */ - -#ifndef _LDB_ERRORS_H_ - -/*! \cond DOXYGEN_IGNORE */ -#define _LDB_ERRORS_H_ 1 -/*! \endcond */ - -/** - \file ldb_errors.h - - This header provides a set of result codes for LDB function calls. - - Many LDB function calls return an integer value (int). As shown in - the function documentation, those return values may indicate - whether the function call worked correctly (in which case it - returns LDB_SUCCESS) or some problem occurred (in which case some - other value will be returned). As a special case, - LDB_ERR_COMPARE_FALSE or LDB_ERR_COMPARE_TRUE may be returned, - which does not indicate an error. - - \note Not all error codes make sense for LDB, however they are - based on the LDAP error codes, and are kept for reference and to - avoid overlap. - - \note Some of this documentation is based on information in - the OpenLDAP documentation, as developed and maintained by the - <a href="http://www.openldap.org/">The OpenLDAP Project</a>. - */ - -/** - The function call succeeded. - - If a function returns LDB_SUCCESS, then that function, and the - underlying transactions that may have been required, completed - successfully. -*/ -#define LDB_SUCCESS 0 - -/** - The function call failed for some non-specific reason. -*/ -#define LDB_ERR_OPERATIONS_ERROR 1 - -/** - The function call failed because of a protocol violation. -*/ -#define LDB_ERR_PROTOCOL_ERROR 2 - -/** - The function call failed because a time limit was exceeded. -*/ -#define LDB_ERR_TIME_LIMIT_EXCEEDED 3 - -/** - The function call failed because a size limit was exceeded. -*/ -#define LDB_ERR_SIZE_LIMIT_EXCEEDED 4 - -/** - The function was for value comparison, and the comparison operation - returned false. - - \note This is a status value, and doesn't normally indicate an - error. -*/ -#define LDB_ERR_COMPARE_FALSE 5 - -/** - The function was for value comparison, and the comparison operation - returned true. - - \note This is a status value, and doesn't normally indicate an - error. -*/ -#define LDB_ERR_COMPARE_TRUE 6 - -/** - The function used an authentication method that is not supported by - the database. -*/ -#define LDB_ERR_AUTH_METHOD_NOT_SUPPORTED 7 - -/** - The function call required a underlying operation that required - strong authentication. - - This will normally only occur if you are using LDB with a LDAP - backend. -*/ -#define LDB_ERR_STRONG_AUTH_REQUIRED 8 -/* 9 RESERVED */ - -/** - The function resulted in a referral to another server. -*/ -#define LDB_ERR_REFERRAL 10 - -/** - The function failed because an administrative / policy limit was - exceeded. -*/ -#define LDB_ERR_ADMIN_LIMIT_EXCEEDED 11 - -/** - The function required an extension or capability that the - database cannot provide. -*/ -#define LDB_ERR_UNSUPPORTED_CRITICAL_EXTENSION 12 - -/** - The function involved a transaction or database operation that - could not be performed without a secure link. -*/ -#define LDB_ERR_CONFIDENTIALITY_REQUIRED 13 - -/** - This is an intermediate result code for SASL bind operations that - have more than one step. - - \note This is a result code that does not normally indicate an - error has occurred. -*/ -#define LDB_ERR_SASL_BIND_IN_PROGRESS 14 - -/** - The function referred to an attribute type that is not present in - the entry. -*/ -#define LDB_ERR_NO_SUCH_ATTRIBUTE 16 - -/** - The function referred to an attribute type that is invalid -*/ -#define LDB_ERR_UNDEFINED_ATTRIBUTE_TYPE 17 - -/** - The function required a filter type that is not available for the - specified attribute. -*/ -#define LDB_ERR_INAPPROPRIATE_MATCHING 18 - -/** - The function would have violated an attribute constraint. -*/ -#define LDB_ERR_CONSTRAINT_VIOLATION 19 - -/** - The function involved an attribute type or attribute value that - already exists in the entry. -*/ -#define LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS 20 -/** - The function used an invalid (incorrect syntax) attribute value. -*/ -#define LDB_ERR_INVALID_ATTRIBUTE_SYNTAX 21 - -/* 22-31 unused */ - -/** - The function referred to an object that does not exist in the - database. -*/ -#define LDB_ERR_NO_SUCH_OBJECT 32 - -/** - The function referred to an alias which points to a non-existant - object in the database. -*/ -#define LDB_ERR_ALIAS_PROBLEM 33 - -/** - The function used a DN which was invalid (incorrect syntax). -*/ -#define LDB_ERR_INVALID_DN_SYNTAX 34 - -/* 35 RESERVED */ - -/** - The function required dereferencing of an alias, and something went - wrong during the dereferencing process. -*/ -#define LDB_ERR_ALIAS_DEREFERENCING_PROBLEM 36 - -/* 37-47 unused */ - -/** - The function passed in the wrong authentication method. -*/ -#define LDB_ERR_INAPPROPRIATE_AUTHENTICATION 48 - -/** - The function passed in or referenced incorrect credentials during - authentication. -*/ -#define LDB_ERR_INVALID_CREDENTIALS 49 - -/** - The function required access permissions that the user does not - possess. -*/ -#define LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS 50 - -/** - The function required a transaction or call that the database could - not perform because it is busy. -*/ -#define LDB_ERR_BUSY 51 - -/** - The function required a transaction or call to a database that is - not available. -*/ -#define LDB_ERR_UNAVAILABLE 52 - -/** - The function required a transaction or call to a database that the - database declined to perform. -*/ -#define LDB_ERR_UNWILLING_TO_PERFORM 53 - -/** - The function failed because it resulted in a loop being detected. -*/ -#define LDB_ERR_LOOP_DETECT 54 - -/* 55-63 unused */ - -/** - The function failed because it would have violated a naming rule. -*/ -#define LDB_ERR_NAMING_VIOLATION 64 - -/** - The function failed because it would have violated the schema. -*/ -#define LDB_ERR_OBJECT_CLASS_VIOLATION 65 - -/** - The function required an operation that is only allowed on leaf - objects, but the object is not a leaf. -*/ -#define LDB_ERR_NOT_ALLOWED_ON_NON_LEAF 66 - -/** - The function required an operation that cannot be performed on a - Relative DN, but the object is a Relative DN. -*/ -#define LDB_ERR_NOT_ALLOWED_ON_RDN 67 - -/** - The function failed because the entry already exists. -*/ -#define LDB_ERR_ENTRY_ALREADY_EXISTS 68 - -/** - The function failed because modifications to an object class are - not allowable. -*/ -#define LDB_ERR_OBJECT_CLASS_MODS_PROHIBITED 69 - -/* 70 RESERVED FOR CLDAP */ - -/** - The function failed because it needed to be applied to multiple - databases. -*/ -#define LDB_ERR_AFFECTS_MULTIPLE_DSAS 71 - -/* 72-79 unused */ - -/** - The function failed for unknown reasons. -*/ -#define LDB_ERR_OTHER 80 - -/* 81-90 RESERVED for APIs */ - -#endif /* _LDB_ERRORS_H_ */ diff --git a/ldb/include/ldb_handlers.h b/ldb/include/ldb_handlers.h deleted file mode 100644 index e1c14e679..000000000 --- a/ldb/include/ldb_handlers.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - ldb database library - - Copyright (C) Simo Sorce 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -/* - * Name: ldb - * - * Component: ldb header - * - * Description: defines attribute handlers - * - * Author: Simo Sorce - */ - - -int ldb_handler_copy( struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *in, struct ldb_val *out); - -int ldb_handler_fold( struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *in, struct ldb_val *out); - -int ldb_canonicalise_Integer( struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *in, struct ldb_val *out); - -int ldb_comparison_Integer( struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *v1, const struct ldb_val *v2); - -int ldb_comparison_binary( struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *v1, const struct ldb_val *v2); - -int ldb_comparison_fold( struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *v1, const struct ldb_val *v2); - -int ldb_canonicalise_dn( struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *in, struct ldb_val *out); - -int ldb_comparison_dn( struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *v1, const struct ldb_val *v2); - -int ldb_comparison_objectclass( struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *v1, const struct ldb_val *v2); - -int ldb_comparison_utctime( struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *v1, const struct ldb_val *v2); - -int ldb_canonicalise_utctime( struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *in, struct ldb_val *out); - diff --git a/ldb/include/ldb_includes.h b/ldb/include/ldb_includes.h deleted file mode 100644 index b55350a9d..000000000 --- a/ldb/include/ldb_includes.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _LDB_PRIVATE_INCLUDES_H_ -#define _LDB_PRIVATE_INCLUDES_H_ -/* - a temporary includes file until I work on the ldb build system -*/ - -#if (_SAMBA_BUILD_ >= 4) -/* tell ldb we have the internal ldap code */ -#define HAVE_ILDAP 1 -#endif - -#if (_SAMBA_BUILD_ <= 3) -/* allow forbidden string functions - should be replaced with _m functions */ -#undef strcasecmp -#undef strncasecmp -#define dyn_MODULESDIR dyn_LIBDIR -#endif - -#include "replace.h" -#include "system/filesys.h" -#include "system/time.h" -#include "talloc.h" -#include "tevent.h" -#include "ldb.h" -#include "ldb_errors.h" -#include "ldb_private.h" -#include "dlinklist.h" - -#endif /*_LDB_PRIVATE_INCLUDES_H_*/ diff --git a/ldb/include/ldb_private.h b/ldb/include/ldb_private.h deleted file mode 100644 index 6120025d1..000000000 --- a/ldb/include/ldb_private.h +++ /dev/null @@ -1,286 +0,0 @@ -/* - ldb database library - - Copyright (C) Andrew Tridgell 2004 - Copyright (C) Stefan Metzmacher 2004 - Copyright (C) Simo Sorce 2004-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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -/* - * Name: ldb - * - * Component: ldb private header - * - * Description: defines internal ldb structures used by the subsystem and modules - * - * Author: Andrew Tridgell - * Author: Stefan Metzmacher - */ - -#ifndef _LDB_PRIVATE_H_ -#define _LDB_PRIVATE_H_ 1 - -struct ldb_context; - -struct ldb_module_ops; - -struct ldb_backend_ops; - -struct ldb_handle { - int status; - enum ldb_state state; - struct ldb_context *ldb; -}; - -/* basic module structure */ -struct ldb_module { - struct ldb_module *prev, *next; - struct ldb_context *ldb; - void *private_data; - const struct ldb_module_ops *ops; -}; - -/* - these function pointers define the operations that a ldb module can intercept -*/ -struct ldb_module_ops { - const char *name; - int (*init_context) (struct ldb_module *); - int (*search)(struct ldb_module *, struct ldb_request *); /* search */ - int (*add)(struct ldb_module *, struct ldb_request *); /* add */ - int (*modify)(struct ldb_module *, struct ldb_request *); /* modify */ - int (*del)(struct ldb_module *, struct ldb_request *); /* delete */ - int (*rename)(struct ldb_module *, struct ldb_request *); /* rename */ - int (*request)(struct ldb_module *, struct ldb_request *); /* match any other operation */ - int (*extended)(struct ldb_module *, struct ldb_request *); /* extended operations */ - int (*start_transaction)(struct ldb_module *); - int (*end_transaction)(struct ldb_module *); - int (*del_transaction)(struct ldb_module *); - int (*sequence_number)(struct ldb_module *, struct ldb_request *); - void *private_data; -}; - -/* - schema related information needed for matching rules -*/ -struct ldb_schema { - /* attribute handling table */ - unsigned num_attributes; - struct ldb_schema_attribute *attributes; - - unsigned num_dn_extended_syntax; - struct ldb_dn_extended_syntax *dn_extended_syntax; -}; - -/* - every ldb connection is started by establishing a ldb_context -*/ -struct ldb_context { - /* the operations provided by the backend */ - struct ldb_module *modules; - - /* debugging operations */ - struct ldb_debug_ops debug_ops; - - /* custom utf8 functions */ - struct ldb_utf8_fns utf8_fns; - - /* backend specific opaque parameters */ - struct ldb_opaque { - struct ldb_opaque *next; - const char *name; - void *value; - } *opaque; - - struct ldb_schema schema; - - char *err_string; - - int transaction_active; - - int default_timeout; - - unsigned int flags; - - unsigned int create_perms; - - char *modules_dir; - - struct event_context *ev_ctx; -}; - -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) -#endif - -/* - simplify out of memory handling -*/ -#define ldb_oom(ldb) ldb_debug_set(ldb, LDB_DEBUG_FATAL, "ldb out of memory at %s:%d\n", __FILE__, __LINE__) - -/* The following definitions come from lib/ldb/common/ldb.c */ - -int ldb_connect_backend(struct ldb_context *ldb, const char *url, const char *options[], - struct ldb_module **backend_module); -void ldb_set_default_dns(struct ldb_context *ldb); - -/* The following definitions come from lib/ldb/common/ldb_debug.c */ -void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4); -void ldb_debug_set(struct ldb_context *ldb, enum ldb_debug_level level, - const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4); - -/* The following definitions come from lib/ldb/common/ldb_ldif.c */ -int ldb_should_b64_encode(const struct ldb_val *val); - -extern const struct ldb_module_ops ldb_objectclass_module_ops; -extern const struct ldb_module_ops ldb_operational_module_ops; -extern const struct ldb_module_ops ldb_paged_results_module_ops; -extern const struct ldb_module_ops ldb_rdn_name_module_ops; -extern const struct ldb_module_ops ldb_schema_module_ops; -extern const struct ldb_module_ops ldb_asq_module_ops; -extern const struct ldb_module_ops ldb_server_sort_module_ops; -extern const struct ldb_module_ops ldb_ldap_module_ops; -extern const struct ldb_module_ops ldb_ildap_module_ops; -extern const struct ldb_module_ops ldb_paged_searches_module_ops; -extern const struct ldb_module_ops ldb_tdb_module_ops; -extern const struct ldb_module_ops ldb_skel_module_ops; -extern const struct ldb_module_ops ldb_subtree_rename_module_ops; -extern const struct ldb_module_ops ldb_subtree_delete_module_ops; -extern const struct ldb_module_ops ldb_sqlite3_module_ops; -extern const struct ldb_module_ops ldb_wins_ldb_module_ops; -extern const struct ldb_module_ops ldb_ranged_results_module_ops; - -extern const struct ldb_backend_ops ldb_tdb_backend_ops; -extern const struct ldb_backend_ops ldb_sqlite3_backend_ops; -extern const struct ldb_backend_ops ldb_ldap_backend_ops; -extern const struct ldb_backend_ops ldb_ldapi_backend_ops; -extern const struct ldb_backend_ops ldb_ldaps_backend_ops; - -int ldb_match_msg(struct ldb_context *ldb, - const struct ldb_message *msg, - const struct ldb_parse_tree *tree, - struct ldb_dn *base, - enum ldb_scope scope); - -const struct ldb_schema_syntax *ldb_standard_syntax_by_name(struct ldb_context *ldb, - const char *syntax); - -/* The following definitions come from lib/ldb/common/ldb_attributes.c */ - -int ldb_schema_attribute_add_with_syntax(struct ldb_context *ldb, - const char *name, - unsigned flags, - const struct ldb_schema_syntax *syntax); -int ldb_schema_attribute_add(struct ldb_context *ldb, - const char *name, - unsigned flags, - const char *syntax); -void ldb_schema_attribute_remove(struct ldb_context *ldb, const char *name); -int ldb_setup_wellknown_attributes(struct ldb_context *ldb); - -const char **ldb_subclass_list(struct ldb_context *ldb, const char *classname); -void ldb_subclass_remove(struct ldb_context *ldb, const char *classname); -int ldb_subclass_add(struct ldb_context *ldb, const char *classname, const char *subclass); - -int ldb_handler_copy(struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *in, struct ldb_val *out); -int ldb_comparison_binary(struct ldb_context *ldb, void *mem_ctx, - const struct ldb_val *v1, const struct ldb_val *v2); - -/* The following definitions come from lib/ldb/common/ldb_controls.c */ -struct ldb_control *get_control_from_list(struct ldb_control **controls, const char *oid); -int save_controls(struct ldb_control *exclude, struct ldb_request *req, struct ldb_control ***saver); -int check_critical_controls(struct ldb_control **controls); - -/* The following definitions come from lib/ldb/common/ldb_utf8.c */ -char *ldb_casefold_default(void *context, void *mem_ctx, const char *s, size_t n); - -void ldb_msg_remove_element(struct ldb_message *msg, struct ldb_message_element *el); - -int ldb_msg_element_compare_name(struct ldb_message_element *el1, - struct ldb_message_element *el2); -void ldb_dump_results(struct ldb_context *ldb, struct ldb_result *result, FILE *f); - -/** - Obtain current/next database sequence number -*/ -int ldb_sequence_number(struct ldb_context *ldb, enum ldb_sequence_type type, uint64_t *seq_num); - -#define LDB_SEQ_GLOBAL_SEQUENCE 0x01 -#define LDB_SEQ_TIMESTAMP_SEQUENCE 0x02 - - -/* MODULES specific headers -- SSS */ - -/* The following definitions come from lib/ldb/common/ldb_modules.c */ - -struct ldb_context *ldb_module_get_ctx(struct ldb_module *module); - -const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *string); -int ldb_load_modules_list(struct ldb_context *ldb, const char **module_list, struct ldb_module *backend, struct ldb_module **out); -int ldb_load_modules(struct ldb_context *ldb, const char *options[]); -int ldb_init_module_chain(struct ldb_context *ldb, struct ldb_module *module); -int ldb_next_request(struct ldb_module *module, struct ldb_request *request); -int ldb_next_start_trans(struct ldb_module *module); -int ldb_next_end_trans(struct ldb_module *module); -int ldb_next_del_trans(struct ldb_module *module); -int ldb_next_init(struct ldb_module *module); - -void ldb_set_errstring(struct ldb_context *ldb, const char *err_string); -void ldb_asprintf_errstring(struct ldb_context *ldb, const char *format, ...) PRINTF_ATTRIBUTE(2,3); -void ldb_reset_err_string(struct ldb_context *ldb); - -const char *ldb_default_modules_dir(void); - -int ldb_register_module(const struct ldb_module_ops *); - -typedef int (*ldb_connect_fn)(struct ldb_context *ldb, const char *url, - unsigned int flags, const char *options[], - struct ldb_module **module); - -struct ldb_backend_ops { - const char *name; - ldb_connect_fn connect_fn; -}; - -const char *ldb_default_modules_dir(void); - -int ldb_register_backend(const char *url_prefix, ldb_connect_fn); - -struct ldb_handle *ldb_handle_new(TALLOC_CTX *mem_ctx, struct ldb_context *ldb); - -int ldb_module_send_entry(struct ldb_request *req, - struct ldb_message *msg, - struct ldb_control **ctrls); - -int ldb_module_send_referral(struct ldb_request *req, - char *ref); - -int ldb_module_done(struct ldb_request *req, - struct ldb_control **ctrls, - struct ldb_extended *response, - int error); - -int ldb_mod_register_control(struct ldb_module *module, const char *oid); - - -struct ldb_val ldb_binary_decode(void *mem_ctx, const char *str); - -#endif diff --git a/ldb/install-sh b/ldb/install-sh deleted file mode 100755 index 58719246f..000000000 --- a/ldb/install-sh +++ /dev/null @@ -1,238 +0,0 @@ -#! /bin/sh -# -# install - install a program, script, or datafile -# This comes from X11R5. -# -# Calling this script install-sh is preferred over install.sh, to prevent -# `make' implicit rules from creating a file called install from it -# when there is no Makefile. -# -# This script is compatible with the BSD install script, but was written -# from scratch. -# - - -# set DOITPROG to echo to test this script - -# Don't use :- since 4.3BSD and earlier shells don't like it. -doit="${DOITPROG-}" - - -# put in absolute paths if you don't have them in your path; or use env. vars. - -mvprog="${MVPROG-mv}" -cpprog="${CPPROG-cp}" -chmodprog="${CHMODPROG-chmod}" -chownprog="${CHOWNPROG-chown}" -chgrpprog="${CHGRPPROG-chgrp}" -stripprog="${STRIPPROG-strip}" -rmprog="${RMPROG-rm}" -mkdirprog="${MKDIRPROG-mkdir}" - -transformbasename="" -transform_arg="" -instcmd="$mvprog" -chmodcmd="$chmodprog 0755" -chowncmd="" -chgrpcmd="" -stripcmd="" -rmcmd="$rmprog -f" -mvcmd="$mvprog" -src="" -dst="" -dir_arg="" - -while [ x"$1" != x ]; do - case $1 in - -c) instcmd="$cpprog" - shift - continue;; - - -d) dir_arg=true - shift - continue;; - - -m) chmodcmd="$chmodprog $2" - shift - shift - continue;; - - -o) chowncmd="$chownprog $2" - shift - shift - continue;; - - -g) chgrpcmd="$chgrpprog $2" - shift - shift - continue;; - - -s) stripcmd="$stripprog" - shift - continue;; - - -t=*) transformarg=`echo $1 | sed 's/-t=//'` - shift - continue;; - - -b=*) transformbasename=`echo $1 | sed 's/-b=//'` - shift - continue;; - - *) if [ x"$src" = x ] - then - src=$1 - else - # this colon is to work around a 386BSD /bin/sh bug - : - dst=$1 - fi - shift - continue;; - esac -done - -if [ x"$src" = x ] -then - echo "install: no input file specified" - exit 1 -else - true -fi - -if [ x"$dir_arg" != x ]; then - dst=$src - src="" - - if [ -d $dst ]; then - instcmd=: - else - instcmd=mkdir - fi -else - -# Waiting for this to be detected by the "$instcmd $src $dsttmp" command -# might cause directories to be created, which would be especially bad -# if $src (and thus $dsttmp) contains '*'. - - if [ -f $src -o -d $src ] - then - true - else - echo "install: $src does not exist" - exit 1 - fi - - if [ x"$dst" = x ] - then - echo "install: no destination specified" - exit 1 - else - true - fi - -# If destination is a directory, append the input filename; if your system -# does not like double slashes in filenames, you may need to add some logic - - if [ -d $dst ] - then - dst="$dst"/`basename $src` - else - true - fi -fi - -## this sed command emulates the dirname command -dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` - -# Make sure that the destination directory exists. -# this part is taken from Noah Friedman's mkinstalldirs script - -# Skip lots of stat calls in the usual case. -if [ ! -d "$dstdir" ]; then -defaultIFS=' -' -IFS="${IFS-${defaultIFS}}" - -oIFS="${IFS}" -# Some sh's can't handle IFS=/ for some reason. -IFS='%' -set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` -IFS="${oIFS}" - -pathcomp='' - -while [ $# -ne 0 ] ; do - pathcomp="${pathcomp}${1}" - shift - - if [ ! -d "${pathcomp}" ] ; - then - $mkdirprog "${pathcomp}" - else - true - fi - - pathcomp="${pathcomp}/" -done -fi - -if [ x"$dir_arg" != x ] -then - $doit $instcmd $dst && - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi -else - -# If we're going to rename the final executable, determine the name now. - - if [ x"$transformarg" = x ] - then - dstfile=`basename $dst` - else - dstfile=`basename $dst $transformbasename | - sed $transformarg`$transformbasename - fi - -# don't allow the sed command to completely eliminate the filename - - if [ x"$dstfile" = x ] - then - dstfile=`basename $dst` - else - true - fi - -# Make a temp file name in the proper directory. - - dsttmp=$dstdir/#inst.$$# - -# Move or copy the file name to the temp name - - $doit $instcmd $src $dsttmp && - - trap "rm -f ${dsttmp}" 0 && - -# and set any options; do chmod last to preserve setuid bits - -# If any of these fail, we abort the whole thing. If we want to -# ignore errors from any of these, just make sure not to ignore -# errors from the above "$doit $instcmd $src $dsttmp" command. - - if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && - if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && - if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && - if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && - -# Now rename the file to the real destination. - - $doit $rmcmd -f $dstdir/$dstfile && - $doit $mvcmd $dsttmp $dstdir/$dstfile - -fi && - - -exit 0 diff --git a/ldb/ldap.m4 b/ldb/ldap.m4 deleted file mode 100644 index 417083ed6..000000000 --- a/ldb/ldap.m4 +++ /dev/null @@ -1,90 +0,0 @@ -######################################################## -# Compile with LDAP support? - -LDAP_LIBS="" -with_ldap_support=auto -AC_MSG_CHECKING([for LDAP support]) - -AC_ARG_WITH(ldap, -AS_HELP_STRING([--with-ldap],[LDAP backend support (default=yes)]), -[ case "$withval" in - yes|no) - with_ldap_support=$withval - ;; - esac ]) - -AC_MSG_RESULT($with_ldap_support) - -if test x"$with_ldap_support" != x"no"; then - - ################################################################## - # first test for ldap.h and lber.h - # (ldap.h is required for this test) - AC_CHECK_HEADERS(ldap.h lber.h) - - if test x"$ac_cv_header_ldap_h" != x"yes"; then - if test x"$with_ldap_support" = x"yes"; then - AC_MSG_ERROR(ldap.h is needed for LDAP support) - else - AC_MSG_WARN(ldap.h is needed for LDAP support) - fi - - with_ldap_support=no - fi -fi - -if test x"$with_ldap_support" != x"no"; then - ac_save_LIBS=$LIBS - - ################################################################## - # we might need the lber lib on some systems. To avoid link errors - # this test must be before the libldap test - AC_CHECK_LIB_EXT(lber, LDAP_LIBS, ber_scanf) - - ######################################################## - # now see if we can find the ldap libs in standard paths - AC_CHECK_LIB_EXT(ldap, LDAP_LIBS, ldap_init) - - AC_CHECK_FUNC_EXT(ldap_domain2hostlist,$LDAP_LIBS) - - ######################################################## - # If we have LDAP, does it's rebind procedure take 2 or 3 arguments? - # Check found in pam_ldap 145. - AC_CHECK_FUNC_EXT(ldap_set_rebind_proc,$LDAP_LIBS) - - LIBS="$LIBS $LDAP_LIBS" - AC_CACHE_CHECK(whether ldap_set_rebind_proc takes 3 arguments, smb_ldap_cv_ldap_set_rebind_proc, [ - AC_TRY_COMPILE([ - #include <lber.h> - #include <ldap.h>], - [ldap_set_rebind_proc(0, 0, 0);], - [smb_ldap_cv_ldap_set_rebind_proc=3], - [smb_ldap_cv_ldap_set_rebind_proc=2] - ) - ]) - - AC_DEFINE_UNQUOTED(LDAP_SET_REBIND_PROC_ARGS, $smb_ldap_cv_ldap_set_rebind_proc, [Number of arguments to ldap_set_rebind_proc]) - - AC_CHECK_FUNC_EXT(ldap_initialize,$LDAP_LIBS) - - if test x"$ac_cv_lib_ext_ldap_ldap_init" = x"yes" -a x"$ac_cv_func_ext_ldap_domain2hostlist" = x"yes"; then - AC_DEFINE(HAVE_LDAP,1,[Whether ldap is available]) - AC_DEFINE(HAVE_LDB_LDAP,1,[Whether ldb_ldap is available]) - with_ldap_support=yes - AC_MSG_CHECKING(whether LDAP support is used) - AC_MSG_RESULT(yes) - SMB_ENABLE(LDAP,YES) - else - if test x"$with_ldap_support" = x"yes"; then - AC_MSG_ERROR(libldap is needed for LDAP support) - else - AC_MSG_WARN(libldap is needed for LDAP support) - fi - - LDAP_LIBS="" - with_ldap_support=no - fi - LIBS=$ac_save_LIBS -fi - -SMB_EXT_LIB(LDAP,[${LDAP_LIBS}],[${LDAP_CFLAGS}],[${LDAP_CPPFLAGS}],[${LDAP_LDFLAGS}]) diff --git a/ldb/ldb.mk b/ldb/ldb.mk deleted file mode 100644 index 66cdea15c..000000000 --- a/ldb/ldb.mk +++ /dev/null @@ -1,81 +0,0 @@ -LDB_LIB = -Llib -lldb - -LIB_FLAGS=$(LDFLAGS) $(LIBS) $(LDB_LIB) $(POPT_LIBS) $(TALLOC_LIBS) \ - $(TDB_LIBS) $(EVENTS_LIBS) $(LDAP_LIBS) $(LIBDL) - -LDB_TDB_DIR=ldb_tdb -LDB_TDB_OBJ=$(LDB_TDB_DIR)/ldb_tdb.o \ - $(LDB_TDB_DIR)/ldb_pack.o $(LDB_TDB_DIR)/ldb_search.o $(LDB_TDB_DIR)/ldb_index.o \ - $(LDB_TDB_DIR)/ldb_cache.o $(LDB_TDB_DIR)/ldb_tdb_wrap.o - -LDB_MAP_DIR=ldb_map -LDB_MAP_OBJ=$(LDB_MAP_DIR)/ldb_map.o $(LDB_MAP_DIR)/ldb_map_inbound.o \ - $(LDB_MAP_DIR)/ldb_map_outbound.o - -COMDIR=common -COMMON_OBJ=$(COMDIR)/ldb.o $(COMDIR)/ldb_ldif.o \ - $(COMDIR)/ldb_parse.o $(COMDIR)/ldb_msg.o $(COMDIR)/ldb_utf8.o \ - $(COMDIR)/ldb_debug.o $(COMDIR)/ldb_modules.o \ - $(COMDIR)/ldb_dn.o $(COMDIR)/ldb_match.o $(COMDIR)/ldb_attributes.o \ - $(COMDIR)/attrib_handlers.o $(COMDIR)/ldb_controls.o $(COMDIR)/qsort.o - -MODDIR=modules -MODULES_OBJ=$(MODDIR)/operational.o $(MODDIR)/rdn_name.o \ - $(MODDIR)/paged_results.o $(MODDIR)/sort.o $(MODDIR)/asq.o - -NSSDIR=nssldb -NSS_OBJ= $(NSSDIR)/ldb-nss.o $(NSSDIR)/ldb-pwd.o $(NSSDIR)/ldb-grp.o -NSS_LIB = lib/libnss_ldb.$(SHLIBEXT).2 - -lib/libldb.a: $(OBJS) - ar -rv $@ $(OBJS) - @-ranlib $@ - -sample.$(SHLIBEXT): tests/sample_module.o - $(MDLD) $(MDLD_FLAGS) -o $@ tests/sample_module.o - -bin/ldbadd: tools/ldbadd.o tools/cmdline.o - $(CC) -o bin/ldbadd tools/ldbadd.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) - -bin/ldbsearch: tools/ldbsearch.o tools/cmdline.o - $(CC) -o bin/ldbsearch tools/ldbsearch.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) - -bin/ldbdel: tools/ldbdel.o tools/cmdline.o - $(CC) -o bin/ldbdel tools/ldbdel.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) - -bin/ldbmodify: tools/ldbmodify.o tools/cmdline.o - $(CC) -o bin/ldbmodify tools/ldbmodify.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) - -bin/ldbedit: tools/ldbedit.o tools/cmdline.o - $(CC) -o bin/ldbedit tools/ldbedit.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) - -bin/ldbrename: tools/ldbrename.o tools/cmdline.o - $(CC) -o bin/ldbrename tools/ldbrename.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) - -bin/ldbtest: tools/ldbtest.o tools/cmdline.o - $(CC) -o bin/ldbtest tools/ldbtest.o tools/cmdline.o $(LIB_FLAGS) $(LD_EXPORT_DYNAMIC) - -examples/ldbreader: examples/ldbreader.o - $(CC) -o examples/ldbreader examples/ldbreader.o $(LIB_FLAGS) - -examples/ldifreader: examples/ldifreader.o - $(CC) -o examples/ldifreader examples/ldifreader.o $(LIB_FLAGS) - -# Python bindings -build-python:: ldb.$(SHLIBEXT) - -pyldb.o: $(ldbdir)/pyldb.c - $(CC) $(PICFLAG) -c $(ldbdir)/pyldb.c $(CFLAGS) `$(PYTHON_CONFIG) --cflags` - -ldb.$(SHLIBEXT): pyldb.o - $(SHLD) $(SHLD_FLAGS) -o ldb.$(SHLIBEXT) pyldb.o $(LIB_FLAGS) `$(PYTHON_CONFIG) --ldflags` - -install-python:: build-python - mkdir -p $(DESTDIR)`$(PYTHON) -c "import distutils.sysconfig; print distutils.sysconfig.get_python_lib(1, prefix='$(prefix)')"` - cp ldb.$(SHLIBEXT) $(DESTDIR)`$(PYTHON) -c "import distutils.sysconfig; print distutils.sysconfig.get_python_lib(1, prefix='$(prefix)')"` - -check-python:: build-python - LD_LIBRARY_PATH=lib PYTHONPATH=.:$(ldbdir) $(PYTHON) $(ldbdir)/tests/python/api.py - -clean:: - rm -f ldb.$(SHLIBEXT) diff --git a/ldb/ldb.pc.in b/ldb/ldb.pc.in deleted file mode 100644 index b7e4c8584..000000000 --- a/ldb/ldb.pc.in +++ /dev/null @@ -1,16 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ -modulesdir=@modulesdir@ - -Name: ldb -Description: An LDAP-like embedded database -Version: @PACKAGE_VERSION@ -Requires.private: tdb -Requires: talloc -Libs: -L${libdir} -lldb -Libs.private: @LDAP_LIBS@ -Cflags: -I${includedir} -Modulesdir: ${modulesdir} -URL: http://ldb.samba.org/ diff --git a/ldb/ldb_ildap/config.mk b/ldb/ldb_ildap/config.mk deleted file mode 100644 index 6a1ef8164..000000000 --- a/ldb/ldb_ildap/config.mk +++ /dev/null @@ -1,13 +0,0 @@ -################################################ -# Start MODULE ldb_ildap -[MODULE::ldb_ildap] -SUBSYSTEM = LIBLDB -CFLAGS = -I$(ldbsrcdir)/include -PRIVATE_DEPENDENCIES = LIBTALLOC LIBCLI_LDAP CREDENTIALS -INIT_FUNCTION = LDB_BACKEND(ldapi),LDB_BACKEND(ldaps),LDB_BACKEND(ldap) -ALIASES = ldapi ldaps ldap -# End MODULE ldb_ildap -################################################ - -ldb_ildap_OBJ_FILES = $(ldbsrcdir)/ldb_ildap/ldb_ildap.o - diff --git a/ldb/ldb_ildap/ldb_ildap.c b/ldb/ldb_ildap/ldb_ildap.c deleted file mode 100644 index b17d063c0..000000000 --- a/ldb/ldb_ildap/ldb_ildap.c +++ /dev/null @@ -1,835 +0,0 @@ -/* - ldb database library - ildap backend - - Copyright (C) Andrew Tridgell 2005 - Copyright (C) Simo Sorce 2008 - - ** 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -/* - * Name: ldb_ildap - * - * Component: ldb ildap backend - * - * Description: This is a ldb backend for the internal ldap - * client library in Samba4. By using this backend we are - * independent of a system ldap library - * - * Author: Andrew Tridgell - * - * Modifications: - * - * - description: make the module use asyncronous calls - * date: Feb 2006 - * author: Simo Sorce - */ - - -#include "includes.h" -#include "ldb_includes.h" - -#include "lib/events/events.h" -#include "libcli/ldap/ldap.h" -#include "libcli/ldap/ldap_client.h" -#include "auth/auth.h" -#include "auth/credentials/credentials.h" - -struct ildb_private { - struct ldap_connection *ldap; - struct event_context *event_ctx; -}; - -struct ildb_context { - struct ldb_module *module; - struct ldb_request *req; - - struct ildb_private *ildb; - struct ldap_request *ireq; - - bool done; - - struct ildb_destructor_ctx *dc; -}; - -static void ildb_request_done(struct ildb_context *ctx, - struct ldb_control **ctrls, int error) -{ - struct ldb_reply *ares; - - ctx->done = true; - - if (ctx->req == NULL) { - /* if the req has been freed already just return */ - return; - } - - ares = talloc_zero(ctx->req, struct ldb_reply); - if (!ares) { - ldb_oom(ctx->req->handle->ldb); - ctx->req->callback(ctx->req, NULL); - return; - } - ares->type = LDB_REPLY_DONE; - ares->controls = talloc_steal(ares, ctrls); - ares->error = error; - - ctx->req->callback(ctx->req, ares); -} - -static void ildb_auto_done_callback(struct event_context *ev, - struct timed_event *te, - struct timeval t, - void *private_data) -{ - struct ildb_context *ac; - - ac = talloc_get_type(private_data, struct ildb_context); - ildb_request_done(ac, NULL, LDB_SUCCESS); -} - -/* - convert a ldb_message structure to a list of ldap_mod structures - ready for ildap_add() or ildap_modify() -*/ -static struct ldap_mod **ildb_msg_to_mods(void *mem_ctx, int *num_mods, - const struct ldb_message *msg, - int use_flags) -{ - struct ldap_mod **mods; - unsigned int i; - int n = 0; - - /* allocate maximum number of elements needed */ - mods = talloc_array(mem_ctx, struct ldap_mod *, msg->num_elements+1); - if (!mods) { - errno = ENOMEM; - return NULL; - } - mods[0] = NULL; - - for (i = 0; i < msg->num_elements; i++) { - const struct ldb_message_element *el = &msg->elements[i]; - - mods[n] = talloc(mods, struct ldap_mod); - if (!mods[n]) { - goto failed; - } - mods[n + 1] = NULL; - mods[n]->type = 0; - mods[n]->attrib = *el; - if (use_flags) { - switch (el->flags & LDB_FLAG_MOD_MASK) { - case LDB_FLAG_MOD_ADD: - mods[n]->type = LDAP_MODIFY_ADD; - break; - case LDB_FLAG_MOD_DELETE: - mods[n]->type = LDAP_MODIFY_DELETE; - break; - case LDB_FLAG_MOD_REPLACE: - mods[n]->type = LDAP_MODIFY_REPLACE; - break; - } - } - n++; - } - - *num_mods = n; - return mods; - -failed: - talloc_free(mods); - return NULL; -} - - -/* - map an ildap NTSTATUS to a ldb error code -*/ -static int ildb_map_error(struct ldb_module *module, NTSTATUS status) -{ - struct ildb_private *ildb = talloc_get_type(module->private_data, struct ildb_private); - - TALLOC_CTX *mem_ctx = talloc_new(ildb); - if (NT_STATUS_IS_OK(status)) { - return LDB_SUCCESS; - } - if (!mem_ctx) { - ldb_oom(module->ldb); - return LDB_ERR_OPERATIONS_ERROR; - } - ldb_set_errstring(module->ldb, - ldap_errstr(ildb->ldap, mem_ctx, status)); - talloc_free(mem_ctx); - if (NT_STATUS_IS_LDAP(status)) { - return NT_STATUS_LDAP_CODE(status); - } - return LDB_ERR_OPERATIONS_ERROR; -} - -static void ildb_request_timeout(struct event_context *ev, struct timed_event *te, - struct timeval t, void *private_data) -{ - struct ildb_context *ac = talloc_get_type(private_data, struct ildb_context); - - if (ac->ireq->state == LDAP_REQUEST_PENDING) { - DLIST_REMOVE(ac->ireq->conn->pending, ac->ireq); - } - - ildb_request_done(ac, NULL, LDB_ERR_TIME_LIMIT_EXCEEDED); -} - -static void ildb_callback(struct ldap_request *req) -{ - struct ildb_context *ac; - NTSTATUS status; - struct ldap_SearchResEntry *search; - struct ldap_message *msg; - struct ldb_control **controls; - struct ldb_message *ldbmsg; - char *referral; - bool callback_failed; - bool request_done; - int ret; - int i; - - ac = talloc_get_type(req->async.private_data, struct ildb_context); - callback_failed = false; - request_done = false; - controls = NULL; - - if (!NT_STATUS_IS_OK(req->status)) { - ret = ildb_map_error(ac->module, req->status); - ildb_request_done(ac, NULL, ret); - return; - } - - if (req->num_replies < 1) { - ret = LDB_ERR_OPERATIONS_ERROR; - ildb_request_done(ac, NULL, ret); - return; - } - - switch (req->type) { - - case LDAP_TAG_ModifyRequest: - if (req->replies[0]->type != LDAP_TAG_ModifyResponse) { - ret = LDB_ERR_PROTOCOL_ERROR; - break; - } - status = ldap_check_response(ac->ireq->conn, &req->replies[0]->r.GeneralResult); - ret = ildb_map_error(ac->module, status); - request_done = true; - break; - - case LDAP_TAG_AddRequest: - if (req->replies[0]->type != LDAP_TAG_AddResponse) { - ret = LDB_ERR_PROTOCOL_ERROR; - return; - } - status = ldap_check_response(ac->ireq->conn, &req->replies[0]->r.GeneralResult); - ret = ildb_map_error(ac->module, status); - request_done = true; - break; - - case LDAP_TAG_DelRequest: - if (req->replies[0]->type != LDAP_TAG_DelResponse) { - ret = LDB_ERR_PROTOCOL_ERROR; - return; - } - status = ldap_check_response(ac->ireq->conn, &req->replies[0]->r.GeneralResult); - ret = ildb_map_error(ac->module, status); - request_done = true; - break; - - case LDAP_TAG_ModifyDNRequest: - if (req->replies[0]->type != LDAP_TAG_ModifyDNResponse) { - ret = LDB_ERR_PROTOCOL_ERROR; - return; - } - status = ldap_check_response(ac->ireq->conn, &req->replies[0]->r.GeneralResult); - ret = ildb_map_error(ac->module, status); - request_done = true; - break; - - case LDAP_TAG_SearchRequest: - /* loop over all messages */ - for (i = 0; i < req->num_replies; i++) { - - msg = req->replies[i]; - switch (msg->type) { - - case LDAP_TAG_SearchResultDone: - - status = ldap_check_response(ac->ireq->conn, &msg->r.GeneralResult); - if (!NT_STATUS_IS_OK(status)) { - ret = ildb_map_error(ac->module, status); - break; - } - - controls = talloc_steal(ac, msg->controls); - if (msg->r.SearchResultDone.resultcode) { - if (msg->r.SearchResultDone.errormessage) { - ldb_set_errstring(ac->module->ldb, msg->r.SearchResultDone.errormessage); - } - } - - ret = msg->r.SearchResultDone.resultcode; - request_done = true; - break; - - case LDAP_TAG_SearchResultEntry: - - ldbmsg = ldb_msg_new(ac); - if (!ldbmsg) { - ret = LDB_ERR_OPERATIONS_ERROR; - break; - } - - search = &(msg->r.SearchResultEntry); - - ldbmsg->dn = ldb_dn_new(ldbmsg, ac->module->ldb, search->dn); - if ( ! ldb_dn_validate(ldbmsg->dn)) { - ret = LDB_ERR_OPERATIONS_ERROR; - break; - } - ldbmsg->num_elements = search->num_attributes; - ldbmsg->elements = talloc_move(ldbmsg, &search->attributes); - - controls = talloc_steal(ac, msg->controls); - - ret = ldb_module_send_entry(ac->req, ldbmsg, controls); - if (ret != LDB_SUCCESS) { - callback_failed = true; - } - break; - - case LDAP_TAG_SearchResultReference: - - referral = talloc_strdup(ac, msg->r.SearchResultReference.referral); - - ret = ldb_module_send_referral(ac->req, referral); - if (ret != LDB_SUCCESS) { - callback_failed = true; - } - break; - - default: - /* TAG not handled, fail ! */ - ret = LDB_ERR_PROTOCOL_ERROR; - break; - } - - if (ret != LDB_SUCCESS) { - break; - } - } - - talloc_free(req->replies); - req->replies = NULL; - req->num_replies = 0; - - break; - - default: - ret = LDB_ERR_PROTOCOL_ERROR; - break; - } - - if (ret != LDB_SUCCESS) { - - /* if the callback failed the caller will have freed the - * request. Just return and don't try to use it */ - if ( ! callback_failed) { - request_done = true; - } - } - - if (request_done) { - ildb_request_done(ac, controls, ret); - } - return; -} - -static int ildb_request_send(struct ildb_context *ac, struct ldap_message *msg) -{ - struct ldap_request *req; - - if (!ac) { - return LDB_ERR_OPERATIONS_ERROR; - } - - req = ldap_request_send(ac->ildb->ldap, msg); - if (req == NULL) { - ldb_set_errstring(ac->module->ldb, "async send request failed"); - return LDB_ERR_OPERATIONS_ERROR; - } - ac->ireq = talloc_steal(ac, req); - - if (!ac->ireq->conn) { - ldb_set_errstring(ac->module->ldb, "connection to remote LDAP server dropped?"); - return LDB_ERR_OPERATIONS_ERROR; - } - - talloc_free(req->time_event); - req->time_event = NULL; - if (ac->req->timeout) { - req->time_event = event_add_timed(ac->ildb->event_ctx, ac, - timeval_current_ofs(ac->req->timeout, 0), - ildb_request_timeout, ac); - } - - req->async.fn = ildb_callback; - req->async.private_data = ac; - - return LDB_SUCCESS; -} - -/* - search for matching records using an asynchronous function - */ -static int ildb_search(struct ildb_context *ac) -{ - struct ldb_request *req = ac->req; - struct ldap_message *msg; - int n; - - if (!req->callback || !req->context) { - ldb_set_errstring(ac->module->ldb, "Async interface called with NULL callback function or NULL context"); - return LDB_ERR_OPERATIONS_ERROR; - } - - if (req->op.search.tree == NULL) { - ldb_set_errstring(ac->module->ldb, "Invalid expression parse tree"); - return LDB_ERR_OPERATIONS_ERROR; - } - - msg = new_ldap_message(req); - if (msg == NULL) { - ldb_set_errstring(ac->module->ldb, "Out of Memory"); - return LDB_ERR_OPERATIONS_ERROR; - } - - msg->type = LDAP_TAG_SearchRequest; - - if (req->op.search.base == NULL) { - msg->r.SearchRequest.basedn = talloc_strdup(msg, ""); - } else { - msg->r.SearchRequest.basedn = ldb_dn_get_extended_linearized(msg, req->op.search.base, 0); - } - if (msg->r.SearchRequest.basedn == NULL) { - ldb_set_errstring(ac->module->ldb, "Unable to determine baseDN"); - talloc_free(msg); - return LDB_ERR_OPERATIONS_ERROR; - } - - if (req->op.search.scope == LDB_SCOPE_DEFAULT) { - msg->r.SearchRequest.scope = LDB_SCOPE_SUBTREE; - } else { - msg->r.SearchRequest.scope = req->op.search.scope; - } - - msg->r.SearchRequest.deref = LDAP_DEREFERENCE_NEVER; - msg->r.SearchRequest.timelimit = 0; - msg->r.SearchRequest.sizelimit = 0; - msg->r.SearchRequest.attributesonly = 0; - msg->r.SearchRequest.tree = discard_const(req->op.search.tree); - - for (n = 0; req->op.search.attrs && req->op.search.attrs[n]; n++) /* noop */ ; - msg->r.SearchRequest.num_attributes = n; - msg->r.SearchRequest.attributes = discard_const(req->op.search.attrs); - msg->controls = req->controls; - - return ildb_request_send(ac, msg); -} - -/* - add a record -*/ -static int ildb_add(struct ildb_context *ac) -{ - struct ldb_request *req = ac->req; - struct ldap_message *msg; - struct ldap_mod **mods; - int i,n; - - msg = new_ldap_message(req); - if (msg == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - - msg->type = LDAP_TAG_AddRequest; - - msg->r.AddRequest.dn = ldb_dn_get_extended_linearized(msg, req->op.add.message->dn, 0); - if (msg->r.AddRequest.dn == NULL) { - talloc_free(msg); - return LDB_ERR_INVALID_DN_SYNTAX; - } - - mods = ildb_msg_to_mods(msg, &n, req->op.add.message, 0); - if (mods == NULL) { - talloc_free(msg); - return LDB_ERR_OPERATIONS_ERROR; - } - - msg->r.AddRequest.num_attributes = n; - msg->r.AddRequest.attributes = talloc_array(msg, struct ldb_message_element, n); - if (msg->r.AddRequest.attributes == NULL) { - talloc_free(msg); - return LDB_ERR_OPERATIONS_ERROR; - } - - for (i = 0; i < n; i++) { - msg->r.AddRequest.attributes[i] = mods[i]->attrib; - } - - return ildb_request_send(ac, msg); -} - -/* - modify a record -*/ -static int ildb_modify(struct ildb_context *ac) -{ - struct ldb_request *req = ac->req; - struct ldap_message *msg; - struct ldap_mod **mods; - int i,n; - - msg = new_ldap_message(req); - if (msg == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - - msg->type = LDAP_TAG_ModifyRequest; - - msg->r.ModifyRequest.dn = ldb_dn_get_extended_linearized(msg, req->op.mod.message->dn, 0); - if (msg->r.ModifyRequest.dn == NULL) { - talloc_free(msg); - return LDB_ERR_INVALID_DN_SYNTAX; - } - - mods = ildb_msg_to_mods(msg, &n, req->op.mod.message, 1); - if (mods == NULL) { - talloc_free(msg); - return LDB_ERR_OPERATIONS_ERROR; - } - - msg->r.ModifyRequest.num_mods = n; - msg->r.ModifyRequest.mods = talloc_array(msg, struct ldap_mod, n); - if (msg->r.ModifyRequest.mods == NULL) { - talloc_free(msg); - return LDB_ERR_OPERATIONS_ERROR; - } - - for (i = 0; i < n; i++) { - msg->r.ModifyRequest.mods[i] = *mods[i]; - } - - return ildb_request_send(ac, msg); -} - -/* - delete a record -*/ -static int ildb_delete(struct ildb_context *ac) -{ - struct ldb_request *req = ac->req; - struct ldap_message *msg; - - msg = new_ldap_message(req); - if (msg == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - - msg->type = LDAP_TAG_DelRequest; - - msg->r.DelRequest.dn = ldb_dn_get_extended_linearized(msg, req->op.del.dn, 0); - if (msg->r.DelRequest.dn == NULL) { - talloc_free(msg); - return LDB_ERR_INVALID_DN_SYNTAX; - } - - return ildb_request_send(ac, msg); -} - -/* - rename a record -*/ -static int ildb_rename(struct ildb_context *ac) -{ - struct ldb_request *req = ac->req; - struct ldap_message *msg; - - msg = new_ldap_message(req); - if (msg == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - - msg->type = LDAP_TAG_ModifyDNRequest; - msg->r.ModifyDNRequest.dn = ldb_dn_get_extended_linearized(msg, req->op.rename.olddn, 0); - if (msg->r.ModifyDNRequest.dn == NULL) { - talloc_free(msg); - return LDB_ERR_INVALID_DN_SYNTAX; - } - - msg->r.ModifyDNRequest.newrdn = - talloc_asprintf(msg, "%s=%s", - ldb_dn_get_rdn_name(req->op.rename.newdn), - ldb_dn_escape_value(msg, *ldb_dn_get_rdn_val(req->op.rename.newdn))); - if (msg->r.ModifyDNRequest.newrdn == NULL) { - talloc_free(msg); - return LDB_ERR_OPERATIONS_ERROR; - } - - msg->r.ModifyDNRequest.newsuperior = - ldb_dn_alloc_linearized(msg, ldb_dn_get_parent(msg, req->op.rename.newdn)); - if (msg->r.ModifyDNRequest.newsuperior == NULL) { - talloc_free(msg); - return LDB_ERR_INVALID_DN_SYNTAX; - } - - msg->r.ModifyDNRequest.deleteolddn = true; - - return ildb_request_send(ac, msg); -} - -static int ildb_start_trans(struct ldb_module *module) -{ - /* TODO implement a local locking mechanism here */ - - return LDB_SUCCESS; -} - -static int ildb_end_trans(struct ldb_module *module) -{ - /* TODO implement a local transaction mechanism here */ - - return LDB_SUCCESS; -} - -static int ildb_del_trans(struct ldb_module *module) -{ - /* TODO implement a local locking mechanism here */ - - return LDB_SUCCESS; -} - -static bool ildb_dn_is_special(struct ldb_request *req) -{ - struct ldb_dn *dn = NULL; - - switch (req->operation) { - case LDB_ADD: - dn = req->op.add.message->dn; - break; - case LDB_MODIFY: - dn = req->op.mod.message->dn; - break; - case LDB_DELETE: - dn = req->op.del.dn; - break; - case LDB_RENAME: - dn = req->op.rename.olddn; - break; - default: - break; - } - - if (dn && ldb_dn_is_special(dn)) { - return true; - } - return false; -} - -static int ildb_handle_request(struct ldb_module *module, struct ldb_request *req) -{ - struct ildb_private *ildb; - struct ildb_context *ac; - struct timed_event *te; - int ret; - - ildb = talloc_get_type(module->private_data, struct ildb_private); - - if (req->starttime == 0 || req->timeout == 0) { - ldb_set_errstring(module->ldb, "Invalid timeout settings"); - return LDB_ERR_TIME_LIMIT_EXCEEDED; - } - - ac = talloc_zero(req, struct ildb_context); - if (ac == NULL) { - ldb_set_errstring(module->ldb, "Out of Memory"); - return LDB_ERR_OPERATIONS_ERROR; - } - - ac->module = module; - ac->req = req; - ac->ildb = ildb; - - if (ildb_dn_is_special(req)) { - - te = event_add_timed(ac->ildb->event_ctx, - ac, timeval_zero(), - ildb_auto_done_callback, ac); - if (NULL == te) { - return LDB_ERR_OPERATIONS_ERROR; - } - - return LDB_SUCCESS; - } - - switch (ac->req->operation) { - case LDB_SEARCH: - ret = ildb_search(ac); - break; - case LDB_ADD: - ret = ildb_add(ac); - break; - case LDB_MODIFY: - ret = ildb_modify(ac); - break; - case LDB_DELETE: - ret = ildb_delete(ac); - break; - case LDB_RENAME: - ret = ildb_rename(ac); - break; - default: - /* no other op supported */ - ret = LDB_ERR_OPERATIONS_ERROR; - break; - } - - return ret; -} - -static const struct ldb_module_ops ildb_ops = { - .name = "ldap", - .search = ildb_handle_request, - .add = ildb_handle_request, - .modify = ildb_handle_request, - .del = ildb_handle_request, - .rename = ildb_handle_request, -/* .request = ildb_handle_request, */ - .start_transaction = ildb_start_trans, - .end_transaction = ildb_end_trans, - .del_transaction = ildb_del_trans, -}; - -/* - connect to the database -*/ -static int ildb_connect(struct ldb_context *ldb, const char *url, - unsigned int flags, const char *options[], - struct ldb_module **_module) -{ - struct ldb_module *module; - struct ildb_private *ildb; - NTSTATUS status; - struct cli_credentials *creds; - - module = talloc(ldb, struct ldb_module); - if (!module) { - ldb_oom(ldb); - return -1; - } - talloc_set_name_const(module, "ldb_ildap backend"); - module->ldb = ldb; - module->prev = module->next = NULL; - module->ops = &ildb_ops; - - ildb = talloc(module, struct ildb_private); - if (!ildb) { - ldb_oom(ldb); - goto failed; - } - module->private_data = ildb; - - ildb->event_ctx = ldb_get_event_context(ldb); - - - ildb->ldap = ldap4_new_connection(ildb, ldb_get_opaque(ldb, "loadparm"), - ildb->event_ctx); - if (!ildb->ldap) { - ldb_oom(ldb); - goto failed; - } - - if (flags & LDB_FLG_RECONNECT) { - ldap_set_reconn_params(ildb->ldap, 10); - } - - status = ldap_connect(ildb->ldap, url); - if (!NT_STATUS_IS_OK(status)) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to connect to ldap URL '%s' - %s\n", - url, ldap_errstr(ildb->ldap, module, status)); - goto failed; - } - - /* caller can optionally setup credentials using the opaque token 'credentials' */ - creds = talloc_get_type(ldb_get_opaque(ldb, "credentials"), struct cli_credentials); - if (creds == NULL) { - struct auth_session_info *session_info = talloc_get_type(ldb_get_opaque(ldb, "sessionInfo"), struct auth_session_info); - if (session_info) { - creds = session_info->credentials; - } - } - - if (creds != NULL && cli_credentials_authentication_requested(creds)) { - const char *bind_dn = cli_credentials_get_bind_dn(creds); - if (bind_dn) { - const char *password = cli_credentials_get_password(creds); - status = ldap_bind_simple(ildb->ldap, bind_dn, password); - if (!NT_STATUS_IS_OK(status)) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n", - ldap_errstr(ildb->ldap, module, status)); - goto failed; - } - } else { - status = ldap_bind_sasl(ildb->ldap, creds, ldb_get_opaque(ldb, "loadparm")); - if (!NT_STATUS_IS_OK(status)) { - ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n", - ldap_errstr(ildb->ldap, module, status)); - goto failed; - } - } - } - - *_module = module; - return 0; - -failed: - talloc_free(module); - return -1; -} - -_PUBLIC_ const struct ldb_backend_ops ldb_ldap_backend_ops = { - .name = "ldap", - .connect_fn = ildb_connect -}; - -_PUBLIC_ const struct ldb_backend_ops ldb_ldapi_backend_ops = { - .name = "ldapi", - .connect_fn = ildb_connect -}; - -_PUBLIC_ const struct ldb_backend_ops ldb_ldaps_backend_ops = { - .name = "ldaps", - .connect_fn = ildb_connect -}; - diff --git a/ldb/ldb_ldap/ldb_ldap.c b/ldb/ldb_ldap/ldb_ldap.c deleted file mode 100644 index 9f8b3e9f3..000000000 --- a/ldb/ldb_ldap/ldb_ldap.c +++ /dev/null @@ -1,894 +0,0 @@ -/* - ldb database library - - Copyright (C) Andrew Tridgell 2004 - Copyright (C) Simo Sorce 2006 - - ** 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 3 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, see <http://www.gnu.org/licenses/>. -*/ - -/* - * Name: ldb_ldap - * - * Component: ldb ldap backend - * - * Description: core files for LDAP backend - * - * Author: Andrew Tridgell - * - * Modifications: - * - * - description: make the module use asyncronous calls - * date: Feb 2006 - * author: Simo Sorce - */ - -#include "ldb_includes.h" - -#define LDAP_DEPRECATED 1 -#include <ldap.h> - -struct lldb_private { - LDAP *ldap; -}; - -struct lldb_context { - struct ldb_module *module; - struct ldb_request *req; - - struct lldb_private *lldb; - - struct ldb_control **controls; - int msgid; -}; - -static int lldb_ldap_to_ldb(int err) { - /* Ldap errors and ldb errors are defined to the same values */ - return err; -} - -/* - convert a ldb_message structure to a list of LDAPMod structures - ready for ldap_add() or ldap_modify() -*/ -static LDAPMod **lldb_msg_to_mods(void *mem_ctx, const struct ldb_message *msg, int use_flags) -{ - LDAPMod **mods; - unsigned int i, j; - int num_mods = 0; - - /* allocate maximum number of elements needed */ - mods = talloc_array(mem_ctx, LDAPMod *, msg->num_elements+1); - if (!mods) { - errno = ENOMEM; - return NULL; - } - mods[0] = NULL; - - for (i=0;i<msg->num_elements;i++) { - const struct ldb_message_element *el = &msg->elements[i]; - - mods[num_mods] = talloc(mods, LDAPMod); - if (!mods[num_mods]) { - goto failed; - } - mods[num_mods+1] = NULL; - mods[num_mods]->mod_op = LDAP_MOD_BVALUES; - if (use_flags) { - switch (el->flags & LDB_FLAG_MOD_MASK) { - case LDB_FLAG_MOD_ADD: - mods[num_mods]->mod_op |= LDAP_MOD_ADD; - break; - case LDB_FLAG_MOD_DELETE: - mods[num_mods]->mod_op |= LDAP_MOD_DELETE; - break; - case LDB_FLAG_MOD_REPLACE: - mods[num_mods]->mod_op |= LDAP_MOD_REPLACE; - break; - } - } - mods[num_mods]->mod_type = discard_const_p(char, el->name); - mods[num_mods]->mod_vals.modv_bvals = talloc_array(mods[num_mods], - struct berval *, - 1+el->num_values); - if (!mods[num_mods]->mod_vals.modv_bvals) { - goto failed; - } - - for (j=0;j<el->num_values;j++) { - mods[num_mods]->mod_vals.modv_bvals[j] = talloc(mods[num_mods]->mod_vals.modv_bvals, - struct berval); - if (!mods[num_mods]->mod_vals.modv_bvals[j]) { - goto failed; - } - mods[num_mods]->mod_vals.modv_bvals[j]->bv_val = el->values[j].data; - mods[num_mods]->mod_vals.modv_bvals[j]->bv_len = el->values[j].length; - } - mods[num_mods]->mod_vals.modv_bvals[j] = NULL; - num_mods++; - } - - return mods; - -failed: - talloc_free(mods); - return NULL; -} - -/* - add a single set of ldap message values to a ldb_message -*/ -static int lldb_add_msg_attr(struct ldb_context *ldb, - struct ldb_message *msg, - const char *attr, struct berval **bval) -{ - int count, i; - struct ldb_message_element *el; - - count = ldap_count_values_len(bval); - - if (count <= 0) { - return -1; - } - - el = talloc_realloc(msg, msg->elements, struct ldb_message_element, - msg->num_elements + 1); - if (!el) { - errno = ENOMEM; - return -1; - } - - msg->elements = el; - - el = &msg->elements[msg->num_elements]; - - el->name = talloc_strdup(msg->elements, attr); - if (!el->name) { - errno = ENOMEM; - return -1; - } - el->flags = 0; - - el->num_values = 0; - el->values = talloc_array(msg->elements, struct ldb_val, count); - if (!el->values) { - errno = ENOMEM; - return -1; - } - - for (i=0;i<count;i++) { - /* we have to ensure this is null terminated so that - ldb_msg_find_attr_as_string() can work */ - el->values[i].data = talloc_size(el->values, bval[i]->bv_len+1); - if (!el->values[i].data) { - errno = ENOMEM; - return -1; - } - memcpy(el->values[i].data, bval[i]->bv_val, bval[i]->bv_len); - el->values[i].data[bval[i]->bv_len] = 0; - el->values[i].length = bval[i]->bv_len; - el->num_values++; - } - - msg->num_elements++; - - return 0; -} - -/* - search for matching records -*/ -static int lldb_search(struct lldb_context *lldb_ac) -{ - struct lldb_private *lldb = lldb_ac->lldb; - struct ldb_module *module = lldb_ac->module; - struct ldb_request *req = lldb_ac->req; - struct timeval tv; - int ldap_scope; - char *search_base; - char *expression; - int ret; - - if (!req->callback || !req->context) { - ldb_set_errstring(module->ldb, "Async interface called with NULL callback function or NULL context"); - return LDB_ERR_OPERATIONS_ERROR; - } - - if (req->op.search.tree == NULL) { - ldb_set_errstring(module->ldb, "Invalid expression parse tree"); - return LDB_ERR_OPERATIONS_ERROR; - } - - if (req->controls != NULL) { - ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Controls are not yet supported by ldb_ldap backend!\n"); - } - - req->handle->state = LDB_ASYNC_PENDING; - - search_base = ldb_dn_alloc_linearized(lldb_ac, req->op.search.base); - if (req->op.search.base == NULL) { - search_base = talloc_strdup(lldb_ac, ""); - } - if (search_base == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - - expression = ldb_filter_from_tree(lldb_ac, req->op.search.tree); - if (expression == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - - switch (req->op.search.scope) { - case LDB_SCOPE_BASE: - ldap_scope = LDAP_SCOPE_BASE; - break; - case LDB_SCOPE_ONELEVEL: - ldap_scope = LDAP_SCOPE_ONELEVEL; - break; - default: - ldap_scope = LDAP_SCOPE_SUBTREE; - break; - } - - tv.tv_sec = req->timeout; - tv.tv_usec = 0; - - ret = ldap_search_ext(lldb->ldap, search_base, ldap_scope, - expression, - discard_const_p(char *, req->op.search.attrs), - 0, - NULL, - NULL, - &tv, - LDAP_NO_LIMIT, - &lldb_ac->msgid); - - if (ret != LDAP_SUCCESS) { - ldb_set_errstring(module->ldb, ldap_err2string(ret)); - } - - return lldb_ldap_to_ldb(ret); -} - -/* - add a record -*/ -static int lldb_add(struct lldb_context *lldb_ac) -{ - struct lldb_private *lldb = lldb_ac->lldb; - struct ldb_module *module = lldb_ac->module; - struct ldb_request *req = lldb_ac->req; - LDAPMod **mods; - char *dn; - int ret; - - req->handle->state = LDB_ASYNC_PENDING; - - mods = lldb_msg_to_mods(lldb_ac, req->op.add.message, 0); - if (mods == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - - dn = ldb_dn_alloc_linearized(lldb_ac, req->op.add.message->dn); - if (dn == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - - ret = ldap_add_ext(lldb->ldap, dn, mods, - NULL, - NULL, - &lldb_ac->msgid); - - if (ret != LDAP_SUCCESS) { - ldb_set_errstring(module->ldb, ldap_err2string(ret)); - } - - return lldb_ldap_to_ldb(ret); -} - -/* - modify a record -*/ -static int lldb_modify(struct lldb_context *lldb_ac) -{ - struct lldb_private *lldb = lldb_ac->lldb; - struct ldb_module *module = lldb_ac->module; - struct ldb_request *req = lldb_ac->req; - LDAPMod **mods; - char *dn; - int ret; - - req->handle->state = LDB_ASYNC_PENDING; - - mods = lldb_msg_to_mods(lldb_ac, req->op.mod.message, 1); - if (mods == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - - dn = ldb_dn_alloc_linearized(lldb_ac, req->op.mod.message->dn); - if (dn == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - - ret = ldap_modify_ext(lldb->ldap, dn, mods, - NULL, - NULL, - &lldb_ac->msgid); - - if (ret != LDAP_SUCCESS) { - ldb_set_errstring(module->ldb, ldap_err2string(ret)); - } - - return lldb_ldap_to_ldb(ret); -} - -/* - delete a record -*/ -static int lldb_delete(struct lldb_context *lldb_ac) -{ - struct lldb_private *lldb = lldb_ac->lldb; - struct ldb_module *module = lldb_ac->module; - struct ldb_request *req = lldb_ac->req; - char *dnstr; - int ret; - - req->handle->state = LDB_ASYNC_PENDING; - - dnstr = ldb_dn_alloc_linearized(lldb_ac, req->op.del.dn); - - ret = ldap_delete_ext(lldb->ldap, dnstr, - NULL, - NULL, - &lldb_ac->msgid); - - if (ret != LDAP_SUCCESS) { - ldb_set_errstring(module->ldb, ldap_err2string(ret)); - } - - return lldb_ldap_to_ldb(ret); -} - -/* - rename a record -*/ -static int lldb_rename(struct lldb_context *lldb_ac) -{ - struct lldb_private *lldb = lldb_ac->lldb; - struct ldb_module *module = lldb_ac->module; - struct ldb_request *req = lldb_ac->req; - char *old_dn; - char *newrdn; - char *parentdn; - int ret; - - req->handle->state = LDB_ASYNC_PENDING; - - old_dn = ldb_dn_alloc_linearized(lldb_ac, req->op.rename.olddn); - if (old_dn == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - - newrdn = talloc_asprintf(lldb_ac, "%s=%s", - ldb_dn_get_rdn_name(req->op.rename.newdn), - ldb_dn_escape_value(lldb, *(ldb_dn_get_rdn_val(req->op.rename.newdn)))); - if (!newrdn) { - return LDB_ERR_OPERATIONS_ERROR; - } - - parentdn = ldb_dn_alloc_linearized(lldb_ac, ldb_dn_get_parent(lldb_ac, req->op.rename.newdn)); - if (!parentdn) { - return LDB_ERR_OPERATIONS_ERROR; - } - - ret = ldap_rename(lldb->ldap, old_dn, newrdn, parentdn, - 1, NULL, NULL, - &lldb_ac->msgid); - - if (ret != LDAP_SUCCESS) { - ldb_set_errstring(module->ldb, ldap_err2string(ret)); - } - - return lldb_ldap_to_ldb(ret); -} - -static int lldb_start_trans(struct ldb_module *module) -{ - /* TODO implement a local transaction mechanism here */ - - return LDB_SUCCESS; -} - -static int lldb_end_trans(struct ldb_module *module) -{ - /* TODO implement a local transaction mechanism here */ - - return LDB_SUCCESS; -} - -static int lldb_del_trans(struct ldb_module *module) -{ - /* TODO implement a local transaction mechanism here */ - - return LDB_SUCCESS; -} - -void lldb_request_done(struct ldb_request *req, - struct ldb_control **ctrls, int error) -{ - struct ldb_reply *ares; - - ares = talloc_zero(req, struct ldb_reply); - if (!ares) { - ldb_oom(req->handle->ldb); - req->callback(req, NULL); - return; - } - ares->type = LDB_REPLY_DONE; - ares->controls = talloc_steal(ares, ctrls); - ares->error = error; - - req->callback(req, ares); -} - -/* return false if the request is still in progress - * return true if the request is completed - */ -static bool lldb_parse_result(struct lldb_context *ac, LDAPMessage *result) -{ - struct lldb_private *lldb = ac->lldb; - LDAPControl **serverctrlsp = NULL; - char **referralsp = NULL; - char *matcheddnp = NULL; - char *errmsgp = NULL; - LDAPMessage *msg; - int type; - struct ldb_message *ldbmsg; - char *referral; - bool callback_failed; - bool request_done; - bool lret; - int ret; - int i; - - type = ldap_msgtype(result); - callback_failed = false; - request_done = false; - - switch (type) { - case LDAP_RES_SEARCH_ENTRY: - - msg = ldap_first_entry(lldb->ldap, result); - if (msg != NULL) { - BerElement *berptr = NULL; - char *attr, *dn; - - ldbmsg = ldb_msg_new(ac); - if (!ldbmsg) { - ret = LDB_ERR_OPERATIONS_ERROR; - break; - } - - dn = ldap_get_dn(lldb->ldap, msg); - if (!dn) { - talloc_free(ldbmsg); - ret = LDB_ERR_OPERATIONS_ERROR; - break; - } - ldbmsg->dn = ldb_dn_new(ldbmsg, ac->module->ldb, dn); - if ( ! ldb_dn_validate(ldbmsg->dn)) { - talloc_free(ldbmsg); - ret = LDB_ERR_OPERATIONS_ERROR; - break; - } - ldap_memfree(dn); - - ldbmsg->num_elements = 0; - ldbmsg->elements = NULL; - - /* loop over all attributes */ - for (attr=ldap_first_attribute(lldb->ldap, msg, &berptr); - attr; - attr=ldap_next_attribute(lldb->ldap, msg, berptr)) { - struct berval **bval; - bval = ldap_get_values_len(lldb->ldap, msg, attr); - - if (bval) { - lldb_add_msg_attr(ac->module->ldb, ldbmsg, attr, bval); - ldap_value_free_len(bval); - } - } - if (berptr) ber_free(berptr, 0); - - ret = ldb_module_send_entry(ac->req, ldbmsg, NULL /* controls not yet supported */); - if (ret != LDB_SUCCESS) { - - callback_failed = true; - } - } else { - ret = LDB_ERR_OPERATIONS_ERROR; - } - break; - - case LDAP_RES_SEARCH_REFERENCE: - - if (ldap_parse_result(lldb->ldap, result, &ret, - &matcheddnp, &errmsgp, - &referralsp, &serverctrlsp, 0) != LDAP_SUCCESS) { - ret = LDB_ERR_OPERATIONS_ERROR; - } - if (ret != LDB_SUCCESS) { - break; - } - if (referralsp == NULL) { - ret = LDB_ERR_PROTOCOL_ERROR; - break; - } - - for (i = 0; referralsp[i]; i++) { - referral = talloc_strdup(ac, referralsp[i]); - - ret = ldb_module_send_referral(ac->req, referral); - if (ret != LDB_SUCCESS) { - callback_failed = true; - break; - } - } - break; - - case LDAP_RES_SEARCH_RESULT: - case LDAP_RES_MODIFY: - case LDAP_RES_ADD: - case LDAP_RES_DELETE: - case LDAP_RES_MODDN: - - if (ldap_parse_result(lldb->ldap, result, &ret, - &matcheddnp, &errmsgp, - &referralsp, &serverctrlsp, 0) != LDAP_SUCCESS) { - ret = LDB_ERR_OPERATIONS_ERROR; - } - if (ret != LDB_SUCCESS) { - break; - } - - if (serverctrlsp != NULL) { - /* FIXME: transform the LDAPControl list into an ldb_control one */ - ac->controls = NULL; - } - - request_done = true; - break; - - default: - ret = LDB_ERR_PROTOCOL_ERROR; - break; - } - - if (ret != LDB_SUCCESS) { - - /* if the callback failed the caller will have freed the - * request. Just return and don't try to use it */ - if (callback_failed) { - - /* tell lldb_wait to remove the request from the - * queue */ - lret = true; - goto free_and_return; - } - - request_done = true; - } - - if (request_done) { - lldb_request_done(ac->req, ac->controls, ret); - lret = true; - goto free_and_return; - } - - lret = false; - -free_and_return: - - if (matcheddnp) ldap_memfree(matcheddnp); - if (errmsgp && *errmsgp) { - ldb_set_errstring(ac->module->ldb, errmsgp); - } - if (errmsgp) { - ldap_memfree(errmsgp); - } - if (referralsp) ldap_value_free(referralsp); - if (serverctrlsp) ldap_controls_free(serverctrlsp); - - ldap_msgfree(result); - - return lret; -} - -static void lldb_timeout(struct event_context *ev, - struct timed_event *te, - struct timeval t, - void *private_data) -{ - struct lldb_context *ac; - ac = talloc_get_type(private_data, struct lldb_context); - - lldb_request_done(ac->req, NULL, LDB_ERR_TIME_LIMIT_EXCEEDED); -} - -static void lldb_callback(struct event_context *ev, - struct timed_event *te, - struct timeval t, - void *private_data) -{ - struct lldb_context *ac; - struct timed_event *lte; - struct timeval tv; - LDAPMessage *result; - int lret; - - ac = talloc_get_type(private_data, struct lldb_context); - - if (!ac->msgid) { - lldb_request_done(ac->req, NULL, LDB_ERR_OPERATIONS_ERROR); - return; - } - - tv.tv_sec = 0; - tv.tv_usec = 0; - lret = ldap_result(ac->lldb->ldap, ac->msgid, 0, &tv, &result); - if (lret == 0) { - goto respin; - } - if (lret == -1) { - lldb_request_done(ac->req, NULL, LDB_ERR_OPERATIONS_ERROR); - return; - } - - if ( ! lldb_parse_result(ac, result)) { - goto respin; - } - - return; - -respin: - tv.tv_sec = 0; - tv.tv_usec = 100; - lte = event_add_timed(ev, ac, tv, lldb_callback, ac); - if (NULL == lte) { - lldb_request_done(ac->req, NULL, LDB_ERR_OPERATIONS_ERROR); - } -} - -static bool lldb_dn_is_special(struct ldb_request *req) -{ - struct ldb_dn *dn = NULL; - - switch (req->operation) { - case LDB_ADD: - dn = req->op.add.message->dn; - break; - case LDB_MODIFY: - dn = req->op.mod.message->dn; - break; - case LDB_DELETE: - dn = req->op.del.dn; - break; - case LDB_RENAME: - dn = req->op.rename.olddn; - break; - default: - break; - } - - if (dn && ldb_dn_is_special(dn)) { - return true; - } - return false; -} - -static void lldb_auto_done_callback(struct event_context *ev, - struct timed_event *te, - struct timeval t, - void *private_data) -{ - struct lldb_context *ac; - - ac = talloc_get_type(private_data, struct lldb_context); - lldb_request_done(ac->req, NULL, LDB_SUCCESS); -} - -static int lldb_handle_request(struct ldb_module *module, struct ldb_request *req) -{ - struct lldb_private *lldb; - struct lldb_context *ac; - struct event_context *ev; - struct timed_event *te; - struct timeval tv; - int ret; - - lldb = talloc_get_type(module->private_data, struct lldb_private); - - if (req->starttime == 0 || req->timeout == 0) { - ldb_set_errstring(module->ldb, "Invalid timeout settings"); - return LDB_ERR_TIME_LIMIT_EXCEEDED; - } - - ev = ldb_get_event_context(module->ldb); - if (NULL == ev) { - return LDB_ERR_OPERATIONS_ERROR; - } - - ac = talloc_zero(module->ldb, struct lldb_context); - if (ac == NULL) { - ldb_set_errstring(module->ldb, "Out of Memory"); - return LDB_ERR_OPERATIONS_ERROR; - } - - ac->module = module; - ac->req = req; - ac->lldb = lldb; - ac->msgid = 0; - - if (lldb_dn_is_special(req)) { - tv.tv_sec = 0; - tv.tv_usec = 0; - te = event_add_timed(ev, ac, tv, - lldb_auto_done_callback, ac); - if (NULL == te) { - return LDB_ERR_OPERATIONS_ERROR; - } - - return LDB_SUCCESS; - } - - switch (ac->req->operation) { - case LDB_SEARCH: - ret = lldb_search(ac); - break; - case LDB_ADD: - ret = lldb_add(ac); - break; - case LDB_MODIFY: - ret = lldb_modify(ac); - break; - case LDB_DELETE: - ret = lldb_delete(ac); - break; - case LDB_RENAME: - ret = lldb_rename(ac); - break; - default: - /* no other op supported */ - ret = LDB_ERR_OPERATIONS_ERROR; - break; - } - - if (ret != LDB_SUCCESS) { - lldb_request_done(req, NULL, ret); - return ret; - } - - tv.tv_sec = 0; - tv.tv_usec = 0; - te = event_add_timed(ev, ac, tv, lldb_callback, ac); - if (NULL == te) { - return LDB_ERR_OPERATIONS_ERROR; - } - - - tv.tv_sec = req->starttime + req->timeout; - tv.tv_usec = 0; - te = event_add_timed(ev, ac, tv, lldb_timeout, ac); - if (NULL == te) { - return LDB_ERR_OPERATIONS_ERROR; - } - - return LDB_SUCCESS; -} - -static const struct ldb_module_ops lldb_ops = { - .name = "ldap", - .search = lldb_handle_request, - .add = lldb_handle_request, - .modify = lldb_handle_request, - .del = lldb_handle_request, - .rename = lldb_handle_request, - .request = lldb_handle_request, - .start_transaction = lldb_start_trans, - .end_transaction = lldb_end_trans, - .del_transaction = lldb_del_trans, -}; - - -static int lldb_destructor(struct lldb_private *lldb) -{ - ldap_unbind(lldb->ldap); - return 0; -} - -/* - connect to the database -*/ -static int lldb_connect(struct ldb_context *ldb, - const char *url, - unsigned int flags, - const char *options[], - struct ldb_module **_module) -{ - struct ldb_module *module; - struct lldb_private *lldb; - int version = 3; - int ret; - - module = talloc(ldb, struct ldb_module); - if (module == NULL) { - ldb_oom(ldb); - talloc_free(lldb); - return -1; - } - talloc_set_name_const(module, "ldb_ldap backend"); - module->ldb = ldb; - module->prev = module->next = NULL; - module->ops = &lldb_ops; - - lldb = talloc(module, struct lldb_private); - if (!lldb) { - ldb_oom(ldb); - goto failed; - } - module->private_data = lldb; - lldb->ldap = NULL; - - ret = ldap_initialize(&lldb->ldap, url); - if (ret != LDAP_SUCCESS) { - ldb_debug(ldb, LDB_DEBUG_FATAL, "ldap_initialize failed for URL '%s' - %s\n", - url, ldap_err2string(ret)); - goto failed; - } - - talloc_set_destructor(lldb, lldb_destructor); - - ret = ldap_set_option(lldb->ldap, LDAP_OPT_PROTOCOL_VERSION, &version); - if (ret != LDAP_SUCCESS) { - ldb_debug(ldb, LDB_DEBUG_FATAL, "ldap_set_option failed - %s\n", - ldap_err2string(ret)); - goto failed; - } - - *_module = module; - return 0; - -failed: - talloc_free(module); - return -1; -} - -const struct ldb_backend_ops ldb_ldap_backend_ops = { - .name = "ldap", - .connect_fn = lldb_connect -}; - -const struct ldb_backend_ops ldb_ldapi_backend_ops = { - .name = "ldapi", - .connect_fn = lldb_connect -}; - -const struct ldb_backend_ops ldb_ldaps_backend_ops = { - .name = "ldaps", - .connect_fn = lldb_connect -}; diff --git a/ldb/ldb_map/ldb_map.c b/ldb/ldb_map/ldb_map.c deleted file mode 100644 index 72d8378a0..000000000 --- a/ldb/ldb_map/ldb_map.c +++ /dev/null @@ -1,1103 +0,0 @@ -/* - ldb database mapping module - - Copyright (C) Jelmer Vernooij 2005 - Copyright (C) Martin Kuehl <mkhl@samba.org> 2006 - Copyright (C) Simo Sorce 2008 - - ** 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 3 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, see <http://www.gnu.org/licenses/>. - -*/ - -/* - * Name: ldb - * - * Component: ldb ldb_map module - * - * Description: Map portions of data into a different format on a - * remote partition. - * - * Author: Jelmer Vernooij, Martin Kuehl - */ - -#include "ldb_includes.h" - -#include "ldb_map.h" -#include "ldb_map_private.h" - -#ifndef _PUBLIC_ -#define _PUBLIC_ -#endif - -/* Description of the provided ldb requests: - - special attribute 'isMapped' - - - search: - - if parse tree can be split - - search remote records w/ remote attrs and parse tree - - otherwise - - enumerate all remote records - - for each remote result - - map remote result to local message - - search local result - - is present - - merge local into remote result - - run callback on merged result - - otherwise - - run callback on remote result - - - add: - - split message into local and remote part - - if local message is not empty - - add isMapped to local message - - add local message - - add remote message - - - modify: - - split message into local and remote part - - if local message is not empty - - add isMapped to local message - - search for local record - - if present - - modify local record - - otherwise - - add local message - - modify remote record - - - delete: - - search for local record - - if present - - delete local record - - delete remote record - - - rename: - - search for local record - - if present - - rename local record - - modify local isMapped - - rename remote record -*/ - - - -/* Private data structures - * ======================= */ - -/* Global private data */ -/* Extract mappings from private data. */ -const struct ldb_map_context *map_get_context(struct ldb_module *module) -{ - const struct map_private *data = talloc_get_type(module->private_data, struct map_private); - return data->context; -} - -/* Create a generic request context. */ -struct map_context *map_init_context(struct ldb_module *module, - struct ldb_request *req) -{ - struct map_context *ac; - - ac = talloc_zero(req, struct map_context); - if (ac == NULL) { - ldb_set_errstring(module->ldb, "Out of Memory"); - return NULL; - } - - ac->module = module; - ac->req = req; - - return ac; -} - -/* Dealing with DNs for different partitions - * ========================================= */ - -/* Check whether any data should be stored in the local partition. */ -bool map_check_local_db(struct ldb_module *module) -{ - const struct ldb_map_context *data = map_get_context(module); - - if (!data->remote_base_dn || !data->local_base_dn) { - return false; - } - - return true; -} - -/* Copy a DN with the base DN of the local partition. */ -static struct ldb_dn *ldb_dn_rebase_local(void *mem_ctx, const struct ldb_map_context *data, struct ldb_dn *dn) -{ - struct ldb_dn *new_dn; - - new_dn = ldb_dn_copy(mem_ctx, dn); - if ( ! ldb_dn_validate(new_dn)) { - talloc_free(new_dn); - return NULL; - } - - /* may be we don't need to rebase at all */ - if ( ! data->remote_base_dn || ! data->local_base_dn) { - return new_dn; - } - - if ( ! ldb_dn_remove_base_components(new_dn, ldb_dn_get_comp_num(data->remote_base_dn))) { - talloc_free(new_dn); - return NULL; - } - - if ( ! ldb_dn_add_base(new_dn, data->local_base_dn)) { - talloc_free(new_dn); - return NULL; - } - - return new_dn; -} - -/* Copy a DN with the base DN of the remote partition. */ -static struct ldb_dn *ldb_dn_rebase_remote(void *mem_ctx, const struct ldb_map_context *data, struct ldb_dn *dn) -{ - struct ldb_dn *new_dn; - - new_dn = ldb_dn_copy(mem_ctx, dn); - if ( ! ldb_dn_validate(new_dn)) { - talloc_free(new_dn); - return NULL; - } - - /* may be we don't need to rebase at all */ - if ( ! data->remote_base_dn || ! data->local_base_dn) { - return new_dn; - } - - if ( ! ldb_dn_remove_base_components(new_dn, ldb_dn_get_comp_num(data->local_base_dn))) { - talloc_free(new_dn); - return NULL; - } - - if ( ! ldb_dn_add_base(new_dn, data->remote_base_dn)) { - talloc_free(new_dn); - return NULL; - } - - return new_dn; -} - -/* Run a request and make sure it targets the remote partition. */ -/* TODO: free old DNs and messages? */ -int ldb_next_remote_request(struct ldb_module *module, struct ldb_request *request) -{ - const struct ldb_map_context *data = map_get_context(module); - struct ldb_message *msg; - - switch (request->operation) { - case LDB_SEARCH: - if (request->op.search.base) { - request->op.search.base = ldb_dn_rebase_remote(request, data, request->op.search.base); - } else { - request->op.search.base = data->remote_base_dn; - /* TODO: adjust scope? */ - } - break; - - case LDB_ADD: - msg = ldb_msg_copy_shallow(request, request->op.add.message); - msg->dn = ldb_dn_rebase_remote(msg, data, msg->dn); - request->op.add.message = msg; - break; - - case LDB_MODIFY: - msg = ldb_msg_copy_shallow(request, request->op.mod.message); - msg->dn = ldb_dn_rebase_remote(msg, data, msg->dn); - request->op.mod.message = msg; - break; - - case LDB_DELETE: - request->op.del.dn = ldb_dn_rebase_remote(request, data, request->op.del.dn); - break; - - case LDB_RENAME: - request->op.rename.olddn = ldb_dn_rebase_remote(request, data, request->op.rename.olddn); - request->op.rename.newdn = ldb_dn_rebase_remote(request, data, request->op.rename.newdn); - break; - - default: - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " - "Invalid remote request!\n"); - return LDB_ERR_OPERATIONS_ERROR; - } - - return ldb_next_request(module, request); -} - - -/* Finding mappings for attributes and objectClasses - * ================================================= */ - -/* Find an objectClass mapping by the local name. */ -static const struct ldb_map_objectclass *map_objectclass_find_local(const struct ldb_map_context *data, const char *name) -{ - int i; - - for (i = 0; data->objectclass_maps && data->objectclass_maps[i].local_name; i++) { - if (ldb_attr_cmp(data->objectclass_maps[i].local_name, name) == 0) { - return &data->objectclass_maps[i]; - } - } - - return NULL; -} - -/* Find an objectClass mapping by the remote name. */ -static const struct ldb_map_objectclass *map_objectclass_find_remote(const struct ldb_map_context *data, const char *name) -{ - int i; - - for (i = 0; data->objectclass_maps && data->objectclass_maps[i].remote_name; i++) { - if (ldb_attr_cmp(data->objectclass_maps[i].remote_name, name) == 0) { - return &data->objectclass_maps[i]; - } - } - - return NULL; -} - -/* Find an attribute mapping by the local name. */ -const struct ldb_map_attribute *map_attr_find_local(const struct ldb_map_context *data, const char *name) -{ - int i; - - for (i = 0; data->attribute_maps[i].local_name; i++) { - if (ldb_attr_cmp(data->attribute_maps[i].local_name, name) == 0) { - return &data->attribute_maps[i]; - } - } - for (i = 0; data->attribute_maps[i].local_name; i++) { - if (ldb_attr_cmp(data->attribute_maps[i].local_name, "*") == 0) { - return &data->attribute_maps[i]; - } - } - - return NULL; -} - -/* Find an attribute mapping by the remote name. */ -const struct ldb_map_attribute *map_attr_find_remote(const struct ldb_map_context *data, const char *name) -{ - const struct ldb_map_attribute *map; - const struct ldb_map_attribute *wildcard = NULL; - int i, j; - - for (i = 0; data->attribute_maps[i].local_name; i++) { - map = &data->attribute_maps[i]; - if (ldb_attr_cmp(map->local_name, "*") == 0) { - wildcard = &data->attribute_maps[i]; - } - - switch (map->type) { - case MAP_IGNORE: - break; - - case MAP_KEEP: - if (ldb_attr_cmp(map->local_name, name) == 0) { - return map; - } - break; - - case MAP_RENAME: - case MAP_CONVERT: - if (ldb_attr_cmp(map->u.rename.remote_name, name) == 0) { - return map; - } - break; - - case MAP_GENERATE: - for (j = 0; map->u.generate.remote_names && map->u.generate.remote_names[j]; j++) { - if (ldb_attr_cmp(map->u.generate.remote_names[j], name) == 0) { - return map; - } - } - break; - } - } - - /* We didn't find it, so return the wildcard record if one was configured */ - return wildcard; -} - - -/* Mapping attributes - * ================== */ - -/* Check whether an attribute will be mapped into the remote partition. */ -bool map_attr_check_remote(const struct ldb_map_context *data, const char *attr) -{ - const struct ldb_map_attribute *map = map_attr_find_local(data, attr); - - if (map == NULL) { - return false; - } - if (map->type == MAP_IGNORE) { - return false; - } - - return true; -} - -/* Map an attribute name into the remote partition. */ -const char *map_attr_map_local(void *mem_ctx, const struct ldb_map_attribute *map, const char *attr) -{ - if (map == NULL) { - return talloc_strdup(mem_ctx, attr); - } - - switch (map->type) { - case MAP_KEEP: - return talloc_strdup(mem_ctx, attr); - - case MAP_RENAME: - case MAP_CONVERT: - return talloc_strdup(mem_ctx, map->u.rename.remote_name); - - default: - return NULL; - } -} - -/* Map an attribute name back into the local partition. */ -const char *map_attr_map_remote(void *mem_ctx, const struct ldb_map_attribute *map, const char *attr) -{ - if (map == NULL) { - return talloc_strdup(mem_ctx, attr); - } - - if (map->type == MAP_KEEP) { - return talloc_strdup(mem_ctx, attr); - } - - return talloc_strdup(mem_ctx, map->local_name); -} - - -/* Merge two lists of attributes into a single one. */ -int map_attrs_merge(struct ldb_module *module, void *mem_ctx, - const char ***attrs, const char * const *more_attrs) -{ - int i, j, k; - - for (i = 0; *attrs && (*attrs)[i]; i++) /* noop */ ; - for (j = 0; more_attrs && more_attrs[j]; j++) /* noop */ ; - - *attrs = talloc_realloc(mem_ctx, *attrs, const char *, i+j+1); - if (*attrs == NULL) { - map_oom(module); - return -1; - } - - for (k = 0; k < j; k++) { - (*attrs)[i + k] = more_attrs[k]; - } - - (*attrs)[i+k] = NULL; - - return 0; -} - -/* Mapping ldb values - * ================== */ - -/* Map an ldb value into the remote partition. */ -struct ldb_val ldb_val_map_local(struct ldb_module *module, void *mem_ctx, - const struct ldb_map_attribute *map, const struct ldb_val *val) -{ - if (map && (map->type == MAP_CONVERT) && (map->u.convert.convert_local)) { - return map->u.convert.convert_local(module, mem_ctx, val); - } - - return ldb_val_dup(mem_ctx, val); -} - -/* Map an ldb value back into the local partition. */ -struct ldb_val ldb_val_map_remote(struct ldb_module *module, void *mem_ctx, - const struct ldb_map_attribute *map, const struct ldb_val *val) -{ - if (map && (map->type == MAP_CONVERT) && (map->u.convert.convert_remote)) { - return map->u.convert.convert_remote(module, mem_ctx, val); - } - - return ldb_val_dup(mem_ctx, val); -} - - -/* Mapping DNs - * =========== */ - -/* Check whether a DN is below the local baseDN. */ -bool ldb_dn_check_local(struct ldb_module *module, struct ldb_dn *dn) -{ - const struct ldb_map_context *data = map_get_context(module); - - if (!data->local_base_dn) { - return true; - } - - return ldb_dn_compare_base(data->local_base_dn, dn) == 0; -} - -/* Map a DN into the remote partition. */ -struct ldb_dn *ldb_dn_map_local(struct ldb_module *module, void *mem_ctx, struct ldb_dn *dn) -{ - const struct ldb_map_context *data = map_get_context(module); - struct ldb_dn *newdn; - const struct ldb_map_attribute *map; - enum ldb_map_attr_type map_type; - const char *name; - struct ldb_val value; - int i, ret; - - if (dn == NULL) { - return NULL; - } - - newdn = ldb_dn_copy(mem_ctx, dn); - if (newdn == NULL) { - map_oom(module); - return NULL; - } - - /* For each RDN, map the component name and possibly the value */ - for (i = 0; i < ldb_dn_get_comp_num(newdn); i++) { - map = map_attr_find_local(data, ldb_dn_get_component_name(dn, i)); - - /* Unknown attribute - leave this RDN as is and hope the best... */ - if (map == NULL) { - map_type = MAP_KEEP; - } else { - map_type = map->type; - } - - switch (map_type) { - case MAP_IGNORE: - case MAP_GENERATE: - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " - "MAP_IGNORE/MAP_GENERATE attribute '%s' " - "used in DN!\n", ldb_dn_get_component_name(dn, i)); - goto failed; - - case MAP_CONVERT: - if (map->u.convert.convert_local == NULL) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " - "'convert_local' not set for attribute '%s' " - "used in DN!\n", ldb_dn_get_component_name(dn, i)); - goto failed; - } - /* fall through */ - case MAP_KEEP: - case MAP_RENAME: - name = map_attr_map_local(newdn, map, ldb_dn_get_component_name(dn, i)); - if (name == NULL) goto failed; - - value = ldb_val_map_local(module, newdn, map, ldb_dn_get_component_val(dn, i)); - if (value.data == NULL) goto failed; - - ret = ldb_dn_set_component(newdn, i, name, value); - if (ret != LDB_SUCCESS) { - goto failed; - } - - break; - } - } - - return newdn; - -failed: - talloc_free(newdn); - return NULL; -} - -/* Map a DN into the local partition. */ -struct ldb_dn *ldb_dn_map_remote(struct ldb_module *module, void *mem_ctx, struct ldb_dn *dn) -{ - const struct ldb_map_context *data = map_get_context(module); - struct ldb_dn *newdn; - const struct ldb_map_attribute *map; - enum ldb_map_attr_type map_type; - const char *name; - struct ldb_val value; - int i, ret; - - if (dn == NULL) { - return NULL; - } - - newdn = ldb_dn_copy(mem_ctx, dn); - if (newdn == NULL) { - map_oom(module); - return NULL; - } - - /* For each RDN, map the component name and possibly the value */ - for (i = 0; i < ldb_dn_get_comp_num(newdn); i++) { - map = map_attr_find_remote(data, ldb_dn_get_component_name(dn, i)); - - /* Unknown attribute - leave this RDN as is and hope the best... */ - if (map == NULL) { - map_type = MAP_KEEP; - } else { - map_type = map->type; - } - - switch (map_type) { - case MAP_IGNORE: - case MAP_GENERATE: - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " - "MAP_IGNORE/MAP_GENERATE attribute '%s' " - "used in DN!\n", ldb_dn_get_component_name(dn, i)); - goto failed; - - case MAP_CONVERT: - if (map->u.convert.convert_remote == NULL) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " - "'convert_remote' not set for attribute '%s' " - "used in DN!\n", ldb_dn_get_component_name(dn, i)); - goto failed; - } - /* fall through */ - case MAP_KEEP: - case MAP_RENAME: - name = map_attr_map_remote(newdn, map, ldb_dn_get_component_name(dn, i)); - if (name == NULL) goto failed; - - value = ldb_val_map_remote(module, newdn, map, ldb_dn_get_component_val(dn, i)); - if (value.data == NULL) goto failed; - - ret = ldb_dn_set_component(newdn, i, name, value); - if (ret != LDB_SUCCESS) { - goto failed; - } - - break; - } - } - - return newdn; - -failed: - talloc_free(newdn); - return NULL; -} - -/* Map a DN and its base into the local partition. */ -/* TODO: This should not be required with GUIDs. */ -struct ldb_dn *ldb_dn_map_rebase_remote(struct ldb_module *module, void *mem_ctx, struct ldb_dn *dn) -{ - const struct ldb_map_context *data = map_get_context(module); - struct ldb_dn *dn1, *dn2; - - dn1 = ldb_dn_rebase_local(mem_ctx, data, dn); - dn2 = ldb_dn_map_remote(module, mem_ctx, dn1); - - talloc_free(dn1); - return dn2; -} - - -/* Converting DNs and objectClasses (as ldb values) - * ================================================ */ - -/* Map a DN contained in an ldb value into the remote partition. */ -static struct ldb_val ldb_dn_convert_local(struct ldb_module *module, void *mem_ctx, const struct ldb_val *val) -{ - struct ldb_dn *dn, *newdn; - struct ldb_val newval; - - dn = ldb_dn_from_ldb_val(mem_ctx, module->ldb, val); - if (! ldb_dn_validate(dn)) { - newval.length = 0; - newval.data = NULL; - talloc_free(dn); - return newval; - } - newdn = ldb_dn_map_local(module, mem_ctx, dn); - talloc_free(dn); - - newval.length = 0; - newval.data = (uint8_t *)ldb_dn_alloc_linearized(mem_ctx, newdn); - if (newval.data) { - newval.length = strlen((char *)newval.data); - } - talloc_free(newdn); - - return newval; -} - -/* Map a DN contained in an ldb value into the local partition. */ -static struct ldb_val ldb_dn_convert_remote(struct ldb_module *module, void *mem_ctx, const struct ldb_val *val) -{ - struct ldb_dn *dn, *newdn; - struct ldb_val newval; - - dn = ldb_dn_from_ldb_val(mem_ctx, module->ldb, val); - if (! ldb_dn_validate(dn)) { - newval.length = 0; - newval.data = NULL; - talloc_free(dn); - return newval; - } - newdn = ldb_dn_map_remote(module, mem_ctx, dn); - talloc_free(dn); - - newval.length = 0; - newval.data = (uint8_t *)ldb_dn_alloc_linearized(mem_ctx, newdn); - if (newval.data) { - newval.length = strlen((char *)newval.data); - } - talloc_free(newdn); - - return newval; -} - -/* Map an objectClass into the remote partition. */ -static struct ldb_val map_objectclass_convert_local(struct ldb_module *module, void *mem_ctx, const struct ldb_val *val) -{ - const struct ldb_map_context *data = map_get_context(module); - const char *name = (char *)val->data; - const struct ldb_map_objectclass *map = map_objectclass_find_local(data, name); - struct ldb_val newval; - - if (map) { - newval.data = (uint8_t*)talloc_strdup(mem_ctx, map->remote_name); - newval.length = strlen((char *)newval.data); - return newval; - } - - return ldb_val_dup(mem_ctx, val); -} - -/* Generate a remote message with a mapped objectClass. */ -static void map_objectclass_generate_remote(struct ldb_module *module, const char *local_attr, const struct ldb_message *old, struct ldb_message *remote, struct ldb_message *local) -{ - const struct ldb_map_context *data = map_get_context(module); - struct ldb_message_element *el, *oc; - struct ldb_val val; - bool found_extensibleObject = false; - int i; - - /* Find old local objectClass */ - oc = ldb_msg_find_element(old, "objectClass"); - if (oc == NULL) { - return; - } - - /* Prepare new element */ - el = talloc_zero(remote, struct ldb_message_element); - if (el == NULL) { - ldb_oom(module->ldb); - return; /* TODO: fail? */ - } - - /* Copy local objectClass element, reverse space for an extra value */ - el->num_values = oc->num_values + 1; - el->values = talloc_array(el, struct ldb_val, el->num_values); - if (el->values == NULL) { - talloc_free(el); - ldb_oom(module->ldb); - return; /* TODO: fail? */ - } - - /* Copy local element name "objectClass" */ - el->name = talloc_strdup(el, local_attr); - - /* Convert all local objectClasses */ - for (i = 0; i < el->num_values - 1; i++) { - el->values[i] = map_objectclass_convert_local(module, el->values, &oc->values[i]); - if (ldb_attr_cmp((char *)el->values[i].data, data->add_objectclass) == 0) { - found_extensibleObject = true; - } - } - - if (!found_extensibleObject) { - val.data = (uint8_t *)talloc_strdup(el->values, data->add_objectclass); - val.length = strlen((char *)val.data); - - /* Append additional objectClass data->add_objectclass */ - el->values[i] = val; - } else { - el->num_values--; - } - - /* Add new objectClass to remote message */ - ldb_msg_add(remote, el, 0); -} - -/* Map an objectClass into the local partition. */ -static struct ldb_val map_objectclass_convert_remote(struct ldb_module *module, void *mem_ctx, const struct ldb_val *val) -{ - const struct ldb_map_context *data = map_get_context(module); - const char *name = (char *)val->data; - const struct ldb_map_objectclass *map = map_objectclass_find_remote(data, name); - struct ldb_val newval; - - if (map) { - newval.data = (uint8_t*)talloc_strdup(mem_ctx, map->local_name); - newval.length = strlen((char *)newval.data); - return newval; - } - - return ldb_val_dup(mem_ctx, val); -} - -/* Generate a local message with a mapped objectClass. */ -static struct ldb_message_element *map_objectclass_generate_local(struct ldb_module *module, void *mem_ctx, const char *local_attr, const struct ldb_message *remote) -{ - const struct ldb_map_context *data = map_get_context(module); - struct ldb_message_element *el, *oc; - struct ldb_val val; - int i; - - /* Find old remote objectClass */ - oc = ldb_msg_find_element(remote, "objectClass"); - if (oc == NULL) { - return NULL; - } - - /* Prepare new element */ - el = talloc_zero(mem_ctx, struct ldb_message_element); - if (el == NULL) { - ldb_oom(module->ldb); - return NULL; - } - - /* Copy remote objectClass element */ - el->num_values = oc->num_values; - el->values = talloc_array(el, struct ldb_val, el->num_values); - if (el->values == NULL) { - talloc_free(el); - ldb_oom(module->ldb); - return NULL; - } - - /* Copy remote element name "objectClass" */ - el->name = talloc_strdup(el, local_attr); - - /* Convert all remote objectClasses */ - for (i = 0; i < el->num_values; i++) { - el->values[i] = map_objectclass_convert_remote(module, el->values, &oc->values[i]); - } - - val.data = (uint8_t *)talloc_strdup(el->values, data->add_objectclass); - val.length = strlen((char *)val.data); - - /* Remove last value if it was the string in data->add_objectclass (eg samba4top, extensibleObject) */ - if (ldb_val_equal_exact(&val, &el->values[i-1])) { - el->num_values--; - el->values = talloc_realloc(el, el->values, struct ldb_val, el->num_values); - if (el->values == NULL) { - talloc_free(el); - ldb_oom(module->ldb); - return NULL; - } - } - - return el; -} - -static const struct ldb_map_attribute objectclass_convert_map = { - .local_name = "objectClass", - .type = MAP_CONVERT, - .u = { - .convert = { - .remote_name = "objectClass", - .convert_local = map_objectclass_convert_local, - .convert_remote = map_objectclass_convert_remote, - }, - }, -}; - - -/* Mappings for searches on objectClass= assuming a one-to-one - * mapping. Needed because this is a generate operator for the - * add/modify code */ -static int map_objectclass_convert_operator(struct ldb_module *module, void *mem_ctx, - struct ldb_parse_tree **new, const struct ldb_parse_tree *tree) -{ - - return map_subtree_collect_remote_simple(module, mem_ctx, new, tree, &objectclass_convert_map); -} - -/* Auxiliary request construction - * ============================== */ - -/* Build a request to search a record by its DN. */ -struct ldb_request *map_search_base_req(struct map_context *ac, struct ldb_dn *dn, const char * const *attrs, const struct ldb_parse_tree *tree, void *context, ldb_map_callback_t callback) -{ - const struct ldb_parse_tree *search_tree; - struct ldb_request *req; - int ret; - - if (tree) { - search_tree = tree; - } else { - search_tree = ldb_parse_tree(ac, NULL); - if (search_tree == NULL) { - return NULL; - } - } - - ret = ldb_build_search_req_ex(&req, ac->module->ldb, ac, - dn, LDB_SCOPE_BASE, - search_tree, attrs, - NULL, - context, callback, - ac->req); - if (ret != LDB_SUCCESS) { - return NULL; - } - - return req; -} - -/* Build a request to update the 'IS_MAPPED' attribute */ -struct ldb_request *map_build_fixup_req(struct map_context *ac, - struct ldb_dn *olddn, - struct ldb_dn *newdn, - void *context, - ldb_map_callback_t callback) -{ - struct ldb_request *req; - struct ldb_message *msg; - const char *dn; - int ret; - - /* Prepare message */ - msg = ldb_msg_new(ac); - if (msg == NULL) { - map_oom(ac->module); - return NULL; - } - - /* Update local 'IS_MAPPED' to the new remote DN */ - msg->dn = ldb_dn_copy(msg, olddn); - dn = ldb_dn_alloc_linearized(msg, newdn); - if ( ! dn || ! ldb_dn_validate(msg->dn)) { - goto failed; - } - if (ldb_msg_add_empty(msg, IS_MAPPED, LDB_FLAG_MOD_REPLACE, NULL) != 0) { - goto failed; - } - if (ldb_msg_add_string(msg, IS_MAPPED, dn) != 0) { - goto failed; - } - - /* Prepare request */ - ret = ldb_build_mod_req(&req, ac->module->ldb, - ac, msg, NULL, - context, callback, - ac->req); - if (ret != LDB_SUCCESS) { - goto failed; - } - talloc_steal(req, msg); - - return req; -failed: - talloc_free(msg); - return NULL; -} - -/* Module initialization - * ===================== */ - - -/* Builtin mappings for DNs and objectClasses */ -static const struct ldb_map_attribute builtin_attribute_maps[] = { - { - .local_name = "dn", - .type = MAP_CONVERT, - .u = { - .convert = { - .remote_name = "dn", - .convert_local = ldb_dn_convert_local, - .convert_remote = ldb_dn_convert_remote, - }, - }, - }, - { - .local_name = NULL, - } -}; - -static const struct ldb_map_attribute objectclass_attribute_map = { - .local_name = "objectClass", - .type = MAP_GENERATE, - .convert_operator = map_objectclass_convert_operator, - .u = { - .generate = { - .remote_names = { "objectClass", NULL }, - .generate_local = map_objectclass_generate_local, - .generate_remote = map_objectclass_generate_remote, - }, - }, -}; - - -/* Find the special 'MAP_DN_NAME' record and store local and remote - * base DNs in private data. */ -static int map_init_dns(struct ldb_module *module, struct ldb_map_context *data, const char *name) -{ - static const char * const attrs[] = { MAP_DN_FROM, MAP_DN_TO, NULL }; - struct ldb_dn *dn; - struct ldb_message *msg; - struct ldb_result *res; - int ret; - - if (!name) { - data->local_base_dn = NULL; - data->remote_base_dn = NULL; - return LDB_SUCCESS; - } - - dn = ldb_dn_new_fmt(data, module->ldb, "%s=%s", MAP_DN_NAME, name); - if ( ! ldb_dn_validate(dn)) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " - "Failed to construct '%s' DN!\n", MAP_DN_NAME); - return LDB_ERR_OPERATIONS_ERROR; - } - - ret = ldb_search(module->ldb, data, &res, dn, LDB_SCOPE_BASE, attrs, NULL); - talloc_free(dn); - if (ret != LDB_SUCCESS) { - return ret; - } - if (res->count == 0) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " - "No results for '%s=%s'!\n", MAP_DN_NAME, name); - talloc_free(res); - return LDB_ERR_CONSTRAINT_VIOLATION; - } - if (res->count > 1) { - ldb_debug(module->ldb, LDB_DEBUG_ERROR, "ldb_map: " - "Too many results for '%s=%s'!\n", MAP_DN_NAME, name); - talloc_free(res); - return LDB_ERR_CONSTRAINT_VIOLATION; - } - - msg = res->msgs[0]; - data->local_base_dn = ldb_msg_find_attr_as_dn(module->ldb, data, msg, MAP_DN_FROM); - data->remote_base_dn = ldb_msg_find_attr_as_dn(module->ldb, data, msg, MAP_DN_TO); - talloc_free(res); - - return LDB_SUCCESS; -} - -/* Store attribute maps and objectClass maps in private data. */ -static int map_init_maps(struct ldb_module *module, struct ldb_map_context *data, - const struct ldb_map_attribute *attrs, - const struct ldb_map_objectclass *ocls, - const char * const *wildcard_attributes) -{ - int i, j, last; - last = 0; - - /* Count specified attribute maps */ - for (i = 0; attrs[i].local_name; i++) /* noop */ ; - /* Count built-in attribute maps */ - for (j = 0; builtin_attribute_maps[j].local_name; j++) /* noop */ ; - - /* Store list of attribute maps */ - data->attribute_maps = talloc_array(data, struct ldb_map_attribute, i+j+2); - if (data->attribute_maps == NULL) { - map_oom(module); - return LDB_ERR_OPERATIONS_ERROR; - } - - /* Specified ones go first */ - for (i = 0; attrs[i].local_name; i++) { - data->attribute_maps[last] = attrs[i]; - last++; - } - - /* Built-in ones go last */ - for (i = 0; builtin_attribute_maps[i].local_name; i++) { - data->attribute_maps[last] = builtin_attribute_maps[i]; - last++; - } - - if (data->add_objectclass) { - /* ObjectClass one is very last, if required */ - data->attribute_maps[last] = objectclass_attribute_map; - last++; - } else if (ocls) { - data->attribute_maps[last] = objectclass_convert_map; - last++; - } - - /* Ensure 'local_name == NULL' for the last entry */ - memset(&data->attribute_maps[last], 0, sizeof(struct ldb_map_attribute)); - - /* Store list of objectClass maps */ - data->objectclass_maps = ocls; - - data->wildcard_attributes = wildcard_attributes; - - return LDB_SUCCESS; -} - -/* Initialize global private data. */ -_PUBLIC_ int ldb_map_init(struct ldb_module *module, const struct ldb_map_attribute *attrs, - const struct ldb_map_objectclass *ocls, - const char * const *wildcard_attributes, - const char *add_objectclass, - const char *name) -{ - struct map_private *data; - int ret; - - /* Prepare private data */ - data = talloc_zero(module, struct map_private); - if (data == NULL) { - map_oom(module); - return LDB_ERR_OPERATIONS_ERROR; - } - - module->private_data = data; - - data->context = talloc_zero(data, struct ldb_map_context); - if (!data->context) { - map_oom(module); - return LDB_ERR_OPERATIONS_ERROR; - } - - /* Store local and remote baseDNs */ - ret = map_init_dns(module, data->context, name); - if (ret != LDB_SUCCESS) { - talloc_free(data); - return ret; - } - - data->context->add_objectclass = add_objectclass; - - /* Store list of attribute and objectClass maps */ - ret = map_init_maps(module, data->context, attrs, ocls, wildcard_attributes); - if (ret != LDB_SUCCESS) { - talloc_free(data); - return ret; - } - - return LDB_SUCCESS; -} diff --git a/ldb/ldb_map/ldb_map.h b/ldb/ldb_map/ldb_map.h deleted file mode 100644 index 7f92c15b9..000000000 --- a/ldb/ldb_map/ldb_map.h +++ /dev/null @@ -1,171 +0,0 @@ -/* - ldb database mapping module - - Copyright (C) Jelmer Vernooij 2005 - Copyright (C) Martin Kuehl <mkhl@samba.org> 2006 - - ** 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 3 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, see <http://www.gnu.org/licenses/>. - -*/ - -#ifndef __LDB_MAP_H__ -#define __LDB_MAP_H__ - -/* ldb_map is a skeleton LDB module that can be used for any other modules - * that need to map attributes. - * - * The term 'remote' in this header refers to the connection where the - * original schema is used on while 'local' means the local connection - * that any upper layers will use. - * - * All local attributes will have to have a definition. Not all remote - * attributes need a definition as LDB is a lot less strict than LDAP - * (in other words, sending unknown attributes to an LDAP server hurts us, - * while returning too many attributes in ldb_search() doesn't) - */ - - -/* Name of the internal attribute pointing from the local to the - * remote part of a record */ -#define IS_MAPPED "isMapped" - - -struct ldb_map_context; - -/* convert a local ldb_val to a remote ldb_val */ -typedef struct ldb_val (*ldb_map_convert_func) (struct ldb_module *module, void *mem_ctx, const struct ldb_val *val); - -#define LDB_MAP_MAX_REMOTE_NAMES 10 - -/* map from local to remote attribute */ -struct ldb_map_attribute { - const char *local_name; /* local name */ - - enum ldb_map_attr_type { - MAP_IGNORE, /* Ignore this local attribute. Doesn't exist remotely. */ - MAP_KEEP, /* Keep as is. Same name locally and remotely. */ - MAP_RENAME, /* Simply rename the attribute. Name changes, data is the same */ - MAP_CONVERT, /* Rename + convert data */ - MAP_GENERATE /* Use generate function for generating new name/data. - Used for generating attributes based on - multiple remote attributes. */ - } type; - - /* if set, will be called for search expressions that contain this attribute */ - int (*convert_operator)(struct ldb_module *, TALLOC_CTX *ctx, struct ldb_parse_tree **new, const struct ldb_parse_tree *); - - union { - struct { - const char *remote_name; - } rename; - - struct { - const char *remote_name; - - /* Convert local to remote data */ - ldb_map_convert_func convert_local; - - /* Convert remote to local data */ - /* an entry can have convert_remote set to NULL, as long as there as an entry with the same local_name - * that is non-NULL before it. */ - ldb_map_convert_func convert_remote; - } convert; - - struct { - /* Generate the local attribute from remote message */ - struct ldb_message_element *(*generate_local)(struct ldb_module *, TALLOC_CTX *mem_ctx, const char *remote_attr, const struct ldb_message *remote); - - /* Update remote message with information from local message */ - void (*generate_remote)(struct ldb_module *, const char *local_attr, const struct ldb_message *old, struct ldb_message *remote, struct ldb_message *local); - - /* Name(s) for this attribute on the remote server. This is an array since - * one local attribute's data can be split up into several attributes - * remotely */ - const char *remote_names[LDB_MAP_MAX_REMOTE_NAMES]; - - /* Names of additional remote attributes - * required for the generation. NULL - * indicates that `local_attr' suffices. */ - /* -#define LDB_MAP_MAX_SELF_ATTRIBUTES 10 - const char *self_attrs[LDB_MAP_MAX_SELF_ATTRIBUTES]; - */ - } generate; - } u; -}; - - -#define LDB_MAP_MAX_SUBCLASSES 10 -#define LDB_MAP_MAX_MUSTS 10 -#define LDB_MAP_MAX_MAYS 50 - -/* map from local to remote objectClass */ -struct ldb_map_objectclass { - const char *local_name; - const char *remote_name; - const char *base_classes[LDB_MAP_MAX_SUBCLASSES]; - const char *musts[LDB_MAP_MAX_MUSTS]; - const char *mays[LDB_MAP_MAX_MAYS]; -}; - - -/* private context data */ -struct ldb_map_context { - struct ldb_map_attribute *attribute_maps; - /* NOTE: Always declare base classes first here */ - const struct ldb_map_objectclass *objectclass_maps; - - /* Remote (often operational) attributes that should be added - * to any wildcard search */ - const char * const *wildcard_attributes; - - /* ObjectClass (if any) to be added to remote attributes on add */ - const char *add_objectclass; - - /* struct ldb_context *mapped_ldb; */ - struct ldb_dn *local_base_dn; - struct ldb_dn *remote_base_dn; -}; - -/* Global private data */ -struct map_private { - void *caller_private; - struct ldb_map_context *context; -}; - -/* Initialize global private data. */ -int ldb_map_init(struct ldb_module *module, const struct ldb_map_attribute *attrs, - const struct ldb_map_objectclass *ocls, - const char * const *wildcard_attributes, - const char *add_objectclass, - const char *name); - -int map_add(struct ldb_module *module, struct ldb_request *req); -int map_search(struct ldb_module *module, struct ldb_request *req); -int map_rename(struct ldb_module *module, struct ldb_request *req); -int map_delete(struct ldb_module *module, struct ldb_request *req); -int map_modify(struct ldb_module *module, struct ldb_request *req); - -#define LDB_MAP_OPS \ - .add = map_add, \ - .modify = map_modify, \ - .del = map_delete, \ - .rename = map_rename, \ - .search = map_search, - -#endif /* __LDB_MAP_H__ */ diff --git a/ldb/ldb_map/ldb_map_inbound.c b/ldb/ldb_map/ldb_map_inbound.c deleted file mode 100644 index 96605f23e..000000000 --- a/ldb/ldb_map/ldb_map_inbound.c +++ /dev/null @@ -1,791 +0,0 @@ -/* - ldb database mapping module - - Copyright (C) Jelmer Vernooij 2005 - Copyright (C) Martin Kuehl <mkhl@samba.org> 2006 - Copyright (C) Simo Sorce <idra@samba.org> 2008 - |