public DirectoryEntriesWrapper(DirectoryEntries directoryEntries)
        {
            if(directoryEntries == null)
                throw new ArgumentNullException("directoryEntries");

            this._directoryEntries = directoryEntries;
        }
Esempio n. 2
0
		internal SAMQuerySet(List<string> schemaTypes, DirectoryEntries entries, DirectoryEntry ctxBase, int sizeLimit, SAMStoreCtx storeCtx, SAMMatcher samMatcher)
		{
			this.schemaTypes = schemaTypes;
			this.entries = entries;
			this.sizeLimit = sizeLimit;
			this.storeCtx = storeCtx;
			this.ctxBase = ctxBase;
			this.matcher = samMatcher;
			this.enumerator = this.entries.GetEnumerator();
		}
Esempio n. 3
0
        // We will iterate over all principals under ctxBase, returning only those which are in the list of types and which
        // satisfy ALL the matching properties.
        internal SAMQuerySet(
                        List<string> schemaTypes,
                        DirectoryEntries entries,
                        DirectoryEntry ctxBase,
                        int sizeLimit,
                        SAMStoreCtx storeCtx,
                        SAMMatcher samMatcher)
        {
            GlobalDebug.WriteLineIf(GlobalDebug.Info, "SAMQuerySet", "SAMQuerySet: creating for path={0}, sizelimit={1}", ctxBase.Path, sizeLimit);

            _schemaTypes = schemaTypes;
            _entries = entries;
            _sizeLimit = sizeLimit;     // -1 == no limit
            _storeCtx = storeCtx;
            _ctxBase = ctxBase;
            _matcher = samMatcher;

            _enumerator = _entries.GetEnumerator();
        }
        public DirectoryEntry(string sLDAPPath)
        {
            this.sLDAPPath = sLDAPPath;
            propertyCollection = null;
            nativeObject = null;
            sName = null;
            children = null;
            objectSecurity = null;
            guid = Guid.Empty;
            parent = null;
            objectClassType = null;

            SDSUtils.CrackPath(sLDAPPath, out sProtocol, out sServer, out sCNs, out sDCs);

            /*if (sProtocol != null) Console.WriteLine("sProtocol is " + sProtocol);
            if (sServer != null) Console.WriteLine("sServer is " + sServer);
            if (sCNs != null) Console.WriteLine("sCNs is " + sCNs);
            if (sDCs != null) Console.WriteLine("sDCs is " + sDCs); */

            string[] rootDNcom;

            if (sServer != null)
            {
                rootDNcom = sServer.Split('.');

                rootDN = "";

                foreach (string str in rootDNcom)
                {
                    string temp = string.Concat("dc=", str, ",");
                    rootDN = string.Concat(rootDN, temp);
                }

                rootDN = rootDN.Substring(0, rootDN.Length - 1);
            }
            //beacuse rootDN is nothing but collection of all DC's from DN
            if (sDCs != null)
                rootDN = sDCs;

            baseDn = "";

            //sCNs = RootDSE, Configuration, Schema, Domain
            if (sCNs != null && sDCs == null)
            {
                if (sCNs.Equals("RootDSE", StringComparison.InvariantCultureIgnoreCase))
                    baseDn = "";
                else if (sCNs.Equals("Configuration", StringComparison.InvariantCultureIgnoreCase))
                    baseDn = string.Concat("CN=Configuration,", rootDN);
                else if (sCNs.Equals("Schema", StringComparison.InvariantCultureIgnoreCase))
                    baseDn = string.Concat("CN=Schema,", rootDN);
                else if (sCNs.Equals("Domain", StringComparison.InvariantCultureIgnoreCase) ||
                 sCNs.Equals("", StringComparison.InvariantCultureIgnoreCase) ||
                 sCNs.StartsWith("<"))
                {
                    if (rootDN != null)
                        baseDn = rootDN;
                }
                else baseDn = string.Concat(sCNs, ",", rootDN);

            }

            if (sCNs != null && sDCs != null)
                baseDn = string.Concat(sCNs, ",", sDCs);

            if (sCNs == null && sDCs != null)
                baseDn = sDCs;

            if (sCNs == null && sDCs == null)
                baseDn = rootDN;

            //assign sName value using the dN of this node
            if (baseDn.Equals("", StringComparison.InvariantCultureIgnoreCase))
                sName = "RootDSE";
            else
                sName = baseDn;
        }
        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;
            }
        }
 public static DirectoryEntriesWrapper FromDirectoryEntries(DirectoryEntries directoryEntries)
 {
     return directoryEntries;
 }
 public IDirectoryEntries Create(DirectoryEntries directoryEntries)
 {
     return new DirectoryEntriesWrapper(directoryEntries);
 }
 internal DirectoryEntriesWrapper(DirectoryEntries directory)
 {
     _directoryEntries = directory;
 }
