/usr/share/pyshared/lshell/utils.py is in lshell 0.9.16-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #
# Limited command Shell (lshell)
#
# Copyright (C) 2008-2013 Ignace Mouzannar (ghantoos) <ghantoos@ghantoos.org>
#
# This file is part of lshell
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import re
try:
from os import urandom
except:
def urandom(n):
try:
_urandomfd = open("/dev/urandom", 'r')
except Exception,e:
print e
raise NotImplementedError("/dev/urandom (or equivalent) not found")
bytes = ""
while len(bytes) < n:
bytes += _urandomfd.read(n - len(bytes))
_urandomfd.close()
return bytes
def get_aliases(line, aliases):
""" Replace all configured aliases in the line
"""
for item in aliases.keys():
reg1 = '(^|; |;)%s([ ;&\|]+|$)(.*)' % item
reg2 = '(^|; |;)%s([ ;&\|]+|$)' % item
# in case aliase bigin with the same command
# (this is until i find a proper regex solution..)
aliaskey = urandom(10)
while re.findall(reg1, line):
(before, after, rest) = re.findall(reg1, line)[0]
linesave = line
cmd = "%s %s" % (item, rest)
line = re.sub(reg2, "%s%s%s" % (before, aliaskey, \
after), line, 1)
# if line does not change after sub, exit loop
if linesave == line:
break
# replace the key by the actual alias
line = line.replace(aliaskey, aliases[item])
for char in [';']:
# remove all remaining double char
line = line.replace('%s%s' %(char, char), '%s' %char)
return line
|