示例#1
0
        private EntryModel GetEntry(AceInfo entry)
        {
            var identityPath = NodeHead.Get(entry.IdentityId)?.Path;

            if (identityPath == null)
            {
                return(null);
            }

            var perms = new Dictionary <string, object>();

            foreach (var permissionType in PermissionType.PermissionTypes)
            {
                var allow = (entry.AllowBits & permissionType.Mask) != 0;
                var deny  = (entry.DenyBits & permissionType.Mask) != 0;
                if (allow || deny)
                {
                    perms.Add(permissionType.Name, deny ? "deny" : "allow");
                }
            }

            return(new EntryModel
            {
                Identity = identityPath,
                LocalOnly = entry.LocalOnly,
                Permissions = perms
            });
        }
        public void Sharing_AclEd_SettingInconsistentEntryIsInvalidOperation()
        {
            EnsureRepository();
            var ctx           = CurrentContext.Security;
            var normalEditor  = ctx.CreateAclEditor();
            var sharingEditor = ctx.CreateAclEditor(EntryType.Sharing);
            var normalEntry   = new AceInfo {
                EntryType = EntryType.Normal, IdentityId = Id("U1"), AllowBits = 0x1ul
            };
            var sharingEntry = new AceInfo {
                EntryType = EntryType.Sharing, IdentityId = Id("U2"), AllowBits = 0x2ul
            };

            // ACTION 1
            normalEditor.SetEntry(Id("E1"), normalEntry, false);
            try
            {
                normalEditor.SetEntry(Id("E1"), sharingEntry, false);
                Assert.Fail();
            }
            catch (InvalidOperationException)
            {
            }

            // ACTION 2
            sharingEditor.SetEntry(Id("E1"), sharingEntry, false);
            try
            {
                sharingEditor.SetEntry(Id("E1"), normalEntry, false);
                Assert.Fail();
            }
            catch (InvalidOperationException)
            {
            }
        }
示例#3
0
        public static void Export(this AceInfo aceInfo, XmlWriter writer)
        {
            writer.WriteStartElement("Identity");
            writer.WriteAttributeString("path", NodeHead.Get(aceInfo.IdentityId).Path);
            if (aceInfo.LocalOnly)
            {
                writer.WriteAttributeString("propagation", "LocalOnly");
            }
            var values = aceInfo.GetPermissionValues();

            foreach (var permType in PermissionType.PermissionTypes)
            {
                var value = values[permType.Index];
                if (value == PermissionValue.Undefined)
                {
                    continue;
                }
                writer.WriteElementString(permType.Name, value.ToString());
            }
            writer.WriteEndElement();
        }
