o `E@sddlmZddlmZddlZddlmZdefddZdefdd Z d Z d Z Gd d d eZ Gddde ZGdddeZGdddZeZdS))hexlify)EnumN)OptionalreturncCstttd}d|S)zPrepare an AUTH command line with the current effective user ID. This is the preferred authentication method for typical D-Bus connections over a Unix domain socket. asciisAUTH EXTERNAL %b )rstrosgeteuidencode)hex_uidr ./usr/lib/python3/dist-packages/jeepney/auth.pymake_auth_externalsrcCs&ddlm}td|d}d|S)zFormat an AUTH command line for the ANONYMOUS mechanism Jeepney's higher-level wrappers don't currently use this mechanism, but third-party code may choose to. See for details. ) __version__z Jeepney %srsAUTH ANONYMOUS %s )rrr )rtracer r r make_auth_anonymouss rsBEGIN sNEGOTIATE_UNIX_FD c@s eZdZdZdZdZdZdZdS) ClientStaterN)__name__ __module__ __qualname__WaitingForData WaitingForOkWaitingForRejectWaitingForAgreeUnixFDSuccessr r r r rs rc@s"eZdZdZdddZddZdS) AuthenticationErrorz%Raised when DBus authentication failsAuthentication failedcCs||_||_dSNmsgdata)selfr&r%r r r __init__(s zAuthenticationError.__init__cCs|jd|jS)Nz . Bus sent: r$r'r r r __str__,szAuthenticationError.__str__N)r")rrr__doc__r(r*r r r r r!&s  r!cs eZdZdZfddZZS)FDNegotiationErrorzBRaised when file descriptor support is requested but not availablecstj|dddS)Nz%File descriptor support not available)r%)superr()r'r& __class__r r r(1szFDNegotiationError.__init__)rrrr+r( __classcell__r r r.r r,/sr,c@sVeZdZdZdddZeddZddZd ee fd d Z d d Z de fddZ dS) AuthenticatorzProcess data for the SASL authentication conversation If enable_fds is True, this includes negotiating support for passing file descriptors. FcCs,||_t|_dt|_tj|_d|_dS)N) enable_fds bytearraybufferr_to_sendrrstateerror)r'r3r r r r(;s   zAuthenticator.__init__cCs |jtjuSr#)r7rr r)r r r authenticatedBs zAuthenticator.authenticatedcCs t|jdSr#)iter data_to_sendr)r r r __iter__Fs zAuthenticator.__iter__rcCs"|js|jrdSd|j|_}|S)aGet a line of data to send to the server The data returned should be sent before waiting to receive data. Returns empty bytes if waiting for more data from the server, and None if authentication is finished (success or error). Iterating over the Authenticator object will also yield these lines; :meth:`feed` should be called with received data inside the loop. N)r9r8r6)r'to_sendr r r r;Is zAuthenticator.data_to_sendcCsn|jtjur|dr|jrttjfSttjfSn|jtjur0|dr)ttjfS||_ t |||_ t |)NsOK s AGREE_UNIX_FD) r7rr startswithr3NEGOTIATE_UNIX_FDrBEGINr r8r,r!)r'liner r r process_lineXs       zAuthenticator.process_liner&cCsr|j|7_d|jvr*|jdd\}|_|jrt|jd||\|_|_dSt|jdkr7t|jddS)zProcess received data Raises AuthenticationError if the incoming data is not as expected for successful authentication. The connection should then be abandoned. s rzUnexpected data receivedi z*Too much data received without line endingN)r5splitr!rCr6r7len)r'r&rBr r r feedns  zAuthenticator.feedN)F) rrrr+r(propertyr9r<rbytesr;rCrFr r r r r15s  r1)binasciirenumrrtypingrrHrrrAr@r ValueErrorr!r,r1 SASLParserr r r r s     S