Find out User cannot change password value of ldap

烈酒焚心 提交于 2019-12-12 04:14:32

问题


I am trying to find out that in ad, user has allowed to change password or not. I have used SearchResponse to find out that user exists or not.


回答1:


SearchResponse response = (SearchResponse)connection.SendRequest(request); DirectoryAttribute attribute = response.Entries[0].Attributes["ntSecurityDescriptor"];

            if (attribute != null)
            {
                const string PASSWORD_GUID = "{ab721a53-1e2f-11d0-9819-00aa0040529b}";
                const int ADS_ACETYPE_ACCESS_DENIED_OBJECT = 6;
                bool fEveryone = false;
                bool fSelf = false;

                ActiveDs.ADsSecurityUtility secUtility = new ActiveDs.ADsSecurityUtility();
                ActiveDs.IADsSecurityDescriptor sd = (IADsSecurityDescriptor)secUtility.ConvertSecurityDescriptor((byte[])attribute[0], (int)ADS_SD_FORMAT_ENUM.ADS_SD_FORMAT_RAW, (int)ADS_SD_FORMAT_ENUM.ADS_SD_FORMAT_IID);
                ActiveDs.IADsAccessControlList acl = (ActiveDs.IADsAccessControlList)sd.DiscretionaryAcl;

                foreach (ActiveDs.IADsAccessControlEntry ace in acl)
                {
                    if ((ace.ObjectType != null) && (ace.ObjectType.ToUpper() == PASSWORD_GUID.ToUpper()))
                    {
                        if ((ace.Trustee == "Everyone") && (ace.AceType == ADS_ACETYPE_ACCESS_DENIED_OBJECT))
                        {
                            fEveryone = true;
                        }
                        if ((ace.Trustee == @"NT AUTHORITY\SELF") && (ace.AceType == ADS_ACETYPE_ACCESS_DENIED_OBJECT))
                        {
                            fSelf = true;
                        }

                        break;
                    }
                }

                if (fEveryone || fSelf)
                {
                    return Global.RequestContants.CANT_CHANGE_PASSWORD;
                }
                else
                {
                    return string.Empty;
                }
            }


来源:https://stackoverflow.com/questions/12908745/find-out-user-cannot-change-password-value-of-ldap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!