Creating new virtual server issues

SYSTEM INFORMATION
OS type and version centos 7
Webmin version 2.001
Virtualmin version 7.2

I do not have BIND server running. I use godaddy for my DNS records.

However, setting up a new server recently, and I noticed that several things failed when it was doing its thing.
I feel like I never saw this before, maybe I had BIND running but I do not recall.

My questions is: Why would webilizer, spam filtering and virus filtering fail? I mean they are not really related to DNS right?

Adding new DNS zone ..
.. DNS domain failed! : Failed to open /var/named/chroot/etc/named.conf for writing : No such file or directory
Adding to email domains list ..
.. done
Adding default mail aliases ..
.. done
Adding new virtual website ..
.. Apache website failed! : Failed to open /var/named/chroot/etc/named.conf for writing : No such file or directory
Setting up scheduled Webalizer reporting ..
.. no logging directive found in webserver configuration!
Setting up log file rotation ..
.. done
Creating MariaDB login ..
.. done
Creating MariaDB database domain.ca ..
.. done
Setting up spam filtering ..
.. Spam filtering failed! : Failed to open /var/named/chroot/etc/named.conf for writing : No such file or directory
Setting up virus filtering ..
.. Virus filtering failed! : Failed to open /var/named/chroot/etc/named.conf for writing : No such file or directory
Setting up AWStats reporting ..
.. AWStats reporting failed! : virtualmin-awstats::feature_setup failed : Failed to open /var/named/chroot/etc/named.conf for writing : No such file or directory
Adding DAV directives to website configuration ..
.. done


Hello,

This is a known bug. It can be fixed easily :

And that is a very good question!

@Jamie, I have taken a very deep look to this problem. I think it needs your close attention. I think the code in either read_file_lines or flush_file_lines has a bug.

This is what I found out. The Virtualmin function try_function runs $rv = &$func(@args) in eval block. As this block called (i.e. failing dns_setup in this case), and when a config file is missing that is being read in read_file_lines sub, it still makes its way to %main::file_cache, and later when flush_file_lines is called without an argument, that un-existent file first gets to @files and then to open_tempfile and eventually fails.

While running tests I made it work locally by changing flush_file_lines and making sure that files taken from %main:file_cache can be read by adding one extra line to the line 3607:

@files = grep { -r "$_" } @files;

That local fix made the code execute as expected. Although, I suspect that you may want to solve it some other way, for example not adding file to the cache at the first place, if it cannot be read.

This issue can be reproduced in a very simple steps:

  1. Go to BIND module config and set chroot to something un-existent, i.e. /var/named/chroot/etc
  2. Go to Virtualmin and create a new domain with and without DNS feature enabled:
  • In case DNS feature is enabled all irrelevant to DNS features that call flush_file_lines() without an argument will fail false-positively as OP described
  • In case DNS feature is not selected upon domain creation all works as expected

What if the file doesn’t exist yet?

As we flush/write the file that is expected to be read first – how is this possible to expect that file may not exist?

It is possible to call read_file_lines on a non-existent file, update the array ref, and then call flush_file_lines to create the file.

The real question here is why we’re reading and writing named.conf when it doesn’t exist. I will need to look into that…

That issue with named.conf is a known and fixed issue when Webmin BIND config on CentOS 7 wasn’t updated properly getting incorrect chroot directive.

Then we need to check that the directory we’re trying to write a file in is actually exists. Nevertheless, either way we shouldn’t fail here the way we do, as we sometimes call this code in eval.

@Jamie, something like this instead:

@files = grep { my ($dir) = $_ =~ /^(.*)\/.*$/; -d $dir } @files;

… or may be we should create a directory (recursively) instead if that doesn’t exist?

No, the bug is at a higher level - the BIND module and DNS support in Virtualmin shouldn’t even be doing anything if the config doesn’t exist. This should fix it : We are only reading named.conf, not writing here · webmin/webmin@90e1646 · GitHub

@Jamie, well this patch seems fine. Although, it doesn’t solve the initial problem in question! Also, I am worried that we could call bind8::get_config_parent to load a config for later writing ?

As we expect to write a file that may not exist, I would like to suggest to check if a directory for a file actually exists!

Please have a look at this PR:

This patch works for me and solves the initial “problem” in question. Even though the initial config is incorrect, if we write a file that may not exist, it looks reasonable to me to check on the file directory existence first, and if not create it.

But in this case, creating that directory is just wrong - it would be an invalid path that BIND doesn’t actually use.

Yes, it would create a wrong directory, and this would be expected as a caller has to care about setting the right path. But this isn’t the case and we call this code in eval {}. However, if you think that the PR it’s unsuitable we can leave it as it is.

Also, I am not sure that this problem can be solved easily because the file in question that is failing is expected to be opened for writing.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.