s3:lib/netapi: make use of ads_simple_creds/libnetapi_get_creds in NetGetJoinableOUs_l
authorStefan Metzmacher <metze@samba.org>
Tue, 5 Mar 2024 16:40:48 +0000 (17:40 +0100)
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/lib/netapi/joindomain.c

index 04fc423b41f5f710cfff70a365919f800d0623c6..f57f441d301e81d9c9f48f377558f4454a1e6935 100644 (file)
@@ -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;