diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 28a32180eb8..e377b533548 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -97,7 +97,7 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) return W_ERROR_V(WERR_NOT_ENOUGH_MEMORY); } - ret = libnetapi_net_init(context, lp_ctx); + ret = libnetapi_net_init(context, lp_ctx, NULL); TALLOC_FREE(frame); return ret; } @@ -111,7 +111,8 @@ the command line). ****************************************************************/ NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context, - struct loadparm_context *lp_ctx) + struct loadparm_context *lp_ctx, + struct cli_credentials *creds) { NET_API_STATUS status; struct libnetapi_ctx *ctx = NULL; @@ -123,17 +124,19 @@ NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context, return W_ERROR_V(WERR_NOT_ENOUGH_MEMORY); } - ctx->creds = cli_credentials_init(ctx); + ctx->creds = creds; if (ctx->creds == NULL) { - TALLOC_FREE(frame); - return W_ERROR_V(WERR_NOT_ENOUGH_MEMORY); + ctx->creds = cli_credentials_init(ctx); + if (ctx->creds == NULL) { + TALLOC_FREE(frame); + return W_ERROR_V(WERR_NOT_ENOUGH_MEMORY); + } + /* Ignore return code, as we might not have a smb.conf */ + (void)cli_credentials_guess(ctx->creds, lp_ctx); } BlockSignals(True, SIGPIPE); - /* Ignore return code, as we might not have a smb.conf */ - (void)cli_credentials_guess(ctx->creds, lp_ctx); - status = libnetapi_init_private_context(ctx); if (status != 0) { TALLOC_FREE(frame); diff --git a/source3/lib/netapi/netapi_net.h b/source3/lib/netapi/netapi_net.h index 86dd3abe229..8febc2a8a4c 100644 --- a/source3/lib/netapi/netapi_net.h +++ b/source3/lib/netapi/netapi_net.h @@ -22,4 +22,5 @@ /* This function is to init the libnetapi subsystem, without * re-reading config files or setting debug levels etc */ NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **ctx, - struct loadparm_context *lp_ctx); + struct loadparm_context *lp_ctx, + struct cli_credentials *creds); diff --git a/source3/utils/net_dom.c b/source3/utils/net_dom.c index 9f052abac4f..4342990eaa1 100644 --- a/source3/utils/net_dom.c +++ b/source3/utils/net_dom.c @@ -376,12 +376,7 @@ int net_dom(struct net_context *c, int argc, const char **argv) {NULL, NULL, 0, NULL, NULL} }; - status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx); - if (status != 0) { - return -1; - } - - status = libnetapi_set_creds(c->netapi_ctx, c->creds); + status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx, c->creds); if (status != 0) { return -1; } diff --git a/source3/utils/net_offlinejoin.c b/source3/utils/net_offlinejoin.c index 72493feb9be..5294fd98ad7 100644 --- a/source3/utils/net_offlinejoin.c +++ b/source3/utils/net_offlinejoin.c @@ -54,12 +54,7 @@ int net_offlinejoin(struct net_context *c, int argc, const char **argv) net_warn_member_options(); - status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx); - if (status != 0) { - return -1; - } - - status = libnetapi_set_creds(c->netapi_ctx, c->creds); + status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx, c->creds); if (status != 0) { return -1; } diff --git a/source3/utils/net_rpc.c b/source3/utils/net_rpc.c index 383afd2eced..a55de7d5df8 100644 --- a/source3/utils/net_rpc.c +++ b/source3/utils/net_rpc.c @@ -1312,12 +1312,7 @@ int net_rpc_user(struct net_context *c, int argc, const char **argv) {NULL, NULL, 0, NULL, NULL} }; - status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx); - if (status != 0) { - return -1; - } - - status = libnetapi_set_creds(c->netapi_ctx, c->creds); + status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx, c->creds); if (status != 0) { return -1; } @@ -3505,12 +3500,7 @@ int net_rpc_group(struct net_context *c, int argc, const char **argv) {NULL, NULL, 0, NULL, NULL} }; - status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx); - if (status != 0) { - return -1; - } - - status = libnetapi_set_creds(c->netapi_ctx, c->creds); + status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx, c->creds); if (status != 0) { return -1; } @@ -5474,17 +5464,11 @@ int net_rpc_share(struct net_context *c, int argc, const char **argv) {NULL, NULL, 0, NULL, NULL} }; - status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx); + status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx, c->creds); if (status != 0) { return -1; } - status = libnetapi_set_creds(c->netapi_ctx, c->creds); - if (status != 0) { - return -1; - } - - if (argc == 0) { if (c->display_usage) { d_printf("%s\n%s", @@ -5757,12 +5741,7 @@ int net_rpc_file(struct net_context *c, int argc, const char **argv) {NULL, NULL, 0, NULL, NULL} }; - status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx); - if (status != 0) { - return -1; - } - - status = libnetapi_set_creds(c->netapi_ctx, c->creds); + status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx, c->creds); if (status != 0) { return -1; } @@ -8369,12 +8348,7 @@ int net_rpc(struct net_context *c, int argc, const char **argv) {NULL, NULL, 0, NULL, NULL} }; - status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx); - if (status != 0) { - return -1; - } - - status = libnetapi_set_creds(c->netapi_ctx, c->creds); + status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx, c->creds); if (status != 0) { return -1; } diff --git a/source3/utils/net_rpc_shell.c b/source3/utils/net_rpc_shell.c index 1c2abd0990c..1ea7080e35d 100644 --- a/source3/utils/net_rpc_shell.c +++ b/source3/utils/net_rpc_shell.c @@ -229,11 +229,7 @@ int net_rpc_shell(struct net_context *c, int argc, const char **argv) return -1; } - if (libnetapi_net_init(&c->netapi_ctx, c->lp_ctx) != 0) { - return -1; - } - - net_api_status = libnetapi_set_creds(c->netapi_ctx, c->creds); + net_api_status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx, c->creds); if (net_api_status != 0) { return -1; } diff --git a/source4/torture/libnetapi/libnetapi.c b/source4/torture/libnetapi/libnetapi.c index 605488d1873..fa6dcef2637 100644 --- a/source4/torture/libnetapi/libnetapi.c +++ b/source4/torture/libnetapi/libnetapi.c @@ -32,6 +32,7 @@ bool torture_libnetapi_init_context(struct torture_context *tctx, NET_API_STATUS status; struct libnetapi_ctx *ctx; TALLOC_CTX *frame = talloc_stackframe(); + struct cli_credentials *creds = samba_cmdline_get_creds(); if (!lp_load_global(lpcfg_configfile(tctx->lp_ctx))) { fprintf(stderr, "error loading %s\n", lpcfg_configfile(tctx->lp_ctx)); @@ -41,17 +42,12 @@ bool torture_libnetapi_init_context(struct torture_context *tctx, load_interfaces(); - status = libnetapi_net_init(&ctx, tctx->lp_ctx); + status = libnetapi_net_init(&ctx, tctx->lp_ctx, creds); if (status != 0) { talloc_free(frame); return false; } - libnetapi_set_username(ctx, - cli_credentials_get_username(samba_cmdline_get_creds())); - libnetapi_set_password(ctx, - cli_credentials_get_password(samba_cmdline_get_creds())); - *ctx_p = ctx; talloc_free(frame);