'Returns True if the group is the user\'s primary group or if the user is
listed in the group\'s memberUid attribute.'

def is_member(self, ldap_user, group_dn):

    try:
        user_uid = ldap_user.attrs['uid'][0]
        try:
            is_member = ldap_user.connection.compare_s(force_str(group_dn), 'memberUid', force_str(user_uid))
        except (ldap.UNDEFINED_TYPE, ldap.NO_SUCH_ATTRIBUTE):
            is_member = False
        if (not is_member):
            try:
                user_gid = ldap_user.attrs['gidNumber'][0]
                is_member = ldap_user.connection.compare_s(force_str(group_dn), 'gidNumber', force_str(user_gid))
            except (ldap.UNDEFINED_TYPE, ldap.NO_SUCH_ATTRIBUTE):
                is_member = False
    except (KeyError, IndexError):
        is_member = False
    return is_member
