]> git.sur5r.net Git - openldap/commitdiff
move DN/config test in slapdn/slaptest
authorPierangelo Masarati <ando@openldap.org>
Wed, 17 Mar 2004 23:25:09 +0000 (23:25 +0000)
committerPierangelo Masarati <ando@openldap.org>
Wed, 17 Mar 2004 23:25:09 +0000 (23:25 +0000)
servers/slapd/Makefile.in
servers/slapd/main.c
servers/slapd/slapcommon.c
servers/slapd/slapcommon.h
servers/slapd/slapdn.c [new file with mode: 0644]
servers/slapd/slaptest.c [new file with mode: 0644]

index c044775b3a281950ba6b3a7d0113b4df80c14af2..644d064c7aed8ee31d8dfa3ccf05ca24cde5f579 100644 (file)
@@ -13,7 +13,7 @@
 ## top-level directory of the distribution or, alternatively, at
 ## <http://www.OpenLDAP.org/license.html>.
 
-SLAPTOOLS=slapadd slapcat slapindex slappasswd
+SLAPTOOLS=slapadd slapcat slapdn slapindex slappasswd slaptest
 PROGRAMS=slapd $(SLAPTOOLS)
 XPROGRAMS=sslapd libbackends.a .backend liboverlays.a
 XSRCS=version.c
@@ -35,7 +35,8 @@ SRCS  = main.c globals.c config.c daemon.c \
                oidm.c starttls.c index.c sets.c referral.c root_dse.c \
                sasl.c module.c mra.c mods.c sl_malloc.c limits.c \
                backglue.c operational.c matchedValues.c cancel.c syncrepl.c \
-               slapadd.c slapcat.c slapcommon.c slapindex.c slappasswd.c \
+               slapadd.c slapcat.c slapcommon.c slapdn.c slapindex.c \
+               slappasswd.c slaptest.c \
                backover.c ctxcsn.c ldapsync.c sessionlog.c $(@PLAT@_SRCS)
 
 OBJS   = main.o globals.o config.o daemon.o \
@@ -50,7 +51,8 @@ OBJS  = main.o globals.o config.o daemon.o \
                oidm.o starttls.o index.o sets.o referral.o root_dse.o \
                sasl.o module.o mra.o mods.o sl_malloc.o limits.o \
                backglue.o operational.o matchedValues.o cancel.o syncrepl.o \
-               slapadd.o slapcat.o slapcommon.o slapindex.o slappasswd.o \
+               slapadd.o slapcat.o slapcommon.o slapdn.o slapindex.o \
+               slappasswd.o slaptest.c \
                backover.o ctxcsn.o ldapsync.o sessionlog.o $(@PLAT@_OBJS)
 
 LDAP_INCDIR= ../../include -I$(srcdir)/slapi
index 6d4096b9bc5cbbad3d1817a73e0d8be5add5939d..4ed2c6cc6d1f4ad9823ce98937a0e8a48ee0d9ed 100644 (file)
@@ -65,7 +65,7 @@ static struct sockaddr_in     bind_addr;
 #endif
 
 typedef int (MainFunc) LDAP_P(( int argc, char *argv[] ));
