]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
netapi: Pass loadparm_context to libnetapi_net_init()
authorSamuel Cabrero <scabrero@samba.org>
Thu, 7 Sep 2023 12:34:36 +0000 (14:34 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 11 Sep 2023 02:42:41 +0000 (02:42 +0000)
The net's tool cmdline lp_ctx can be reused, no need to init a new one except
for external library users.

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/lib/netapi/netapi.c
source3/lib/netapi/netapi_net.h
source3/utils/net_dom.c
source3/utils/net_offlinejoin.c
source3/utils/net_rpc.c
source3/utils/net_rpc_shell.c
source4/torture/libnetapi/libnetapi.c

index fe9821646a81b8eacb71421cee217be2caaccc8c..28a32180eb8bf4e9201df7de91f33fd3d8220075 100644 (file)
@@ -62,6 +62,8 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context)
 {
        NET_API_STATUS ret;
        TALLOC_CTX *frame;
+       struct loadparm_context *lp_ctx = NULL;
+
        if (stat_ctx && libnetapi_initialized) {
                *context = stat_ctx;
                return NET_API_STATUS_SUCCESS;
@@ -89,7 +91,13 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context)
 
        BlockSignals(True, SIGPIPE);
 
-       ret = libnetapi_net_init(context);
+       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);
        TALLOC_FREE(frame);
        return ret;
 }
@@ -102,12 +110,12 @@ level etc, this avoids doing so again (which causes trouble with -d on
 the command line).
 ****************************************************************/
 
-NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context)
+NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context,
+                                 struct loadparm_context *lp_ctx)
 {
        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) {
@@ -121,12 +129,6 @@ NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **context)
                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);
 
        /* Ignore return code, as we might not have a smb.conf */
index c1b06ade3beee5615c4b4a1b7b9aa399b627178f..86dd3abe22998be28f1cc36f4e157afcade6644b 100644 (file)
@@ -21,4 +21,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);
+NET_API_STATUS libnetapi_net_init(struct libnetapi_ctx **ctx,
+                                 struct loadparm_context *lp_ctx);
index 4b48e1566bc87f55c6673f34fdfedfadeb0d8895..9f052abac4f4eb959eb82cced246dac86db59f23 100644 (file)
@@ -376,7 +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);
+       status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx);
        if (status != 0) {
                return -1;
        }
index 5b919f81044fb6fd2891d243d0f8ce2f74398569..72493feb9bef68663f66e3041642a3139080b966 100644 (file)
@@ -54,7 +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);
+       status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx);
        if (status != 0) {
                return -1;
        }
index 69fd48191badcf9805657c776ca1491d9027017b..383afd2eced81506dceaaea54aec5bb0256ff3a8 100644 (file)
@@ -1312,7 +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);
+       status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx);
        if (status != 0) {
                return -1;
        }
@@ -3505,7 +3505,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);
+       status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx);
        if (status != 0) {
                return -1;
        }
@@ -5474,7 +5474,7 @@ 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);
+       status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx);
        if (status != 0) {
                return -1;
        }
@@ -5757,7 +5757,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);
+       status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx);
        if (status != 0) {
                return -1;
        }
@@ -8369,7 +8369,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);
+       status = libnetapi_net_init(&c->netapi_ctx, c->lp_ctx);
        if (status != 0) {
                return -1;
        }
index 634c5b5248af49ceddc6ffb51b5b5ca57632fab2..1c2abd0990c703fd91200e0b7a73c440c64f5636 100644 (file)
@@ -229,7 +229,7 @@ int net_rpc_shell(struct net_context *c, int argc, const char **argv)
                return -1;
        }
 
-       if (libnetapi_net_init(&c->netapi_ctx) != 0) {
+       if (libnetapi_net_init(&c->netapi_ctx, c->lp_ctx) != 0) {
                return -1;
        }
 
index a7560ac6c67ffac93714b03cd8321ea592231c83..605488d1873b1631183db4024a84602c3f50a030 100644 (file)
@@ -41,7 +41,7 @@ bool torture_libnetapi_init_context(struct torture_context *tctx,
 
        load_interfaces();
 
-       status = libnetapi_net_init(&ctx);
+       status = libnetapi_net_init(&ctx, tctx->lp_ctx);
        if (status != 0) {
                talloc_free(frame);
                return false;