From: Stefan Metzmacher Date: Wed, 27 Apr 2022 11:11:26 +0000 (+0200) Subject: s3:libads: add ads_connect_creds() helper X-Git-Tag: tdb-1.4.11~764 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31e4614ee3636eb5d835435dfe68379b0bee382e;p=thirdparty%2Fsamba.git s3:libads: add ads_connect_creds() helper In future ads_connect_creds() will be used by callers directly instead of using ads_connect(). Signed-off-by: Stefan Metzmacher Reviewed-by: Andreas Schneider --- diff --git a/source3/libads/ads_proto.h b/source3/libads/ads_proto.h index c44119eebdf..1256652c5e0 100644 --- a/source3/libads/ads_proto.h +++ b/source3/libads/ads_proto.h @@ -87,6 +87,7 @@ int ads_kinit_password(ADS_STRUCT *ads); bool ads_sitename_match(ADS_STRUCT *ads); bool ads_closest_dc(ADS_STRUCT *ads); ADS_STATUS ads_connect_cldap_only(ADS_STRUCT *ads); +ADS_STATUS ads_connect_creds(ADS_STRUCT *ads, struct cli_credentials *creds); ADS_STATUS ads_connect(ADS_STRUCT *ads); ADS_STATUS ads_connect_user_creds(ADS_STRUCT *ads); void ads_zero_ldap(ADS_STRUCT *ads); diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index 593881c8d4f..1e05d14e4aa 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -1122,6 +1122,34 @@ ADS_STATUS ads_connect_cldap_only(ADS_STRUCT *ads) return ads_connect_internal(ads, NULL); } +/** + * Connect to the LDAP server + * @param ads Pointer to an existing ADS_STRUCT + * @return status of connection + **/ +ADS_STATUS ads_connect_creds(ADS_STRUCT *ads, struct cli_credentials *creds) +{ + SMB_ASSERT(creds != NULL); + + /* + * We allow upgrades from + * ADS_AUTH_NO_BIND if credentials + * are specified + */ + ads->auth.flags &= ~ADS_AUTH_NO_BIND; + + /* + * We allow upgrades from ADS_AUTH_ANON_BIND, + * as we don't want to use simple binds with + * non-anon credentials + */ + if (!cli_credentials_is_anonymous(creds)) { + ads->auth.flags &= ~ADS_AUTH_ANON_BIND; + } + + return ads_connect_internal(ads, creds); +} + /* * Connect to the LDAP server * @param ads Pointer to an existing ADS_STRUCT