示例#1
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;
            }
        }
示例#2
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));
            }
        }
示例#3
0
 internal static bool?IsProtectedFromDeletion(ADObject directoryObj, ADSessionInfo sessionInfo)
 {
     return(ProtectedFromDeletionUtil.IsProtectedFromDeletion(directoryObj, ProtectedFromDeletionUtil.BuildCmdletSessionInfo(sessionInfo)));
 }