/// <summary>
        /// Parse the RopModifyPermissionsRequest structure.
        /// </summary>
        /// <param name="s">A stream containing RopModifyPermissionsRequest structure.</param>
        public override void Parse(Stream s)
        {
            base.Parse(s);
            this.RopId            = (RopIdType)this.ReadByte();
            this.LogonId          = this.ReadByte();
            this.InputHandleIndex = this.ReadByte();
            this.ModifyFlags      = (ModifyFlags)this.ReadByte();
            this.ModifyCount      = this.ReadUshort();
            List <PermissionData> listPermissionData = new List <PermissionData>();

            for (int i = 0; i < this.ModifyCount; i++)
            {
                PermissionData tempPermissionData = new PermissionData();
                tempPermissionData.Parse(s);
                listPermissionData.Add(tempPermissionData);
            }

            this.PermissionsData = listPermissionData.ToArray();
        }
Beispiel #2
0
        public static bool TryParseModifyOptions(
            IEnumerable <string> values,
            string optionName,
            EnumerableModifier <string>?modifier,
            [NotNullWhen(true)] out ModifyOptions?modifyOptions,
            out bool aggregateOnly)
        {
            modifyOptions = null;
            aggregateOnly = false;

            var           sortProperty = ValueSortProperty.None;
            List <string>?options      = null;

            foreach (string value in values)
            {
                int index = value.IndexOf('=');

                if (index >= 0)
                {
                    string key    = value.Substring(0, index);
                    string value2 = value.Substring(index + 1);

                    if (OptionValues.SortBy.IsKeyOrShortKey(key))
                    {
                        if (!TryParseAsEnum(
                                value2,
                                optionName,
                                out sortProperty,
                                provider: OptionValueProviders.ValueSortPropertyProvider))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        WriteOptionError(value, optionName, OptionValueProviders.ModifyFlagsProvider);
                        return(false);
                    }
                }
                else
                {
                    string value2 = value;

                    if (value2 == "ao")
                    {
                        LogHelpers.WriteObsoleteWarning(
                            $"Value '{value2}' is obsolete. Use value '{OptionValues.ModifyFlags_AggregateOnly.HelpValue}' instead.");

                        value2 = OptionValues.ModifyFlags_AggregateOnly.ShortValue;
                    }

                    (options ??= new List <string>()).Add(value2);
                }
            }

            var modifyFlags = ModifyFlags.None;

            if (options != null &&
                !TryParseAsEnumFlags(
                    options,
                    optionName,
                    out modifyFlags,
                    provider: OptionValueProviders.ModifyFlagsProvider))
            {
                return(false);
            }

            ModifyFlags except_Intersect_Group = modifyFlags & ModifyFlags.Except_Intersect_Group;

            if (except_Intersect_Group != ModifyFlags.None &&
                except_Intersect_Group != ModifyFlags.Except &&
                except_Intersect_Group != ModifyFlags.Intersect &&
                except_Intersect_Group != ModifyFlags.Group)
            {
                WriteError($"Values '{OptionValues.ModifyFlags_Except.HelpValue}', "
                           + $"'{OptionValues.ModifyFlags_Intersect.HelpValue}' and "
                           + $"'{OptionValues.ModifyFlags_Group.HelpValue}' cannot be used at the same time.");

                return(false);
            }

            var functions = ModifyFunctions.None;

            if ((modifyFlags & ModifyFlags.Distinct) != 0)
            {
                functions |= ModifyFunctions.Distinct;
            }

            if ((modifyFlags & ModifyFlags.Ascending) != 0)
            {
                functions |= ModifyFunctions.Sort;
            }

            if ((modifyFlags & ModifyFlags.Descending) != 0)
            {
                functions |= ModifyFunctions.SortDescending;
            }

            if ((modifyFlags & ModifyFlags.Except) != 0)
            {
                functions |= ModifyFunctions.Except;
            }

            if ((modifyFlags & ModifyFlags.Intersect) != 0)
            {
                functions |= ModifyFunctions.Intersect;
            }

            if ((modifyFlags & ModifyFlags.Group) != 0)
            {
                functions |= ModifyFunctions.Group;
            }

            if ((modifyFlags & ModifyFlags.RemoveEmpty) != 0)
            {
                functions |= ModifyFunctions.RemoveEmpty;
            }

            if ((modifyFlags & ModifyFlags.RemoveWhiteSpace) != 0)
            {
                functions |= ModifyFunctions.RemoveWhiteSpace;
            }

            if ((modifyFlags & ModifyFlags.TrimStart) != 0)
            {
                functions |= ModifyFunctions.TrimStart;
            }

            if ((modifyFlags & ModifyFlags.TrimEnd) != 0)
            {
                functions |= ModifyFunctions.TrimEnd;
            }

            if ((modifyFlags & ModifyFlags.ToLower) != 0)
            {
                functions |= ModifyFunctions.ToLower;
            }

            if ((modifyFlags & ModifyFlags.ToUpper) != 0)
            {
                functions |= ModifyFunctions.ToUpper;
            }

            if (sortProperty != ValueSortProperty.None &&
                (functions & ModifyFunctions.Sort) == 0 &&
                (functions & ModifyFunctions.SortDescending) == 0)
            {
                functions |= ModifyFunctions.Sort;
            }

            aggregateOnly = (modifyFlags & ModifyFlags.AggregateOnly) != 0;

            if (modifyFlags != ModifyFlags.None ||
                functions != ModifyFunctions.None ||
                modifier != null)
            {
                modifyOptions = new ModifyOptions(
                    functions: functions,
                    aggregate: (modifyFlags & ModifyFlags.Aggregate) != 0 || aggregateOnly,
                    ignoreCase: (modifyFlags & ModifyFlags.IgnoreCase) != 0,
                    cultureInvariant: (modifyFlags & ModifyFlags.CultureInvariant) != 0,
                    sortProperty: sortProperty,
                    modifier: modifier);
            }
            else
            {
                modifyOptions = ModifyOptions.Default;
            }

            return(true);
        }
        /// <summary>
        /// Create buffer to get ModifyPermissions
        /// </summary>
        /// <param name="permissionsDataArray">Permission data array is used to set permission</param>
        /// <param name="modifyFlags">Set the ModifyFlags, specified in [MS-OXCPERM] section 2.2.2</param>
        /// <returns>A request used to modify permissions</returns>
        private RopModifyPermissionsRequest CreateModifyPermissionsRequestBuffer(PermissionData[] permissionsDataArray, ModifyFlags modifyFlags)
        {
            RopModifyPermissionsRequest modifyPermissionsRequest = new RopModifyPermissionsRequest
            {
                RopId = (byte)RopId.RopModifyPermissions,
                LogonId = Constants.CommonLogonId,
                InputHandleIndex = Constants.CommonInputHandleIndex,
                ModifyFlags = (byte)modifyFlags,
                ModifyCount = (ushort)permissionsDataArray.Length,
                PermissionsData = permissionsDataArray
            };

            return modifyPermissionsRequest;
        }
        /// <summary>
        /// Parse the RopModifyPermissionsRequest structure.
        /// </summary>
        /// <param name="s">An stream containing RopModifyPermissionsRequest structure.</param>
        public override void Parse(Stream s)
        {
            base.Parse(s);

            this.RopId = (RopIdType)ReadByte();
            this.LogonId = ReadByte();
            this.InputHandleIndex = ReadByte();
            this.ModifyFlags = (ModifyFlags)ReadByte();
            this.ModifyCount = ReadUshort();
            List<PermissionData> listPermissionData = new List<PermissionData>();
            for (int i = 0; i < ModifyCount; i++)
            {
                PermissionData tempPermissionData = new PermissionData();
                tempPermissionData.Parse(s);
                listPermissionData.Add(tempPermissionData);
            }
            this.PermissionsData = listPermissionData.ToArray();
        }