diff options
author | Andrew Bartlett <abartlet@samba.org> | 2006-08-17 08:31:19 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:15:39 -0500 |
commit | 7de75a991bda653497a0989de93608310b55894a (patch) | |
tree | a672da526817cded9f620511ca02d92f34f3a3ad | |
parent | 9f7da6fea0bc9a330f8620d100e27d4eabbae253 (diff) | |
download | samba-7de75a991bda653497a0989de93608310b55894a.tar.gz samba-7de75a991bda653497a0989de93608310b55894a.tar.bz2 samba-7de75a991bda653497a0989de93608310b55894a.zip |
r17580: Add a new tools to convert back from AD-like schema to OpenLDAP.
Add attribute syntax mapping to the existing OpenLDAP -> AD tool.
Andrew Bartlett
(This used to be commit ba1c652bae700a82acde166e70035d61c320e233)
-rw-r--r-- | source4/lib/ldb/Makefile.in | 2 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb_msg.c | 17 | ||||
-rw-r--r-- | source4/lib/ldb/config.mk | 14 | ||||
-rw-r--r-- | source4/lib/ldb/include/ldb.h | 3 | ||||
-rw-r--r-- | source4/lib/ldb/man/ad2oLschema.1.xml | 87 | ||||
-rw-r--r-- | source4/lib/ldb/tools/convert.c | 165 | ||||
-rw-r--r-- | source4/lib/ldb/tools/convert.h | 10 | ||||
-rw-r--r-- | source4/lib/ldb/tools/oLschema2ldif.c | 50 |
8 files changed, 312 insertions, 36 deletions
diff --git a/source4/lib/ldb/Makefile.in b/source4/lib/ldb/Makefile.in index 6e5d652416..94bf4f8a1c 100644 --- a/source4/lib/ldb/Makefile.in +++ b/source4/lib/ldb/Makefile.in @@ -114,7 +114,7 @@ bin/ldbtest: tools/ldbtest.o tools/cmdline.o $(LIBS) $(CC) -o bin/ldbtest tools/ldbtest.o tools/cmdline.o $(LIB_FLAGS) bin/oLschema2ldif: tools/oLschema2ldif.o tools/cmdline.o $(LIBS) - $(CC) -o bin/oLschema2ldif tools/oLschema2ldif.o tools/cmdline.o $(LIB_FLAGS) + $(CC) -o bin/oLschema2ldif tools/oLschema2ldif.o tools/cmdline.o tools/convert.o $(LIB_FLAGS) examples/ldbreader: examples/ldbreader.o $(LIBS) $(CC) -o examples/ldbreader examples/ldbreader.o $(LIB_FLAGS) diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c index 2cbfc2467a..d40dcde010 100644 --- a/source4/lib/ldb/common/ldb_msg.c +++ b/source4/lib/ldb/common/ldb_msg.c @@ -366,6 +366,23 @@ double ldb_msg_find_attr_as_double(const struct ldb_message *msg, 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 (strcasecmp(v->data, "FALSE") == 0) { + return 0; + } + if (strcasecmp(v->data, "TRUE") == 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) diff --git a/source4/lib/ldb/config.mk b/source4/lib/ldb/config.mk index 7b6458dd63..d52ec4cf06 100644 --- a/source4/lib/ldb/config.mk +++ b/source4/lib/ldb/config.mk @@ -271,12 +271,26 @@ PRIVATE_DEPENDENCIES = \ INSTALLDIR = BINDIR MANPAGE = man/oLschema2ldif.1 OBJ_FILES= \ + tools/convert.o \ tools/oLschema2ldif.o PRIVATE_DEPENDENCIES = \ LIBLDB_CMDLINE # End BINARY oLschema2ldif ################################################ +################################################ +# Start BINARY ad2oLschema +[BINARY::ad2oLschema] +INSTALLDIR = BINDIR +MANPAGE = man/ad2oLschema.1 +OBJ_FILES= \ + tools/convert.o \ + tools/ad2oLschema.o +PRIVATE_DEPENDENCIES = \ + LIBLDB_CMDLINE +# End BINARY ad2oLschema +################################################ + ####################### # Start LIBRARY swig_ldb [LIBRARY::swig_ldb] diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h index e756a9b00b..2e659b5307 100644 --- a/source4/lib/ldb/include/ldb.h +++ b/source4/lib/ldb/include/ldb.h @@ -1265,6 +1265,9 @@ uint64_t ldb_msg_find_attr_as_uint64(const struct ldb_message *msg, 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); diff --git a/source4/lib/ldb/man/ad2oLschema.1.xml b/source4/lib/ldb/man/ad2oLschema.1.xml new file mode 100644 index 0000000000..a4e304f15f --- /dev/null +++ b/source4/lib/ldb/man/ad2oLschema.1.xml @@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="iso-8859-1"?> +<!DOCTYPE refentry PUBLIC "-//Samba-Team//DTD DocBook V4.2-Based Variant V1.0//EN" "http://www.samba.org/samba/DTD/samba-doc"> +<refentry id="ad2oLschema.1"> + +<refmeta> + <refentrytitle>ad2oLschema</refentrytitle> + <manvolnum>1</manvolnum> +</refmeta> + + +<refnamediv> + <refname>ad2oLschema</refname> + <refpurpose>Converts AC-like LDAP schemas to OpenLDAP + compatible schema files</refpurpose> +</refnamediv> + +<refsynopsisdiv> + <cmdsynopsis> + <command>ad2oLschema</command> + <arg choice="opt">-I INPUT-FILE</arg> + <arg choice="opt">-O OUTPUT-FILE</arg> + </cmdsynopsis> +</refsynopsisdiv> + +<refsect1> + <title>DESCRIPTION</title> + + <para>ad2oLschema is a simple tool that converts AD-like LDIF + schema files into OpenLDAP schema files.</para> +</refsect1> + + +<refsect1> + <title>OPTIONS</title> + + <variablelist> + <varlistentry> + <term>-H url</term> + <listitem><para>URL to an LDB or LDAP server with an AD schema to read. </para></listitem> + </varlistentry> + + <varlistentry> + <term>-I input-file</term> <listitem><para>AD schema + to read. If neither this nor -H is specified, the + schema file will be read from standard input. + </para></listitem> + </varlistentry> + + <varlistentry> + <term>-O output-file</term> + <listitem><para>File to write OpenLDAP version of schema to. + </para></listitem> + </varlistentry> + </variablelist> +</refsect1> + +<refsect1> + <title>VERSION</title> + + <para>This man page is correct for version 4.0 of the Samba suite.</para> +</refsect1> + +<refsect1> + <title>SEE ALSO</title> + + <para>ldb(7), ldbmodify, ldbdel, ldif(5)</para> + +</refsect1> + +<refsect1> + <title>AUTHOR</title> + + <para> ldb was written by + <ulink url="http://samba.org/~tridge/">Andrew Tridgell</ulink>. + ad2oLschema was written by <ulink + url="http://samba.org/~abartlet/">Andrew Bartlett</ulink>. + </para> + + <para> +If you wish to report a problem or make a suggestion then please see +the <ulink url="http://ldb.samba.org/"/> web site for +current contact and maintainer information. + </para> + +</refsect1> + +</refentry> diff --git a/source4/lib/ldb/tools/convert.c b/source4/lib/ldb/tools/convert.c new file mode 100644 index 0000000000..222bb3cfd0 --- /dev/null +++ b/source4/lib/ldb/tools/convert.c @@ -0,0 +1,165 @@ +/* + 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 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "convert.h" +#include "includes.h" +#include "ldb/include/includes.h" + +/* Shared map for converting syntax between formats */ +static const struct syntax_map syntax_map[] = { + { + .Standard_OID = "1.3.6.1.4.1.1466.115.121.1.12", + .AD_OID = "2.5.5.1", + .equality = "distinguishedNameMatch", + .comment = "Object(DS-DN) == a DN" + }, + { + .Standard_OID = "1.3.6.1.4.1.1466.115.121.1.38", + .AD_OID = "2.5.5.2", + .equality = "objectIdentifierMatch", + .comment = "OID String" + }, + { + .Standard_OID = "1.2.840.113556.1.4.905", + .AD_OID = "2.5.5.4", + .equality = "caseIgnoreMatch", + .substring = "caseIgnoreSubstringsMatch", + .comment = "Case Insensitive String" + }, + { + .Standard_OID = "1.3.6.1.4.1.1466.115.121.1.44", + .AD_OID = "2.5.5.5", + .equality = "caseExactIA5Match", + .comment = "Printable String" + }, + { + .Standard_OID = "1.3.6.1.4.1.1466.115.121.1.36", + .AD_OID = "2.5.5.6", + .equality = "numericStringMatch", + .substring = "numericStringSubstringsMatch", + .comment = "Numeric String" + }, + { + .Standard_OID = "1.2.840.113556.1.4.903", + .AD_OID = "2.5.5.7", + .equality = "distinguishedNameMatch", + .comment = "OctetString: Binary+DN" + }, + { + .Standard_OID = "1.3.6.1.4.1.1466.115.121.1.7", + .AD_OID = "2.5.5.8", + .equality = "booleanMatch", + .comment = "Boolean" + }, + { + .Standard_OID = "1.3.6.1.4.1.1466.115.121.1.27", + .AD_OID = "2.5.5.9", + .equality = "integerMatch", + .comment = "Integer" + }, + { + .Standard_OID = "1.3.6.1.4.1.1466.115.121.1.40", + .AD_OID = "2.5.5.10", + .equality = "octetStringMatch", + .comment = "Octet String" + }, + { + .Standard_OID = "1.3.6.1.4.1.1466.115.121.1.24", + .AD_OID = "2.5.5.11", + .equality = "generalizedTimeMatch", + .comment = "Generalized Time" + }, + { + .Standard_OID = "1.3.6.1.4.1.1466.115.121.1.53", + .AD_OID = "2.5.5.11", + .equality = "generalizedTimeMatch", + .comment = "UTC Time" + }, + { + .Standard_OID = "1.3.6.1.4.1.1466.115.121.1.15", + .AD_OID = "2.5.5.12", + .equality = "caseIgnoreMatch", + .substring = "caseIgnoreSubstringsMatch", + .comment = "Directory String" + }, + { + .Standard_OID = "1.3.6.1.4.1.1466.115.121.1.43", + .AD_OID = "2.5.5.13", + .comment = "Presentation Address" + }, + { + .Standard_OID = "Not Found Yet", + .AD_OID = "2.5.5.14", + .equality = "distinguishedNameMatch", + .comment = "OctetString: String+DN" + }, + { + .Standard_OID = "1.2.840.113556.1.4.907", + .AD_OID = "2.5.5.15", + .equality = "octetStringMatch", + .comment = "NT Security Descriptor" + }, + { + .Standard_OID = "1.2.840.113556.1.4.906", + .AD_OID = "2.5.5.16", + .equality = "integerMatch", + .comment = "Large Integer" + }, + { + .Standard_OID = "1.3.6.1.4.1.1466.115.121.1.40", + .AD_OID = "2.5.5.17", + .equality = "octetStringMatch", + .comment = "Octet String - Security Identifier (SID)" + }, + { + .Standard_OID = "1.3.6.1.4.1.1466.115.121.1.26", + .AD_OID = "2.5.5.5", + .equality = "caseExactIA5Match", + .comment = "IA5 String" + }, + { } +}; + + +const struct syntax_map *find_syntax_map_by_ad_oid(const char *ad_oid) +{ + int i; + for (i=0; syntax_map[i].Standard_OID; i++) { + if (strcasecmp(ad_oid, syntax_map[i].AD_OID) == 0) { + return &syntax_map[i]; + } + } + return NULL; +} + +const struct syntax_map *find_syntax_map_by_standard_oid(const char *standard_oid) +{ + int i; + for (i=0; syntax_map[i].Standard_OID; i++) { + if (strcasecmp(standard_oid, syntax_map[i].Standard_OID) == 0) { + return &syntax_map[i]; + } + } + return NULL; +} diff --git a/source4/lib/ldb/tools/convert.h b/source4/lib/ldb/tools/convert.h new file mode 100644 index 0000000000..de379343a6 --- /dev/null +++ b/source4/lib/ldb/tools/convert.h @@ -0,0 +1,10 @@ +struct syntax_map { + const char *Standard_OID; + const char *AD_OID; + const char *equality; + const char *substring; + const char *comment; +}; + +const struct syntax_map *find_syntax_map_by_ad_oid(const char *ad_oid); +const struct syntax_map *find_syntax_map_by_standard_oid(const char *standard_oid); diff --git a/source4/lib/ldb/tools/oLschema2ldif.c b/source4/lib/ldb/tools/oLschema2ldif.c index 288cf4c3c3..f734e99683 100644 --- a/source4/lib/ldb/tools/oLschema2ldif.c +++ b/source4/lib/ldb/tools/oLschema2ldif.c @@ -25,16 +25,17 @@ /* * Name: ldb * - * Component: ldbdel + * Component: oLschema2ldif * - * Description: utility to delete records - modelled on ldapdelete + * Description: utility to convert an OpenLDAP schema into AD LDIF * - * Author: Andrew Tridgell + * Author: Simo Sorce */ #include "includes.h" #include "ldb/include/includes.h" #include "ldb/tools/cmdline.h" +#include "ldb/tools/convert.h" #define SCHEMA_UNKNOWN 0 #define SCHEMA_NAME 1 @@ -51,33 +52,6 @@ #define SCHEMA_SYNTAX 12 #define SCHEMA_DESC 13 -struct syntax_map { - const char *Standard_OID; - const char *AD_OID; - const char *comment; -} syntax_map[] = { - { "1.3.6.1.4.1.1466.115.121.1.12", "2.5.5.1", "Object(DS-DN) == a DN" }, - { "1.3.6.1.4.1.1466.115.121.1.38", "2.5.5.2", "OID String" }, - { "1.2.840.113556.1.4.905", "2.5.5.4", "Case Insensitive String" }, - { "1.3.6.1.4.1.1466.115.121.1.44", "2.5.5.5", "Printable String" }, - { "1.3.6.1.4.1.1466.115.121.1.36", "2.5.5.6", "Numeric String" }, - { "1.2.840.113556.1.4.903", "2.5.5.7", "OctetString: Binary+DN" }, - { "1.3.6.1.4.1.1466.115.121.1.7", "2.5.5.8", "Boolean" }, - { "1.3.6.1.4.1.1466.115.121.1.27", "2.5.5.9", "Integer" }, - { "1.3.6.1.4.1.1466.115.121.1.40", "2.5.5.10", "Octet String" }, - { "1.3.6.1.4.1.1466.115.121.1.24", "2.5.5.11", "Generalized Time" }, - { "1.3.6.1.4.1.1466.115.121.1.53", "2.5.5.11", "UTC Time" }, - { "1.3.6.1.4.1.1466.115.121.1.15", "2.5.5.12", "Directory String" }, - { "1.3.6.1.4.1.1466.115.121.1.43", "2.5.5.13", "Presentation Address" }, - { "Not Found Yet", "2.5.5.14", "OctetString: String+DN" }, - { "1.2.840.113556.1.4.907", "2.5.5.15", "NT Security Descriptor" }, - { "1.2.840.113556.1.4.906", "2.5.5.16", "Interval" }, - { "1.3.6.1.4.1.1466.115.121.1.40", "2.5.5.17", "Octet String - Security Identifier (SID)" }, - { "1.3.6.1.4.1.1466.115.121.1.26", "2.5.5.5", "IA5 String" }, - { NULL, NULL } -}; - - struct schema_conv { int count; int failures; @@ -460,9 +434,15 @@ static struct ldb_message *process_entry(TALLOC_CTX *mem_ctx, const char *entry) break; case SCHEMA_SYNTAX: - MSG_ADD_STRING("attributeSyntax", token->value); + { + const struct syntax_map *map = + find_syntax_map_by_standard_oid(token->value); + if (!map) { + break; + } + MSG_ADD_STRING("attributeSyntax", map->AD_OID); break; - + } case SCHEMA_DESC: MSG_ADD_STRING("description", token->value); break; @@ -564,9 +544,10 @@ static struct schema_conv process_file(FILE *in, FILE *out) static void usage(void) { - printf("Usage: oLschema2ldif <options>\n"); + printf("Usage: oLschema2ldif -H NONE <options>\n"); + printf("\nConvert OpenLDAP schema to AD-like LDIF format\n\n"); printf("Options:\n"); - printf(" -I inputfile inputfile otherwise STDIN\n"); + printf(" -I inputfile inputfile of OpenLDAP style schema otherwise STDIN\n"); printf(" -O outputfile outputfile otherwise STDOUT\n"); printf(" -o options pass options like modules to activate\n"); printf(" e.g: -o modules:timestamps\n"); @@ -582,7 +563,6 @@ static void usage(void) struct ldb_cmdline *options; FILE *in = stdin; FILE *out = stdout; - ldb_global_init(); ctx = talloc_new(NULL); |