Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=55450
-- v2: wldap32: Map LDAP_OPT_AUTO_RECONNECT to LDAP_OPT_RESTART and add tests.
From: Alex Henrie alexhenrie24@gmail.com
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=55450 --- dlls/wldap32/option.c | 29 +++++++++++++++++++++++---- dlls/wldap32/tests/parse.c | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 4 deletions(-)
diff --git a/dlls/wldap32/option.c b/dlls/wldap32/option.c index c3e17f81b47..ef095d34823 100644 --- a/dlls/wldap32/option.c +++ b/dlls/wldap32/option.c @@ -92,6 +92,7 @@ ULONG CDECL ldap_get_optionA( LDAP *ld, int option, void *value ) return WLDAP32_LDAP_SUCCESS; }
+ case WLDAP32_LDAP_OPT_AUTO_RECONNECT: case WLDAP32_LDAP_OPT_DEREF: case WLDAP32_LDAP_OPT_DESC: case WLDAP32_LDAP_OPT_ERROR_NUMBER: @@ -115,7 +116,6 @@ ULONG CDECL ldap_get_optionA( LDAP *ld, int option, void *value ) return WLDAP32_LDAP_LOCAL_ERROR;
case WLDAP32_LDAP_OPT_AREC_EXCLUSIVE: - case WLDAP32_LDAP_OPT_AUTO_RECONNECT: case WLDAP32_LDAP_OPT_CLIENT_CERTIFICATE: case WLDAP32_LDAP_OPT_DNSDOMAIN_NAME: case WLDAP32_LDAP_OPT_ENCRYPT: @@ -218,6 +218,13 @@ ULONG CDECL ldap_get_optionW( LDAP *ld, int option, void *value )
return WLDAP32_LDAP_SUCCESS; } + case WLDAP32_LDAP_OPT_AUTO_RECONNECT: + { + BOOL *on = value; + ret = ldap_get_option( CTX(ld), LDAP_OPT_RESTART, value ); + if (!ret) *on = !!*on; + return ret; + }
case WLDAP32_LDAP_OPT_DEREF: case WLDAP32_LDAP_OPT_DESC: @@ -242,7 +249,6 @@ ULONG CDECL ldap_get_optionW( LDAP *ld, int option, void *value ) return WLDAP32_LDAP_LOCAL_ERROR;
case WLDAP32_LDAP_OPT_AREC_EXCLUSIVE: - case WLDAP32_LDAP_OPT_AUTO_RECONNECT: case WLDAP32_LDAP_OPT_CLIENT_CERTIFICATE: case WLDAP32_LDAP_OPT_DNSDOMAIN_NAME: case WLDAP32_LDAP_OPT_ENCRYPT: @@ -300,6 +306,7 @@ ULONG CDECL ldap_set_optionA( LDAP *ld, int option, void *value ) controlarrayfreeW( ctrlsW ); return ret; } + case WLDAP32_LDAP_OPT_AUTO_RECONNECT: case WLDAP32_LDAP_OPT_DEREF: case WLDAP32_LDAP_OPT_DESC: case WLDAP32_LDAP_OPT_ERROR_NUMBER: @@ -327,7 +334,6 @@ ULONG CDECL ldap_set_optionA( LDAP *ld, int option, void *value ) return WLDAP32_LDAP_UNWILLING_TO_PERFORM;
case WLDAP32_LDAP_OPT_AREC_EXCLUSIVE: - case WLDAP32_LDAP_OPT_AUTO_RECONNECT: case WLDAP32_LDAP_OPT_CLIENT_CERTIFICATE: case WLDAP32_LDAP_OPT_DNSDOMAIN_NAME: case WLDAP32_LDAP_OPT_ENCRYPT: @@ -473,6 +479,22 @@ ULONG CDECL ldap_set_optionW( LDAP *ld, int option, void *value )
return map_error( ldap_set_option( CTX(ld), option, value ) ); } + case WLDAP32_LDAP_OPT_AUTO_RECONNECT: + { + if (value == WLDAP32_LDAP_OPT_ON) + value = LDAP_OPT_ON; + else if (value == WLDAP32_LDAP_OPT_OFF) + value = LDAP_OPT_OFF; + else if (*(ULONG *)value == 1) + value = LDAP_OPT_ON; + else if (*(ULONG *)value == 0) + value = LDAP_OPT_OFF; + else + return WLDAP32_LDAP_PARAM_ERROR; + + return map_error( ldap_set_option( CTX(ld), LDAP_OPT_RESTART, value ) ); + } + case WLDAP32_LDAP_OPT_REFERRAL_HOP_LIMIT: return map_error( ldap_set_option( CTX(ld), LDAP_OPT_REFHOPLIMIT, value ) );
@@ -533,7 +555,6 @@ ULONG CDECL ldap_set_optionW( LDAP *ld, int option, void *value ) return WLDAP32_LDAP_UNWILLING_TO_PERFORM;
case WLDAP32_LDAP_OPT_AREC_EXCLUSIVE: - case WLDAP32_LDAP_OPT_AUTO_RECONNECT: case WLDAP32_LDAP_OPT_CLIENT_CERTIFICATE: case WLDAP32_LDAP_OPT_DNSDOMAIN_NAME: case WLDAP32_LDAP_OPT_ENCRYPT: diff --git a/dlls/wldap32/tests/parse.c b/dlls/wldap32/tests/parse.c index 995297cce10..573ab172ebf 100644 --- a/dlls/wldap32/tests/parse.c +++ b/dlls/wldap32/tests/parse.c @@ -593,6 +593,45 @@ static void test_opt_server_certificate(void) ldap_unbind( ld ); }
+static void test_opt_auto_reconnect(void) +{ + LDAP *ld; + ULONG ret, value; + + ld = ldap_initA( (char *)"db.debian.org", 389 ); + ok( ld != NULL, "ldap_init failed\n" ); + + ret = ldap_set_optionA( ld, LDAP_OPT_AUTO_RECONNECT, LDAP_OPT_ON ); + ok( !ret, "ldap_set_optionA should succeed, got %#lx\n", ret ); + ret = ldap_get_optionA( ld, LDAP_OPT_AUTO_RECONNECT, &value ); + ok( !ret, "ldap_get_optionA should succeed, got %#lx\n", ret ); + ok( value == 1, "got %lu\n", ret ); + + ret = ldap_set_optionA( ld, LDAP_OPT_AUTO_RECONNECT, LDAP_OPT_OFF ); + ok( !ret, "ldap_set_optionA should succeed, got %#lx\n", ret ); + ret = ldap_get_optionA( ld, LDAP_OPT_AUTO_RECONNECT, &value ); + ok( !ret, "ldap_get_optionA should succeed, got %#lx\n", ret ); + ok( value == 0, "got %lu\n", ret ); + + value = 1; + ret = ldap_set_optionA( ld, LDAP_OPT_AUTO_RECONNECT, &value ); + ok( !ret, "ldap_set_optionA should succeed, got %#lx\n", ret ); + ret = ldap_get_optionA( ld, LDAP_OPT_AUTO_RECONNECT, &value ); + ok( !ret, "ldap_get_optionA should succeed, got %#lx\n", ret ); + ok( value == 1, "got %lu\n", ret ); + + value = 0; + ret = ldap_set_optionA( ld, LDAP_OPT_AUTO_RECONNECT, &value ); + ok( !ret, "ldap_set_optionA should succeed, got %#lx\n", ret ); + ret = ldap_get_optionA( ld, LDAP_OPT_AUTO_RECONNECT, &value ); + ok( !ret, "ldap_get_optionA should succeed, got %#lx\n", ret ); + ok( value == 0, "got %lu\n", ret ); + + value = 2; + ret = ldap_set_optionA( ld, LDAP_OPT_AUTO_RECONNECT, &value ); + ok( ret == LDAP_PARAM_ERROR, "ldap_set_optionA should fail, got %#lx\n", ret ); +} + START_TEST (parse) { LDAP *ld; @@ -602,6 +641,7 @@ START_TEST (parse) test_ldap_bind_sA(); test_opt_ssl(); test_opt_server_certificate(); + test_opt_auto_reconnect();
ld = ldap_initA( (char *)"db.debian.org", 389 ); ok( ld != NULL, "ldap_init failed\n" );
On Thu Aug 17 11:58:42 2023 +0000, Hans Leidekker wrote:
We probably shouldn't touch 'value' on failure.
Good point, fixed.