ws2_32/tests: Add some tests for opening the Afd device.
[wine.git] / dlls / wldap32 / error.c
blobe7a19144bf22539a89041219492e2eb44e8fd4d7
1 /*
2 * WLDAP32 - LDAP support for Wine
4 * Copyright 2005 Hans Leidekker
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winuser.h"
25 #include "winnls.h"
26 #include "winldap.h"
28 #include "wine/debug.h"
29 #include "winldap_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
33 extern HINSTANCE hwldap32 DECLSPEC_HIDDEN;
35 ULONG map_error( int error )
37 switch (error)
39 case 0: return LDAP_SUCCESS;
40 case -1: return LDAP_SERVER_DOWN;
41 case -2: return LDAP_LOCAL_ERROR;
42 case -3: return LDAP_ENCODING_ERROR;
43 case -4: return LDAP_DECODING_ERROR;
44 case -5: return LDAP_TIMEOUT;
45 case -6: return LDAP_AUTH_UNKNOWN;
46 case -7: return LDAP_FILTER_ERROR;
47 case -8: return LDAP_USER_CANCELLED;
48 case -9: return LDAP_PARAM_ERROR;
49 case -10: return LDAP_NO_MEMORY;
50 case -11: return LDAP_CONNECT_ERROR;
51 case -12: return LDAP_NOT_SUPPORTED;
52 case -13: return LDAP_CONTROL_NOT_FOUND;
53 case -14: return LDAP_NO_RESULTS_RETURNED;
54 case -15: return LDAP_MORE_RESULTS_TO_RETURN;
55 case -16: return LDAP_CLIENT_LOOP;
56 case -17: return LDAP_REFERRAL_LIMIT_EXCEEDED;
57 default: return error;
61 /***********************************************************************
62 * ldap_err2stringA (WLDAP32.@)
64 * See ldap_err2stringW.
66 char * CDECL ldap_err2stringA( ULONG err )
68 static char buf[256] = "";
70 TRACE( "(0x%08x)\n", err );
72 if (err <= LDAP_REFERRAL_LIMIT_EXCEEDED)
73 LoadStringA( hwldap32, err, buf, 256 );
74 else
75 LoadStringA( hwldap32, LDAP_LOCAL_ERROR, buf, 256 );
77 return buf;
80 /***********************************************************************
81 * ldap_err2stringW (WLDAP32.@)
83 * Convert an error code into a string describing the error.
85 * PARAMS
86 * err [I] Error code to convert.
88 * RETURNS
89 * Success: Pointer to a string containing the error description.
90 * Failure: NULL
92 * NOTES
93 * The returned string is statically allocated, you must not
94 * free this string.
96 WCHAR * CDECL ldap_err2stringW( ULONG err )
98 static WCHAR buf[256] = { 0 };
100 TRACE( "(0x%08x)\n", err );
102 if (err <= LDAP_REFERRAL_LIMIT_EXCEEDED)
103 LoadStringW( hwldap32, err, buf, 256 );
104 else
105 LoadStringW( hwldap32, LDAP_LOCAL_ERROR, buf, 256 );
107 return buf;
110 /***********************************************************************
111 * ldap_perror (WLDAP32.@)
113 * Print a given error string.
115 * PARAMS
116 * ld [I] Pointer to an LDAP context.
117 * msg [I] Error string.
119 * RETURNS
120 * Nothing.
122 * NOTES
123 * Like native, this function does nothing.
125 void CDECL ldap_perror( LDAP *ld, const PCHAR msg )
127 TRACE( "(%p, %s)\n", ld, debugstr_a(msg) );
130 /***********************************************************************
131 * ldap_result2error (WLDAP32.@)
133 * Parse an LDAP message and return the error obtained from it.
135 * PARAMS
136 * ld [I] Pointer to an LDAP context.
137 * res [I] Pointer to an LDAPMessage structure.
138 * free [I] Ask for the LDAPMessage structure to be freed.
140 * RETURNS
141 * Success: LDAP_SUCCESS
142 * Failure: An LDAP error code.
144 * NOTES
145 * If not asked for, use ldap_msgfree to free the LDAPMessage.
147 ULONG CDECL ldap_result2error( LDAP *ld, LDAPMessage *res, ULONG free )
149 ULONG ret;
150 int error;
152 TRACE( "(%p, %p, 0x%08x)\n", ld, res, free );
154 if (!ld || !res) return ~0u;
156 ret = map_error( ldap_funcs->fn_ldap_parse_result( CTX(ld), MSG(res), &error, NULL, NULL, NULL, NULL, free ) );
157 if (ret == LDAP_SUCCESS)
158 ret = error;
159 else
160 ret = ~0u;
162 return ret;
165 /***********************************************************************
166 * LdapGetLastError (WLDAP32.@)
168 * Return the last error set by an LDAP function call.
170 * PARAMS
171 * None.
173 * RETURNS
174 * An LDAP error code.
176 ULONG CDECL LdapGetLastError( void )
178 TRACE( "\n" );
179 return GetLastError();
182 static const ULONG errormap[] = {
183 /* LDAP_SUCCESS */ ERROR_SUCCESS,
184 /* LDAP_OPERATIONS_ERROR */ ERROR_OPEN_FAILED,
185 /* LDAP_PROTOCOL_ERROR */ ERROR_INVALID_LEVEL,
186 /* LDAP_TIMELIMIT_EXCEEDED */ ERROR_TIMEOUT,
187 /* LDAP_SIZELIMIT_EXCEEDED */ ERROR_MORE_DATA,
188 /* LDAP_COMPARE_FALSE */ ERROR_DS_GENERIC_ERROR,
189 /* LDAP_COMPARE_TRUE */ ERROR_DS_GENERIC_ERROR,
190 /* LDAP_AUTH_METHOD_NOT_SUPPORTED */ ERROR_ACCESS_DENIED,
191 /* LDAP_STRONG_AUTH_REQUIRED */ ERROR_ACCESS_DENIED,
192 /* LDAP_REFERRAL_V2 */ ERROR_MORE_DATA,
193 /* LDAP_REFERRAL */ ERROR_MORE_DATA,
194 /* LDAP_ADMIN_LIMIT_EXCEEDED */ ERROR_NOT_ENOUGH_QUOTA,
195 /* LDAP_UNAVAILABLE_CRIT_EXTENSION */ ERROR_CAN_NOT_COMPLETE,
196 /* LDAP_CONFIDENTIALITY_REQUIRED */ ERROR_DS_GENERIC_ERROR,
197 /* LDAP_SASL_BIND_IN_PROGRESS */ ERROR_DS_GENERIC_ERROR,
198 /* 0x0f */ ERROR_DS_GENERIC_ERROR,
199 /* LDAP_NO_SUCH_ATTRIBUTE */ ERROR_INVALID_PARAMETER,
200 /* LDAP_UNDEFINED_TYPE */ ERROR_DS_GENERIC_ERROR,
201 /* LDAP_INAPPROPRIATE_MATCHING */ ERROR_INVALID_PARAMETER,
202 /* LDAP_CONSTRAINT_VIOLATION */ ERROR_INVALID_PARAMETER,
203 /* LDAP_ATTRIBUTE_OR_VALUE_EXISTS */ ERROR_ALREADY_EXISTS,
204 /* LDAP_INVALID_SYNTAX */ ERROR_INVALID_NAME,
205 /* 0x16 */ ERROR_DS_GENERIC_ERROR,
206 /* 0x17 */ ERROR_DS_GENERIC_ERROR,
207 /* 0x18 */ ERROR_DS_GENERIC_ERROR,
208 /* 0x19 */ ERROR_DS_GENERIC_ERROR,
209 /* 0x1a */ ERROR_DS_GENERIC_ERROR,
210 /* 0x1b */ ERROR_DS_GENERIC_ERROR,
211 /* 0x1c */ ERROR_DS_GENERIC_ERROR,
212 /* 0x1d */ ERROR_DS_GENERIC_ERROR,
213 /* 0x1e */ ERROR_DS_GENERIC_ERROR,
214 /* 0x1f */ ERROR_DS_GENERIC_ERROR,
215 /* LDAP_NO_SUCH_OBJECT */ ERROR_FILE_NOT_FOUND,
216 /* LDAP_ALIAS_PROBLEM */ ERROR_DS_GENERIC_ERROR,
217 /* LDAP_INVALID_DN_SYNTAX */ ERROR_INVALID_PARAMETER,
218 /* LDAP_IS_LEAF */ ERROR_DS_GENERIC_ERROR,
219 /* LDAP_ALIAS_DEREF_PROBLEM */ ERROR_DS_GENERIC_ERROR,
220 /* 0x25 */ ERROR_DS_GENERIC_ERROR,
221 /* 0x26 */ ERROR_DS_GENERIC_ERROR,
222 /* 0x27 */ ERROR_DS_GENERIC_ERROR,
223 /* 0x28 */ ERROR_DS_GENERIC_ERROR,
224 /* 0x29 */ ERROR_DS_GENERIC_ERROR,
225 /* 0x2a */ ERROR_DS_GENERIC_ERROR,
226 /* 0x2b */ ERROR_DS_GENERIC_ERROR,
227 /* 0x2c */ ERROR_DS_GENERIC_ERROR,
228 /* 0x2d */ ERROR_DS_GENERIC_ERROR,
229 /* 0x2e */ ERROR_DS_GENERIC_ERROR,
230 /* 0x2f */ ERROR_DS_GENERIC_ERROR,
231 /* LDAP_INAPPROPRIATE_AUTH */ ERROR_ACCESS_DENIED,
232 /* LDAP_INVALID_CREDENTIALS */ ERROR_WRONG_PASSWORD,
233 /* LDAP_INSUFFICIENT_RIGHTS */ ERROR_ACCESS_DENIED,
234 /* LDAP_BUSY */ ERROR_BUSY,
235 /* LDAP_UNAVAILABLE */ ERROR_DEV_NOT_EXIST,
236 /* LDAP_UNWILLING_TO_PERFORM */ ERROR_CAN_NOT_COMPLETE,
237 /* LDAP_LOOP_DETECT */ ERROR_DS_GENERIC_ERROR,
238 /* 0x37 */ ERROR_DS_GENERIC_ERROR,
239 /* 0x38 */ ERROR_DS_GENERIC_ERROR,
240 /* 0x39 */ ERROR_DS_GENERIC_ERROR,
241 /* 0x3a */ ERROR_DS_GENERIC_ERROR,
242 /* 0x3b */ ERROR_DS_GENERIC_ERROR,
243 /* LDAP_SORT_CONTROL_MISSING */ 8261,
244 /* LDAP_OFFSET_RANGE_ERROR */ 8262,
245 /* 0x3e */ ERROR_DS_GENERIC_ERROR,
246 /* 0x3f */ ERROR_DS_GENERIC_ERROR,
247 /* LDAP_NAMING_VIOLATION */ ERROR_INVALID_PARAMETER,
248 /* LDAP_OBJECT_CLASS_VIOLATION */ ERROR_INVALID_PARAMETER,
249 /* LDAP_NOT_ALLOWED_ON_NONLEAF */ ERROR_CAN_NOT_COMPLETE,
250 /* LDAP_NOT_ALLOWED_ON_RDN */ ERROR_ACCESS_DENIED,
251 /* LDAP_ALREADY_EXISTS */ ERROR_ALREADY_EXISTS,
252 /* LDAP_NO_OBJECT_CLASS_MODS */ ERROR_ACCESS_DENIED,
253 /* LDAP_RESULTS_TOO_LARGE */ ERROR_INSUFFICIENT_BUFFER,
254 /* LDAP_AFFECTS_MULTIPLE_DSAS */ ERROR_CAN_NOT_COMPLETE,
255 /* 0x48 */ ERROR_DS_GENERIC_ERROR,
256 /* 0x49 */ ERROR_DS_GENERIC_ERROR,
257 /* 0x4a */ ERROR_DS_GENERIC_ERROR,
258 /* 0x4b */ ERROR_DS_GENERIC_ERROR,
259 /* LDAP_VIRTUAL_LIST_VIEW_ERROR */ ERROR_DS_GENERIC_ERROR,
260 /* 0x4d */ ERROR_DS_GENERIC_ERROR,
261 /* 0x4e */ ERROR_DS_GENERIC_ERROR,
262 /* 0x4f */ ERROR_DS_GENERIC_ERROR,
263 /* LDAP_OTHER */ ERROR_DS_GENERIC_ERROR,
264 /* LDAP_SERVER_DOWN */ ERROR_BAD_NET_RESP,
265 /* LDAP_LOCAL_ERROR */ ERROR_DS_GENERIC_ERROR,
266 /* LDAP_ENCODING_ERROR */ ERROR_UNEXP_NET_ERR,
267 /* LDAP_DECODING_ERROR */ ERROR_UNEXP_NET_ERR,
268 /* LDAP_TIMEOUT */ ERROR_SERVICE_REQUEST_TIMEOUT,
269 /* LDAP_AUTH_UNKNOWN */ ERROR_WRONG_PASSWORD,
270 /* LDAP_FILTER_ERROR */ ERROR_INVALID_PARAMETER,
271 /* LDAP_USER_CANCELLED */ ERROR_CANCELLED,
272 /* LDAP_PARAM_ERROR */ ERROR_INVALID_PARAMETER,
273 /* LDAP_NO_MEMORY */ ERROR_NOT_ENOUGH_MEMORY,
274 /* LDAP_CONNECT_ERROR */ ERROR_CONNECTION_REFUSED,
275 /* LDAP_NOT_SUPPORTED */ ERROR_CAN_NOT_COMPLETE,
276 /* LDAP_CONTROL_NOT_FOUND */ ERROR_NOT_FOUND,
277 /* LDAP_NO_RESULTS_RETURNED */ ERROR_MORE_DATA,
278 /* LDAP_MORE_RESULTS_TO_RETURN */ ERROR_MORE_DATA,
279 /* LDAP_CLIENT_LOOP */ ERROR_DS_GENERIC_ERROR,
280 /* LDAP_REFERRAL_LIMIT_EXCEEDED */ ERROR_DS_GENERIC_ERROR
283 /***********************************************************************
284 * LdapMapErrorToWin32 (WLDAP32.@)
286 * Map an LDAP error code to a Win32 error code.
288 * PARAMS
289 * err [I] An LDAP error code.
291 * RETURNS
292 * A Win32 error code.
294 ULONG CDECL LdapMapErrorToWin32( ULONG err )
296 TRACE( "(0x%08x)\n", err );
298 if (err >= ARRAY_SIZE( errormap )) return ERROR_DS_GENERIC_ERROR;
299 return errormap[err];