Esempio n. 9
0
		private ArrayList Load(DirectoryEntries deCollection)
		{
			ArrayList list = new ArrayList();
			DirectoryEntry de;
			foreach (DirectoryEntry tempLoopVar_de in deCollection)
			{
				de = tempLoopVar_de;
				list.Add(Load(de));
			}
			return list;
		}
Esempio n. 10
0
 /// <summary>
 /// 递归显示IIS树,做了特殊处理
 /// </summary>
 /// <param name="subDre"></param>
 /// <param name="nodeToAddTo"></param>
 private void GetDirectories(DirectoryEntries subDre, TreeNode nodeToAddTo)
 {
     TreeNode aNode;
     DirectoryEntries subDres;
     foreach (DirectoryEntry dr in subDre)
     {
         if (dr.SchemaClassName.Equals("IIsWebServer") || dr.SchemaClassName.Equals("IIsWebVirtualDir"))
         {
             if (dr.SchemaClassName.Equals("IIsWebServer"))
             {
                 aNode = new TreeNode();
                 aNode.Text = dr.Properties["ServerComment"].Value.ToString();
                 aNode.Name = dr.Path;// + "/ROOT"
                 rootNode = aNode;
             }
             else
             {
                 aNode = new TreeNode();
                 aNode.Text = dr.Name;
                 aNode.Name = dr.Path;
             }
             subDres = dr.Children;
             if (subDres != null)
             {
                 if (string.Compare(dr.Name, "root", true) == 0)
                     GetDirectories(subDres, rootNode);//略过第二结点
                 else
                     GetDirectories(subDres, aNode);
             }
             if (aNode.Text != "" && (string.Compare(dr.Name, "root", true) != 0))
             {
                 nodeToAddTo.Nodes.Add(aNode);
                 rootNode = nodeToAddTo;
             }
         }
     }
 }
Esempio n. 11
0
 //获取虚拟目录集合
 private VirtualDirectories GetVirDirs(DirectoryEntries des)
 {
     VirtualDirectories tmpdirs = new VirtualDirectories();
     foreach (DirectoryEntry de in des)
     {
         if (de.SchemaClassName == "IIsWebVirtualDir")
         {
             VirtualDirectory vd = new VirtualDirectory();
             vd.Name = de.Name;
             vd.AccessRead = (bool)de.Properties["AccessRead"][0];
             vd.AccessExecute = (bool)de.Properties["AccessExecute"][0];
             vd.AccessWrite = (bool)de.Properties["AccessWrite"][0];
             vd.AnonymousUserName = (string)de.Properties["AnonymousUserName"][0];
             vd.AnonymousUserPass = (string)de.Properties["AnonymousUserName"][0];
             vd.AuthBasic = (bool)de.Properties["AuthBasic"][0];
             vd.AuthNTLM = (bool)de.Properties["AuthNTLM"][0];
             vd.ContentIndexed = (bool)de.Properties["ContentIndexed"][0];
             vd.EnableDefaultDoc = (bool)de.Properties["EnableDefaultDoc"][0];
             vd.EnableDirBrowsing = (bool)de.Properties["EnableDirBrowsing"][0];
             vd.AccessSSL = (bool)de.Properties["AccessSSL"][0];
             vd.Accessscript = (bool)de.Properties["Accessscript"][0];
             vd.Path = (string)de.Properties["Path"][0];
             vd.flag = 0;
             vd.DefaultDoc = (string)de.Properties["DefaultDoc"][0];
             tmpdirs.Add(vd.Name, vd);
         }
     }
     return tmpdirs;
 }
