s3:netapi: Use public functions for username/password
authorAndreas Schneider <asn@samba.org>
Thu, 18 Mar 2021 10:14:39 +0000 (11:14 +0100)
committerGünther Deschner <gd@samba.org>
Wed, 24 Mar 2021 00:55:32 +0000 (00:55 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
source3/lib/netapi/cm.c
source3/lib/netapi/joindomain.c

index 3f4e188b39656db4874c0d3fb831a705d96243df..fd5cc56786dd5a494614823245b72998ac0ab88b 100644 (file)
@@ -72,6 +72,9 @@ static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx,
        struct client_ipc_connection *p;
        NTSTATUS status;
        struct cli_credentials *creds = NULL;
+       const char *username = NULL;
+       const char *password = NULL;
+       NET_API_STATUS rc;
 
        if (!ctx || !pp || !server_name) {
                return WERR_INVALID_PARAMETER;
@@ -89,17 +92,30 @@ static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx,
        if (!auth_info) {
                return WERR_NOT_ENOUGH_MEMORY;
        }
+
+       rc = libnetapi_get_username(ctx, &username);
+       if (rc != 0) {
+               TALLOC_FREE(auth_info);
+               return WERR_INTERNAL_ERROR;
+       }
+
+       rc = libnetapi_get_password(ctx, &password);
+       if (rc != 0) {
+               TALLOC_FREE(auth_info);
+               return WERR_INTERNAL_ERROR;
+       }
+
        set_cmdline_auth_info_signing_state_raw(auth_info, SMB_SIGNING_IPC_DEFAULT);
        set_cmdline_auth_info_use_kerberos(auth_info, ctx->use_kerberos);
-       set_cmdline_auth_info_username(auth_info, ctx->username);
-       if (ctx->password) {
-               set_cmdline_auth_info_password(auth_info, ctx->password);
+       set_cmdline_auth_info_username(auth_info, username);
+       if (password != NULL) {
+               set_cmdline_auth_info_password(auth_info, password);
        } else {
                set_cmdline_auth_info_getpass(auth_info);
        }
 
-       if (ctx->username && ctx->username[0] &&
-           ctx->password && ctx->password[0] &&
+       if (username && username[0] &&
+           password && password[0] &&
            ctx->use_kerberos) {
                set_cmdline_auth_info_fallback_after_kerberos(auth_info, true);
        }
index afb1de45a7199b90ed490d38c5d163322b4ab11c..90a58824fe50e15379823145cc8c111c10a0ea9a 100644 (file)
@@ -429,7 +429,9 @@ WERROR NetGetJoinableOUs_l(struct libnetapi_ctx *ctx,
        if (r->in.account) {
                ads->auth.user_name = SMB_STRDUP(r->in.account);
        } else {
-               const char *username = cli_credentials_get_username(ctx->creds);
+               const char *username = NULL;
+
+               libnetapi_get_username(ctx, &username);
                if (username != NULL) {
                        ads->auth.user_name = SMB_STRDUP(username);
                }
@@ -439,7 +441,9 @@ WERROR NetGetJoinableOUs_l(struct libnetapi_ctx *ctx,
        if (r->in.password) {
                ads->auth.password = SMB_STRDUP(r->in.password);
        } else {
-               const char *password = cli_credentials_get_password(ctx->creds);
+               const char *password = NULL;
+
+               libnetapi_get_password(ctx, &password);
                if (password != NULL) {
                        ads->auth.password = SMB_STRDUP(password);
                }