Example #1
0
        public static int CheckLdapTimedOut(string sDN, string sRootDN)
        {
            int              ret        = -1;
            LdapMessage      message    = null;
            DirectoryContext dircontext = null;

            if (exisitngDirContext != null && exisitngDirContext.Count > 0)
            {
                foreach (DirectoryContext context in exisitngDirContext)
                {
                    if (context.DomainName.Equals(sRootDN, StringComparison.InvariantCultureIgnoreCase))
                    {
                        dircontext = context;
                    }
                }
            }

            ret = dircontext.SearchSynchronous(
                sDN,
                Likewise.LMC.LDAP.Interop.LdapAPI.LDAPSCOPE.BASE,
                "(objectClass=*)",
                new string[]
            {
                "objectClass", "distinguishedName", null
            },
                false,
                out message);

            return(ret);
        }
Example #2
0
        public void CommitChanges()
        {
            Assign_dirContext();

            if (dirContext == null)
            {
                return;
            }

            if (!get_baseDnFor_guidOrsid_called)
            {
                Get_baseDn_Guid_Or_sid();
            }

            string[]    search_attrs = { null };
            LdapMessage ldapMessage  = dirContext.SearchSynchronous(
                baseDn,
                LdapAPI.LDAPSCOPE.BASE,
                "(objectClass=*)",
                search_attrs,
                false);
            List <LdapEntry> ldapEntries = (ldapMessage != null ? ldapMessage.Ldap_Get_Entries() : null);

            //if this object does not exist in AD, we need create it first
            if (ldapEntries == null || ldapEntries.Count == 0)
            {
                int ret = SDSUtils.AddNewObj(dirContext, objectClassType, baseDn);
                if (ret != 0)
                {
                    //Console.WriteLine("Create new object failed!");
                    return;
                }
            }

            //go through the properties to check whether there is PropertyValueCollection has been modified
            //PropertyCollection: Dictionary<string, PropertyValueCollection>
            if (propertyCollection != null && propertyCollection.Count > 0)
            {
                foreach (KeyValuePair <string, PropertyValueCollection> kvp in propertyCollection)
                {
                    if (kvp.Value.Modified)
                    {
                        //Console.WriteLine("BaseDN is " + baseDn + " Modified key value pair: " + kvp.Key );
                        int ret = SDSUtils.ModifyProperty(dirContext, baseDn, kvp.Key, kvp.Value);
                        //if (ret != 0) ; Console.WriteLine("Modify a property failed");
                    }
                }
            }

            //go through its children to see whether this is any children marked needed be deleted
            if (children != null && children.Count > 0)
            {
                DirectoryEntries modifiedChildren = new DirectoryEntries();

                foreach (DirectoryEntry child in children)
                {
                    if (child.ToBeDeleted) //delete this DE
                    {
                        int ret = SDSUtils.DeleteObj(dirContext, child.Name);
                    }
                }

                //reflect the changes to children collection
                foreach (DirectoryEntry child in children)
                {
                    if (!child.ToBeDeleted)
                    {
                        modifiedChildren.Add(child);
                    }
                }

                children = modifiedChildren;
            }
        }
Example #3
0
        /// <summary>
        /// Method used to print the Ldap contents to the log
        /// </summary>
        /// <param name="logLevel"></param>
        private void printLdapContentsToLog(Logger.LogLevel logLevel)
        {
            if (Logger.currentLogLevel < logLevel)
            {
                return;
            }

            string[] search_attrs = { null };

            string distinguishedName = "cn=schema,cn=configuration,dc=corpqa,dc=centeris,dc=com";

            DateTime    start       = DateTime.Now;
            LdapMessage ldapMessage = _adContext.SearchSynchronous(distinguishedName,
                                                                   LdapAPI.LDAPSCOPE.SUB_TREE,
                                                                   "objectClass=*",
                                                                   search_attrs,
                                                                   false);


            DateTime finish = DateTime.Now;

            Logger.Log(String.Format("finish ldap schema: scope=1 basedn={0} delta-time={1}",
                                     distinguishedName, finish - start), Logger.timingLogLevel);

            if (ldapMessage == null)
            {
                Logger.Log("ldapMessage = null");
            }
            else
            {
                List <LdapEntry> ldapEntries = ldapMessage.Ldap_Get_Entries();
                if (ldapEntries == null || ldapEntries.Count == 0)
                {
                    return;
                }

                foreach (LdapEntry ldapNextEntry in ldapEntries)
                {
                    string s = ldapNextEntry.GetDN();
                    Logger.Log(String.Format("DN = {0}", s));

                    List <string> attrNames    = new List <string>();
                    string[]      tmpAttrNames = ldapNextEntry.GetAttributeNames();
                    foreach (string attrName in tmpAttrNames)
                    {
                        attrNames.Add(attrName);
                    }
                    if (!attrNames.Contains("objectClass"))
                    {
                        attrNames.Add("objectClass");
                    }

                    foreach (string attr in attrNames)
                    {
                        LdapValue[] values = ldapNextEntry.GetAttributeValues(attr, _adContext);
                        if (values != null && values.Length > 0)
                        {
                            foreach (LdapValue value in values)
                            {
                                if (value != null)
                                {
                                    Logger.Log(String.Format("\t{0} ==> {1}", attr, value.stringData));
                                }
                                else
                                {
                                    Logger.Log(String.Format("\t{0} ==> NULL", attr));
                                }
                            }
                        }
                        else
                        {
                            Logger.Log(String.Format("\t{0} ==> UNSET", attr));
                        }
                    }
                }
            }
        }