Exemple #1
0
        public IResult Collect(SearchString searchstring)
        {
            _logger.Debug($"Collecting");
            LDAPSearchString   searchString = (LDAPSearchString)searchstring;
            List <ILDAPObject> ldapObjects  = new List <ILDAPObject>();

            var results = Searcher.GetResultEntries(searchString).ToList();

            foreach (var result in results)
            {
                //If we need User
                if (searchString.ReturnAttributes.Contains("sAMAccountName"))
                {
                    var user = User.GetUserObject(result);
                    ldapObjects.Add(user);
                }
                else
                {
                    ldapObjects.Add(new LDAPBaseObject {
                        Attributes = ProcessAttributes(result.Attributes), DistinguishedName = result.DistinguishedName
                    });
                }
            }

            CollectResult = new LDAPResult {
                LDAPObjects = ldapObjects, Title = searchstring.Title
            };

            _logger.Debug("LDAP Objects Collected");
            return(CollectResult);
        }
        public override void DisplayResult(IResult collectResult)
        {
            if (collectResult == null)
            {
                return;
            }
            LDAPResult collectResults = (LDAPResult)collectResult;

            if (collectResults.LDAPObjects.Count == 0)
            {
                return;
            }

            foreach (var ldapObject in collectResults.LDAPObjects)
            {
                Console.WriteLine("    * {0}", ldapObject.DistinguishedName.ToUpper());

                if (ldapObject is User u)
                {
                    foreach (var attr in u.Properities)
                    {
                        foreach (var value in attr.Value)
                        {
                            Console.WriteLine("      - {0, -30}  {1}", attr.Key + ":", value);
                        }
                    }
                }
                else if (ldapObject is LDAPBaseObject b)
                {
                    foreach (var dict in b.Attributes)
                    {
                        foreach (var attr in dict.Value)
                        {
                            Console.WriteLine("      {0, -30}    {1}", dict.Key, attr);
                        }
                        //Console.WriteLine();
                    }
                }
                //Console.WriteLine();
            }
        }