~ubuntu-branches/ubuntu/maverick/openldap/maverick-proposed

« back to all changes in this revision

Viewing changes to libraries/libldap/error.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2009-09-07 13:41:10 UTC
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: james.westby@ubuntu.com-20090907134110-jsdrvn0atu1fex4m
Tags: upstream-2.4.18
ImportĀ upstreamĀ versionĀ 2.4.18

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $OpenLDAP: pkg/ldap/libraries/libldap/error.c,v 1.76.2.4 2009/01/22 00:00:54 kurt Exp $ */
 
1
/* $OpenLDAP: pkg/ldap/libraries/libldap/error.c,v 1.76.2.6 2009/08/12 23:54:21 quanah Exp $ */
2
2
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3
3
 *
4
4
 * Copyright 1998-2009 The OpenLDAP Foundation.
25
25
 
26
26
#include "ldap-int.h"
27
27
 
28
 
struct ldaperror {
29
 
        int     e_code;
30
 
        char *e_reason;
31
 
};
32
 
 
33
 
static struct ldaperror ldap_builtin_errlist[] = {
34
 
        {LDAP_SUCCESS,                                  N_("Success")},
35
 
        {LDAP_OPERATIONS_ERROR,                 N_("Operations error")},
36
 
        {LDAP_PROTOCOL_ERROR,                   N_("Protocol error")},
37
 
        {LDAP_TIMELIMIT_EXCEEDED,               N_("Time limit exceeded")},
38
 
        {LDAP_SIZELIMIT_EXCEEDED,               N_("Size limit exceeded")},
39
 
        {LDAP_COMPARE_FALSE,                    N_("Compare False")},
40
 
        {LDAP_COMPARE_TRUE,                     N_("Compare True")},
41
 
        {LDAP_STRONG_AUTH_NOT_SUPPORTED, N_("Authentication method not supported")},
42
 
        {LDAP_STRONG_AUTH_REQUIRED,     N_("Strong(er) authentication required")},
43
 
        {LDAP_PARTIAL_RESULTS,                  N_("Partial results and referral received")},
44
 
 
45
 
        {LDAP_REFERRAL,                                 N_("Referral")},
46
 
        {LDAP_ADMINLIMIT_EXCEEDED,              N_("Administrative limit exceeded")},
47
 
        {LDAP_UNAVAILABLE_CRITICAL_EXTENSION,
48
 
                                                                        N_("Critical extension is unavailable")},
49
 
        {LDAP_CONFIDENTIALITY_REQUIRED, N_("Confidentiality required")},
50
 
        {LDAP_SASL_BIND_IN_PROGRESS,    N_("SASL bind in progress")},
51
 
 
52
 
        {LDAP_NO_SUCH_ATTRIBUTE,                N_("No such attribute")},
53
 
        {LDAP_UNDEFINED_TYPE,                   N_("Undefined attribute type")},
54
 
        {LDAP_INAPPROPRIATE_MATCHING,   N_("Inappropriate matching")},
55
 
        {LDAP_CONSTRAINT_VIOLATION,     N_("Constraint violation")},
56
 
        {LDAP_TYPE_OR_VALUE_EXISTS,     N_("Type or value exists")},
57
 
        {LDAP_INVALID_SYNTAX,                   N_("Invalid syntax")},
58
 
 
59
 
        {LDAP_NO_SUCH_OBJECT,                   N_("No such object")},
60
 
        {LDAP_ALIAS_PROBLEM,                    N_("Alias problem")},
61
 
        {LDAP_INVALID_DN_SYNTAX,                N_("Invalid DN syntax")},
62
 
        {LDAP_IS_LEAF,                                  N_("Entry is a leaf")},
63
 
        {LDAP_ALIAS_DEREF_PROBLEM,              N_("Alias dereferencing problem")},
64
 
 
65
 
        {LDAP_INAPPROPRIATE_AUTH,               N_("Inappropriate authentication")},
66
 
        {LDAP_INVALID_CREDENTIALS,              N_("Invalid credentials")},
67
 
        {LDAP_INSUFFICIENT_ACCESS,              N_("Insufficient access")},
68
 
        {LDAP_BUSY,                                     N_("Server is busy")},
69
 
        {LDAP_UNAVAILABLE,                              N_("Server is unavailable")},
70
 
        {LDAP_UNWILLING_TO_PERFORM,     N_("Server is unwilling to perform")},
71
 
