From 8e19437ddc4a7364f5e4784635a75486de2ad798 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Fri, 1 Apr 2005 12:59:26 +0000 Subject: [PATCH] allow slapdn to return the DN in pretty/normal only mode, without diagnostics, to be used as filter (should allow reading from stdin as well) --- servers/slapd/slapcommon.c | 18 ++++++++++++++++-- servers/slapd/slapcommon.h | 4 ++++ servers/slapd/slapdn.c | 23 ++++++++++++++++++----- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/servers/slapd/slapcommon.c b/servers/slapd/slapcommon.c index 1306b88411..e3f94152f3 100644 --- a/servers/slapd/slapcommon.c +++ b/servers/slapd/slapcommon.c @@ -74,7 +74,7 @@ usage( int tool, const char *progname ) break; case SLAPDN: - options = " DN [...]\n"; + options = "\n\t[-N | -P] DN [...]\n"; break; case SLAPINDEX: @@ -194,7 +194,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; @@ -262,6 +262,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 +279,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; diff --git a/servers/slapd/slapcommon.h b/servers/slapd/slapcommon.h index e3def431a5..423f0fbd87 100644 --- a/servers/slapd/slapcommon.h +++ b/servers/slapd/slapcommon.h @@ -56,6 +56,7 @@ typedef struct tool_vars { slap_ssf_t tv_transport_ssf; slap_ssf_t tv_tls_ssf; slap_ssf_t tv_sasl_ssf; + unsigned tv_dn_mode; } tool_vars; extern tool_vars tool_globals; @@ -83,6 +84,9 @@ extern tool_vars tool_globals; #define transport_ssf tool_globals.tv_transport_ssf #define tls_ssf tool_globals.tv_tls_ssf #define sasl_ssf tool_globals.tv_sasl_ssf +#define dn_mode tool_globals.tv_dn_mode +#define SLAP_TOOL_LDAPDN_PRETTY SLAP_LDAPDN_PRETTY +#define SLAP_TOOL_LDAPDN_NORMAL (SLAP_LDAPDN_PRETTY << 1) void slap_tool_init LDAP_P(( const char* name, diff --git a/servers/slapd/slapdn.c b/servers/slapd/slapdn.c index 400d5071db..0119e7fab5 100644 --- a/servers/slapd/slapdn.c +++ b/servers/slapd/slapdn.c @@ -62,11 +62,24 @@ slapdn( int argc, char **argv ) } } else { - fprintf( stderr, "DN: <%s> check succeeded\n" - "normalized: <%s>\n" - "pretty: <%s>\n", - dn.bv_val, - ndn.bv_val, pdn.bv_val ); + switch ( dn_mode ) { + case SLAP_TOOL_LDAPDN_PRETTY: + printf( "%s\n", pdn.bv_val ); + break; + + case SLAP_TOOL_LDAPDN_NORMAL: + printf( "%s\n", ndn.bv_val ); + break; + + default: + printf( "DN: <%s> check succeeded\n" + "normalized: <%s>\n" + "pretty: <%s>\n", + dn.bv_val, + ndn.bv_val, pdn.bv_val ); + break; + } + ch_free( ndn.bv_val ); ch_free( pdn.bv_val ); } -- 2.39.5