Example #1
0
        public static string CreateDecoratedUser(string id, string password)
        {
            var windowsUsername = GenerateDecoratedUsername(id);

            WindowsUsersAndGroups.CreateUser(windowsUsername, password, GenrateUserDescription(id));

            return(windowsUsername);
        }
Example #2
0
        public void Create()
        {
            if (this.created)
            {
                throw new InvalidOperationException("This user has already been created.");
            }

            if (WindowsUsersAndGroups.ExistsUser(this.username))
            {
                throw new InvalidOperationException("This windows user already exists.");
            }

            WindowsUsersAndGroups.CreateUser(this.username, this.password);
            Persistence.SaveValue("prison_users", this.username, this.password);
            this.created = true;
        }
        public void BasicTest()
        {
            string rnd       = (DateTime.Now.Ticks % 100).ToString();
            string userbase  = "UhuruTestUser" + rnd;
            string user1     = userbase + "1";
            string user2     = userbase + "2";
            string groupbase = "UhuruTestGroup" + rnd;
            string group1    = groupbase + "1";
            string group2    = groupbase + "2";

            // test users
            WindowsUsersAndGroups.CreateUser(user1, "test1234#");
            WindowsUsersAndGroups.CreateUser(user2, "test1234#", "Delete me pls...");

            using (new UserImpersonator(user2, "", "test1234#", true))
            {
            }
            UserImpersonator.DeleteUserProfile(user2, "");

            Assert.IsTrue(WindowsUsersAndGroups.ExistsUser(user2));
            Assert.IsTrue(WindowsUsersAndGroups.GetUsers().Contains(user2));

            WindowsUsersAndGroups.DeleteUser(user2);

            Assert.IsFalse(WindowsUsersAndGroups.GetUsers().Contains(user2));
            Assert.IsFalse(WindowsUsersAndGroups.ExistsUser(user2));

            // test groups
            WindowsUsersAndGroups.CreateGroup(group1);
            WindowsUsersAndGroups.CreateGroup(group2, "delete me too...");

            Assert.IsTrue(WindowsUsersAndGroups.ExistsGroup(group2));
            Assert.IsTrue(WindowsUsersAndGroups.GetGroups().Contains(group2));
            WindowsUsersAndGroups.DeleteGroup(group2);
            Assert.IsFalse(WindowsUsersAndGroups.GetGroups().Contains(group2));
            Assert.IsFalse(WindowsUsersAndGroups.ExistsGroup(group2));

            // test users and groups
            Assert.IsFalse(WindowsUsersAndGroups.IsUserMemberOfGroup(user1, group1));
            WindowsUsersAndGroups.AddUserToGroup(user1, group1);
            Assert.IsTrue(WindowsUsersAndGroups.IsUserMemberOfGroup(user1, group1));
            WindowsUsersAndGroups.RemoveUserFromGroup(user1, group1);
            Assert.IsFalse(WindowsUsersAndGroups.IsUserMemberOfGroup(user1, group1));

            WindowsUsersAndGroups.DeleteGroup(group1);
            WindowsUsersAndGroups.DeleteUser(user1);
        }
        public void Create()
        {
            if (this.created)
            {
                throw new InvalidOperationException("This user has already been created.");
            }

            if (WindowsUsersAndGroups.UserExists(this.username))
            {
                throw new InvalidOperationException("This windows user already exists.");
            }

            WindowsUsersAndGroups.CreateUser(this.username, this.password);

            this.userSID = WindowsUsersAndGroups.GetLocalUserSid(this.username);

            this.created = true;
        }
Example #5
0
        public void Create()
        {
            if (this.created)
            {
                throw new InvalidOperationException("This user has already been created.");
            }

            if (WindowsUsersAndGroups.ExistsUser(this.username))
            {
                throw new InvalidOperationException("This windows user already exists.");
            }

            WindowsUsersAndGroups.CreateUser(this.username, this.password);

            this.userSID = new NTAccount(null, this.username).Translate(typeof(SecurityIdentifier)).Value;

            Persistence.SaveValue("prison_users", this.username, this.password);
            this.created = true;
        }
        public void StressTest()
        {
            int n = 200;

            string rnd       = (DateTime.Now.Ticks % 100).ToString();
            string userbase  = "UTestUser" + rnd;
            string user1     = userbase + "1";
            string user2     = userbase + "2";
            string groupbase = "UTestGroup" + rnd;
            string group1    = groupbase + "1";
            string group2    = groupbase + "2";

            for (int i = 0; i < n; i++)
            {
                WindowsUsersAndGroups.CreateUser(user1 + i.ToString(), "test1234#");
                WindowsUsersAndGroups.CreateUser(user2 + i.ToString(), "test1234#", "Delete me pls...");
                WindowsUsersAndGroups.DeleteUser(user2 + i.ToString());

                WindowsUsersAndGroups.CreateGroup(group1 + i.ToString());
                WindowsUsersAndGroups.CreateGroup(group2 + i.ToString(), "delete me too...");
                WindowsUsersAndGroups.DeleteGroup(group2 + i.ToString());
            }

            for (int i = 0; i < n; i++)
            {
                Assert.IsFalse(WindowsUsersAndGroups.IsUserMemberOfGroup(user1 + i.ToString(), group1 + i.ToString()));
                WindowsUsersAndGroups.AddUserToGroup(user1 + i.ToString(), group1 + i.ToString());
                Assert.IsTrue(WindowsUsersAndGroups.IsUserMemberOfGroup(user1 + i.ToString(), group1 + i.ToString()));
                WindowsUsersAndGroups.RemoveUserFromGroup(user1 + i.ToString(), group1 + i.ToString());
                Assert.IsFalse(WindowsUsersAndGroups.IsUserMemberOfGroup(user1 + i.ToString(), group1 + i.ToString()));
            }

            bool      fail = false;
            Exception ex   = null;

            for (int i = 0; i < n; i++)
            {
                try
                {
                    WindowsUsersAndGroups.DeleteGroup(group1 + i.ToString());
                }
                catch (Exception e)
                {
                    ex   = e;
                    fail = true;
                }

                try
                {
                    WindowsUsersAndGroups.DeleteUser(user1 + i.ToString());
                }
                catch (Exception e)
                {
                    ex   = e;
                    fail = true;
                }
            }

            if (fail)
            {
                throw ex;
            }
        }