mò
s…	Gc           @   sÇ   d  k  Z  d  k Z d  k Z e  i d ƒ Z e i d d ƒ d „  Z d „  Z d „  Z d „  Z	 e
 d j oX e d d	 ƒ GHe d d
 ƒ GHe d d ƒ GHe	 d d ƒ GHe	 d d ƒ GHe	 d d ƒ GHn d  S(   Ns   W92-130-LDAP-2.mit.edut    c         c   so   xh t  i d t i d |  g  ƒ D]G } x> t  i d t i d | d d g ƒ D] } | d d d VqM Wq  Wd S(	   s^   
    getldapgroups(user): returns a generator for the list of LDAP groups containing user
    s   ou=affiliates,dc=mit,dc=edus   uid=s   ou=groups,dc=mit,dc=edus   uniqueMember=i    t   cni   N(   t   lt   search_st   ldapt   SCOPE_ONELEVELt   usert	   user_datat
   group_data(   R   R   R   (    (    t   getgroups.pyt   getldapgroups   s       ' c         C   sl   xe t  i d t i d |  g  ƒ D]D } t  i d t i d | d | d d g  ƒ g  j o t Sq  q  Wt S(	   s_   
    checkldapgroups(user, group): returns True if and only if user is in LDAP group group
    s   ou=affiliates,dc=mit,dc=edus   uid=s   ou=groups,dc=mit,dc=edus   (&(cn=s   )(uniqueMember=i    s   ))N(	   R   R   R   R   R   t   result_datat   groupt   Truet   False(   R   R   R   (    (    R	   t   checkldapgroup   s       6c         C   s´   |  G| GHt i d d | g d t i d t i ƒ} t i d d d g d | i d t i d t i ƒ} | i ƒ  o t	 Sn x2 | i i
 ƒ  i ƒ  D] } | |  j o t Sq‘ q‘ Wt	 S(
   s[   
    checkafsgroup(user, group) returns True if and only if user is in AFS group group
    t   ptst
   membershipt   stdoutt   stderrt   greps   -vs   ^Memberst   stdinN(   R   R   t
   subprocesst   Popent   PIPEt   pR   t   p2t   waitR   t   readt   splitt   memberR   (   R   R   R   R   R   (    (    R	   t   checkafsgroup   s     	*3 c         C   sÑ   t  i d d d | g d t  i d t  i ƒ} t  i d d g d | i d t  i d t  i ƒ} | i ƒ  o t Sn xW | i i	 ƒ  i
 ƒ  D]@ } | |  j o t Sn | d	 j o t |  | ƒ o t Sq‰ q‰ Wt S(   s\   
    checklockerowner(user, locker) returns True if and only if user administers locker
    t   fst   listacls   /mit/R   R   R   s   ^  .* rlidwka$R   t   rlidwkaN(   R   R   t   lockerR   R   R   R   R   R   R   R   t   entryR   R   R   (   R   R#   R   R   R$   (    (    R	   t   checklockerowner*   s     .0 t   __main__t   tabbotts   system:debathenas   system:debathena-roots   system:hmmt-requestt   scriptst   ecpricet   hmmt(   R   t   pprintR   t   openR   t   simple_bind_sR
   R   R   R%   t   __name__(   R
   R   R+   R   R   R%   R   R   (    (    R	   t   ?   s   								