
    =OOfF                     R    d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
 d Zd Zd	 Zy
)
   )edir_add_members_to_groups   )LDAPInvalidDnError)SEQUENCE_TYPESBASEDEREF_NEVER)safe_dnc           	         t        |t              s|g}t        |t              s|g}d}|D ]3  }| j                  |dt        t        ddg      }| j
                  j                  s| j                  |      \  }}n6| j
                  j                  r|\  }}}}n| j                  }| j                  }|d   dk(  st        |dz         d|d	   d
   v r|d	   d
   d   ng }d|d	   d
   v r|d	   d
   d   ng }	|D 
cg c]  }
|
j                          }}
|	D 
cg c]  }
|
j                          }	}
|D ],  }|j                         |	vr  y|j                         |vs+d}. 6 d|fS c c}
w c c}
w )a  
    :param connection: a bound Connection object
    :param members_dn: the list of members to add to groups
    :param groups_dn: the list of groups where members are to be added
    :return: two booleans. The first when True means that all members have membership in all groups, The second when True means that
    there are inconsistences in the securityEquals attribute
    Checks user's group membership.
    Raises LDAPInvalidDNError if member is not found in the DIT.
    F(objectclass=*)groupMembershipsecurityEqualsdereference_aliases
attributesdescriptionsuccess
 not found    r   FFT
isinstancer   searchr   r	   strategysyncget_responsethread_saferesultresponser   lower)
connection
members_dn	groups_dnpartialmemberr   r   _existing_security_equalsexisting_group_membershipelementgroups               k/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/ldap3/extend/novell/checkGroupsMemberships.py_check_members_have_membershipsr,   !   s    j.1 \
i0K	G ""6+<dXc  rC  EU  qV"  W""'')66v>Hf""..)/&68Q#**%..m$	1$Vl%:;;Rbfnopfqr~fR8A;|#<=M#N  FH Teiqrsit  vB  jC  UCHQK$=>O$P  IK!C[#\GMMO#\ #\D]$^W]]_$^!$^ 	E{{}$==#{{}$<<		)4 = $]$^   8E&E+c           	         t        |t              s|g}t        |t              s|g}d}|D ]3  }| j                  |dt        t        ddg      }| j
                  j                  s| j                  |      \  }}n6| j
                  j                  r|\  }}}}n| j                  }| j                  }|d   dk(  st        |dz         d|d	   d
   v r|d	   d
   d   ng }d|d	   d
   v r|d	   d
   d   ng }	|D 
cg c]  }
|
j                          }}
|	D 
cg c]  }
|
j                          }	}
|D ],  }|j                         |vr  y|j                         |	vs+d}. 6 d|fS c c}
w c c}
w )a  
    :param connection: a bound Connection object
    :param members_dn: the list of members to add to groups
    :param groups_dn: the list of groups where members are to be added
    :return: two booleans. The first when True means that all members have membership in all groups, The second when True means that
    there are inconsistences in the EquivalentToMe attribute
    Checks if groups have members in their 'member' attribute.
    Raises LDAPInvalidDNError if member is not found in the DIT.
    Fr   r%   equivalentToMer   r   r   r   r   r   r   Tr   )r!   r#   r"   r$   r*   r   r   r&   existing_membersexisting_equivalent_to_mer)   r%   s               r+   _check_groups_contain_membersr2   Q   s    i0K	j.1 \
G ""5*;TWbpx  {K  pL"  M""'')66v>Hf""..)/&68Q#**%..m$	1$U\%9::BJhWXkZfNgBg8A;|4X>moScgopqgrs  hA  TAHQK$=>N$O  GI!;KLGMMOLLD]$^W]]_$^!$^  	F||~%55#||~%>>		'2 = M$^r-   c           	         t        |t              s|g}t        |t              s|g}| j                  rJg }g }|D ]  }|j                  t	        |              |D ]  }|j                  t	        |              |}|}	 t        | ||      \  }	}
t        | ||      \  }}|	s|sy|r)|	r|r|r|	r|s|
r|D ]  }|D ]  }t        | ||d|         y# t        $ r Y yw xY w)a  
    :param connection: a bound Connection object
    :param members_dn: the list of members to check
    :param groups_dn: the list of groups to check
    :param fix: checks for inconsistences in the users-groups relation and fixes them
    :param transaction: activates an LDAP transaction when fixing
    :return: a boolean where True means that the operation was successful and False means an error has happened
    Checks and fixes users-groups relations following the eDirectory rules: groups are checked against 'groupMembership'
    attribute in the member object while members are checked against 'member' attribute in the group object.
    Raises LDAPInvalidDnError if members or groups are not found in the DIT.
    FT)	r   r   check_namesappendr
   r,   r2   r   r   )r!   r"   r#   fixtransactionsafe_members_dnsafe_groups_dn	member_dngroup_dnmembers_have_membershipspartial_member_securitygroups_contain_memberspartial_group_securityr%   r*   s                  r+   edir_check_groups_membershipsr@      s*     i0K	j.1 \
# 	7I""79#56	7! 	5H!!'("34	5 %
"	<[\fhrt}<~9 "99VWaclnx9y6 6 $,B
$-C*3K)*$ ]& ]E.z65$P[\]] !  s   > C 	CCN)__doc__addMembersToGroupsr   core.exceptionsr    r   r   r	   utils.dnr
   r,   r2   r@        r+   <module>rH      s,   4 ; 1 1 1 -`,^4rG   