resources: Change Dutch sublanguage code to SUBLANG_NEUTRAL.
[wine] / dlls / wldap32 / rename.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 #else
35 #define LDAP_NOT_SUPPORTED  0x5c
36 #endif
37
38 #include "winldap_private.h"
39 #include "wldap32.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
42
43 /***********************************************************************
44  *      ldap_rename_extA     (WLDAP32.@)
45  *
46  *  See ldap_rename_extW.
47  */
48 ULONG CDECL ldap_rename_extA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newrdn,
49     PCHAR newparent, INT delete, PLDAPControlA *serverctrls,
50     PLDAPControlA *clientctrls, ULONG *message )
51 {
52     ULONG ret = LDAP_NOT_SUPPORTED;
53 #ifdef HAVE_LDAP
54     WCHAR *dnW = NULL, *newrdnW = NULL, *newparentW = NULL;
55     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
56
57     ret = WLDAP32_LDAP_NO_MEMORY;
58
59     TRACE( "(%p, %s, %s, %s, 0x%02x, %p, %p, %p)\n", ld, debugstr_a(dn),
60            debugstr_a(newrdn), debugstr_a(newparent), delete,
61            serverctrls, clientctrls, message );
62
63     if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
64
65     if (dn) {
66         dnW = strAtoW( dn );
67         if (!dnW) goto exit;
68     }
69     if (newrdn) {
70         newrdnW = strAtoW( newrdn );
71         if (!newrdnW) goto exit;
72     }
73     if (newparent) {
74         newparentW = strAtoW( newparent );
75         if (!newparentW) goto exit;
76     }
77     if (serverctrls) {
78         serverctrlsW = controlarrayAtoW( serverctrls );
79         if (!serverctrlsW) goto exit;
80     }
81     if (clientctrls) {
82         clientctrlsW = controlarrayAtoW( clientctrls );
83         if (!clientctrlsW) goto exit;
84     }
85
86     ret = ldap_rename_extW( ld, dnW, newrdnW, newparentW, delete,
87                             serverctrlsW, clientctrlsW, message );
88
89 exit:
90     strfreeW( dnW );
91     strfreeW( newrdnW );
92     strfreeW( newparentW );
93     controlarrayfreeW( serverctrlsW );
94     controlarrayfreeW( clientctrlsW );
95
96 #endif
97     return ret;
98 }
99
100 /***********************************************************************
101  *      ldap_rename_extW     (WLDAP32.@)
102  *
103  * Change the DN of a directory entry (asynchronous operation).
104  *
105  * PARAMS
106  *  ld          [I] Pointer to an LDAP context.
107  *  dn          [I] DN of the entry to change.
108  *  newrdn      [I] New RDN for the entry.
109  *  newparent   [I] New parent for the entry.
110  *  delete      [I] Delete old RDN?
111  *  serverctrls [I] Array of LDAP server controls.
112  *  clientctrls [I] Array of LDAP client controls.
113  *  message     [O] Message ID of the operation.
114  *
115  * RETURNS
116  *  Success: LDAP_SUCCESS
117  *  Failure: An LDAP error code.
118  *
119  * NOTES
120  *  Call ldap_result with the message ID to get the result of
121  *  the operation. Cancel the operation by calling ldap_abandon
122  *  with the message ID.
123  */
124 ULONG CDECL ldap_rename_extW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newrdn,
125     PWCHAR newparent, INT delete, PLDAPControlW *serverctrls,
126     PLDAPControlW *clientctrls, ULONG *message )
127 {
128     ULONG ret = LDAP_NOT_SUPPORTED;
129 #ifdef HAVE_LDAP
130     char *dnU = NULL, *newrdnU = NULL, *newparentU = NULL;
131     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
132
133     ret = WLDAP32_LDAP_NO_MEMORY;
134
135     TRACE( "(%p, %s, %s, %s, 0x%02x, %p, %p, %p)\n", ld, debugstr_w(dn),
136            debugstr_w(newrdn), debugstr_w(newparent), delete,
137            serverctrls, clientctrls, message );
138
139     if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
140
141     if (dn) {
142         dnU = strWtoU( dn );
143         if (!dnU) goto exit;
144     }
145     if (newrdn) {
146         newrdnU = strWtoU( newrdn );
147         if (!newrdnU) goto exit;
148     }
149     if (newparent) {
150         newparentU = strWtoU( newparent );
151         if (!newparentU) goto exit;
152     }
153     if (serverctrls) {
154         serverctrlsU = controlarrayWtoU( serverctrls );
155         if (!serverctrlsU) goto exit;
156     }
157     if (clientctrls) {
158         clientctrlsU = controlarrayWtoU( clientctrls );
159         if (!clientctrlsU) goto exit;
160     }
161
162     ret = ldap_rename( ld, dn ? dnU : "", newrdn ? newrdnU : "", newparentU,
163                        delete, serverctrlsU, clientctrlsU, (int *)message );
164
165 exit:
166     strfreeU( dnU );
167     strfreeU( newrdnU );
168     strfreeU( newparentU );
169     controlarrayfreeU( serverctrlsU );
170     controlarrayfreeU( clientctrlsU );
171
172 #endif
173     return ret;
174 }
175
176 /***********************************************************************
177  *      ldap_rename_ext_sA     (WLDAP32.@)
178  *
179  *  See ldap_rename_ext_sW.
180  */
181 ULONG CDECL ldap_rename_ext_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newrdn,
182     PCHAR newparent, INT delete, PLDAPControlA *serverctrls,
183     PLDAPControlA *clientctrls )
184 {
185     ULONG ret = LDAP_NOT_SUPPORTED;
186 #ifdef HAVE_LDAP
187     WCHAR *dnW = NULL, *newrdnW = NULL, *newparentW = NULL;
188     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
189
190     ret = WLDAP32_LDAP_NO_MEMORY;
191
192     TRACE( "(%p, %s, %s, %s, 0x%02x, %p, %p)\n", ld, debugstr_a(dn),
193            debugstr_a(newrdn), debugstr_a(newparent), delete,
194            serverctrls, clientctrls );
195
196     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
197
198     if (dn) {
199         dnW = strAtoW( dn );
200         if (!dnW) goto exit;
201     }
202     if (newrdn) {
203         newrdnW = strAtoW( newrdn );
204         if (!newrdnW) goto exit;
205     }
206     if (newparent) {
207         newparentW = strAtoW( newparent );
208         if (!newparentW) goto exit;
209     }
210     if (serverctrls) {
211         serverctrlsW = controlarrayAtoW( serverctrls );
212         if (!serverctrlsW) goto exit;
213     }
214     if (clientctrls) {
215         clientctrlsW = controlarrayAtoW( clientctrls );
216         if (!clientctrlsW) goto exit;
217     }
218
219     ret = ldap_rename_ext_sW( ld, dnW, newrdnW, newparentW, delete,
220                               serverctrlsW, clientctrlsW );
221
222 exit:
223     strfreeW( dnW );
224     strfreeW( newrdnW );
225     strfreeW( newparentW );
226     controlarrayfreeW( serverctrlsW );
227     controlarrayfreeW( clientctrlsW );
228
229 #endif
230     return ret;
231 }
232 /***********************************************************************
233  *      ldap_rename_ext_sW     (WLDAP32.@)
234  *
235  * Change the DN of a directory entry (synchronous operation).
236  *
237  * PARAMS
238  *  ld          [I] Pointer to an LDAP context.
239  *  dn          [I] DN of the entry to change.
240  *  newrdn      [I] New RDN for the entry.
241  *  newparent   [I] New parent for the entry.
242  *  delete      [I] Delete old RDN?
243  *  serverctrls [I] Array of LDAP server controls.
244  *  clientctrls [I] Array of LDAP client controls.
245  *
246  * RETURNS
247  *  Success: LDAP_SUCCESS
248  *  Failure: An LDAP error code.
249  */ 
250 ULONG CDECL ldap_rename_ext_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newrdn,
251     PWCHAR newparent, INT delete, PLDAPControlW *serverctrls,
252     PLDAPControlW *clientctrls )
253 {
254     ULONG ret = LDAP_NOT_SUPPORTED;
255 #ifdef HAVE_LDAP
256     char *dnU = NULL, *newrdnU = NULL, *newparentU = NULL;
257     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
258
259     ret = WLDAP32_LDAP_NO_MEMORY;
260
261     TRACE( "(%p, %s, %s, %s, 0x%02x, %p, %p)\n", ld, debugstr_w(dn),
262            debugstr_w(newrdn), debugstr_w(newparent), delete,
263            serverctrls, clientctrls );
264
265     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
266
267     if (dn) {
268         dnU = strWtoU( dn );
269         if (!dnU) goto exit;
270     }
271     if (newrdn) {
272         newrdnU = strWtoU( newrdn );
273         if (!newrdnU) goto exit;
274     }
275     if (newparent) {
276         newparentU = strWtoU( newparent );
277         if (!newparentU) goto exit;
278     }
279     if (serverctrls) {
280         serverctrlsU = controlarrayWtoU( serverctrls );
281         if (!serverctrlsU) goto exit;
282     }
283     if (clientctrls) {
284         clientctrlsU = controlarrayWtoU( clientctrls );
285         if (!clientctrlsU) goto exit;
286     }
287
288     ret = ldap_rename_s( ld, dn ? dnU : "", newrdn ? newrdnU : "", newparentU,
289                          delete, serverctrlsU, clientctrlsU );
290
291 exit:
292     strfreeU( dnU );
293     strfreeU( newrdnU );
294     strfreeU( newparentU );
295     controlarrayfreeU( serverctrlsU );
296     controlarrayfreeU( clientctrlsU );
297
298 #endif
299     return ret;
300 }