Fix missing pre-login Unix identity on installation and upgrades
This commit is contained in:
@@ -10,6 +10,7 @@ with tempfile.TemporaryDirectory(prefix='mars-deb-') as tmp:
|
||||
def copy(src,dst,mode=0o644):
|
||||
target=stage/dst;target.parent.mkdir(parents=True,exist_ok=True);shutil.copy2(root/src,target);target.chmod(mode)
|
||||
for name in ('mars_vme','mars-pcapd','mars-print'):copy('build/'+name,'usr/local/sbin/'+name,0o755)
|
||||
copy('packaging/ensure-default-identity.py','usr/local/libexec/mars-ensure-default-identity',0o755)
|
||||
copy('packaging/mars-ipxpkt-net','usr/local/libexec/mars-ipxpkt-net',0o755)
|
||||
copy('dos-compat-export.py','usr/local/sbin/mars-dos-export',0o755)
|
||||
copy('install-driver-packages.py','usr/local/libexec/mars-install-drivers',0o755)
|
||||
@@ -48,6 +49,7 @@ if [ "$1" = configure ]; then
|
||||
umask 077
|
||||
printf '2 MARS\\n3 0x12345678 1\\n1 SYS /var/mars_nwe/SYS ikO\\n6 2\\n5 0\\n200 0\\n' > /usr/local/etc/mars_nwe/nwserv.conf
|
||||
fi
|
||||
python3 /usr/local/libexec/mars-ensure-default-identity /usr/local/etc/mars_nwe/nwserv.conf
|
||||
if [ ! -s /var/lib/mars_nwe/bindery/nwobj.pag ]; then
|
||||
install -d -m 0700 /var/lib/mars_nwe/bindery
|
||||
touch /var/lib/mars_nwe/bindery/.mars-fixed-width-v1
|
||||
|
||||
33
packaging/ensure-default-identity.py
Normal file
33
packaging/ensure-default-identity.py
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Fill absent pre-login Unix identity entries; preserve explicit administrator choices."""
|
||||
import pathlib, pwd, re, shutil, sys, tempfile, os, time
|
||||
|
||||
def repair(path):
|
||||
path = pathlib.Path(path)
|
||||
text = path.read_text()
|
||||
present = set(re.findall(r'^\s*(10|11)\s+', text, re.M))
|
||||
account = pwd.getpwnam('nobody')
|
||||
values = {'10': account.pw_gid, '11': account.pw_uid}
|
||||
if any(v <= 0 for v in values.values()):
|
||||
raise ValueError('nobody must have non-root UID and GID')
|
||||
addition = ''.join(f'{key} {value}\n' for key, value in values.items() if key not in present)
|
||||
if not addition:
|
||||
return False
|
||||
backup = str(path) + '.pre-default-identity-' + str(time.time_ns())
|
||||
shutil.copy2(path, backup)
|
||||
os.chmod(backup, 0o600)
|
||||
fd, temp = tempfile.mkstemp(dir=path.parent)
|
||||
try:
|
||||
with os.fdopen(fd, 'w') as stream:
|
||||
stream.write(text + ('\n' if text and not text.endswith('\n') else '') + '# Unprivileged identity before NetWare login\n' + addition)
|
||||
st = path.stat()
|
||||
os.chown(temp, st.st_uid, st.st_gid)
|
||||
os.chmod(temp, 0o600)
|
||||
os.replace(temp, path)
|
||||
finally:
|
||||
if os.path.exists(temp): os.unlink(temp)
|
||||
print('Added missing default identity entries; backup: ' + backup)
|
||||
return True
|
||||
|
||||
if __name__ == '__main__':
|
||||
repair(sys.argv[1])
|
||||
Reference in New Issue
Block a user