Esempio n. 1
0
        /// <summary>
        ///  在根目录下创建组织单元
        /// </summary>
        /// <param name="ou">组织单元名称</param>
        /// <returns></returns>
        public bool CreateNewUnit(string ou, string ouName)
        {
            bool result = false;

            ///获得创建DirectoryEntry 的父对象
            string         LDAPDomain = "/" + Iadc.GetLDAPDomain();
            DirectoryEntry oDE        = Iadc.GetDirectoryObject(LDAPDomain);
            DirectoryEntry oDEC       = new DirectoryEntry();

            //校验是否存在全局同名的组织单元
            if (!Iadch.CheckUnit(ou))
            {
                try
                {
                    //创建子组织单元
                    oDEC = oDE.Children.Add("OU=" + ou, "organizationalunit");
                    oDEC.Properties["description"].Value = ouName;
                    oDEC.Properties["l"].Value           = "1";
                    oDEC.CommitChanges();
                    result = true;
                }
                catch (Exception err)
                {
                    result = false;
                }
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// 将组移动到组织单元上
        /// </summary>
        /// <param name="cn"></param>
        /// <param name="parentcn"></param>
        public int MoveGroupToUnit(string cn, string ou, string ouPath, out string errStr)
        {
            int result = 0;

            errStr = "";
            string LDAPDomain = "/" + ouPath.ToString() + Iadc.GetLDAPDomain();

            LDAPDomain = ouPath;
            DirectoryEntry oDE  = Iads.GetUnitEntry(ou, LDAPDomain.Substring(18));
            DirectoryEntry oDEC = Iads.GetGroupEntry(cn);

            if (!Iadch.CheckGroup(cn))
            {
                return(2);
            }

            try
            {
                oDEC.MoveTo(oDE);
                oDE.CommitChanges();
                result = 1;
            }
            catch (Exception err)
            {
                result = 0;
                errStr = err.ToString();
            }
            finally
            {
                oDEC.Close();
                oDE.Close();
            }

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// 将用户移动到容器
        /// </summary>
        /// <param name="cn">UserName</param>
        /// <param name="ou">容器</param>
        public int MoveUserToUnit(string cn, string ou, string father_OU, out string errStr)
        {
            int result = 0;

            errStr = "";
            string LDAPDomain = "/" + father_OU.ToString() + Iadc.GetLDAPDomain();

            DirectoryEntry oUnit = new DirectoryEntry();
            DirectoryEntry oUser = new DirectoryEntry();

            if (!Iadch.CheckUnit(ou))
            {
                errStr = "未找到指定的机构/部门";
                return(3);
            }

            if (!Iadch.CheckUser(cn))
            {
                errStr = "未找到指定的用户";
                return(2);
            }

            try
            {
                oUnit = Iads.GetUnitEntry(ou, LDAPDomain);
                oUser = Iads.GetUserEntry(cn);
                if (!oUnit.Properties["member"].Contains(oUser.Properties["distinguishedName"].Value))
                {
                    oUser.Properties["l"].Value = "4";

                    oUser.MoveTo(oUnit);
                    oUser.CommitChanges();
                    oUnit.CommitChanges();
                    result = 1;
                }
            }
            catch (Exception err)
            {
                result = 0;
            }
            finally
            {
                oUser.Close();
            }
            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// 验证账号是否存在
        /// </summary>
        /// <returns></returns>
        public bool CheckUser(string userName, string father_OU)
        {
            AD_Common Iadc       = new AD_Common();
            string    LDAPDomain = "/" + father_OU.ToString() + Iadc.GetLDAPDomain();
            string    condition  = "(&(objectClass=user)(cn=" + userName + "))";
            bool      result     = Iads.CommonWayBool(condition, LDAPDomain);

            return(result);
        }
Esempio n. 5
0
        public SearchResult CommonWay(string condition)
        {
            string            LDAPDomain = "/" + Iadc.GetLDAPDomain();
            DirectoryEntry    de         = Iadc.GetDirectoryObject(LDAPDomain);
            DirectorySearcher deSearch   = new DirectorySearcher();

            deSearch.SearchRoot  = de;
            deSearch.Filter      = condition;
            deSearch.SearchScope = SearchScope.Subtree;
            SearchResult results = deSearch.FindOne();

            return(results);
        }
Esempio n. 6
0
		/// <summary>
		/// 验证账号是否存在
		/// </summary>
		/// <returns></returns>
		public  bool CheckUser(string userName,string father_OU)
		{
			AD_Common Iadc=new AD_Common();
			string LDAPDomain ="/"+father_OU.ToString()+ Iadc.GetLDAPDomain() ;
			string condition="(&(objectClass=user)(cn="+userName+"))";
			bool result=Iads.CommonWayBool(condition,LDAPDomain);
			return result;
		}