]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
add unit test for plugin_register source param
authorColin Vidal <colin@isc.org>
Tue, 19 Aug 2025 12:45:56 +0000 (14:45 +0200)
committerColin Vidal <colin@isc.org>
Tue, 9 Sep 2025 07:42:34 +0000 (09:42 +0200)
Update the existing test's syncplugin plugin with a new parameter
indicating whether the plugin should be loaded in a view or a zone.
If it doesn't match where the plugin is actually loaded, it fails the
initialization. This covers the correctless of the `source` parameter of
`plugin_register` API.

bin/tests/system/hooks/conf/bad-topviewlevel.conf.j2
bin/tests/system/hooks/conf/good-toplevel.conf.j2
bin/tests/system/hooks/conf/good-viewlevel.conf.j2
bin/tests/system/hooks/conf/good-viewzonelevel.conf.j2
bin/tests/system/hooks/conf/good-zonelevel.conf.j2
bin/tests/system/hooks/driver/test-async.c
bin/tests/system/hooks/driver/test-syncplugin.c
bin/tests/system/hooks/ns2/named.conf.j2

index 9e7338dbd76a5e9b4e53044d550e8600439f5214..7e213436cb805a5854d6b985990044344f3e8ef0 100644 (file)
  */
 
 view foo {
-       plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { rcode servfail; };
+       plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" {
+               rcode servfail;
+       };
+};
+plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" {
+       rcode servfail;
 };
-plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { rcode servfail; };
index 3e416a6c6a4c3b8c8fd4d6c3d566b866bda03957..9064bf4116d888a50e1ba3cd76f3e978a7202dcc 100644 (file)
@@ -11,4 +11,6 @@
  * information regarding copyright ownership.
  */
 
-plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { rcode servfail; };
+plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" {
+       rcode servfail;
+};
index 7efc0a175de7968126716fd8612c43887a1e367b..4e1a2d64bdacc55c03dc75afdd99d9f64d3bd05a 100644 (file)
@@ -12,5 +12,7 @@
  */
 
 view foo {
-       plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { rcode servfail; };
+       plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" {
+               rcode servfail;
+       };
 };
index a1b0f2cf46e10a790126dceb98e0e1568c046ec1..7d992824cdad05eb6e77647f66eed40ed6b539a4 100644 (file)
 
 view someview {
        zone "foo.bar" {
-               plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { rcode servfail; };
+               plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" {
+                       rcode servfail;
+               };
                type primary;
                file "foo.bar.db";
        };
-       plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { rcode servfail; };
+       plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" {
+               rcode servfail;
+       };
 };
index 133ef864d7b63fcb7d68e60b18c4884a28ff9c7e..cf8162193d003033fcef72360abff7a3c8fde73e 100644 (file)
@@ -12,7 +12,9 @@
  */
 
 zone "foo.bar" {
-       plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" { rcode servfail; };
+       plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" {
+               rcode servfail;
+       };
        type primary;
        file "foo.bar.db";
 };
index d6b9faa25e8487eb9634f275dac4a6f28473fb41..4cc8ef79431ef38e5395f5704dc51bc70ef68e9d 100644 (file)
@@ -125,9 +125,11 @@ logmsg(const char *fmt, ...) {
 isc_result_t
 plugin_register(const char *parameters, const void *cfg, const char *cfg_file,
                unsigned long cfg_line, isc_mem_t *mctx, void *actx,
-               ns_hooktable_t *hooktable, void **instp) {
+               ns_hooktable_t *hooktable, ns_hooksource_t source,
+               void **instp) {
        async_instance_t *inst = NULL;
 
+       UNUSED(source);
        UNUSED(parameters);
        UNUSED(cfg);
        UNUSED(actx);
index 1d082900b66a00ad5b8225847e7337beac191c4d..4ab4be49668a92cb4429d8a25728cda2cd0de7e6 100644 (file)
@@ -67,6 +67,7 @@ syncplugin__hook(void *arg, void *cbdata, isc_result_t *resp) {
 
 static cfg_clausedef_t syncplugin__cfgclauses[] = {
        { "rcode", &cfg_type_astring, 0 },
+       { "source", &cfg_type_astring, 0 },
        { "firstlbl", &cfg_type_qstring, CFG_CLAUSEFLAG_OPTIONAL }
 };
 
@@ -112,7 +113,8 @@ syncplugin__parse_rcode(const cfg_obj_t *syncplugincfg, uint8_t *rcode) {
 isc_result_t
 plugin_register(const char *parameters, const void *cfg, const char *cfgfile,
                unsigned long cfgline, isc_mem_t *mctx, void *actx,
-               ns_hooktable_t *hooktable, void **instp) {
+               ns_hooktable_t *hooktable, ns_hooksource_t source,
+               void **instp) {
        isc_result_t result;
        cfg_parser_t *parser = NULL;
        cfg_obj_t *syncplugincfg = NULL;
@@ -120,9 +122,11 @@ plugin_register(const char *parameters, const void *cfg, const char *cfgfile,
        isc_buffer_t b;
        ns_hook_t hook;
        syncplugin_t *inst = NULL;
+       char *sourcestr = NULL;
 
        UNUSED(cfg);
        UNUSED(actx);
+       UNUSED(source);
 
        inst = isc_mem_get(mctx, sizeof(*inst));
        *inst = (syncplugin_t){ .mctx = mctx };
@@ -146,6 +150,25 @@ plugin_register(const char *parameters, const void *cfg, const char *cfgfile,
                strncpy(inst->firstlbl, firstlbl, len);
        }
 
+       obj = NULL;
+       CHECK(cfg_map_get(syncplugincfg, "source", &obj));
+       sourcestr = obj->value.string.base;
+
+       if (strcmp(sourcestr, "zone") == 0) {
+               if (source != NS_HOOKSOURCE_ZONE) {
+                       result = ISC_R_FAILURE;
+                       goto cleanup;
+               }
+       } else if (strcmp(sourcestr, "view") == 0) {
+               if (source != NS_HOOKSOURCE_VIEW) {
+                       result = ISC_R_FAILURE;
+                       goto cleanup;
+               }
+       } else {
+               result = ISC_R_FAILURE;
+               goto cleanup;
+       }
+
        hook = (ns_hook_t){ .action = syncplugin__hook, .action_data = inst };
        ns_hook_add(hooktable, mctx, NS_QUERY_NXDOMAIN_BEGIN, &hook);
 
index 35431d89142a2ba9fd80ce3a96921913790643ea..87678738cee82d3b0d32de53ad16da7285d17bf0 100644 (file)
@@ -35,8 +35,9 @@ controls {
        inet 10.53.0.2 port @CONTROLPORT@ allow { any; } keys { rndc_key; };
 };
 
-plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" {
+plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" {
        rcode noerror;
+       source view;
 };
 
 zone "example.com" {
@@ -47,31 +48,35 @@ zone "example.com" {
 zone "example2.com" {
        type primary;
        file "example.db";
-       plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" {
+       plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" {
                rcode servfail;
+               source zone;
        };
 };
 
 zone "example3.com" {
        type primary;
        file "example.db";
-       plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" {
+       plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" {
                rcode notimp;
+               source zone;
        };
 };
 
 template exampletmpl {
        type primary;
        file "$name.db";
-       plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" {
+       plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" {
                rcode notauth;
                firstlbl "skipfoo";
+               source zone;
        };
 };
 
 zone "example4.com" {
        template exampletmpl;
-       plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin.so" {
+       plugin query "@TOP_BUILDDIR@/testlib-driver-syncplugin" {
                rcode notzone;
+               source zone;
        };
 };