wldap32: Don't return uninitialised 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 ULONG ldap_modrdnA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn )
44 {
45     ULONG ret = LDAP_NOT_SUPPORTED;
46 #ifdef HAVE_LDAP
47     WCHAR *dnW = NULL, *newdnW = NULL;
48
49     ret = WLDAP32_LDAP_NO_MEMORY;
50
51     TRACE( "(%p, %s, %s)\n", ld, debugstr_a(dn), debugstr_a(newdn) );
52
53     if (!ld || !newdn) return ~0UL;
54
55     if (dn) {
56         dnW = strAtoW( dn );
57         if (!dnW) goto exit;
58     }
59
60     newdnW = strAtoW( newdn );
61     if (!newdnW) goto exit;
62
63     ret = ldap_modrdnW( ld, dnW, newdnW );
64
65 exit:
66     strfreeW( dnW );
67     strfreeW( newdnW );
68
69 #endif
70     return ret;
71 }
72
73 ULONG ldap_modrdnW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn )
74 {
75     ULONG ret = LDAP_NOT_SUPPORTED;
76 #ifdef HAVE_LDAP
77     char *dnU = NULL, *newdnU = NULL;
78     int msg;
79
80     ret = WLDAP32_LDAP_NO_MEMORY;
81
82     TRACE( "(%p, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(newdn) );
83
84     if (!ld || !newdn) return ~0UL;
85
86     if (dn) {
87         dnU = strWtoU( dn );
88         if (!dnU) goto exit;
89     }
90
91     newdnU = strWtoU( newdn );
92     if (!newdnU) goto exit;
93
94     ret = ldap_rename( ld, dn ? dnU : "", newdnU, NULL, 1, NULL, NULL, &msg );
95
96     if (ret == LDAP_SUCCESS)
97         ret = msg;
98     else
99         ret = ~0UL;
100
101 exit:
102     strfreeU( dnU );
103     strfreeU( newdnU );
104
105 #endif
106     return ret;
107 }
108
109 ULONG ldap_modrdn2A( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn, INT delete )
110 {
111     ULONG ret = LDAP_NOT_SUPPORTED;
112 #ifdef HAVE_LDAP
113     WCHAR *dnW = NULL, *newdnW = NULL;
114
115     ret = WLDAP32_LDAP_NO_MEMORY;
116
117     TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_a(dn), newdn, delete );
118
119     if (!ld || !newdn) return ~0UL;
120
121     if (dn) {
122         dnW = strAtoW( dn );
123         if (!dnW) goto exit;
124     }
125
126     newdnW = strAtoW( newdn );
127     if (!newdnW) goto exit;
128
129     ret = ldap_modrdn2W( ld, dnW, newdnW, delete );
130
131 exit:
132     strfreeW( dnW );
133     strfreeW( newdnW );
134
135 #endif
136     return ret;
137 }
138
139 ULONG ldap_modrdn2W( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn, INT delete )
140 {
141     ULONG ret = LDAP_NOT_SUPPORTED;
142 #ifdef HAVE_LDAP
143     char *dnU = NULL, *newdnU = NULL;
144     int msg;
145
146     ret = WLDAP32_LDAP_NO_MEMORY;
147
148     TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_w(dn), newdn, delete );
149
150     if (!ld || !newdn) return ~0UL;
151
152     if (dn) {
153         dnU = strWtoU( dn );
154         if (!dnU) goto exit;
155     }
156
157     newdnU = strWtoU( newdn );
158     if (!newdnU) goto exit;
159
160     ret = ldap_rename( ld, dn ? dnU : "", newdnU, NULL, delete, NULL, NULL, &msg );
161
162     if (ret == LDAP_SUCCESS)
163         ret = msg;
164     else
165         ret = ~0UL;
166
167 exit:
168     strfreeU( dnU );
169     strfreeU( newdnU );
170
171 #endif
172     return ret;
173 }
174
175 ULONG ldap_modrdn2_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn, INT delete )
176 {
177     ULONG ret = LDAP_NOT_SUPPORTED;
178 #ifdef HAVE_LDAP
179     WCHAR *dnW = NULL, *newdnW = NULL;
180
181     ret = WLDAP32_LDAP_NO_MEMORY;
182
183     TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_a(dn), newdn, delete );
184
185     if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
186
187     if (dn) {
188         dnW = strAtoW( dn );
189         if (!dnW) goto exit;
190     }
191
192     newdnW = strAtoW( newdn );
193     if (!newdnW) goto exit;
194
195     ret = ldap_modrdn2_sW( ld, dnW, newdnW, delete );
196
197 exit:
198     strfreeW( dnW );
199     strfreeW( newdnW );
200
201 #endif
202     return ret;
203 }
204
205 ULONG ldap_modrdn2_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn, INT delete )
206 {
207     ULONG ret = LDAP_NOT_SUPPORTED;
208 #ifdef HAVE_LDAP
209     char *dnU = NULL, *newdnU = NULL;
210
211     ret = WLDAP32_LDAP_NO_MEMORY;
212
213     TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_w(dn), newdn, delete );
214
215     if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
216
217     if (dn) {
218         dnU = strWtoU( dn );
219         if (!dnU) goto exit;
220     }
221
222     newdnU = strWtoU( newdn );
223     if (!newdnU) goto exit;
224
225     ret = ldap_rename_s( ld, dn ? dnU : "", newdnU, NULL, delete, NULL, NULL );
226
227 exit:
228     strfreeU( dnU );
229     strfreeU( newdnU );
230
231 #endif
232     return ret;
233 }
234
235 ULONG ldap_modrdn_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn )
236 {
237     ULONG ret = LDAP_NOT_SUPPORTED;
238 #ifdef HAVE_LDAP
239     WCHAR *dnW = NULL, *newdnW = NULL;
240
241     ret = WLDAP32_LDAP_NO_MEMORY;
242
243     TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), newdn );
244
245     if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
246
247     if (dn) {
248         dnW = strAtoW( dn );
249         if (!dnW) goto exit;
250     }
251
252     newdnW = strAtoW( newdn );
253     if (!newdnW) goto exit;
254
255     ret = ldap_modrdn_sW( ld, dnW, newdnW );
256
257 exit:
258     strfreeW( dnW );
259     strfreeW( newdnW );
260
261 #endif
262     return ret;
263 }
264
265 ULONG ldap_modrdn_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn )
266 {
267     ULONG ret = LDAP_NOT_SUPPORTED;
268 #ifdef HAVE_LDAP
269     char *dnU = NULL, *newdnU = NULL;
270
271     ret = WLDAP32_LDAP_NO_MEMORY;
272
273     TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), newdn );
274
275     if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
276
277     if (dn) {
278         dnU = strWtoU( dn );
279         if (!dnU) goto exit;
280     }
281
282     newdnU = strWtoU( newdn );
283     if (!newdnU) goto exit;
284
285     ret = ldap_rename_s( ld, dn ? dnU : "", newdnU, NULL, 1, NULL, NULL );
286
287 exit:
288     strfreeU( dnU );
289     strfreeU( newdnU );
290
291 #endif
292     return ret;
293 }