]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4:libnet: pass an explicit talloc parent to libnet_context_init()
authorStefan Metzmacher <metze@samba.org>
Fri, 9 May 2025 11:30:36 +0000 (13:30 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Mon, 19 May 2025 09:11:29 +0000 (09:11 +0000)
We should not implicitly use the tevent_context as talloc parent.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
14 files changed:
source4/lib/policy/gp_ldap.c
source4/libnet/libnet.c
source4/libnet/py_net.c
source4/torture/libnet/domain.c
source4/torture/libnet/libnet_BecomeDC.c
source4/torture/libnet/libnet_domain.c
source4/torture/libnet/libnet_group.c
source4/torture/libnet/libnet_lookup.c
source4/torture/libnet/libnet_rpc.c
source4/torture/libnet/libnet_share.c
source4/torture/libnet/libnet_user.c
source4/torture/libnet/utils.c
source4/torture/rpc/dfs.c
source4/torture/rpc/testjoin.c

index 67b329b12957d95f4771437fcef1ea01df8b5ecb..2806c128493fc16f6f1c8a0ae903c6aaf3fbc756 100644 (file)
@@ -160,7 +160,7 @@ NTSTATUS gp_init(TALLOC_CTX *mem_ctx,
        NTSTATUS rv;
 
        /* Initialise the libnet context */
-       net_ctx = libnet_context_init(ev_ctx, lp_ctx);
+       net_ctx = libnet_context_init(mem_ctx, ev_ctx, lp_ctx);
        net_ctx->cred = credentials;
 
        /* Prepare libnet lookup structure for looking a DC (PDC is correct). */
index a590893bee21ab31c1da8bacc4eda1c7519c5652..b04be2187f90b9d298c713bf97cc69be6ce762b4 100644 (file)
@@ -23,7 +23,8 @@
 #include "param/param.h"
 #include "libcli/resolve/resolve.h"
 
-struct libnet_context *libnet_context_init(struct tevent_context *ev,
+struct libnet_context *libnet_context_init(TALLOC_CTX *mem_ctx,
+                                          struct tevent_context *ev,
                                           struct loadparm_context *lp_ctx)
 {
        struct libnet_context *ctx;
@@ -34,7 +35,7 @@ struct libnet_context *libnet_context_init(struct tevent_context *ev,
        }
 
        /* create brand new libnet context */
-       ctx = talloc_zero(ev, struct libnet_context);
+       ctx = talloc_zero(mem_ctx, struct libnet_context);
        if (!ctx) {
                return NULL;
        }
index b65bd5c2a730da8e421660e2f707ac1348c3c04e..d53d345e45d8c2745380edea1b15ba1251452755 100644 (file)
@@ -865,7 +865,9 @@ static PyMethodDef net_obj_methods[] = {
 
 static void py_net_dealloc(py_net_Object *self)
 {
-       talloc_free(self->ev);
+       /* explicitly free libnet_ctx before ev */
+       talloc_free(self->libnet_ctx);
+       talloc_free(self->mem_ctx);
        PyObject_Del(self);
 }
 
@@ -889,8 +891,8 @@ static PyObject *net_obj_new(PyTypeObject *type, PyObject *args, PyObject *kwarg
 
        /* FIXME: we really need to get a context from the caller or we may end
         * up with 2 event contexts */
-       ret->ev = s4_event_context_init(NULL);
-       ret->mem_ctx = talloc_new(ret->ev);
+       ret->mem_ctx = talloc_new(NULL);
+       ret->ev = s4_event_context_init(ret->mem_ctx);
 
        lp = lpcfg_from_py_object(ret->mem_ctx, py_lp);
        if (lp == NULL) {
@@ -898,7 +900,7 @@ static PyObject *net_obj_new(PyTypeObject *type, PyObject *args, PyObject *kwarg
                return NULL;
        }
 
-       ret->libnet_ctx = libnet_context_init(ret->ev, lp);
+       ret->libnet_ctx = libnet_context_init(ret->mem_ctx, ret->ev, lp);
        if (ret->libnet_ctx == NULL) {
                PyErr_SetString(PyExc_RuntimeError, "Unable to initialize net");
                Py_DECREF(ret);
index c1cfc919d002215b45124411a25a7cdc01834e51..743d0857963be01281b76d2ac3a05ef809c97fe1 100644 (file)
@@ -85,7 +85,7 @@ bool torture_domainopen(struct torture_context *torture)
 
        mem_ctx = talloc_init("test_domain_open");
 
-       net_ctx = libnet_context_init(torture->ev, torture->lp_ctx);
+       net_ctx = libnet_context_init(torture, torture->ev, torture->lp_ctx);
 
        status = torture_rpc_connection(torture,
                                        &net_ctx->samr.pipe,
index e88198daf2b84af2d7bf93f10dba5612fa20d79a..5530fa514cfb6df0da1c5b8ce99c6a1afedc5290 100644 (file)
@@ -92,7 +92,7 @@ bool torture_net_become_dc(struct torture_context *torture)
                               location);
        torture_assert(torture, s, "libnet_vampire_cb_state_init");
 
-       ctx = libnet_context_init(torture->ev, torture->lp_ctx);
+       ctx = libnet_context_init(torture, torture->ev, torture->lp_ctx);
        ctx->cred = samba_cmdline_get_creds();
 
        ZERO_STRUCT(b);
index 24440005aaca436fa1e25804332af2b9fefb3607..c1c83fd39a460af030789ab290f31c9317f946a5 100644 (file)
@@ -135,7 +135,7 @@ bool torture_domain_open_lsa(struct torture_context *torture)
           of specific server name. */
        domain_name = lpcfg_workgroup(torture->lp_ctx);
 
-       ctx = libnet_context_init(torture->ev, torture->lp_ctx);
+       ctx = libnet_context_init(torture, torture->ev, torture->lp_ctx);
        if (ctx == NULL) {
                torture_comment(torture, "failed to create libnet context\n");
                return false;
@@ -189,7 +189,7 @@ bool torture_domain_close_lsa(struct torture_context *torture)
                return false;
        }
 
-       ctx = libnet_context_init(torture->ev, torture->lp_ctx);
+       ctx = libnet_context_init(torture, torture->ev, torture->lp_ctx);
        if (ctx == NULL) {
                torture_comment(torture, "failed to create libnet context\n");
                ret = false;
@@ -251,7 +251,7 @@ bool torture_domain_open_samr(struct torture_context *torture)
 
        mem_ctx = talloc_init("test_domainopen_lsa");
 
-       ctx = libnet_context_init(torture->ev, torture->lp_ctx);
+       ctx = libnet_context_init(torture, torture->ev, torture->lp_ctx);
        ctx->cred = samba_cmdline_get_creds();
 
        /* we're accessing domain controller so the domain name should be
@@ -316,7 +316,7 @@ bool torture_domain_close_samr(struct torture_context *torture)
                return false;
        }
 
-       ctx = libnet_context_init(torture->ev, torture->lp_ctx);
+       ctx = libnet_context_init(torture, torture->ev, torture->lp_ctx);
        if (ctx == NULL) {
                torture_comment(torture, "failed to create libnet context\n");
                ret = false;
@@ -380,7 +380,7 @@ bool torture_domain_list(struct torture_context *torture)
                return false;
        }
 
-       ctx = libnet_context_init(torture->ev, torture->lp_ctx);
+       ctx = libnet_context_init(torture, torture->ev, torture->lp_ctx);
        if (ctx == NULL) {
                torture_comment(torture, "failed to create libnet context\n");
                ret = false;
index e3e20307d3a51300ae856c68ca8f886de696c715..949f82b89e1389bb99ab58380ad7db587d6e8d7c 100644 (file)
@@ -113,7 +113,7 @@ bool torture_grouplist(struct torture_context *torture)
        struct libnet_GroupList req;
        int i;
 
-       ctx = libnet_context_init(torture->ev, torture->lp_ctx);
+       ctx = libnet_context_init(torture, torture->ev, torture->lp_ctx);
        ctx->cred = samba_cmdline_get_creds();
 
        domain_name.string = lpcfg_workgroup(torture->lp_ctx);
@@ -176,7 +176,7 @@ bool torture_creategroup(struct torture_context *torture)
 
        mem_ctx = talloc_init("test_creategroup");
 
-       ctx = libnet_context_init(torture->ev, torture->lp_ctx);
+       ctx = libnet_context_init(torture, torture->ev, torture->lp_ctx);
        ctx->cred = samba_cmdline_get_creds();
 
        req.in.group_name = TEST_GROUPNAME;
index e6e23dc049574abd2bf1b78e778c6c564091936b..5adc7daa6b866ac73ba6ca099467aced8ef6ade4 100644 (file)
@@ -38,7 +38,7 @@ bool torture_lookup(struct torture_context *torture)
 
        mem_ctx = talloc_init("test_lookup");
 
-       ctx = libnet_context_init(torture->ev, torture->lp_ctx);
+       ctx = libnet_context_init(torture, torture->ev, torture->lp_ctx);
        ctx->cred = samba_cmdline_get_creds();
 
        lookup.in.hostname = torture_setting_string(torture, "host", NULL);
@@ -82,7 +82,7 @@ bool torture_lookup_host(struct torture_context *torture)
 
        mem_ctx = talloc_init("test_lookup_host");
 
-       ctx = libnet_context_init(torture->ev, torture->lp_ctx);
+       ctx = libnet_context_init(torture, torture->ev, torture->lp_ctx);
        ctx->cred = samba_cmdline_get_creds();
 
        lookup.in.hostname = torture_setting_string(torture, "host", NULL);
@@ -125,7 +125,7 @@ bool torture_lookup_pdc(struct torture_context *torture)
 
        mem_ctx = talloc_init("test_lookup_pdc");
 
-       ctx = libnet_context_init(torture->ev, torture->lp_ctx);
+       ctx = libnet_context_init(torture, torture->ev, torture->lp_ctx);
        ctx->cred = samba_cmdline_get_creds();
 
        talloc_steal(ctx, mem_ctx);
@@ -170,7 +170,7 @@ bool torture_lookup_sam_name(struct torture_context *torture)
        struct libnet_LookupName r;
        bool ret = true;
 
-       ctx = libnet_context_init(torture->ev, torture->lp_ctx);
+       ctx = libnet_context_init(torture, torture->ev, torture->lp_ctx);
        ctx->cred = samba_cmdline_get_creds();
 
        mem_ctx = talloc_init("torture lookup sam name");
index 9820432e224d90acf7abb6596c702d0acac86538..358cc09e20d9993cd99aa573fb82b2bd5c8046ea 100644 (file)
@@ -89,7 +89,7 @@ static bool torture_rpc_connect(struct torture_context *torture,
 {
        struct libnet_context *ctx;
 
-       ctx = libnet_context_init(torture->ev, torture->lp_ctx);
+       ctx = libnet_context_init(torture, torture->ev, torture->lp_ctx);
        ctx->cred = samba_cmdline_get_creds();
 
        torture_comment(torture, "Testing connection to LSA interface\n");
index da74b99f8adf1387c33603b8975dbbc70936d2b7..7303e01af253e69a1a9c73be39e6570bd63b026c 100644 (file)
@@ -175,7 +175,7 @@ bool torture_listshares(struct torture_context *torture)
                goto done;
        }
 
-       libnetctx = libnet_context_init(torture->ev, torture->lp_ctx);
+       libnetctx = libnet_context_init(torture, torture->ev, torture->lp_ctx);
        if (!libnetctx) {
                torture_comment(torture, "Couldn't allocate libnet context\n");
                ret = false;
@@ -262,7 +262,7 @@ bool torture_delshare(struct torture_context *torture)
        status = torture_rpc_binding(torture, &binding);
        torture_assert_ntstatus_ok(torture, status, "Failed to get binding");
 
-       libnetctx = libnet_context_init(torture->ev, torture->lp_ctx);
+       libnetctx = libnet_context_init(torture, torture->ev, torture->lp_ctx);
        libnetctx->cred = samba_cmdline_get_creds();
 
        status = torture_rpc_connection(torture,
index 9029827f203d6adaaa1ae64259345e5833955d2f..f1f883ee11ce35838e70c85acaf1421863b103cf 100644 (file)
@@ -465,7 +465,7 @@ bool torture_userlist(struct torture_context *torture)
        struct libnet_UserList req;
        int i;
 
-       ctx = libnet_context_init(torture->ev, torture->lp_ctx);
+       ctx = libnet_context_init(torture, torture->ev, torture->lp_ctx);
        ctx->cred = samba_cmdline_get_creds();
 
        domain_name.string = lpcfg_workgroup(torture->lp_ctx);
index de859d57a1db0b5c7f607e44c5f8d120db05a8ab..719a4514b3cf5e7823c4a542009dd46b61914914 100644 (file)
@@ -489,7 +489,7 @@ bool test_libnet_context_init(struct torture_context *tctx,
        bool bret = true;
        struct libnet_context *net_ctx;
 
-       net_ctx = libnet_context_init(tctx->ev, tctx->lp_ctx);
+       net_ctx = libnet_context_init(tctx, tctx->ev, tctx->lp_ctx);
        torture_assert(tctx, net_ctx != NULL, "Failed to create libnet_context");
 
        /* Use command line credentials for testing */
index 14af288972763783dcf6a22114817613bc61b646..adb78e90283ccc747624ea84bc15d024e69dfceb 100644 (file)
@@ -52,7 +52,7 @@ static bool test_NetShareAdd(struct torture_context *tctx,
 
        printf("Creating share %s\n", sharename);
 
-       if (!(libnetctx = libnet_context_init(tctx->ev, tctx->lp_ctx))) {
+       if (!(libnetctx = libnet_context_init(tctx, tctx->ev, tctx->lp_ctx))) {
                return false;
        }
 
@@ -91,7 +91,7 @@ static bool test_NetShareDel(struct torture_context *tctx,
 
        torture_comment(tctx, "Deleting share %s\n", sharename);
 
-       if (!(libnetctx = libnet_context_init(tctx->ev, tctx->lp_ctx))) {
+       if (!(libnetctx = libnet_context_init(tctx, tctx->ev, tctx->lp_ctx))) {
                return false;
        }
 
index 133b9f09c43c3814540801ab66f99fa0225c41d3..1308811b76fd12349c2e47daadb0b7c9ad28e44f 100644 (file)
@@ -546,7 +546,7 @@ _PUBLIC_ struct test_join *torture_join_domain(struct torture_context *tctx,
                return NULL;
        }
        
-       libnet_ctx = libnet_context_init(tctx->ev, tctx->lp_ctx);
+       libnet_ctx = libnet_context_init(tctx, tctx->ev, tctx->lp_ctx);
        if (!libnet_ctx) {
                talloc_free(tj);
                return NULL;