Skip to content

Commit 06ccd8e

Browse files
phlogistonjohnmergify[bot]
authored andcommitted
commands: update smb.conf post- provision and join funcs
Global options passed to the samba-tool commands do no persist in the smb.conf generated by samba-tool domain {provision,join} commands. In order to get custom global configurations into the AD DC we can instead use the smbconf configuration reader to read the current smb.conf and merge in any options defined in the sambacc configuration. Signed-off-by: John Mulligan <[email protected]>
1 parent 3a70510 commit 06ccd8e

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

sambacc/commands/addc.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
import logging
2020
import os
2121
import shutil
22+
import typing
2223

2324
from sambacc import addc
2425
from sambacc import samba_cmds
26+
from sambacc import smbconf_api
27+
from sambacc import smbconf_samba
2528

2629
from .cli import best_waiter, CommandBuilder, Context, Fail
2730

@@ -88,6 +91,7 @@ def _prep_provision(ctx: Context) -> None:
8891
admin_password=domconfig.admin_password,
8992
options=ctx.instance_config.global_options(),
9093
)
94+
_merge_config(_provisioned, ctx.instance_config.global_options())
9195

9296

9397
def _prep_join(ctx: Context) -> None:
@@ -105,6 +109,27 @@ def _prep_join(ctx: Context) -> None:
105109
admin_password=domconfig.admin_password,
106110
options=ctx.instance_config.global_options(),
107111
)
112+
_merge_config(_provisioned, ctx.instance_config.global_options())
113+
114+
115+
def _merge_config(
116+
smb_conf_path: str,
117+
options: typing.Optional[typing.Iterable[tuple[str, str]]] = None,
118+
) -> None:
119+
if not options:
120+
return
121+
txt_conf = smbconf_samba.SMBConf.from_file(smb_conf_path)
122+
tmp_conf = smbconf_api.SimpleConfigStore()
123+
tmp_conf.import_smbconf(txt_conf)
124+
global_section = dict(tmp_conf["global"])
125+
global_section.update(options)
126+
tmp_conf["global"] = list(global_section.items())
127+
try:
128+
os.rename(smb_conf_path, f"{smb_conf_path}.orig")
129+
except OSError:
130+
pass
131+
with open(smb_conf_path, "w") as fh:
132+
smbconf_api.write_store_as_smb_conf(fh, tmp_conf)
108133

109134

110135
def _prep_wait_on_domain(ctx: Context) -> None:

0 commit comments

Comments
 (0)