Your IP : 172.28.240.42


Current Path : /usr/lib/pymodules/python2.7/
Upload File :
Current File : //usr/lib/pymodules/python2.7/lshell.pyc


WLc@sdZddlZddlZddlZddlZddlmZmZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZdZdZdddgZejd	krejZnd
ZedZdZd
ZdeZdZdZdejefdYZdfdYZdefdYZ dZ!dZ"e#dkre"ndS(s'lshell restricts a user's shell environment to limited sets of commands
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 
iN(tgetpasstgetusers3Ignace Mouzannar (ghantoos) <ghantoos@ghantoos.org>s0.9.14tallowedt	forbiddentwarning_counters/usrts/etc/lshell.confs	.lhistorys.lshell_locksUsage: lshell [OPTIONS]
  --config <file> : Config file location (default %s)
  --log    <dir>  : Log files directory
  -h, --help      : Show this help message
  --version       : Show version
s-Limited Shell (lshell) limited help.
Cheers.
sRYou are in a limited shell.
Type '?' or 'help' to get the list of allowed commandstShellCmdcBseZdZddddddZdZdZdZdZdZ	dZ
dddZdd	Zddd
Z
dZddZd
ZdZdZdZdZdZdZdZdZdZdZRS(s Main lshell CLI class
    cCs|dkrtj|_n	||_|dkr?tj|_n	||_|dkrctj|_n	||_||_|jd|_|jddkr|j|jdn|jd|_|jj	dt
jj||jj
drA|jd|_|jjdt|_|jjdtjd	|_nt|_d
|j|_|jd|_||_||_dS(Ntlogpathttimeris+./-s	Logged intprompts%us%his%s:~$ tintro(tNonetsyststdintstdouttstderrtconftlogtmytimert
identcharsterrortcmdtCmdt__init__thas_keyt
promptbasetreplaceRtostunameR	R
tg_cmdtg_line(tselftuserconfR
RRRR((s&/usr/lib/pymodules/python2.7/lshell.pyRYs2				%	cCsh|jdkrQ|jjd|jdkrA|jjdntjdn|j|j|j	ddkrt
j||S|j|jdkrt
j||S|j|j	d	krt
jd
d|j	d|j|_t
jd
d|j	d|j|_t|j	dtkrEt|j|j	d|_n|jjd|j|jdkrx|jq;|jdkr|jq;|jdkr|jq;|jdkr|jq;|jdkr|jq;tj|jn@|jdkr;|jjd|j|jjd|jnddd|_|_|_t
j||S(s This method actually takes care of all the called method that are          not resolved (i.e not existing methods). It actually will simulate             the existance of any method    entered in the 'allowed' variable list. 
        e.g. You just have to add 'uname' in list of allowed commands in               the 'allowed' variable, and lshell will react as if you had                    added a do_uname in the ShellCmd class!
        tquittexittEOFtExiteds
itstrictiRs^~$|^~/s%s/t	home_paths ~/s %s/taliasess	CMD: "%s"tcdtlpathtlsudothistorytexportRt?thelpsINFO: unknown syntax -> "%s"s*** unknown syntax: %s
(squitsexitR#N(RR-shelpN(RRRRtwriteRR"tcheck_secureRRtobjectt__getattribute__t
check_pathtretsubtg_argttypetdicttget_aliasestinfoR(R)R*R+R,RtsystemRtwarnR(Rtattr((s&/usr/lib/pymodules/python2.7/lshell.pyt__getattr__sB	"




cCs|jddrjtjjdxF|jddjdD]'}|r<tjjd|d q<q<Wn|jddrtjjdxF|jddjdD]'}|rtjjd|d qqWnd	S(
s* lists allowed and forbidden path
        tpathis	Allowed:
t|s %s
iisDenied:
N(RRRR/tsplit(RR?((s&/usr/lib/pymodules/python2.7/lshell.pyR)s!"!cCsU|jjdrQtjjdx,|jdD]}tjjd|q0WndS(s% lists allowed sudo commands
        t
sudo_commandssAllowed sudo commands:
s - %s
N(RRRRR/(Rtcommand((s&/usr/lib/pymodules/python2.7/lshell.pyR*scCsyytj|jdWn,tk
rI|jjd|jdnXt|jdd}d}x8|jD]*}tj	j
d||f|d7}qsWWn|jjdnXdS(s$ print the commands history
        thistory_files(WARN: couldn't write history to file %s
tris%d:  %ss#** Unable to read the history file.N(treadlinetwrite_history_fileRtIOErrorRRtopent	readlinesRRR/tcritical(Rtftititem((s&/usr/lib/pymodules/python2.7/lshell.pyR+s
cCs|jjdr|jjddd}|jdr|jddjddd!\}}tjji||6qndS(s export environment variables t it=iiN(RtcountRARtenvirontupdate(Rtenvtvartvalue((s&/usr/lib/pymodules/python2.7/lshell.pyR,s
)cCst|jdkry3tjtjj|j|jtjWqtk
r\}}t	j
jd|j|fqXn'tj|jd|jtjdS(s, implementation of the "cd" command
        islshell: %s: %s
R&N(
tlenR6RtchdirR?trealpathtupdateprompttgetcwdtOSErrorRRR/R(RtErrorNumbertErrorMessage((s&/usr/lib/pymodules/python2.7/lshell.pyR(s$cCsx|jdD]t}|dkr\tjd|||f|r|sU|jdndSq||kr|s~|jdndSqWd}tjd|}xQ|D]I}||j|d	d
!j7}||j|d	jdd7}qWtjd|}x4|D],}||j|dd
!jdd7}qWtjd
|}x>|D]6}tjd|d}||j|dd
 7}qTW|dkrdS|jds|jdrdStjd|}	tj	dd|}x.|	D]&}
