Ñò pØcJc @s­dZddkZddkZddklZlZddkTddklZddk Tddk Tddk Thed6ed6Z de efd „ƒYZdd klZdS( s Server-mode SFTP support. iÿÿÿÿN(tMD5tSHA(t*(tSubsystemHandlertsha1tmd5t SFTPServercBs­eZdZed„Zd„Zd„Zd„Zd„Ze eƒZd„Z e e ƒZ d„Z e d„Z dd „Zd „Zd „Zd „Zd „Zd„ZRS(sä Server-side SFTP subsystem support. Since this is a L{SubsystemHandler}, it can be (and is meant to be) set as the handler for C{"sftp"} requests. Use L{Transport.set_subsystem_handler} to activate this class. cOsŽti|ƒti||||ƒ|iƒ}ti|iƒdƒ|_|iƒ|_ d|_ h|_ h|_ ||||Ž|_ dS(sâ The constructor for SFTPServer is meant to be called from within the L{Transport} as a subsystem handler. C{server} and any additional parameters or keyword parameters are passed from the original call to L{Transport.set_subsystem_handler}. @param channel: channel passed from the L{Transport}. @type channel: L{Channel} @param name: name of the requested subsystem. @type name: str @param server: the server object associated with this channel and subsystem @type server: L{ServerInterface} @param sftp_si: a subclass of L{SFTPServerInterface} to use for handling individual requests. @type sftp_si: class s.sftpiN(tBaseSFTPt__init__Rt get_transporttutilt get_loggertget_log_channeltloggert get_hexdumpt ultra_debugt next_handlet file_tablet folder_tabletserver(tselftchanneltnameRtsftp_sitlargstkwargst transport((s8/usr/lib/python2.6/site-packages/paramiko/sftp_server.pyR0s     cCs‹tt|ƒtƒoCxn|D]4}tt|ƒi|d|iiƒd|ƒqWn/tt|ƒi|d|iiƒd|ƒdS(Ns[chan s] (t issubclassttypetlisttsuperRt_logtsocktget_name(Rtleveltmsgtm((s8/usr/lib/python2.6/site-packages/paramiko/sftp_server.pyRMs 6c Csd||_|itdt|ƒƒ|iƒ|iiƒx#toy|iƒ\}}Wnit j o|itdƒdSt j o:}|itdt |ƒƒ|itt i ƒƒdSXt|ƒ}|iƒ}y|i|||ƒWq=t j oW}|itdt |ƒƒ|itt i ƒƒy|i|tƒWq[q[Xq=Xq=WdS(Ns!Started sftp server on channel %ssEOF -- end of sessionsException on channel: s Exception in server processing: (R RtDEBUGtreprt_send_server_versionRtsession_startedtTruet _read_packettEOFErrort ExceptiontstrR t tb_stringstMessagetget_intt_processt _send_statust SFTP_FAILURE( RRRRtttdatateR#trequest_number((s8/usr/lib/python2.6/site-packages/paramiko/sftp_server.pytstart_subsystemTs4     cCs~|iiƒtt|ƒiƒx!|iiƒD]}|iƒq0Wx!|iiƒD]}|iƒqTWh|_h|_dS(N( Rt session_endedRRtfinish_subsystemRt itervaluestcloseR(Rtf((s8/usr/lib/python2.6/site-packages/paramiko/sftp_server.pyR:ps  cCsB|tijotS|tijp|tijotStSdS(s Convert an errno value (as from an C{OSError} or C{IOError}) into a standard SFTP result code. This is a convenience function for trapping exceptions in server code and returning an appropriate result. @param e: an errno code, as from C{OSError.errno}. @type e: int @return: an SFTP error code like L{SFTP_NO_SUCH_FILE}. @rtype: int N(terrnotEACCEStSFTP_PERMISSION_DENIEDtENOENTtENOTDIRtSFTP_NO_SUCH_FILER3(R6((s8/usr/lib/python2.6/site-packages/paramiko/sftp_server.pyt convert_errno{s  cCsÍtidjoZ|i|i@oti||iƒn|i|i@oti||i |i ƒqjn|i|i @o ti ||i |ifƒn|i|i@ot|dƒi|iƒndS(sn Change a file's attributes on the local filesystem. The contents of C{attr} are used to change the permissions, owner, group ownership, and/or modification & access time of the file, depending on which attributes are present in C{attr}. This is meant to be a handy helper function for translating SFTP file requests into local file operations. @param filename: name of the file to alter (should usually be an absolute path). @type filename: str @param attr: attributes to change. @type attr: L{SFTPAttributes} twin32sw+N(tsystplatformt_flagstFLAG_PERMISSIONStostchmodtst_modet FLAG_UIDGIDtchowntst_uidtst_gidt FLAG_AMTIMEtutimetst_atimetst_mtimet FLAG_SIZEtopenttruncatetst_size(tfilenametattr((s8/usr/lib/python2.6/site-packages/paramiko/sftp_server.pyt set_file_attrs! cGsûtƒ}|i|ƒxÈ|D]À}t|ƒtjo|i|ƒqt|ƒtjo|i|ƒqt|ƒtjo|i|ƒqt|ƒtjo|i |ƒqt dt |ƒdt t|ƒƒƒ‚qW|i |t|ƒƒdS(Nsunknown type for s type ( R/tadd_intRtinttlongt add_int64R-t add_stringtSFTPAttributest_packR,R&t _send_packet(RR7R4targR#titem((s8/usr/lib/python2.6/site-packages/paramiko/sftp_server.pyt _response°s  .cCsœtt|ƒtƒp|i||ƒdS|id|iƒ|id7_|o||i|iƒ|D]6}|i|iƒ|it|ƒƒ|i |ƒqdW|i t t|ƒƒdS(Ni( t_get_next_filestlenR2tSFTP_EOFR/R\R`RYR-RbRctCMD_NAME(RR7RltflistR#RZ((s8/usr/lib/python2.6/site-packages/paramiko/sftp_server.pyt _read_folderás   cCsŒ|iƒ}|iƒ}|iƒ}|iƒ}|iƒ}||ijo|i|tdƒdS|i|}xG|D](} | tjo| } t| } PqxqxW|i|tdƒdS|djoK|i ƒ} t t | ƒt ƒp|i|| dƒdS| i |}n|djo |}n|djo|i|tdƒdSd} |}x×|||joÅt||||ƒ}t|dƒ}d}| iƒ}xv||joh|i||ƒ}t |ƒtj o|i||d ƒdS|i|ƒ|t|ƒ7}||7}qªW| |iƒ7} q^Wtƒ}|i|ƒ|id ƒ|i| ƒ|i| ƒ|itt|ƒƒdS( NsInvalid handlesNo supported hash types foundisUnable to stat fileisBlock size too smallRoisUnable to hash files check-file(t get_stringtget_listt get_int64R0RR2tSFTP_BAD_MESSAGEt _hash_classR3tstatRRRaRXtmintnewtreadR-tupdateR|tdigestR/R\R`t add_bytesRctCMD_EXTENDED_REPLY(RR7R#Rktalg_listtstarttlengtht block_sizeR=txtalgnametalgtsttsum_outtoffsettblocklentchunklentcountthash_objR5((s8/usr/lib/python2.6/site-packages/paramiko/sftp_server.pyt _check_fileïsh                      cCs¸|t@o|t@o ti}n"|t@o ti}n ti}|t@o|tiO}n|t@o|ti O}n|t @o|ti O}n|t @o|ti O}n|S(s;convert SFTP-style open() flags to python's os.open() flags(tSFTP_FLAG_READtSFTP_FLAG_WRITERJtO_RDWRtO_WRONLYtO_R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os check-file(>RR%t CMD_NAMEStCMD_OPENRR¬R0Rat _from_msgRmRRVt CMD_CLOSERR2tSFTP_OKRR<R„tCMD_READRƒR‰RR-R|R}RftCMD_DATAt CMD_WRITEtwritet CMD_REMOVEtremovet CMD_RENAMEtrenamet CMD_MKDIRtmkdirt CMD_RMDIRtrmdirt CMD_OPENDIRRzt CMD_READDIRR€tCMD_STATR†Rt CMD_ATTRSt CMD_LSTATtlstatt CMD_FSTATt CMD_SETSTATtchattrt CMD_FSETSTATt CMD_READLINKtreadlinkR~t CMD_SYMLINKtsymlinkt CMD_REALPATHt canonicalizet CMD_EXTENDEDRœtSFTP_OP_UNSUPPORTED(RR4R7R#RxR«RZRkR—RR5toldpathtnewpathRlRyt target_pathtrpathttag((s8/usr/lib/python2.6/site-packages/paramiko/sftp_server.pyR1<sè  &            '      #  #                #  $  #   #  #   N(t__name__t __module__t__doc__tSFTPServerInterfaceRRR8R:RDt staticmethodR[RftFalseRmRpR2RzR€RœR¬R1(((s8/usr/lib/python2.6/site-packages/paramiko/sftp_server.pyR)s"          ; (Rg(R×RJR>t Crypto.HashRRtparamiko.commontparamiko.serverRt paramiko.sftptparamiko.sftp_sitparamiko.sftp_attrR…RRtparamiko.sftp_handleRg(((s8/usr/lib/python2.6/site-packages/paramiko/sftp_server.pyts       ÿ”