Skip to content

Commit

Permalink
commands: update smb.conf post- provision and join funcs
Browse files Browse the repository at this point in the history
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 <jmulligan@redhat.com>
  • Loading branch information
phlogistonjohn committed Aug 11, 2023
1 parent 3aaab86 commit c1fd3a0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions sambacc/commands/addc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
import logging
import os
import shutil
import typing

from sambacc import addc
from sambacc import samba_cmds
from sambacc import smbconf_api
from sambacc import smbconf_samba

from .cli import best_waiter, CommandBuilder, Context, Fail

Expand Down Expand Up @@ -88,6 +91,7 @@ def _prep_provision(ctx: Context) -> None:
admin_password=domconfig.admin_password,
options=ctx.instance_config.global_options(),
)
_merge_config(_provisioned, ctx.instance_config.global_options())


def _prep_join(ctx: Context) -> None:
Expand All @@ -105,6 +109,27 @@ def _prep_join(ctx: Context) -> None:
admin_password=domconfig.admin_password,
options=ctx.instance_config.global_options(),
)
_merge_config(_provisioned, ctx.instance_config.global_options())


def _merge_config(
smb_conf_path: str,
options: typing.Optional[typing.Iterable[tuple[str, str]]] = None,
) -> None:
if not options:
return
txt_conf = smbconf_samba.SMBConf.from_file(smb_conf_path)
tmp_conf = smbconf_api.SimpleConfigStore()
tmp_conf.import_smbconf(txt_conf)
global_section = dict(tmp_conf["global"])
global_section.update(options)
tmp_conf["global"] = list(global_section.items())
try:
os.rename(smb_conf_path, f"{smb_conf_path}.orig")
except OSError:
pass
with open(smb_conf_path, "w") as fh:
smbconf_api.write_store_as_smb_conf(fh, tmp_conf)


def _prep_wait_on_domain(ctx: Context) -> None:
Expand Down

0 comments on commit c1fd3a0

Please sign in to comment.