propsys: Add support for VT_LPSTR to PropVariantChangeType.
[wine.git] / dlls / wldap32 / modrdn.c
blob3e2c86795664a3faa5cb054952a400eb6a580d3f
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"
22 #include "wine/port.h"
24 #include <stdarg.h>
25 #ifdef HAVE_LDAP_H
26 #include <ldap.h>
27 #endif
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winnls.h"
33 #include "winldap_private.h"
34 #include "wldap32.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
39 /***********************************************************************
40 * ldap_modrdnA (WLDAP32.@)
42 * See ldap_modrdnW.
44 ULONG CDECL ldap_modrdnA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn )
46 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
47 #ifdef HAVE_LDAP
48 WCHAR *dnW = NULL, *newdnW = NULL;
50 ret = WLDAP32_LDAP_NO_MEMORY;
52 TRACE( "(%p, %s, %s)\n", ld, debugstr_a(dn), debugstr_a(newdn) );
54 if (!ld || !newdn) return ~0u;
56 if (dn) {
57 dnW = strAtoW( dn );
58 if (!dnW) goto exit;
61 newdnW = strAtoW( newdn );
62 if (!newdnW) goto exit;
64 ret = ldap_modrdnW( ld, dnW, newdnW );
66 exit:
67 strfreeW( dnW );
68 strfreeW( newdnW );
70 #endif
71 return ret;
74 /***********************************************************************
75 * ldap_modrdnW (WLDAP32.@)
77 * Change the RDN of a directory entry (asynchronous operation).
79 * PARAMS
80 * ld [I] Pointer to an LDAP context.
81 * dn [I] DN of the entry to change.
82 * newdn [I] New DN for the entry.
84 * RETURNS
85 * Success: Message ID of the modrdn operation.
86 * Failure: An LDAP error code.
88 * NOTES
89 * Call ldap_result with the message ID to get the result of
90 * the operation. Cancel the operation by calling ldap_abandon
91 * with the message ID.
93 ULONG CDECL ldap_modrdnW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn )
95 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
96 #ifdef HAVE_LDAP
97 char *dnU = NULL, *newdnU = NULL;
98 int msg;
100 ret = WLDAP32_LDAP_NO_MEMORY;
102 TRACE( "(%p, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(newdn) );
104 if (!ld || !newdn) return ~0u;
106 if (dn) {
107 dnU = strWtoU( dn );
108 if (!dnU) goto exit;
111 newdnU = strWtoU( newdn );
112 if (!newdnU) goto exit;
114 ret = ldap_rename( ld, dn ? dnU : "", newdnU, NULL, 1, NULL, NULL, &msg );
116 if (ret == LDAP_SUCCESS)
117 ret = msg;
118 else
119 ret = ~0u;
121 exit:
122 strfreeU( dnU );
123 strfreeU( newdnU );
125 #endif
126 return ret;
129 /***********************************************************************
130 * ldap_modrdn2A (WLDAP32.@)
132 * See ldap_modrdn2W.
134 ULONG CDECL ldap_modrdn2A( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn, INT delete )
136 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
137 #ifdef HAVE_LDAP
138 WCHAR *dnW = NULL, *newdnW = NULL;
140 ret = WLDAP32_LDAP_NO_MEMORY;
142 TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_a(dn), newdn, delete );
144 if (!ld || !newdn) return ~0u;
146 if (dn) {
147 dnW = strAtoW( dn );
148 if (!dnW) goto exit;
151 newdnW = strAtoW( newdn );
152 if (!newdnW) goto exit;
154 ret = ldap_modrdn2W( ld, dnW, newdnW, delete );
156 exit:
157 strfreeW( dnW );
158 strfreeW( newdnW );
160 #endif
161 return ret;
164 /***********************************************************************
165 * ldap_modrdn2W (WLDAP32.@)
167 * Change the RDN of a directory entry (asynchronous operation).
169 * PARAMS
170 * ld [I] Pointer to an LDAP context.
171 * dn [I] DN of the entry to change.
172 * newdn [I] New DN for the entry.
173 * delete [I] Delete old DN?
175 * RETURNS
176 * Success: Message ID of the modrdn operation.
177 * Failure: An LDAP error code.
179 * NOTES
180 * Call ldap_result with the message ID to get the result of
181 * the operation. Cancel the operation by calling ldap_abandon
182 * with the message ID.
184 ULONG CDECL ldap_modrdn2W( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn, INT delete )
186 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
187 #ifdef HAVE_LDAP
188 char *dnU = NULL, *newdnU = NULL;
189 int msg;
191 ret = WLDAP32_LDAP_NO_MEMORY;
193 TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_w(dn), newdn, delete );
195 if (!ld || !newdn) return ~0u;
197 if (dn) {
198 dnU = strWtoU( dn );
199 if (!dnU) goto exit;
202 newdnU = strWtoU( newdn );
203 if (!newdnU) goto exit;
205 ret = ldap_rename( ld, dn ? dnU : "", newdnU, NULL, delete, NULL, NULL, &msg );
207 if (ret == LDAP_SUCCESS)
208 ret = msg;
209 else
210 ret = ~0u;
212 exit:
213 strfreeU( dnU );
214 strfreeU( newdnU );
216 #endif
217 return ret;
220 /***********************************************************************
221 * ldap_modrdn2_sA (WLDAP32.@)
223 * See ldap_modrdn2_sW.
225 ULONG CDECL ldap_modrdn2_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn, INT delete )
227 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
228 #ifdef HAVE_LDAP
229 WCHAR *dnW = NULL, *newdnW = NULL;
231 ret = WLDAP32_LDAP_NO_MEMORY;
233 TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_a(dn), newdn, delete );
235 if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
237 if (dn) {
238 dnW = strAtoW( dn );
239 if (!dnW) goto exit;
242 newdnW = strAtoW( newdn );
243 if (!newdnW) goto exit;
245 ret = ldap_modrdn2_sW( ld, dnW, newdnW, delete );
247 exit:
248 strfreeW( dnW );
249 strfreeW( newdnW );
251 #endif
252 return ret;
255 /***********************************************************************
256 * ldap_modrdn2_sW (WLDAP32.@)
258 * Change the RDN of a directory entry (synchronous operation).
260 * PARAMS
261 * ld [I] Pointer to an LDAP context.
262 * dn [I] DN of the entry to change.
263 * newdn [I] New DN for the entry.
264 * delete [I] Delete old DN?
266 * RETURNS
267 * Success: LDAP_SUCCESS
268 * Failure: An LDAP error code.
270 ULONG CDECL ldap_modrdn2_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn, INT delete )
272 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
273 #ifdef HAVE_LDAP
274 char *dnU = NULL, *newdnU = NULL;
276 ret = WLDAP32_LDAP_NO_MEMORY;
278 TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_w(dn), newdn, delete );
280 if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
282 if (dn) {
283 dnU = strWtoU( dn );
284 if (!dnU) goto exit;
287 newdnU = strWtoU( newdn );
288 if (!newdnU) goto exit;
290 ret = map_error( ldap_rename_s( ld, dn ? dnU : "", newdnU, NULL, delete, NULL, NULL ));
292 exit:
293 strfreeU( dnU );
294 strfreeU( newdnU );
296 #endif
297 return ret;
300 /***********************************************************************
301 * ldap_modrdn_sA (WLDAP32.@)
303 * See ldap_modrdn_sW.
305 ULONG CDECL ldap_modrdn_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn )
307 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
308 #ifdef HAVE_LDAP
309 WCHAR *dnW = NULL, *newdnW = NULL;
311 ret = WLDAP32_LDAP_NO_MEMORY;
313 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), newdn );
315 if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
317 if (dn) {
318 dnW = strAtoW( dn );
319 if (!dnW) goto exit;
322 newdnW = strAtoW( newdn );
323 if (!newdnW) goto exit;
325 ret = ldap_modrdn_sW( ld, dnW, newdnW );
327 exit:
328 strfreeW( dnW );
329 strfreeW( newdnW );
331 #endif
332 return ret;
335 /***********************************************************************
336 * ldap_modrdn_sW (WLDAP32.@)
338 * Change the RDN of a directory entry (synchronous operation).
340 * PARAMS
341 * ld [I] Pointer to an LDAP context.
342 * dn [I] DN of the entry to change.
343 * newdn [I] New DN for the entry.
345 * RETURNS
346 * Success: LDAP_SUCCESS
347 * Failure: An LDAP error code.
349 ULONG CDECL ldap_modrdn_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn )
351 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
352 #ifdef HAVE_LDAP
353 char *dnU = NULL, *newdnU = NULL;
355 ret = WLDAP32_LDAP_NO_MEMORY;
357 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), newdn );
359 if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
361 if (dn) {
362 dnU = strWtoU( dn );
363 if (!dnU) goto exit;
366 newdnU = strWtoU( newdn );
367 if (!newdnU) goto exit;
369 ret = map_error( ldap_rename_s( ld, dn ? dnU : "", newdnU, NULL, 1, NULL, NULL ));
371 exit:
372 strfreeU( dnU );
373 strfreeU( newdnU );
375 #endif
376 return ret;