Avoid using deprecated openldap functions.

Correct some return values.
This commit is contained in:
Hans Leidekker 2005-11-18 16:29:32 +00:00 committed by Alexandre Julliard
parent ae6239d53d
commit 6c4011e768
9 changed files with 126 additions and 33 deletions

View File

@ -67,6 +67,7 @@ ULONG ldap_deleteW( WLDAP32_LDAP *ld, PWCHAR dn )
ULONG ret = LDAP_NOT_SUPPORTED;
#ifdef HAVE_LDAP
char *dnU = NULL;
int msg;
TRACE( "(%p, %s)\n", ld, debugstr_w(dn) );
@ -77,7 +78,13 @@ ULONG ldap_deleteW( WLDAP32_LDAP *ld, PWCHAR dn )
if (!dnU) return WLDAP32_LDAP_NO_MEMORY;
}
ret = ldap_delete( ld, dn ? dnU : "" );
ret = ldap_delete_ext( ld, dn ? dnU : "", NULL, NULL, &msg );
if (ret == LDAP_SUCCESS)
ret = msg;
else
ret = ~0UL;
strfreeU( dnU );
#endif
@ -275,7 +282,7 @@ ULONG ldap_delete_sW( WLDAP32_LDAP *ld, PWCHAR dn )
if (!dnU) return WLDAP32_LDAP_NO_MEMORY;
}
ret = ldap_delete_s( ld, dn ? dnU : "" );
ret = ldap_delete_ext_s( ld, dn ? dnU : "", NULL, NULL );
strfreeU( dnU );
#endif

View File

@ -118,7 +118,7 @@ PWCHAR *ldap_explode_dnW( PWCHAR dn, ULONG notypes )
ret = strarrayUtoW( retU );
strfreeU( dnU );
ldap_value_free( retU );
ldap_memvfree( (void **)retU );
#endif
return ret;

View File

@ -84,11 +84,18 @@ ULONG WLDAP32_ldap_result2error( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *res, ULO
{
ULONG ret = LDAP_NOT_SUPPORTED;
#ifdef HAVE_LDAP
int error;
TRACE( "(%p, %p, 0x%08lx)\n", ld, res, free );
if (!ld) return ~0UL;
ret = ldap_result2error( ld, res, free );
if (!ld || !res) return ~0UL;
ret = ldap_parse_result( ld, res, &error, NULL, NULL, NULL, NULL, free );
if (ret == LDAP_SUCCESS)
ret = error;
else
ret = ~0UL;
#endif
return ret;

View File

@ -50,7 +50,7 @@ ULONG WLDAP32_ldap_abandon( WLDAP32_LDAP *ld, ULONG msgid )
TRACE( "(%p, 0x%08lx)\n", ld, msgid );
if (!ld) return ~0UL;
ret = ldap_abandon( ld, msgid );
ret = ldap_abandon_ext( ld, msgid, NULL, NULL );
#endif
return ret;
@ -81,7 +81,7 @@ ULONG ldap_check_filterW( WLDAP32_LDAP *ld, PWCHAR filter )
TRACE( "(%p, %s)\n", ld, debugstr_w(filter) );
if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
return LDAP_SUCCESS;
return LDAP_SUCCESS; /* FIXME: do some checks */
}
ULONG ldap_cleanup( HANDLE instance )
@ -357,7 +357,7 @@ ULONG WLDAP32_ldap_result( WLDAP32_LDAP *ld, ULONG msgid, ULONG all,
TRACE( "(%p, 0x%08lx, 0x%08lx, %p, %p)\n", ld, msgid, all, timeout, res );
if (!ld || !res) return ~0UL;
if (!ld || !res || msgid == ~0UL) return ~0UL;
ret = ldap_result( ld, msgid, all, (struct timeval *)timeout, res );
#endif

View File

@ -79,6 +79,7 @@ ULONG ldap_modifyW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *mods[] )
#ifdef HAVE_LDAP
char *dnU = NULL;
LDAPMod **modsU = NULL;
int msg;
ret = WLDAP32_LDAP_NO_MEMORY;
@ -95,7 +96,13 @@ ULONG ldap_modifyW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *mods[] )
if (!modsU) goto exit;
}
ret = ldap_modify( ld, dn ? dnU : "", mods ? modsU : nullmods );
ret = ldap_modify_ext( ld, dn ? dnU : "", mods ? modsU : nullmods,
NULL, NULL, &msg );
if (ret == LDAP_SUCCESS)
ret = msg;
else
ret = ~0UL;
exit:
strfreeU( dnU );
@ -342,7 +349,7 @@ ULONG ldap_modify_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *mods[] )
if (!modsU) goto exit;
}
ret = ldap_modify_s( ld, dn ? dnU : "", mods ? modsU : nullmods );
ret = ldap_modify_ext_s( ld, dn ? dnU : "", mods ? modsU : nullmods, NULL, NULL );
exit:
strfreeU( dnU );

