From: Pavel Kalugin Date: Sun, 20 Aug 2023 20:06:56 +0000 (+0300) Subject: libnetapi: Use lpcfg_set_cmdline() X-Git-Tag: tevent-0.16.0~550 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b6246737b98a3f84d3f6aa54296d5a60477e4ef;p=thirdparty%2Fsamba.git libnetapi: Use lpcfg_set_cmdline() Replace lp_set_cmdline() with lpcfg_set_cmdline() in netapi.c. For this purpose: 1. Add loadparm_context to the libnetapi_ctx because we need it in libnetapi_set_debuglevel() and libnetapi_set_logfile(). 2. Move loadparm_context creation from libnetapi_net_init() to libnetapi_init() and add the lp_ctx parameter to the former. Signed-off-by: Pavel Kalugin Reviewed-by: Andreas Schneider Reviewed-by: Andrew Bartlett --- diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index e377b533548..cbf9068ee61 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -74,10 +74,16 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) #endif frame = talloc_stackframe(); + lp_ctx = loadparm_init_s3(frame, loadparm_s3_helpers()); + if (lp_ctx == NULL) { + TALLOC_FREE(frame); + return W_ERROR_V(WERR_NOT_ENOUGH_MEMORY); + } + /* When libnetapi is invoked from an application, it does not * want to be swamped with level 10 debug messages, even if * this has been set for the server in smb.conf */ - lp_set_cmdline("log level", "0"); + lpcfg_set_cmdline(lp_ctx, "log level", "0"); setup_logging("libnetapi", DEBUG_STDERR); if (!lp_load_global(get_dyn_CONFIGFILE())) { @@ -91,13 +97,10 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) BlockSignals(True, SIGPIPE); - lp_ctx = loadparm_init_s3(frame, loadparm_s3_helpers()); - if (lp_ctx == NULL) { - TALLOC_FREE(frame); - return W_ERROR_V(WERR_NOT_ENOUGH_MEMORY); - } - ret = libnetapi_net_init(context, lp_ctx, NULL); + if (ret == NET_API_STATUS_SUCCESS) { + talloc_steal(*context, lp_ctx); + } TALLOC_FREE(frame); return ret; } @@ -124,6 +127,8 @@ NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context, return W_ERROR_V(WERR_NOT_ENOUGH_MEMORY); } + ctx->lp_ctx = lp_ctx; + ctx->creds = creds; if (ctx->creds == NULL) { ctx->creds = cli_credentials_init(ctx); @@ -147,7 +152,7 @@ NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context, talloc_steal(NULL, ctx); *context = stat_ctx = ctx; - + TALLOC_FREE(frame); return NET_API_STATUS_SUCCESS; } @@ -211,8 +216,8 @@ NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx, { TALLOC_CTX *frame = talloc_stackframe(); ctx->debuglevel = talloc_strdup(ctx, debuglevel); - - if (!lp_set_cmdline("log level", debuglevel)) { + + if (!lpcfg_set_cmdline(ctx->lp_ctx, "log level", debuglevel)) { TALLOC_FREE(frame); return W_ERROR_V(WERR_GEN_FAILURE); } @@ -229,7 +234,7 @@ NET_API_STATUS libnetapi_set_logfile(struct libnetapi_ctx *ctx, TALLOC_CTX *frame = talloc_stackframe(); ctx->logfile = talloc_strdup(ctx, logfile); - if (!lp_set_cmdline("log file", logfile)) { + if (!lpcfg_set_cmdline(ctx->lp_ctx, "log file", logfile)) { TALLOC_FREE(frame); return W_ERROR_V(WERR_GEN_FAILURE); } @@ -416,7 +421,7 @@ char *libnetapi_errstr(NET_API_STATUS status) TALLOC_CTX *frame = talloc_stackframe(); char *ret; if (status & 0xc0000000) { - ret = talloc_strdup(NULL, + ret = talloc_strdup(NULL, get_friendly_nt_error_msg(NT_STATUS(status))); } else { ret = talloc_strdup(NULL, diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h index 5cfd8d0efd2..c0d0ea0baca 100644 --- a/source3/lib/netapi/netapi_private.h +++ b/source3/lib/netapi/netapi_private.h @@ -63,6 +63,7 @@ struct libnetapi_ctx { struct cli_credentials *creds; void *private_data; + struct loadparm_context *lp_ctx; };