s3:netapi: Add a cli_credentials pointer to struct libnetapi_ctx
authorAndreas Schneider <asn@samba.org>
Thu, 18 Mar 2021 09:43:26 +0000 (10:43 +0100)
committerGünther Deschner <gd@samba.org>
Wed, 24 Mar 2021 00:55:32 +0000 (00:55 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
source3/lib/netapi/netapi.c
source3/lib/netapi/netapi_private.h

index 4c8a96e2e70aa101a071784a762f88d3d1390f49..591523edfe09d52b2a28f841cf113e1ef064f1a2 100644 (file)
@@ -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 {
index 67cf8961e7bd7a72307edc7fd0620e9a4efd9f6f..ba2f8bb26510d4dc22dffb9a7894bed2d308452c 100644 (file)
@@ -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;
 };