mirror of
https://github.com/openSUSE/osc.git
synced 2025-02-21 17:52:14 +01:00
Mute oscrc permissions warning when there's no password set
This commit is contained in:
parent
d72f393f4d
commit
097ca0f445
35
osc/conf.py
35
osc/conf.py
@ -1879,18 +1879,6 @@ def get_config(override_conffile=None,
|
|||||||
if not os.path.exists(conffile):
|
if not os.path.exists(conffile):
|
||||||
raise oscerr.NoConfigfile(conffile, account_not_configured_text % conffile)
|
raise oscerr.NoConfigfile(conffile, account_not_configured_text % conffile)
|
||||||
|
|
||||||
# make sure oscrc is not world readable, it may contain a password
|
|
||||||
conffile_stat = os.stat(conffile)
|
|
||||||
# applying 0o7777 mask because we want to ignore the file type bits
|
|
||||||
if conffile_stat.st_mode & 0o7777 != 0o600:
|
|
||||||
try:
|
|
||||||
os.chmod(conffile, 0o600)
|
|
||||||
except OSError as e:
|
|
||||||
if e.errno in (errno.EROFS, errno.EPERM):
|
|
||||||
print(f"Warning: Configuration file '{conffile}' may have insecure file permissions.", file=sys.stderr)
|
|
||||||
else:
|
|
||||||
raise e
|
|
||||||
|
|
||||||
cp = get_configParser(conffile)
|
cp = get_configParser(conffile)
|
||||||
|
|
||||||
if not cp.has_section("general"):
|
if not cp.has_section("general"):
|
||||||
@ -1900,6 +1888,29 @@ def get_config(override_conffile=None,
|
|||||||
msg += new_conf_template % defaults
|
msg += new_conf_template % defaults
|
||||||
raise oscerr.ConfigError(msg, conffile)
|
raise oscerr.ConfigError(msg, conffile)
|
||||||
|
|
||||||
|
has_password = False
|
||||||
|
for section in cp.sections():
|
||||||
|
keys = ["pass", "passx"]
|
||||||
|
for key in keys:
|
||||||
|
value = cp.get(section, key, fallback="").strip()
|
||||||
|
if value:
|
||||||
|
has_password = True
|
||||||
|
break
|
||||||
|
|
||||||
|
# make sure oscrc is not world readable, it may contain a password
|
||||||
|
conffile_stat = os.stat(conffile)
|
||||||
|
# applying 0o7777 mask because we want to ignore the file type bits
|
||||||
|
if conffile_stat.st_mode & 0o7777 != 0o600:
|
||||||
|
try:
|
||||||
|
os.chmod(conffile, 0o600)
|
||||||
|
except OSError as e:
|
||||||
|
if e.errno in (errno.EROFS, errno.EPERM):
|
||||||
|
if has_password:
|
||||||
|
print(f"Warning: Configuration file '{conffile}' may have insecure file permissions.", file=sys.stderr)
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
global config
|
global config
|
||||||
|
|
||||||
config = Options()
|
config = Options()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user