Esempio n. 12
0
        public DirectoryEntry(string sLDAPPath)
        {
            this.sLDAPPath     = sLDAPPath;
            propertyCollection = null;
            nativeObject       = null;
            sName           = null;
            children        = null;
            objectSecurity  = null;
            guid            = Guid.Empty;
            parent          = null;
            objectClassType = null;

            SDSUtils.CrackPath(sLDAPPath, out sProtocol, out sServer, out sCNs, out sDCs);

            /*if (sProtocol != null) Console.WriteLine("sProtocol is " + sProtocol);
             * if (sServer != null) Console.WriteLine("sServer is " + sServer);
             * if (sCNs != null) Console.WriteLine("sCNs is " + sCNs);
             * if (sDCs != null) Console.WriteLine("sDCs is " + sDCs); */

            string[] rootDNcom;

            if (sServer != null)
            {
                rootDNcom = sServer.Split('.');

                rootDN = "";

                foreach (string str in rootDNcom)
                {
                    string temp = string.Concat("dc=", str, ",");
                    rootDN = string.Concat(rootDN, temp);
                }

                rootDN = rootDN.Substring(0, rootDN.Length - 1);
            }
            //beacuse rootDN is nothing but collection of all DC's from DN
            if (sDCs != null)
            {
                rootDN = sDCs;
            }

            baseDn = "";

            //sCNs = RootDSE, Configuration, Schema, Domain
            if (sCNs != null && sDCs == null)
            {
                if (sCNs.Equals("RootDSE", StringComparison.InvariantCultureIgnoreCase))
                {
                    baseDn = "";
                }
                else if (sCNs.Equals("Configuration", StringComparison.InvariantCultureIgnoreCase))
                {
                    baseDn = string.Concat("CN=Configuration,", rootDN);
                }
                else if (sCNs.Equals("Schema", StringComparison.InvariantCultureIgnoreCase))
                {
                    baseDn = string.Concat("CN=Schema,", rootDN);
                }
                else if (sCNs.Equals("Domain", StringComparison.InvariantCultureIgnoreCase) ||
                         sCNs.Equals("", StringComparison.InvariantCultureIgnoreCase) ||
                         sCNs.StartsWith("<"))
                {
                    if (rootDN != null)
                    {
                        baseDn = rootDN;
                    }
                }
                else
                {
                    baseDn = string.Concat(sCNs, ",", rootDN);
                }
            }

            if (sCNs != null && sDCs != null)
            {
                baseDn = string.Concat(sCNs, ",", sDCs);
            }

            if (sCNs == null && sDCs != null)
            {
                baseDn = sDCs;
            }

            if (sCNs == null && sDCs == null)
            {
                baseDn = rootDN;
            }

            //assign sName value using the dN of this node
            if (baseDn.Equals("", StringComparison.InvariantCultureIgnoreCase))
            {
                sName = "RootDSE";
            }
            else
            {
                sName = baseDn;
            }
        }
Esempio n. 13
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;
            }
        }
        /// <summary>
        
        /// </summary>
        
        
        public IList<LDAPObject> CreateObjects(DirectoryEntries entries)
        {
            List<LDAPObject> list = new List<LDAPObject>(10);
            foreach (DirectoryEntry item in entries)
                list.Add(CreateObject(item));

            return list;
        }