        {LDAP_LOOP_DETECT,                              N_("Loop detected")},
72
 
 
73
 
        {LDAP_NAMING_VIOLATION,                 N_("Naming violation")},
74
 
        {LDAP_OBJECT_CLASS_VIOLATION,   N_("Object class violation")},
75
 
        {LDAP_NOT_ALLOWED_ON_NONLEAF,   N_("Operation not allowed on non-leaf")},
76
 
        {LDAP_NOT_ALLOWED_ON_RDN,               N_("Operation not allowed on RDN")},
77
 
        {LDAP_ALREADY_EXISTS,                   N_("Already exists")},
78
 
        {LDAP_NO_OBJECT_CLASS_MODS,     N_("Cannot modify object class")},
79
 
        {LDAP_RESULTS_TOO_LARGE,                N_("Results too large")},
80
 
        {LDAP_AFFECTS_MULTIPLE_DSAS,    N_("Operation affects multiple DSAs")},
81
 
 
82
 
        {LDAP_OTHER,                                    N_("Other (e.g., implementation specific) error")},
83
 
 
84
 
        {LDAP_CANCELLED,                                N_("Cancelled")},
85
 
        {LDAP_NO_SUCH_OPERATION,                N_("No Operation to Cancel")},
86
 
        {LDAP_TOO_LATE,                                 N_("Too Late to Cancel")},
87
 
        {LDAP_CANNOT_CANCEL,                    N_("Cannot Cancel")},
88
 
 
89
 
        {LDAP_ASSERTION_FAILED,                 N_("Assertion Failed")},
90
 
        {LDAP_X_ASSERTION_FAILED,               N_("Assertion Failed (X)")},
91
 
 
92
 
        {LDAP_PROXIED_AUTHORIZATION_DENIED, N_("Proxied Authorization Denied")},
93
 
        {LDAP_X_PROXY_AUTHZ_FAILURE,            N_("Proxy Authorization Failure (X)")},
94
 
 
95
 
        {LDAP_SYNC_REFRESH_REQUIRED,    N_("Content Sync Refresh Required")},
96
 
        {LDAP_X_SYNC_REFRESH_REQUIRED,  N_("Content Sync Refresh Required (X)")},
97
 
 
98
 
        {LDAP_X_NO_OPERATION,                   N_("No Operation (X)")},
99
 
 
100
 
        {LDAP_CUP_RESOURCES_EXHAUSTED,  N_("LCUP Resources Exhausted")},
101
 
        {LDAP_CUP_SECURITY_VIOLATION,   N_("LCUP Security Violation")},
102
 
        {LDAP_CUP_INVALID_DATA,                 N_("LCUP Invalid Data")},
103
 
        {LDAP_CUP_UNSUPPORTED_SCHEME,   N_("LCUP Unsupported Scheme")},
104
 
        {LDAP_CUP_RELOAD_REQUIRED,              N_("LCUP Reload Required")},
105
 
 
106
 
#ifdef LDAP_X_TXN
107
 
        {LDAP_X_TXN_SPECIFY_OKAY,               N_("TXN specify okay")},
108
 
        {LDAP_X_TXN_ID_INVALID,                 N_("TXN ID is invalid")},
109
 
#endif
110
 
 
111
 
        /* API ResultCodes */
112
 
        {LDAP_SERVER_DOWN,                              N_("Can't contact LDAP server")},
113
 
        {LDAP_LOCAL_ERROR,                              N_("Local error")},
114
 
        {LDAP_ENCODING_ERROR,                   N_("Encoding error")},
115
 
        {LDAP_DECODING_ERROR,                   N_("Decoding error")},
116
 
        {LDAP_TIMEOUT,                                  N_("Timed out")},
117
 
        {LDAP_AUTH_UNKNOWN,                             N_("Unknown authentication method")},
118
 
        {LDAP_FILTER_ERROR,                             N_("Bad search filter")},
119
 
        {LDAP_USER_CANCELLED,                   N_("User cancelled operation")},
120
 
        {LDAP_PARAM_ERROR,                              N_("Bad parameter to an ldap routine")},
121
 
        {LDAP_NO_MEMORY,                                N_("Out of memory")},
122
 
 
123
 
        {LDAP_CONNECT_ERROR,                    N_("Connect error")},
124
 
        {LDAP_NOT_SUPPORTED,                    N_("Not Supported")},
125
 
