private static bool InExcludeGroups(string user) { bool contains = false; if (Global.Config.ExcludeGroups != null) { var u = DomainUser.Parse(user); if (u.IsLocal) { string[] groups = UserAccess.GetLocalUserGroups(u.Name); contains = Global.Config.ExcludeGroups.Any( s => groups.Any( g => string.Equals(s, g, StringComparison.OrdinalIgnoreCase))); } else if (Global.Config.ADValid) { var exclude = Global.Config.ExcludeGroups .Select(s => DomainGroup.Parse(s)) .Where(g => string.Equals(u.Domain, g.Domain, StringComparison.OrdinalIgnoreCase)) .Select(g => g.Name); if (exclude.Any()) { var ldap = new LdapAccess(Global.Config.ADPath, Global.Config.ADUser, Global.Config.ADPasswordValue, Global.Config.ADOrganization); var groups = ldap.GetUserGroups(u.Name); contains = exclude.Any(s => groups.Any(g => string.Equals(s, g, StringComparison.OrdinalIgnoreCase))); } } } return(contains); }
public static string[] GetLocalGroupMembers(string groupname) { int read; int total; int resume; IntPtr pbuf; int ret = netapi.NetLocalGroupGetMembers(null, groupname, 3, out pbuf, -1, out read, out total, out resume); if (ret != 0) { throw new Win32Exception(ret); } List <string> members = new List <string>(); if (read > 0) { var m = new LOCALGROUP_MEMBERS_INFO_3(); IntPtr pItem = pbuf; for (int i = 0; i < read; ++i) { Marshal.PtrToStructure(pItem, m); pItem = new IntPtr(pItem.ToInt64() + Marshal.SizeOf(typeof(LOCALGROUP_MEMBERS_INFO_3))); members.Add(DomainUser.Parse(m.domainandname).ToString()); } } netapi.NetApiBufferFree(pbuf); return(members.ToArray()); }