]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:libads: add ads_simple_creds() helper
authorStefan Metzmacher <metze@samba.org>
Thu, 28 Apr 2022 15:51:57 +0000 (17:51 +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/sasl.c

index 2c9ca5b9898f9accccc998faec5ba0c9a78ec359..959ba7dba5c31aca0ab8dd95219013ce39455b9f 100644 (file)
@@ -206,6 +206,11 @@ ADS_STATUS ads_ranged_search(ADS_STRUCT *ads,
 
 /* The following definitions come from libads/sasl.c  */
 
+NTSTATUS ads_simple_creds(TALLOC_CTX *mem_ctx,
+                         const char *account_domain,
+                         const char *account_name,
+                         const char *password,
+                         struct cli_credentials **_creds);
 NTSTATUS ads_legacy_creds(ADS_STRUCT *ads,
                          TALLOC_CTX *mem_ctx,
                          struct cli_credentials **_creds);
index 8cbb8062cca2864f82eead6e0f8bd2968c23e9ca..36cd5311a25042e8f30b3137a0d7be6f7e367d2a 100644 (file)
 #include "krb5_env.h"
 #include "lib/util/asn1.h"
 
+NTSTATUS ads_simple_creds(TALLOC_CTX *mem_ctx,
+                         const char *account_domain,
+                         const char *account_name,
+                         const char *password,
+                         struct cli_credentials **_creds)
+{
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct cli_credentials *creds = NULL;
+       struct loadparm_context *lp_ctx = NULL;
+       bool ok;
+
+       lp_ctx = loadparm_init_s3(frame, loadparm_s3_helpers());
+       if (lp_ctx == NULL) {
+               DBG_ERR("loadparm_init_s3 failed\n");
+               TALLOC_FREE(frame);
+               return NT_STATUS_INVALID_SERVER_STATE;
+       }
+
+       creds = cli_credentials_init(mem_ctx);
+       if (creds == NULL) {
+               TALLOC_FREE(frame);
+               return NT_STATUS_NO_MEMORY;
+       }
+       talloc_steal(frame, creds);
+
+       ok = cli_credentials_guess(creds, lp_ctx);
+       if (!ok) {
+               TALLOC_FREE(frame);
+               return NT_STATUS_INTERNAL_ERROR;
+       }
+
+       if (account_domain != NULL && account_domain[0] != '\0') {
+               ok = cli_credentials_set_domain(creds,
+                                               account_domain,
+                                               CRED_SPECIFIED);
+               if (!ok) {
+                       TALLOC_FREE(frame);
+                       return NT_STATUS_NO_MEMORY;
+               }
+       }
+       if (password != NULL) {
+               ok = cli_credentials_set_password(creds,
+                                                 password,
+                                                 CRED_SPECIFIED);
+               if (!ok) {
+                       TALLOC_FREE(frame);
+                       return NT_STATUS_NO_MEMORY;
+               }
+       }
+
+       cli_credentials_parse_string(creds,
+                                    account_name,
+                                    CRED_SPECIFIED);
+
+       *_creds = talloc_move(mem_ctx, &creds);
+       TALLOC_FREE(frame);
+       return NT_STATUS_OK;
+}
+
 #ifdef HAVE_LDAP
 
 static ADS_STATUS ads_sasl_gensec_wrap(struct ads_saslwrap *wrap,