Fix missing pre-login Unix identity on installation and upgrades
This commit is contained in:
@@ -24,6 +24,7 @@ fi
|
|||||||
if [[ -n $backup ]]; then install -m 0600 "$backup" "$conf"; fi
|
if [[ -n $backup ]]; then install -m 0600 "$backup" "$conf"; fi
|
||||||
[[ -f $conf ]] || { echo "Missing $conf after original installation" >&2; exit 1; }
|
[[ -f $conf ]] || { echo "Missing $conf after original installation" >&2; exit 1; }
|
||||||
chmod 0600 "$conf"
|
chmod 0600 "$conf"
|
||||||
|
python3 packaging/ensure-default-identity.py "$conf"
|
||||||
install -D -m 0755 packaging/mars-ipxpkt-net "$prefix/libexec/mars-ipxpkt-net"
|
install -D -m 0755 packaging/mars-ipxpkt-net "$prefix/libexec/mars-ipxpkt-net"
|
||||||
install -D -m 0755 publish-mtcp.sh "$prefix/sbin/mars-publish-mtcp"
|
install -D -m 0755 publish-mtcp.sh "$prefix/sbin/mars-publish-mtcp"
|
||||||
install -D -m 0755 publish-winclient.sh "$prefix/sbin/mars-publish-winclient"
|
install -D -m 0755 publish-winclient.sh "$prefix/sbin/mars-publish-winclient"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ with tempfile.TemporaryDirectory(prefix='mars-deb-') as tmp:
|
|||||||
def copy(src,dst,mode=0o644):
|
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)
|
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)
|
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('packaging/mars-ipxpkt-net','usr/local/libexec/mars-ipxpkt-net',0o755)
|
||||||
copy('dos-compat-export.py','usr/local/sbin/mars-dos-export',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)
|
copy('install-driver-packages.py','usr/local/libexec/mars-install-drivers',0o755)
|
||||||
@@ -48,6 +49,7 @@ if [ "$1" = configure ]; then
|
|||||||
umask 077
|
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
|
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
|
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
|
if [ ! -s /var/lib/mars_nwe/bindery/nwobj.pag ]; then
|
||||||
install -d -m 0700 /var/lib/mars_nwe/bindery
|
install -d -m 0700 /var/lib/mars_nwe/bindery
|
||||||
touch /var/lib/mars_nwe/bindery/.mars-fixed-width-v1
|
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])
|
||||||
20
tests/test_default_identity.py
Normal file
20
tests/test_default_identity.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import importlib.util, pathlib, tempfile, unittest, pwd
|
||||||
|
spec = importlib.util.spec_from_file_location('identity', pathlib.Path(__file__).resolve().parents[1] / 'packaging/ensure-default-identity.py')
|
||||||
|
m = importlib.util.module_from_spec(spec); spec.loader.exec_module(m)
|
||||||
|
class IdentityTest(unittest.TestCase):
|
||||||
|
def test_missing_and_idempotent(self):
|
||||||
|
with tempfile.TemporaryDirectory() as d:
|
||||||
|
p=pathlib.Path(d)/'nwserv.conf'; p.write_text('2 MARS\n')
|
||||||
|
self.assertTrue(m.repair(p)); content=p.read_text()
|
||||||
|
self.assertIn(f'11 {pwd.getpwnam("nobody").pw_uid}\n', content)
|
||||||
|
self.assertFalse(m.repair(p)); self.assertEqual(p.read_text(), content)
|
||||||
|
self.assertEqual(len(list(pathlib.Path(d).glob('*.pre-*'))), 1)
|
||||||
|
def test_preserve_existing(self):
|
||||||
|
with tempfile.TemporaryDirectory() as d:
|
||||||
|
p=pathlib.Path(d)/'nwserv.conf'; p.write_text('10 123\n11 456\n')
|
||||||
|
self.assertFalse(m.repair(p)); self.assertEqual(p.read_text(),'10 123\n11 456\n')
|
||||||
|
def test_partial(self):
|
||||||
|
with tempfile.TemporaryDirectory() as d:
|
||||||
|
p=pathlib.Path(d)/'nwserv.conf'; p.write_text('# 11 0\n10 123')
|
||||||
|
m.repair(p); self.assertIn('10 123\n',p.read_text()); self.assertIn('\n11 ',p.read_text())
|
||||||
|
if __name__ == '__main__': unittest.main()
|
||||||
Reference in New Issue
Block a user