ghantoos / lshell

lshell is a shell coded in Python, that lets you restrict a user's environment to limited sets of commands, choose to enable/disable any command over SSH (e.g. SCP, SFTP, rsync, etc.), log user's commands, implement timing restriction, and more.
GNU General Public License v3.0
436 stars 112 forks source link

&& and aliases doesn't work #79

Closed xlr-8 closed 10 years ago

xlr-8 commented 10 years ago

Aware of this issue: https://github.com/ghantoos/lshell/issues/67

I believe this one is similar but not implying builtins such as cd but aliases instead.

lshell --version lshell-0.9.16 - Limited Shell

su - lshell Password: You are in a limited shell. Type '?' or 'help' to get the list of allowed commands lshell:~$ ll total 0 -rw-r--r-- 1 lshell lshell 0 Jun 28 00:59 test1 -rw-r--r-- 1 lshell lshell 0 Jun 28 00:59 test2 lshell:~$ echo "OK" && ls -l OK total 0 -rw-r--r-- 1 lshell lshell 0 Jun 28 00:59 test1 -rw-r--r-- 1 lshell lshell 0 Jun 28 00:59 test2 lshell:~$ echo "OK" && ll OK sh: ll: command not found

xlr-8 commented 10 years ago

I believe the problem comes from the get_aliases function.

According to my tests:

lshell:~$ ll             
Get_aliases: line-in => ll
Get_aliases: line-out => ls -l
CMD: "ls -l"
total 4
-rwxr-xr-x 1 lshell lshell 9 Jun 28 01:40 export-var.txt
-rw-r--r-- 1 lshell lshell 0 Jun 28 00:59 test1
-rw-r--r-- 1 lshell lshell 0 Jun 28 00:59 test2
lshell:~$ 
lshell:~$ echo "OK" && ll
Get_aliases: line-in => echo "OK" && ll
Get_aliases: line-out => echo "OK" && ll
CMD: "echo "OK" && ll"
OK
sh: ll: command not found

I'm thinking of a patch where we could check for aliases at every 'beginning' (after ||, &&, ;, etc), however I feel like it doesn't make much sens now, and while the project is getting bigger a more serious work should be done on a proper lexer/parser; otherwise issues like this will keep on being reported.

What do you think?

xlr-8 commented 10 years ago

Actually I believe the problem, is indeed related to https://github.com/ghantoos/lshell/issues/67

As every implemented command or aliases seem to fail:

lshell:~$ echo "test" && history
test
lshell:~$ echo "test" && export VAR='OK' 
test
lshell:~$ echo $VAR
lshell:~$ export VAR='OK' && echo "test"   
lshell:~$ echo $VAR
OK
ghantoos commented 10 years ago

@xlr-8 it you could check that everything works fine now, it would be great! :)

xlr-8 commented 9 years ago

Will do

xlr-8 commented 9 years ago

Hey, got couple minutes to try it out. Problem still occurs to me - and as said more general than only aliases; builtins also impacted:

Used the same test as before:

lshell:~$ help
cd  clear  echo  exit  export  help  history  ll  lpath  ls  lsudo  sleep
lshell:~$ echo "OK" && ll # alias
OK
sh: ll: command not found
lshell:~$ echo "test" && history # builtin
test
lshell:~$ echo "test" && export VAR='OK' # builtin
test
lshell:~$ echo $VAR
lshell:~$ export VAR='OK' && echo "test"  # builtin
lshell:~$ echo $VAR
OK
lshell:~$ 

I double checked and have your latest commit, sorry! :(

ghantoos commented 9 years ago

Just tested, and it works fine over here. It looks to me that you have lshell installed in your system's python libraries?

Can you test by adding the current directory in the PYTHONPATH?

git clone git://github.com/ghantoos/lshell.git
cd lshell
export PYTHONPATH=$PWD/
./bin/lshell

Thanks!

xlr-8 commented 9 years ago

Oops , indeed the other version messing with this one! Sorry. Does work fine for aliases, still the issue for builtins, but think we can leave this issue closed! Thanks

ghantoos commented 9 years ago

:+1: