4 Copyright (C) Simo Sorce 2005
6 ** NOTE! The following LGPL license applies to the ldb
7 ** library. This does NOT imply that all of Samba is released
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 3 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, see <http://www.gnu.org/licenses/>.
27 * Component: oLschema2ldif
29 * Description: utility to convert an OpenLDAP schema into AD LDIF
36 #include "lib/cmdline/popt_common.h"
38 static struct options {
44 static struct poptOption popt_options[] = {
46 { "basedn", 'b', POPT_ARG_STRING, &options.basedn, 0, "base DN", "DN" },
47 { "input", 'I', POPT_ARG_STRING, &options.input, 0,
48 "inputfile of OpenLDAP style schema otherwise STDIN", "inputfile"},
49 { "output", 'O', POPT_ARG_STRING, &options.output, 0,
50 "outputfile otherwise STDOUT", "outputfile"},
56 static void usage(void)
59 printf("Usage: oLschema2ldif <options>\n");
60 printf("\nConvert OpenLDAP schema to AD-like LDIF format\n\n");
61 printf("Converts records from an openLdap formatted schema to an ldif schema\n\n");
62 pc = poptGetContext("oLschema2ldif", 0, NULL, popt_options,
63 POPT_CONTEXT_KEEP_FIRST);
64 poptPrintHelp(pc, stdout, 0);
69 int main(int argc, const char **argv)
72 struct schema_conv ret;
74 struct conv_options copt;
77 ctx = talloc_new(NULL);
79 setenv("LDB_URL", "NONE", 1);
81 pc = poptGetContext(argv[0], argc, argv, popt_options,
82 POPT_CONTEXT_KEEP_FIRST);
84 while((opt = poptGetNextOpt(pc)) != -1) {
85 fprintf(stderr, "Invalid option %s: %s\n",
86 poptBadOption(pc, 0), poptStrerror(opt));
90 if (options.basedn == NULL) {
91 printf("Base DN not specified\n");
98 copt.ldb_ctx = ldb_init(ctx, NULL);
100 copt.basedn = ldb_dn_new(ctx, copt.ldb_ctx, options.basedn);
101 if (!ldb_dn_validate(copt.basedn)) {
102 printf("Malformed Base DN\n");
108 copt.in = fopen(options.input, "r");
110 perror(options.input);
115 if (options.output) {
116 copt.out = fopen(options.output, "w");
118 perror(options.output);
124 ret = process_file(ctx, &copt);
129 printf("Converted %d records with %d failures\n", ret.count, ret.failures);