|
jjd}|d}t
|dkr.|}
nd}
|dkr|
d|jdkr|
r|jddkr|s|jdqn|jj
d|dSn|r|jd|jd<n||jdkr|r|r|s|jd|qn|jj
d|dSqWdS(sThis method is used to check the content on the typed command.              Its purpose is to forbid the user to user to override the lshell               command restrictions. 
        The forbidden characters are placed in the 'forbidden' variable.
        Feel free to update the list. Emptying it would be quite useless..: )

        A warining counter has been added, to kick out of lshell a user if he          is warned more than X time (X beeing the 'warning_counter' variable).
        Rt&R@s[^\%s]\%s[^\%s]tsyntaxiis\$\([^)]+[)]iiR%s
\`[^`]+[`]s\$\{[^}]+[}]s
=|\+|\?|\-s$(t`s&|\||;s\)$RROtsudoRBRCs*** forbidden sudo -> %stoversshRs*** unknown command: %s(R_R@N(RR4tfindalltcounter_updateR3tstripR0RAt
startswithR5RWRRRK(RtlineR%tsshRNt
returncodet
executionstcurlytvariabletlinestsperate_linetsplitcmdRCtcmdargs((s&/usr/lib/pymodules/python2.7/lshell.pyR0sf
 '
*


	cCs|r|}n	|j}|jddkrH|jjd||fn|jdcd8<|jddkr|jjd||f|jjdtjdnE|jjd||f|jjd|jd|jjdd	S(
sK Update the warning_counter, log and display a warning to the user
        Ris*** forbidden %s -> "%s"iis*** Kicked outs<*** You have %s warning(s) left, before getting kicked out.
s!This incident has been reported.
N(RRRRKRR"RR/(RtmessagetypeR?Rh((s&/usr/lib/pymodules/python2.7/lshell.pyReBs"		c
	CsYt|jdd}t|jddd }|jj}x|D]}yt|}WnnXt|dkrt|}ntjj|}t	j
