]> git.sur5r.net Git - openldap/blob - servers/slapd/slapdn.c
ITS#3579 fix init order
[openldap] / servers / slapd / slapdn.c
1 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
2  *
3  * Copyright 2004-2005 The OpenLDAP Foundation.
4  * Portions Copyright 2004 Pierangelo Masarati.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
11  * A copy of this license is available in file LICENSE in the
12  * top-level directory of the distribution or, alternatively, at
13  * <http://www.OpenLDAP.org/license.html>.
14  */
15 /* ACKNOWLEDGEMENTS:
16  * This work was initially developed by Pierangelo Masarati for inclusion
17  * in OpenLDAP Software.
18  */
19
20 #include "portable.h"
21
22 #include <stdio.h>
23
24 #include <ac/stdlib.h>
25
26 #include <ac/ctype.h>
27 #include <ac/string.h>
28 #include <ac/socket.h>
29 #include <ac/unistd.h>
30
31 #include <lber.h>
32 #include <ldif.h>
33 #include <lutil.h>
34
35 #include "slapcommon.h"
36
37 int
38 slapdn( int argc, char **argv )
39 {
40         int                     rc = EXIT_SUCCESS;
41         const char              *progname = "slapdn";
42
43 #ifdef NEW_LOGGING
44         lutil_log_initialize( argc, argv );
45 #endif
46         slap_tool_init( progname, SLAPDN, argc, argv );
47
48         argv = &argv[ optind ];
49         argc -= optind;
50
51         for ( ; argc--; argv++ ) {
52                 struct berval   dn, pdn, ndn;
53
54                 dn.bv_val = argv[ 0 ];
55                 dn.bv_len = strlen( argv[ 0 ] );
56
57                 rc = dnPrettyNormal( NULL, &dn,
58                                         &pdn, &ndn, NULL );
59                 if ( rc != LDAP_SUCCESS ) {
60                         fprintf( stderr, "DN: <%s> check failed %d (%s)\n",
61                                         dn.bv_val, rc,
62                                         ldap_err2string( rc ) );
63                         rc = 1;
64                         
65                 } else {
66                         fprintf( stderr, "DN: <%s> check succeeded\n"
67                                         "normalized: <%s>\n"
68                                         "pretty:     <%s>\n",
69                                         dn.bv_val,
70                                         ndn.bv_val, pdn.bv_val );
71                         ch_free( ndn.bv_val );
72                         ch_free( pdn.bv_val );
73                         rc = 0;
74                 }
75         }
76         
77         slap_tool_destroy();
78
79         return rc;
80 }