Skip to content

Commit

Permalink
[bug] can't allow access to "/" (Closes #99)
Browse files Browse the repository at this point in the history
When user set path to "/", the validation regex would become "//.*".
This would then fail to allow the user accessing "/".
  • Loading branch information
Ignace Mouzannar authored and Ignace Mouzannar committed May 14, 2015
1 parent e7191fc commit 2645042
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lshell/checkconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ def get_config_sub(self, section):
for path in eval(stuff):
for item in glob.glob(path):
liste[0] += os.path.realpath(item) + '/.*|'
# remove double slashes
liste[0] = liste[0].replace("//","/")
self.conf_raw.update({key:str(liste)})
elif stuff and type(eval(stuff)) is list:
self.conf_raw.update({key:stuff})
Expand All @@ -412,6 +414,8 @@ def get_config_sub(self, section):
for path in self.myeval(value, 'path'):
for item in glob.glob(path):
liste[0] += os.path.realpath(item) + '/.*|'
# remove double slashes
liste[0] = liste[0].replace("//","/")
self.conf_raw.update({key:str(liste)})
else:
self.conf_raw.update(dict([item]))
Expand Down
15 changes: 15 additions & 0 deletions test/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,20 @@ def test_17_exitcode_without_separator(self):
result = self.child.before.split('\n')[1].strip()
self.assertEqual(expected, result)

def test_18_allow_slash(self):
""" 18 - user should able to allow / access minus some directory (e.g. /var) """
self.child = pexpect.spawn('%s/bin/lshell '
'--config %s/etc/lshell.conf --path "[\'/\'] - [\'/var\']"'
% (TOPDIR, TOPDIR))
self.child.expect('%s:~\$' % self.user)

expected = "*** forbidden path: /var/"
self.child.sendline('cd /')
self.child.expect('%s:/\$' % self.user)
self.child.sendline('cd var')
self.child.expect('%s:/\$' % self.user)
result = self.child.before.split('\n')[1].strip()
self.assertEqual(expected, result)

if __name__ == '__main__':
unittest.main()

0 comments on commit 2645042

Please sign in to comment.