]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/main.c
Use AC_STRERROR_R
[openldap] / servers / slapd / main.c
index 56267449fd3fd3e148e1e7086e24e82e65438647..0fdef6bc8702a406b0c7d725b848d8f71a4d4421 100644 (file)
@@ -66,7 +66,7 @@ static struct sockaddr_in     bind_addr;
 
 typedef int (MainFunc) LDAP_P(( int argc, char *argv[] ));
 extern MainFunc slapadd, slapcat, slapdn, slapindex, slappasswd,
-       slaptest, slapauth;
+       slaptest, slapauth, slapacl;
 
 static struct {
        char *name;
@@ -79,6 +79,13 @@ static struct {
        {"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}
 };
 
@@ -125,6 +132,8 @@ static int   cnvt_str2int( char *, STRDISP_P, int );
 static int check = CHECK_NONE;
 static int version = 0;
 
+void *slap_tls_ctx;
+
 static void
 usage( char *name )
 {
@@ -199,8 +208,9 @@ int main( int argc, char **argv )
        }
 #endif
        char    *serverNamePrefix = "";
+       size_t  l;
 
-       sl_mem_init();
+       slap_sl_mem_init();
 
        serverName = lutil_progname( "slapd", argc, argv );
 
@@ -211,8 +221,6 @@ int main( int argc, char **argv )
                                MAIN_RETURN(rc);
                        }
                }
-
-               goto unrecognized_server_name;
        }
 
 #ifdef HAVE_NT_SERVICE_MANAGER
@@ -390,15 +398,26 @@ int main( int argc, char **argv )
                        break;
 
                case 'T':
-                       for (i=0; tools[i].name; i++) {
+                       /* 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);
+                                       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";
-unrecognized_server_name:;
                        fprintf( stderr, "program name \"%s%s\" unrecognized; "
                                        "aborting...\n", serverNamePrefix, serverName );
                        /* FALLTHRU */
@@ -605,18 +624,32 @@ unrecognized_server_name:;
                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