~ttx/openldap/lucid-gssapi-495418

« back to all changes in this revision

Viewing changes to servers/slapd/slapdn.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2008-07-10 14:45:49 UTC
  • Revision ID: james.westby@ubuntu.com-20080710144549-wck73med0e72gfyo
Tags: upstream-2.4.10
ImportĀ upstreamĀ versionĀ 2.4.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
 
2
 *
 
3
 * Copyright 2004-2008 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,
 
50
                                pdn = BER_BVNULL,
 
51
                                ndn = BER_BVNULL;
 
52
 
 
53
                ber_str2bv( argv[ 0 ], 0, 0, &dn );
 
54
 
 
55
                switch ( dn_mode ) {
 
56
                case SLAP_TOOL_LDAPDN_PRETTY:
 
57
                        rc = dnPretty( NULL, &dn, &pdn, NULL );
 
58
                        break;
 
59
 
 
60
                case SLAP_TOOL_LDAPDN_NORMAL:
 
61
                        rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL );
 
62
                        break;
 
63
 
 
64
                default:
 
65
                        rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn, NULL );
 
66
                        break;
 
67
                }
 
68
 
 
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;
 
76
                        }
 
77
                        
 
78
                } else {
 
79
                        switch ( dn_mode ) {
 
80
                        case SLAP_TOOL_LDAPDN_PRETTY:
 
81
                                printf( "%s\n", pdn.bv_val );
 
82
                                break;
 
83
 
 
84
                        case SLAP_TOOL_LDAPDN_NORMAL:
 
85
                                printf( "%s\n", ndn.bv_val );
 
86
                                break;
 
87
 
 
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;
 
95
                        }
 
96
 
 
97
                        ch_free( ndn.bv_val );
 
98
                        ch_free( pdn.bv_val );
 
99
                }
 
100
        }
 
101
        
 
102
        slap_tool_destroy();
 
103
 
 
104
        return rc;
 
105
}