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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
24 #include "wine/debug.h"
36 #define LDAP_SUCCESS 0x00
37 #define LDAP_NOT_SUPPORTED 0x5c
40 #include "winldap_private.h"
43 extern HINSTANCE hwldap32;
45 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
47 /***********************************************************************
48 * ldap_err2stringA (WLDAP32.@)
50 * See ldap_err2stringW.
52 PCHAR ldap_err2stringA( ULONG err )
54 static char buf[256] = "";
56 TRACE( "(0x%08lx)\n", err );
58 if (err <= WLDAP32_LDAP_REFERRAL_LIMIT_EXCEEDED)
59 LoadStringA( hwldap32, err, buf, 256 );
61 LoadStringA( hwldap32, WLDAP32_LDAP_LOCAL_ERROR, buf, 256 );
66 /***********************************************************************
67 * ldap_err2stringW (WLDAP32.@)
69 * Convert an error code into a string describing the error.
72 * err [I] Error code to convert.
75 * Success: Pointer to a string containing the error description.
79 * The returned string is statically allocated, you must not
82 PWCHAR ldap_err2stringW( ULONG err )
84 static WCHAR buf[256] = { 0 };
86 TRACE( "(0x%08lx)\n", err );
88 if (err <= WLDAP32_LDAP_REFERRAL_LIMIT_EXCEEDED)
89 LoadStringW( hwldap32, err, buf, 256 );
91 LoadStringW( hwldap32, WLDAP32_LDAP_LOCAL_ERROR, buf, 256 );
96 /***********************************************************************
97 * ldap_perror (WLDAP32.@)
99 * Print a given error string.
102 * ld [I] Pointer to an LDAP context.
103 * msg [I] Error string.
109 * Like native, this function does nothing.
111 void WLDAP32_ldap_perror( WLDAP32_LDAP *ld, const PCHAR msg )
113 TRACE( "(%p, %s)\n", ld, debugstr_a(msg) );
116 /***********************************************************************
117 * ldap_result2error (WLDAP32.@)
119 * Parse an LDAP message and return the error obtained from it.
122 * ld [I] Pointer to an LDAP context.
123 * res [I] Pointer to an LDAPMessage structure.
124 * free [I] Ask for the LDAPMessage structure to be freed.
127 * Success: LDAP_SUCCESS
128 * Failure: An LDAP error code.
131 * If not asked for, use ldap_msgfree to free the LDAPMessage.
133 ULONG WLDAP32_ldap_result2error( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *res, ULONG free )
135 ULONG ret = LDAP_NOT_SUPPORTED;
139 TRACE( "(%p, %p, 0x%08lx)\n", ld, res, free );
141 if (!ld || !res) return ~0UL;
143 ret = ldap_parse_result( ld, res, &error, NULL, NULL, NULL, NULL, free );
145 if (ret == LDAP_SUCCESS)
154 /***********************************************************************
155 * LdapGetLastError (WLDAP32.@)
157 * Return the last error set by an LDAP function call.
163 * An LDAP error code.
165 ULONG LdapGetLastError( void )
168 return GetLastError();
171 static const ULONG WLDAP32_errormap[] = {
172 /* LDAP_SUCCESS */ ERROR_SUCCESS,
173 /* LDAP_OPERATIONS_ERROR */ ERROR_OPEN_FAILED,
174 /* LDAP_PROTOCOL_ERROR */ ERROR_INVALID_LEVEL,
175 /* LDAP_TIMELIMIT_EXCEEDED */ ERROR_TIMEOUT,
176 /* LDAP_SIZELIMIT_EXCEEDED */ ERROR_MORE_DATA,
177 /* LDAP_COMPARE_FALSE */ ERROR_DS_GENERIC_ERROR,
178 /* LDAP_COMPARE_TRUE */ ERROR_DS_GENERIC_ERROR,
179 /* LDAP_AUTH_METHOD_NOT_SUPPORTED */ ERROR_ACCESS_DENIED,
180 /* LDAP_STRONG_AUTH_REQUIRED */ ERROR_ACCESS_DENIED,
181 /* LDAP_REFERRAL_V2 */ ERROR_MORE_DATA,
182 /* LDAP_REFERRAL */ ERROR_MORE_DATA,
183 /* LDAP_ADMIN_LIMIT_EXCEEDED */ ERROR_NOT_ENOUGH_QUOTA,
184 /* LDAP_UNAVAILABLE_CRIT_EXTENSION */ ERROR_CAN_NOT_COMPLETE,
185 /* LDAP_CONFIDENTIALITY_REQUIRED */ ERROR_DS_GENERIC_ERROR,
186 /* LDAP_SASL_BIND_IN_PROGRESS */ ERROR_DS_GENERIC_ERROR,
187 /* 0x0f */ ERROR_DS_GENERIC_ERROR,
188 /* LDAP_NO_SUCH_ATTRIBUTE */ ERROR_INVALID_PARAMETER,
189 /* LDAP_UNDEFINED_TYPE */ ERROR_DS_GENERIC_ERROR,
190 /* LDAP_INAPPROPRIATE_MATCHING */ ERROR_INVALID_PARAMETER,
191 /* LDAP_CONSTRAINT_VIOLATION */ ERROR_INVALID_PARAMETER,
192 /* LDAP_ATTRIBUTE_OR_VALUE_EXISTS */ ERROR_ALREADY_EXISTS,
193 /* LDAP_INVALID_SYNTAX */ ERROR_INVALID_NAME,
194 /* 0x16 */ ERROR_DS_GENERIC_ERROR,
195 /* 0x17 */ ERROR_DS_GENERIC_ERROR,
196 /* 0x18 */ ERROR_DS_GENERIC_ERROR,
197 /* 0x19 */ ERROR_DS_GENERIC_ERROR,
198 /* 0x1a */ ERROR_DS_GENERIC_ERROR,
199 /* 0x1b */ ERROR_DS_GENERIC_ERROR,
200 /* 0x1c */ ERROR_DS_GENERIC_ERROR,
201 /* 0x1d */ ERROR_DS_GENERIC_ERROR,
202 /* 0x1e */ ERROR_DS_GENERIC_ERROR,
203 /* 0x1f */ ERROR_DS_GENERIC_ERROR,
204 /* LDAP_NO_SUCH_OBJECT */ ERROR_FILE_NOT_FOUND,
205 /* LDAP_ALIAS_PROBLEM */ ERROR_DS_GENERIC_ERROR,
206 /* LDAP_INVALID_DN_SYNTAX */ ERROR_INVALID_PARAMETER,
207 /* LDAP_IS_LEAF */ ERROR_DS_GENERIC_ERROR,
208 /* LDAP_ALIAS_DEREF_PROBLEM */ ERROR_DS_GENERIC_ERROR,
209 /* 0x25 */ ERROR_DS_GENERIC_ERROR,
210 /* 0x26 */ ERROR_DS_GENERIC_ERROR,
211 /* 0x27 */ ERROR_DS_GENERIC_ERROR,
212 /* 0x28 */ ERROR_DS_GENERIC_ERROR,
213 /* 0x29 */ ERROR_DS_GENERIC_ERROR,
214 /* 0x2a */ ERROR_DS_GENERIC_ERROR,
215 /* 0x2b */ ERROR_DS_GENERIC_ERROR,
216 /* 0x2c */ ERROR_DS_GENERIC_ERROR,
217 /* 0x2d */ ERROR_DS_GENERIC_ERROR,
218 /* 0x2e */ ERROR_DS_GENERIC_ERROR,
219 /* 0x2f */ ERROR_DS_GENERIC_ERROR,
220 /* LDAP_INAPPROPRIATE_AUTH */ ERROR_ACCESS_DENIED,
221 /* LDAP_INVALID_CREDENTIALS */ ERROR_WRONG_PASSWORD,
222 /* LDAP_INSUFFICIENT_RIGHTS */ ERROR_ACCESS_DENIED,
223 /* LDAP_BUSY */ ERROR_BUSY,
224 /* LDAP_UNAVAILABLE */ ERROR_DEV_NOT_EXIST,
225 /* LDAP_UNWILLING_TO_PERFORM */ ERROR_CAN_NOT_COMPLETE,
226 /* LDAP_LOOP_DETECT */ ERROR_DS_GENERIC_ERROR,
227 /* 0x37 */ ERROR_DS_GENERIC_ERROR,
228 /* 0x38 */ ERROR_DS_GENERIC_ERROR,
229 /* 0x39 */ ERROR_DS_GENERIC_ERROR,
230 /* 0x3a */ ERROR_DS_GENERIC_ERROR,
231 /* 0x3b */ ERROR_DS_GENERIC_ERROR,
232 /* LDAP_SORT_CONTROL_MISSING */ 8261,
233 /* LDAP_OFFSET_RANGE_ERROR */ 8262,
234 /* 0x3e */ ERROR_DS_GENERIC_ERROR,
235 /* 0x3f */ ERROR_DS_GENERIC_ERROR,
236 /* LDAP_NAMING_VIOLATION */ ERROR_INVALID_PARAMETER,
237 /* LDAP_OBJECT_CLASS_VIOLATION */ ERROR_INVALID_PARAMETER,
238 /* LDAP_NOT_ALLOWED_ON_NONLEAF */ ERROR_CAN_NOT_COMPLETE,
239 /* LDAP_NOT_ALLOWED_ON_RDN */ ERROR_ACCESS_DENIED,
240 /* LDAP_ALREADY_EXISTS */ ERROR_ALREADY_EXISTS,
241 /* LDAP_NO_OBJECT_CLASS_MODS */ ERROR_ACCESS_DENIED,
242 /* LDAP_RESULTS_TOO_LARGE */ ERROR_INSUFFICIENT_BUFFER,
243 /* LDAP_AFFECTS_MULTIPLE_DSAS */ ERROR_CAN_NOT_COMPLETE,
244 /* 0x48 */ ERROR_DS_GENERIC_ERROR,
245 /* 0x49 */ ERROR_DS_GENERIC_ERROR,
246 /* 0x4a */ ERROR_DS_GENERIC_ERROR,
247 /* 0x4b */ ERROR_DS_GENERIC_ERROR,
248 /* LDAP_VIRTUAL_LIST_VIEW_ERROR */ ERROR_DS_GENERIC_ERROR,
249 /* 0x4d */ ERROR_DS_GENERIC_ERROR,
250 /* 0x4e */ ERROR_DS_GENERIC_ERROR,
251 /* 0x4f */ ERROR_DS_GENERIC_ERROR,
252 /* LDAP_OTHER */ ERROR_DS_GENERIC_ERROR,
253 /* LDAP_SERVER_DOWN */ ERROR_BAD_NET_RESP,
254 /* LDAP_LOCAL_ERROR */ ERROR_DS_GENERIC_ERROR,
255 /* LDAP_ENCODING_ERROR */ ERROR_UNEXP_NET_ERR,
256 /* LDAP_DECODING_ERROR */ ERROR_UNEXP_NET_ERR,
257 /* LDAP_TIMEOUT */ ERROR_SERVICE_REQUEST_TIMEOUT,
258 /* LDAP_AUTH_UNKNOWN */ ERROR_WRONG_PASSWORD,
259 /* LDAP_FILTER_ERROR */ ERROR_INVALID_PARAMETER,
260 /* LDAP_USER_CANCELLED */ ERROR_CANCELLED,
261 /* LDAP_PARAM_ERROR */ ERROR_INVALID_PARAMETER,
262 /* LDAP_NO_MEMORY */ ERROR_NOT_ENOUGH_MEMORY,
263 /* LDAP_CONNECT_ERROR */ ERROR_CONNECTION_REFUSED,
264 /* LDAP_NOT_SUPPORTED */ ERROR_CAN_NOT_COMPLETE,
265 /* LDAP_CONTROL_NOT_FOUND */ ERROR_NOT_FOUND,
266 /* LDAP_NO_RESULTS_RETURNED */ ERROR_MORE_DATA,
267 /* LDAP_MORE_RESULTS_TO_RETURN */ ERROR_MORE_DATA,
268 /* LDAP_CLIENT_LOOP */ ERROR_DS_GENERIC_ERROR,
269 /* LDAP_REFERRAL_LIMIT_EXCEEDED */ ERROR_DS_GENERIC_ERROR
272 /***********************************************************************
273 * LdapMapErrorToWin32 (WLDAP32.@)
275 * Map an LDAP error code to a Win32 error code.
278 * err [I] An LDAP error code.
281 * A Win32 error code.
283 ULONG LdapMapErrorToWin32( ULONG err )
285 TRACE( "(0x%08lx)\n", err );
287 if (err >= sizeof(WLDAP32_errormap)/sizeof(WLDAP32_errormap[0]))
288 return ERROR_DS_GENERIC_ERROR;
289 return WLDAP32_errormap[err];