mirror of
https://github.com/samba-team/samba.git
synced 2025-02-01 05:47:28 +03:00
netapi: Pass net's cmdline credentials to libnetapi_net_init()
Avoid unnecessary credentials allocation and initialization by passing the net's cmdline creds to libnetapi_net_init() directly. Fixes the problem of running cli_credentials_guess() (which runs password callbacks) twice, one for the net's cmdline creds and a second time for the creds initialized in libnetapi_net_init(), just to override them immediately after. Example: $ export PASSWD_FD=0 $ ./bin/net offlinejoin composeodj <...> foo bar Password is read from STDIN twice. Signed-off-by: Samuel Cabrero <scabrero@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
parent
5cad827810
commit
8cdb4f2985
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user