/// <summary>Refresh the netgroup cache</summary>
        /// <exception cref="System.IO.IOException"/>
        public override void CacheGroupsRefresh()
        {
            IList <string> groups = NetgroupCache.GetNetgroupNames();

            NetgroupCache.Clear();
            CacheGroupsAdd(groups);
        }
        /// <summary>Gets unix groups and netgroups for the user.</summary>
        /// <remarks>
        /// Gets unix groups and netgroups for the user.
        /// It gets all unix groups as returned by id -Gn but it
        /// only returns netgroups that are used in ACLs (there is
        /// no way to get all netgroups for a given user, see
        /// documentation for getent netgroup)
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        public override IList <string> GetGroups(string user)
        {
            // parent gets unix groups
            IList <string> groups = new List <string>(base.GetGroups(user));

            NetgroupCache.GetNetgroups(user, groups);
            return(groups);
        }
Пример #3
0
        public virtual void TestUserRemoval()
        {
            IList <string> users = new AList <string>();

            users.AddItem(User1);
            users.AddItem(User2);
            NetgroupCache.Add(Group1, users);
            VerifyGroupMembership(User1, 1, Group1);
            VerifyGroupMembership(User2, 1, Group1);
            users.Remove(User2);
            NetgroupCache.Clear();
            NetgroupCache.Add(Group1, users);
            VerifyGroupMembership(User1, 1, Group1);
            VerifyGroupMembership(User2, 0, null);
        }
Пример #4
0
        public virtual void TestMembership()
        {
            IList <string> users = new AList <string>();

            users.AddItem(User1);
            users.AddItem(User2);
            NetgroupCache.Add(Group1, users);
            users = new AList <string>();
            users.AddItem(User1);
            users.AddItem(User3);
            NetgroupCache.Add(Group2, users);
            VerifyGroupMembership(User1, 2, Group1);
            VerifyGroupMembership(User1, 2, Group2);
            VerifyGroupMembership(User2, 1, Group1);
            VerifyGroupMembership(User3, 1, Group2);
        }
 /// <summary>Add a group to cache, only netgroups are cached</summary>
 /// <param name="groups">list of group names to add to cache</param>
 /// <exception cref="System.IO.IOException"/>
 public override void CacheGroupsAdd(IList <string> groups)
 {
     foreach (string group in groups)
     {
         if (group.Length == 0)
         {
         }
         else
         {
             // better safe than sorry (should never happen)
             if (group[0] == '@')
             {
                 if (!NetgroupCache.IsCached(group))
                 {
                     NetgroupCache.Add(group, GetUsersForNetgroup(group));
                 }
             }
         }
     }
 }
Пример #6
0
        private void VerifyGroupMembership(string user, int size, string group)
        {
            IList <string> groups = new AList <string>();

            NetgroupCache.GetNetgroups(user, groups);
            Assert.Equal(size, groups.Count);
            if (size > 0)
            {
                bool present = false;
                foreach (string groupEntry in groups)
                {
                    if (groupEntry.Equals(group))
                    {
                        present = true;
                        break;
                    }
                }
                Assert.True(present);
            }
        }
Пример #7
0
 public virtual void Teardown()
 {
     NetgroupCache.Clear();
 }