Skip to content

Commit

Permalink
Merge pull request #584 from NethServer/fixDomainValidation
Browse files Browse the repository at this point in the history
Add domain inclusion check in bind-user-domains script NethServer/dev#6860
  • Loading branch information
stephdl authored Feb 26, 2024
2 parents e7fd189 + 4640cdd commit a52971a
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import sys
import json
import agent
import os
from agent.ldapproxy import Ldapproxy

request = json.load(sys.stdin)

lp = Ldapproxy()
domains = lp.get_domains_list()

domain_list = request["domains"]
module_id = os.environ["AGENT_TASK_USER"].removeprefix('module/')

Expand All @@ -25,6 +29,13 @@ except Exception as ex:
previous_domains = rdb.hget(f'cluster/module_domains', module_id) or ""

rdb = agent.redis_connect(privileged=True)
# we test if the domain_list is included in the list of domains
is_included = set(domain_list).issubset(set(domains))

if not is_included:
print(f"Error: the domain_list {domain_list} is not included in the list of domains {domains}", file=sys.stderr)
sys.exit(1)

rdb.hset(f'cluster/module_domains', module_id, " ".join(domain_list))

union_domains = set(domain_list) | set(previous_domains.split())
Expand Down

0 comments on commit a52971a

Please sign in to comment.