本文整理汇总了C#中System.DirectoryServices.DirectorySearcher.FindAll方法的典型用法代码示例。如果您正苦于以下问题:C# DirectorySearcher.FindAll方法的具体用法?C# DirectorySearcher.FindAll怎么用?C# DirectorySearcher.FindAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.DirectoryServices.DirectorySearcher
的用法示例。
在下文中一共展示了DirectorySearcher.FindAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: verifyNTuser
public static string verifyNTuser(string userName)
{
DirectoryEntry dEntry = new DirectoryEntry("LDAP://ds.kycourts.net/CN=Users,DC=ds,DC=kycourts,DC=net");
DirectorySearcher dSearch = new DirectorySearcher(dEntry);
dSearch.PageSize = 6000;
dSearch.Filter = "cn="+userName;
dSearch.PropertiesToLoad.Add("cn");
dSearch.PropertiesToLoad.Add("mail");
dSearch.PropertiesToLoad.Add("objectSid");
dSearch.CacheResults = true;
if (dSearch.FindAll().Count > 0)
{
foreach (SearchResult sResultSet in dSearch.FindAll())
{
SecurityIdentifier sid = new SecurityIdentifier((byte[])sResultSet.Properties["objectSid"][0], 0);
string[] namesid = sid.ToString().Split('-');
dEntry.Close();
return sResultSet.Properties["cn"][0].ToString() + ";" + sResultSet.Properties["mail"][0].ToString() + ";" +
namesid[namesid.Length - 1].ToString();
}
}
else
{
dEntry.Close();
return "false";
}
return "false";
}
示例2: GetEmailAddress
public static string GetEmailAddress(string userName, string password, string domain)
{
try
{
using (DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain, userName, password))
{
using (DirectorySearcher searcher = new DirectorySearcher(entry))
{
searcher.Filter = string.Format("sAMAccountName={0}", userName);
searcher.PropertiesToLoad.Add("Mail");
SearchResultCollection en = searcher.FindAll();
if (en.Count > 0)
{
return en[0].Properties["Mail"][0].ToString();
}
else
{
return string.Empty;
}
}
}
}
catch (Exception)
{
return string.Empty;
}
}
示例3: checkExchangeVersionInstalled
/// <summary>
/// Get the current Exchange version for the current server from Active Directy (ldap)
/// </summary>
/// <returns></returns>
public static string checkExchangeVersionInstalled()
{
try
{
string domain = System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName;
DirectoryEntry rootDSE = new DirectoryEntry(string.Format("LDAP://{0}/rootDSE", domain));
DirectoryEntry objDirectoryEntry = new DirectoryEntry(string.Format("LDAP://{0}/{1}", domain, rootDSE.Properties["configurationNamingContext"].Value.ToString()));
DirectorySearcher searcher = new DirectorySearcher(objDirectoryEntry, "(&(objectClass=msExchExchangeServer))");
SearchResultCollection col = searcher.FindAll();
string version = string.Empty;
foreach (SearchResult result in col)
{
DirectoryEntry user = result.GetDirectoryEntry();
if (String.Equals(user.Properties["name"].Value.ToString(), Dns.GetHostName(), StringComparison.InvariantCultureIgnoreCase))
{
version = user.Properties["serialNumber"].Value.ToString();
break;
}
}
return version != string.Empty ? version : "Not installed";
}
catch (Exception)
{
return "Not installed";
}
}
示例4: UserSever
/// <summary>
/// Retorna listado de usarios almacenado en servidor
/// iP= 192.168.0.5
/// </summary>
/// <returns></returns>
public List<EntiServerUser> UserSever()
{
try
{
DirectoryEntry LdapConnection = createDirectoryEntry();
DirectorySearcher ds = new DirectorySearcher(LdapConnection);
ds.Filter = "(&(objectClass=user))";
SearchResultCollection result = ds.FindAll();
if (result != null)
{
for (int i = 0; i < result.Count; i++)
{
EntiServerUser us = new EntiServerUser();
us.user = result[i].Properties["userPrincipalName"][0].ToString();
us.name = result[i].Properties["CN"][0].ToString();
user.Add(us);
}
return user;
}
else
{
return null;
}
}
catch (DirectoryServicesCOMException){
throw;
}
catch (InvalidOperationException){
throw;
}
catch (NotSupportedException){
throw;
}
}
示例5: EnumerateGroups
/// <summary>
/// Enumerates the groups.
/// </summary>
/// <param name="domain">The domain.</param>
/// <returns></returns>
public static List<Group> EnumerateGroups(string domain)
{
List<Group> groups = new List<Group>();
try
{
DirectoryEntry directoryObject = new DirectoryEntry("LDAP://" + domain);
DirectorySearcher searcher = new DirectorySearcher(directoryObject);
searcher.Filter = "(ObjectCategory=group)";
foreach (SearchResult result in searcher.FindAll())
{
groups.Add(new Group(result.GetDirectoryEntry().Name.Replace("CN=", string.Empty), result.GetDirectoryEntry().Path));
}
directoryObject.Close();
directoryObject.Dispose();
}
catch (DirectoryServicesCOMException e)
{
Console.WriteLine("An Error Occurred: " + e.Message.ToString());
}
groups.Sort();
return groups;
}
示例6: FindGroups
/// <summary>
/// Возвращает все группы из AD, имена которых удовлетворяют заданному фильтру
/// </summary>
/// <param name="groupFilter">Фильтр по имени группы.</param>
/// <param name="args"></param>
/// <returns></returns>
public ADGroupCollection FindGroups( string groupFilter )
{
try
{
using (DirectoryEntry entry = new DirectoryEntry( _groupPath, LdapUserName,
ConfigurationManager.AppSettings["LdapPassword"] ))
using (DirectorySearcher searcher = new DirectorySearcher( entry ))
{
searcher.SearchScope = SearchScope.Subtree;
searcher.Filter = String.Format( @"(&(objectCategory=group)(name={0}))", groupFilter );
ADGroupCollection groups = new ADGroupCollection();
try
{
foreach (SearchResult result in searcher.FindAll())
groups.Add( new ADGroup( result ) );
}
catch (ArgumentException) { } // неверная строка поиска
return groups;
}
}
catch (Exception ex)
{
throw new CoreApplicationException(Resources.ResourceManager.GetString("ErrorSearchingGroupException"), ex);
}
}
示例7: Search
public KeyValuePair<String, String>[] Search(string path, string[] properties, string filter) {
List<KeyValuePair<string, string>> result = new List<KeyValuePair<string, string>>();
using (DirectoryEntry deRoot = new DirectoryEntry(M_AD + path, M_USER, M_PASSWORD, AuthenticationTypes.Secure)) {
using (DirectorySearcher search = new DirectorySearcher(deRoot, filter)) {
SearchResultCollection src = search.FindAll();
if (src != null) {
foreach (SearchResult sr in src) {
DirectoryEntry de = sr.GetDirectoryEntry();
KeyValuePair<string, string> dict = new KeyValuePair<string, string>();
foreach (string prop in properties) {
string val = "";
if (de.Properties.Contains(prop)) {
if (de.Properties[prop].Value.GetType() == typeof(Object[])) {
val = String.Join(",", (Object[])de.Properties[prop].Value);
}
else {
val = de.Properties.Contains(prop) ? de.Properties[prop].Value.ToString() : String.Empty;
}
}
dict = new KeyValuePair<string, string>(prop, val);
result.Add(dict);
}
de.Close();
}
}
src.Dispose();
}
deRoot.Close();
}
return result.ToArray();
}
示例8: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
// TODO this todo was here for ages
var dc = new DirectoryContext(DirectoryContextType.Domain, "ptsecurity.ru");
var address = Request.Params["address"];
var filter = "Address=" + address;
var result = "";
var domain = Domain.GetDomain(dc);
// this is our vulnerabilitiy of LDAP injection *in this file*
// FIXED: AI issue #3, High, LDAP Injection, https://github.com/SDLTestAccount/IT/issues/3
// GET /Tests/1 INPUT DATA VERIFICATION/9 LDAP Injection/Ldap.aspx?address=%7bfilter%7d+%3d+* HTTP/1.1
// Host:localhost
var ds = new DirectorySearcher(domain.GetDirectoryEntry());//, filter);
using (var src = ds.FindAll())
{
// TODO it was edit here by developer 1 year ago
foreach (var res in src)
{
result = res.ToString();
}
}
// let's go
// this is our first vulnerability of XSS in this file
// we will demonstrate False Positive scenario here (FP Marker)
// FP: AI issue #4, High, Cross-site Scripting, https://github.com/SDLTestAccount/IT/issues/4
// GET /Tests/1 INPUT DATA VERIFICATION/9 LDAP Injection/Ldap.aspx HTTP/1.1
// Host:localhost
// (System.DirectoryServices.DirectorySearcher.FindAll().GetEnumerator().MoveNext() && (System.DirectoryServices.DirectorySearcher.FindAll().GetEnumerator().Current.ToString() == "<script>alert(0)</script>"))
Response.Write(result);
// this is our second vulnerability of XSS in this file
// we will demonstrate what happen if developer fails with his fix (VERIFY Marker)
// FIXED: AI issue #4, High, Cross-site Scripting, https://github.com/SDLTestAccount/IT/issues/4
// GET /Tests/1 INPUT DATA VERIFICATION/9 LDAP Injection/Ldap.aspx HTTP/1.1
// Host:localhost
// (System.DirectoryServices.DirectorySearcher.FindAll().GetEnumerator().MoveNext() && (System.DirectoryServices.DirectorySearcher.FindAll().GetEnumerator().Current.ToString() == "<script>alert(0)</script>"))
Response.Write("result");
// this is our third vulnerability of XSS in this file
// we will demonstrate what happen if we really fix vulnerability (VERIFY Marker)
// FIXED: AI issue #4, High, Cross-site Scripting, https://github.com/SDLTestAccount/IT/issues/4
// GET /Tests/1 INPUT DATA VERIFICATION/9 LDAP Injection/Ldap.aspx HTTP/1.1
// Host:localhost
// (System.DirectoryServices.DirectorySearcher.FindAll().GetEnumerator().MoveNext() && (System.DirectoryServices.DirectorySearcher.FindAll().GetEnumerator().Current.ToString() == "<script>alert(0)</script>"))
Response.Write("result");
// this is our fourth vulnerability of XSS in this file
// we will demonstrate what happen if developer want to cheat (FIXED Marker)
// FIXED: AI issue #4, High, Cross-site Scripting, https://github.com/SDLTestAccount/IT/issues/4
// GET /Tests/1 INPUT DATA VERIFICATION/9 LDAP Injection/Ldap.aspx HTTP/1.1
// Host:localhost
// (System.DirectoryServices.DirectorySearcher.FindAll().GetEnumerator().MoveNext() && (System.DirectoryServices.DirectorySearcher.FindAll().GetEnumerator().Current.ToString() == "<script>alert(0)</script>"))
Response.Write("result");
}
示例9: _getUsers
IObservableCollection<DirectoryUser> _getUsers(string filter)
{
var entry = new DirectoryEntry("LDAP://" + _settings.LdapPath);
var ds = new DirectorySearcher(entry)
{
Filter = filter,
SearchScope = SearchScope.OneLevel
};
var results = new BindableCollection<DirectoryUser>();
using (entry)
using (ds)
{
var searchResults = ds.FindAll();
foreach (SearchResult searchResult in searchResults)
{
var userPrincipalName = searchResult.Properties["userPrincipalName"];
var fullname = searchResult.Properties["cn"];
results.Add(new DirectoryUser(userPrincipalName.Count > 0 ? (string)userPrincipalName[0] : "", fullname.Count > 0 ? (string)fullname[0] : ""));
}
}
return results;
}
示例10: EnumerateComputers
public static List<SearchResult> EnumerateComputers()
{
string domain = System.Environment.UserDomainName;
List<SearchResult> computerList = new List<SearchResult>();
if (domain.Length == 0)
{
domain = System.Environment.MachineName;
}
try
{
DirectoryEntry directoryEntry = new DirectoryEntry("LDAP://" + domain);
DirectorySearcher compSearcher = new DirectorySearcher(directoryEntry);
compSearcher.SizeLimit = 100000;
compSearcher.PageSize = 1000;
compSearcher.Filter = "ObjectCategory=computer";
foreach (SearchResult computer in compSearcher.FindAll())
{
computerList.Add(computer);
}
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message, "There was an error!", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
}
return computerList;
}
示例11: EnumerateOU
/// <summary>
/// Find all OUs beneath a given OU
/// </summary>
/// <param name="OuDn">Distinguished name of the parent OU</param>
/// <param name="type">Type of objects to return</param>
/// <returns>Children OUs from the given OU distinguished name</returns>
public static ArrayList EnumerateOU(string OuDn, string type)
{
//Define our return type of array list
ArrayList alObjects = new ArrayList();
try
{
//Create a DirectoryEntry object with the passed in OU distinguished name
DirectoryEntry directoryObject = new DirectoryEntry("LDAP://" + OuDn);
DirectorySearcher ouSearch = new DirectorySearcher(directoryObject.Path);
ouSearch.Filter = "(objectClass=" + type + ")";
ouSearch.SearchRoot = directoryObject;
ouSearch.SearchScope = SearchScope.OneLevel;
SearchResultCollection allOUS = ouSearch.FindAll();
//Foreach child in the OU given
foreach (SearchResult child in allOUS)
{
DirectoryEntry de = child.GetDirectoryEntry();
//Add the child to our array list to return
alObjects.Add(de);
}
}
//If an error occurred
catch (DirectoryServicesCOMException e)
{
//Display the error message in a message box.
MessageBox.Show("An Error Occurred: " + e.Message.ToString());
}
//Return the array list of children of the given ou
return alObjects;
}
示例12: GetUserDisplayName
public string GetUserDisplayName(string alias)
{
using (DirectoryEntry root = GetRootEntry())
{
using (DirectorySearcher searcher = new DirectorySearcher(root))
{
searcher.Filter = alias.Format<string>("(|(&(objectCategory=person)(objectClass=user)(samAccountName={0})))");
using (SearchResultCollection searchResult = searcher.FindAll())
{
using (DirectoryEntry user = searchResult[0].GetDirectoryEntry())
{
if (user.Properties.Contains("displayName"))
{
return user.Properties["displayName"].Value.ToString();
}
else
{
return alias;
}
};
};
}
};
}
示例13: GetDisabledAccountsFLA
/// <summary>
/// Return a hast table of all disabled AD samaccountname
/// </summary>
/// <returns></returns>
public Hashtable GetDisabledAccountsFLA()
{
Hashtable ht = new Hashtable();
Boolean isActive;
try
{
DirectoryEntry directoryRoot = new DirectoryEntry(this.adStartLocation);
DirectorySearcher searcher = new DirectorySearcher(directoryRoot,
"(&(objectClass=User)(objectCategory=Person))");
SearchResultCollection results = searcher.FindAll();
foreach (SearchResult result in results)
{
DirectoryEntry de = result.GetDirectoryEntry();
isActive = IsActive(de);
if (!isActive)
{
string accountValue = (string)result.Properties["samaccountname"][0];
//will keep the accounts in alpha order
ht.Add(accountValue.ToUpper(), accountValue.ToUpper());
}
}
}
catch (Exception e)
{
throw new Exception("ActiveDirectoryAttributes - disabled accounts", e);
}
return (ht);
}
示例14: GetNetBIOSDomains
private List<ADDomain> GetNetBIOSDomains()
{
List<ADDomain> ret = new List<ADDomain>();
DirectoryEntry RootDSE = new DirectoryEntry("LDAP://rootDSE");
// Retrieve the Configuration Naming Context from RootDSE
string configNC = RootDSE.Properties["configurationNamingContext"].Value.ToString();
// Connect to the Configuration Naming Context
DirectoryEntry configSearchRoot = new DirectoryEntry("LDAP://" + configNC);
// Search for all partitions where the NetBIOSName is set.
DirectorySearcher configSearch = new DirectorySearcher(configSearchRoot);
configSearch.Filter = ("(NETBIOSName=*)");
// Configure search to return dnsroot and ncname attributes
configSearch.PropertiesToLoad.Add("dnsroot");
configSearch.PropertiesToLoad.Add("NETBIOSName");
SearchResultCollection forestPartitionList = configSearch.FindAll();
// Loop through each returned domain in the result collection
foreach (SearchResult domainPartition in forestPartitionList)
{
ADDomain ad = new ADDomain();
ad.Name = domainPartition.Properties["NETBIOSName"][0].ToString();
ad.Path = domainPartition.Properties["NETBIOSName"][0].ToString();
ret.Add(ad);
}
return ret;
}
示例15: popFile
// iterate users in an OU, write their mail attribute such as:
// sAMAccountName + "@amdg.rockhursths.edu"
public static void popFile(System.IO.StreamWriter file, string dn, string year)
{
//establish the OU
DirectoryEntry ou = new DirectoryEntry("LDAP://" + dn);
//establish the search object for above OU
DirectorySearcher searcher = new DirectorySearcher(ou);
//filter the search
searcher.Filter = "(ObjectCategory=user)";
//go through every single search result and update its mail attribute
foreach (SearchResult result in searcher.FindAll())
{
//entry for every user
DirectoryEntry user = null;
user = result.GetDirectoryEntry();
string givenName = user.Properties["givenName"].Value.ToString();
string sn = user.Properties["sn"].Value.ToString();
string sAMAccountName = user.Properties["sAMAccountName"].Value.ToString().ToLower();
string mail = user.Properties["mail"].Value.ToString().ToLower();
file.WriteLine(year + "," + givenName + "," + sn + "," + sAMAccountName + "," + mail);
}
}