From: Stefan Metzmacher Date: Thu, 28 Apr 2022 15:51:57 +0000 (+0200) Subject: s3:libads: add ads_simple_creds() helper X-Git-Tag: tdb-1.4.11~753 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=353abcb4d3eb7952997abfa6f8196c673ab7ac9b;p=thirdparty%2Fsamba.git s3:libads: add ads_simple_creds() 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 2c9ca5b9898..959ba7dba5c 100644 --- a/source3/libads/ads_proto.h +++ b/source3/libads/ads_proto.h @@ -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); diff --git a/source3/libads/sasl.c b/source3/libads/sasl.c index 8cbb8062cca..36cd5311a25 100644 --- a/source3/libads/sasl.c +++ b/source3/libads/sasl.c @@ -28,6 +28,65 @@ #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,