-extern MainFunc slapadd, slapcat, slapindex, slappasswd;
+extern MainFunc slapadd, slapcat, slapdn, slapindex, slappasswd, slaptest;
 
 static struct {
        char *name;
@@ -73,8 +73,10 @@ static struct {
 } tools[] = {
        {"slapadd", slapadd},
        {"slapcat", slapcat},
+       {"slapdn", slapdn},
        {"slapindex", slapindex},
        {"slappasswd", slappasswd},
+       {"slaptest", slaptest},
        {NULL, NULL}
 };
 
index 9db0214ef047bf8b7274032f6de7e07d78cc1675..996536b4f87b1bc7518be4d5bcff539316018cc3 100644 (file)
@@ -49,24 +49,29 @@ usage( int tool, const char *progname )
 {
        char *options = NULL;
        fprintf( stderr,
-               "usage: %s [-v] [-c] [-d debuglevel] [-f configfile]\n"
-                       "\t[-n databasenumber | -b suffix]", progname );
+               "usage: %s [-v] [-c] [-d debuglevel] [-f configfile]\n",
+               progname );
 
        switch( tool ) {
        case SLAPADD:
-               options = "\n\t[-l ldiffile] [-u] [-p [-w] | -r [-i syncreplidlist] [-w]]\n";
+               options = "\t[-n databasenumber | -b suffix]\n"
+                       "\t[-l ldiffile] [-u] [-p [-w] | -r [-i syncreplidlist] [-w]]\n";
                break;
 
        case SLAPCAT:
-               options = "\t[-l ldiffile] [-m] [-k]\n";
+               options = "\t[-n databasenumber | -b suffix] [-l ldiffile] [-m] [-k]\n";
+               break;
+
+       case SLAPDN:
+               options = "\tDN [...]\n";
                break;
 
        case SLAPINDEX:
-               options = "\n";
+               options = "\t[-n databasenumber | -b suffix]\n";
                break;
        }
 
-       if( options != NULL ) {
+       if ( options != NULL ) {
                fputs( options, stderr );
        }
        exit( EXIT_FAILURE );
@@ -110,16 +115,21 @@ slap_tool_init(
                options = "b:cd:f:i:l:n:prtuvWw";
                break;
 
-       case SLAPINDEX:
-               options = "b:cd:f:n:v";
-               mode |= SLAP_TOOL_READMAIN;
-               break;
-
        case SLAPCAT:
                options = "b:cd:f:kl:mn:s:v";
                mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
                break;
 
+       case SLAPDN:
+       case SLAPTEST:
+               options = "d:f:v";
+               break;
+
+       case SLAPINDEX:
+               options = "b:cd:f:n:v";
+               mode |= SLAP_TOOL_READMAIN;
+               break;
+
        default:
                fprintf( stderr, "%s: unknown tool mode (%d)\n",
                         progname, tool );
@@ -223,16 +233,38 @@ slap_tool_init(
                }
        }
 
-       if ( ( argc != optind ) || (dbnum >= 0 && base.bv_val != NULL ) ) {
-               usage( tool, progname );
-       }
+       switch ( tool ) {
+       case SLAPADD:
+       case SLAPCAT:
+       case SLAPINDEX:
+               if ( ( argc != optind ) || (dbnum >= 0 && base.bv_val != NULL ) ) {
+                       usage( tool, progname );
+               }
+
+               if ( replica_promotion && replica_demotion ) {
+                       usage( tool, progname );
+
+               } else if ( !replica_promotion && !replica_demotion ) {
+                       if ( update_ctxcsn != SLAP_TOOL_CTXCSN_KEEP ) {
+                               usage( tool, progname );
+                       }
+               }
+               break;
 
-       if ( replica_promotion && replica_demotion ) {
-               usage( tool, progname );
-       } else if ( !replica_promotion && !replica_demotion ) {
-               if ( update_ctxcsn != SLAP_TOOL_CTXCSN_KEEP ) {
+       case SLAPDN:
+               if ( argc == optind ) {
                        usage( tool, progname );
                }
+               break;
+
+       case SLAPTEST:
+               if ( argc != optind ) {
+                       usage( tool, progname );
+               }
+               break;
+
+       default:
+               break;
        }
 
        if ( ldiffile == NULL ) {
@@ -279,9 +311,19 @@ slap_tool_init(
 
        ldap_syslog = 0;
 
-       if ( !nbackends ) {
-               fprintf( stderr, "No databases found in config file\n" );
-               exit( EXIT_FAILURE );
+       switch ( tool ) {
+       case SLAPADD:
+       case SLAPCAT:
+       case SLAPINDEX:
+               if ( !nbackends ) {
+                       fprintf( stderr, "No databases found "
+                                       "in config file\n" );
+                       exit( EXIT_FAILURE );
+               }
+               break;
+
+       default:
+               break;
        }
 
        rc = glue_sub_init();
@@ -298,6 +340,15 @@ slap_tool_init(
                exit( EXIT_FAILURE );
        }
 
+       switch ( tool ) {
+       case SLAPDN:
+       case SLAPTEST:
+               return;
+
+       default:
+               break;
+       }
+
        if( subtree ) {
                struct berval val;
                val.bv_val = subtree;
index fdeb68a1a461b7ade2e57e96e4a2358d81046e7f..12a1b57ffd3e88e631216da0e0179495d2a3f577 100644 (file)
 enum slaptool {
        SLAPADD=1,      /* LDIF -> database tool */
        SLAPCAT,        /* database -> LDIF tool */
+       SLAPDN,         /* DN check w/ syntax tool */
        SLAPINDEX,      /* database index tool */
-       SLAPPASSWD      /* password generation tool */
+       SLAPPASSWD,     /* password generation tool */
+       SLAPTEST,       /* slapd.conf test tool */
+       SLAPLAST
 };
 
 #define SLAP_TOOL_CTXCSN_KEEP  0
diff --git a/servers/slapd/slapdn.c b/servers/slapd/slapdn.c
new file mode 100644 (file)
index 0000000..3db6e0b
--- /dev/null
@@ -0,0 +1,80 @@
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 2004 The OpenLDAP Foundation.
+ * Portions Copyright 2004 Pierangelo Masarati.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* ACKNOWLEDGEMENTS:
+ * This work was initially developed by Pierangelo Masarati for inclusion
+ * in OpenLDAP Software.
+ */
+
+#include "portable.h"
+
+#include <stdio.h>
+
+#include <ac/stdlib.h>
+
+#include <ac/ctype.h>
+#include <ac/string.h>
+#include <ac/socket.h>
+#include <ac/unistd.h>
+
+#include <lber.h>
+#include <ldif.h>
+#include <lutil.h>
+
+#include "slapcommon.h"
+
+int
+slapdn( int argc, char **argv )
+{
+       int                     rc = EXIT_SUCCESS;
+       const char              *progname = "slapdn";
+
+#ifdef NEW_LOGGING
+       lutil_log_initialize( argc, argv );
+#endif
+       slap_tool_init( progname, SLAPDN, argc, argv );
+
+       argv = &argv[ optind ];
+       argc -= optind;
+
+       for ( ; argc--; argv++ ) {
+               struct berval   dn, pdn, ndn;
+
+               dn.bv_val = argv[ 0 ];
+               dn.bv_len = strlen( argv[ 0 ] );
+
+               rc = dnPrettyNormal( NULL, &dn,
+                                       &pdn, &ndn, NULL );
+               if ( rc != LDAP_SUCCESS ) {
+                       fprintf( stderr, "DN: <%s> check failed %d (%s)\n",
+                                       dn.bv_val, rc,
+                                       ldap_err2string( rc ) );
+                       rc = 1;
+                       
+               } else {
+                       fprintf( stderr, "DN: <%s> check succeeded\n"
+                                       "normalized: <%s>\n"
+                                       "pretty:     <%s>\n",
+                                       dn.bv_val,
+                                       ndn.bv_val, pdn.bv_val );
+                       ch_free( ndn.bv_val );
+                       ch_free( pdn.bv_val );
+                       rc = 0;
+               }
+       }
+       
+       slap_tool_destroy();
+
+       return rc;
+}
diff --git a/servers/slapd/slaptest.c b/servers/slapd/slaptest.c
new file mode 100644 (file)
index 0000000..7a20dfd
--- /dev/null
@@ -0,0 +1,53 @@
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 2004 The OpenLDAP Foundation.
+ * Portions Copyright 2004 Pierangelo Masarati.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* ACKNOWLEDGEMENTS:
+ * This work was initially developed by Pierangelo Masarati for inclusion
+ * in OpenLDAP Software.
+ */
+
+#include "portable.h"
+
+#include <stdio.h>
+
+#include <ac/stdlib.h>
+
+#include <ac/ctype.h>
+#include <ac/string.h>
+#include <ac/socket.h>
+#include <ac/unistd.h>
+
+#include <lber.h>
+#include <ldif.h>
+#include <lutil.h>
+
+#include "slapcommon.h"
+
+int
+slaptest( int argc, char **argv )
+{
+       int                     rc = EXIT_SUCCESS;
+       const char              *progname = "slaptest";
+
+#ifdef NEW_LOGGING
+       lutil_log_initialize( argc, argv );
+#endif
+       slap_tool_init( progname, SLAPTEST, argc, argv );
+
+       fprintf( stderr, "config file testing succeeded\n");
+
+       slap_tool_destroy();
+
+       return rc;
+}