Ubuntu 18.04, unboud 1.6.7 and python module

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/&gt;

[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&gt; .

[https://www.emetriq.com] <https://www.facebook.com/emetriq/&gt; [https://www.emetriq.com] <https://www.instagram.com/emetriq_at_work/?hl=de&gt; [https://www.emetriq.com] <https://twitter.com/emetriq?lang=de&gt; [https://www.emetriq.com] <https://www.xing.com/companies/emetriqgmbh&gt;

emetriq GmbH
Vorsetzen 35
20459 Hamburg

Sitz der Gesellschaft: Bonn
Handelsregister: AG Bonn, HRB 20117
Geschäftsführer: Claas Voigt, Stephan Jäckel

(attachments)

unbound-module.txt (2.78 KB)

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)

Hi Wouter,

thanks for your suggestions which I implemented!

I was able to get the script running with a self compiled Ubuntu 1.6.7 (the version used by Ubuntu 18.04) without any problems (with qstate.qinfo.qname_str) so I think the problem is with the Ubuntu 18.04 package.

The python-unbound package behaves a bit odd - it installs a python2 module but strace shows unbound is using python3. I opened a bug report @ launchpad.net.

Greetings from Hamburg
Christian

Am 05.08.20, 12:35 schrieb "Unbound-users im Auftrag von Wouter Wijngaards via Unbound-users" <unbound-users-bounces@lists.nlnetlabs.nl im Auftrag von unbound-users@lists.nlnetlabs.nl>:

    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)