示例#4
0
        private static Texture2D Texture2DFromReader(GraphicsDevice graphicsDevice, BinaryReader reader)
        {
            string signature = new string(reader.ReadChars(4));

            if (signature != "\x01\x00\x00\x00")
            {
                throw new InvalidDataException($"Incorrect signature; expected '01 00 00 00', got '{StringToHex(signature)}'");
            }
            SimisAceFormatOptions options = (SimisAceFormatOptions)reader.ReadInt32();
            int width         = reader.ReadInt32();
            int height        = reader.ReadInt32();
            int surfaceFormat = reader.ReadInt32();
            int channelCount  = reader.ReadInt32();

            reader.ReadBytes(128); // Miscellaneous other data we don't care about.

            // If there are mipmaps, we must validate that the image is square and dimensions are an integral power-of-two.
            if ((options & SimisAceFormatOptions.MipMaps) != 0)
            {
                if (width != height)
                {
                    throw new InvalidDataException($"Dimensions must match when mipmaps are used; got {width}x{height}");
                }
                if (width == 0 || (width & (width - 1)) != 0)
                {
                    throw new InvalidDataException($"Width must be an integral power of 2 when mipmaps are used; got {width}");
                }
                if (height == 0 || (height & (height - 1)) != 0)
                {
                    throw new InvalidDataException($"Height must be an integral power of 2 when mipmaps are used; got {height}");
                }
            }

            // If the data is raw data, we must be able to convert the Ace format in to an XNA format or we'll blow up.
            SurfaceFormat textureFormat = SurfaceFormat.Color;

            if ((options & SimisAceFormatOptions.RawData) != 0)
            {
                if (!SimisAceSurfaceFormats.ContainsKey(surfaceFormat))
                {
                    throw new InvalidDataException($"Unsupported surface format {surfaceFormat:X8}");
                }
                textureFormat = SimisAceSurfaceFormats[surfaceFormat];
            }

            // Calculate how many images we're going to load; 1 for non-mipmapped, 1+log(width)/log(2) for mipmapped.
            int       imageCount = 1 + (int)((options & SimisAceFormatOptions.MipMaps) != 0 ? Math.Log(width) / Math.Log(2) : 0);
            Texture2D texture;

            if ((options & SimisAceFormatOptions.MipMaps) == 0)
            {
                texture = new Texture2D(graphicsDevice, width, height, false, textureFormat);
            }
            else
            {
                texture = new Texture2D(graphicsDevice, width, height, true, textureFormat);
            }

            // Read in the color channels; each one defines a size (in bits) and type (reg, green, blue, mask, alpha).
            var channels = new List <SimisAceChannel>();

            for (var channel = 0; channel < channelCount; channel++)
            {
                var size = (byte)reader.ReadUInt64();
                if ((size != 1) && (size != 8))
                {
                    throw new InvalidDataException($"Unsupported color channel size {size}");
                }
                var type = reader.ReadUInt64();
                if ((type < 2) || (type > 6))
                {
                    throw new InvalidDataException($"Unknown color channel type {type}");
                }
                channels.Add(new SimisAceChannel(size, (SimisAceChannelId)type));
            }

            // Construct some info about this texture for the game to use in optimisations.
            var aceInfo = new AceInfo();

            texture.Tag = aceInfo;
            if (channels.Any(c => c.Type == SimisAceChannelId.Alpha))
            {
                aceInfo.AlphaBits = 8;
            }
            else if (channels.Any(c => c.Type == SimisAceChannelId.Mask))
            {
                aceInfo.AlphaBits = 1;
            }

            if ((options & SimisAceFormatOptions.RawData) != 0)
            {
                // Raw data is stored as a table of 32bit int offsets to each mipmap level.
                reader.ReadBytes(imageCount * 4);

                var buffer = new byte[0];
                for (var imageIndex = 0; imageIndex < imageCount; imageIndex++)
                {
                    var imageWidth  = width / (int)Math.Pow(2, imageIndex);
                    var imageHeight = height / (int)Math.Pow(2, imageIndex);

                    // If the mipmap level is width>=4, it is stored as raw data with a 32bit int length header.
                    // Otherwise, it is stored as a 32bit ARGB block.
                    if (imageWidth >= 4 && imageHeight >= 4)
                    {
                        buffer = reader.ReadBytes(reader.ReadInt32());
                    }

                    // For <4 pixels the images are in RGB format. There's no point reading them though, as the
                    // API accepts the 4x4 image's data for the 2x2 and 1x1 case. They do need to be set though!

                    texture.SetData(imageIndex, null, buffer, 0, buffer.Length);
                }
            }
            else
            {
                // Structured data is stored as a table of 32bit offsets to each scanline of each image.
                for (var imageIndex = 0; imageIndex < imageCount; imageIndex++)
                {
                    reader.ReadBytes(4 * height / (int)Math.Pow(2, imageIndex));
                }

                var buffer         = new int[width * height];
                var channelBuffers = new byte[8][];
                for (var imageIndex = 0; imageIndex < imageCount; imageIndex++)
                {
                    var imageWidth  = width / (int)Math.Pow(2, imageIndex);
                    var imageHeight = height / (int)Math.Pow(2, imageIndex);
                    for (var y = 0; y < imageHeight; y++)
                    {
                        foreach (var channel in channels)
                        {
                            if (channel.Size == 1)
                            {
                                // 1bpp channels start with the MSB and work down to LSB and then the next byte.
                                var bytes = reader.ReadBytes((int)Math.Ceiling((double)channel.Size * imageWidth / 8));
                                channelBuffers[(int)channel.Type] = new byte[imageWidth];
                                for (var x = 0; x < imageWidth; x++)
                                {
                                    channelBuffers[(int)channel.Type][x] = (byte)(((bytes[x / 8] >> (7 - (x % 8))) & 1) * 0xFF);
                                }
                            }
                            else
                            {
                                // 8bpp are simple.
                                channelBuffers[(int)channel.Type] = reader.ReadBytes(imageWidth);
                            }
                        }
                        for (var x = 0; x < imageWidth; x++)
                        {
                            buffer[imageWidth * y + x] = channelBuffers[(int)SimisAceChannelId.Red][x] + (channelBuffers[(int)SimisAceChannelId.Green][x] << 8) + (channelBuffers[(int)SimisAceChannelId.Blue][x] << 16);
                            if (channelBuffers[(int)SimisAceChannelId.Alpha] != null)
                            {
                                buffer[imageWidth * y + x] += channelBuffers[(int)SimisAceChannelId.Alpha][x] << 24;
                            }
                            else if (channelBuffers[(int)SimisAceChannelId.Mask] != null)
                            {
                                buffer[imageWidth * y + x] += channelBuffers[(int)SimisAceChannelId.Mask][x] << 24;
                            }
                            else
                            {
                                buffer[imageWidth * y + x] += (0xFF << 24);
                            }
                        }
                    }
                    texture.SetData(imageIndex, null, buffer, 0, imageWidth * imageHeight);
                }
            }

            return(texture);
        }
 internal PermissionChange(SecurityEntity entity, AceInfo entry) : this(entity, entry.IdentityId,
                                                                        entry.EntryType,
                                                                        entry.AllowBits, entry.DenyBits)
 {
 }