Ubuntu 18.04, unboud 1.6.7 and python module

Wouter Wijngaards wouter at nlnetlabs.nl
Wed Aug 5 10:35:07 UTC 2020


Hi Christian,

If I try this with the latest version from the code repository, I can
make it work just fine.  I guess it would also work with unbound 1.11.0.

It turns out to work just fine with qname_str=qstate.qinfo.qname_str
Also the qnamelisttostr can work with ".".join.
The python_script variable has changed to a config_strlist in the newer
releases, and thus I included something to print that correctly.
The list for that python_script config parameter means you can load
multiple python scripts by having more than one python-script: "file"
line in the config file, and in that order, having more than one
"python" element in the module-config list of modules.  For here, it is
only a type change and the script is easily fixed to print that right.
Or print env.cfg.python_script.str the first element in the list.

Perhaps these issues are already fixed as part of Python-3 related fixes
in the code base.

Here is the changes:

--- test2.py.orig	2020-08-05 12:06:38.739887060 +0200
+++ test2.py	2020-08-05 12:25:21.826634657 +0200
@@ -4,13 +4,17 @@
 debugModule = True

 def qnameListToStr( qname_list ):
-    qname_list_decode = list()
-    for l in qname_list:
-        qname_list_decode.append( l.decode('utf-8') )
-    return ".".join( qname_list_decode )
+    return ".".join(qname_list)
+
+def strlisttostr( str_list ):
+    thelist = list()
+    while str_list is not None:
+        thelist.append(str_list.str)
+        str_list = str_list.next
+    return " ".join( thelist )

 def init_standard(id, env):
-    log_info("aws-hostnames: init called, module id is %d port: %d
script: %s verbosity: %s" % (id, env.cfg.port, env.cfg.python_script,
env.cfg.verbosity))
+    log_info("aws-hostnames: init called, module id is %d port: %d
script: %s verbosity: %s" % (id, env.cfg.port,
strlisttostr(env.cfg.python_script), env.cfg.verbosity))

     # Build pattern for checking, pattern matches everything like
     # ip-[0-9]-[0-9]-[0-9]-[0-9].domain.name
@@ -39,6 +43,7 @@
         return True

     elif event == MODULE_EVENT_MODDONE:
+        #qname_str = qstate.qinfo.qname_str
         qname_str = qnameListToStr(qstate.qinfo.qname_list)
         log_info("python: MODDONE with rcode '%s' and priming '%s' and
query '%s' of type '%s'" % (
                     qstate.return_rcode, qstate.is_priming, qname_str,
qstate.qinfo.qtype_str

Best regards, Wouter

On 05/08/2020 11:41, Christian Kelinski via Unbound-users wrote:
> Hi,
> 
> we have a unbound python modul up and running which resolves Hostnames like ip-1-2-3-4.some.domain to 1.2.3.4. Currently our environment is Ubuntu 16.04 and unbound 1.5.8.
> 
> Since Ubuntu 16.04 is EOL in some months I want to update our Servers to Ubuntu 18.04. But the module is not working anymore.
> 
> First it seems that accessing qstate.qinfo.qname_str in operate() doesn't work. I get an error:
> error: pythonmod: Exception occurred in function operate, event: module_event_moddone
> 
> No big deal since the info could be retrieved from qstate.qinfo.qname_list
> 
> But when calling msg.set_return_msg(qstate) with a DNSMessage Object which has the answer appended it always fails (and unbound returns SERVFAIL). I compiled the documentation for unbound 1.6.7 and tried the "Response generation" example without luck.
> 
> I both tried python2 and python3 with same results.
> 
> With some small modifications I got the module up and running with Ubuntu 20.04 which ships with unbound 1.9.4. This modified version also works with Ubuntu 18.04 and a from source compiled unbound 1.11.0.
> 
> I attached the module to this E-Mail. Doing a "dig
> 
> I seems I'm missing something since - based on the documentation - I doing it okay __ Has someone experienced something similar with Ubuntu 18.04/unbound 1.6.7?
> 
> Thanks in advance and thanks for creating such a lovely software!
> Christian
> 
> 
> [https://www.emetriq.com] <https://www.emetriq.com/whitepaper-reports/programmatic-data-playbook/>
> 
> [https://www.emetriq.com] <https://www.emetriq.com>
> 
> Whitepaper, Analysen & Reports rund um Data-driven Advertising gibt es auch im monatlichen E-Mail-Newsletter emetriq Data Update <https://www.emetriq.com/newsletter/?utm_source=emetriq_mail&utm_medium=outlook&utm_campaign=newsletter> .
> 
> [https://www.emetriq.com] <https://www.facebook.com/emetriq/> [https://www.emetriq.com]  <https://www.instagram.com/emetriq_at_work/?hl=de> [https://www.emetriq.com]  <https://twitter.com/emetriq?lang=de> [https://www.emetriq.com]  <https://www.xing.com/companies/emetriqgmbh>
> 
> emetriq GmbH
> Vorsetzen 35
> 20459 Hamburg
> 
> Sitz der Gesellschaft: Bonn
> Handelsregister: AG Bonn, HRB 20117
> Geschäftsführer: Claas Voigt, Stephan Jäckel
> ________________________________
> Wir sind Mitglied im BVDW (Bundesverband Digitale Wirtschaft)
> ________________________________
> Datenschutz ist emetriq sehr wichtig. Weitere Informationen finden Sie in unseren Datenschutzhinweisen unter www.emetriq.com/datenschutz <https://www.emetriq.com/datenschutz> .
> 
> This e-mail is confidential and is intended for the addressee(s) only.
> If you are not the named addressee you may not use it, copy it or
> disclose it to any other person. If you received this message in error
> please notify the sender immediately.
> 


More information about the Unbound-users mailing list