wldap32: Document the modify and modrdn functions.
[wine] / dlls / wldap32 / dn.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_SUCCESS        0x00
36 #endif
37
38 #include "winldap_private.h"
39 #include "wldap32.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
42
43 /***********************************************************************
44  *      ldap_dn2ufnA     (WLDAP32.@)
45  *
46  * See ldap_dn2ufnW.
47  */
48 PCHAR ldap_dn2ufnA( PCHAR dn )
49 {
50     PCHAR ret = NULL;
51 #ifdef HAVE_LDAP
52     WCHAR *dnW, *retW;
53
54     TRACE( "(%s)\n", debugstr_a(dn) );
55
56     dnW = strAtoW( dn );
57     if (!dnW) return NULL;
58
59     retW = ldap_dn2ufnW( dnW );
60     ret = strWtoA( retW );
61
62     strfreeW( dnW );
63     ldap_memfreeW( retW );
64
65 #endif
66     return ret;
67 }
68
69 /***********************************************************************
70  *      ldap_dn2ufnW     (WLDAP32.@)
71  *
72  * Convert a DN to a user-friendly name.
73  *
74  * PARAMS
75  *  dn  [I] DN to convert.
76  *
77  * RETURNS
78  *  Success: Pointer to a string containing the user-friendly name. 
79  *  Failure: NULL
80  *
81  * NOTES
82  *  Free the string with ldap_memfree.
83  */
84 PWCHAR ldap_dn2ufnW( PWCHAR dn )
85 {
86     PWCHAR ret = NULL;
87 #ifdef HAVE_LDAP
88     char *dnU, *retU;
89
90     TRACE( "(%s)\n", debugstr_w(dn) );
91
92     dnU = strWtoU( dn );
93     if (!dnU) return NULL;
94
95     retU = ldap_dn2ufn( dnU );
96     ret = strUtoW( retU );
97
98     strfreeU( dnU );
99     ldap_memfree( retU );
100
101 #endif
102     return ret;
103 }
104
105 /***********************************************************************
106  *      ldap_explode_dnA     (WLDAP32.@)
107  *
108  * See ldap_explode_dnW.
109  */
110 PCHAR *ldap_explode_dnA( PCHAR dn, ULONG notypes )
111 {
112     PCHAR *ret = NULL;
113 #ifdef HAVE_LDAP
114     WCHAR *dnW, **retW;
115
116     TRACE( "(%s, 0x%08lx)\n", debugstr_a(dn), notypes );
117
118     dnW = strAtoW( dn );
119     if (!dnW) return NULL;
120
121     retW = ldap_explode_dnW( dnW, notypes );
122     ret = strarrayWtoA( retW );
123
124     strfreeW( dnW );
125     ldap_value_freeW( retW );
126
127 #endif
128     return ret;
129 }
130
131 /***********************************************************************
132  *      ldap_explode_dnW     (WLDAP32.@)
133  *
134  * Break up a DN into its components.
135  *
136  * PARAMS
137  *  dn       [I] DN to break up.
138  *  notypes  [I] Remove attribute type information from the components.
139  *
140  * RETURNS
141  *  Success: Pointer to a NULL-terminated array that contains the DN
142  *           components. 
143  *  Failure: NULL
144  *
145  * NOTES
146  *  Free the string array with ldap_value_free.
147  */
148 PWCHAR *ldap_explode_dnW( PWCHAR dn, ULONG notypes )
149 {
150     PWCHAR *ret = NULL;
151 #ifdef HAVE_LDAP
152     char *dnU, **retU;
153
154     TRACE( "(%s, 0x%08lx)\n", debugstr_w(dn), notypes );
155
156     dnU = strWtoU( dn );
157     if (!dnU) return NULL;
158
159     retU = ldap_explode_dn( dnU, notypes );
160     ret = strarrayUtoW( retU );
161
162     strfreeU( dnU );
163     ldap_memvfree( (void **)retU );
164
165 #endif
166     return ret;
167 }
168
169 /***********************************************************************
170  *      ldap_get_dnA     (WLDAP32.@)
171  *
172  * See ldap_get_dnW.
173  */
174 PCHAR ldap_get_dnA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
175 {
176     PCHAR ret = NULL;
177 #ifdef HAVE_LDAP
178     PWCHAR retW;
179
180     TRACE( "(%p, %p)\n", ld, entry );
181
182     if (!ld || !entry) return NULL;
183
184     retW = ldap_get_dnW( ld, entry );
185
186     ret = strWtoA( retW );
187     ldap_memfreeW( retW );
188
189 #endif
190     return ret;
191 }
192
193 /***********************************************************************
194  *      ldap_get_dnW     (WLDAP32.@)
195  *
196  * Retrieve the DN from a given LDAP message.
197  *
198  * PARAMS
199  *  ld     [I] Pointer to an LDAP context.
200  *  entry  [I] LDAPMessage structure to retrieve the DN from.
201  *
202  * RETURNS
203  *  Success: Pointer to a string that contains the DN.
204  *  Failure: NULL
205  *
206  * NOTES
207  *  Free the string with ldap_memfree.
208  */
209 PWCHAR ldap_get_dnW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
210 {
211     PWCHAR ret = NULL;
212 #ifdef HAVE_LDAP
213     char *retU;
214
215     TRACE( "(%p, %p)\n", ld, entry );
216
217     if (!ld || !entry) return NULL;
218
219     retU = ldap_get_dn( ld, entry );
220
221     ret = strUtoW( retU );
222     ldap_memfree( retU );
223
224 #endif
225     return ret;
226 }
227
228 /***********************************************************************
229  *      ldap_ufn2dnA     (WLDAP32.@)
230  *
231  * See ldap_ufn2dnW.
232  */
233 ULONG ldap_ufn2dnA( PCHAR ufn, PCHAR *dn )
234 {
235     ULONG ret = LDAP_SUCCESS;
236 #ifdef HAVE_LDAP
237     PWCHAR ufnW = NULL, dnW = NULL;
238
239     TRACE( "(%s, %p)\n", debugstr_a(ufn), dn );
240
241     if (!dn) return WLDAP32_LDAP_PARAM_ERROR;
242
243     *dn = NULL;
244
245     if (ufn) {
246         ufnW = strAtoW( ufn );
247         if (!ufnW) return WLDAP32_LDAP_NO_MEMORY;
248     }
249
250     ret = ldap_ufn2dnW( ufnW, &dnW );
251
252     if (dnW) {
253         *dn = strWtoA( dnW );
254         if (!*dn) ret = WLDAP32_LDAP_NO_MEMORY;
255     }
256
257     strfreeW( ufnW );
258     ldap_memfreeW( dnW );
259
260 #endif
261     return ret;
262 }
263
264 /***********************************************************************
265  *      ldap_ufn2dnW     (WLDAP32.@)
266  *
267  * Convert a user-friendly name to a DN.
268  *
269  * PARAMS
270  *  ufn  [I] User-friendly name to convert.
271  *  dn   [O] Receives a pointer to a string containing the DN. 
272  *
273  * RETURNS
274  *  Success: LDAP_SUCCESS
275  *  Failure: An LDAP error code.
276  *
277  * NOTES
278  *  Free the string with ldap_memfree.
279  */
280 ULONG ldap_ufn2dnW( PWCHAR ufn, PWCHAR *dn )
281 {
282     ULONG ret = LDAP_SUCCESS;
283 #ifdef HAVE_LDAP
284     char *ufnU = NULL;
285
286     TRACE( "(%s, %p)\n", debugstr_w(ufn), dn );
287
288     if (!dn) return WLDAP32_LDAP_PARAM_ERROR;
289
290     *dn = NULL;
291
292     if (ufn) {
293         ufnU = strWtoU( ufn );
294         if (!ufnU) return WLDAP32_LDAP_NO_MEMORY;
295
296         /* FIXME: do more than just a copy */
297         *dn = strUtoW( ufnU );
298         if (!*dn) ret = WLDAP32_LDAP_NO_MEMORY;
299     }
300
301     strfreeU( ufnU );
302
303 #endif
304     return ret;
305 }