Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/protocols/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyc


[XMc@s dZddlmZddlZddlmZddlmZddlm	Z	m
Z
dZdZd
e
fdYZdefd
YZdefdYZdefdYZdejfdYZdddYZdejfdYZd
ddddddgZdS(s>
Ident protocol implementation.

@author: Jean-Paul Calderone
i(t
generatorsN(tdefer(tbasic(tlogtfailureiiit
IdentErrorcBseZdZdZdZRS(s;
    Can't determine connection owner; reason unknown.
    s
UNKNOWN-ERRORcCs|jS(N(tidentDescription(tself((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyt__str__s(t__name__t
__module__t__doc__RR(((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyRstNoUsercBseZdZdZRS(s
    The connection specified by the port pair is not currently in use or
    currently not owned by an identifiable entity.
    sNO-USER(R	R
RR(((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyR!stInvalidPortcBseZdZdZRS(s
    Either the local or foreign port was improperly specified. This should
    be returned if either or both of the port ids were out of range (TCP
    port numbers are from 1-65535), negative integers, reals or in any
    fashion not recognized as a non-negative integer.
    sINVALID-PORT(R	R
RR(((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyR
)st
HiddenUsercBseZdZdZRS(s
    The server was able to identify the user of this port, but the
    information was not returned at the request of the user.
    sHIDDEN-USER(R	R
RR(((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyR3stIdentServercBsDeZdZdZdZdZdZdZdZRS(s
    The Identification Protocol (a.k.a., "ident", a.k.a., "the Ident
    Protocol") provides a means to determine the identity of a user of a
    particular TCP connection. Given a TCP port number pair, it returns a
    character string which identifies the owner of that connection on the
    server's system.

    Server authors should subclass this class and override the lookup method.
    The default implementation returns an UNKNOWN-ERROR response for every
    query.
    cCs|jd}t|dkr.|jnytt|\}}Wntk
rd|jnkXt|ko|tknrt|kotknr|j||n|j	t
jt||dS(Nt,i(
tsplittlentinvalidQuerytmaptintt
ValueErrort	_MIN_PORTt	_MAX_PORTt
validQueryt	_ebLookupRtFailureR
(RtlinetpartstportOnServertportOnClient((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pytlineReceivedHs

8cCs|jjdS(N(t	transporttloseConnection(R((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyRWscCsn|jjj|f}|jjj|f}tj|j||j|j||j	|j
||dS(s
        Called when a valid query is received to look up and deliver the
        response.

        @param portOnServer: The server port from the query.
        @param portOnClient: The client port from the query.
        N(R!tgetHostthosttgetPeerRt
maybeDeferredtlookuptaddCallbackt	_cbLookupt
addErrbackR(RRRt
serverAddrt
clientAddr((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyR[s
cCs-|\}}|jd||||fdS(Ns%d, %d : USERID : %s : %s(tsendLine(Rt.1tsporttcporttsysNametuserId((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyR)ks	cCsc|jtr/|jd|||jfn0tj||jd||t|jfdS(Ns%d, %d : ERROR : %s(tcheckRR-tvalueRterr(RRR/R0((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyRns 
cCs
tdS(shLookup user information about the specified address pair.

        Return value should be a two-tuple of system name and username.
        Acceptable values for the system name may be found online at::

            U{http://www.iana.org/assignments/operating-system-names}

        This method may also raise any IdentError subclass (or IdentError
        itself) to indicate user information will not be provided for the
        given query.

        A Deferred may also be returned.

        @param serverAddress: A two-tuple representing the server endpoint
        of the address being queried.  The first element is a string holding
        a dotted-quad IP address.  The second element is an integer
        representing the port.

        @param clientAddress: Like L{serverAddress}, but represents the
        client endpoint of the address being queried.
        N(R(Rt
serverAddresst
clientAddress((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyR'us(	R	R
RR RRR)RR'(((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyR;s					tProcServerMixincBseZdZdZy#ddlmZedZ[Wnek
rQdZnXdZdZ	dZ
d	Zd
ZRS(sIImplements lookup() to grab entries for responses from /proc/net/tcp
    tLINUXi(tgetpwuidcCs||dS(Ni((RtuidR:((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pytgetUsernamescCs
tdS(N(R(RR;((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyR<sccs6td}|jx|D]}|jVqWdS(Ns
/proc/net/tcp(tfiletreadlinetstrip(RtftL((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pytentriess

c
Cs7djtttjdtjdt|dS(Nt.t4Bs=Li(tjoinRtstrtstructtunpacktpackR(Rthexstr((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pytdottedQuadFromHexStringscCs=|jd\}}|j|}t|d}||fS(Nt:i(RRKR(Rtpackedtaddrtport((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyt
unpackAddressscCsm|jj}|j|d\}}|j|d\}}t|d}||f||f|fS(Niii(R?RRPR(RRRt	localAddrt	localPortt
remoteAddrt
remotePortR;((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyt	parseLines
cCsrxb|jD]T}|j|\}}}||kr
|d|dkr
|j|j|fSq
WtdS(Ni(RBRUtSYSTEM_NAMER<R(RR6R7tentRQRSR;((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyR's
 (
R	R
RRVtpwdR:R<tImportErrorRBRKRPRUR'(((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyR8s

				tIdentClientcBsGeZeeeefZdZdZdZ	dZ
dZRS(cCs
g|_dS(N(tqueries(R((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyt__init__scCsi|jjtj||ft|jdkrC|jddS|jd||f|jddS(sBLookup user information about the specified address pair.
        iiis%d, %d(R[tappendRtDeferredRR-(RRR((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyR's
cCs|js tjd|fnd|jjd\}}}|j|||jr|jd|jdd|jddfndS(NsUnexpected server response: %ris%d, %dii(R[Rtmsgtpopt
parseResponseR-(RRtdt_((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyR s		cCs8x(|jD]}|djt|q
Wg|_dS(Ni(R[terrbackR(Rtreasontq((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pytconnectionLostscCs|jdd}t|dkr:|jt|nttj|\}}}|dkrx7|jD],}|j|krk|j||dSqkW|jt|n|j	||fdS(NRLiitERROR(
RRRdRRRFR?t
errorTypesRtcallback(RtdeferredRRtportsttypetaddInfotet((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyRas(R	R
RRR
RRiR\R'R RgRa(((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyRZs		
			ii((Rt
__future__RRGttwisted.internetRttwisted.protocolsRttwisted.pythonRRRRt	ExceptionRRR
RtLineOnlyReceiverRR8RZt__all__(((s;/usr/lib/python2.7/dist-packages/twisted/protocols/ident.pyt<module>	s"
R..