oleacc: Fix LresultFromObject return type.
[wine/wine64.git] / dlls / wldap32 / dn.c
blob438430ee1e0e029a9a061fbf782873a0200a4dcc
1 /*
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
21 #include "config.h"
23 #include "wine/port.h"
24 #include "wine/debug.h"
26 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
32 #ifdef HAVE_LDAP_H
33 #include <ldap.h>
34 #endif
36 #include "winldap_private.h"
37 #include "wldap32.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
41 /***********************************************************************
42 * ldap_dn2ufnA (WLDAP32.@)
44 * See ldap_dn2ufnW.
46 PCHAR CDECL ldap_dn2ufnA( PCHAR dn )
48 PCHAR ret = NULL;
49 #ifdef HAVE_LDAP
50 WCHAR *dnW, *retW;
52 TRACE( "(%s)\n", debugstr_a(dn) );
54 dnW = strAtoW( dn );
55 if (!dnW) return NULL;
57 retW = ldap_dn2ufnW( dnW );
58 ret = strWtoA( retW );
60 strfreeW( dnW );
61 ldap_memfreeW( retW );
63 #endif
64 return ret;
67 /***********************************************************************
68 * ldap_dn2ufnW (WLDAP32.@)
70 * Convert a DN to a user-friendly name.
72 * PARAMS
73 * dn [I] DN to convert.
75 * RETURNS
76 * Success: Pointer to a string containing the user-friendly name.
77 * Failure: NULL
79 * NOTES
80 * Free the string with ldap_memfree.
82 PWCHAR CDECL ldap_dn2ufnW( PWCHAR dn )
84 PWCHAR ret = NULL;
85 #ifdef HAVE_LDAP
86 char *dnU, *retU;
88 TRACE( "(%s)\n", debugstr_w(dn) );
90 dnU = strWtoU( dn );
91 if (!dnU) return NULL;
93 retU = ldap_dn2ufn( dnU );
94 ret = strUtoW( retU );
96 strfreeU( dnU );
97 ldap_memfree( retU );
99 #endif
100 return ret;
103 /***********************************************************************
104 * ldap_explode_dnA (WLDAP32.@)
106 * See ldap_explode_dnW.
108 PCHAR * CDECL ldap_explode_dnA( PCHAR dn, ULONG notypes )
110 PCHAR *ret = NULL;
111 #ifdef HAVE_LDAP
112 WCHAR *dnW, **retW;
114 TRACE( "(%s, 0x%08x)\n", debugstr_a(dn), notypes );
116 dnW = strAtoW( dn );
117 if (!dnW) return NULL;
119 retW = ldap_explode_dnW( dnW, notypes );
120 ret = strarrayWtoA( retW );
122 strfreeW( dnW );
123 ldap_value_freeW( retW );
125 #endif
126 return ret;
129 /***********************************************************************
130 * ldap_explode_dnW (WLDAP32.@)
132 * Break up a DN into its components.
134 * PARAMS
135 * dn [I] DN to break up.
136 * notypes [I] Remove attribute type information from the components.
138 * RETURNS
139 * Success: Pointer to a NULL-terminated array that contains the DN
140 * components.
141 * Failure: NULL
143 * NOTES
144 * Free the string array with ldap_value_free.
146 PWCHAR * CDECL ldap_explode_dnW( PWCHAR dn, ULONG notypes )
148 PWCHAR *ret = NULL;
149 #ifdef HAVE_LDAP
150 char *dnU, **retU;
152 TRACE( "(%s, 0x%08x)\n", debugstr_w(dn), notypes );
154 dnU = strWtoU( dn );
155 if (!dnU) return NULL;
157 retU = ldap_explode_dn( dnU, notypes );
158 ret = strarrayUtoW( retU );
160 strfreeU( dnU );
161 ldap_memvfree( (void **)retU );
163 #endif
164 return ret;
167 /***********************************************************************
168 * ldap_get_dnA (WLDAP32.@)
170 * See ldap_get_dnW.
172 PCHAR CDECL ldap_get_dnA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
174 PCHAR ret = NULL;
175 #ifdef HAVE_LDAP
176 PWCHAR retW;
178 TRACE( "(%p, %p)\n", ld, entry );
180 if (!ld || !entry) return NULL;
182 retW = ldap_get_dnW( ld, entry );
184 ret = strWtoA( retW );
185 ldap_memfreeW( retW );
187 #endif
188 return ret;
191 /***********************************************************************
192 * ldap_get_dnW (WLDAP32.@)
194 * Retrieve the DN from a given LDAP message.
196 * PARAMS
197 * ld [I] Pointer to an LDAP context.
198 * entry [I] LDAPMessage structure to retrieve the DN from.
200 * RETURNS
201 * Success: Pointer to a string that contains the DN.
202 * Failure: NULL
204 * NOTES
205 * Free the string with ldap_memfree.
207 PWCHAR CDECL ldap_get_dnW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
209 PWCHAR ret = NULL;
210 #ifdef HAVE_LDAP
211 char *retU;
213 TRACE( "(%p, %p)\n", ld, entry );
215 if (!ld || !entry) return NULL;
217 retU = ldap_get_dn( ld, entry );
219 ret = strUtoW( retU );
220 ldap_memfree( retU );
222 #endif
223 return ret;
226 /***********************************************************************
227 * ldap_ufn2dnA (WLDAP32.@)
229 * See ldap_ufn2dnW.
231 ULONG CDECL ldap_ufn2dnA( PCHAR ufn, PCHAR *dn )
233 ULONG ret = WLDAP32_LDAP_SUCCESS;
234 #ifdef HAVE_LDAP
235 PWCHAR ufnW = NULL, dnW = NULL;
237 TRACE( "(%s, %p)\n", debugstr_a(ufn), dn );
239 if (!dn) return WLDAP32_LDAP_PARAM_ERROR;
241 *dn = NULL;
243 if (ufn) {
244 ufnW = strAtoW( ufn );
245 if (!ufnW) return WLDAP32_LDAP_NO_MEMORY;
248 ret = ldap_ufn2dnW( ufnW, &dnW );
250 if (dnW) {
251 *dn = strWtoA( dnW );
252 if (!*dn) ret = WLDAP32_LDAP_NO_MEMORY;
255 strfreeW( ufnW );
256 ldap_memfreeW( dnW );
258 #endif
259 return ret;
262 /***********************************************************************
263 * ldap_ufn2dnW (WLDAP32.@)
265 * Convert a user-friendly name to a DN.
267 * PARAMS
268 * ufn [I] User-friendly name to convert.
269 * dn [O] Receives a pointer to a string containing the DN.
271 * RETURNS
272 * Success: LDAP_SUCCESS
273 * Failure: An LDAP error code.
275 * NOTES
276 * Free the string with ldap_memfree.
278 ULONG CDECL ldap_ufn2dnW( PWCHAR ufn, PWCHAR *dn )
280 ULONG ret = WLDAP32_LDAP_SUCCESS;
281 #ifdef HAVE_LDAP
282 char *ufnU = NULL;
284 TRACE( "(%s, %p)\n", debugstr_w(ufn), dn );
286 if (!dn) return WLDAP32_LDAP_PARAM_ERROR;
288 *dn = NULL;
290 if (ufn) {
291 ufnU = strWtoU( ufn );
292 if (!ufnU) return WLDAP32_LDAP_NO_MEMORY;
294 /* FIXME: do more than just a copy */
295 *dn = strUtoW( ufnU );
296 if (!*dn) ret = WLDAP32_LDAP_NO_MEMORY;
299 strfreeU( ufnU );
301 #endif
302 return ret;