2005-07-21 13:02:11 +02:00
|
|
|
/*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-07-21 13:02:11 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2021-04-19 10:04:52 +02:00
|
|
|
#include <stdlib.h>
|
2005-07-21 13:02:11 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
2019-03-29 16:31:28 +01:00
|
|
|
#include "winternl.h"
|
2021-04-19 10:04:54 +02:00
|
|
|
#include "winldap.h"
|
2005-07-21 13:02:11 +02:00
|
|
|
|
2011-09-05 17:23:34 +02:00
|
|
|
#include "wine/debug.h"
|
2021-04-16 09:59:14 +02:00
|
|
|
#include "winldap_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
|
2005-07-21 13:02:11 +02:00
|
|
|
|
2005-11-18 17:56:44 +01:00
|
|
|
/* Split a space separated string of hostnames into a string array */
|
|
|
|
static char **split_hostnames( const char *hostnames )
|
|
|
|
{
|
|
|
|
char **res, *str, *p, *q;
|
|
|
|
unsigned int i = 0;
|
|
|
|
|
|
|
|
str = strdupU( hostnames );
|
|
|
|
if (!str) return NULL;
|
|
|
|
|
|
|
|
p = str;
|
|
|
|
while (isspace( *p )) p++;
|
|
|
|
if (*p) i++;
|
|
|
|
|
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
if (isspace( *p ))
|
|
|
|
{
|
|
|
|
while (isspace( *p )) p++;
|
|
|
|
if (*p) i++;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
2021-04-19 10:04:52 +02:00
|
|
|
if (!(res = malloc( (i + 1) * sizeof(char *) )))
|
2005-11-18 17:56:44 +01:00
|
|
|
{
|
2021-04-19 10:04:52 +02:00
|
|
|
free( str );
|
2005-11-18 17:56:44 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = str;
|
|
|
|
while (isspace( *p )) p++;
|
|
|
|
|
|
|
|
q = p;
|
|
|
|
i = 0;
|
2018-02-20 12:06:10 +01:00
|
|
|
|
2005-11-18 17:56:44 +01:00
|
|
|
while (*p)
|
|
|
|
{
|
|
|
|
if (p[1] != '\0')
|
|
|
|
{
|
|
|
|
if (isspace( *p ))
|
|
|
|
{
|
|
|
|
*p = '\0'; p++;
|
|
|
|
res[i] = strdupU( q );
|
|
|
|
if (!res[i]) goto oom;
|
|
|
|
i++;
|
2018-02-20 12:06:10 +01:00
|
|
|
|
2005-11-18 17:56:44 +01:00
|
|
|
while (isspace( *p )) p++;
|
|
|
|
q = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res[i] = strdupU( q );
|
|
|
|
if (!res[i]) goto oom;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
res[i] = NULL;
|
|
|
|
|
2021-04-19 10:04:52 +02:00
|
|
|
free( str );
|
2005-11-18 17:56:44 +01:00
|
|
|
return res;
|
|
|
|
|
|
|
|
oom:
|
2021-04-19 10:04:52 +02:00
|
|
|
while (i > 0) free( res[--i] );
|
|
|
|
free( res );
|
|
|
|
free( str );
|
2005-11-18 17:56:44 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine if a URL starts with a known LDAP scheme */
|
2013-10-01 23:33:52 +02:00
|
|
|
static BOOL has_ldap_scheme( char *url )
|
2005-11-18 17:56:44 +01:00
|
|
|
{
|
2019-03-29 16:31:28 +01:00
|
|
|
return !_strnicmp( url, "ldap://", 7 ) ||
|
|
|
|
!_strnicmp( url, "ldaps://", 8 ) ||
|
|
|
|
!_strnicmp( url, "ldapi://", 8 ) ||
|
|
|
|
!_strnicmp( url, "cldap://", 8 );
|
2005-11-18 17:56:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Flatten an array of hostnames into a space separated string of URLs.
|
2011-08-02 22:20:32 +02:00
|
|
|
* Prepend a given scheme and append a given port number to each hostname
|
2005-11-18 17:56:44 +01:00
|
|
|
* if necessary.
|
|
|
|
*/
|
2006-08-11 14:42:06 +02:00
|
|
|
static char *join_hostnames( const char *scheme, char **hostnames, ULONG portnumber )
|
2005-11-18 17:56:44 +01:00
|
|
|
{
|
|
|
|
char *res, *p, *q, **v;
|
2021-04-14 09:40:25 +02:00
|
|
|
unsigned int i = 0, size = 0;
|
2006-09-30 12:07:23 +02:00
|
|
|
static const char sep[] = " ", fmt[] = ":%d";
|
2005-12-31 13:33:31 +01:00
|
|
|
char port[7];
|
2005-11-18 17:56:44 +01:00
|
|
|
|
2021-04-14 09:40:25 +02:00
|
|
|
sprintf( port, fmt, portnumber );
|
2005-11-18 17:56:44 +01:00
|
|
|
|
|
|
|
for (v = hostnames; *v; v++)
|
|
|
|
{
|
|
|
|
if (!has_ldap_scheme( *v ))
|
|
|
|
{
|
|
|
|
size += strlen( scheme );
|
|
|
|
q = *v;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* skip past colon in scheme prefix */
|
|
|
|
q = strchr( *v, '/' );
|
|
|
|
|
|
|
|
size += strlen( *v );
|
|
|
|
|
2021-04-14 09:40:25 +02:00
|
|
|
if (!strchr( q, ':' ))
|
2005-11-18 17:56:44 +01:00
|
|
|
size += strlen( port );
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
size += (i - 1) * strlen( sep );
|
2021-04-19 10:04:52 +02:00
|
|
|
if (!(res = malloc( size + 1 ))) return NULL;
|
2005-11-18 17:56:44 +01:00
|
|
|
|
|
|
|
p = res;
|
|
|
|
for (v = hostnames; *v; v++)
|
|
|
|
{
|
|
|
|
if (v != hostnames)
|
|
|
|
{
|
|
|
|
strcpy( p, sep );
|
|
|
|
p += strlen( sep );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!has_ldap_scheme( *v ))
|
|
|
|
{
|
|
|
|
strcpy( p, scheme );
|
|
|
|
p += strlen( scheme );
|
|
|
|
q = *v;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* skip past colon in scheme prefix */
|
|
|
|
q = strchr( *v, '/' );
|
|
|
|
|
|
|
|
strcpy( p, *v );
|
|
|
|
p += strlen( *v );
|
|
|
|
|
|
|
|
if (!strchr( q, ':' ))
|
|
|
|
{
|
|
|
|
strcpy( p, port );
|
|
|
|
p += strlen( port );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-08-11 14:42:06 +02:00
|
|
|
static char *urlify_hostnames( const char *scheme, char *hostnames, ULONG port )
|
2005-11-18 17:56:44 +01:00
|
|
|
{
|
2005-12-31 13:33:31 +01:00
|
|
|
char *url = NULL, **strarray;
|
2005-11-18 17:56:44 +01:00
|
|
|
|
|
|
|
strarray = split_hostnames( hostnames );
|
2005-12-31 13:33:31 +01:00
|
|
|
if (strarray)
|
|
|
|
url = join_hostnames( scheme, strarray, port );
|
|
|
|
else
|
|
|
|
return NULL;
|
2005-11-18 17:56:44 +01:00
|
|
|
|
2005-12-31 13:33:31 +01:00
|
|
|
strarrayfreeU( strarray );
|
2005-11-18 17:56:44 +01:00
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2005-07-21 13:02:11 +02:00
|
|
|
|
2021-04-19 10:04:54 +02:00
|
|
|
static LDAP *create_context( const char *url )
|
2017-10-05 10:05:33 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAP *ld;
|
|
|
|
int version = LDAP_VERSION3;
|
2020-04-03 10:56:57 +02:00
|
|
|
|
2021-04-19 10:04:52 +02:00
|
|
|
if (!(ld = calloc( 1, sizeof( *ld )))) return NULL;
|
2021-04-19 10:04:54 +02:00
|
|
|
if (map_error( ldap_funcs->fn_ldap_initialize( &CTX(ld), url ) ) != LDAP_SUCCESS)
|
2020-04-03 10:56:57 +02:00
|
|
|
{
|
2021-04-19 10:04:52 +02:00
|
|
|
free( ld );
|
2020-04-03 10:56:57 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2021-04-19 10:04:54 +02:00
|
|
|
ldap_funcs->fn_ldap_set_option( CTX(ld), LDAP_OPT_PROTOCOL_VERSION, &version );
|
2017-10-05 10:05:33 +02:00
|
|
|
return ld;
|
|
|
|
}
|
|
|
|
|
2005-12-31 13:33:31 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* cldap_openA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See cldap_openW.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAP * CDECL cldap_openA( char *hostname, ULONG portnumber )
|
2005-08-22 20:56:54 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAP *ld;
|
2005-11-18 17:56:44 +01:00
|
|
|
WCHAR *hostnameW = NULL;
|
|
|
|
|
2006-09-30 12:07:23 +02:00
|
|
|
TRACE( "(%s, %d)\n", debugstr_a(hostname), portnumber );
|
2005-08-22 20:56:54 +02:00
|
|
|
|
2021-04-16 09:59:14 +02:00
|
|
|
if (hostname && !(hostnameW = strAtoW( hostname ))) return NULL;
|
2005-11-18 17:56:44 +01:00
|
|
|
|
|
|
|
ld = cldap_openW( hostnameW, portnumber );
|
|
|
|
|
2021-04-19 10:04:52 +02:00
|
|
|
free( hostnameW );
|
2005-11-18 17:56:44 +01:00
|
|
|
return ld;
|
2005-08-22 20:56:54 +02:00
|
|
|
}
|
|
|
|
|
2005-12-31 13:33:31 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* cldap_openW (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Initialize an LDAP context and create a UDP connection.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hostname [I] Name of the host to connect to.
|
2011-08-02 22:20:32 +02:00
|
|
|
* portnumber [I] Port number to use.
|
2005-12-31 13:33:31 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Pointer to an LDAP context.
|
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The hostname string can be a space separated string of hostnames,
|
|
|
|
* in which case the LDAP runtime will try to connect to the hosts
|
|
|
|
* in order, until a connection can be made. A hostname may have a
|
2011-08-02 22:20:32 +02:00
|
|
|
* trailing port number (separated from the hostname by a ':'), which
|
|
|
|
* will take precedence over the port number supplied as a parameter
|
2005-12-31 13:33:31 +01:00
|
|
|
* to this function.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAP * CDECL cldap_openW( WCHAR *hostname, ULONG portnumber )
|
2005-08-22 20:56:54 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAP *ld = NULL;
|
2021-04-16 09:59:14 +02:00
|
|
|
char *hostnameU, *url = NULL;
|
2005-11-18 17:56:44 +01:00
|
|
|
|
2006-09-30 12:07:23 +02:00
|
|
|
TRACE( "(%s, %d)\n", debugstr_w(hostname), portnumber );
|
2005-08-22 20:56:54 +02:00
|
|
|
|
2021-04-19 10:04:53 +02:00
|
|
|
if (!(hostnameU = strWtoU( hostname ? hostname : L"localhost" ))) return NULL;
|
2021-04-16 09:59:14 +02:00
|
|
|
if (!(url = urlify_hostnames( "cldap://", hostnameU, portnumber ))) goto exit;
|
2005-11-18 17:56:44 +01:00
|
|
|
|
2017-10-05 10:05:33 +02:00
|
|
|
ld = create_context( url );
|
2005-11-18 17:56:44 +01:00
|
|
|
|
|
|
|
exit:
|
2021-04-19 10:04:52 +02:00
|
|
|
free( hostnameU );
|
|
|
|
free( url );
|
2005-11-18 17:56:44 +01:00
|
|
|
return ld;
|
2005-08-22 20:56:54 +02:00
|
|
|
}
|
|
|
|
|
2005-12-31 13:33:31 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_connect (WLDAP32.@)
|
|
|
|
*
|
2021-04-14 09:40:25 +02:00
|
|
|
* Connect to an LDAP server.
|
2005-12-31 13:33:31 +01:00
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ld [I] Pointer to an LDAP context.
|
|
|
|
* timeout [I] Pointer to an l_timeval structure specifying the
|
|
|
|
* timeout in seconds.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: LDAP_SUCCESS
|
|
|
|
* Failure: An LDAP error code.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The timeout parameter may be NULL in which case a default timeout
|
|
|
|
* value will be used.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG CDECL ldap_connect( LDAP *ld, struct l_timeval *timeout )
|
2005-08-22 20:56:54 +02:00
|
|
|
{
|
|
|
|
TRACE( "(%p, %p)\n", ld, timeout );
|
|
|
|
|
2021-04-19 10:04:54 +02:00
|
|
|
if (!ld) return LDAP_PARAM_ERROR;
|
|
|
|
return LDAP_SUCCESS; /* FIXME: do something, e.g. ping the host */
|
2005-08-22 20:56:54 +02:00
|
|
|
}
|
|
|
|
|
2005-12-31 13:33:31 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_initA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_initW.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAP * CDECL ldap_initA( const PCHAR hostname, ULONG portnumber )
|
2005-07-21 13:02:11 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAP *ld;
|
2005-07-26 20:25:22 +02:00
|
|
|
WCHAR *hostnameW = NULL;
|
2005-07-21 13:02:11 +02:00
|
|
|
|
2006-09-30 12:07:23 +02:00
|
|
|
TRACE( "(%s, %d)\n", debugstr_a(hostname), portnumber );
|
2005-07-21 13:02:11 +02:00
|
|
|
|
2021-04-16 09:59:14 +02:00
|
|
|
if (hostname && !(hostnameW = strAtoW( hostname ))) return NULL;
|
2005-07-21 13:02:11 +02:00
|
|
|
|
|
|
|
ld = ldap_initW( hostnameW, portnumber );
|
|
|
|
|
2021-04-19 10:04:52 +02:00
|
|
|
free( hostnameW );
|
2005-07-21 13:02:11 +02:00
|
|
|
return ld;
|
|
|
|
}
|
|
|
|
|
2005-12-31 13:33:31 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_initW (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Initialize an LDAP context and create a TCP connection.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hostname [I] Name of the host to connect to.
|
2011-08-02 22:20:32 +02:00
|
|
|
* portnumber [I] Port number to use.
|
2005-12-31 13:33:31 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Pointer to an LDAP context.
|
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The hostname string can be a space separated string of hostnames,
|
|
|
|
* in which case the LDAP runtime will try to connect to the hosts
|
|
|
|
* in order, until a connection can be made. A hostname may have a
|
2011-08-02 22:20:32 +02:00
|
|
|
* trailing port number (separated from the hostname by a ':'), which
|
|
|
|
* will take precedence over the port number supplied as a parameter
|
2005-12-31 13:33:31 +01:00
|
|
|
* to this function. The connection will not be made until the first
|
|
|
|
* LDAP function that needs it is called.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAP * CDECL ldap_initW( const PWCHAR hostname, ULONG portnumber )
|
2005-07-21 13:02:11 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAP *ld = NULL;
|
2021-04-16 09:59:14 +02:00
|
|
|
char *hostnameU, *url = NULL;
|
2005-07-26 20:25:22 +02:00
|
|
|
|
2006-09-30 12:07:23 +02:00
|
|
|
TRACE( "(%s, %d)\n", debugstr_w(hostname), portnumber );
|
2005-07-21 13:02:11 +02:00
|
|
|
|
2021-04-19 10:04:53 +02:00
|
|
|
if (!(hostnameU = strWtoU( hostname ? hostname : L"localhost" ))) return NULL;
|
2021-04-16 09:59:14 +02:00
|
|
|
if (!(url = urlify_hostnames( "ldap://", hostnameU, portnumber ))) goto exit;
|
2005-11-18 17:56:44 +01:00
|
|
|
|
2017-10-05 10:05:33 +02:00
|
|
|
ld = create_context( url );
|
2005-07-21 13:02:11 +02:00
|
|
|
|
2005-07-26 20:25:22 +02:00
|
|
|
exit:
|
2021-04-19 10:04:52 +02:00
|
|
|
free( hostnameU );
|
|
|
|
free( url );
|
2005-07-21 13:02:11 +02:00
|
|
|
return ld;
|
|
|
|
}
|
|
|
|
|
2005-12-31 13:33:31 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_openA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_openW.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAP * CDECL ldap_openA( char *hostname, ULONG portnumber )
|
2005-07-21 13:02:11 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAP *ld;
|
2005-07-26 20:25:22 +02:00
|
|
|
WCHAR *hostnameW = NULL;
|
2005-07-21 13:02:11 +02:00
|
|
|
|
2006-09-30 12:07:23 +02:00
|
|
|
TRACE( "(%s, %d)\n", debugstr_a(hostname), portnumber );
|
2005-07-21 13:02:11 +02:00
|
|
|
|
2021-04-16 09:59:14 +02:00
|
|
|
if (hostname && !(hostnameW = strAtoW( hostname ))) return NULL;
|
2005-07-21 13:02:11 +02:00
|
|
|
|
|
|
|
ld = ldap_openW( hostnameW, portnumber );
|
|
|
|
|
2021-04-19 10:04:52 +02:00
|
|
|
free( hostnameW );
|
2005-07-21 13:02:11 +02:00
|
|
|
return ld;
|
|
|
|
}
|
|
|
|
|
2005-12-31 13:33:31 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_openW (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Initialize an LDAP context and create a TCP connection.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hostname [I] Name of the host to connect to.
|
2011-08-02 22:20:32 +02:00
|
|
|
* portnumber [I] Port number to use.
|
2005-12-31 13:33:31 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Pointer to an LDAP context.
|
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The hostname string can be a space separated string of hostnames,
|
|
|
|
* in which case the LDAP runtime will try to connect to the hosts
|
|
|
|
* in order, until a connection can be made. A hostname may have a
|
2011-08-02 22:20:32 +02:00
|
|
|
* trailing port number (separated from the hostname by a ':'), which
|
|
|
|
* will take precedence over the port number supplied as a parameter
|
2005-12-31 13:33:31 +01:00
|
|
|
* to this function.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAP * CDECL ldap_openW( WCHAR *hostname, ULONG portnumber )
|
2005-07-21 13:02:11 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAP *ld = NULL;
|
2021-04-16 09:59:14 +02:00
|
|
|
char *hostnameU, *url = NULL;
|
2005-07-21 13:02:11 +02:00
|
|
|
|
2006-09-30 12:07:23 +02:00
|
|
|
TRACE( "(%s, %d)\n", debugstr_w(hostname), portnumber );
|
2005-07-21 13:02:11 +02:00
|
|
|
|
2021-04-19 10:04:53 +02:00
|
|
|
if (!(hostnameU = strWtoU( hostname ? hostname : L"localhost" ))) return NULL;
|
2021-04-16 09:59:14 +02:00
|
|
|
if (!(url = urlify_hostnames( "ldap://", hostnameU, portnumber ))) goto exit;
|
2005-11-18 17:56:44 +01:00
|
|
|
|
2017-10-05 10:05:33 +02:00
|
|
|
ld = create_context( url );
|
2005-11-18 17:56:44 +01:00
|
|
|
|
|
|
|
exit:
|
2021-04-19 10:04:52 +02:00
|
|
|
free( hostnameU );
|
|
|
|
free( url );
|
2005-11-18 17:56:44 +01:00
|
|
|
return ld;
|
|
|
|
}
|
|
|
|
|
2005-12-31 13:33:31 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_sslinitA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_sslinitW.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAP * CDECL ldap_sslinitA( char *hostname, ULONG portnumber, int secure )
|
2005-11-18 17:56:44 +01:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAP *ld;
|
2005-11-18 17:56:44 +01:00
|
|
|
WCHAR *hostnameW = NULL;
|
|
|
|
|
2006-09-30 12:07:23 +02:00
|
|
|
TRACE( "(%s, %d, 0x%08x)\n", debugstr_a(hostname), portnumber, secure );
|
2005-11-18 17:56:44 +01:00
|
|
|
|
2021-04-16 09:59:14 +02:00
|
|
|
if (hostname && !(hostnameW = strAtoW( hostname ))) return NULL;
|
2005-11-18 17:56:44 +01:00
|
|
|
|
|
|
|
ld = ldap_sslinitW( hostnameW, portnumber, secure );
|
|
|
|
|
2021-04-19 10:04:52 +02:00
|
|
|
free( hostnameW );
|
2005-11-18 17:56:44 +01:00
|
|
|
return ld;
|
|
|
|
}
|
|
|
|
|
2005-12-31 13:33:31 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_sslinitW (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Initialize an LDAP context and create a secure TCP connection.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hostname [I] Name of the host to connect to.
|
2011-08-02 22:20:32 +02:00
|
|
|
* portnumber [I] Port number to use.
|
2005-12-31 13:33:31 +01:00
|
|
|
* secure [I] Ask the server to create an SSL connection.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: Pointer to an LDAP context.
|
|
|
|
* Failure: NULL
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The hostname string can be a space separated string of hostnames,
|
|
|
|
* in which case the LDAP runtime will try to connect to the hosts
|
|
|
|
* in order, until a connection can be made. A hostname may have a
|
2011-08-02 22:20:32 +02:00
|
|
|
* trailing port number (separated from the hostname by a ':'), which
|
|
|
|
* will take precedence over the port number supplied as a parameter
|
2005-12-31 13:33:31 +01:00
|
|
|
* to this function. The connection will not be made until the first
|
|
|
|
* LDAP function that needs it is called.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAP * CDECL ldap_sslinitW( WCHAR *hostname, ULONG portnumber, int secure )
|
2005-11-18 17:56:44 +01:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
LDAP *ld = NULL;
|
2021-04-16 09:59:14 +02:00
|
|
|
char *hostnameU, *url = NULL;
|
2005-11-18 17:56:44 +01:00
|
|
|
|
2006-09-30 12:07:23 +02:00
|
|
|
TRACE( "(%s, %d, 0x%08x)\n", debugstr_w(hostname), portnumber, secure );
|
2005-11-18 17:56:44 +01:00
|
|
|
|
2021-04-19 10:04:53 +02:00
|
|
|
if (!(hostnameU = strWtoU( hostname ? hostname : L"localhost" ))) return NULL;
|
2005-11-18 17:56:44 +01:00
|
|
|
|
|
|
|
if (secure)
|
|
|
|
url = urlify_hostnames( "ldaps://", hostnameU, portnumber );
|
|
|
|
else
|
|
|
|
url = urlify_hostnames( "ldap://", hostnameU, portnumber );
|
|
|
|
if (!url) goto exit;
|
2021-01-19 15:55:31 +01:00
|
|
|
|
|
|
|
ld = create_context( url );
|
2005-07-21 13:02:11 +02:00
|
|
|
|
2005-07-26 20:25:22 +02:00
|
|
|
exit:
|
2021-04-19 10:04:52 +02:00
|
|
|
free( hostnameU );
|
|
|
|
free( url );
|
2005-07-21 13:02:11 +02:00
|
|
|
return ld;
|
|
|
|
}
|
2005-07-25 13:09:51 +02:00
|
|
|
|
2005-12-31 13:33:31 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_start_tls_sA (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* See ldap_start_tls_sW.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG CDECL ldap_start_tls_sA( LDAP *ld, ULONG *retval, LDAPMessage **result, LDAPControlA **serverctrls,
|
|
|
|
LDAPControlA **clientctrls )
|
2005-07-25 13:09:51 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG ret = LDAP_NO_MEMORY;
|
2005-07-26 20:25:22 +02:00
|
|
|
LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
|
2005-08-02 16:42:10 +02:00
|
|
|
|
2005-07-25 13:09:51 +02:00
|
|
|
TRACE( "(%p, %p, %p, %p, %p)\n", ld, retval, result, serverctrls, clientctrls );
|
|
|
|
|
2009-01-05 12:40:28 +01:00
|
|
|
if (!ld) return ~0u;
|
2005-07-25 13:09:51 +02:00
|
|
|
|
2021-04-16 09:59:14 +02:00
|
|
|
if (serverctrls && !(serverctrlsW = controlarrayAtoW( serverctrls ))) goto exit;
|
|
|
|
if (clientctrls && !(clientctrlsW = controlarrayAtoW( clientctrls ))) goto exit;
|
2005-07-25 13:09:51 +02:00
|
|
|
|
|
|
|
ret = ldap_start_tls_sW( ld, retval, result, serverctrlsW, clientctrlsW );
|
|
|
|
|
2005-07-26 20:25:22 +02:00
|
|
|
exit:
|
2005-07-25 13:09:51 +02:00
|
|
|
controlarrayfreeW( serverctrlsW );
|
|
|
|
controlarrayfreeW( clientctrlsW );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-12-31 13:33:31 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_start_tls_s (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Start TLS encryption on an LDAP connection.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ld [I] Pointer to an LDAP context.
|
|
|
|
* retval [I] Return value from the server.
|
|
|
|
* result [I] Response message from the server.
|
|
|
|
* serverctrls [I] Array of LDAP server controls.
|
|
|
|
* clientctrls [I] Array of LDAP client controls.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: LDAP_SUCCESS
|
|
|
|
* Failure: An LDAP error code.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* LDAP function that needs it is called.
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG CDECL ldap_start_tls_sW( LDAP *ld, ULONG *retval, LDAPMessage **result, LDAPControlW **serverctrls,
|
|
|
|
LDAPControlW **clientctrls )
|
2005-07-25 13:09:51 +02:00
|
|
|
{
|
2021-04-19 10:04:54 +02:00
|
|
|
ULONG ret = LDAP_NO_MEMORY;
|
2021-04-16 09:59:14 +02:00
|
|
|
LDAPControlU **serverctrlsU = NULL, **clientctrlsU = NULL;
|
2005-07-25 13:09:51 +02:00
|
|
|
|
|
|
|
TRACE( "(%p, %p, %p, %p, %p)\n", ld, retval, result, serverctrls, clientctrls );
|
2021-04-16 09:59:14 +02:00
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
FIXME( "result message not supported\n" );
|
|
|
|
*result = NULL;
|
|
|
|
}
|
2005-07-25 13:09:51 +02:00
|
|
|
|
2009-01-05 12:40:28 +01:00
|
|
|
if (!ld) return ~0u;
|
2005-07-25 13:09:51 +02:00
|
|
|
|
2021-04-16 09:59:14 +02:00
|
|
|
if (serverctrls && !(serverctrlsU = controlarrayWtoU( serverctrls ))) goto exit;
|
|
|
|
if (clientctrls && !(clientctrlsU = controlarrayWtoU( clientctrls ))) goto exit;
|
2005-07-25 13:09:51 +02:00
|
|
|
|
2021-04-19 10:04:54 +02:00
|
|
|
ret = map_error( ldap_funcs->fn_ldap_start_tls_s( CTX(ld), serverctrlsU, clientctrlsU ) );
|
2005-07-25 13:09:51 +02:00
|
|
|
|
2005-07-26 20:25:22 +02:00
|
|
|
exit:
|
2005-07-25 13:09:51 +02:00
|
|
|
controlarrayfreeU( serverctrlsU );
|
|
|
|
controlarrayfreeU( clientctrlsU );
|
|
|
|
return ret;
|
|
|
|
}
|
2005-11-18 17:56:44 +01:00
|
|
|
|
2005-12-31 13:33:31 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_startup (WLDAP32.@)
|
|
|
|
*/
|
2021-04-16 09:59:14 +02:00
|
|
|
ULONG CDECL ldap_startup( LDAP_VERSION_INFO *version, HANDLE *instance )
|
2005-11-18 17:56:44 +01:00
|
|
|
{
|
|
|
|
TRACE( "(%p, %p)\n", version, instance );
|
2021-04-19 10:04:54 +02:00
|
|
|
return LDAP_SUCCESS;
|
2005-11-18 17:56:44 +01:00
|
|
|
}
|
|
|
|
|
2005-12-31 13:33:31 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ldap_stop_tls_s (WLDAP32.@)
|
|
|
|
*
|
|
|
|
* Stop TLS encryption on an LDAP connection.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* ld [I] Pointer to an LDAP context.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: TRUE
|
|
|
|
* Failure: FALSE
|
|
|
|
*/
|
2021-04-19 10:04:54 +02:00
|
|
|
BOOLEAN CDECL ldap_stop_tls_s( LDAP *ld )
|
2005-11-18 17:56:44 +01:00
|
|
|
{
|
|
|
|
TRACE( "(%p)\n", ld );
|
2005-12-31 13:33:31 +01:00
|
|
|
return TRUE; /* FIXME: find a way to stop tls on a connection */
|
2005-11-18 17:56:44 +01:00
|
|
|
}
|