add DN check mode; rework check sinfrastructure

This commit is contained in:
Pierangelo Masarati 2004-03-16 18:36:38 +00:00
parent c9fae6c942
commit a453df6280

View File

@ -116,7 +116,11 @@ static int cnvt_str2int( char *, STRDISP_P, int );
#endif /* LOG_LOCAL4 */ #endif /* LOG_LOCAL4 */
static int check_config = 0; #define CHECK_NONE 0x00
#define CHECK_CONFIG 0x01
#define CHECK_DN 0x02
static int check = CHECK_NONE;
static struct berval check_dn = BER_BVC("");
static int version = 0; static int version = 0;
static void static void
@ -144,6 +148,7 @@ usage( char *name )
#endif #endif
"\t-s level\tSyslog level\n" "\t-s level\tSyslog level\n"
"\t-t\t\tCheck configuration file and exit\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) #if defined(HAVE_SETUID) && defined(HAVE_SETGID)
"\t-u user\t\tUser (id or name) to run as\n" "\t-u user\t\tUser (id or name) to run as\n"
"\t-V\t\tprint version info (-VV only)\n" "\t-V\t\tprint version info (-VV only)\n"
@ -266,7 +271,7 @@ int main( int argc, char **argv )
#endif #endif
while ( (i = getopt( argc, argv, while ( (i = getopt( argc, argv,
"c:d:f:h:s:n:t:T:V" "c:d:D:f:h:s:n:tT:V"
#if LDAP_PF_INET6 #if LDAP_PF_INET6
"46" "46"
#endif #endif
@ -370,8 +375,15 @@ int main( int argc, char **argv )
break; break;
case 't': case 't':
check_config++; check |= CHECK_CONFIG;
break; break;
case 'D':
check |= CHECK_DN;
check_dn.bv_val = optarg;
check_dn.bv_len = strlen( optarg );
break;
case 'V': case 'V':
version++; version++;
break; break;
@ -431,7 +443,7 @@ int main( int argc, char **argv )
Debug( LDAP_DEBUG_ANY, "%s", Versionstr, 0, 0 ); Debug( LDAP_DEBUG_ANY, "%s", Versionstr, 0, 0 );
#endif #endif
if( !check_config && slapd_daemon_init( urls ) != 0 ) { if( check == CHECK_NONE && slapd_daemon_init( urls ) != 0 ) {
rc = 1; rc = 1;
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 ); SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 );
goto stop; goto stop;
@ -532,17 +544,21 @@ int main( int argc, char **argv )
rc = 1; rc = 1;
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 19 ); SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 19 );
if ( check_config ) { if ( check & CHECK_CONFIG ) {
fprintf( stderr, "config check failed\n" ); fprintf( stderr, "config check failed\n" );
} }
goto destroy; goto destroy;
} }
if ( check_config ) { if ( check & CHECK_CONFIG ) {
rc = 0;
fprintf( stderr, "config check succeeded\n" ); fprintf( stderr, "config check succeeded\n" );
goto destroy;
check &= ~CHECK_CONFIG;
if ( check == CHECK_NONE ) {
rc = 0;
goto destroy;
}
} }
if ( glue_sub_init( ) != 0 ) { if ( glue_sub_init( ) != 0 ) {
@ -568,6 +584,32 @@ int main( int argc, char **argv )
goto destroy; 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 #ifdef HAVE_TLS
rc = ldap_pvt_tls_init(); rc = ldap_pvt_tls_init();
if( rc != 0) { if( rc != 0) {