]> git.sur5r.net Git - openldap/blob - servers/slapd/slapdn.c
e756c5b41dc289a89cbe0b6f95e6c7faa9a6db7e
[openldap] / servers / slapd / slapdn.c
1 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
2  *
3  * Copyright 2004-2007 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 = 0;
41         const char              *progname = "slapdn";
42
43         slap_tool_init( progname, SLAPDN, argc, argv );
44
45         argv = &argv[ optind ];
46         argc -= optind;
47
48         for ( ; argc--; argv++ ) {
49                 struct berval   dn, pdn, ndn;
50
51                 ber_str2bv( argv[ 0 ], 0, 0, &dn );
52
53                 rc = dnPrettyNormal( NULL, &dn,
54                                         &pdn, &ndn, NULL );
55                 if ( rc != LDAP_SUCCESS ) {
56                         fprintf( stderr, "DN: <%s> check failed %d (%s)\n",
57                                         dn.bv_val, rc,
58                                         ldap_err2string( rc ) );
59                         if ( !continuemode ) {
60                                 rc = -1;
61                                 break;
62                         }
63                         
64                 } else {
65                         switch ( dn_mode ) {
66                         case SLAP_TOOL_LDAPDN_PRETTY:
67                                 printf( "%s\n", pdn.bv_val );
68                                 break;
69
70                         case SLAP_TOOL_LDAPDN_NORMAL:
71                                 printf( "%s\n", ndn.bv_val );
72                                 break;
73
74                         default:
75                                 printf( "DN: <%s> check succeeded\n"
76                                                 "normalized: <%s>\n"
77                                                 "pretty:     <%s>\n",
78                                                 dn.bv_val,
79                                                 ndn.bv_val, pdn.bv_val );
80                                 break;
81                         }
82
83                         ch_free( ndn.bv_val );
84                         ch_free( pdn.bv_val );
85                 }
86         }
87         
88         slap_tool_destroy();
89
90         return rc;
91 }