Esempio n. 1
0
        /// <summary>
        /// Gets all groups and users from target.
        /// </summary>
        /// <returns>
        /// It returns a list of WindowsAccount struct where each element represents a user or group account.
        /// </returns>
        public virtual IEnumerable<WindowsAccount> GetAllGroupsAndUsers()
        {
            var allUsers = new Dictionary<string, WindowsAccount>();
            var allLocalGroups = GetAllUsersByGroup();

            foreach (var group in allLocalGroups)
            {
                allUsers.Add(group.Name, group);

                if (group.Members == null)
                    continue;

                foreach (var user in group.Members)
                {
                    if (!allUsers.ContainsKey(user.Name))
                    {
                        var newUserAccount = new WindowsAccount(user.Name, user.Enabled, user.AccountSID, AccountType.User);
                        allUsers.Add(user.Name, newUserAccount);
                    }
                }
            }

            var allBuiltinAccounts = this.GetAllBuiltinAccounts();
            foreach (var builtinAccount in allBuiltinAccounts)
                if (!allUsers.ContainsKey(builtinAccount.Name))
                    allUsers.Add(builtinAccount.Name, builtinAccount);

            return allUsers.Select(user => user.Value);
        }
Esempio n. 2
0
        public void AddMember(string accountName, bool?accountEnabled, string accountSID)
        {
            if (this.Members == null)
            {
                this.Members = new List <WindowsAccount>();
            }

            if (this.HasMember(accountName))
            {
                return;
            }

            var newMember = new WindowsAccount(accountName, accountEnabled, accountSID, GetMemberAccount());

            ((List <WindowsAccount>) this.Members).Add(newMember);
        }
Esempio n. 3
0
        /// <summary>
        /// It gets all local users (and its groups) from target.
        /// </summary>
        /// <returns>
        /// It returns a list of WindowsAccount struct where each element represents a user account.
        /// In order to access user groups, use the Members property.
        /// </returns>
        public virtual IEnumerable <WindowsAccount> GetAllGroupByUsers()
        {
            var allUsers = new Dictionary <string, WindowsAccount>();

            var allUsersByGroup = GetAllUsersByGroup();

            foreach (var group in allUsersByGroup)
            {
                if (group.Members == null)
                {
                    continue;
                }

                foreach (var user in group.Members)
                {
                    if (allUsers.ContainsKey(user.Name))
                    {
                        allUsers[user.Name].AddMember(group.Name, group.Enabled, group.AccountSID);
                    }
                    else
                    {
                        var newUserAccount = new WindowsAccount(user.Name, user.Enabled, user.AccountSID, AccountType.User);
                        newUserAccount.AddMember(group.Name, group.Enabled, group.AccountSID);
                        allUsers.Add(user.Name, newUserAccount);
                    }
                }
            }

            var allBuiltinAccounts = this.GetAllBuiltinAccounts();

            foreach (var builtinAccount in allBuiltinAccounts)
            {
                if (!allUsers.ContainsKey(builtinAccount.Name))
                {
                    allUsers.Add(builtinAccount.Name, builtinAccount);
                }
            }

            return(allUsers.Select(user => user.Value));
        }
Esempio n. 4
0
 private WindowsAccount NewGuestAccount()
 {
     var guestAccount = new WindowsAccount("Guest", false, "", AccountType.User);
     guestAccount.AddMember("group1", true, "");
     guestAccount.AddMember("group2", null, "");
     return guestAccount;
 }
Esempio n. 5
0
 private WindowsAccount NewEveryoneAccount()
 {
     var everyoneAccount = new WindowsAccount("Everyone", true, "", AccountType.User);
     everyoneAccount.AddMember("group1", true, "");
     return everyoneAccount;
 }
        private UserSID55ObjectCollector CreateMockedObjectCollector(WindowsAccount fakeUserAccount)
        {
            var fakeWindowsAccounts = new List<WindowsAccount>();
            if (fakeUserAccount != null)
                fakeWindowsAccounts.Add(fakeUserAccount);

            var mocks = new MockRepository();
            var fakeUserProvider = mocks.DynamicMock<WindowsUsersProvider>(null, null);
            Expect.Call(fakeUserProvider.GetAllGroupByUsers()).Return(fakeWindowsAccounts);
            mocks.ReplayAll();

            return new UserSID55ObjectCollector(fakeUserProvider);
        }
 private WindowsAccount GetFakeWindowsAccount(bool userEnabled, string[] fakeUserGroups)
 {
     var fakeUserAccount = new WindowsAccount("Fake User", (bool?)userEnabled, "S-1-18", AccountType.User);
     foreach (var fakeGroup in fakeUserGroups)
         fakeUserAccount.AddMember(string.Format("Fake Group {0}", fakeGroup), (bool?)true, fakeGroup);
     
     return fakeUserAccount;
 }
 private void AssertCollectedWindowsAccount(WindowsAccount accountToAssert, string expectedAccountName, bool? accountMustBeEnabled = null)
 {
     Assert.IsNotNull(accountToAssert, "The result cannot be null.");
     Assert.AreEqual(AccountType.User, accountToAssert.AccountType, "Unexpected windows user account type was found.");
     Assert.AreEqual(expectedAccountName, accountToAssert.Name, "Unexpected user account name was found.");
     Assert.AreEqual(accountMustBeEnabled, accountToAssert.Enabled, "Unexpected user account status.");
 }
Esempio n. 9
0
        public void AddMember(string accountName, bool? accountEnabled, string accountSID)
        {
            if (this.Members == null)
                this.Members = new List<WindowsAccount>();

            if (this.HasMember(accountName))
                return;

            var newMember = new WindowsAccount(accountName, accountEnabled, accountSID, GetMemberAccount());
            ((List<WindowsAccount>)this.Members).Add(newMember);
        }
Esempio n. 10
0
        private ItemType CreateUserItemFromWindowsAccount(WindowsAccount windowsAccount)
        {
            var groups = new EntityItemStringType[] { new EntityItemStringType() { status = StatusEnumeration.doesnotexist } };
            if (windowsAccount.Members.HasItems())
                groups = windowsAccount.Members.Select(g => new EntityItemStringType() { Value = g.Name }).ToArray();

            return new user_item()
            {
                status = StatusEnumeration.exists,
                user = OvalHelper.CreateItemEntityWithStringValue(windowsAccount.Name),
                enabled = OvalHelper.CreateBooleanEntityItemFromBoolValue(windowsAccount.Enabled),
                group = groups
            };
        }