Skip to content

Commit

Permalink
Inhibit DNS service
Browse files Browse the repository at this point in the history
If Samba DC is configured on the local node, inhibit our DNS service.
  • Loading branch information
DavidePrincipi committed Dec 11, 2024
1 parent ab3cf4c commit 212d35f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 9 additions & 3 deletions imageroot/actions/get-configuration/10get
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import json
import sys

import agent
import network

config = json.load(open("config.json"))
Expand All @@ -18,8 +18,14 @@ if config["interface"] != "" and config["dhcp-server"]["start"] == "" and config
config["dhcp-server"]["start"] = str(interface["start"])
config["dhcp-server"]["end"] = str(interface["end"])

# we test if tcp/53 or udp/53 is bound to the interface
config["is_dns_bound"] = network.are_ports_53_bound()
# Lookup local Samba DCs. They want to bind DNS port 53 like us.
local_samba_dcs = agent.list_service_providers(rdb, 'ldap', 'tcp', {
"schema": "ad",
"node": os.environ["NODE_ID"],
})

# we test if tcp/53 or udp/53 is bound to the interface, or local Samba DCs are present
config["is_dns_bound"] = network.are_ports_53_bound() or local_samba_dcs
# check if dnsmasq is enabled in the configuration, needed to determine in the UI if the DNS server was enabled and used by dnsmasq.
# the dnsmasq service is always running, we cannot state if it is enabled/active or not.
config['is_dns_enabled'] = config["dns-server"]["enabled"]
Expand Down
14 changes: 12 additions & 2 deletions imageroot/bin/expand-config
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ except FileNotFoundError:
json.dump(config, fp=open("config.json", "w"))


rdb = agent.redis_connect(use_replica=True)
# Lookup local Samba DCs. They want to bind DNS port 53 like us.
local_samba_dcs = agent.list_service_providers(rdb, 'ldap', 'tcp', {
"schema": "ad",
"node": os.environ["NODE_ID"],
})

# convert json to configuration file
with open("dnsmasq.d/00config.conf", "w") as file:
file.write("# This file is automatically generated by NethServer, manual changes will be lost.\n")
Expand All @@ -42,8 +49,11 @@ with open("dnsmasq.d/00config.conf", "w") as file:
if config["dhcp-server"]["enabled"]:
file.write("dhcp-range=set:default," + config["dhcp-server"]["start"] + "," + config["dhcp-server"]["end"] + "," + str(config["dhcp-server"]["lease"]) + "h\n")

# write dns-server configuration
if config["dns-server"]["enabled"]:
# write dns-server configuration, if no local Samba DC is present
if local_samba_dcs:
agent.print("Local Active Directory DC found, DNS feature is blocked.", local_samba_dcs, file=sys.stderr)
file.write("port=0\n")
elif config["dns-server"]["enabled"]:
file.write("server=" + config["dns-server"]["primary-server"] + "\n")
if config["dns-server"]["secondary-server"] != "":
file.write("server=" + config["dns-server"]["secondary-server"] + "\n")
Expand Down

0 comments on commit 212d35f

Please sign in to comment.