push c22b4aa826b27f0c6bc5101b378e6e68716a85d9
[wine/hacks.git] / dlls / wldap32 / modrdn.c
blob76bf892b2a691185604e9b924568533d766d5fef
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_modrdnA (WLDAP32.@)
44 * See ldap_modrdnW.
46 ULONG CDECL ldap_modrdnA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn )
48 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
49 #ifdef HAVE_LDAP
50 WCHAR *dnW = NULL, *newdnW = NULL;
52 ret = WLDAP32_LDAP_NO_MEMORY;
54 TRACE( "(%p, %s, %s)\n", ld, debugstr_a(dn), debugstr_a(newdn) );
56 if (!ld || !newdn) return ~0u;
58 if (dn) {
59 dnW = strAtoW( dn );
60 if (!dnW) goto exit;
63 newdnW = strAtoW( newdn );
64 if (!newdnW) goto exit;
66 ret = ldap_modrdnW( ld, dnW, newdnW );
68 exit:
69 strfreeW( dnW );
70 strfreeW( newdnW );
72 #endif
73 return ret;
76 /***********************************************************************
77 * ldap_modrdnW (WLDAP32.@)
79 * Change the RDN of a directory entry (asynchronous operation).
81 * PARAMS
82 * ld [I] Pointer to an LDAP context.
83 * dn [I] DN of the entry to change.
84 * newdn [I] New DN for the entry.
86 * RETURNS
87 * Success: Message ID of the modrdn operation.
88 * Failure: An LDAP error code.
90 * NOTES
91 * Call ldap_result with the message ID to get the result of
92 * the operation. Cancel the operation by calling ldap_abandon
93 * with the message ID.
95 ULONG CDECL ldap_modrdnW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn )
97 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
98 #ifdef HAVE_LDAP
99 char *dnU = NULL, *newdnU = NULL;
100 int msg;
102 ret = WLDAP32_LDAP_NO_MEMORY;
104 TRACE( "(%p, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(newdn) );
106 if (!ld || !newdn) return ~0u;
108 if (dn) {
109 dnU = strWtoU( dn );
110 if (!dnU) goto exit;
113 newdnU = strWtoU( newdn );
114 if (!newdnU) goto exit;
116 ret = ldap_rename( ld, dn ? dnU : "", newdnU, NULL, 1, NULL, NULL, &msg );
118 if (ret == LDAP_SUCCESS)
119 ret = msg;
120 else
121 ret = ~0u;
123 exit:
124 strfreeU( dnU );
125 strfreeU( newdnU );
127 #endif
128 return ret;
131 /***********************************************************************
132 * ldap_modrdn2A (WLDAP32.@)
134 * See ldap_modrdn2W.
136 ULONG CDECL ldap_modrdn2A( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn, INT delete )
138 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
139 #ifdef HAVE_LDAP
140 WCHAR *dnW = NULL, *newdnW = NULL;
142 ret = WLDAP32_LDAP_NO_MEMORY;
144 TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_a(dn), newdn, delete );
146 if (!ld || !newdn) return ~0u;
148 if (dn) {
149 dnW = strAtoW( dn );
150 if (!dnW) goto exit;
153 newdnW = strAtoW( newdn );
154 if (!newdnW) goto exit;
156 ret = ldap_modrdn2W( ld, dnW, newdnW, delete );
158 exit:
159 strfreeW( dnW );
160 strfreeW( newdnW );
162 #endif
163 return ret;
166 /***********************************************************************
167 * ldap_modrdn2W (WLDAP32.@)
169 * Change the RDN of a directory entry (asynchronous operation).
171 * PARAMS
172 * ld [I] Pointer to an LDAP context.
173 * dn [I] DN of the entry to change.
174 * newdn [I] New DN for the entry.
175 * delete [I] Delete old DN?
177 * RETURNS
178 * Success: Message ID of the modrdn operation.
179 * Failure: An LDAP error code.
181 * NOTES
182 * Call ldap_result with the message ID to get the result of
183 * the operation. Cancel the operation by calling ldap_abandon
184 * with the message ID.
186 ULONG CDECL ldap_modrdn2W( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn, INT delete )
188 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
189 #ifdef HAVE_LDAP
190 char *dnU = NULL, *newdnU = NULL;
191 int msg;
193 ret = WLDAP32_LDAP_NO_MEMORY;
195 TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_w(dn), newdn, delete );
197 if (!ld || !newdn) return ~0u;
199 if (dn) {
200 dnU = strWtoU( dn );
201 if (!dnU) goto exit;
204 newdnU = strWtoU( newdn );
205 if (!newdnU) goto exit;
207 ret = ldap_rename( ld, dn ? dnU : "", newdnU, NULL, delete, NULL, NULL, &msg );
209 if (ret == LDAP_SUCCESS)
210 ret = msg;
211 else
212 ret = ~0u;
214 exit:
215 strfreeU( dnU );
216 strfreeU( newdnU );
218 #endif
219 return ret;
222 /***********************************************************************
223 * ldap_modrdn2_sA (WLDAP32.@)
225 * See ldap_modrdn2_sW.
227 ULONG CDECL ldap_modrdn2_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn, INT delete )
229 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
230 #ifdef HAVE_LDAP
231 WCHAR *dnW = NULL, *newdnW = NULL;
233 ret = WLDAP32_LDAP_NO_MEMORY;
235 TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_a(dn), newdn, delete );
237 if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
239 if (dn) {
240 dnW = strAtoW( dn );
241 if (!dnW) goto exit;
244 newdnW = strAtoW( newdn );
245 if (!newdnW) goto exit;
247 ret = ldap_modrdn2_sW( ld, dnW, newdnW, delete );
249 exit:
250 strfreeW( dnW );
251 strfreeW( newdnW );
253 #endif
254 return ret;
257 /***********************************************************************
258 * ldap_modrdn2_sW (WLDAP32.@)
260 * Change the RDN of a directory entry (synchronous operation).
262 * PARAMS
263 * ld [I] Pointer to an LDAP context.
264 * dn [I] DN of the entry to change.
265 * newdn [I] New DN for the entry.
266 * delete [I] Delete old DN?
268 * RETURNS
269 * Success: LDAP_SUCCESS
270 * Failure: An LDAP error code.
272 ULONG CDECL ldap_modrdn2_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn, INT delete )
274 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
275 #ifdef HAVE_LDAP
276 char *dnU = NULL, *newdnU = NULL;
278 ret = WLDAP32_LDAP_NO_MEMORY;
280 TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_w(dn), newdn, delete );
282 if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
284 if (dn) {
285 dnU = strWtoU( dn );
286 if (!dnU) goto exit;
289 newdnU = strWtoU( newdn );
290 if (!newdnU) goto exit;
292 ret = map_error( ldap_rename_s( ld, dn ? dnU : "", newdnU, NULL, delete, NULL, NULL ));
294 exit:
295 strfreeU( dnU );
296 strfreeU( newdnU );
298 #endif
299 return ret;
302 /***********************************************************************
303 * ldap_modrdn_sA (WLDAP32.@)
305 * See ldap_modrdn_sW.
307 ULONG CDECL ldap_modrdn_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn )
309 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
310 #ifdef HAVE_LDAP
311 WCHAR *dnW = NULL, *newdnW = NULL;
313 ret = WLDAP32_LDAP_NO_MEMORY;
315 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), newdn );
317 if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
319 if (dn) {
320 dnW = strAtoW( dn );
321 if (!dnW) goto exit;
324 newdnW = strAtoW( newdn );
325 if (!newdnW) goto exit;
327 ret = ldap_modrdn_sW( ld, dnW, newdnW );
329 exit:
330 strfreeW( dnW );
331 strfreeW( newdnW );
333 #endif
334 return ret;
337 /***********************************************************************
338 * ldap_modrdn_sW (WLDAP32.@)
340 * Change the RDN of a directory entry (synchronous operation).
342 * PARAMS
343 * ld [I] Pointer to an LDAP context.
344 * dn [I] DN of the entry to change.
345 * newdn [I] New DN for the entry.
347 * RETURNS
348 * Success: LDAP_SUCCESS
349 * Failure: An LDAP error code.
351 ULONG CDECL ldap_modrdn_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn )
353 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
354 #ifdef HAVE_LDAP
355 char *dnU = NULL, *newdnU = NULL;
357 ret = WLDAP32_LDAP_NO_MEMORY;
359 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), newdn );
361 if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
363 if (dn) {
364 dnU = strWtoU( dn );
365 if (!dnU) goto exit;
368 newdnU = strWtoU( newdn );
369 if (!newdnU) goto exit;
371 ret = map_error( ldap_rename_s( ld, dn ? dnU : "", newdnU, NULL, 1, NULL, NULL ));
373 exit:
374 strfreeU( dnU );
375 strfreeU( newdnU );
377 #endif
378 return ret;