3 # Copyright (C) Andrew Bartlett 2015, 2018
4 # Copyright (C) Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
5 # Copyright (C) Joe Guo <joeg@catalyst.net.nz>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from samba.netcmd import CommandError
23 def get_partition_maps(samdb):
24 """Generate dictionaries mapping short partition names to the
26 base_dn = samdb.domain_dn()
29 "CONFIGURATION": str(samdb.get_config_basedn()),
30 "SCHEMA": "CN=Schema,%s" % samdb.get_config_basedn(),
31 "DNSDOMAIN": "DC=DomainDnsZones,%s" % base_dn,
32 "DNSFOREST": "DC=ForestDnsZones,%s" % base_dn
36 for s, l in short_to_long.items():
39 return short_to_long, long_to_short
42 def get_partition(samdb, part):
43 # Allow people to say "--partition=DOMAIN" rather than
44 # "--partition=DC=blah,DC=..."
46 short_partitions, long_partitions = get_partition_maps(samdb)
47 part = short_partitions.get(part.upper(), part)
48 if part not in long_partitions:
49 raise CommandError("unknown partition %s" % part)