2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 2004-2009 The OpenLDAP Foundation.
5 * Portions Copyright 2004 Pierangelo Masarati.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by Pierangelo Masarati for inclusion
18 * in OpenLDAP Software.
25 #include <ac/stdlib.h>
28 #include <ac/string.h>
29 #include <ac/socket.h>
30 #include <ac/unistd.h>
36 #include "slapcommon.h"
39 slapdn( int argc, char **argv )
42 const char *progname = "slapdn";
44 slap_tool_init( progname, SLAPDN, argc, argv );
46 argv = &argv[ optind ];
49 for ( ; argc--; argv++ ) {
54 ber_str2bv( argv[ 0 ], 0, 0, &dn );
57 case SLAP_TOOL_LDAPDN_PRETTY:
58 rc = dnPretty( NULL, &dn, &pdn, NULL );
61 case SLAP_TOOL_LDAPDN_NORMAL:
62 rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL );
66 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
70 if ( rc != LDAP_SUCCESS ) {
71 fprintf( stderr, "DN: <%s> check failed %d (%s)\n",
73 ldap_err2string( rc ) );
74 if ( !continuemode ) {
81 case SLAP_TOOL_LDAPDN_PRETTY:
82 printf( "%s\n", pdn.bv_val );
85 case SLAP_TOOL_LDAPDN_NORMAL:
86 printf( "%s\n", ndn.bv_val );
90 printf( "DN: <%s> check succeeded\n"
94 ndn.bv_val, pdn.bv_val );
98 ch_free( ndn.bv_val );
99 ch_free( pdn.bv_val );
103 if ( slap_tool_destroy())