1 /* w32-ldap-help.h - Map utf8 based API into a wchar_t API.
2 * Copyright (C) 2010 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * GnuPG 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
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <https://www.gnu.org/licenses/>.
20 #ifndef W32_LDAP_HELP_H
21 #define W32_LDAP_HELP_H
23 #ifndef HAVE_W32CE_SYSTEM
24 # error This is only required for W32CE.
29 _dirmngr_ldap_init (const char *host, unsigned short port)
32 wchar_t *whost = NULL;
36 whost = utf8_to_wchar (host);
40 ld = ldap_init (whost, port);
47 _dirmngr_ldap_simple_bind_s (LDAP *ld, const char *user, const char *pass)
50 wchar_t *wuser, *wpass;
52 wuser = user? utf8_to_wchar (user) : NULL;
53 wpass = pass? utf8_to_wchar (pass) : NULL;
54 /* We can't easily map errnos to ldap_errno, thus we pass a NULL to
55 the function in the hope that the server will throw an error. */
56 ret = ldap_simple_bind_s (ld, wuser, wpass);
64 _dirmngr_ldap_search_st (LDAP *ld, const char *base, ULONG scope,
65 const char *filter, char **attrs,
66 ULONG attrsonly, struct timeval *timeout,
69 ULONG ret = LDAP_NO_MEMORY;
70 wchar_t *wbase = NULL;
71 wchar_t *wfilter = NULL;
72 wchar_t **wattrs = NULL;
77 wbase = utf8_to_wchar (base);
83 wfilter = utf8_to_wchar (filter);
89 for (i=0; attrs[i]; i++)
91 wattrs = xtrycalloc (i+1, sizeof *wattrs);
94 for (i=0; attrs[i]; i++)
96 wattrs[i] = utf8_to_wchar (attrs[i]);
102 ret = ldap_search_st (ld, wbase, scope, wfilter, wattrs, attrsonly,
103 (struct l_timeval *)timeout, res);
108 for (i=0; wattrs[i]; i++)
119 _dirmngr_ldap_first_attribute (LDAP *ld, LDAPMessage *msg, BerElement **elem)
124 wattr = ldap_first_attribute (ld, msg, elem);
127 attr = wchar_to_utf8 (wattr);
128 ldap_memfree (wattr);
134 _dirmngr_ldap_next_attribute (LDAP *ld, LDAPMessage *msg, BerElement *elem)
139 wattr = ldap_next_attribute (ld, msg, elem);
142 attr = wchar_to_utf8 (wattr);
143 ldap_memfree (wattr);
147 static inline BerValue **
148 _dirmngr_ldap_get_values_len (LDAP *ld, LDAPMessage *msg, const char *attr)
155 wattr = utf8_to_wchar (attr);
162 ret = ldap_get_values_len (ld, msg, wattr);
169 #endif /*W32_LDAP_HELP_H*/