Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions sambacc/commands/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,19 @@
@setup_steps.command("nsswitch")
def _import_nsswitch(ctx: Context) -> None:
# should nsswitch validation/edit be conditional only on ads?
nss = nsswitch.NameServiceSwitchLoader("/etc/nsswitch.conf")
nss.read()
if not nss.winbind_enabled():
nss.ensure_winbind_enabled()
nss.write()
paths = ["/etc/nsswitch.conf", "/usr/etc/nsswitch.conf"]
for path in paths:
nss = nsswitch.NameServiceSwitchLoader(path)
try:
nss.read()
if not nss.winbind_enabled():
nss.ensure_winbind_enabled()
nss.write("/etc/nsswitch.conf")
return
except FileNotFoundError:
pass

raise FileNotFoundError(f"Failed to open {' or '.join(paths)}")


@setup_steps.command("smb_ctdb")
Expand Down
9 changes: 6 additions & 3 deletions sambacc/textfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ def read(self) -> None:
with open(self.path) as f:
self.readfp(f)

def write(self) -> None:
tpath = self._tmp_path(self.path)
def write(self, alternate_path: typing.Optional[str] = None) -> None:
path = self.path
if alternate_path:
path = alternate_path
tpath = self._tmp_path(path)
with open(tpath, "w") as f:
self.writefp(f)
os.rename(tpath, self.path)
os.rename(tpath, path)

def _tmp_path(self, path: str) -> str:
# for later: make this smarter
Expand Down
Loading