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 WINE_DEFAULT_DEBUG_CHANNEL(wldap32
);
45 ULONG
WLDAP32_ldap_abandon( WLDAP32_LDAP
*ld
, ULONG msgid
)
47 ULONG ret
= LDAP_NOT_SUPPORTED
;
50 TRACE( "(%p, 0x%08lx)\n", ld
, msgid
);
53 ret
= ldap_abandon( ld
, msgid
);
59 ULONG
ldap_check_filterA( WLDAP32_LDAP
*ld
, PCHAR filter
)
62 WCHAR
*filterW
= NULL
;
64 TRACE( "(%p, %s)\n", ld
, debugstr_a(filter
) );
66 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
69 filterW
= strAtoW( filter
);
70 if (!filterW
) return WLDAP32_LDAP_NO_MEMORY
;
73 ret
= ldap_check_filterW( ld
, filterW
);
79 ULONG
ldap_check_filterW( WLDAP32_LDAP
*ld
, PWCHAR filter
)
81 TRACE( "(%p, %s)\n", ld
, debugstr_w(filter
) );
83 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
87 ULONG
ldap_cleanup( HANDLE instance
)
89 TRACE( "(%p)\n", instance
);
93 WLDAP32_LDAP
*ldap_conn_from_msg( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*res
)
95 TRACE( "(%p, %p)\n", ld
, res
);
97 if (!ld
|| !res
) return NULL
;
98 return ld
; /* FIXME: not always correct */
101 ULONG
WLDAP32_ldap_count_entries( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*res
)
103 ULONG ret
= LDAP_NOT_SUPPORTED
;
106 TRACE( "(%p, %p)\n", ld
, res
);
108 if (!ld
) return ~0UL;
109 ret
= ldap_count_entries( ld
, res
);
115 ULONG
WLDAP32_ldap_count_references( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*res
)
117 ULONG ret
= LDAP_NOT_SUPPORTED
;
120 TRACE( "(%p, %p)\n", ld
, res
);
123 ret
= ldap_count_references( ld
, res
);
129 static ULONG
get_escape_size( PCHAR src
, ULONG srclen
)
135 for (i
= 0; i
< srclen
; i
++)
137 if ((src
[i
] >= '0' && src
[i
] <= '9') ||
138 (src
[i
] >= 'A' && src
[i
] <= 'Z') ||
139 (src
[i
] >= 'a' && src
[i
] <= 'z'))
148 static void escape_filter_element( PCHAR src
, ULONG srclen
, PCHAR dst
)
151 char fmt
[] = "\\%02X";
154 for (i
= 0; i
< srclen
; i
++)
156 if ((src
[i
] >= '0' && src
[i
] <= '9') ||
157 (src
[i
] >= 'A' && src
[i
] <= 'Z') ||
158 (src
[i
] >= 'a' && src
[i
] <= 'z'))
162 sprintf( d
, fmt
, (unsigned char)src
[i
] );
169 ULONG
ldap_escape_filter_elementA( PCHAR src
, ULONG srclen
, PCHAR dst
, ULONG dstlen
)
173 TRACE( "(%p, 0x%08lx, %p, 0x%08lx)\n", src
, srclen
, dst
, dstlen
);
175 len
= get_escape_size( src
, srclen
);
176 if (!dst
) return len
;
178 if (!src
|| dstlen
< len
)
179 return WLDAP32_LDAP_PARAM_ERROR
;
182 escape_filter_element( src
, srclen
, dst
);
187 ULONG
ldap_escape_filter_elementW( PCHAR src
, ULONG srclen
, PWCHAR dst
, ULONG dstlen
)
191 TRACE( "(%p, 0x%08lx, %p, 0x%08lx)\n", src
, srclen
, dst
, dstlen
);
193 len
= get_escape_size( src
, srclen
);
194 if (!dst
) return len
;
196 /* no matter what you throw at it, this is what native returns */
197 return WLDAP32_LDAP_PARAM_ERROR
;
200 PCHAR
ldap_first_attributeA( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*entry
,
201 WLDAP32_BerElement
** ptr
)
207 TRACE( "(%p, %p, %p)\n", ld
, entry
, ptr
);
209 if (!ld
|| !entry
) return NULL
;
210 retW
= ldap_first_attributeW( ld
, entry
, ptr
);
212 ret
= strWtoA( retW
);
213 ldap_memfreeW( retW
);
219 PWCHAR
ldap_first_attributeW( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*entry
,
220 WLDAP32_BerElement
** ptr
)
226 TRACE( "(%p, %p, %p)\n", ld
, entry
, ptr
);
228 if (!ld
|| !entry
) return NULL
;
229 retU
= ldap_first_attribute( ld
, entry
, ptr
);
231 ret
= strUtoW( retU
);
232 ldap_memfree( retU
);
238 WLDAP32_LDAPMessage
*WLDAP32_ldap_first_entry( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*res
)
242 TRACE( "(%p, %p)\n", ld
, res
);
244 if (!ld
|| !res
) return NULL
;
245 return ldap_first_entry( ld
, res
);
251 WLDAP32_LDAPMessage
*WLDAP32_ldap_first_reference( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*res
)
255 TRACE( "(%p, %p)\n", ld
, res
);
257 if (!ld
) return NULL
;
258 return ldap_first_reference( ld
, res
);
264 void ldap_memfreeA( PCHAR block
)
266 TRACE( "(%p)\n", block
);
270 void ldap_memfreeW( PWCHAR block
)
272 TRACE( "(%p)\n", block
);
276 ULONG
WLDAP32_ldap_msgfree( WLDAP32_LDAPMessage
*res
)
278 ULONG ret
= LDAP_SUCCESS
;
281 TRACE( "(%p)\n", res
);
288 PCHAR
ldap_next_attributeA( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*entry
,
289 WLDAP32_BerElement
*ptr
)
295 TRACE( "(%p, %p, %p)\n", ld
, entry
, ptr
);
297 if (!ld
|| !entry
|| !ptr
) return NULL
;
298 retW
= ldap_next_attributeW( ld
, entry
, ptr
);
300 ret
= strWtoA( retW
);
301 ldap_memfreeW( retW
);
307 PWCHAR
ldap_next_attributeW( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*entry
,
308 WLDAP32_BerElement
*ptr
)
314 TRACE( "(%p, %p, %p)\n", ld
, entry
, ptr
);
316 if (!ld
|| !entry
|| !ptr
) return NULL
;
317 retU
= ldap_next_attribute( ld
, entry
, ptr
);
319 ret
= strUtoW( retU
);
320 ldap_memfree( retU
);
326 WLDAP32_LDAPMessage
*WLDAP32_ldap_next_entry( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*entry
)
330 TRACE( "(%p, %p)\n", ld
, entry
);
332 if (!ld
|| !entry
) return NULL
;
333 return ldap_next_entry( ld
, entry
);
339 WLDAP32_LDAPMessage
*WLDAP32_ldap_next_reference( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*entry
)
343 TRACE( "(%p, %p)\n", ld
, entry
);
345 if (!ld
|| !entry
) return NULL
;
346 return ldap_next_reference( ld
, entry
);
352 ULONG
WLDAP32_ldap_result( WLDAP32_LDAP
*ld
, ULONG msgid
, ULONG all
,
353 struct l_timeval
*timeout
, WLDAP32_LDAPMessage
**res
)
355 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
358 TRACE( "(%p, 0x%08lx, 0x%08lx, %p, %p)\n", ld
, msgid
, all
, timeout
, res
);
360 if (!ld
|| !res
) return ~0UL;
361 ret
= ldap_result( ld
, msgid
, all
, (struct timeval
*)timeout
, res
);
367 int LdapUnicodeToUTF8( LPCWSTR src
, int srclen
, LPSTR dst
, int dstlen
)
369 return WideCharToMultiByte( CP_UTF8
, 0, src
, srclen
, dst
, dstlen
, NULL
, NULL
);
372 int LdapUTF8ToUnicode( LPCSTR src
, int srclen
, LPWSTR dst
, int dstlen
)
374 return MultiByteToWideChar( CP_UTF8
, 0, src
, srclen
, dst
, dstlen
);