From: Jeremy Allison Date: Sat, 8 Aug 2020 03:18:50 +0000 (-0700) Subject: s3: libads: Add utility function ads_zero_ldap(). X-Git-Tag: talloc-2.3.2~824 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0535a265f94e0f828d0b8408c05d59a0dff3dbce;p=thirdparty%2Fsamba.git s3: libads: Add utility function ads_zero_ldap(). When initializing or re-initializing the ldap part of the ADS_STRUCT, we should call this to ensure that ads->ldap.ss is correctly recognized as a zero IPaddr by is_zero_addr(). It zeros out the ads->ldap but then adds zero_sockaddr() to initialize as AF_INET. Otherwise it's left by accident as AF_UNSPEC (0). Not yet used. Signed-off-by: Jeremy Allison Reviewed-by: Andreas Schneider --- diff --git a/source3/libads/ads_proto.h b/source3/libads/ads_proto.h index 6cdde0cf6eb..5701a5d79d4 100644 --- a/source3/libads/ads_proto.h +++ b/source3/libads/ads_proto.h @@ -81,6 +81,7 @@ bool ads_sitename_match(ADS_STRUCT *ads); bool ads_closest_dc(ADS_STRUCT *ads); ADS_STATUS ads_connect(ADS_STRUCT *ads); ADS_STATUS ads_connect_user_creds(ADS_STRUCT *ads); +void ads_zero_ldap(ADS_STRUCT *ads); void ads_disconnect(ADS_STRUCT *ads); ADS_STATUS ads_do_search_all_fn(ADS_STRUCT *ads, const char *bind_path, int scope, const char *expr, const char **attrs, diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index ee4628a09a2..18e2b86fb8e 100755 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -749,6 +749,25 @@ ADS_STATUS ads_connect_user_creds(ADS_STRUCT *ads) return ads_connect(ads); } +/** + * Zero out the internal ads->ldap struct and initialize the address to zero IP. + * @param ads Pointer to an existing ADS_STRUCT + * + * Sets the ads->ldap.ss to a valid + * zero ip address that can be detected by + * our is_zero_addr() function. Otherwise + * it is left as AF_UNSPEC (0). + **/ +void ads_zero_ldap(ADS_STRUCT *ads) +{ + ZERO_STRUCT(ads->ldap); + /* + * Initialize the sockaddr_storage so we can use + * sockaddr test functions against it. + */ + zero_sockaddr(&ads->ldap.ss); +} + /** * Disconnect the LDAP server * @param ads Pointer to an existing ADS_STRUCT