wldap32: Use ~0u instead of ~0ul for DWORD values.
[wine] / dlls / wldap32 / modrdn.c
1 /*
2  * WLDAP32 - LDAP support for Wine
3  *
4  * Copyright 2005 Hans Leidekker
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #include "wine/port.h"
24 #include "wine/debug.h"
25
26 #include <stdarg.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
31
32 #ifdef HAVE_LDAP_H
33 #include <ldap.h>
34 #endif
35
36 #include "winldap_private.h"
37 #include "wldap32.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
40
41 /***********************************************************************
42  *      ldap_modrdnA     (WLDAP32.@)
43  *
44  * See ldap_modrdnW.
45  */
46 ULONG CDECL ldap_modrdnA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn )
47 {
48     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
49 #ifdef HAVE_LDAP
50     WCHAR *dnW = NULL, *newdnW = NULL;
51
52     ret = WLDAP32_LDAP_NO_MEMORY;
53
54     TRACE( "(%p, %s, %s)\n", ld, debugstr_a(dn), debugstr_a(newdn) );
55
56     if (!ld || !newdn) return ~0u;
57
58     if (dn) {
59         dnW = strAtoW( dn );
60         if (!dnW) goto exit;
61     }
62
63     newdnW = strAtoW( newdn );
64     if (!newdnW) goto exit;
65
66     ret = ldap_modrdnW( ld, dnW, newdnW );
67
68 exit:
69     strfreeW( dnW );
70     strfreeW( newdnW );
71
72 #endif
73     return ret;
74 }
75
76 /***********************************************************************
77  *      ldap_modrdnW     (WLDAP32.@)
78  *
79  * Change the RDN of a directory entry (asynchronous operation).
80  *
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. 
85  *
86  * RETURNS
87  *  Success: Message ID of the modrdn operation.
88  *  Failure: An LDAP error code.
89  *
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.
94  */
95 ULONG CDECL ldap_modrdnW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn )
96 {
97     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
98 #ifdef HAVE_LDAP
99     char *dnU = NULL, *newdnU = NULL;
100     int msg;
101
102     ret = WLDAP32_LDAP_NO_MEMORY;
103
104     TRACE( "(%p, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(newdn) );
105
106     if (!ld || !newdn) return ~0u;
107
108     if (dn) {
109         dnU = strWtoU( dn );
110         if (!dnU) goto exit;
111     }
112
113     newdnU = strWtoU( newdn );
114     if (!newdnU) goto exit;
115
116     ret = ldap_rename( ld, dn ? dnU : "", newdnU, NULL, 1, NULL, NULL, &msg );
117
118     if (ret == LDAP_SUCCESS)
119         ret = msg;
120     else
121         ret = ~0u;
122
123 exit:
124     strfreeU( dnU );
125     strfreeU( newdnU );
126
127 #endif
128     return ret;
129 }
130
131 /***********************************************************************
132  *      ldap_modrdn2A     (WLDAP32.@)
133  *
134  * See ldap_modrdn2W.
135  */
136 ULONG CDECL ldap_modrdn2A( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn, INT delete )
137 {
138     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
139 #ifdef HAVE_LDAP
140     WCHAR *dnW = NULL, *newdnW = NULL;
141
142     ret = WLDAP32_LDAP_NO_MEMORY;
143
144     TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_a(dn), newdn, delete );
145
146     if (!ld || !newdn) return ~0u;
147
148     if (dn) {
149         dnW = strAtoW( dn );
150         if (!dnW) goto exit;
151     }
152
153     newdnW = strAtoW( newdn );
154     if (!newdnW) goto exit;
155
156     ret = ldap_modrdn2W( ld, dnW, newdnW, delete );
157
158 exit:
159     strfreeW( dnW );
160     strfreeW( newdnW );
161
162 #endif
163     return ret;
164 }
165
166 /***********************************************************************
167  *      ldap_modrdn2W     (WLDAP32.@)
168  *
169  * Change the RDN of a directory entry (asynchronous operation).
170  *
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?
176  *
177  * RETURNS
178  *  Success: Message ID of the modrdn operation.
179  *  Failure: An LDAP error code.
180  *
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.
185  */
186 ULONG CDECL ldap_modrdn2W( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn, INT delete )
187 {
188     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
189 #ifdef HAVE_LDAP
190     char *dnU = NULL, *newdnU = NULL;
191     int msg;
192
193     ret = WLDAP32_LDAP_NO_MEMORY;
194
195     TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_w(dn), newdn, delete );
196
197     if (!ld || !newdn) return ~0u;
198
199     if (dn) {
200         dnU = strWtoU( dn );
201         if (!dnU) goto exit;
202     }
203
204     newdnU = strWtoU( newdn );
205     if (!newdnU) goto exit;
206
207     ret = ldap_rename( ld, dn ? dnU : "", newdnU, NULL, delete, NULL, NULL, &msg );
208
209     if (ret == LDAP_SUCCESS)
210         ret = msg;
211     else
212         ret = ~0u;
213
214 exit:
215     strfreeU( dnU );
216     strfreeU( newdnU );
217
218 #endif
219     return ret;
220 }
221
222 /***********************************************************************
223  *      ldap_modrdn2_sA     (WLDAP32.@)
224  *
225  * See ldap_modrdn2_sW.
226  */
227 ULONG CDECL ldap_modrdn2_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn, INT delete )
228 {
229     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
230 #ifdef HAVE_LDAP
231     WCHAR *dnW = NULL, *newdnW = NULL;
232
233     ret = WLDAP32_LDAP_NO_MEMORY;
234
235     TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_a(dn), newdn, delete );
236
237     if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
238
239     if (dn) {
240         dnW = strAtoW( dn );
241         if (!dnW) goto exit;
242     }
243
244     newdnW = strAtoW( newdn );
245     if (!newdnW) goto exit;
246
247     ret = ldap_modrdn2_sW( ld, dnW, newdnW, delete );
248
249 exit:
250     strfreeW( dnW );
251     strfreeW( newdnW );
252
253 #endif
254     return ret;
255 }
256
257 /***********************************************************************
258  *      ldap_modrdn2_sW     (WLDAP32.@)
259  *
260  * Change the RDN of a directory entry (synchronous operation).
261  *
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?
267  *
268  * RETURNS
269  *  Success: LDAP_SUCCESS
270  *  Failure: An LDAP error code.
271  */
272 ULONG CDECL ldap_modrdn2_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn, INT delete )
273 {
274     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
275 #ifdef HAVE_LDAP
276     char *dnU = NULL, *newdnU = NULL;
277
278     ret = WLDAP32_LDAP_NO_MEMORY;
279
280     TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_w(dn), newdn, delete );
281
282     if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
283
284     if (dn) {
285         dnU = strWtoU( dn );
286         if (!dnU) goto exit;
287     }
288
289     newdnU = strWtoU( newdn );
290     if (!newdnU) goto exit;
291
292     ret = map_error( ldap_rename_s( ld, dn ? dnU : "", newdnU, NULL, delete, NULL, NULL ));
293
294 exit:
295     strfreeU( dnU );
296     strfreeU( newdnU );
297
298 #endif
299     return ret;
300 }
301
302 /***********************************************************************
303  *      ldap_modrdn_sA     (WLDAP32.@)
304  *
305  * See ldap_modrdn_sW.
306  */
307 ULONG CDECL ldap_modrdn_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn )
308 {
309     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
310 #ifdef HAVE_LDAP
311     WCHAR *dnW = NULL, *newdnW = NULL;
312
313     ret = WLDAP32_LDAP_NO_MEMORY;
314
315     TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), newdn );
316
317     if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
318
319     if (dn) {
320         dnW = strAtoW( dn );
321         if (!dnW) goto exit;
322     }
323
324     newdnW = strAtoW( newdn );
325     if (!newdnW) goto exit;
326
327     ret = ldap_modrdn_sW( ld, dnW, newdnW );
328
329 exit:
330     strfreeW( dnW );
331     strfreeW( newdnW );
332
333 #endif
334     return ret;
335 }
336
337 /***********************************************************************
338  *      ldap_modrdn_sW     (WLDAP32.@)
339  *
340  * Change the RDN of a directory entry (synchronous operation).
341  *
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. 
346  *
347  * RETURNS
348  *  Success: LDAP_SUCCESS
349  *  Failure: An LDAP error code.
350  */
351 ULONG CDECL ldap_modrdn_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn )
352 {
353     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
354 #ifdef HAVE_LDAP
355     char *dnU = NULL, *newdnU = NULL;
356
357     ret = WLDAP32_LDAP_NO_MEMORY;
358
359     TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), newdn );
360
361     if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
362
363     if (dn) {
364         dnU = strWtoU( dn );
365         if (!dnU) goto exit;
366     }
367
368     newdnU = strWtoU( newdn );
369     if (!newdnU) goto exit;
370
371     ret = map_error( ldap_rename_s( ld, dn ? dnU : "", newdnU, NULL, 1, NULL, NULL ));
372
373 exit:
374     strfreeU( dnU );
375     strfreeU( newdnU );
376
377 #endif
378     return ret;
379 }