コード例 #1
0
        internal static bool?IsProtectedFromDeletion(ADObject directoryObj, CmdletSessionInfo cmdletSessionInfo)
        {
            bool flag;

            ProtectedFromDeletionUtil.AddObjectToCache(directoryObj, cmdletSessionInfo);
            if (!directoryObj.Contains("nTSecurityDescriptor") || directoryObj["nTSecurityDescriptor"].Value == null)
            {
                bool?nullable = null;
                return(nullable);
            }
            else
            {
                bool flag1 = ProtectedFromDeletionUtil.EveryoneDeniedDeleteAndDeleteTree(directoryObj);
                if (!Utils.IsNamingContext(directoryObj) && !Utils.IsDeleted(directoryObj))
                {
                    string   parentPath   = ADPathModule.GetParentPath(directoryObj.DistinguishedName, null, ADPathFormat.X500);
                    ADObject cachedObject = ProtectedFromDeletionUtil.GetCachedObject(parentPath, ProtectedFromDeletionUtil.AttributesToFetchOnParent, cmdletSessionInfo);
                    if (cachedObject != null)
                    {
                        if (!cachedObject.Contains("nTSecurityDescriptor") || cachedObject["nTSecurityDescriptor"].Value == null)
                        {
                            bool?nullable1 = null;
                            return(nullable1);
                        }
                        else
                        {
                            if (!ProtectedFromDeletionUtil.EveryoneDeniedDeleteChild(cachedObject))
                            {
                                flag = false;
                            }
                            else
                            {
                                flag = flag1;
                            }
                            return(new bool?(flag));
                        }
                    }
                }
                return(new bool?(flag1));
            }
        }
コード例 #2
0
        internal static bool ProtectFromAccidentalDeletion(ADObject directoryObj, CmdletSessionInfo cmdletSessionInfo)
        {
            ADObject cachedObject;
            string   value = directoryObj["distinguishedName"].Value as string;

            if (!directoryObj.Contains("nTSecurityDescriptor") || !directoryObj.Contains("sdRightsEffective"))
            {
                cachedObject = ProtectedFromDeletionUtil.GetCachedObject(value, ProtectedFromDeletionUtil.AttributesToFetchOnObject, cmdletSessionInfo);
            }
            else
            {
                cachedObject = directoryObj;
                ProtectedFromDeletionUtil.AddObjectToCache(directoryObj, cmdletSessionInfo);
            }
            if (cachedObject == null || !cachedObject.Contains("nTSecurityDescriptor") || cachedObject["nTSecurityDescriptor"].Value == null)
            {
                object[] objArray = new object[1];
                objArray[0] = directoryObj["distinguishedName"].Value;
                throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.InsufficientPermissionsToProtectObject, objArray));
            }
            else
            {
                if (ProtectedFromDeletionUtil.EveryoneDeniedDeleteAndDeleteTree(cachedObject) || Utils.HasFlagsSet((int)cachedObject["sdRightsEffective"].Value, 4))
                {
                    if (!Utils.IsNamingContext(cachedObject) && !Utils.IsDeleted(cachedObject))
                    {
                        string   parentPath = ADPathModule.GetParentPath(value, null, ADPathFormat.X500);
                        ADObject aDObject   = ProtectedFromDeletionUtil.GetCachedObject(parentPath, ProtectedFromDeletionUtil.AttributesToFetchOnParent, cmdletSessionInfo);
                        if (aDObject != null && !ProtectedFromDeletionUtil.EveryoneDeniedDeleteChild(aDObject))
                        {
                            if (Utils.HasFlagsSet((int)aDObject["sdRightsEffective"].Value, 4))
                            {
                                ActiveDirectorySecurity activeDirectorySecurity = (ActiveDirectorySecurity)aDObject["nTSecurityDescriptor"].Value;
                                activeDirectorySecurity.AddAccessRule(ProtectedFromDeletionUtil.ACEConstants.DeleteChildAccessRule);
                                using (ADActiveObject aDActiveObject = new ADActiveObject(cmdletSessionInfo.ADSessionInfo, aDObject))
                                {
                                    aDObject.TrackChanges = true;
                                    aDObject["nTSecurityDescriptor"].Value = activeDirectorySecurity;
                                    aDActiveObject.Update();
                                }
                            }
                            else
                            {
                                object[] value1 = new object[2];
                                value1[0] = directoryObj["distinguishedName"].Value;
                                value1[1] = aDObject["distinguishedName"].Value;
                                throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.InsufficientPermissionsToProtectObjectParent, value1));
                            }
                        }
                    }
                    ActiveDirectorySecurity activeDirectorySecurity1 = (ActiveDirectorySecurity)cachedObject["nTSecurityDescriptor"].Value;
                    if (ProtectedFromDeletionUtil.EveryoneDeniedDeleteAndDeleteTree(cachedObject))
                    {
                        return(false);
                    }
                    else
                    {
                        activeDirectorySecurity1.AddAccessRule(ProtectedFromDeletionUtil.ACEConstants.DeleteAndDeleteTreeAccessRule);
                        if (!directoryObj.Contains("nTSecurityDescriptor"))
                        {
                            directoryObj.Add("nTSecurityDescriptor", activeDirectorySecurity1);
                        }
                        else
                        {
                            directoryObj["nTSecurityDescriptor"].Value = activeDirectorySecurity1;
                        }
                        return(true);
                    }
                }
                else
                {
                    object[] objArray1 = new object[1];
                    objArray1[0] = directoryObj["distinguishedName"].Value;
                    throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.InsufficientPermissionsToProtectObject, objArray1));
                }
            }
        }