private bool DoesACLBelongToUser(ManagementBaseObject daclTrustee, string userTrusteeName, WmiDataProvider wmiProvider)
        {
            var winTrustee = this.getWinTrusteeFromManagementObject(daclTrustee);
            if (userTrusteeName.Equals(winTrustee.SIDString))
                return true;

            string username = this.getPropertyValueAsString(daclTrustee, "Name");
            var wql = new WQLBuilder().WithWmiClass("Win32_Account").AddParameter("SID", userTrusteeName).Build();
            var accountName = wmiProvider.ExecuteWQL(wql);

            if ((accountName.Count() > 0) && accountName.First().GetValueOf("Name").ToString().Equals(username, StringComparison.InvariantCultureIgnoreCase))
                return true;

            string userDomain = this.getPropertyValueAsString(daclTrustee, "Domain");
            string[] trusteeParts = userTrusteeName.Split(new string[] { @"\" }, StringSplitOptions.RemoveEmptyEntries);

            bool matchUsername = username.Equals(trusteeParts.Last(), StringComparison.CurrentCultureIgnoreCase);
            bool matchUserDomain = userDomain.Equals(trusteeParts.First(), StringComparison.CurrentCultureIgnoreCase);

            bool isSystemAccount = (userTrusteeName.IndexOf(@"\") < 0);
            return isSystemAccount ? matchUsername : (matchUsername && matchUserDomain);
        }
Ejemplo n.º 2
0
 private void CreateExpectationForGetGroupComponent(WmiDataProvider fakeWmiProvider, string groupName)
 {
     var fakeWin32GroupUserRecords = new List<WmiObject>();
     var groupComponent = GroupComponent(FAKE_COMPUTER_NAME, groupName);
     var wqlAdministratorsUsers = new WQLBuilder().WithWmiClass("Win32_GroupUser").AddParameter("GroupComponent", groupComponent).Build();
     Expect.Call(fakeWmiProvider.ExecuteWQL(wqlAdministratorsUsers)).Return(new[] { NewWmiObjectForFakeGroupUser("fakeUser") });
 }