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
23 #include "wine/port.h"
24 #include "wine/debug.h"
35 #define LDAP_NOT_SUPPORTED 0x5c
38 #include "winldap_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
43 ULONG CDECL ldap_parse_extended_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
44 PCHAR *oid, struct WLDAP32_berval **data, BOOLEAN free )
46 ULONG ret = LDAP_NOT_SUPPORTED;
50 TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld, result, oid, data, free );
52 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
53 if (!result) return WLDAP32_LDAP_NO_RESULTS_RETURNED;
55 ret = ldap_parse_extended_resultW( ld, result, &oidW, data, free );
58 *oid = strWtoA( oidW );
59 if (!*oid) ret = WLDAP32_LDAP_NO_MEMORY;
60 ldap_memfreeW( oidW );
67 ULONG CDECL ldap_parse_extended_resultW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
68 PWCHAR *oid, struct WLDAP32_berval **data, BOOLEAN free )
70 ULONG ret = LDAP_NOT_SUPPORTED;
74 TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld, result, oid, data, free );
76 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
77 if (!result) return WLDAP32_LDAP_NO_RESULTS_RETURNED;
79 ret = ldap_parse_extended_result( ld, result, &oidU, (struct berval **)data, free );
82 *oid = strUtoW( oidU );
83 if (!*oid) ret = WLDAP32_LDAP_NO_MEMORY;
91 ULONG CDECL ldap_parse_referenceA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *message,
94 ULONG ret = LDAP_NOT_SUPPORTED;
96 WCHAR **referralsW = NULL;
98 TRACE( "(%p, %p, %p)\n", ld, message, referrals );
100 if (!ld) return ~0UL;
102 ret = ldap_parse_referenceW( ld, message, &referralsW );
104 *referrals = strarrayWtoA( referralsW );
105 ldap_value_freeW( referralsW );
111 ULONG CDECL ldap_parse_referenceW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *message,
114 ULONG ret = LDAP_NOT_SUPPORTED;
115 #ifdef HAVE_LDAP_PARSE_REFERENCE
116 char **referralsU = NULL;
118 TRACE( "(%p, %p, %p)\n", ld, message, referrals );
120 if (!ld) return ~0UL;
122 ret = ldap_parse_reference( ld, message, &referralsU, NULL, 0 );
124 *referrals = strarrayUtoW( referralsU );
125 ldap_memfree( referralsU );
131 ULONG CDECL ldap_parse_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
132 ULONG *retcode, PCHAR *matched, PCHAR *error, PCHAR **referrals,
133 PLDAPControlA **serverctrls, BOOLEAN free )
135 ULONG ret = LDAP_NOT_SUPPORTED;
137 WCHAR **matchedW = NULL, **errorW = NULL, **referralsW = NULL;
138 LDAPControlW **serverctrlsW = NULL;
140 TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld, result, retcode,
141 matched, error, referrals, serverctrls, free );
143 if (!ld) return ~0UL;
145 ret = ldap_parse_resultW( ld, result, retcode, matchedW, errorW,
146 &referralsW, &serverctrlsW, free );
148 matched = strarrayWtoA( matchedW );
149 error = strarrayWtoA( errorW );
151 *referrals = strarrayWtoA( referralsW );
152 *serverctrls = controlarrayWtoA( serverctrlsW );
154 ldap_value_freeW( matchedW );
155 ldap_value_freeW( errorW );
156 ldap_value_freeW( referralsW );
157 ldap_controls_freeW( serverctrlsW );
163 ULONG CDECL ldap_parse_resultW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
164 ULONG *retcode, PWCHAR *matched, PWCHAR *error, PWCHAR **referrals,
165 PLDAPControlW **serverctrls, BOOLEAN free )
167 ULONG ret = LDAP_NOT_SUPPORTED;
169 char **matchedU = NULL, **errorU = NULL, **referralsU = NULL;
170 LDAPControl **serverctrlsU = NULL;
172 TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld, result, retcode,
173 matched, error, referrals, serverctrls, free );
175 if (!ld) return ~0UL;
177 ret = ldap_parse_result( ld, result, (int *)retcode, matchedU, errorU,
178 &referralsU, &serverctrlsU, free );
180 matched = strarrayUtoW( matchedU );
181 error = strarrayUtoW( errorU );
183 *referrals = strarrayUtoW( referralsU );
184 *serverctrls = controlarrayUtoW( serverctrlsU );
186 ldap_memfree( matchedU );
187 ldap_memfree( errorU );
188 ldap_memfree( referralsU );
189 ldap_controls_free( serverctrlsU );
195 ULONG CDECL ldap_parse_sort_controlA( WLDAP32_LDAP *ld, PLDAPControlA *control,
196 ULONG *result, PCHAR *attr )
198 ULONG ret = LDAP_NOT_SUPPORTED;
201 LDAPControlW **controlW = NULL;
203 TRACE( "(%p, %p, %p, %p)\n", ld, control, result, attr );
205 if (!ld) return ~0UL;
208 controlW = controlarrayAtoW( control );
209 if (!controlW) return WLDAP32_LDAP_NO_MEMORY;
212 ret = ldap_parse_sort_controlW( ld, controlW, result, &attrW );
214 *attr = strWtoA( attrW );
215 controlarrayfreeW( controlW );
221 ULONG CDECL ldap_parse_sort_controlW( WLDAP32_LDAP *ld, PLDAPControlW *control,
222 ULONG *result, PWCHAR *attr )
224 ULONG ret = LDAP_NOT_SUPPORTED;
227 LDAPControl **controlU = NULL;
229 TRACE( "(%p, %p, %p, %p)\n", ld, control, result, attr );
231 if (!ld) return ~0UL;
234 controlU = controlarrayWtoU( control );
235 if (!controlU) return WLDAP32_LDAP_NO_MEMORY;
238 ret = ldap_parse_sort_control( ld, controlU, result, &attrU );
240 *attr = strUtoW( attrU );
241 controlarrayfreeU( controlU );
247 INT CDECL ldap_parse_vlv_controlA( WLDAP32_LDAP *ld, PLDAPControlA *control,
248 PULONG targetpos, PULONG listcount,
249 struct WLDAP32_berval **context, PINT errcode )
251 int ret = LDAP_NOT_SUPPORTED;
253 LDAPControlW **controlW = NULL;
255 TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld, control, targetpos,
256 listcount, context, errcode );
258 if (!ld) return ~0UL;
261 controlW = controlarrayAtoW( control );
262 if (!controlW) return WLDAP32_LDAP_NO_MEMORY;
265 ret = ldap_parse_vlv_controlW( ld, controlW, targetpos, listcount,
268 controlarrayfreeW( controlW );
274 INT CDECL ldap_parse_vlv_controlW( WLDAP32_LDAP *ld, PLDAPControlW *control,
275 PULONG targetpos, PULONG listcount,
276 struct WLDAP32_berval **context, PINT errcode )
278 int ret = LDAP_NOT_SUPPORTED;
280 LDAPControl **controlU = NULL;
282 TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld, control, targetpos,
283 listcount, context, errcode );
285 if (!ld) return ~0UL;
288 controlU = controlarrayWtoU( control );
289 if (!controlU) return WLDAP32_LDAP_NO_MEMORY;
292 ret = ldap_parse_vlv_control( ld, controlU, targetpos, listcount,
293 (struct berval **)context, errcode );
295 controlarrayfreeU( controlU );