From: Stefan Metzmacher Date: Tue, 5 Mar 2024 16:40:48 +0000 (+0100) Subject: s3:lib/netapi: make use of ads_simple_creds/libnetapi_get_creds in NetGetJoinableOUs_l X-Git-Tag: tdb-1.4.11~748 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0edd3406b9a0db65a77dd17ca9ab6ad28c09728;p=thirdparty%2Fsamba.git s3:lib/netapi: make use of ads_simple_creds/libnetapi_get_creds in NetGetJoinableOUs_l Signed-off-by: Stefan Metzmacher Reviewed-by: Andreas Schneider --- diff --git a/source3/lib/netapi/joindomain.c b/source3/lib/netapi/joindomain.c index 04fc423b41f..f57f441d301 100644 --- a/source3/lib/netapi/joindomain.c +++ b/source3/lib/netapi/joindomain.c @@ -403,6 +403,7 @@ WERROR NetGetJoinableOUs_l(struct libnetapi_ctx *ctx, NTSTATUS status; ADS_STATUS ads_status; ADS_STRUCT *ads = NULL; + struct cli_credentials *creds = NULL; struct netr_DsRGetDCNameInfo *info = NULL; const char *dc = NULL; uint32_t flags = DS_DIRECTORY_SERVICE_REQUIRED | @@ -435,47 +436,21 @@ WERROR NetGetJoinableOUs_l(struct libnetapi_ctx *ctx, goto out; } - ADS_TALLOC_CONST_FREE(ads->auth.user_name); - if (r->in.account) { - ads->auth.user_name = talloc_strdup(ads, r->in.account); - if (ads->auth.user_name == NULL) { - ret = WERR_NOT_ENOUGH_MEMORY; - goto out; - } - } else { - const char *username = NULL; - - libnetapi_get_username(ctx, &username); - if (username != NULL) { - ads->auth.user_name = talloc_strdup(ads, username); - if (ads->auth.user_name == NULL) { - ret = WERR_NOT_ENOUGH_MEMORY; - goto out; - } - } - } - - ADS_TALLOC_CONST_FREE(ads->auth.password); - if (r->in.password) { - ads->auth.password = talloc_strdup(ads, r->in.password); - if (ads->auth.password == NULL) { - ret = WERR_NOT_ENOUGH_MEMORY; + if (r->in.account != NULL) { + status = ads_simple_creds(ads, + r->in.domain, + r->in.account, + r->in.password, + &creds); + if (!NT_STATUS_IS_OK(status)) { + ret = WERR_NERR_DEFAULTJOINREQUIRED; goto out; } } else { - const char *password = NULL; - - libnetapi_get_password(ctx, &password); - if (password != NULL) { - ads->auth.password = talloc_strdup(ads, password); - if (ads->auth.password == NULL) { - ret = WERR_NOT_ENOUGH_MEMORY; - goto out; - } - } + libnetapi_get_creds(ctx, &creds); } - ads_status = ads_connect_user_creds(ads); + ads_status = ads_connect_creds(ads, creds); if (!ADS_ERR_OK(ads_status)) { ret = WERR_NERR_DEFAULTJOINREQUIRED; goto out;