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_SUCCESS 0x00
38 #include "winldap_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
43 /***********************************************************************
44 * ldap_dn2ufnA (WLDAP32.@)
48 PCHAR ldap_dn2ufnA( PCHAR dn )
54 TRACE( "(%s)\n", debugstr_a(dn) );
57 if (!dnW) return NULL;
59 retW = ldap_dn2ufnW( dnW );
60 ret = strWtoA( retW );
63 ldap_memfreeW( retW );
69 /***********************************************************************
70 * ldap_dn2ufnW (WLDAP32.@)
72 * Convert a DN to a user-friendly name.
75 * dn [I] DN to convert.
78 * Success: Pointer to a string containing the user-friendly name.
82 * Free the string with ldap_memfree.
84 PWCHAR ldap_dn2ufnW( PWCHAR dn )
90 TRACE( "(%s)\n", debugstr_w(dn) );
93 if (!dnU) return NULL;
95 retU = ldap_dn2ufn( dnU );
96 ret = strUtoW( retU );
105 /***********************************************************************
106 * ldap_explode_dnA (WLDAP32.@)
108 * See ldap_explode_dnW.
110 PCHAR *ldap_explode_dnA( PCHAR dn, ULONG notypes )
116 TRACE( "(%s, 0x%08lx)\n", debugstr_a(dn), notypes );
119 if (!dnW) return NULL;
121 retW = ldap_explode_dnW( dnW, notypes );
122 ret = strarrayWtoA( retW );
125 ldap_value_freeW( retW );
131 /***********************************************************************
132 * ldap_explode_dnW (WLDAP32.@)
134 * Break up a DN into its components.
137 * dn [I] DN to break up.
138 * notypes [I] Remove attribute type information from the components.
141 * Success: Pointer to a NULL-terminated array that contains the DN
146 * Free the string array with ldap_value_free.
148 PWCHAR *ldap_explode_dnW( PWCHAR dn, ULONG notypes )
154 TRACE( "(%s, 0x%08lx)\n", debugstr_w(dn), notypes );
157 if (!dnU) return NULL;
159 retU = ldap_explode_dn( dnU, notypes );
160 ret = strarrayUtoW( retU );
163 ldap_memvfree( (void **)retU );
169 /***********************************************************************
170 * ldap_get_dnA (WLDAP32.@)
174 PCHAR ldap_get_dnA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
180 TRACE( "(%p, %p)\n", ld, entry );
182 if (!ld || !entry) return NULL;
184 retW = ldap_get_dnW( ld, entry );
186 ret = strWtoA( retW );
187 ldap_memfreeW( retW );
193 /***********************************************************************
194 * ldap_get_dnW (WLDAP32.@)
196 * Retrieve the DN from a given LDAP message.
199 * ld [I] Pointer to an LDAP context.
200 * entry [I] LDAPMessage structure to retrieve the DN from.
203 * Success: Pointer to a string that contains the DN.
207 * Free the string with ldap_memfree.
209 PWCHAR ldap_get_dnW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
215 TRACE( "(%p, %p)\n", ld, entry );
217 if (!ld || !entry) return NULL;
219 retU = ldap_get_dn( ld, entry );
221 ret = strUtoW( retU );
222 ldap_memfree( retU );
228 /***********************************************************************
229 * ldap_ufn2dnA (WLDAP32.@)
233 ULONG ldap_ufn2dnA( PCHAR ufn, PCHAR *dn )
235 ULONG ret = LDAP_SUCCESS;
237 PWCHAR ufnW = NULL, dnW = NULL;
239 TRACE( "(%s, %p)\n", debugstr_a(ufn), dn );
241 if (!dn) return WLDAP32_LDAP_PARAM_ERROR;
246 ufnW = strAtoW( ufn );
247 if (!ufnW) return WLDAP32_LDAP_NO_MEMORY;
250 ret = ldap_ufn2dnW( ufnW, &dnW );
253 *dn = strWtoA( dnW );
254 if (!*dn) ret = WLDAP32_LDAP_NO_MEMORY;
258 ldap_memfreeW( dnW );
264 /***********************************************************************
265 * ldap_ufn2dnW (WLDAP32.@)
267 * Convert a user-friendly name to a DN.
270 * ufn [I] User-friendly name to convert.
271 * dn [O] Receives a pointer to a string containing the DN.
274 * Success: LDAP_SUCCESS
275 * Failure: An LDAP error code.
278 * Free the string with ldap_memfree.
280 ULONG ldap_ufn2dnW( PWCHAR ufn, PWCHAR *dn )
282 ULONG ret = LDAP_SUCCESS;
286 TRACE( "(%s, %p)\n", debugstr_w(ufn), dn );
288 if (!dn) return WLDAP32_LDAP_PARAM_ERROR;
293 ufnU = strWtoU( ufn );
294 if (!ufnU) return WLDAP32_LDAP_NO_MEMORY;
296 /* FIXME: do more than just a copy */
297 *dn = strUtoW( ufnU );
298 if (!*dn) ret = WLDAP32_LDAP_NO_MEMORY;