Permalink
Browse files

[feature] add possibility to disable exit (Closes #156)

Added disable_exit flag. If set to 1, it will disable user exit.
This could be useful when lshell is spawned from another
none-restricted shell (e.g. bash)
  • Loading branch information...
Ignace Mouzannar Ignace Mouzannar
Ignace Mouzannar authored and Ignace Mouzannar committed Sep 19, 2016
1 parent d11bcbe commit f693b98c373959abd12b103058ab9571c73ed938
Showing with 28 additions and 1 deletion.
  1. +4 −0 etc/lshell.conf
  2. +1 −0 lshell/checkconfig.py
  3. +2 −1 lshell/shellcmd.py
  4. +1 −0 lshell/variables.py
  5. +4 −0 man/lshell.1
  6. +16 −0 test/test_functional.py
View
@@ -137,3 +137,7 @@ strict : 0
## define the script to run at user login
#login_script : "/path/to/myscript.sh"
+
+## disable user exit, this could be useful when lshell is spawned from another
+## none-restricted shell (e.g. bash)
+#disable_exit : 0
View
@@ -472,6 +472,7 @@ def get_config_user(self):
'history_size',
'login_script',
'winscp',
+ 'disable_exit',
'quiet']:
try:
if len(self.conf_raw[item]) == 0:
View
@@ -105,7 +105,8 @@ def __getattr__(self, attr):
self.log.error('Exited')
if self.g_cmd == 'EOF':
self.stdout.write('\n')
- sys.exit(0)
+ if self.conf['disable_exit'] != 1:
+ sys.exit(0)
# check that commands/chars present in line are allowed/secure
ret_check_secure, self.conf = sec.check_secure(
View
@@ -87,6 +87,7 @@
'path_noexec=',
'allowed_shell_escape=',
'winscp=',
+ 'disable_exit=',
'include_dir=']
builtins_list = ['cd',
View
@@ -170,6 +170,10 @@ in the \'allowed\' variable.
.I allowed_cmd_path
a list of path; all executable files inside these path will be allowed
.TP
+.I disable_exit
+disable user exit, this could be useful when lshell is spawned from another
+none-restricted shell (e.g. bash)
+.TP
.I env_path
update the environment variable $PATH of the user (optional)
.TP
View
@@ -429,5 +429,21 @@ def test_30_help_cmd(self):
result = self.child.before.decode('utf8').split('\n', 1)[1]
self.assertEqual(expected, result)
+ def test_31_disable_exit(self):
+ """ F31 | test disabled exit command """
+ self.child = pexpect.spawn('%s/bin/lshell '
+ '--config %s/etc/lshell.conf '
+ '--disable_exit 1 '
+ % (TOPDIR, TOPDIR))
+ self.child.expect('%s:~\$' % self.user)
+
+ expected = u''
+ self.child.sendline('exit')
+ self.child.expect('%s:~\$' % self.user)
+
+ result = self.child.before.decode('utf8').split('\n')[1]
+
+ self.assertIn(expected, result)
+
if __name__ == '__main__':
unittest.main()

0 comments on commit f693b98

Please sign in to comment.