From 7bfbea4c3c8f71dceedcc017153dcf31ab223b59 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 28 Apr 2022 18:38:17 +0200 Subject: [PATCH] s3:libads: add ads_connect_simple_anon() helper Signed-off-by: Stefan Metzmacher Reviewed-by: Andreas Schneider --- source3/libads/ads_proto.h | 1 + source3/libads/ldap.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/source3/libads/ads_proto.h b/source3/libads/ads_proto.h index 1256652c5e0..2c9ca5b9898 100644 --- a/source3/libads/ads_proto.h +++ b/source3/libads/ads_proto.h @@ -88,6 +88,7 @@ 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_simple_anon(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); diff --git a/source3/libads/ldap.c b/source3/libads/ldap.c index 1e05d14e4aa..c909e427fc5 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -1150,6 +1150,31 @@ ADS_STATUS ads_connect_creds(ADS_STRUCT *ads, struct cli_credentials *creds) return ads_connect_internal(ads, creds); } +/** + * Connect to the LDAP server using anonymous credentials + * using a simple bind without username/password + * + * @param ads Pointer to an existing ADS_STRUCT + * @return status of connection + **/ +ADS_STATUS ads_connect_simple_anon(ADS_STRUCT *ads) +{ + TALLOC_CTX *frame = talloc_stackframe(); + struct cli_credentials *creds = NULL; + ADS_STATUS status; + + creds = cli_credentials_init_anon(frame); + if (creds == NULL) { + TALLOC_FREE(frame); + return ADS_ERROR_SYSTEM(errno); + } + + ads->auth.flags |= ADS_AUTH_ANON_BIND; + status = ads_connect_creds(ads, creds); + TALLOC_FREE(frame); + return status; +} + /* * Connect to the LDAP server * @param ads Pointer to an existing ADS_STRUCT -- 2.11.4.GIT