Пример #1
0
        /// <summary>
        /// 添加新组到指定的组织单元
        /// </summary>
        /// <param name="cn">用户组</param>
        /// <param name="ouPath">组织单元路径(格式:OU=sddsd,OU=sdsdsd,顺序,子倒父)</param>
        /// <param name="description">描述</param>
        /// <returns>bool</returns>
        public int CreateGroupToUnit(string cn, string description, string path, out string errStr)
        {
            int result = 0;

            errStr = "";

            //创建指定路径的组织单元对象
            int i = 0; int j = 0;
            //string LDAPDomain ="/"+ouPath.ToString()+Iadc.GetLDAPDomain() ;

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

            //DirectoryEntry oDE= Iadc.GetDirectoryObject(LDAPDomain);

            DirectoryEntry oDE = Iadc.GetDirectoryObject(Iads.GetUnit(cn).ToString(), i, j);
            //DirectoryEntry oDE= Iadc.GetDirectoryObject(ouPath);



            DirectoryEntry oDEC = new DirectoryEntry();

            try
            {
                if (!Iadch.CheckGroup(cn))
                {
                    oDEC = oDE.Children.Add("cn=" + cn, "group");
                    //oDEC.Properties["grouptype"].Value = ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_GLOBAL_GROUP | ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_SECURITY_ENABLED ;
                    oDEC.Properties["sAMAccountName"].Value = cn;
                    oDEC.Properties["description"].Value    = description;

                    oDEC.Properties["displayName"].Value = path;
                    oDEC.CommitChanges();
                    result = 1;
                }
                else
                {
                    //移动组到正确的OU中
                    oDEC = Iads.GetGroupEntry(cn);
                    oDEC.Properties["displayName"].Value = path;
                    oDEC.CommitChanges();
                    oDEC.MoveTo(oDE);

                    oDE.CommitChanges();
                    result = 2;
                    errStr = "目录已存在该组,不能重复添加";
                }
            }
            catch (Exception err)
            {
                result = 0;
                errStr = err.ToString();
            }
            finally
            {
                oDE.Close();
                oDEC.Close();
            }

            return(result);
        }
Пример #2
0
        public DirectoryEntry UserExists(string UserName, string Password)
        {
            DirectoryEntry    de       = Iadc.GetDirectoryObject();
            DirectorySearcher deSearch = new DirectorySearcher();

            deSearch.SearchRoot  = de;
            deSearch.Filter      = "((objectClass=user)(cn=" + UserName + ")(userPassword="******"))";
            deSearch.SearchScope = SearchScope.Subtree;
            SearchResult results = deSearch.FindOne();

            de = new DirectoryEntry(results.Path, ADUser, ADPassword, AuthenticationTypes.Secure);
            return(de);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
0
 public void Set_Sign_User_Card(string cn, out string ErrResult)
 {
     try
     {
         int i = 0;
         int j = 0;
         ErrResult = "";
         DirectoryEntry usr = Iadc.GetDirectoryObject(Iads.GetUser(cn), i, j);
         //电话页
         string system_sign = Convert.ToString(usr.Properties["extensionAttribute9"].Value);
         if (system_sign.Length == 6)
         {
             string a = system_sign.Substring(0, 2);
             string b = system_sign.Substring(3, 3);
             usr.Properties["extensionAttribute9"].Value = a + "3" + b;
             usr.CommitChanges();
             usr.Close();
             ErrResult = "";
         }
     }
     catch (Exception ex) { ErrResult = ex.ToString(); }
 }