Skip to content

Commit

Permalink
Ensure required samba directories are created (#14144)
Browse files Browse the repository at this point in the history
SCALE moved samba's passdb backend path out of the system dataset
because of some edge cases where samba processes could prevent
system dataset migration. This commit expands the list of samba-related
directories that the middleware process manages.
  • Loading branch information
anodos325 authored Aug 6, 2024
1 parent a1c894b commit d77173e
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions src/middlewared/middlewared/plugins/smb.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,35 @@ def by_rid(rid):


class SMBPath(enum.Enum):
GLOBALCONF = ('/usr/local/etc/smb4.conf', '/etc/smb4.conf', 0o755, False)
SHARECONF = ('/usr/local/etc/smb4_share.conf', '/etc/smb4_share.conf', 0o755, False)
STATEDIR = ('/var/db/system/samba4', '/var/db/system/samba4', 0o755, True)
PRIVATEDIR = ('/var/db/system/samba4/private', '/var/db/system/samba4', 0o700, True)
LEGACYSTATE = ('/root/samba', '/root/samba', 0o755, True)
LEGACYPRIVATE = ('/root/samba/private', '/root/samba/private', 0o700, True)
MSG_SOCK = ('/var/db/system/samba4/private/msg.sock', '/var/db/system/samba4/msg.sock', 0o700, False)
RUNDIR = ('/var/run/samba4', '/var/run/samba', 0o755, True)
LOCKDIR = ('/var/run/samba4', '/var/run/samba-lock', 0o755, True)
LOGDIR = ('/var/log/samba4', '/var/log/samba4', 0o755, True)
IPCSHARE = ('/var/tmp', '/tmp', 0o1777, True)
WINBINDD_PRIVILEGED = ('/var/db/system/samba4/winbindd_privileged', '/var/db/system/samba4/winbindd_privileged', 0o750, True)
GLOBALCONF = ('/usr/local/etc/smb4.conf', 0o755, False)
SHARECONF = ('/usr/local/etc/smb4_share.conf', 0o755, False)
STATEDIR = ('/var/db/system/samba4', 0o755, True)
PRIVATEDIR = ('/var/db/system/samba4/private', 0o700, True)
LEGACYSTATE = ('/root/samba', 0o755, True)
LEGACYPRIVATE = ('/root/samba/private', 0o700, True)
MSG_SOCK = ('/var/db/system/samba4/private/msg.sock', 0o700, False)
RUNDIR = ('/var/run/samba4', True)
CACHEDIR = ('/var/run/samba-cache', 0o755, True)
PASSDB_DIR = ('/var/run/samba-cache/private', 0o700, True)
LOCKDIR = ('/var/run/samba4', 0o755, True)
LOGDIR = ('/var/log/samba4', 0o755, True)
IPCSHARE = ('/var/tmp', 0o1777, True)
WINBINDD_PRIVILEGED = ('/var/db/system/samba4/winbindd_privileged', 0o750, True)

@property
def path(self):
return self.value[0]

def platform(self):
return self.value[1] if osc.IS_LINUX else self.value[0]
return self.value[0]

@property
def mode(self):
return self.value[2]
return self.value[1]

@property
def is_dir(self):
return self.value[3]
return self.value[2]


class SMBSharePreset(enum.Enum):
Expand Down Expand Up @@ -375,12 +383,7 @@ async def setup_directories(self):
await self.middleware.call('etc.generate', 'smb')

for p in SMBPath:
if p == SMBPath.STATEDIR:
path = await self.middleware.call("smb.getparm", "state directory", "global")
elif p == SMBPath.PRIVATEDIR:
path = await self.middleware.call("smb.getparm", "privatedir", "global")
else:
path = p.platform()
path = p.path

try:
if not await self.middleware.call('filesystem.acl_is_trivial', path):
Expand All @@ -394,10 +397,10 @@ async def setup_directories(self):
pass

if not os.path.exists(path):
if p.is_dir():
os.mkdir(path, p.mode())
if p.is_dir:
os.mkdir(path, p.mode)
else:
os.chmod(path, p.mode())
os.chmod(path, p.mode)

@private
async def import_conf_to_registry(self):
Expand Down

0 comments on commit d77173e

Please sign in to comment.