diff options
author | Ivo De Decker <ivo.dedecker@ugent.be> | 2013-05-10 13:33:02 +0200 |
---|---|---|
committer | Ivo De Decker <ivo.dedecker@ugent.be> | 2013-05-10 13:33:02 +0200 |
commit | 31202ad025bcdeb2585d18dc3f4641b5cf9c0ec4 (patch) | |
tree | 32c20d66684ac97b86e55495146e9a676bfae85a /source3/lib/netapi/netapi.c | |
parent | 2865eba17fddda6c49f1209ca92d539111e7ff93 (diff) | |
download | samba-31202ad025bcdeb2585d18dc3f4641b5cf9c0ec4.tar.gz |
Imported Upstream version 4.0.0+dfsg1upstream/4.0.0+dfsg1
Diffstat (limited to 'source3/lib/netapi/netapi.c')
-rw-r--r-- | source3/lib/netapi/netapi.c | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index ffb84b0005..b1586ebee6 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -24,7 +24,6 @@ #include "krb5_env.h" struct libnetapi_ctx *stat_ctx = NULL; -TALLOC_CTX *frame = NULL; static bool libnetapi_initialized = false; /**************************************************************** @@ -38,7 +37,7 @@ static NET_API_STATUS libnetapi_init_private_context(struct libnetapi_ctx *ctx) return W_ERROR_V(WERR_INVALID_PARAM); } - priv = TALLOC_ZERO_P(ctx, struct libnetapi_private_ctx); + priv = talloc_zero(ctx, struct libnetapi_private_ctx); if (!priv) { return W_ERROR_V(WERR_NOMEM); } @@ -57,6 +56,8 @@ were not expecting it. NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) { + NET_API_STATUS ret; + TALLOC_CTX *frame; if (stat_ctx && libnetapi_initialized) { *context = stat_ctx; return NET_API_STATUS_SUCCESS; @@ -76,7 +77,7 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) lp_set_cmdline("log level", "0"); setup_logging("libnetapi", DEBUG_STDERR); - if (!lp_load(get_dyn_CONFIGFILE(), true, false, false, false)) { + if (!lp_load_global(get_dyn_CONFIGFILE())) { TALLOC_FREE(frame); fprintf(stderr, "error loading %s\n", get_dyn_CONFIGFILE() ); return W_ERROR_V(WERR_GENERAL_FAILURE); @@ -88,7 +89,9 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context) BlockSignals(True, SIGPIPE); - return libnetapi_net_init(context); + ret = libnetapi_net_init(context); + TALLOC_FREE(frame); + return ret; } /**************************************************************** @@ -103,8 +106,7 @@ NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context) { NET_API_STATUS status; struct libnetapi_ctx *ctx = NULL; - - frame = talloc_stackframe(); + TALLOC_CTX *frame = talloc_stackframe(); ctx = talloc_zero(frame, struct libnetapi_ctx); if (!ctx) { @@ -115,9 +117,9 @@ NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context) BlockSignals(True, SIGPIPE); if (getenv("USER")) { - ctx->username = talloc_strdup(frame, getenv("USER")); + ctx->username = talloc_strdup(ctx, getenv("USER")); } else { - ctx->username = talloc_strdup(frame, ""); + ctx->username = talloc_strdup(ctx, ""); } if (!ctx->username) { TALLOC_FREE(frame); @@ -133,8 +135,10 @@ NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context) libnetapi_initialized = true; + talloc_steal(NULL, ctx); *context = stat_ctx = ctx; - + + TALLOC_FREE(frame); return NET_API_STATUS_SUCCESS; } @@ -158,10 +162,13 @@ NET_API_STATUS libnetapi_getctx(struct libnetapi_ctx **ctx) NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) { + TALLOC_CTX *frame; + if (!ctx) { return NET_API_STATUS_SUCCESS; } + frame = talloc_stackframe(); libnetapi_samr_free(ctx); libnetapi_shutdown_cm(ctx); @@ -175,16 +182,18 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) gfree_names(); gfree_loadparm(); - gfree_case_tables(); gfree_charcnv(); gfree_interfaces(); secrets_shutdown(); + if (ctx == stat_ctx) { + stat_ctx = NULL; + } TALLOC_FREE(ctx); - TALLOC_FREE(frame); gfree_debugsyms(); + talloc_free(frame); return NET_API_STATUS_SUCCESS; } @@ -196,10 +205,14 @@ NET_API_STATUS libnetapi_free(struct libnetapi_ctx *ctx) NET_API_STATUS libnetapi_set_debuglevel(struct libnetapi_ctx *ctx, const char *debuglevel) { + TALLOC_CTX *frame = talloc_stackframe(); ctx->debuglevel = talloc_strdup(ctx, debuglevel); + if (!lp_set_cmdline("log level", debuglevel)) { + TALLOC_FREE(frame); return W_ERROR_V(WERR_GENERAL_FAILURE); } + TALLOC_FREE(frame); return NET_API_STATUS_SUCCESS; } @@ -269,15 +282,22 @@ NET_API_STATUS libnetapi_set_use_ccache(struct libnetapi_ctx *ctx) } /**************************************************************** +Return a libnetapi error as a string, caller must free with NetApiBufferFree ****************************************************************/ -const char *libnetapi_errstr(NET_API_STATUS status) +char *libnetapi_errstr(NET_API_STATUS status) { + TALLOC_CTX *frame = talloc_stackframe(); + char *ret; if (status & 0xc0000000) { - return get_friendly_nt_error_msg(NT_STATUS(status)); + ret = talloc_strdup(NULL, + get_friendly_nt_error_msg(NT_STATUS(status))); + } else { + ret = talloc_strdup(NULL, + get_friendly_werror_msg(W_ERROR(status))); } - - return get_friendly_werror_msg(W_ERROR(status)); + TALLOC_FREE(frame); + return ret; } /**************************************************************** @@ -301,9 +321,10 @@ NET_API_STATUS libnetapi_set_error_string(struct libnetapi_ctx *ctx, } /**************************************************************** +Return a libnetapi_errstr(), caller must free with NetApiBufferFree ****************************************************************/ -const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, +char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, NET_API_STATUS status_in) { NET_API_STATUS status; @@ -317,7 +338,7 @@ const char *libnetapi_get_error_string(struct libnetapi_ctx *ctx, } if (tmp_ctx->error_string) { - return tmp_ctx->error_string; + return talloc_strdup(NULL, tmp_ctx->error_string); } return libnetapi_errstr(status_in); |