From: Andreas Schneider Date: Thu, 18 Mar 2021 09:43:26 +0000 (+0100) Subject: s3:netapi: Add a cli_credentials pointer to struct libnetapi_ctx X-Git-Tag: tevent-0.11.0~1420 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7bb70f701e49e11d41583369737522f3db9b9382;p=thirdparty%2Fsamba.git s3:netapi: Add a cli_credentials pointer to struct libnetapi_ctx Signed-off-by: Andreas Schneider Reviewed-by: Guenther Deschner --- diff --git a/source3/lib/netapi/netapi.c b/source3/lib/netapi/netapi.c index 4c8a96e2e70..591523edfe0 100644 --- a/source3/lib/netapi/netapi.c +++ b/source3/lib/netapi/netapi.c @@ -23,6 +23,8 @@ #include "lib/netapi/netapi_private.h" #include "secrets.h" #include "krb5_env.h" +#include "source3/param/loadparm.h" +#include "lib/param/param.h" struct libnetapi_ctx *stat_ctx = NULL; static bool libnetapi_initialized = false; @@ -104,6 +106,7 @@ NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context) NET_API_STATUS status; struct libnetapi_ctx *ctx = NULL; TALLOC_CTX *frame = talloc_stackframe(); + struct loadparm_context *lp_ctx = NULL; ctx = talloc_zero(frame, struct libnetapi_ctx); if (!ctx) { @@ -111,8 +114,22 @@ NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context) 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); + } + + lp_ctx = loadparm_init_s3(frame, loadparm_s3_helpers()); + if (lp_ctx == NULL) { + TALLOC_FREE(frame); + return W_ERROR_V(WERR_NOT_ENOUGH_MEMORY); + } + BlockSignals(True, SIGPIPE); + cli_credentials_guess(ctx->creds, lp_ctx); + if (getenv("USER")) { ctx->username = talloc_strdup(ctx, getenv("USER")); } else { diff --git a/source3/lib/netapi/netapi_private.h b/source3/lib/netapi/netapi_private.h index 67cf8961e7b..ba2f8bb2651 100644 --- a/source3/lib/netapi/netapi_private.h +++ b/source3/lib/netapi/netapi_private.h @@ -21,6 +21,7 @@ #define __LIB_NETAPI_PRIVATE_H__ #include "lib/netapi/netapi_net.h" +#include "auth/credentials/credentials.h" #define LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, fn) \ DEBUG(10,("redirecting call %s to localhost\n", #fn)); \ @@ -63,6 +64,8 @@ struct libnetapi_ctx { int use_ccache; int disable_policy_handle_cache; + struct cli_credentials *creds; + void *private_data; };