Exemplo n.º 1
0
 public IEnumerable <IdentitySourceItem> GetAllIdentities()
 {
     foreach (var unixUser in UnixUserInfo.GetLocalUsers())
     {
         yield return(new IdentitySourceItem()
         {
             DisplayName = unixUser.RealName, UserName = unixUser.UserName
         });
     }
 }
Exemplo n.º 2
0
 public void ListAllUsers_ToString()
 {
     try {
         Console.WriteLine("Listing all users");
         foreach (UnixUserInfo user in UnixUserInfo.GetLocalUsers())
         {
             Console.WriteLine("\t{0}", user);
         }
     }
     catch (Exception e) {
         Assert.Fail(
             string.Format("#TLAU_TS: Exception listing local users: {0}",
                           e.ToString()));
     }
 }
Exemplo n.º 3
0
        public bool Authorize(string Username, string Password)
        {
            CheckSystemType();
            var users = UnixUserInfo.GetLocalUsers();
            var user  = users.FirstOrDefault(a => a.UserName == Username && a.Password == Password);

            authenticated = (user == null);

            if (user == null)
            {
                return(false);
            }

            UserDir = user.HomeDirectory;

            return(authenticated);
        }
Exemplo n.º 4
0
        public void NonReentrantSyscalls()
        {
            ArrayList user_ids = new ArrayList(4);
            IList     users    = UnixUserInfo.GetLocalUsers();

            foreach (UnixUserInfo user in users)
            {
                try
                {
                    Passwd byName = Syscall.getpwnam(user.UserName);
                    Assert.IsNotNull(byName, "#TNRS: access by name");
                    UnixUserInfo n = new UnixUserInfo(byName);
                    Assert.AreEqual(user, n, "#TNRS: construct by name");

                    if (!user_ids.Contains(user.UserId))
                    {
                        user_ids.Add(user.UserId);
                    }
                }
                catch (Exception e)
                {
                    Assert.Fail(
                        string.Format("#TNRS: Exception constructing UnixUserInfo (string): {0}",
                                      e.ToString()));
                }
            }

            foreach (long uid in user_ids)
            {
                try
                {
                    Passwd byId = Syscall.getpwuid(Convert.ToUInt32(uid));
                    Assert.IsNotNull(byId, "#TNRS: access by uid");

                    UnixUserInfo u = new UnixUserInfo(byId);
                    Assert.IsTrue(users.Contains(u), "TNRS: construct by uid");
                }
                catch (Exception e)
                {
                    Assert.Fail(
                        string.Format("#TNRS: Exception constructing UnixUserInfo (uint): {0}",
                                      e.ToString()));
                }
            }
        }
Exemplo n.º 5
0
        public void ReentrantConstructors()
        {
            ArrayList user_ids = new ArrayList(4);
            IList     users    = UnixUserInfo.GetLocalUsers();

            foreach (UnixUserInfo user in users)
            {
                try
                {
                    UnixUserInfo byName = new UnixUserInfo(user.UserName);
                    Assert.AreEqual(user, byName, "#TRC: construct by name");

                    if (!user_ids.Contains(user.UserId))
                    {
                        user_ids.Add(user.UserId);
                    }
                }
                catch (Exception e)
                {
                    Assert.Fail(
                        string.Format("#TRC: Exception constructing UnixUserInfo (string): {0}",
                                      e.ToString()));
                }
            }

            foreach (uint uid in user_ids)
            {
                try
                {
                    UnixUserInfo byId = new UnixUserInfo(uid);
                    Assert.IsTrue(users.Contains(byId), "TRC: construct by uid");
                }
                catch (Exception e)
                {
                    Assert.Fail(
                        string.Format("#TRC: Exception constructing UnixUserInfo (uint): {0}",
                                      e.ToString()));
                }
            }
        }