1

LDAP で PosixAccount を既存のユーザーに書き込もうとしました。エラーは発生しませんが、LDAP を確認すると、新しいエントリが書き込まれていません。

最初に新しいユーザーを追加しましたが、これはうまく機能しています! =>

        public bool RegisterUser(UserObject userObj, HttpContext httpContext){
        bool success = false;

        //create a directory entry
        using (DirectoryEntry de = new DirectoryEntry())
        {
            try
            {
                InitializeCommonDataForDirectoryEntry(
                    de,
                    String.Format("{0}/{1}",
                        GetConfigEntry(Common.CommonDefinitions.CE_LDAP_CONFIG_SERVER, httpContext),
                        GetConfigEntry(Common.CommonDefinitions.CE_LDAP_CONFIG_DIRECTORY_ENTRY_ROOT, httpContext)),
                        httpContext);

                DirectorySearcher ds = new DirectorySearcher(de);
                ds.SearchScope = System.DirectoryServices.SearchScope.Subtree;
                ds.Filter = "(&(objectClass=organizationalUnit)(ou=people))";

                SearchResult result = ds.FindOne();
                if (result != null)
                {
                    DirectoryEntry myDirectoryEntry = result.GetDirectoryEntry();
                    DirectoryEntry newEntry = myDirectoryEntry.Children.Add(String.Format("cn={0}", userObj.userName), "inetOrgPerson");

                    if (userObj.company != null && !userObj.company.Equals(String.Empty))
                        newEntry.Properties["businessCategory"].Add(String.Format("{0}", userObj.company));
                    newEntry.Properties["givenName"].Add(String.Format("{0}", userObj.firstName));
                    newEntry.Properties["sn"].Add(String.Format("{0}", userObj.lastName));
                    newEntry.Properties["uid"].Add(String.Format("{0}", userObj.userName));
                    newEntry.Properties["mail"].Add(String.Format("{0}", userObj.email));
                    userObj.password = GenerateSaltedSHA1(userObj.password);
                    newEntry.Properties["userPassword"].Add(String.Format("{0}", userObj.password));
                    newEntry.Properties["pager"].Add(String.Format("{0}", userObj.newsletter));
                    newEntry.Properties["initials"].Add(String.Format("{0}", GetConfigEntry(Common.CommonDefinitions.CE_MOWEE_PACKAGE_1, httpContext)));

                    newEntry.CommitChanges();
                    newEntry.RefreshCache();
                    success = true;
                }
            }
            catch (Exception ex)
            {
                Trace.Write("Exception : RegisterUser: " + ex);
                GeneralUtils.SendBugMail(ex, httpContext);
            }
        }
        return success;
    }

その後、私はそのユーザーのために posixAccount を書きたいと思っていますが、これは機能していません。

