From: Jeremy Allison Date: Thu, 23 Jul 2020 02:03:23 +0000 (-0700) Subject: s3: libads: Don't re-do DNS lookups in ads_domain_func_level() if not needed. X-Git-Tag: talloc-2.3.2~819 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf0cfa03ac6fd4c4e2c7d86079796079754f3cf2;p=thirdparty%2Fsamba.git s3: libads: Don't re-do DNS lookups in ads_domain_func_level() if not needed. ADS_STRUCT may be being reused after a DC lookup from ads_find_dc(), so ads->ldap.ss may already have a good address (even if ads->server.ldap_server == NULL). Only re-initialize the ADS_STRUCT and redo the ads_find_fc() DNS lookups if we have to. Signed-off-by: Jeremy Allison Reviewed-by: Andreas Schneider Autobuild-User(master): Andreas Schneider Autobuild-Date(master): Tue Aug 18 09:46:28 UTC 2020 on sn-devel-184 --- diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index 04d699c348a..2fc9b2009b6 100755 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -3351,11 +3351,28 @@ ADS_STATUS ads_domain_func_level(ADS_STRUCT *ads, uint32_t *val) /* establish a new ldap tcp session if necessary */ if ( !ads->ldap.ld ) { - if ( (ads_s = ads_init( ads->server.realm, ads->server.workgroup, - ads->server.ldap_server, ADS_SASL_PLAIN )) == NULL ) - { - status = ADS_ERROR_NT(NT_STATUS_NO_MEMORY); - goto done; + /* + * ADS_STRUCT may be being reused after a + * DC lookup, so ads->ldap.ss may already have a + * good address. If not, re-initialize the passed-in + * ADS_STRUCT with the given server.XXXX parameters. + * + * Note that this doesn't depend on + * ads->server.ldap_server != NULL, + * as the case where ads->server.ldap_server==NULL and + * ads->ldap.ss != zero_address is precisely the DC + * lookup case where ads->ldap.ss was found by going + * through ads_find_dc() again we want to avoid repeating. + */ + if (is_zero_addr(&ads->ldap.ss)) { + ads_s = ads_init(ads->server.realm, + ads->server.workgroup, + ads->server.ldap_server, + ADS_SASL_PLAIN ); + if (ads_s == NULL ) { + status = ADS_ERROR_NT(NT_STATUS_NO_MEMORY); + goto done; + } } ads_s->auth.flags = ADS_AUTH_ANON_BIND; status = ads_connect( ads_s );