summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2023-05-10 15:46:55 +1200
committerAndrew Bartlett <abartlet@samba.org>2023-05-16 23:29:32 +0000
commit5d5fd0129ac19258d15a452756f0d3647dbe1e34 (patch)
tree40a3043abbb01b064580552fe010404b3790731f /python
parente5c3e076c8f85cda11bf0be29a6f26a852c5a343 (diff)
downloadsamba-5d5fd0129ac19258d15a452756f0d3647dbe1e34.tar.gz
python: Add function to get the functional level as a python intger from smb.conf
The lp.get() returns the normalised string from the enum handler Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Diffstat (limited to 'python')
-rw-r--r--python/samba/functional_level.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/python/samba/functional_level.py b/python/samba/functional_level.py
index 1cb09ce1d79..4c1142273b0 100644
--- a/python/samba/functional_level.py
+++ b/python/samba/functional_level.py
@@ -60,3 +60,24 @@ def level_to_string(level):
DS_DOMAIN_FUNCTION_2016: "2016",
}
return strings.get(level, "higher than 2016")
+
+def dc_level_from_lp(lp):
+ """Return the ad dc functional level as an integer from a LoadParm"""
+
+ # I don't like the RuntimeError here, but these "can't happen"
+ # except by a developer stuffup.
+
+ smb_conf_dc_functional_level = lp.get('ad dc functional level')
+ if smb_conf_dc_functional_level is None:
+ # This shouldn't be possible, except if the default option
+ # value is not in the loadparm enum table
+ raise RuntimeError(f"'ad dc functional level' in smb.conf unrecognised!")
+
+ try:
+ return string_to_level(smb_conf_dc_functional_level)
+ except KeyError:
+ # This shouldn't be possible at all, unless the table in
+ # python/samba/functional_level.py is not a superset of that
+ # in lib/param/param_table.c
+ raise RuntimeError(f"'ad dc functional level = {smb_conf_dc_functional_level}'"
+ " in smb.conf is not valid!")