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"
35 #define LDAP_SUCCESS 0x00
36 #define LDAP_NOT_SUPPORTED 0x5c
39 #include "winldap_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
44 ULONG WLDAP32_ldap_count_values_len( struct WLDAP32_berval **vals )
46 ULONG ret = LDAP_NOT_SUPPORTED;
49 TRACE( "(%p)\n", vals );
50 ret = ldap_count_values_len( (struct berval **)vals );
56 ULONG ldap_count_valuesA( PCHAR *vals )
58 ULONG ret = LDAP_NOT_SUPPORTED;
62 TRACE( "(%p)\n", vals );
66 valsW = strarrayAtoW( vals );
67 if (!valsW) return WLDAP32_LDAP_NO_MEMORY;
69 ret = ldap_count_valuesW( valsW );
70 strarrayfreeW( valsW );
76 ULONG ldap_count_valuesW( PWCHAR *vals )
78 ULONG ret = LDAP_NOT_SUPPORTED;
82 TRACE( "(%p)\n", vals );
97 PCHAR *ldap_get_valuesA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, PCHAR attr )
101 WCHAR *attrW = NULL, **retW;
103 TRACE( "(%p, %p, %s)\n", ld, entry, debugstr_a(attr) );
105 if (!ld || !entry || !attr) return NULL;
107 attrW = strAtoW( attr );
108 if (!attrW) return NULL;
110 retW = ldap_get_valuesW( ld, entry, attrW );
112 ret = strarrayWtoA( retW );
113 ldap_value_freeW( retW );
121 static char *bv2str( struct berval *bv )
124 unsigned int len = bv->bv_len;
126 str = HeapAlloc( GetProcessHeap(), 0, len + 1 );
129 memcpy( str, bv->bv_val, len );
135 static char **bv2str_array( struct berval **bv )
137 unsigned int len = 0, i = 0;
138 struct berval **p = bv;
146 str = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(char *) );
147 if (!str) return NULL;
152 str[i] = bv2str( *p );
155 for (--i; i >= 0; i--)
156 HeapFree( GetProcessHeap(), 0, str[i] );
158 HeapFree( GetProcessHeap(), 0, str );
169 PWCHAR *ldap_get_valuesW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, PWCHAR attr )
173 char *attrU = NULL, **retU;
176 TRACE( "(%p, %p, %s)\n", ld, entry, debugstr_w(attr) );
178 if (!ld || !entry || !attr) return NULL;
180 attrU = strWtoU( attr );
181 if (!attrU) return NULL;
183 bv = ldap_get_values_len( ld, entry, attrU );
185 retU = bv2str_array( bv );
186 ret = strarrayUtoW( retU );
188 ldap_value_free_len( bv );
189 strarrayfreeU( retU );
196 struct WLDAP32_berval **ldap_get_values_lenA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *message,
201 struct WLDAP32_berval **ret;
203 TRACE( "(%p, %p, %s)\n", ld, message, debugstr_a(attr) );
205 if (!ld || !message || !attr) return NULL;
207 attrW = strAtoW( attr );
208 if (!attrW) return NULL;
210 ret = ldap_get_values_lenW( ld, message, attrW );
219 struct WLDAP32_berval **ldap_get_values_lenW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *message,
226 TRACE( "(%p, %p, %s)\n", ld, message, debugstr_w(attr) );
228 if (!ld || !message || !attr) return NULL;
230 attrU = strWtoU( attr );
231 if (!attrU) return NULL;
233 ret = ldap_get_values_len( ld, message, attrU );
236 return (struct WLDAP32_berval **)ret;
242 ULONG WLDAP32_ldap_value_free_len( struct WLDAP32_berval **vals )
246 TRACE( "(%p)\n", vals );
247 ldap_value_free_len( (struct berval **)vals );
253 ULONG ldap_value_freeA( PCHAR *vals )
255 TRACE( "(%p)\n", vals );
257 strarrayfreeA( vals );
261 ULONG ldap_value_freeW( PWCHAR *vals )
263 TRACE( "(%p)\n", vals );
265 strarrayfreeW( vals );