No empty .Rs/.Re
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / slapdn.c
blob2aa12232b23e50ac1c4c57836ac3852ce6771415
1 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3 * Copyright 2004-2008 The OpenLDAP Foundation.
4 * Portions Copyright 2004 Pierangelo Masarati.
5 * All rights reserved.
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.
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>.
15 /* ACKNOWLEDGEMENTS:
16 * This work was initially developed by Pierangelo Masarati for inclusion
17 * in OpenLDAP Software.
20 #include "portable.h"
22 #include <stdio.h>
24 #include <ac/stdlib.h>
26 #include <ac/ctype.h>
27 #include <ac/string.h>
28 #include <ac/socket.h>
29 #include <ac/unistd.h>
31 #include <lber.h>
32 #include <ldif.h>
33 #include <lutil.h>
35 #include "slapcommon.h"
37 int
38 slapdn( int argc, char **argv )
40 int rc = 0;
41 const char *progname = "slapdn";
43 slap_tool_init( progname, SLAPDN, argc, argv );
45 argv = &argv[ optind ];
46 argc -= optind;
48 for ( ; argc--; argv++ ) {
49 struct berval dn,
50 pdn = BER_BVNULL,
51 ndn = BER_BVNULL;
53 ber_str2bv( argv[ 0 ], 0, 0, &dn );
55 switch ( dn_mode ) {
56 case SLAP_TOOL_LDAPDN_PRETTY:
57 rc = dnPretty( NULL, &dn, &pdn, NULL );
58 break;
60 case SLAP_TOOL_LDAPDN_NORMAL:
61 rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL );
62 break;
64 default:
65 rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
66 break;
69 if ( rc != LDAP_SUCCESS ) {
70 fprintf( stderr, "DN: <%s> check failed %d (%s)\n",
71 dn.bv_val, rc,
72 ldap_err2string( rc ) );
73 if ( !continuemode ) {
74 rc = -1;
75 break;
78 } else {
79 switch ( dn_mode ) {
80 case SLAP_TOOL_LDAPDN_PRETTY:
81 printf( "%s\n", pdn.bv_val );
82 break;
84 case SLAP_TOOL_LDAPDN_NORMAL:
85 printf( "%s\n", ndn.bv_val );
86 break;
88 default:
89 printf( "DN: <%s> check succeeded\n"
90 "normalized: <%s>\n"
91 "pretty: <%s>\n",
92 dn.bv_val,
93 ndn.bv_val, pdn.bv_val );
94 break;
97 ch_free( ndn.bv_val );
98 ch_free( pdn.bv_val );
102 slap_tool_destroy();
104 return rc;