#endif
typedef int (MainFunc) LDAP_P(( int argc, char *argv[] ));
-extern MainFunc slapadd, slapcat, slapindex, slappasswd;
+extern MainFunc slapadd, slapcat, slapdn, slapindex, slappasswd,
+ slaptest, slapauth, slapacl;
static struct {
char *name;
} tools[] = {
{"slapadd", slapadd},
{"slapcat", slapcat},
+ {"slapdn", slapdn},
{"slapindex", slapindex},
{"slappasswd", slappasswd},
+ {"slaptest", slaptest},
+ {"slapauth", slapauth},
+ {"slapacl", slapacl},
+ /* NOTE: new tools must be added in chronological order,
+ * not in alphabetical order, because for backwards
+ * compatibility name[4] is used to identify the
+ * tools; so name[4]=='a' must refer to "slapadd" and
+ * not to "slapauth". Alphabetical order can be used
+ * for tools whose name[4] is not used yet */
{NULL, NULL}
};
#endif /* LOG_LOCAL4 */
#define CHECK_NONE 0x00
-#define CHECK_CONFIG 0x01
-#define CHECK_DN 0x02
+#define CHECK_CONFIG 0x01
static int check = CHECK_NONE;
-static struct berval check_dn = BER_BVC("");
static int version = 0;
+void *slap_tls_ctx;
+
static void
usage( char *name )
{
fprintf( stderr,
"\t-4\t\tIPv4 only\n"
"\t-6\t\tIPv6 only\n"
- "\t-T (a|c|i|p)\tRun in Tool mode\n"
+ "\t-T {add|auth|cat|dn|index|passwd|test}\n"
+ "\t\t\tRun in Tool mode\n"
"\t-c cookie\tSync cookie of consumer\n"
"\t-d level\tDebug level" "\n"
"\t-f filename\tConfiguration file\n"
"\t-r directory\tSandbox directory to chroot to\n"
#endif
"\t-s level\tSyslog level\n"
- "\t-t\t\tCheck configuration file and exit\n"
- "\t-D dn\tCheck dn and exit\n"
#if defined(HAVE_SETUID) && defined(HAVE_SETGID)
"\t-u user\t\tUser (id or name) to run as\n"
"\t-V\t\tprint version info (-VV only)\n"
char *serverName;
int serverMode = SLAP_SERVER_MODE;
- struct berval cookie = { 0, NULL };
+ struct berval cookie = BER_BVNULL;
struct sync_cookie *scp = NULL;
struct sync_cookie *scp_entry = NULL;
leakfile = stderr;
}
#endif
+ char *serverNamePrefix = "";
+ size_t l;
- sl_mem_init();
+ slap_sl_mem_init();
serverName = lutil_progname( "slapd", argc, argv );
#endif
while ( (i = getopt( argc, argv,
- "c:d:D:f:h:s:n:tT:V"
+ "c:d:f:h:s:n:tT:V"
#if LDAP_PF_INET6
"46"
#endif
break;
case 't':
+ /* deprecated; use slaptest instead */
+ fprintf( stderr, "option -t deprecated; "
+ "use slaptest command instead\n" );
check |= CHECK_CONFIG;
break;
- case 'D':
- check |= CHECK_DN;
- check_dn.bv_val = optarg;
- check_dn.bv_len = strlen( optarg );
- break;
-
case 'V':
version++;
break;
case 'T':
- for (i=0; tools[i].name; i++) {
- if ( optarg[0] == tools[i].name[4] ) {
- rc = tools[i].func(argc, argv);
- MAIN_RETURN(rc);
+ /* try full option string first */
+ for ( i = 0; tools[i].name; i++ ) {
+ if ( strcmp( optarg, &tools[i].name[4] ) == 0 ) {
+ rc = tools[i].func( argc, argv );
+ MAIN_RETURN( rc );
+ }
+ }
+
+ /* try bits of option string (backward compatibility for single char) */
+ l = strlen( optarg );
+ for ( i = 0; tools[i].name; i++ ) {
+ if ( strncmp( optarg, &tools[i].name[4], l ) == 0 ) {
+ rc = tools[i].func( argc, argv );
+ MAIN_RETURN( rc );
}
}
+
+ /* issue error */
+ serverName = optarg;
+ serverNamePrefix = "slap";
+ fprintf( stderr, "program name \"%s%s\" unrecognized; "
+ "aborting...\n", serverNamePrefix, serverName );
/* FALLTHRU */
default:
usage( argv[0] );
goto destroy;
}
- if ( check & CHECK_DN ) {
- struct berval pdn, ndn;
-
- rc = dnPrettyNormal( NULL, &check_dn,
- &pdn, &ndn, NULL );
- if ( rc != LDAP_SUCCESS ) {
- fprintf( stderr, "DN: <%s> check failed %d (%s)\n",
- check_dn.bv_val, rc,
- ldap_err2string( rc ) );
- rc = 1;
-
- } else {
- fprintf( stderr, "DN: <%s> check succeeded\n"
- "normalized: <%s>\n"
- "pretty: <%s>\n",
- check_dn.bv_val,
- ndn.bv_val, pdn.bv_val );
- rc = 0;
- }
-
- check &= ~CHECK_DN;
- if ( check == CHECK_NONE ) {
- goto destroy;
- }
- }
-
#ifdef HAVE_TLS
rc = ldap_pvt_tls_init();
if( rc != 0) {
goto destroy;
}
- rc = ldap_pvt_tls_init_def_ctx();
- if( rc != 0) {
+ {
+ void *def_ctx = NULL;
+
+ /* Save existing default ctx, if any */
+ ldap_pvt_tls_get_option( NULL, LDAP_OPT_X_TLS_CTX, &def_ctx );
+
+ /* Force new ctx to be created */
+ ldap_pvt_tls_set_option( NULL, LDAP_OPT_X_TLS_CTX, NULL );
+
+ rc = ldap_pvt_tls_init_def_ctx();
+ if( rc != 0) {
#ifdef NEW_LOGGING
- LDAP_LOG( SLAPD, CRIT, "main: tls init def ctx failed: %d\n", rc, 0, 0 );
+ LDAP_LOG( SLAPD, CRIT, "main: tls init def ctx failed: %d\n", rc, 0, 0 );
#else
- Debug( LDAP_DEBUG_ANY,
- "main: TLS init def ctx failed: %d\n",
- rc, 0, 0 );
+ Debug( LDAP_DEBUG_ANY,
+ "main: TLS init def ctx failed: %d\n",
+ rc, 0, 0 );
#endif
- rc = 1;
- SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
- goto destroy;
+ rc = 1;
+ SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 20 );
+ goto destroy;
+ }
+ /* Retrieve slapd's own ctx */
+ ldap_pvt_tls_get_option( NULL, LDAP_OPT_X_TLS_CTX, &slap_tls_ctx );
+ /* Restore previous ctx */
+ ldap_pvt_tls_set_option( NULL, LDAP_OPT_X_TLS_CTX, def_ctx );
}
#endif