Remove redundant check.
[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
79     ret = WLDAP32_LDAP_NO_MEMORY;
80
81     TRACE( "(%p, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(newdn) );
82
83     if (!ld || !newdn) return ~0UL;
84
85     if (dn) {
86         dnU = strWtoU( dn );
87         if (!dnU) goto exit;
88     }
89
90     newdnU = strWtoU( newdn );
91     if (!newdnU) goto exit;
92
93     ret = ldap_modrdn( ld, dn ? dnU : "", newdnU );
94
95 exit:
96     strfreeU( dnU );
97     strfreeU( newdnU );
98
99 #endif
100     return ret;
101 }
102
103 ULONG ldap_modrdn2A( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn, INT delete )
104 {
105     ULONG ret = LDAP_NOT_SUPPORTED;
106 #ifdef HAVE_LDAP
107     WCHAR *dnW = NULL, *newdnW = NULL;
108
109     ret = WLDAP32_LDAP_NO_MEMORY;
110
111     TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_a(dn), newdn, delete );
112
113     if (!ld || !newdn) return ~0UL;
114
115     if (dn) {
116         dnW = strAtoW( dn );
117         if (!dnW) goto exit;
118     }
119
120     newdnW = strAtoW( newdn );
121     if (!newdnW) goto exit;
122
123     ret = ldap_modrdn2W( ld, dnW, newdnW, delete );
124
125 exit:
126     strfreeW( dnW );
127     strfreeW( newdnW );
128
129 #endif
130     return ret;
131 }
132
133 ULONG ldap_modrdn2W( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn, INT delete )
134 {
135     ULONG ret = LDAP_NOT_SUPPORTED;
136 #ifdef HAVE_LDAP
137     char *dnU = NULL, *newdnU = NULL;
138
139     ret = WLDAP32_LDAP_NO_MEMORY;
140
141     TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_w(dn), newdn, delete );
142
143     if (!ld || !newdn) return ~0UL;
144
145     if (dn) {
146         dnU = strWtoU( dn );
147         if (!dnU) goto exit;
148     }
149
150     newdnU = strWtoU( newdn );
151     if (!newdnU) goto exit;
152
153     ret = ldap_modrdn2( ld, dn ? dnU : "", newdnU, delete );
154
155 exit:
156     strfreeU( dnU );
157     strfreeU( newdnU );
158
159 #endif
160     return ret;
161 }
162
163 ULONG ldap_modrdn2_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn, INT delete )
164 {
165     ULONG ret = LDAP_NOT_SUPPORTED;
166 #ifdef HAVE_LDAP
167     WCHAR *dnW = NULL, *newdnW = NULL;
168
169     ret = WLDAP32_LDAP_NO_MEMORY;
170
171     TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_a(dn), newdn, delete );
172
173     if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
174
175     if (dn) {
176         dnW = strAtoW( dn );
177         if (!dnW) goto exit;
178     }
179
180     newdnW = strAtoW( newdn );
181     if (!newdnW) goto exit;
182
183     ret = ldap_modrdn2_sW( ld, dnW, newdnW, delete );
184
185 exit:
186     strfreeW( dnW );
187     strfreeW( newdnW );
188
189 #endif
190     return ret;
191 }
192
193 ULONG ldap_modrdn2_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn, INT delete )
194 {
195     ULONG ret = LDAP_NOT_SUPPORTED;
196 #ifdef HAVE_LDAP
197     char *dnU = NULL, *newdnU = NULL;
198
199     ret = WLDAP32_LDAP_NO_MEMORY;
200
201     TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_w(dn), newdn, delete );
202
203     if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
204
205     if (dn) {
206         dnU = strWtoU( dn );
207         if (!dnU) goto exit;
208     }
209
210     newdnU = strWtoU( newdn );
211     if (!newdnU) goto exit;
212
213     ret = ldap_modrdn2_s( ld, dn ? dnU : "", newdnU, delete );
214
215 exit:
216     strfreeU( dnU );
217     strfreeU( newdnU );
218
219 #endif
220     return ret;
221 }
222
223 ULONG ldap_modrdn_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn )
224 {
225     ULONG ret = LDAP_NOT_SUPPORTED;
226 #ifdef HAVE_LDAP
227     WCHAR *dnW = NULL, *newdnW = NULL;
228
229     ret = WLDAP32_LDAP_NO_MEMORY;
230
231     TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), newdn );
232
233     if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
234
235     if (dn) {
236         dnW = strAtoW( dn );
237         if (!dnW) goto exit;
238     }
239
240     newdnW = strAtoW( newdn );
241     if (!newdnW) goto exit;
242
243     ret = ldap_modrdn_sW( ld, dnW, newdnW );
244
245 exit:
246     strfreeW( dnW );
247     strfreeW( newdnW );
248
249 #endif
250     return ret;
251 }
252
253 ULONG ldap_modrdn_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn )
254 {
255     ULONG ret = LDAP_NOT_SUPPORTED;
256 #ifdef HAVE_LDAP
257     char *dnU = NULL, *newdnU = NULL;
258
259     ret = WLDAP32_LDAP_NO_MEMORY;
260
261     TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), newdn );
262
263     if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
264
265     if (dn) {
266         dnU = strWtoU( dn );
267         if (!dnU) goto exit;
268     }
269
270     newdnU = strWtoU( newdn );
271     if (!newdnU) goto exit;
272
273     ret = ldap_modrdn_s( ld, dn ? dnU : "", newdnU );
274
275 exit:
276     strfreeU( dnU );
277     strfreeU( newdnU );
278
279 #endif
280     return ret;
281 }