예제 #1
0
        /// <summary>
        /// Overridden ProcessRecord method.
        /// </summary>
        protected override void ProcessRecord()
        {
            if (MapType && Type == null)
            {
                WriteWarning("Must specify Type for MapType to work correctly.");
            }

            SecurityDescriptor sd;

            switch (ParameterSetName)
            {
            case "FromToken":
            {
                Type = Type ?? Parent?.NtType ?? Creator?.NtType;
                if (Type == null)
                {
                    WriteWarning("Security descriptor type not specified, defaulting to File.");
                    Type = NtType.GetTypeByType <NtFile>();
                }
                sd = SecurityDescriptor.Create(Parent, Creator, IsDirectory, AutoInherit, Token, Type.GenericMapping);
            }
            break;

            case "FromSddl":
                sd = new SecurityDescriptor(Sddl);
                break;

            case "FromBytes":
                sd = new SecurityDescriptor(Bytes);
                break;

            case "FromKey":
                sd = new SecurityDescriptor(Key.QueryValue(ValueName).Data);
                break;

            case "FromKeyValue":
                sd = new SecurityDescriptor(KeyValue.Data);
                break;

            default:
                sd = new SecurityDescriptor
                {
                    Dacl = new Acl()
                };
                sd.Dacl.NullAcl = NullDacl;
                break;
            }

            sd.NtType = Type;
            if (MapType)
            {
                sd.MapGenericAccess();
            }

            UpdateSecurityDescriptorControl(sd, Control);
            WriteObject(sd);
        }
        /// <summary>
        /// Overridden ProcessRecord method.
        /// </summary>
        protected override void ProcessRecord()
        {
            if (MapGeneric && Type == null)
            {
                WriteWarning("Must specify Type for MapGeneric to work correctly.");
            }

            SecurityDescriptor sd;

            switch (ParameterSetName)
            {
            case "FromToken":
            {
                Type = Type ?? Parent?.NtType ?? Creator?.NtType;
                if (Type == null)
                {
                    WriteWarning("Security descriptor type not specified, defaulting to File.");
                    Type = NtType.GetTypeByType <NtFile>();
                }

                using (var list = new DisposableList())
                {
                    if (EffectiveToken)
                    {
                        Token = list.AddResource(NtToken.OpenEffectiveToken());
                    }
                    sd = SecurityDescriptor.Create(Parent, Creator, ObjectType,
                                                   Container, AutoInherit, Token, Type.GenericMapping);
                }
            }
            break;

            case "FromSddl":
                sd = new SecurityDescriptor(Sddl);
                break;

            case "FromBytes":
                sd = new SecurityDescriptor(Byte);
                break;

            case "FromKey":
                sd = new SecurityDescriptor(Key.QueryValue(ValueName).Data);
                break;

            case "FromKeyValue":
                sd = new SecurityDescriptor(KeyValue.Data);
                break;

            case "FromBase64":
                sd = SecurityDescriptor.ParseBase64(Base64);
                break;

            default:
                sd = CreateNewSecurityDescriptor();
                break;
            }

            sd.NtType    = Type;
            sd.Container = Container;
            if (MapGeneric)
            {
                sd.MapGenericAccess();
            }

            sd.Control |= Control;
            WriteObject(sd);
        }