Commit a1ebea41 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

Improve error handling for the init functions.

parent a8f4b16b
...@@ -39,21 +39,27 @@ ...@@ -39,21 +39,27 @@
#include "winldap_private.h" #include "winldap_private.h"
#include "wldap32.h" #include "wldap32.h"
/* Should eventually be determined by the algorithm documented on MSDN. */
static const WCHAR defaulthost[] = { 'l','o','c','a','l','h','o','s','t',0 };
WINE_DEFAULT_DEBUG_CHANNEL(wldap32); WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
WLDAP32_LDAP *ldap_initA( PCHAR hostname, ULONG portnumber ) WLDAP32_LDAP *ldap_initA( PCHAR hostname, ULONG portnumber )
{ {
#ifdef HAVE_LDAP #ifdef HAVE_LDAP
WLDAP32_LDAP *ld; WLDAP32_LDAP *ld = NULL;
WCHAR *hostnameW; WCHAR *hostnameW = NULL;
TRACE( "(%s, %ld)\n", debugstr_a(hostname), portnumber ); TRACE( "(%s, %ld)\n", debugstr_a(hostname), portnumber );
if (hostname) {
hostnameW = strAtoW( hostname ); hostnameW = strAtoW( hostname );
if (!hostnameW) return NULL; if (!hostnameW) goto exit;
}
ld = ldap_initW( hostnameW, portnumber ); ld = ldap_initW( hostnameW, portnumber );
exit:
strfreeW( hostnameW ); strfreeW( hostnameW );
return ld; return ld;
...@@ -64,16 +70,23 @@ WLDAP32_LDAP *ldap_initA( PCHAR hostname, ULONG portnumber ) ...@@ -64,16 +70,23 @@ WLDAP32_LDAP *ldap_initA( PCHAR hostname, ULONG portnumber )
WLDAP32_LDAP *ldap_initW( PWCHAR hostname, ULONG portnumber ) WLDAP32_LDAP *ldap_initW( PWCHAR hostname, ULONG portnumber )
{ {
#ifdef HAVE_LDAP #ifdef HAVE_LDAP
LDAP *ld; LDAP *ld = NULL;
char *hostnameU; char *hostnameU = NULL;
TRACE( "(%s, %ld)\n", debugstr_w(hostname), portnumber ); TRACE( "(%s, %ld)\n", debugstr_w(hostname), portnumber );
if (hostname) {
hostnameU = strWtoU( hostname ); hostnameU = strWtoU( hostname );
if (!hostnameU) return NULL; if (!hostnameU) goto exit;
}
else {
hostnameU = strWtoU( defaulthost );
if (!hostnameU) goto exit;
}
ld = ldap_init( hostnameU, portnumber ); ld = ldap_init( hostnameU, portnumber );
exit:
strfreeU( hostnameU ); strfreeU( hostnameU );
return ld; return ld;
...@@ -84,16 +97,19 @@ WLDAP32_LDAP *ldap_initW( PWCHAR hostname, ULONG portnumber ) ...@@ -84,16 +97,19 @@ WLDAP32_LDAP *ldap_initW( PWCHAR hostname, ULONG portnumber )
WLDAP32_LDAP *ldap_openA( PCHAR hostname, ULONG portnumber ) WLDAP32_LDAP *ldap_openA( PCHAR hostname, ULONG portnumber )
{ {
#ifdef HAVE_LDAP #ifdef HAVE_LDAP
WLDAP32_LDAP *ld; WLDAP32_LDAP *ld = NULL;
WCHAR *hostnameW; WCHAR *hostnameW = NULL;
TRACE( "(%s, %ld)\n", debugstr_a(hostname), portnumber ); TRACE( "(%s, %ld)\n", debugstr_a(hostname), portnumber );
if (hostname) {
hostnameW = strAtoW( hostname ); hostnameW = strAtoW( hostname );
if (!hostnameW) return NULL; if (!hostnameW) goto exit;
}
ld = ldap_openW( hostnameW, portnumber ); ld = ldap_openW( hostnameW, portnumber );
exit:
strfreeW( hostnameW ); strfreeW( hostnameW );
return ld; return ld;
...@@ -104,16 +120,23 @@ WLDAP32_LDAP *ldap_openA( PCHAR hostname, ULONG portnumber ) ...@@ -104,16 +120,23 @@ WLDAP32_LDAP *ldap_openA( PCHAR hostname, ULONG portnumber )
WLDAP32_LDAP *ldap_openW( PWCHAR hostname, ULONG portnumber ) WLDAP32_LDAP *ldap_openW( PWCHAR hostname, ULONG portnumber )
{ {
#ifdef HAVE_LDAP #ifdef HAVE_LDAP
LDAP *ld; LDAP *ld = NULL;
char *hostnameU; char *hostnameU = NULL;
TRACE( "(%s, %ld)\n", debugstr_w(hostname), portnumber ); TRACE( "(%s, %ld)\n", debugstr_w(hostname), portnumber );
if (hostname) {
hostnameU = strWtoU( hostname ); hostnameU = strWtoU( hostname );
if (!hostnameU) return NULL; if (!hostnameU) goto exit;
}
else {
hostnameU = strWtoU( defaulthost );
if (!hostnameU) goto exit;
}
ld = ldap_open( hostnameU, portnumber ); ld = ldap_open( hostnameU, portnumber );
exit:
strfreeU( hostnameU ); strfreeU( hostnameU );
return ld; return ld;
...@@ -126,20 +149,25 @@ ULONG ldap_start_tls_sA( WLDAP32_LDAP *ld, PULONG retval, WLDAP32_LDAPMessage ** ...@@ -126,20 +149,25 @@ ULONG ldap_start_tls_sA( WLDAP32_LDAP *ld, PULONG retval, WLDAP32_LDAPMessage **
{ {
ULONG ret = LDAP_NOT_SUPPORTED; ULONG ret = LDAP_NOT_SUPPORTED;
#ifdef HAVE_LDAP #ifdef HAVE_LDAP
LDAPControlW **serverctrlsW, **clientctrlsW; LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
ret = LDAP_NO_MEMORY;
TRACE( "(%p, %p, %p, %p, %p)\n", ld, retval, result, serverctrls, clientctrls ); TRACE( "(%p, %p, %p, %p, %p)\n", ld, retval, result, serverctrls, clientctrls );
if (!ld) return ~0UL; if (!ld) return ~0UL;
if (serverctrls) {
serverctrlsW = controlarrayAtoW( serverctrls ); serverctrlsW = controlarrayAtoW( serverctrls );
if (!serverctrlsW) return LDAP_NO_MEMORY; if (!serverctrlsW) goto exit;
}
if (clientctrls) {
clientctrlsW = controlarrayAtoW( clientctrls ); clientctrlsW = controlarrayAtoW( clientctrls );
if (!clientctrlsW) return LDAP_NO_MEMORY; if (!clientctrlsW) goto exit;
}
ret = ldap_start_tls_sW( ld, retval, result, serverctrlsW, clientctrlsW ); ret = ldap_start_tls_sW( ld, retval, result, serverctrlsW, clientctrlsW );
exit:
controlarrayfreeW( serverctrlsW ); controlarrayfreeW( serverctrlsW );
controlarrayfreeW( clientctrlsW ); controlarrayfreeW( clientctrlsW );
...@@ -152,20 +180,25 @@ ULONG ldap_start_tls_sW( WLDAP32_LDAP *ld, PULONG retval, WLDAP32_LDAPMessage ** ...@@ -152,20 +180,25 @@ ULONG ldap_start_tls_sW( WLDAP32_LDAP *ld, PULONG retval, WLDAP32_LDAPMessage **
{ {
ULONG ret = LDAP_NOT_SUPPORTED; ULONG ret = LDAP_NOT_SUPPORTED;
#ifdef HAVE_LDAP #ifdef HAVE_LDAP
LDAPControl **serverctrlsU, **clientctrlsU; LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
ret = LDAP_NO_MEMORY;
TRACE( "(%p, %p, %p, %p, %p)\n", ld, retval, result, serverctrls, clientctrls ); TRACE( "(%p, %p, %p, %p, %p)\n", ld, retval, result, serverctrls, clientctrls );
if (!ld) return ~0UL; if (!ld) return ~0UL;
if (serverctrls) {
serverctrlsU = controlarrayWtoU( serverctrls ); serverctrlsU = controlarrayWtoU( serverctrls );
if (!serverctrlsU) return LDAP_NO_MEMORY; if (!serverctrlsU) goto exit;
}
if (clientctrls) {
clientctrlsU = controlarrayWtoU( clientctrls ); clientctrlsU = controlarrayWtoU( clientctrls );
if (!clientctrlsU) return LDAP_NO_MEMORY; if (!clientctrlsU) goto exit;
}
ret = ldap_start_tls_s( ld, serverctrlsU, clientctrlsU ); ret = ldap_start_tls_s( ld, serverctrlsU, clientctrlsU );
exit:
controlarrayfreeU( serverctrlsU ); controlarrayfreeU( serverctrlsU );
controlarrayfreeU( clientctrlsU ); controlarrayfreeU( clientctrlsU );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment