Implement ldap_bind* functions.

This commit is contained in:
Hans Leidekker 2005-07-19 20:32:46 +00:00 committed by Alexandre Julliard
parent 8b8c901a78
commit 7a1876e5ae
5 changed files with 287 additions and 0 deletions

View File

@ -9,6 +9,7 @@ EXTRALIBS = @LDAPLIBS@
C_SRCS = \ C_SRCS = \
ber.c \ ber.c \
bind.c \
main.c main.c
@MAKE_DLL_RULES@ @MAKE_DLL_RULES@

134
dlls/wldap32/bind.c Normal file
View File

@ -0,0 +1,134 @@
/*
* WLDAP32 - LDAP support for Wine
*
* Copyright 2005 Hans Leidekker
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include "wine/port.h"
#include "wine/debug.h"
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "winnls.h"
#ifdef HAVE_LDAP
#include <ldap.h>
#else
#define LDAP_SUCCESS 0x00
#define LDAP_NOT_SUPPORTED 0x5c
#endif
#include "winldap_private.h"
#include "wldap32.h"
WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
ULONG ldap_bindA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR cred, ULONG method )
{
ULONG ret = LDAP_NOT_SUPPORTED;
#ifdef HAVE_LDAP
WCHAR *dnW, *credW;
TRACE( "(%p, %s, %p, 0x%08lx)\n", ld, debugstr_a(dn), cred, method );
dnW = strAtoW( dn );
if (!dnW) return LDAP_NO_MEMORY;
credW = strAtoW( cred );
if (!credW) return LDAP_NO_MEMORY;
ret = ldap_bindW( ld, dnW, credW, method );
strfreeW( dnW );
strfreeW( credW );
#endif
return ret;
}
ULONG ldap_bindW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR cred, ULONG method )
{
ULONG ret = LDAP_NOT_SUPPORTED;
#ifdef HAVE_LDAP
char *dnU, *credU;
TRACE( "(%p, %s, %p, 0x%08lx)\n", ld, debugstr_w(dn), cred, method );
dnU = strWtoU( dn );
if (!dnU) return LDAP_NO_MEMORY;
credU = strWtoU( cred );
if (!credU) return LDAP_NO_MEMORY;
ret = ldap_bind( ld, dnU, credU, method );
strfreeU( dnU );
strfreeU( credU );
#endif
return ret;
}
ULONG ldap_bind_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR cred, ULONG method )
{
ULONG ret = LDAP_NOT_SUPPORTED;
#ifdef HAVE_LDAP
WCHAR *dnW, *credW;
TRACE( "(%p, %s, %p, 0x%08lx)\n", ld, debugstr_a(dn), cred, method );
dnW = strAtoW( dn );
if (!dnW) return LDAP_NO_MEMORY;
credW = strAtoW( cred );
if (!credW) return LDAP_NO_MEMORY;
ret = ldap_bind_sW( ld, dnW, credW, method );
strfreeW( dnW );
strfreeW( credW );
#endif
return ret;
}
ULONG ldap_bind_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR cred, ULONG method )
{
ULONG ret = LDAP_NOT_SUPPORTED;
#ifdef HAVE_LDAP
char *dnU, *credU;
TRACE( "(%p, %s, %p, 0x%08lx)\n", ld, debugstr_w(dn), cred, method );
dnU = strWtoU( dn );
if (!dnU) return LDAP_NO_MEMORY;
credU = strWtoU( cred );
if (!credU) return LDAP_NO_MEMORY;
ret = ldap_bind_s( ld, dnU, credU, method );
strfreeU( dnU );
strfreeU( credU );
#endif
return ret;
}

View File

@ -0,0 +1,60 @@
/*
* WLDAP32 - LDAP support for Wine
*
* Copyright 2005 Hans Leidekker
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* This is an internal version of winldap.h where constants, types and
* functions are prefixed with WLDAP32_ whenever they conflict with
* native headers.
*/
typedef struct ldap
{
struct
{
UINT_PTR sb_sd;
UCHAR Reserved1[41];
ULONG_PTR sb_naddr;
UCHAR Reserved2[24];
} ld_sb;
PCHAR ld_host;
ULONG ld_version;
UCHAR ld_lberoptions;
ULONG ld_deref;
ULONG ld_timelimit;
ULONG ld_sizelimit;
ULONG ld_errno;
PCHAR ld_matched;
PCHAR ld_error;
ULONG ld_msgid;
UCHAR Reserved3[25];
ULONG ld_cldaptries;
ULONG ld_cldaptimeout;
ULONG ld_refhoplimit;
ULONG ld_options;
} WLDAP32_LDAP, *WLDAP32_PLDAP;
ULONG ldap_bindA(WLDAP32_LDAP*,PCHAR,PCHAR,ULONG);
ULONG ldap_bindW(WLDAP32_LDAP*,PWCHAR,PWCHAR,ULONG);
ULONG ldap_bind_sA(WLDAP32_LDAP*,PCHAR,PCHAR,ULONG);
ULONG ldap_bind_sW(WLDAP32_LDAP*,PWCHAR,PWCHAR,ULONG);
ULONG LdapGetLastError(void);
ULONG LdapMapErrorToWin32(ULONG);
int LdapUnicodeToUTF8(LPCWSTR,int,LPSTR,int);
int LdapUTF8ToUnicode(LPCSTR,int,LPWSTR,int);

