]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:libads: add ads_connect_machine() helper
authorStefan Metzmacher <metze@samba.org>
Thu, 28 Apr 2022 16:53:03 +0000 (18:53 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 14 May 2024 10:18:31 +0000 (10:18 +0000)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source3/libads/ads_proto.h
source3/libads/ldap.c

index 959ba7dba5c31aca0ab8dd95219013ce39455b9f..2de0377b240aba0a9c31ae26183869871f3a03fa 100644 (file)
@@ -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);
index 50cb19d38a6cb9e0ab37a8029132f2353123b4f7..86d2e813ba6990a292f94769f41a86259791caf5 100644 (file)
@@ -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