Exemplo n.º 1
0
        private static ADObject GetCachedObject(string DN, string[] directoryAttributes, CmdletSessionInfo cmdletSessionInfo)
        {
            IDictionary <string, ADObject> protectedFromDeletionCache = ProtectedFromDeletionUtil.GetProtectedFromDeletionCache(cmdletSessionInfo);

            if (!protectedFromDeletionCache.ContainsKey(DN))
            {
                protectedFromDeletionCache.Add(DN, Utils.GetDirectoryObject(DN, directoryAttributes, cmdletSessionInfo));
            }
            return(protectedFromDeletionCache[DN]);
        }
Exemplo n.º 2
0
        internal static void ToExtendedProtectedFromDeletion(string extendedAttribute, string[] directoryAttributes, ADEntity userObj, ADEntity directoryObj, CmdletSessionInfo cmdletSessionInfo)
        {
            ADObject aDObject = directoryObj as ADObject;

            if (aDObject == null)
            {
                object[] type = new object[2];
                type[0] = "ToExtendedProtectedFromDeletion";
                type[1] = directoryObj.GetType();
                throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, StringResources.MethodNotSupportedForObjectType, type));
            }
            else
            {
                userObj.Add(extendedAttribute, ProtectedFromDeletionUtil.IsProtectedFromDeletion(aDObject, cmdletSessionInfo));
                return;
            }
        }
Exemplo n.º 3
0
        private bool ADObjectPostCommitFSRoutine(ADFactory <T> .DirectoryOperation operation, T instance, ADParameterSet parameters, ADObject directoryObj)
        {
            bool hasValue;

            if (operation != ADFactory <T> .DirectoryOperation.Create || !base.PropertyHasChange(ADObjectFactory <T> .ADObjectPropertyMap.ProtectedFromDeletion.PropertyName, instance, parameters, operation))
            {
                if (operation != ADFactory <T> .DirectoryOperation.Create || !ProtectedFromDeletionUtil.ShouldProtectByDefault(directoryObj.ObjectClass))
                {
                    return(false);
                }
                else
                {
                    return(ProtectedFromDeletionUtil.ProtectFromAccidentalDeletion(directoryObj, base.CmdletSessionInfo));
                }
            }
            else
            {
                bool?singleValueProperty = base.GetSingleValueProperty <bool?>(ADObjectFactory <T> .ADObjectPropertyMap.ProtectedFromDeletion.PropertyName, instance, parameters, operation);
                if (singleValueProperty.HasValue)
                {
                    bool?nullable = singleValueProperty;
                    if (!nullable.GetValueOrDefault())
                    {
                        hasValue = false;
                    }
                    else
                    {
                        hasValue = nullable.HasValue;
                    }
                    if (!hasValue)
                    {
                        return(ProtectedFromDeletionUtil.UnprotectFromAccidentalDeletion(directoryObj, base.CmdletSessionInfo));
                    }
                    else
                    {
                        return(ProtectedFromDeletionUtil.ProtectFromAccidentalDeletion(directoryObj, base.CmdletSessionInfo));
                    }
                }
                else
                {
                    return(false);
                }
            }
        }
Exemplo n.º 4
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));
            }
        }
Exemplo n.º 5
0
        private static void AddObjectToCache(ADObject directoryObj, CmdletSessionInfo cmdletSessionInfo)
        {
            IDictionary <string, ADObject> protectedFromDeletionCache = ProtectedFromDeletionUtil.GetProtectedFromDeletionCache(cmdletSessionInfo);

            protectedFromDeletionCache[directoryObj.DistinguishedName] = directoryObj;
        }
Exemplo n.º 6
0
 internal static bool UnprotectFromAccidentalDeletion(ADObject directoryObj, ADSessionInfo sessionInfo)
 {
     return(ProtectedFromDeletionUtil.UnprotectFromAccidentalDeletion(directoryObj, ProtectedFromDeletionUtil.BuildCmdletSessionInfo(sessionInfo)));
 }
Exemplo n.º 7
0
        internal static bool UnprotectFromAccidentalDeletion(ADObject directoryObj, CmdletSessionInfo cmdletSessionInfo)
        {
            ADObject cachedObject;
            bool     hasValue;
            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)
            {
                bool?nullable = ProtectedFromDeletionUtil.IsProtectedFromDeletion(cachedObject, cmdletSessionInfo);
                if (nullable.HasValue)
                {
                    bool?nullable1 = nullable;
                    if (nullable1.GetValueOrDefault())
                    {
                        hasValue = false;
                    }
                    else
                    {
                        hasValue = nullable1.HasValue;
                    }
                    if (!hasValue)
                    {
                        if (Utils.HasFlagsSet((int)cachedObject["sdRightsEffective"].Value, 4))
                        {
                            ActiveDirectorySecurity activeDirectorySecurity = (ActiveDirectorySecurity)cachedObject["nTSecurityDescriptor"].Value;
                            activeDirectorySecurity.RemoveAccessRule(ProtectedFromDeletionUtil.ACEConstants.DeleteAndDeleteTreeAccessRule);
                            if (!directoryObj.Contains("nTSecurityDescriptor"))
                            {
                                directoryObj.Add("nTSecurityDescriptor", activeDirectorySecurity);
                            }
                            else
                            {
                                directoryObj["nTSecurityDescriptor"].Value = activeDirectorySecurity;
                            }
                            return(true);
                        }
                        else
                        {
                            object[] objArray = new object[1];
                            objArray[0] = directoryObj["distinguishedName"].Value;
                            throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.InsufficientPermissionsToProtectObject, objArray));
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    object[] value1 = new object[1];
                    value1[0] = directoryObj["distinguishedName"].Value;
                    throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.InsufficientPermissionsToProtectObject, value1));
                }
            }
            else
            {
                object[] objArray1 = new object[1];
                objArray1[0] = directoryObj["distinguishedName"].Value;
                throw new ADException(string.Format(CultureInfo.CurrentCulture, StringResources.InsufficientPermissionsToProtectObject, objArray1));
            }
        }
Exemplo n.º 8
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));
                }
            }
        }
Exemplo n.º 9
0
 internal static bool?IsProtectedFromDeletion(ADObject directoryObj, ADSessionInfo sessionInfo)
 {
     return(ProtectedFromDeletionUtil.IsProtectedFromDeletion(directoryObj, ProtectedFromDeletionUtil.BuildCmdletSessionInfo(sessionInfo)));
 }