View File

@ -75,6 +75,7 @@ ULONG ldap_modrdnW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn )
ULONG ret = LDAP_NOT_SUPPORTED;
#ifdef HAVE_LDAP
char *dnU = NULL, *newdnU = NULL;
int msg;
ret = WLDAP32_LDAP_NO_MEMORY;
@ -90,7 +91,12 @@ ULONG ldap_modrdnW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn )
newdnU = strWtoU( newdn );
if (!newdnU) goto exit;
ret = ldap_modrdn( ld, dn ? dnU : "", newdnU );
ret = ldap_rename( ld, dn ? dnU : "", newdnU, NULL, 1, NULL, NULL, &msg );
if (ret == LDAP_SUCCESS)
ret = msg;
else
ret = ~0UL;
exit:
strfreeU( dnU );
@ -135,6 +141,7 @@ ULONG ldap_modrdn2W( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn, INT delete )
ULONG ret = LDAP_NOT_SUPPORTED;
#ifdef HAVE_LDAP
char *dnU = NULL, *newdnU = NULL;
int msg;
ret = WLDAP32_LDAP_NO_MEMORY;
@ -150,7 +157,12 @@ ULONG ldap_modrdn2W( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn, INT delete )
newdnU = strWtoU( newdn );
if (!newdnU) goto exit;
ret = ldap_modrdn2( ld, dn ? dnU : "", newdnU, delete );
ret = ldap_rename( ld, dn ? dnU : "", newdnU, NULL, delete, NULL, NULL, &msg );
if (ret == LDAP_SUCCESS)
ret = msg;
else
ret = ~0UL;
exit:
strfreeU( dnU );
@ -210,7 +222,7 @@ ULONG ldap_modrdn2_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn, INT delete )
newdnU = strWtoU( newdn );
if (!newdnU) goto exit;
ret = ldap_modrdn2_s( ld, dn ? dnU : "", newdnU, delete );
ret = ldap_rename_s( ld, dn ? dnU : "", newdnU, NULL, delete, NULL, NULL );
exit:
strfreeU( dnU );
@ -270,7 +282,7 @@ ULONG ldap_modrdn_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn )
newdnU = strWtoU( newdn );
if (!newdnU) goto exit;
ret = ldap_modrdn_s( ld, dn ? dnU : "", newdnU );
ret = ldap_rename_s( ld, dn ? dnU : "", newdnU, NULL, 1, NULL, NULL );
exit:
strfreeU( dnU );

View File

@ -217,13 +217,13 @@ ULONG ldap_get_optionW( WLDAP32_LDAP *ld, int option, void *value )
infoW->ldapai_vendor_name = strUtoW( infoU.ldapai_vendor_name );
if (!infoW->ldapai_vendor_name)
{
ldap_value_free( infoU.ldapai_extensions );
ldap_memvfree( (void **)infoU.ldapai_extensions );
return WLDAP32_LDAP_NO_MEMORY;
}
}
infoW->ldapai_vendor_version = infoU.ldapai_vendor_version;
ldap_value_free( infoU.ldapai_extensions );
ldap_memvfree( (void **)infoU.ldapai_extensions );
ldap_memfree( infoU.ldapai_vendor_name );
return ret;
}

View File

