]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/slapcommon.c
fix ITS#3753
[openldap] / servers / slapd / slapcommon.c
index 331c9b2e946dad0869c90da6581bf209e2864d80..1d72c5cf7428a0dcd214a4b38bce0a8d4b46e5ec 100644 (file)
@@ -36,6 +36,7 @@
 
 #include "slapcommon.h"
 #include "lutil.h"
+#include "ldif.h"
 
 tool_vars tool_globals;
 
@@ -44,6 +45,8 @@ static char *leakfilename;
 static FILE *leakfile;
 #endif
 
+static LDIFFP dummy;
+
 static void
 usage( int tool, const char *progname )
 {
@@ -54,9 +57,8 @@ usage( int tool, const char *progname )
 
        switch( tool ) {
        case SLAPACL:
-               options = "\n\t[-U authcID | -D authcDN]"
-                       " -b DN -o <var>[=<val>]"
-                       "\n\t[attr[/access][:value]] [...]\n";
+               options = "\n\t[-U authcID | -D authcDN] [-X authzID | -o authzDN=<DN>]"
+                       "\n\t-b DN -o <var>[=<val>] [-u] [attr[/access][:value]] [...]\n";
                break;
 
        case SLAPADD:
@@ -74,7 +76,7 @@ usage( int tool, const char *progname )
                break;
 
        case SLAPDN:
-               options = " DN [...]\n";
+               options = "\n\t[-N | -P] DN [...]\n";
                break;
 
        case SLAPINDEX:
@@ -142,6 +144,9 @@ parse_slapacl( void )
        } else if ( strncasecmp( optarg, "sasl_ssf", len ) == 0 ) {
                sasl_ssf = atoi( p );
 
+       } else if ( strncasecmp( optarg, "authzDN", len ) == 0 ) {
+               ber_str2bv( p, 0, 1, &authzDN );
+
        } else {
                return -1;
        }
@@ -164,8 +169,8 @@ slap_tool_init(
        int argc, char **argv )
 {
        char *options;
-       char *conffile = SLAPD_DEFAULT_CONFIGFILE;
-       char *confdir = SLAPD_DEFAULT_CONFIGDIR;
+       char *conffile = NULL;
+       char *confdir = NULL;
        struct berval base = BER_BVNULL;
        char *filterstr = NULL;
        char *subtree = NULL;
@@ -194,7 +199,7 @@ slap_tool_init(
                break;
 
        case SLAPDN:
-               options = "d:f:F:v";
+               options = "d:f:F:NPv";
                mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
                break;
 
@@ -214,7 +219,7 @@ slap_tool_init(
                break;
 
        case SLAPACL:
-               options = "b:D:d:f:F:o:U:v";
+               options = "b:D:d:f:F:o:uU:vX:";
                mode |= SLAP_TOOL_READMAIN | SLAP_TOOL_READONLY;
                break;
 
@@ -262,6 +267,13 @@ slap_tool_init(
                        ber_str2bv( optarg, 0, 0, &mech );
                        break;
 
+               case 'N':
+                       if ( dn_mode && dn_mode != SLAP_TOOL_LDAPDN_NORMAL ) {
+                               usage( tool, progname );
+                       }
+                       dn_mode = SLAP_TOOL_LDAPDN_NORMAL;
+                       break;
+
                case 'n':       /* which config file db to index */
                        dbnum = atoi( optarg );
                        break;
@@ -272,6 +284,13 @@ slap_tool_init(
                        }
                        break;
 
+               case 'P':
+                       if ( dn_mode && dn_mode != SLAP_TOOL_LDAPDN_PRETTY ) {
+                               usage( tool, progname );
+                       }
+                       dn_mode = SLAP_TOOL_LDAPDN_PRETTY;
+                       break;
+
                case 'q':       /* turn on quick */
                        mode |= SLAP_TOOL_QUICK;
                        break;
@@ -360,9 +379,10 @@ slap_tool_init(
        ldap_syslog = 0;
 
        if ( ldiffile == NULL ) {
-               ldiffp = tool == SLAPCAT ? stdout : stdin;
+               dummy.fp = tool == SLAPCAT ? stdout : stdin;
+               ldiffp = &dummy;
 
-       } else if ((ldiffp = fopen( ldiffile, tool == SLAPCAT ? "w" : "r" ))
+       } else if ((ldiffp = ldif_open( ldiffile, tool == SLAPCAT ? "w" : "r" ))
                == NULL )
        {
                perror( ldiffile );
@@ -500,7 +520,7 @@ slap_tool_init(
                /* If the named base is a glue master, operate on the
                 * entire context
                 */
-               if (SLAP_GLUE_INSTANCE(be)) {
+               if ( SLAP_GLUE_INSTANCE( be ) ) {
                        nosubordinates = 1;
                }
 
@@ -560,8 +580,7 @@ startup:;
        mal_leaktrace(1);
 #endif
 
-       if ( !dryrun && slap_startup( be ) ) {
-
+       if ( !dryrun && be && slap_startup( be ) ) {
                switch ( tool ) {
                case SLAPTEST:
                        fprintf( stderr, "slap_startup failed "
@@ -582,8 +601,8 @@ void slap_tool_destroy( void )
 {
        if ( !dryrun ) {
                slap_shutdown( be );
+               slap_destroy();
        }
-       slap_destroy();
 #ifdef SLAPD_MODULES
        if ( slapMode == SLAP_SERVER_MODE ) {
        /* always false. just pulls in necessary symbol references. */