;ò g?îFc@s<dZdZdkZdkZdklZdddgZhdei<dei<dei<dei  This module is distributed under the terms of the GPL (GNU GENERAL PUBLIC LICENSE) Version 2 (see http://www.gnu.org/copyleft/gpl.html) Python compability note: This module only works with Python 1.6+ since all string parameters are assumed to be Unicode objects and string methods are used instead string module. $Id: base.py,v 1.31 2007/09/17 08:48:39 michael Exp $ s0.8.0N(sLDAPUrlsbasesonessubsu[\w;.-]+(;[\w_-]+)*u(([^,]|\\,)+|".*?")u [ ]*=[ ]*s ([ ]*,[ ]*s)*[ ]*u(dc|)[ ]*=[ ]*u^%s$usdefaultNamingContexts defaultRnrDNs altServersnamingContextsssubschemaSubentryssupportedLDAPVersionssupportedControlssupportedSASLMechanismsssupportedExtensionssupportedFeaturess objectclasss dsServiceNamesogSupportedProfilesnetscapemdsuffixs dataversions dsaVersionsutf-8cCs2gi}|D]}|t||ƒƒq~SdS(s$ return list of Unicode objects N(sappends_[1]slsisunicodescharset(slscharsets_[1]si((s./pylib/ldaputil/base.pys unicode_listFscCs>h}x-|iƒD]\}}t||ƒ|| tuple This function takes a single attribute type and value pair describing a characteristic attribute forming part of a RDN (e.g. 'cn=Michael Stroeder') and returns a 2-tuple containing the attribute type and the attribute value unescaping the attribute value according to RFC 2253 if necessary. s=is\isN( sattr_type_and_valuessplits attr_types attr_valuesrs start_possislensattr_value_lensappendsjoin(sattr_type_and_valuesisattr_value_lensrs attr_values start_poss attr_type((s./pylib/ldaputil/base.pysexplode_rdn_attris   cCsºt|ƒ\}}| ohSnt|ƒtjo|i|ƒ}nh}xat i |i ƒƒD]J}t |ƒ\}}|i|ƒo||i|ƒqd|g||s\>s;s\;s=s\=is#siÿÿÿÿs s\ N(sssreplacesjoin(ss((s./pylib/ldaputil/base.pysescape_dn_chars s!sUSERNAME_NOT_FOUNDcBstZdZd„ZRS(s_ Simple exception class raised when SmartLogin() does not find any entry matching search cCs|iddSdS(Nisdesc(sselfsargs(sself((s./pylib/ldaputil/base.pys__str__%s(s__name__s __module__s__doc__s__str__(((s./pylib/ldaputil/base.pysUSERNAME_NOT_FOUND s sUSERNAME_NOT_UNIQUEcBstZdZd„ZRS(si Simple exception class raised when SmartLogin() does not find more than one entry matching search cCs|iddSdS(Nisdesc(sselfsargs(sself((s./pylib/ldaputil/base.pys__str__-s(s__name__s __module__s__doc__s__str__(((s./pylib/ldaputil/base.pysUSERNAME_NOT_UNIQUE(s s(uid=%s)iiÿÿÿÿc CsF| odSn3t|ƒot|ƒSn|id|ƒ}|tjo d}ny%|i |||dg||ƒ} Wn+tij othdd<ƒ‚nXgi}| D]%} | dtjo|| ƒqµqµ~} | othdd<ƒ‚n?t| ƒdjothdd<ƒ‚nt| ddƒSd S( s‰ Do a smart login. If username is a valid DN it's used as bind-DN without further action. Otherwise filtertemplate is used to construct a LDAP search filter containing username instead of %s. The calling application has to handle all possible exceptions: ldap.NO_SUCH_OBJECT, ldap.FILTER_ERROR, ldapbase.USERNAME_NOT_UNIQUE ldap.INVALID_CREDENTIALS, ldap.INAPPROPRIATE_AUTH ss%ss objectclasssdescs/Smart login did not find a matching user entry.iis$More than one matching user entries.N(susernamesis_dns normalize_dnsfiltertemplatesreplaces searchfilters searchrootsNonesls search_stsscopes attrnamesonlystimeoutsresultsldapsNO_SUCH_OBJECTsUSERNAME_NOT_FOUNDsappends_[1]srslensUSERNAME_NOT_UNIQUE( slsusernames searchrootsfiltertemplatesscopes attrnamesonlystimeouts_[1]s searchfiltersrsresult((s./pylib/ldaputil/base.pys SmartLogin0s.     <c CsdGHhdd<dd<dd<}xK|iƒD]=}t|ƒ}|||jod||||fGHq3q3WdGHhd d <d d <d d <dd<dd<}x]|iƒD]O}t|ƒ}|||jo,dt|ƒt|ƒt||ƒfGHq¹q¹WdGHhdddf<dddf<dddf<dddf<dddf<}x]|iƒD]O}t|ƒ}|||jo,dt|ƒt|ƒt||ƒfGHqoqoWdGHhddfdd f<d!dfdd f<d!dfdd"f<d!d#fdd"f<d!d$fd%d&f<d!d'fd%d&f<}x®|iƒD] \}}t ||ƒ}|d|||fdjp(|diƒ|||fdiƒjo;d(t|ƒt|ƒt|ƒt|||fƒfGHqXqXWd)S(*sTest functionss Testing function is_dn():u o=Michaelsiuiiiiiu "cn="Mike"s%is_dn("%s") returns %d instead of %d.s$ Testing function escape_dn_chars():u #\,+"<>; u\#\\\,\+\"\<\>\;\ s #\,+"<>; s\#\\\,\+\"\<\>\;\ uStrödersStröderss-escape_dn_chars(%s) returns %s instead of %s.s% Testing function explode_rdn_attr():scn=Michael StroederscnsMichael Stroeders cn=whois\+\+swhois++s cn=\#dummy\ s#dummy scn;lang-en-EN=Michael Stroeders cn;lang-en-ENscn=s.explode_rdn_attr(%s) returns %s instead of %s.s Testing function match_dn():s O=MICHAELSs o=michaelsu O=MICHAELSsCN=MICHAEL STROEDER,O=MICHAELSus s" cn=Michael Stroeder,o=Michaels iucn=Michael Stroeder,o=Michaelss<mail=michael@stroeder.com, cn=Michael Stroeder,o=Michaels s+match_dn(%s,%s) returns: %s instead of: %s N(sldap_dnsskeyssldap_dnsis_dns result_is_dnsescape_dn_charssresult_escape_dn_charssreprsexplode_rdn_attrsresult_explode_rdn_attrsmatch_dn_testssdn1sdn2smatch_dnsresult_match_dnslower( sresult_escape_dn_charssldap_dns result_is_dnsresult_match_dnsdn1sdn2sresult_explode_rdn_attrsmatch_dn_testssldap_dns((s./pylib/ldaputil/base.pystestbs:!  3  0Q  0„ Js__main__(.s__doc__s __version__sresldapsldapurlsLDAPUrlsSEARCH_SCOPE_STRs SCOPE_BASEsSCOPE_ONELEVELs SCOPE_SUBTREEs SEARCH_SCOPEsattr_type_patternsattr_value_patterns rdn_patterns dn_patternsdc_rdn_patterns dc_dn_patternscompilesunicodesdn_regexstypes StringTypes UnicodeTypes ROOTDSE_ATTRSs unicode_lists unicode_entrysencode_unicode_listsis_dnsexplode_rdn_attrsrdn_dicts explode_dns normalize_dnsmatching_dn_componentssmatch_dns match_dnlistsextract_referralssParentDNsSplitRDNs ParentDNListsescape_dn_charss LDAPErrorsUSERNAME_NOT_FOUNDsUSERNAME_NOT_UNIQUEs SmartLoginstests__name__($s SEARCH_SCOPEs ROOTDSE_ATTRSs unicode_entrysUSERNAME_NOT_FOUNDs ParentDNLists dn_patternsattr_value_patterns StringTypes SmartLoginsLDAPUrlsParentDNsmatch_dnsSEARCH_SCOPE_STRsresdc_rdn_patternsattr_type_patternsldaps unicode_lists normalize_dns __version__sSplitRDNsencode_unicode_listsmatching_dn_componentsstestsextract_referralss match_dnlistsUSERNAME_NOT_UNIQUEs rdn_patternsrdn_dicts dc_dn_patternsexplode_rdn_attrs UnicodeTypesdn_regexsis_dns explode_dnsescape_dn_chars((s./pylib/ldaputil/base.pys?sJ 6    <         2 D