=>

     public bool WritePosixAccountDataForRegisteredUser(UserObject userObj, HttpContext httpContext)
    {
        bool success = false;

        //create a directory entry
        using (DirectoryEntry de = new DirectoryEntry())
        {
            try
            {
                InitializeCommonDataForDirectoryEntry(
                    de,
                    String.Format("{0}/ou=people,{1}",
                        GetConfigEntry(Common.CommonDefinitions.CE_LDAP_CONFIG_SERVER, httpContext),
                        GetConfigEntry(Common.CommonDefinitions.CE_LDAP_CONFIG_DIRECTORY_ENTRY_ROOT, httpContext)),
                        httpContext);

                DirectorySearcher ds = new DirectorySearcher(de);
                ds.SearchScope = System.DirectoryServices.SearchScope.Subtree;
                ds.Filter = String.Format("(&(objectClass=*)(cn={0}))", userObj.userName);

                SearchResult result = ds.FindOne();
                if (result != null)
                {
                    DirectoryEntry userEntry = result.GetDirectoryEntry();

                    //mandatory attributes
                    /*
                     *      cn
                            gidNumber
                            homeDirectory
                            uid
                            uidNumber
                     * */

                    IADsPropertyList propList = (IADsPropertyList)userEntry.NativeObject;

                    ActiveDs.PropertyEntry myNewEntry1 = new ActiveDs.PropertyEntry();
                    ActiveDs.IADsPropertyValue propVal1 = new ActiveDs.PropertyValue();
                    propVal1.CaseIgnoreString = "posixAccount";
                    propVal1.ADsType = (int)ADSTYPEENUM.ADSTYPE_CASE_IGNORE_STRING;
                    myNewEntry1.Name = "objectClass";
                    myNewEntry1.Values = new object[] { propVal1 };
                    myNewEntry1.ControlCode = (int)ADS_PROPERTY_OPERATION_ENUM.ADS_PROPERTY_APPEND;
                    myNewEntry1.ADsType = (int)ADSTYPEENUM.ADSTYPE_CASE_IGNORE_STRING;
                    propList.PutPropertyItem(myNewEntry1);

                    ActiveDs.PropertyEntry myNewEntry2 = new ActiveDs.PropertyEntry();
                    ActiveDs.IADsPropertyValue propVal2 = new ActiveDs.PropertyValue();
                    propVal2.CaseIgnoreString = "504";
                    propVal2.ADsType = (int)ADSTYPEENUM.ADSTYPE_CASE_IGNORE_STRING;
                    myNewEntry2.Name = "gidNumber";
                    myNewEntry2.Values = new object[] { propVal2 };
                    myNewEntry2.ControlCode = (int)ADS_PROPERTY_OPERATION_ENUM.ADS_PROPERTY_APPEND;
                    myNewEntry2.ADsType = (int)ADSTYPEENUM.ADSTYPE_CASE_IGNORE_STRING;
                    propList.PutPropertyItem(myNewEntry2);

                    ActiveDs.PropertyEntry myNewEntry3 = new ActiveDs.PropertyEntry();
                    ActiveDs.IADsPropertyValue propVal3 = new ActiveDs.PropertyValue();
                    propVal3.CaseIgnoreString = "/data/WowzaMediaServer-3.0.3/content/mowee/" + userObj.userName;
                    propVal3.ADsType = (int)ADSTYPEENUM.ADSTYPE_CASE_IGNORE_STRING;
                    myNewEntry3.Name = "homeDirectory";
                    myNewEntry3.Values = new object[] { propVal3 };
                    myNewEntry3.ControlCode = (int)ADS_PROPERTY_OPERATION_ENUM.ADS_PROPERTY_APPEND;
                    myNewEntry3.ADsType = (int)ADSTYPEENUM.ADSTYPE_CASE_IGNORE_STRING;
                    propList.PutPropertyItem(myNewEntry3);

                    ActiveDs.PropertyEntry myNewEntry4 = new ActiveDs.PropertyEntry();
                    ActiveDs.IADsPropertyValue propVal4 = new ActiveDs.PropertyValue();
                    propVal4.CaseIgnoreString = "1100";
                    propVal4.ADsType = (int)ADSTYPEENUM.ADSTYPE_CASE_IGNORE_STRING;
                    myNewEntry4.Name = "uidNumber";
                    myNewEntry4.Values = new object[] { propVal4 };
                    myNewEntry4.ControlCode = (int)ADS_PROPERTY_OPERATION_ENUM.ADS_PROPERTY_APPEND;
                    myNewEntry4.ADsType = (int)ADSTYPEENUM.ADSTYPE_CASE_IGNORE_STRING;
                    propList.PutPropertyItem(myNewEntry4);

                    ActiveDs.PropertyEntry myNewEntry5 = new ActiveDs.PropertyEntry();
                    ActiveDs.IADsPropertyValue propVal5 = new ActiveDs.PropertyValue();
                    propVal5.CaseIgnoreString = userObj.userName;
                    propVal5.ADsType = (int)ADSTYPEENUM.ADSTYPE_CASE_IGNORE_STRING;
                    myNewEntry5.Name = "cn";
                    myNewEntry5.Values = new object[] { propVal5 };
                    myNewEntry5.ControlCode = (int)ADS_PROPERTY_OPERATION_ENUM.ADS_PROPERTY_APPEND;
                    myNewEntry5.ADsType = (int)ADSTYPEENUM.ADSTYPE_CASE_IGNORE_STRING;
                    propList.PutPropertyItem(myNewEntry5);

                    ActiveDs.PropertyEntry myNewEntry6 = new ActiveDs.PropertyEntry();
                    ActiveDs.IADsPropertyValue propVal6 = new ActiveDs.PropertyValue();
                    propVal6.CaseIgnoreString = userObj.userName;
                    propVal6.ADsType = (int)ADSTYPEENUM.ADSTYPE_CASE_IGNORE_STRING;
                    myNewEntry6.Name = "uid";
                    myNewEntry6.Values = new object[] { propVal6 };
                    myNewEntry6.ControlCode = (int)ADS_PROPERTY_OPERATION_ENUM.ADS_PROPERTY_APPEND;
                    myNewEntry6.ADsType = (int)ADSTYPEENUM.ADSTYPE_CASE_IGNORE_STRING;
                    propList.PutPropertyItem(myNewEntry6);

                    de.RefreshCache(new String[] { "objectClass" });
                    de.RefreshCache(new String[] { "gidNumber" });
                    de.RefreshCache(new String[] { "homeDirectory" });
                    de.RefreshCache(new String[] { "uidNumber" });
                    de.RefreshCache(new String[] { "cn" });
                    de.RefreshCache(new String[] { "uid" });

                    de.CommitChanges();
                    success = true;
                }
            }
            catch (Exception ex)
            {
                Trace.Write("Exception : RegisterUser: " + ex);
                GeneralUtils.SendBugMail(ex, httpContext);
            }
        }
        return success;
    }
4

1 に答える 1

0

あなたが得るエラーは、それ以上の診断に役立つと思います。

AD でオブジェクトを作成すると、CN を指定しなくても、CN セットのデフォルトの命名属性が得られると確信しています。そのため、cn を設定しているこの posixAccount create は、既存の cn 値と競合している可能性があります。AD で CN が多値か単一値かは忘れましたが、単一値の場合はもっと理にかなっています。

于 2013-03-14T12:24:29.640 に答える