From abbf258cfaf5065fd9895ca2f5103591ff14c859 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 27 Feb 2017 01:28:58 +0530 Subject: [PATCH] Linux installer: Check that the umask is suitable before running the installer. This prevents system breakage because of bugs in xdg-mime when the user has set their umask to prevent reading of files by other users on the system. See https://www.mobileread.com/forums/showthread.php?t=277803 --- setup/linux-installer.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/setup/linux-installer.py b/setup/linux-installer.py index 35ee1d39dc..4b14646438 100644 --- a/setup/linux-installer.py +++ b/setup/linux-installer.py @@ -8,7 +8,7 @@ __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' import sys, os, shutil, subprocess, re, platform, signal, tempfile, hashlib, errno -import ssl, socket +import ssl, socket, stat from contextlib import closing is64bit = platform.architecture()[0] == '64bit' @@ -691,7 +691,38 @@ def run_installer(install_dir, isolated, bin_dir, share_dir): return 0 -def main(install_dir=None, isolated=False, bin_dir=None, share_dir=None): +def check_umask(): + # A bad umask can cause system breakage because of bugs in xdg-mime + # See https://www.mobileread.com/forums/showthread.php?t=277803 + mask = os.umask(18) # 18 = 022 + os.umask(mask) + forbid_user_read = mask & stat.S_IRUSR + forbid_group_read = mask & stat.S_IRGRP + forbid_other_read = mask & stat.S_IROTH + if forbid_user_read or forbid_group_read or forbid_other_read: + prints( + 'WARNING: Your current umask disallows reading of files by some users,' + ' this can cause system breakage when running the installer because' + ' of bugs in common system utilities.' + ) + while True: + q = raw_input('Should the installer (f)ix the umask, (i)gnore it or (a)bort [f/i/a Default is abort]: ') or 'a' + if q in 'f i a'.split(): + break + prints('Response', q, 'not understood') + if q == 'f': + mask = mask & ~stat.S_IRUSR & ~stat.S_IRGRP & ~stat.S_IROTH + os.umask(mask) + prints('umask changed to: {:03o}'.format(mask)) + elif q == 'i': + prints('Ignoring bad umask and proceeding anyway, you have been warned!') + else: + raise SystemExit('The system umask is unsuitable, aborting') + + +def main(install_dir=None, isolated=False, bin_dir=None, share_dir=None, ignore_umask=False): + if not ignore_umask: + check_umask() run_installer(install_dir, isolated, bin_dir, share_dir)