d|r;t	jdd	|}tj
d
|dtdtjd
tj}|j|j}}	|	jdjddj}tjj|}ntjj|}
tjj|
r||
ddkr||
d7}
nt	j
||
}|rt	j
||
}nd}|s|rK|s|s|jd|
qndSqKW|sUt	j
|tjdsU|sN|jdtjtj|jd|jtjndSndS(s Check if a path is entered in the line. If so, it checks if user           are allowed to see this path. If user is not allowed, it calls                 self.counter_update. I case of completion, it only returns 0 or 1.
        R?iiitstrtints\$|\*|\?s"|'Rs`which echo` %stshellR
RROt/R&(sstrsintN(RsRRfRAtevalR7RR?t
expanduserR4RdR5t
subprocesstPopentTruetPIPER
RRJt
expandvarsRYtisdirRReR[RXRZ(
RRht
completionRitallowed_path_retdenied_path_reRNtptcintcoutttomatcht
match_allowedtmatch_denied((s&/usr/lib/pymodules/python2.7/lshell.pyR3]sP
	#"

cCs||jdkr&d|j|_n\tj|jd|rld|j|j|jddf|_nd|j|f|_dS(s/ Update prompt when changing directory
        R&s%s:~$ s%s:~%s$ is%s:%s$ N(RRR	R4RdRA(RR?((s&/usr/lib/pymodules/python2.7/lshell.pyRZs	$c
Cs|j|jr|jry,tj|jdtj|jdWnWtk
ry2t|jddj	tj|jdWqtk
rqXnXtj
|_tj|j
tj|jdnze|dk	r||_n|jdr$|jjt|jddnd}x|s1|jrQ|jjd}n|jryt|j}Wqtk
rd}qtk
r|jjdd	}qXnN|jj|j|jj|jj}t|sd}n
|d
 }|j|}|j|}|j||}q-W|j Wd|jr}|jr}ytj|jWq}t!k
ryq}Xnytj"|jdWn,tk
r|j#j$d|jdnXXdS(
sRepeatedly issue a prompt, accept input, parse an initial prefix            off the received input, and dispatch to action methods, passing them           the remainder of the line as argument.
        RDthistory_sizetws
