Comment 7 for bug 1493335

Revision history for this message
Dmzavr (dmzavr) wrote :

Robert, yes, it works and is what i want, exactly.
There is small issue, however. - Primary groups didn''t supported in current code. So, for example, if user1 has 'group1' as its primary group (set in /etc/passwd) he will be filtered out. Can you please improve in_group () method with smth like:

    private bool in_group (string group_name, string user_name)
    {
        unowned Posix.Group? group = Posix.getgrnam (group_name);
        if (group == null)
            return false;

        /* Check if user has group_name as it's primary group */
        unowned Posix.Passwd? pw = Posix.getpwnam( user_name );
        if( pw.pw_gid == group.gr_gid )
            return true;

        /* Check if group_name is user's auxilary group */
        foreach (var name in group.gr_mem)
            if (name == user_name)
                return true;

        return false;
    }