mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-24 00:29:35 -05:00
move DN/config test in slapdn/slaptest
This commit is contained in:
parent
db18784462
commit
764aa5d938
6 changed files with 218 additions and 27 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
}
|
||||
|
||||
if ( replica_promotion && replica_demotion ) {
|
||||
usage( tool, progname );
|
||||
} else if ( !replica_promotion && !replica_demotion ) {
|
||||
if ( update_ctxcsn != SLAP_TOOL_CTXCSN_KEEP ) {
|
||||
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;
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -23,8 +23,11 @@
|
|||
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
|
||||
|
|
|
|||
80
servers/slapd/slapdn.c
Normal file
80
servers/slapd/slapdn.c
Normal file
|
|
@ -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;
|
||||
}
|
||||
53
servers/slapd/slaptest.c
Normal file
53
servers/slapd/slaptest.c
Normal file
|
|
@ -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;
|
||||
}
|
||||
Loading…
Reference in a new issue