]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/main.c
add logs; fix bug in group/dn selection logic
[openldap] / servers / slapd / main.c
index 497d40868161bcc3f2b7b8cf6e82aa1e442d6c65..91887448df8db77dc31acd81f6001455b05c5f52 100644 (file)
@@ -65,7 +65,8 @@ 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, slapauth;
 
 static struct {
        char *name;
@@ -73,8 +74,17 @@ static struct {
 } tools[] = {
        {"slapadd", slapadd},
        {"slapcat", slapcat},
+       {"slapdn", slapdn},
        {"slapindex", slapindex},
        {"slappasswd", slappasswd},
+       {"slaptest", slaptest},
+       {"slapauth", slapauth},
+       /* 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}
 };
 
@@ -116,7 +126,9 @@ static int   cnvt_str2int( char *, STRDISP_P, int );
 
 #endif /* LOG_LOCAL4 */
 
-static int check_config = 0;
+#define CHECK_NONE     0x00
+#define CHECK_CONFIG   0x01
+static int check = CHECK_NONE;
 static int version = 0;
 
 static void
@@ -127,7 +139,8 @@ 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"
@@ -143,7 +156,6 @@ usage( char *name )
                "\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"
 #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"
@@ -182,7 +194,7 @@ int main( int argc, char **argv )
        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;
 
@@ -192,6 +204,8 @@ int main( int argc, char **argv )
                leakfile = stderr;
        }
 #endif
+       char    *serverNamePrefix = "";
+       size_t  l;
 
        sl_mem_init();
 
@@ -266,7 +280,7 @@ int main( int argc, char **argv )
 #endif
 
        while ( (i = getopt( argc, argv,
-                            "c:d:f:h:s:n:t:T:V"
+                            "c:d:f:h:s:n:tT:V"
 #if LDAP_PF_INET6
                                "46"
 #endif
@@ -370,19 +384,39 @@ int main( int argc, char **argv )
                        break;
 
                case 't':
-                       check_config++;
+                       /* deprecated; use slaptest instead */
+                       fprintf( stderr, "option -t deprecated; "
+                               "use slaptest command instead\n" );
+                       check |= CHECK_CONFIG;
                        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] );
@@ -431,7 +465,7 @@ int main( int argc, char **argv )
        Debug( LDAP_DEBUG_ANY, "%s", Versionstr, 0, 0 );
 #endif
 
-       if( !check_config && slapd_daemon_init( urls ) != 0 ) {
+       if( check == CHECK_NONE && slapd_daemon_init( urls ) != 0 ) {
                rc = 1;
                SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 );
                goto stop;
@@ -532,17 +566,21 @@ int main( int argc, char **argv )
                rc = 1;
                SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 19 );
 
-               if ( check_config ) {
+               if ( check & CHECK_CONFIG ) {
                        fprintf( stderr, "config check failed\n" );
                }
 
                goto destroy;
        }
 
-       if ( check_config ) {
-               rc = 0;
+       if ( check & CHECK_CONFIG ) {
                fprintf( stderr, "config check succeeded\n" );
-               goto destroy;
+
+               check &= ~CHECK_CONFIG;
+               if ( check == CHECK_NONE ) {
+                       rc = 0;
+                       goto destroy;
+               }
        }
 
        if ( glue_sub_init( ) != 0 ) {