public bool GetGroups(string _filterAttribute, string _path, string ldapGroup)
{
DirectorySearcher search = new DirectorySearcher(_path);
search.Filter = "(cn=" + _filterAttribute + ")";
search.PropertiesToLoad.Add("memberOf");
try
{
SearchResult result = search.FindOne();
int propertyCount = result.Properties["memberOf"].Count;
String dn;
int equalsIndex, commaIndex;
for (int propertyCounter = 0; propertyCounter < propertyCount;
propertyCounter++)
{
dn = (String)result.Properties["memberOf"][propertyCounter];
equalsIndex = dn.IndexOf("=", 1);
commaIndex = dn.IndexOf(",", 1);
if (-1 == equalsIndex)
{
return false;
}
if (String.Equals(ldapGroup, dn.Substring((equalsIndex + 1),
(commaIndex - equalsIndex) - 1), StringComparison.CurrentCultureIgnoreCase))
{
return true;
}
}
}
catch (Exception ex)
{
Logger.Log("Error obtaining group names. " + ex.Message);
return false;
}
return false;
}