@ -85,6 +85,7 @@ ULONG ldap_searchW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope, PWCHAR filter,
ULONG ret = LDAP_NOT_SUPPORTED;
#ifdef HAVE_LDAP
char *baseU = NULL, *filterU = NULL, **attrsU = NULL;
int msg;
ret = WLDAP32_LDAP_NO_MEMORY;
@ -106,7 +107,13 @@ ULONG ldap_searchW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope, PWCHAR filter,
if (!attrsU) goto exit;
}
ret = ldap_search( ld, baseU, scope, filterU, attrsU, attrsonly );
ret = ldap_search_ext( ld, baseU, scope, filterU, attrsU, attrsonly,
NULL, NULL, NULL, 0, &msg );
if (ret == LDAP_SUCCESS)
ret = msg;
else
ret = ~0UL;
exit:
strfreeU( baseU );
@ -395,7 +402,8 @@ ULONG ldap_search_sW( WLDAP32_LDAP *ld, PWCHAR base, ULONG scope, PWCHAR filter,
if (!attrsU) goto exit;
}
ret = ldap_search_s( ld, baseU, scope, filterU, attrsU, attrsonly, res );
ret = ldap_search_ext_s( ld, baseU, scope, filterU, attrsU, attrsonly,
NULL, NULL, NULL, 0, res );
exit:
strfreeU( baseU );
@ -476,8 +484,8 @@ ULONG ldap_search_stW( WLDAP32_LDAP *ld, const PWCHAR base, ULONG scope,
if (!attrsU) goto exit;
}
ret = ldap_search_st( ld, baseU, scope, filterU, attrsU, attrsonly,
(struct timeval *)timeout, res );
ret = ldap_search_ext_s( ld, baseU, scope, filterU, attrsU, attrsonly,
NULL, NULL, (struct timeval *)timeout, 0, res );
exit:
strfreeU( baseU );

View File

@ -61,10 +61,10 @@ ULONG ldap_count_valuesA( PCHAR *vals )
TRACE( "(%p)\n", vals );
if (vals) {
valsW = strarrayAtoW( vals );
if (!valsW) return WLDAP32_LDAP_NO_MEMORY;
}
if (!vals) return 0;
valsW = strarrayAtoW( vals );
if (!valsW) return WLDAP32_LDAP_NO_MEMORY;
ret = ldap_count_valuesW( valsW );
strarrayfreeW( valsW );
@ -77,17 +77,18 @@ ULONG ldap_count_valuesW( PWCHAR *vals )
{
ULONG ret = LDAP_NOT_SUPPORTED;
#ifdef HAVE_LDAP
char **valsU = NULL;
WCHAR **p = vals;
TRACE( "(%p)\n", vals );
if (vals) {
valsU = strarrayWtoU( vals );
if (!valsU) return WLDAP32_LDAP_NO_MEMORY;
}
if (!vals) return 0;
ret = ldap_count_values( valsU );
strarrayfreeU( valsU );
ret = 0;
while (*p)
{
ret++;
p++;
}
#endif
return ret;
@ -116,11 +117,59 @@ PCHAR *ldap_get_valuesA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, PCHAR att
return ret;
}
static char *bv2str( struct berval *bv )
{
char *str = NULL;
unsigned int len = bv->bv_len;
str = HeapAlloc( GetProcessHeap(), 0, len + 1 );
if (str)
{
memcpy( str, bv->bv_val, len );
str[len] = '\0';
}
return str;
}
static char **bv2str_array( struct berval **bv )
{
unsigned int len = 0, i = 0;
struct berval **p = bv;
char **str;
while (*p)
{
len++;
p++;
}
str = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(char *) );
if (!str) return NULL;
p = bv;
while (*p)
{
str[i] = bv2str( *p );
if (!str[i])
{
for (--i; i >= 0; i--)
HeapFree( GetProcessHeap(), 0, str[i] );
HeapFree( GetProcessHeap(), 0, str );
return NULL;
}
i++;
p++;
}
str[i] = NULL;
return str;
}
PWCHAR *ldap_get_valuesW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, PWCHAR attr )
{
PWCHAR *ret = NULL;
#ifdef HAVE_LDAP
char *attrU = NULL, **retU;
struct berval **bv;
TRACE( "(%p, %p, %s)\n", ld, entry, debugstr_w(attr) );
@ -129,10 +178,13 @@ PWCHAR *ldap_get_valuesW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *entry, PWCHAR a
attrU = strWtoU( attr );
if (!attrU) return NULL;
retU = ldap_get_values( ld, entry, attrU );
bv = ldap_get_values_len( ld, entry, attrU );
retU = bv2str_array( bv );
ret = strarrayUtoW( retU );
ldap_value_free( retU );
ldap_value_free_len( bv );
strarrayfreeU( retU );
strfreeU( attrU );
#endif