Make CryptImport/ExportPublicKeyInfoEx behave the way MSDN describes
[wine/gsoc-2012-control.git] / dlls / wldap32 / dn.c
blobe54946af22ce66b1f6e7831f0695222009e63a6f
1 /*
2 * WLDAP32 - LDAP support for Wine
4 * Copyright 2005 Hans Leidekker
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.
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.
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
21 #include "config.h"
23 #include "wine/port.h"
24 #include "wine/debug.h"
26 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
32 #ifdef HAVE_LDAP_H
33 #include <ldap.h>
34 #else
35 #define LDAP_SUCCESS 0x00
36 #endif
38 #include "winldap_private.h"
39 #include "wldap32.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
43 PCHAR ldap_dn2ufnA( PCHAR dn )
45 PCHAR ret = NULL;
46 #ifdef HAVE_LDAP
47 WCHAR *dnW, *retW;
49 TRACE( "(%s)\n", debugstr_a(dn) );
51 dnW = strAtoW( dn );
52 if (!dnW) return NULL;
54 retW = ldap_dn2ufnW( dnW );
55 ret = strWtoA( retW );
57 strfreeW( dnW );
58 ldap_memfreeW( retW );
60 #endif
61 return ret;
64 PWCHAR ldap_dn2ufnW( PWCHAR dn )
66 PWCHAR ret = NULL;
67 #ifdef HAVE_LDAP
68 char *dnU, *retU;
70 TRACE( "(%s)\n", debugstr_w(dn) );
72 dnU = strWtoU( dn );
73 if (!dnU) return NULL;
75 retU = ldap_dn2ufn( dnU );
76 ret = strUtoW( retU );
78 strfreeU( dnU );
79 ldap_memfree( retU );
81 #endif
82 return ret;
85 PCHAR *ldap_explode_dnA( PCHAR dn, ULONG notypes )
87 PCHAR *ret = NULL;
88 #ifdef HAVE_LDAP
89 WCHAR *dnW, **retW;
91 TRACE( "(%s, 0x%08lx)\n", debugstr_a(dn), notypes );
93 dnW = strAtoW( dn );
94 if (!dnW) return NULL;
96 retW = ldap_explode_dnW( dnW, notypes );
97 ret = strarrayWtoA( retW );
99 strfreeW( dnW );
100 ldap_value_freeW( retW );
102 #endif
103 return ret;
106 PWCHAR *ldap_explode_dnW( PWCHAR dn, ULONG notypes )
108 PWCHAR *ret = NULL;
109 #ifdef HAVE_LDAP
110 char *dnU, **retU;
112 TRACE( "(%s, 0x%08lx)\n", debugstr_w(dn), notypes );
114 dnU = strWtoU( dn );
115 if (!dnU) return NULL;
117 retU = ldap_explode_dn( dnU, notypes );
118 ret = strarrayUtoW( retU );
120 strfreeU( dnU );
121 ldap_value_free( retU );
123 #endif
124 return ret;
127 PCHAR ldap_get_dnA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
129 PCHAR ret = NULL;
130 #ifdef HAVE_LDAP
131 PWCHAR retW;
133 TRACE( "(%p, %p)\n", ld, entry );
135 if (!ld || !entry) return NULL;
137 retW = ldap_get_dnW( ld, entry );
139 ret = strWtoA( retW );
140 ldap_memfreeW( retW );
142 #endif
143 return ret;
146 PWCHAR ldap_get_dnW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry )
148 PWCHAR ret = NULL;
149 #ifdef HAVE_LDAP
150 char *retU;
152 TRACE( "(%p, %p)\n", ld, entry );
154 if (!ld || !entry) return NULL;
156 retU = ldap_get_dn( ld, entry );
158 ret = strUtoW( retU );
159 ldap_memfree( retU );
161 #endif
162 return ret;
165 ULONG ldap_ufn2dnA( PCHAR ufn, PCHAR *dn )
167 ULONG ret = LDAP_SUCCESS;
168 #ifdef HAVE_LDAP
169 PWCHAR ufnW = NULL, dnW = NULL;
171 TRACE( "(%s, %p)\n", debugstr_a(ufn), dn );
173 if (!dn) return WLDAP32_LDAP_PARAM_ERROR;
175 *dn = NULL;
177 if (ufn) {
178 ufnW = strAtoW( ufn );
179 if (!ufnW) return WLDAP32_LDAP_NO_MEMORY;
182 ret = ldap_ufn2dnW( ufnW, &dnW );
184 if (dnW) {
185 *dn = strWtoA( dnW );
186 if (!*dn) ret = WLDAP32_LDAP_NO_MEMORY;
189 strfreeW( ufnW );
190 ldap_memfreeW( dnW );
192 #endif
193 return ret;
196 ULONG ldap_ufn2dnW( PWCHAR ufn, PWCHAR *dn )
198 ULONG ret = LDAP_SUCCESS;
199 #ifdef HAVE_LDAP
200 char *ufnU = NULL;
202 TRACE( "(%s, %p)\n", debugstr_w(ufn), dn );
204 if (!dn) return WLDAP32_LDAP_PARAM_ERROR;
206 *dn = NULL;
208 if (ufn) {
209 ufnU = strWtoU( ufn );
210 if (!ufnU) return WLDAP32_LDAP_NO_MEMORY;
212 /* FIXME: do more than just a copy */
213 *dn = strUtoW( ufnU );
214 if (!*dn) ret = WLDAP32_LDAP_NO_MEMORY;
217 strfreeU( ufnU );
219 #endif
220 return ret;