Skip to content

Commit 9fe18da

Browse files
SQUASH – add file perm checks
1 parent 6250eac commit 9fe18da

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pylib/cqlshlib/cqlshmain.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,21 @@ def resolve_cql_history_file():
112112
return default_cql_history
113113

114114

115+
def check_file_perms(filepath):
116+
""" Check file permissions (not readable by group or others) """
117+
assert os.path.exists(filepath), "File %s does not exist" % filepath
118+
119+
try:
120+
file_stat = os.stat(filepath)
121+
mode = file_stat.st_mode
122+
is_group_readable = bool(mode & 0o040)
123+
is_world_readable = bool(mode & 0o004)
124+
125+
if is_world_readable or is_group_readable:
126+
print('Warning: file {0} has unsafe permissions. You should: chmod 600 {0}'.format(filepath))
127+
except (OSError, IOError):
128+
print('Warning: unable to check for unsafe permissions on file %s' % (filepath))
129+
115130
HISTORY = resolve_cql_history_file()
116131
HISTORY_DIR = os.path.dirname(HISTORY)
117132

@@ -2266,6 +2281,9 @@ def main(cmdline, pkgpath):
22662281
else:
22672282
os.rename(old_config_file, config_file)
22682283

2284+
check_file_perms(config_file)
2285+
check_file_perms(HISTORY)
2286+
22692287
(options, hostname, port) = read_options(cmdline, parser, config_file, cql_dir)
22702288

22712289
docspath = get_docspath(pkgpath)

0 commit comments

Comments
 (0)