ó Ÿ;Xc@sdZddlZddlZejeƒZddlmZddlm Z m Z ddl m Z m Z mZddljjZdddgZdejjejfd „ƒYZe d ƒZd Zdejjejfd „ƒYZdejfd „ƒYZdS( s.passlib.handlers.misc - misc generic handlers iÿÿÿÿN(twarn(t to_native_strt str_consteq(tunicodetutunicode_or_bytes_typest unix_disabledt unix_fallbackt plaintextcBsPeZdZdZdZed„ƒZed„Zd„Z eed„ƒZ RS(s…This class provides the fallback behavior for unix shadow files, and follows the :ref:`password-hash-api`. This class does not implement a hash, but instead provides fallback behavior as found in /etc/shadow on most unix variants. If used, should be the last scheme in the context. * this class will positively identify all hash strings. * for security, passwords will always hash to ``!``. * it rejects all passwords if the hash is NOT an empty string (``!`` or ``*`` are frequently used). * by default it rejects all passwords if the hash is an empty string, but if ``enable_wildcard=True`` is passed to verify(), all passwords will be allowed through if the hash is an empty string. .. deprecated:: 1.6 This has been deprecated due to its "wildcard" feature, and will be removed in Passlib 1.8. Use :class:`unix_disabled` instead. Rtenable_wildcardcCs,t|tƒrtStjj|dƒ‚dS(Nthash(t isinstanceRtTruetuhtexctExpectedStringError(tclsR ((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pytidentify.scKs0tdtƒtt|ƒj|||_dS(Nsf'unix_fallback' is deprecated, and will be removed in Passlib 1.8; please use 'unix_disabled' instead.(RtDeprecationWarningtsuperRt__init__R (tselfR tkwds((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyR5scCs|jr|jStdƒSdS(Nt!(tchecksumR(Rtsecret((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyt_calc_checksum=s cCsFtj|ƒt|tƒs4tjj|dƒ‚n|r>tS|SdS(NR (R tvalidate_secretR RRRtFalse(RRR R ((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pytverifyEs  (senable_wildcard( t__name__t __module__t__doc__tnamet context_kwdst classmethodRRRRR(((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyRs  s*!cBsæeZdZdZdZdZeeeƒƒZ de j krNe dƒZ n e dƒZ edd„ƒZed„ƒZed„ƒZed „ƒZejd d d d ƒedd„ƒƒZedd„ƒZed„ƒZRS(sThis class provides disabled password behavior for unix shadow files, and follows the :ref:`password-hash-api`. This class does not implement a hash, but instead matches the "disabled account" strings found in ``/etc/shadow`` on most Unix variants. "encrypting" a password will simply return the disabled account marker. It will reject all passwords, no matter the hash string. The :meth:`~passlib.ifc.PasswordHash.hash` method supports one optional keyword: :type marker: str :param marker: Optional marker string which overrides the platform default used to indicate a disabled account. If not specified, this will default to ``"*"`` on BSD systems, and use the Linux default ``"!"`` for all other platforms. (:attr:`!unix_disabled.default_marker` will contain the default value) .. versionadded:: 1.6 This class was added as a replacement for the now-deprecated :class:`unix_fallback` class, which had some undesirable features. Rtmarkertbsdt*RcKsVtt|ƒj|}|dk rR|j|ƒsFtd|ƒ‚n||_n|S(Nsinvalid marker: %r(RRtusingtNoneRt ValueErrortdefault_marker(RR$Rtsubcls((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyR'xs   cCsZt|tƒrt}n-t|tƒr0t}ntjj|dƒ‚| pY|d|kS(NR i(R Rt _MARKER_CHARStbytest _MARKER_BYTESR RR(RR tstart((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyRs   cCs5tj|ƒ|j|ƒs1tjj|ƒ‚ntS(N(R RRRtInvalidHashErrorR(RRR ((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyR™s cKsm|r,tj||ƒ|j|j|ƒStj|ƒ|j}|rW|j|ƒs]t‚t|ddƒS(NtparamR$( R twarn_hash_settings_deprecationR'R RR*RtAssertionErrorR(RRRR$((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyR  s  t deprecateds1.7tremoveds2.0cCsy|j|ƒs$tjj|ƒ‚nQ|rGtj|ƒt|ddƒS|dk rh|jd|ƒ}n|j|ƒSdS(NR1tconfigR$( RR RR0RRR(R'R (RRR6R$((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pytgenhashªs  cCsh|jdƒ}|dk rdt|ddƒ}|j|ƒrN|j|ƒ}n|rd||7}qdn|S(NtR1R (R R(RRtenable(RR tout((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pytdisable¸s cCstt|ddƒ}xI|jD]>}|j|ƒr|t|ƒ}|rK|Stdƒ‚qqWtjj|ƒ‚dS(NR1R scannot restore original hash(Rt_disable_prefixest startswithtlenR)R RR0(RR tprefixtorig((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyR9Äs(smarker(N(RRR R!t setting_kwdsR"ttupletstrR,R<tsystplatformRR*R#R(R'RRR R tdeprecated_methodR7R;R9(((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyRRs&    cBsªeZdZdZd ZdZdZed„ƒZedd„ƒZ edd„ƒZ e j ddd d ƒed „ƒƒZe j ddd d ƒedd „ƒƒZRS(s~This class stores passwords in plaintext, and follows the :ref:`password-hash-api`. The :meth:`~passlib.ifc.PasswordHash.hash`, :meth:`~passlib.ifc.PasswordHash.genhash`, and :meth:`~passlib.ifc.PasswordHash.verify` methods all require the following additional contextual keyword: :type encoding: str :param encoding: This controls the character encoding to use (defaults to ``utf-8``). This encoding will be used to encode :class:`!unicode` passwords under Python 2, and decode :class:`!bytes` hashes under Python 3. .. versionchanged:: 1.6 The ``encoding`` keyword was added. Rtencodingsutf-8cCs,t|tƒrtStjj|dƒ‚dS(NR (R RR R RR(RR ((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyRçscCs/tj|ƒ|s|j}nt||dƒS(NR(R Rtdefault_encodingR(RRRG((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyR îs  cCsa|s|j}nt||dƒ}|j|ƒsHtjj|ƒ‚nt|j||ƒ|ƒS(NR (RHRRR RR0RR (RRR RG((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyRõs  R4s1.7R5s2.0cCs |jdƒS(NR8(R (R((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyt genconfigþscCs7|j|ƒs$tjj|ƒ‚n|j|d|ƒS(NRG(RR RR0R (RRR6RG((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyR7s((sencodingN(RRR R!RAR"RHR#RR(R RR RFRIR7(((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyRÐs(R RDtloggingt getLoggerRtlogtwarningsRt passlib.utilsRRtpasslib.utils.compatRRRtpasslib.utils.handlerstutilsthandlersR t__all__tifct DisabledHasht StaticHandlerRR,R.tMinimalHandlerRR(((s9/usr/lib/python2.7/site-packages/passlib/handlers/misc.pyts   "6 "~