private ADItem Search(ADWebService adws, ADDomainInfo domainInfo, string userName)
        {
            ADItem output = null;
            WorkOnReturnedObjectByADWS callback =
                (ADItem aditem) =>
            {
                output = aditem;
            };

            if (userName.StartsWith("S-1-5"))
            {
                adws.Enumerate(domainInfo.DefaultNamingContext,
                               "(objectSid=" + ADConnection.EncodeSidToString(userName) + ")",
                               properties, callback);
                if (output != null)
                {
                    return(output);
                }
            }
            if (userName.StartsWith("CN=") && userName.EndsWith(domainInfo.DefaultNamingContext))
            {
                adws.Enumerate(domainInfo.DefaultNamingContext,
                               "(distinguishedName=" + ADConnection.EscapeLDAP(userName) + ")",
                               properties, callback);
                if (output != null)
                {
                    return(output);
                }
            }
            if (userName.Length <= 20)
            {
                adws.Enumerate(domainInfo.DefaultNamingContext,
                               "(&(objectCategory=person)(objectClass=user)(sAMAccountName=" + ADConnection.EscapeLDAP(userName) + "))",
                               properties, callback);
                if (output != null)
                {
                    return(output);
                }
            }
            adws.Enumerate(domainInfo.DefaultNamingContext,
                           "(cn=" + ADConnection.EscapeLDAP(userName) + ")",
                           properties, callback);
            if (output != null)
            {
                return(output);
            }
            adws.Enumerate(domainInfo.DefaultNamingContext,
                           "(displayName=" + ADConnection.EscapeLDAP(userName) + ")",
                           properties, callback);
            if (output != null)
            {
                return(output);
            }
            return(output);
        }
        private void ExportCNData(ADWebService adws, ADDomainInfo domainInfo, RelationFactory relationFactory, List <string> cns)
        {
            WorkOnReturnedObjectByADWS callback =
                (ADItem aditem) =>
            {
                relationFactory.AnalyzeADObject(aditem);
            };

            foreach (string cn in cns)
            {
                adws.Enumerate(domainInfo.DefaultNamingContext,
                               "(distinguishedName=" + ADConnection.EscapeLDAP(cn) + ")",
                               properties, callback);
            }
        }
예제 #3
0
        private ADItem Search(ADWebService adws, ADDomainInfo domainInfo, string userName)
        {
            ADItem output = null;

            string[] properties = new string[] {
                "distinguishedName",
                "displayName",
                "name",
                "objectSid",
            };
            WorkOnReturnedObjectByADWS callback =
                (ADItem aditem) =>
            {
                output = aditem;
            };

            if (userName.StartsWith("S-1-5"))
            {
                adws.Enumerate(domainInfo.DefaultNamingContext,
                               "(objectSid=" + ADConnection.EncodeSidToString(userName) + ")",
                               properties, callback);
            }

            adws.Enumerate(domainInfo.DefaultNamingContext,
                           "(sAMAccountName=" + ADConnection.EscapeLDAP(userName) + ")",
                           properties, callback);
            if (output != null)
            {
                return(output);
            }
            adws.Enumerate(domainInfo.DefaultNamingContext,
                           "(cn=" + ADConnection.EscapeLDAP(userName) + ")",
                           properties, callback);
            if (output != null)
            {
                return(output);
            }
            adws.Enumerate(domainInfo.DefaultNamingContext,
                           "(displayName=" + ADConnection.EscapeLDAP(userName) + ")",
                           properties, callback);
            if (output != null)
            {
                return(output);
            }
            return(output);
        }
예제 #4
0
        private List <ADItem> Search(string userName, SearchType search = SearchType.Unknown)
        {
            List <ADItem> output        = new List <ADItem>();
            string        searchString  = null;
            string        namingContext = domainInfo.DefaultNamingContext;

            switch (search)
            {
            default:
            case SearchType.Unknown:
                if (userName.StartsWith("S-1-5"))
                {
                    output = Search(userName, SearchType.Sid);
                    if (output != null)
                    {
                        return(output);
                    }
                }
                if (userName.StartsWith("CN=") && userName.EndsWith(domainInfo.DefaultNamingContext))
                {
                    output = Search(userName, SearchType.DistinguishedName);
                    if (output != null)
                    {
                        return(output);
                    }
                }
                if (userName.Length <= 20)
                {
                    output = Search(userName, SearchType.SAMAccountName);
                    if (output != null)
                    {
                        return(output);
                    }
                }
                output = Search(userName, SearchType.Name);
                if (output != null)
                {
                    return(output);
                }
                output = Search(userName, SearchType.DisplayName);
                if (output != null)
                {
                    return(output);
                }
                return(null);

            case SearchType.Sid:
                searchString = "(|(objectSid=" + ADConnection.EncodeSidToString(userName) + ")(sidhistory=" + ADConnection.EncodeSidToString(userName) + "))";
                break;

            case SearchType.DistinguishedName:
                searchString = "(distinguishedName=" + ADConnection.EscapeLDAP(userName) + ")";
                if (userName.EndsWith(domainInfo.ConfigurationNamingContext, StringComparison.InvariantCultureIgnoreCase))
                {
                    namingContext = domainInfo.ConfigurationNamingContext;
                }
                else if (userName.EndsWith(domainInfo.SchemaNamingContext, StringComparison.InvariantCultureIgnoreCase))
                {
                    namingContext = domainInfo.SchemaNamingContext;
                }
                break;

            case SearchType.SAMAccountName:
                searchString = "(&(objectCategory=person)(objectClass=user)(sAMAccountName=" + ADConnection.EscapeLDAP(userName) + "))";
                break;

            case SearchType.Name:
                searchString = "(cn=" + ADConnection.EscapeLDAP(userName) + ")";
                break;

            case SearchType.DisplayName:
                searchString = "(displayName=" + ADConnection.EscapeLDAP(userName) + ")";
                break;

            case SearchType.PrimaryGroupId:
                searchString = "(primaryGroupID=" + userName + ")";
                break;
            }
            WorkOnReturnedObjectByADWS callback =
                (ADItem aditem) =>
            {
                output.Add(aditem);
            };

            adws.Enumerate(namingContext,
                           searchString,
                           properties.ToArray(), callback);
            return(output);
        }