: completeR
s
iR#RiNs(WARN: couldn't write history to file %s
(%tprelooptuse_rawinputtcompletekeyRFtread_history_fileRtset_history_lengthRHRItcloset
get_completert
old_completert
set_completertcompletetparse_and_bindRR
RR/Rstcmdqueuetpopt	raw_inputR	tEOFErrortKeyboardInterrupttflushR
RWtprecmdtonecmdtpostcmdtpostlooptImportErrorRGRR(RR
tstopRh((s&/usr/lib/pymodules/python2.7/lshell.pytcmdloopsf



$			
	


	


cCs|dkrtj}|j}tjd|dj}t|t|}tj|}tj|}|jdddkrt|jddkr|j}nt|jddkr|jdd|j	dkr|j
}n||dkrp|j|\}	}
}|	d	kr9|j}qyyt
|d
|	}Wqytk
rl|j}qyXn	|j}||||||_ny|j|SWntk
rdSXdS(sReturn the next possible completion for 'text'.
        If a command has not been entered, then complete against command list. 
        Otherwise try to call complete_<command> to get list of completions.
        is&|\||;iRORbiiRRt	complete_N(RFtget_line_buffertlstripR4RARWt
get_begidxt
get_endidxtcompletesudoRt
completechdirt	parselinetcompletedefaulttgetattrtAttributeErrort
completenamestcompletion_matchest
IndexErrorR(RttexttstatetoriglineRhtstrippedtbegidxtendidxtcompfuncRtargstfoo((s&/usr/lib/pymodules/python2.7/lshell.pyRs44 
	
cCs|jjddS(s+ This method overrides the original default method. 
        It was originally used to warn when an unknown command was entered             (e.g. *** Unknown syntax: blabla). 
        It has been implemented in the __getattr__ method.
        So it has no use here. Its output is now empty.
        RN(RR/(RRh((s&/usr/lib/pymodules/python2.7/lshell.pytdefaultscGsid|}|j}x&|jdD]}|jd|q$Wg|D]}|j|rF|d^qFS(s This method overrides the original completenames method to overload        it's output with the command available in the 'allowed' variable               This is useful when typing 'tab-tab' in the command prompt
        tdo_Ri(t	get_namesRtappendRg(RRtignoredtdotexttnamesRCta((s&/usr/lib/pymodules/python2.7/lshell.pyRs

cCs-g|jdD]}|j|r|^qS(s complete sudo command RB(RRg(RRRhRRR((s&/usr/lib/pymodules/python2.7/lshell.pyRsc
Csg}|jd}tjd|jd|}ytjj|}Wntj}nXtjj|s|j	ddd}|dkrd}ntjj|stj}qn|j
|ddkrxtj|D]|}tjjtjj||r|d}n
|d}|j
d	rV|j
d	rc|j|qcq|j|qWg|D]}	|	j
|rn|	^qnSd
Sd
S(s complete directories is^~R&RviiRROt.N(RAR4R5RRR?RYR[R~trsplitR3tlistdirtjoinRgRR(
RRRhRRttoreturnt
tocompletet	directorytinstanceR((s&/usr/lib/pymodules/python2.7/lshell.pyR#s2	!

&cCs|j|\}}}||||_|_|_|sE|jS|dkr^|j|S||_|dkr|j|Syt|d|}Wnt	k
r|j|SX||SdS(s This method overrides the original onecomd method, to put the cmd,         arg and line variables in class global variables: self.g_cmd,                  self.g_arg and self.g_line.
        Thos variables are then used by the __getattr__ method
        RRN(
RRR6Rt	emptylineRRtlastcmdRR(RRhRtargtfunc((s&/usr/lib/pymodules/python2.7/lshell.pyRBs

	

cCs|jr
dSdS(s This method overrides the original emptyline method, so it doesn't         repeat the last command if last command was empty.
        I just found this annoying..
        iN(R(R((s&/usr/lib/pymodules/python2.7/lshell.pyRXs	cCs|ryt|d|}Wntk
ry>t|d|j}|rj|jjdt|dSWntk
r~nX|jjdt|j|fdSX|n5tj|j	dj
}|j|j|dS(sK This method overrides the original do_help method. 
        Instead of printing out the that are documented or not, it returns the         list of allowed commands when '?' or 'help' is entered. 
        Of course, it doesn't override the help function: any help_* method            will be called (e.g. help_help(self) )
        thelp_Rs%s
NR(
RRt__doc__RR/RstnohelpR8tfromkeysRtkeystsortt	columnize(RRRtdoctlist_tmp((s&/usr/lib/pymodules/python2.7/lshell.pytdo_help`s"

$

cCs|jjtdS(s Print Help on Help N(RR/t	help_help(R((s&/usr/lib/pymodules/python2.7/lshell.pyR{scCs.tjtj|jtj|jddS(s This function is kicks you out the the lshell after              the 'timer' variable exprires. 'timer' is set in seconds.
        RN(tsignaltSIGALRMt_timererrortalarmR(Rttimeout((s&/usr/lib/pymodules/python2.7/lshell.pyRscCs
tddS(Nslshell timer timeout(t
LshellTimeOut(Rtsignumtframe((s&/usr/lib/pymodules/python2.7/lshell.pyRsN(t__name__t
__module__RRRR>R)R*R+R,R(R0ReR3RZRRRRRRRRRRRR(((s&/usr/lib/pymodules/python2.7/lshell.pyRUs2	%	0				
	
U?	@	#										tCheckConfigcBseZdZddddZdZdZdZdZdZ	dZ
dZd	Zd
Z
dZdZd
dZdZdZddZdZd
d
dZdZdZRS(s# Check the configuration file.
    cCs|dkrtj|_n	||_|dkr?tj|_n	||_|dkrctj|_n	||_i|_|j||j\|_|_|j|jd|j	|j
|j|j|j
|j|j|jdS(s0 Force the calling of the methods below
        t
configfileN(RRR
RRRt
getoptionst	argumentst
check_filet
get_globalt	check_logt
get_configtcheck_user_integritytget_config_usert	check_envtcheck_scp_sftptcheck_passwd(RRR
RR((s&/usr/lib/pymodules/python2.7/lshell.pyRs(				!






cCst|d<y+tj|dddddg\}}Wn.tjk
re|jjd|jnXx|D]\}}|dkrtjj||d<n|dkrtjj||d
<n|dkr||d<n|dkr|jn|dkrm|j	qmqmWd|dg}|j
d
rH|d	|d
g7}nt|tjd<tjj
drtjd|d<n||fS(s This method checks the usage. lshell.py must be called with a              configuration file.
        If no configuration file is specified, it will set the configuration           file path to /etc/lshell.confelf.conf['allowed'].append('exit')
        Rshc:sconfig=slog=R.tversionsMissing or unknown argument(s)
s--configs--logRs-cRis-hs--helps	--versiontLSHELL_ARGStSSH_ORIGINAL_COMMAND(s--config(s--log(s-c(s-hs--help(s	--version(
tconfig_filetgetopttGetoptErrorRR/tusageRR?RYRRRsRR(RRRtoptlistRtoptionRV((s&/usr/lib/pymodules/python2.7/lshell.pyRs4
	

cCs!tjjttjddS(s Prints the usage iN(RRR/RR"(R((s&/usr/lib/pymodules/python2.7/lshell.pyRscCs%tjjdttjddS(s Prints the version slshell-%s - Limited Shell
iN(RRR/t__version__R"(R((s&/usr/lib/pymodules/python2.7/lshell.pyRscCsT|jjdrP|jd}x.|jD]}t||tj|<q,WndS(s5 Load environment variable set in configuration file tenv_varsN(RRRRsRRR(RRtkey((s&/usr/lib/pymodules/python2.7/lshell.pyRs
cCsUtjj|sB|jjd|jjttjdntj|_	dS(sh This method checks the existence of the "argumently" given                 configuration file.
        s!Error: Config file doesn't exist
iN(
RR?texistsRR/RRR"tConfigParsertconfig(Rtfile((s&/usr/lib/pymodules/python2.7/lshell.pyRs
cCsy|jj|jdWn@tjtjfk
r]}|jjd|tj	dnX|jj
ds|jjdtj	dnxH|jjdD]4}|jj|ds|d|j|d<qqWdS(sD Loads the [global] parameters from the configuration file 
        RsERR: %s
itglobals%Config file missing [global] section
iN(
RtreadRRtMissingSectionHeaderErrortParsingErrorRR/RR"thas_sectiontitemsR(RtargumentRN((s&/usr/lib/pymodules/python2.7/lshell.pyRscCsitjd6tjd6tjd6tjd6|_|jjdrtyt|jd}Wqz|jd}qzXnd}tj	|}tj
dt}tj
d|tj
tf}|jtjtj}|j||jtj
d	|jtj|jjd
s5d|jd
<nyt|jd
|jd
<Wntk
rsd|jd
<nX|jd
dkrd|jd
<n#|jd
dkrd|jd
<n|jjdryt|jd}Wn|jd}nXtj}|jd
d|d}|jdd|d}|jdd|d}|jdd|d|df}|jdt}n	t}|jd
dkry|dkrddlm}|dd}	|	j||	j|j|jd
|j|	ntjj|jd|d}
t|
dj}tj|
|_|jj||jj|j|jd
|j|jWqtk
rqXn||jd<||_ dS(s* Sets the log level and log file 
        iiiit
syslognametlshells%%(asctime)s (%s): %%(message)ss%s[%s]: %s: %%(message)ss%(message)stloglevelitlogfilenames%ys%ss%ms%02ds%ds%hs%02d%02ds%utsyslogi(t
SysLogHandlertaddresss/dev/logRs.logRN(!tloggingtCRITICALtERRORtWARNINGtDEBUGtlevelsRRRwt	getLoggert	FormatterRRtgetpidtsetLevelt
StreamHandlert
addHandlertsetFormatterRtt
ValueErrorttimet	localtimeRtlogging.handlersRR?RRIRtFileHandlertlogfileRHR(RtlognameR	tloggert	formattertsyslogformattertlogsterrt
currentimeRR
Rtfp((s&/usr/lib/pymodules/python2.7/lshell.pyRs|


	
	

	



cCs|jj|jdt|_i|_|jdtj}|j	x8|D]0}t
j|d}d|}|j|qVW|j|jdS(s Load default, group and user configuation. Then merge them all. 
        The loadpriority is done in the following order:
            1- User section
            2- Group section
            3- Default section
        RRisgrp:N(RRRRtusertconf_rawtget_config_subRt	getgroupstreversetgrptgetgrgid(Rtgrplisttgidtgrpnametsection((s&/usr/lib/pymodules/python2.7/lshell.pyR\s	



c	Cs|jj|r|xg|jj|D]P}|d}|d}tjd|jdd}t|dkr|dkrx|D]"}|jd
s|jdr|jj	|j
|j||q|dkr|jj	i|j|6q|rl|dkrlddg}x4t|D]&}|dct
jj|d
7<q"W|jj	it||6q|rtt|tkr|jj	i||6qqWq%|dkr|ddkr|jj	i|j|6q%|dkr\ddg}x:|j|dD]&}|dct
jj|d
7<qW|jj	it||6q%|jj	t|gq%WndS(s[ this function is used to interpret the configuration +/-, 
            'all' etc.
        iis([\+\-\s]+\[[^\]]+\])RORR?RcRRt-t+s'all's/.*|N(spathsoversshsalloweds	forbidden(RRRR4RARRWRgR(RSt	minusplust
expand_allRwRR?RYRsR7tlisttmyevalR8(	RR1RNRRVRAtstufftlisteR?((s&/usr/lib/pymodules/python2.7/lshell.pyR)xs>

	
 $ ! $ cCsv|j|r%|j||}n!|dkr@ddg}ng}|j|d|}|jdr|dkrxO|D]&}|dctjj|d7<q~Wqex|D]}|j|qWn|jdre|dkrxx|D]&}|dctjj|d7<qWqexG|D]<}||krD|j|q"|jj	d||fq"Wnit
||6S(	s= update configuration lists containing -/+ operators
        R?RiR3is/.*|R2s#CONF: -['%s'] ignored in '%s' list.(RR7RgRR?RYRtremoveRRRs(RtconfdictRtextraR9tsublistR?RN((s&/usr/lib/pymodules/python2.7/lshell.pyR4s,
'

'
cCsddddddddd	d
ddd
dddddddddg}xtjdjdD]}}tjj|rxbtj|D]:}tjtjj||tjr|j	|qqWq_|j
jd|q_Wt|S(s) expand allowed, if set to 'all'
        tbgtbreaktcaseR(tcontinueRwtexecR"tfgtiftjobstkilltlogintlogouttsettshiftRtsuspendtumasktunsettwaittwhiletPATHt:s$CONF: PATH entry "%s" does not exist(
RRRRAR?RRtaccessRtX_OKRRRRs(Rtexpanded_allRRN((s&/usr/lib/pymodules/python2.7/lshell.pyR5s$RcCsMyt|}|SWn2tk
rH|jjd|tjdnXdS(s? if eval returns SyntaxError, log it as critical iconf missing s/CONF: Incomplete %s field in configuration fileiN(RwtSyntaxErrorRRKRR"(RRVR:t	evaluated((s&/usr/lib/pymodules/python2.7/lshell.pyR7s
cCsixbtD]Z}||jjkr|jjd|d|jjd|jtjdqqWdS(s This method checks if all the required fields by user are present          for the present user.
        In case fields are missing, the user is notified and exited from lshell.
        sERROR: Missing parameter 's'sCERROR: Add it in the in the [%s] or [default] section of conf file.iN(trequired_configR(RRRKR'RR"(RRN((s&/usr/lib/pymodules/python2.7/lshell.pyRs
	cCs*|jjdryt|jd|jd<Wntk
rCnX|jddkrgd|jd<n#|jddkrd|jd<ny"|jj|j|jdWqtk
rqXnx3dddddd	d
ddd
dddddgD]}y$|j	|j|||j|<Wqt
k
r|d0krMg|j|<q|d1krid|j|<q|d2krd|j|<q|d3kri|j|<q|d4krqqd|j|<qtk
r|jj
d|tjdqXqW|j|jd<|jjdrq|jdjd|jd|jd<tjj|j	|jdd|jd<ntjd|jd<|jjdrt|jd|jd<|jddc|jdd7<n/ddg|jd<|jdd|jdd<|jjdr:|j	|jdd|jd<n
d|jd<|jjdr|j	|jd|jd<yOtjj|jdr|jd|jd<n|jjd|jdWqtk
r|jjd qXn|jjd!r|j	|jd!|jd!<n
t|jd!<|jjd"rq|jd"|jd"<|j|j|jd"dntjj|jdrtj|jdn(|jj
d#|jdtjd|jjd$r4y1t|jd$jd|jd|jd$<WqA|jjd%|jd$qAXn
t|jd$<|jd$jd&sd'|jd|jd$f|jd$<ntjd(|jdtjd(<|jdjd)|jdjd*|jdjd+|jdjd,|jdjd-|jdr&|jdjd.nd/S(5s Once all the checks above have passed, the configuration files             values are entered in a dict to be used by the command line it self.
        The lshell command line is then launched!
        RiiRRRBRRRtscpt
scp_uploadtscp_downloadtsftpRcR%R'R	Riis5ERR: in the -%s- field. Check the configuration file.tusernameR&s%utHOMER?s.*Rtenv_pathtscpforces$CONF: scpforce no such directory: %ss CONF: scpforce must be a string!R
tlock_counters(ERR: home directory "%s" does not exist.RDsCONF: history file error: %sRvs%s/%sRPR"R)R*R+tclearRbN(sallowedsoversshs
sudo_commands(shistory_size(RYRZ(saliasessenv_vars(sprompt( R(RRtRRRRRRR7tKeyErrort	TypeErrorRRKRR"R'RRR?tnormpathRRRwRRR
taccount_lockR~RXRDRgR(RRN((s&/usr/lib/pymodules/python2.7/lshell.pyRs
"

$


%

 
 
!


cCs
|r	ndS(s6 check if user account is locked, in which case, exit N((RR'R`tcheck((s&/usr/lib/pymodules/python2.7/lshell.pyReosc	Cs|jjdrtjjdrtjjdrd|jdkr|jddkr|jjdtj|jd|jjdtjd	q|jjd
tjd	nt	|jd(d(d(d(|jd}|j|jdd(ddr|jd|jdnt
|jdd	}t
|jddd
 }x|jdjjdD]v}tjj|d}tj||}|rtj||}nd(}|s|rn|jd|jdqnqnW|jdjdr|jddks$d|jdkrd|jdkr|jdrb|jjd|jdq|jjd|jdtjd	nd|jdkr|jdr||jjdr^|jdjd}tjj|d
}	tjj|jd}
|	|
kr^|jjdd|	|jd
|j|
tj||jd<q^n|jjd|jdq|jjd|jdtjd	ntj|jd|jjdtjd	q|jd|jddq|jdrt|jd|jd |jd<|j|jdd!dddre|jd"|jdn|jjd#|jd|jdd$kr|jd(ntj|jd|jjd%tjd	q|jd&|jdq|jd'|jdnd(S()s This method checks if the user is trying to SCP a file onto the            server. If this is the case, it checks if the user is allowed to use           SCP or not, and    acts as requested. : )
        Rit
SSH_CLIENTtSSH_TTYssftp-serverR[isSFTP connectsSFTP disconnectis*** forbidden SFTP connections
path over SSHR?iRORvsscp RXRcs -f RZs
SCP: GET "%s"sSCP: download forbidden: "%s"s -t RYR_sSCP: forced SCP s
directory: %ss
SCP: PUT "%s"sSCP: upload forbidden: "%s"sSCP disconnectsSCP connectionR'R%schar/command over SSHsOver SSH: "%s"R.R$scommand over SSHsshell escapeN(RRRRRRRR;RR"RRR3tssh_warnRsRfRAR?RYR4RdRgRRtstringRR9R0R(RtcliRRRNRRRtcmdsplittscppatht
forcedpath((s&/usr/lib/pymodules/python2.7/lshell.pyRys#
&


	



"cCs|dkr7|jjd||jjd|n|jjd||f|jjd|jjdtjddS(	s+ log and warn if forbidden action over SSH RXs*** forbidden %ss*** SCP command: %ss*** forbidden %s: "%s"s!This incident has been reported.
R$iN(RRKRRR/RR"(RtmessageRCR((s&/usr/lib/pymodules/python2.7/lshell.pyRiscCs|jj|jrQ|jj|jdrH|jj|jd}qWd}nd}|rtd|jd}||kr|jjd|j	j
dtjdqndSdS(sF As a passwd field is required by user. This method checks in the           configuration file if the password is empty, in wich case, no password         check is required. In the other case, the password is asked to be              entered. 
        If the entered password is wrong, the user is exited from lshell.
        tpasswdsEnter s
's password: s!Error: Wrong password 
Exiting..
sWARN: Wrong passwordiN(
RRR't
has_optiontgetRRRR/RRKRR"(RRptpassword((s&/usr/lib/pymodules/python2.7/lshell.pyRs	cCs|jS(s  returns the configuration dict (R(R((s&/usr/lib/pymodules/python2.7/lshell.pyt
returnconfsN(RRRRRRRRRRRRRR)R4R5R7RRReRRiRRt(((s&/usr/lib/pymodules/python2.7/lshell.pyRs*	/				
		V		&		
		
	i	RcBs#eZdZddZdZRS(s- Custum exception used for timer timeout
    s	Timed OutcCs
||_dS(N(RV(RRV((s&/usr/lib/pymodules/python2.7/lshell.pyRscCs
t|jS(N(treprRV(R((s&/usr/lib/pymodules/python2.7/lshell.pyt__str__s(RRRRRv(((s&/usr/lib/pymodules/python2.7/lshell.pyRscCsx|jD]}d|}xtj||rtj||dd}tj||dd}tj|d||||f|d}|}||kr Pq q Wq
Wx7dddgD]&}|jd||fd	|}qW|S(
s0 Replace all configured aliases in the line
    s(^|; |;)%s([ ;&\|]+|$)iis%s%s%st;R_R@s%s%ss%s(RR4RdR5R(RhR'RNtregt
beforecommandtaftercommandtlinesavetchar((s&/usr/lib/pymodules/python2.7/lshell.pyR9s
$cCstjjtjdtjd<tjjdrStjdttjd}n
tjd}t|j	}yt
|}|jWnett
fk
rtjjdtjdn2tk
r|djdtjjdnXd	S(
s main function itSHELLRis
Exited on user request
Rs
Timer expireds

Time is up.
N(RR?RYRtargvRRRRwRRtRRRRRR/R"RR(RR Rk((s&/usr/lib/pymodules/python2.7/lshell.pytmain$s !

t__main__($RRRRRRRRjR4RR
RRyRFR,Rt
__author__RRWtexec_prefixtconf_prefixRRDt	lock_fileRRR
RR1RRt	ExceptionRR9RR(((s&/usr/lib/pymodules/python2.7/lshell.pyt<module>sJ

7