From: Stefan Metzmacher Date: Thu, 28 Apr 2022 16:53:03 +0000 (+0200) Subject: s3:libads: add ads_connect_machine() helper X-Git-Tag: tdb-1.4.11~752 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9496bfdf4e62fb1707e8fc6520439757978da6e;p=thirdparty%2Fsamba.git s3:libads: add ads_connect_machine() helper Signed-off-by: Stefan Metzmacher Reviewed-by: Andreas Schneider --- diff --git a/source3/libads/ads_proto.h b/source3/libads/ads_proto.h index 959ba7dba5c..2de0377b240 100644 --- a/source3/libads/ads_proto.h +++ b/source3/libads/ads_proto.h @@ -89,6 +89,7 @@ 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_machine(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 50cb19d38a6..86d2e813ba6 100644 --- a/source3/libads/ldap.c +++ b/source3/libads/ldap.c @@ -35,6 +35,7 @@ #include "libsmb/namequery.h" #include "../librpc/gen_ndr/ndr_ads.h" #include "auth/credentials/credentials.h" +#include "passdb.h" #ifdef HAVE_LDAP @@ -1175,6 +1176,32 @@ ADS_STATUS ads_connect_simple_anon(ADS_STRUCT *ads) return status; } +/** + * Connect to the LDAP server using the machine account + * @param ads Pointer to an existing ADS_STRUCT + * @return status of connection + **/ +ADS_STATUS ads_connect_machine(ADS_STRUCT *ads) +{ + TALLOC_CTX *frame = talloc_stackframe(); + struct cli_credentials *creds = NULL; + ADS_STATUS status; + NTSTATUS ntstatus; + + ntstatus = pdb_get_trust_credentials(ads->server.workgroup, + ads->server.realm, + frame, + &creds); + if (!NT_STATUS_IS_OK(ntstatus)) { + TALLOC_FREE(frame); + return ADS_ERROR_NT(ntstatus); + } + + status = ads_connect_creds(ads, creds); + TALLOC_FREE(frame); + return status; +} + /* * Connect to the LDAP server * @param ads Pointer to an existing ADS_STRUCT