]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
[v9_11] pass source file and line to dyndb load function
authorEvan Hunt <each@isc.org>
Fri, 26 Aug 2016 01:09:45 +0000 (18:09 -0700)
committerEvan Hunt <each@isc.org>
Fri, 26 Aug 2016 01:09:45 +0000 (18:09 -0700)
4455. [cleanup] Allow dyndb modules to correctly log the filename
and line number when processing configuration text
from named.conf. [RT #43050]

(cherry picked from commit 02fb764681d145e4607c59280a48617013e886ac)

CHANGES
bin/named/server.c
bin/tests/system/dyndb/driver/driver.c
bin/tests/system/dyndb/tests.sh
lib/dns/dyndb.c
lib/dns/include/dns/dyndb.h
lib/isc/include/isc/lex.h
lib/isc/lex.c
lib/isc/tests/lex_test.c

diff --git a/CHANGES b/CHANGES
index 1714f98ffd4a8edc11aa8d0d9bc74ea1a4e75cc6..83ce423b65309a039b2db4acdbad7ba1402a11b4 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,9 @@
        --- 9.11.0rc1 released ---
 
+4455.  [cleanup]       Allow dyndb modules to correctly log the filename
+                       and line number when processing configuration text
+                       from named.conf. [RT #43050]
+
 4454.  [bug]           'rndc dnstap -reopen' had a race issue. [RT #43089]
 
 4453.  [bug]           Prefetching of DS records failed to update their
index 65ea5718d83de4ca1dcd563aca79ce52a094d72c..bb122fb9c9bc20cae023974e688e64d137bcd6a5 100644 (file)
@@ -1410,8 +1410,9 @@ configure_dyndb(const cfg_obj_t *dyndb, isc_mem_t *mctx,
 
        obj = cfg_tuple_get(dyndb, "parameters");
        if (obj != NULL)
-               result = dns_dyndb_load(library, name,
-                                       cfg_obj_asstring(obj), mctx, dctx);
+               result = dns_dyndb_load(library, name, cfg_obj_asstring(obj),
+                                       cfg_obj_file(obj), cfg_obj_line(obj),
+                                       mctx, dctx);
 
        if (result != ISC_R_SUCCESS)
                isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
index 785c6a8d7fcc5e7246b7ab2a04a66325abfee03f..bef6acb654a47620cfb1cb916dae4b7133980a25 100644 (file)
@@ -51,11 +51,15 @@ dns_dyndb_version_t dyndb_version;
  * @param[in] parameters  User-defined parameters from dyndb section as one
  *                        string. The example above will have
  *                        params = "param1 param2";
+ * @param[in] file       The name of the file from which the parameters
+ *                        were read.
+ * @param[in] line       The line number from which the parameters were read.
  * @param[out] instp      Pointer to instance-specific data
  *                        (for one dyndb section).
  */
 isc_result_t
 dyndb_init(isc_mem_t *mctx, const char *name, const char *parameters,
+          const char *file, unsigned long line,
           const dns_dyndbctx_t *dctx, void **instp)
 {
        isc_result_t result;
@@ -90,6 +94,10 @@ dyndb_init(isc_mem_t *mctx, const char *name, const char *parameters,
        if (result != ISC_R_SUCCESS)
                goto cleanup;
 
+       log_write(ISC_LOG_DEBUG(9),
+                 "loading params for dyndb '%s' from %s:%lu",
+                 name, file, line);
+
        /* Finally, create the instance. */
        CHECK(new_sample_instance(mctx, name, argc, argv, dctx, &sample_inst));
 
index d40c57a9af626148172873162d01965e125b8f76..f9f7c29d657a4ac04988241cf7ea6378166ebf95 100644 (file)
@@ -124,6 +124,11 @@ status=`expr $status + $ret`
 test_del test4.ipv6.example.nil. AAAA || ret=1
 status=`expr $status + $ret`
 
+newtest "I:checking parameter logging"
+grep "loading params for dyndb 'sample' from .*named.conf:33" ns1/named.run > /dev/null || ret=1
+grep "loading params for dyndb 'sample2' from .*named.conf:34" ns1/named.run > /dev/null || ret=1
+status=`expr $status + $ret`
+
 echo "I:checking dyndb still works after reload"
 $RNDC -c ../common/rndc.conf -s 10.53.0.1 -p 9953 reload 2>&1 | sed 's/^/I:ns1 /'
 
index f4f78c6a7e3c6a067ed20da1025a1f42e46881ca..a4775086321b56af2c1d7bd3aa50760196a0300b 100644 (file)
@@ -348,7 +348,8 @@ unload_library(dyndb_implementation_t **impp)
 
 isc_result_t
 dns_dyndb_load(const char *libname, const char *name, const char *parameters,
-              isc_mem_t *mctx, const dns_dyndbctx_t *dctx)
+              const char *file, unsigned long line, isc_mem_t *mctx,
+              const dns_dyndbctx_t *dctx)
 {
        isc_result_t result;
        dyndb_implementation_t *implementation = NULL;
@@ -365,8 +366,8 @@ dns_dyndb_load(const char *libname, const char *name, const char *parameters,
                CHECK(ISC_R_EXISTS);
 
        CHECK(load_library(mctx, libname, name, &implementation));
-       CHECK(implementation->register_func(mctx, name, parameters, dctx,
-                                           &implementation->inst));
+       CHECK(implementation->register_func(mctx, name, parameters, file, line,
+                                           dctx, &implementation->inst));
 
        APPEND(dyndb_implementations, implementation, link);
        result = ISC_R_SUCCESS;
index 3ac24f200cfd2cb31bcab08a325674d68ee67558..66e820b0e4e43b26026d12c51f7f639da687a140 100644 (file)
@@ -57,6 +57,8 @@ struct dns_dyndbctx {
 typedef isc_result_t dns_dyndb_register_t(isc_mem_t *mctx,
                                          const char *name,
                                          const char *parameters,
+                                         const char *file,
+                                         unsigned long line,
                                          const dns_dyndbctx_t *dctx,
                                          void **instp);
 /*%
@@ -95,7 +97,8 @@ typedef int dns_dyndb_version_t(unsigned int *flags);
 
 isc_result_t
 dns_dyndb_load(const char *libname, const char *name, const char *parameters,
-              isc_mem_t *mctx, const dns_dyndbctx_t *dctx);
+              const char *file, unsigned long line, isc_mem_t *mctx,
+              const dns_dyndbctx_t *dctx);
 /*%
  * Load a dyndb module.
  *
@@ -104,6 +107,10 @@ dns_dyndb_load(const char *libname, const char *name, const char *parameters,
  * the instance handle to a list of dyndb instances so it can be cleaned
  * up later.
  *
+ * 'file' and 'line' can be used to indicate the name of the file and
+ * the line number from which the parameters were taken, so that logged
+ * error messages, if any, will display the correct locations.
+ *
  * Returns:
  *\li  #ISC_R_SUCCESS
  *\li  #ISC_R_NOMEMORY
index 1480037782774c1c5f64eb4cd452296dccd32373..bc4b653d1a568aa220378257ea342b0e6d8e960c 100644 (file)
@@ -405,6 +405,23 @@ isc_lex_setsourcename(isc_lex_t *lex, const char *name);
  * \li #ISC_R_NOTFOUND - there are no sources.
  */
 
+isc_result_t
+isc_lex_setsourceline(isc_lex_t *lex, unsigned long line);
+/*%<
+ * Assigns a new line number to the input source. This can be used
+ * when parsing a buffer that's been excerpted from the middle a file,
+ * allowing logged messages to display the correct line number,
+ * rather than the line number within the buffer.
+ *
+ * Requires:
+ *
+ * \li 'lex' is a valid lexer.
+ *
+ * Returns:
+ * \li #ISC_R_SUCCESS
+ * \li #ISC_R_NOTFOUND - there are no sources.
+ */
+
 isc_boolean_t
 isc_lex_isfile(isc_lex_t *lex);
 /*%<
index 9a37986142308b97d484292761523425eea34834..0f8ca532e313d87c86db5b83224cb44433d4bd86 100644 (file)
@@ -973,7 +973,6 @@ isc_lex_getlasttokentext(isc_lex_t *lex, isc_token_t *tokenp, isc_region_t *r)
                    source->ignored;
 }
 
-
 char *
 isc_lex_getsourcename(isc_lex_t *lex) {
        inputsource *source;
@@ -1000,7 +999,6 @@ isc_lex_getsourceline(isc_lex_t *lex) {
        return (source->line);
 }
 
-
 isc_result_t
 isc_lex_setsourcename(isc_lex_t *lex, const char *name) {
        inputsource *source;
@@ -1010,7 +1008,7 @@ isc_lex_setsourcename(isc_lex_t *lex, const char *name) {
        source = HEAD(lex->sources);
 
        if (source == NULL)
-               return(ISC_R_NOTFOUND);
+               return (ISC_R_NOTFOUND);
        newname = isc_mem_strdup(lex->mctx, name);
        if (newname == NULL)
                return (ISC_R_NOMEMORY);
@@ -1019,6 +1017,20 @@ isc_lex_setsourcename(isc_lex_t *lex, const char *name) {
        return (ISC_R_SUCCESS);
 }
 
+isc_result_t
+isc_lex_setsourceline(isc_lex_t *lex, unsigned long line) {
+       inputsource *source;
+
+       REQUIRE(VALID_LEX(lex));
+       source = HEAD(lex->sources);
+
+       if (source == NULL)
+               return (ISC_R_NOTFOUND);
+
+       source->line = line;
+       return (ISC_R_SUCCESS);
+}
+
 isc_boolean_t
 isc_lex_isfile(isc_lex_t *lex) {
        inputsource *source;
index c9756088fd5926b64db26a10124a9dca37ff1f75..3462a753880f9b1d6d17777f76051cbc2090b14e 100644 (file)
 #include <isc/mem.h>
 #include <isc/util.h>
 
-ATF_TC(lex);
-ATF_TC_HEAD(lex, tc) {
+ATF_TC(lex_0xff);
+ATF_TC_HEAD(lex_0xff, tc) {
        atf_tc_set_md_var(tc, "descr", "check handling of 0xff");
 }
-ATF_TC_BODY(lex, tc) {
+ATF_TC_BODY(lex_0xff, tc) {
        isc_mem_t *mctx = NULL;
        isc_result_t result;
        isc_lex_t *lex = NULL;
@@ -51,11 +51,58 @@ ATF_TC_BODY(lex, tc) {
        ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
 }
 
+ATF_TC(lex_setline);
+ATF_TC_HEAD(lex_setline, tc) {
+       atf_tc_set_md_var(tc, "descr", "check setting of source line");
+}
+ATF_TC_BODY(lex_setline, tc) {
+       isc_mem_t *mctx = NULL;
+       isc_result_t result;
+       isc_lex_t *lex = NULL;
+       unsigned char text[] = "text\nto\nbe\nprocessed\nby\nlexer";
+       isc_buffer_t buf;
+       isc_token_t token;
+       unsigned long line;
+       int i;
+
+       UNUSED(tc);
+
+       result = isc_mem_create(0, 0, &mctx);
+       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
+
+       result = isc_lex_create(mctx, 1024, &lex);
+       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
+
+       isc_buffer_init(&buf, &text[0], sizeof(text));
+       isc_buffer_add(&buf, sizeof(text));
+
+       result = isc_lex_openbuffer(lex, &buf);
+       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
+
+       result = isc_lex_setsourceline(lex, 100);
+       ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
+
+       for (i = 0; i < 6; i++) {
+               result = isc_lex_gettoken(lex, 0, &token);
+               ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
+
+               line = isc_lex_getsourceline(lex);
+               ATF_REQUIRE_EQ(line, 100U + i);
+       }
+
+       result = isc_lex_gettoken(lex, 0, &token);
+       ATF_REQUIRE_EQ(result, ISC_R_EOF);
+
+       line = isc_lex_getsourceline(lex);
+       ATF_REQUIRE_EQ(line, 105U);
+}
+
 /*
  * Main
  */
 ATF_TP_ADD_TCS(tp) {
-       ATF_TP_ADD_TC(tp, lex);
+       ATF_TP_ADD_TC(tp, lex_0xff);
+       ATF_TP_ADD_TC(tp, lex_setline);
        return (atf_no_error());
 }