private static void CallUnmanagedCodeWithoutPermission()
    {
        // Create a security permission object to describe the
        // UnmanagedCode permission:
        SecurityPermission perm =
           new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);

        // Deny the UnmanagedCode from our current set of permissions.
        // Any method that is called on this thread until this method
        // returns will be denied access to unmanaged code.
        // Even though the CallUnmanagedCodeWithPermission method
        // is called from a stack frame that already
        // calls Assert for unmanaged code, you still cannot call native
        // code. Because you use Deny here, the permission gets
        // overwritten.
        perm.Deny();

        try
        {
            Console.WriteLine("Attempting to call unmanaged code without permission.");
            NativeMethods.puts("Hello World!");
            NativeMethods._flushall();
            Console.WriteLine("Called unmanaged code without permission. Whoops!");
        }
        catch (SecurityException)
        {
            Console.WriteLine("Caught Security Exception attempting to call unmanaged code.");
        }
    }
    public static void Main()
    {
        SecurityPermission perm = new
                                  SecurityPermission(SecurityPermissionFlag.UnmanagedCode);

        // The method itself is attached with the security permission Deny
        // for unmanaged code, which will override the Assert permission in
        // this stack frame. However, because you are using
        // SuppressUnmanagedCodeSecurityAttribute, you can still call the
        // unmanaged methods successfully.
        // The code should use other security checks to ensure that you
        // don't incur a security hole.
        perm.Assert();
        CallUnmanagedCodeWithoutPermission();

        // The method itself is attached with the security permission
        // Assert for unmanaged code, which will override the Deny
        // permission in this stack frame. Because you are using
        // SuppressUnmanagedCodeSecurityAttribute, you can call the
        // unmanaged methods successfully.
        // The SuppressUnmanagedCodeSecurityAttribute will let you succeed,
        // even if you don't have a permission.
        perm.Deny();
        CallUnmanagedCodeWithPermission();
    }
    private Object Deserialize(SoapFormatter formatter, MemoryStream stream)
    {
        SecurityPermission perm = new SecurityPermission(SecurityPermissionFlag.SerializationFormatter);

        perm.Deny();
        return(formatter.Deserialize(stream));
    }
예제 #4
0
    private void ConstructOM()
    {
        SecurityPermission perm = new SecurityPermission(SecurityPermissionFlag.SerializationFormatter);

        perm.Deny();
        ObjectManager manager = new ObjectManager(null, new StreamingContext(StreamingContextStates.All));
    }
    private void Serialize(SoapFormatter formatter, MemoryStream stream, Object value)
    {
        SecurityPermission perm = new SecurityPermission(SecurityPermissionFlag.SerializationFormatter);

        perm.Deny();
        formatter.Serialize(stream, value);
    }
예제 #6
0
    private static void CallUnmanagedCodeWithoutPermission()
    {
        // Create a security permission object to describe the
        // UnmanagedCode permission:
        SecurityPermission perm =
            new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);

        // Deny the UnmanagedCode from our current set of permissions.
        // Any method that is called on this thread until this method
        // returns will be denied access to unmanaged code.
        // Even though the CallUnmanagedCodeWithPermission method
        // is called from a stack frame that already
        // calls Assert for unmanaged code, you still cannot call native
        // code. Because you use Deny here, the permission gets
        // overwritten.
        perm.Deny();

        try
        {
            Console.WriteLine("Attempting to call unmanaged code without permission.");
            NativeMethods.puts("Hello World!");
            NativeMethods._flushall();
            Console.WriteLine("Called unmanaged code without permission. Whoops!");
        }
        catch (SecurityException)
        {
            Console.WriteLine("Caught Security Exception attempting to call unmanaged code.");
        }
    }
    public static void Main()
    {
        SecurityPermission perm = new
            SecurityPermission(SecurityPermissionFlag.UnmanagedCode);

           // The method itself is attached with the security permission Deny
           // for unmanaged code, which will override the Assert permission in
           // this stack frame. However, because you are using
           // SuppressUnmanagedCodeSecurityAttribute, you can still call the
           // unmanaged methods successfully.
           // The code should use other security checks to ensure that you
           // don't incur a security hole.
           perm.Assert();
           CallUnmanagedCodeWithoutPermission();

           // The method itself is attached with the security permission
           // Assert for unmanaged code, which will override the Deny
           // permission in this stack frame. Because you are using
           // SuppressUnmanagedCodeSecurityAttribute, you can call the
           // unmanaged methods successfully.
           // The SuppressUnmanagedCodeSecurityAttribute will let you succeed,
           // even if you don't have a permission.
           perm.Deny();
           CallUnmanagedCodeWithPermission();
    }
    public static void Main()
    {
        // The method itself will call the security permission Deny
        // for unmanaged code, which will override the Assert permission
        // in this stack frame.
        SecurityPermission perm = new
            SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
        perm.Assert();
        CallUnmanagedCodeWithoutPermission();

        // The method itself will call the security permission Assert
        // for unmanaged code, which will override the Deny permission in
        // this stack frame.
        perm.Deny();
        CallUnmanagedCodeWithPermission();
    }
    public static void Main()
    {
        SecurityPermission perm = new
            SecurityPermission(SecurityPermissionFlag.UnmanagedCode);

        // The method itself is attached with the security permission
        // Deny for unmanaged code, which will override
        // the Assert permission in this stack frame.
        perm.Assert();
        CallUnmanagedCodeWithoutPermission();

        // The method itself is attached with the security permission
        // Assert for unmanaged code, which will override the Deny
        // permission in this stack frame.
        perm.Deny();
        CallUnmanagedCodeWithPermission();
    }
예제 #10
0
    public static void Main()
    {
        // The method itself will call the security permission Deny
        // for unmanaged code, which will override the Assert permission
        // in this stack frame.
        SecurityPermission perm = new
                                  SecurityPermission(SecurityPermissionFlag.UnmanagedCode);

        perm.Assert();
        CallUnmanagedCodeWithoutPermission();

        // The method itself will call the security permission Assert
        // for unmanaged code, which will override the Deny permission in
        // this stack frame.
        perm.Deny();
        CallUnmanagedCodeWithPermission();
    }
예제 #11
0
    public static void Main()
    {
        SecurityPermission perm = new
                                  SecurityPermission(SecurityPermissionFlag.UnmanagedCode);

        // The method itself is attached with the security permission
        // Deny for unmanaged code, which will override
        // the Assert permission in this stack frame.
        perm.Assert();
        CallUnmanagedCodeWithoutPermission();

        // The method itself is attached with the security permission
        // Assert for unmanaged code, which will override the Deny
        // permission in this stack frame.
        perm.Deny();
        CallUnmanagedCodeWithPermission();
    }
예제 #12
0
	private void ConstructOM()
	{
		SecurityPermission perm = new SecurityPermission(SecurityPermissionFlag.SerializationFormatter);
		perm.Deny();
		ObjectManager manager = new ObjectManager(null, new StreamingContext(StreamingContextStates.All));
	}
예제 #13
0
	private Object Deserialize(SoapFormatter formatter, MemoryStream stream)
	{
		SecurityPermission perm = new SecurityPermission(SecurityPermissionFlag.SerializationFormatter);
		perm.Deny();
		return formatter.Deserialize(stream);
	}
예제 #14
0
	private void Serialize(SoapFormatter formatter, MemoryStream stream, Object value)
	{
		SecurityPermission perm = new SecurityPermission(SecurityPermissionFlag.SerializationFormatter);
		perm.Deny();
		formatter.Serialize(stream, value);
	}