        {LDAP_CONTROL_NOT_FOUND,                N_("Control not found")},
126
 
        {LDAP_NO_RESULTS_RETURNED,              N_("No results returned")},
127
 
        {LDAP_MORE_RESULTS_TO_RETURN,   N_("More results to return")},
128
 
        {LDAP_CLIENT_LOOP,                              N_("Client Loop")},
129
 
        {LDAP_REFERRAL_LIMIT_EXCEEDED,  N_("Referral Limit Exceeded")},
130
 
 
131
 
        {0, NULL}
132
 
};
133
 
 
134
 
static struct ldaperror *ldap_errlist = ldap_builtin_errlist; 
135
 
 
136
28
void ldap_int_error_init( void ) {
137
29
}
138
30
 
139
 
static const struct ldaperror *
140
 
ldap_int_error( int err )
141
 
{
142
 
        int     i;
143
 
 
144
 
        /* XXYYZ: O(n) search instead of O(1) lookup */
145
 
        for ( i=0; ldap_errlist[i].e_reason != NULL; i++ ) {
146
 
                if ( err == ldap_errlist[i].e_code ) {
147
 
                        return &ldap_errlist[i];
148
 
                }
149
 
        }
150
 
 
151
 
        return NULL;
152
 
}
153
 
 
154
31
char *
155
32
ldap_err2string( int err )
156
33
{
157
 
        const struct ldaperror *e;
158
 
        
 
34
        char *m;
 
35
 
159
36
        Debug( LDAP_DEBUG_TRACE, "ldap_err2string\n", 0, 0, 0 );
160
37
 
161
 
        e = ldap_int_error( err );
162
 
 
163
 
        if (e) {
164
 
                return e->e_reason;
165
 
 
166
 
        } else if ( LDAP_API_ERROR(err) ) {
167
 
                return _("Unknown API error");
168
 
 
169
 
        } else if ( LDAP_E_ERROR(err) ) {
170
 
                return _("Unknown (extension) error");
171
 
 
172
 
        } else if ( LDAP_X_ERROR(err) ) {
173
 
                return _("Unknown (private extension) error");
 
38
        switch ( err ) {
 
39
#       define C(code, message) case code: m = message; break
 
40
 
 
41
        /* LDAPv3 (RFC 4511) codes */
 
42
        C(LDAP_SUCCESS,                                 N_("Success"));
 
43
        C(LDAP_OPERATIONS_ERROR,                N_("Operations error"));
 
44
        C(LDAP_PROTOCOL_ERROR,                  N_("Protocol error"));
 
45
        C(LDAP_TIMELIMIT_EXCEEDED,              N_("Time limit exceeded"));
 
46
        C(LDAP_SIZELIMIT_EXCEEDED,              N_("Size limit exceeded"));
 
47
        C(LDAP_COMPARE_FALSE,                   N_("Compare False"));
 
48
        C(LDAP_COMPARE_TRUE,                    N_("Compare True"));
 
49
        C(LDAP_STRONG_AUTH_NOT_SUPPORTED,N_("Authentication method not supported"));
 
50
        C(LDAP_STRONG_AUTH_REQUIRED,    N_("Strong(er) authentication required"));
 
51
 
 
52
        C(LDAP_REFERRAL,                                N_("Referral"));
 
53
        C(LDAP_ADMINLIMIT_EXCEEDED,             N_("Administrative limit exceeded"));
 
54
        C(LDAP_UNAVAILABLE_CRITICAL_EXTENSION,
 
55
                                                                        N_("Critical extension is unavailable"));
 
56
        C(LDAP_CONFIDENTIALITY_REQUIRED,N_("Confidentiality required"));
 
57
        C(LDAP_SASL_BIND_IN_PROGRESS,   N_("SASL bind in progress"));
 
58
 
 
59
        C(LDAP_NO_SUCH_ATTRIBUTE,               N_("No such attribute"));
 
60
        C(LDAP_UNDEFINED_TYPE,                  N_("Undefined attribute type"));
 
61
        C(LDAP_INAPPROPRIATE_MATCHING,  N_("Inappropriate matching"));
 
62
        C(LDAP_CONSTRAINT_VIOLATION,    N_("Constraint violation"));
 
63
        C(LDAP_TYPE_OR_VALUE_EXISTS,    N_("Type or value exists"));
 
64
        C(LDAP_INVALID_SYNTAX,                  N_("Invalid syntax"));
 
65
 
 
66
        C(LDAP_NO_SUCH_OBJECT,                  N_("No such object"));
 
67
        C(LDAP_ALIAS_PROBLEM,                   N_("Alias problem"));
 
68
        C(LDAP_INVALID_DN_SYNTAX,               N_("Invalid DN syntax"));
 
69
 
 
70
        C(LDAP_ALIAS_DEREF_PROBLEM,             N_("Alias dereferencing problem"));
 
71
 
 
72
        C(LDAP_INAPPROPRIATE_AUTH,              N_("Inappropriate authentication"));
 
73
        C(LDAP_INVALID_CREDENTIALS,     N_("Invalid credentials"));
 
74
        C(LDAP_INSUFFICIENT_ACCESS,     N_("Insufficient access"));
 
75
        C(LDAP_BUSY,                                    N_("Server is busy"));
 
76
        C(LDAP_UNAVAILABLE,                     N_("Server is unavailable"));
 
77
        C(LDAP_UNWILLING_TO_PERFORM,    N_("Server is unwilling to perform"));
 
78
        C(LDAP_LOOP_DETECT,                     N_("Loop detected"));
 
79
 
 
80
        C(LDAP_NAMING_VIOLATION,                N_("Naming violation"));
 
81
        C(LDAP_OBJECT_CLASS_VIOLATION,  N_("Object class violation"));
 
82
        C(LDAP_NOT_ALLOWED_ON_NONLEAF,  N_("Operation not allowed on non-leaf"));
 
83
        C(LDAP_NOT_ALLOWED_ON_RDN,              N_("Operation not allowed on RDN"));
 
84
        C(LDAP_ALREADY_EXISTS,                  N_("Already exists"));
 
85
        C(LDAP_NO_OBJECT_CLASS_MODS,    N_("Cannot modify object class"));
 
86
 
 
87
        C(LDAP_AFFECTS_MULTIPLE_DSAS,   N_("Operation affects multiple DSAs"));
 
88
 
 
89
        /* Virtual List View draft */
 
90
        C(LDAP_VLV_ERROR,                               N_("Virtual List View error"));
 
91
 
 
92
        C(LDAP_OTHER, N_("Other (e.g., implementation specific) error"));
 
93
 
 
94
        /* LDAPv2 (RFC 1777) codes */
 
95
        C(LDAP_PARTIAL_RESULTS, N_("Partial results and referral received"));
 
96
        C(LDAP_IS_LEAF,                                 N_("Entry is a leaf"));
 
97
 
 
98
        /* Connection-less LDAP (CLDAP - RFC 1798) code */
 
99
        C(LDAP_RESULTS_TOO_LARGE,               N_("Results too large"));
 
100
 
 
101
        /* Cancel Operation (RFC 3909) codes */
 
102
        C(LDAP_CANCELLED,                               N_("Cancelled"));
 
103
        C(LDAP_NO_SUCH_OPERATION,               N_("No Operation to Cancel"));
 
104
        C(LDAP_TOO_LATE,                                N_("Too Late to Cancel"));
 
105
        C(LDAP_CANNOT_CANCEL,                   N_("Cannot Cancel"));
 
106
 
 
107
        /* Assert Control (RFC 4528 and old internet-draft) codes */
 
108
        C(LDAP_ASSERTION_FAILED,                N_("Assertion Failed"));
 
109
        C(LDAP_X_ASSERTION_FAILED,              N_("Assertion Failed (X)"));
 
110
 
 
111
        /* Proxied Authorization Control (RFC 4370 and I-D) codes */
 
112
        C(LDAP_PROXIED_AUTHORIZATION_DENIED, N_("Proxied Authorization Denied"));
 
113
        C(LDAP_X_PROXY_AUTHZ_FAILURE,   N_("Proxy Authorization Failure (X)"));
 
114
 
 
115
        /* Content Sync Operation (RFC 4533 and I-D) codes */
 
116
        C(LDAP_SYNC_REFRESH_REQUIRED,   N_("Content Sync Refresh Required"));
 
117
        C(LDAP_X_SYNC_REFRESH_REQUIRED, N_("Content Sync Refresh Required (X)"));
 
118
 
 
119
        /* No-Op Control (draft-zeilenga-ldap-noop) code */
 
120
        C(LDAP_X_NO_OPERATION,                  N_("No Operation (X)"));
 
121
 
 
122
        /* Client Update Protocol (RFC 3928) codes */
 
123
        C(LDAP_CUP_RESOURCES_EXHAUSTED, N_("LCUP Resources Exhausted"));
 
124
        C(LDAP_CUP_SECURITY_VIOLATION,  N_("LCUP Security Violation"));
 
125
        C(LDAP_CUP_INVALID_DATA,                N_("LCUP Invalid Data"));
 
126
        C(LDAP_CUP_UNSUPPORTED_SCHEME,  N_("LCUP Unsupported Scheme"));
 
127
        C(LDAP_CUP_RELOAD_REQUIRED,             N_("LCUP Reload Required"));
 
128
 
 
129
#ifdef LDAP_X_TXN
 
130
        /* Codes related to LDAP Transactions (draft-zeilenga-ldap-txn) */
 
131
        C(LDAP_X_TXN_SPECIFY_OKAY,              N_("TXN specify okay"));
 
132
        C(LDAP_X_TXN_ID_INVALID,                N_("TXN ID is invalid"));
 
133
#endif
 
134
 
 
135
        /* API codes - renumbered since draft-ietf-ldapext-ldap-c-api */
 
136
        C(LDAP_SERVER_DOWN,                             N_("Can't contact LDAP server"));
 
137
        C(LDAP_LOCAL_ERROR,                             N_("Local error"));
 
138
        C(LDAP_ENCODING_ERROR,                  N_("Encoding error"));
 
139
        C(LDAP_DECODING_ERROR,                  N_("Decoding error"));
 
140
        C(LDAP_TIMEOUT,                                 N_("Timed out"));
 
141
        C(LDAP_AUTH_UNKNOWN,                    N_("Unknown authentication method"));
 
142
        C(LDAP_FILTER_ERROR,                    N_("Bad search filter"));
 
143
        C(LDAP_USER_CANCELLED,                  N_("User cancelled operation"));
 
144
        C(LDAP_PARAM_ERROR,                             N_("Bad parameter to an ldap routine"));
 
145
        C(LDAP_NO_MEMORY,                               N_("Out of memory"));
 
146
        C(LDAP_CONNECT_ERROR,                   N_("Connect error"));
 
147
        C(LDAP_NOT_SUPPORTED,                   N_("Not Supported"));
 
148
        C(LDAP_CONTROL_NOT_FOUND,               N_("Control not found"));
 
149
        C(LDAP_NO_RESULTS_RETURNED,             N_("No results returned"));
 
150
        C(LDAP_MORE_RESULTS_TO_RETURN,  N_("More results to return"));
 
151
        C(LDAP_CLIENT_LOOP,                             N_("Client Loop"));
 
152
        C(LDAP_REFERRAL_LIMIT_EXCEEDED, N_("Referral Limit Exceeded"));
 
153
#       undef C
 
154
 
 
155
        default:
 
156
                m = (LDAP_API_ERROR(err) ? N_("Unknown API error")
 
157
                         : LDAP_E_ERROR(err) ? N_("Unknown (extension) error")
 
158
                         : LDAP_X_ERROR(err) ? N_("Unknown (private extension) error")
 
159
                         : N_("Unknown error"));
 
160
                break;
174
161
        }
175
162
 
176
 
        return _("Unknown error");
 
163
        return _(m);
177
164
}
178
165
 
179
166
/* deprecated */
181
168
ldap_perror( LDAP *ld, LDAP_CONST char *str )
182
169
{
183
170
    int i;
184
 
        const struct ldaperror *e;
185
 
        Debug( LDAP_DEBUG_TRACE, "ldap_perror\n", 0, 0, 0 );
186
171
 
187
172
        assert( ld != NULL );
188
173
        assert( LDAP_VALID( ld ) );
189
174
        assert( str != NULL );
190
175
 
191
 
        e = ldap_int_error( ld->ld_errno );
192
 
 
193
176
        fprintf( stderr, "%s: %s (%d)\n",
194
177
                str ? str : "ldap_perror",
195
 
                e ? _(e->e_reason) : _("unknown result code"),
 
178
                ldap_err2string( ld->ld_errno ),
196
179
                ld->ld_errno );
197
180
 
198
181
        if ( ld->ld_matched != NULL && ld->ld_matched[0] != '\0' ) {