86
dlls/wldap32/wldap32.h Normal file
View File

@ -0,0 +1,86 @@
/*
* WLDAP32 - LDAP support for Wine
*
* Copyright 2005 Hans Leidekker
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* A set of helper functions to convert LDAP data structures
* to and from ansi (A), wide character (W) and utf8 (U) encodings.
*/
static inline LPWSTR strAtoW( LPCSTR str )
{
LPWSTR ret = NULL;
if (str)
{
DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
}
return ret;
}
static inline LPSTR strWtoA( LPCWSTR str )
{
LPSTR ret = NULL;
if (str)
{
DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
}
return ret;
}
static inline char *strWtoU( LPCWSTR str )
{
LPSTR ret = NULL;
if (str)
{
DWORD len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
WideCharToMultiByte( CP_UTF8, 0, str, -1, ret, len, NULL, NULL );
}
return ret;
}
static inline LPWSTR strUtoW( char *str )
{
LPWSTR ret = NULL;
if (str)
{
DWORD len = MultiByteToWideChar( CP_UTF8, 0, str, -1, NULL, 0 );
if ((ret = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
MultiByteToWideChar( CP_UTF8, 0, str, -1, ret, len );
}
return ret;
}
static inline void strfreeA( LPSTR str )
{
HeapFree( GetProcessHeap(), 0, str );
}
static inline void strfreeW( LPWSTR str )
{
HeapFree( GetProcessHeap(), 0, str );
}
static inline void strfreeU( char *str )
{
HeapFree( GetProcessHeap(), 0, str );
}

View File

@ -13,6 +13,12 @@
@ varargs ber_printf(ptr str) @ varargs ber_printf(ptr str)
@ varargs ber_scanf(ptr str) @ varargs ber_scanf(ptr str)
@ cdecl ber_skip_tag(ptr ptr) @ cdecl ber_skip_tag(ptr ptr)
@ cdecl ldap_bind(ptr str str long) ldap_bindA
@ cdecl ldap_bindA(ptr str str long)
@ cdecl ldap_bindW(ptr wstr wstr long)
@ cdecl ldap_bind_s(ptr str str long) ldap_bind_sA
@ cdecl ldap_bind_sA(ptr str str long)
@ cdecl ldap_bind_sW(ptr wstr wstr long)
@ stub ldap_open @ stub ldap_open
@ stub ldap_openA @ stub ldap_openA
@ stub ldap_openW @ stub ldap_openW