init set config.py perms to 0600, otherwise warn user if config.py is not

Since config.py contains passwords in it, it should be protected as much as
possible.  At the very least, the file permissions should be 0600 to
restrict access to user that actually edits and runs 'fdroid' commands.
This commit is contained in:
Hans-Christoph Steiner 2013-11-05 17:27:08 -05:00
parent 749739ec72
commit 5f06fba591
2 changed files with 5 additions and 0 deletions

View file

@ -19,6 +19,7 @@
import glob, os, sys, re import glob, os, sys, re
import shutil import shutil
import stat
import subprocess import subprocess
import time import time
import operator import operator
@ -43,6 +44,9 @@ def read_config(opts, config_file='config.py'):
if not os.path.isfile(config_file): if not os.path.isfile(config_file):
print "Missing config file - is this a repo directory?" print "Missing config file - is this a repo directory?"
sys.exit(2) sys.exit(2)
st = os.stat(config_file)
if st.st_mode & stat.S_IRWXG or st.st_mode & stat.S_IRWXO:
print("WARNING: unsafe permissions on config.py (should be 0600)!")
options = opts options = opts
if not hasattr(options, 'verbose'): if not hasattr(options, 'verbose'):

View file

@ -109,6 +109,7 @@ def main():
os.mkdir('repo') os.mkdir('repo')
shutil.copy(os.path.join(examplesdir, 'fdroid-icon.png'), repodir) shutil.copy(os.path.join(examplesdir, 'fdroid-icon.png'), repodir)
shutil.copyfile(os.path.join(examplesdir, 'config.sample.py'), 'config.py') shutil.copyfile(os.path.join(examplesdir, 'config.sample.py'), 'config.py')
os.chmod('config.py', 0o0600)
else: else:
print('Looks like this is already an F-Droid repo, cowardly refusing to overwrite it...') print('Looks like this is already an F-Droid repo, cowardly refusing to overwrite it...')
sys.exit() sys.exit()