Inheritance: System.Data.Common.DBDataPermission
        private OleDbPermission UnionOleDb(OleDbPermission target, OleDbPermission newPermission)
        {
            if (null == target)
            {
                newPermission._providerRestriction = _providerRestriction;
            }
            else
            {
                string[] theseRestrictions = _providerRestriction; // MDAC 83107
                string[] thoseRestrictions = target._providerRestriction;

                if (null == theseRestrictions)
                {
                    newPermission._providerRestriction = thoseRestrictions;
                }
                else if (null == thoseRestrictions)
                {
                    newPermission._providerRestriction = theseRestrictions;
                }
                else   // union of two string[]
                {
                    int a = theseRestrictions.Length;
                    int b = thoseRestrictions.Length;

                    string[] restrictions = new string[a + b];
                    theseRestrictions.CopyTo(restrictions, 0);
                    thoseRestrictions.CopyTo(restrictions, a);
                    newPermission._providerRestriction = DBConnectionString.RemoveDuplicates(restrictions);
                }
            }
            return(newPermission);
        }
 private OleDbPermission(OleDbPermission permission) : base(permission)   // for Copy
 {
     if (null != permission)
     {
         _providerRestriction = permission._providerRestriction;
         _providers           = permission._providers;
     }
 }
示例#3
0
		public override IPermission CreatePermission () 
		{
			OleDbPermission p = new OleDbPermission (this);
#if !NET_2_0
			p.Provider = _provider;
#endif
			return p;
		}
示例#4
0
        public override IPermission CreatePermission()
        {
            OleDbPermission p = new OleDbPermission(this);

#if !NET_2_0
            p.Provider = _provider;
#endif
            return(p);
        }
        private OleDbPermission IntersectOleDb(OleDbPermission target, OleDbPermission newPermission)
        {
            string[] theseRestrictions = _providerRestriction; // MDAC 83107
            string[] thoseRestrictions = target._providerRestriction;

            if (null != theseRestrictions)
            {
                if (null != thoseRestrictions)
                {
                    int      count       = theseRestrictions.Length;
                    string[] restriction = new string[count];

                    int k = 0;
                    for (int i = 0; i < count; ++i)
                    {
                        if (0 <= Array.BinarySearch(thoseRestrictions, theseRestrictions[i], InvariantComparer.Default))
                        {
                            restriction[k] = theseRestrictions[i];
                            k++;
                        }
                    }
                    if (0 < k)
                    {
                        if (k < count)
                        {
                            // when Provider="SQLOLEDB" and target.Provider="SQLOLEDB;SQLOLEDB.1"
                            string[] tmp = new string[k];
                            for (int i = 0; i < k; ++i)
                            {
                                tmp[i] = restriction[i];
                            }
                            newPermission._providerRestriction = tmp;
                        }
                        else
                        {
                            // when Provider="SQLOLEDB" and target.Provider="SQLOLEDB"
                            newPermission._providerRestriction = restriction;
                        }
                    }
                    else
                    {
                        // when Provider="SQLOLEDB" and target.Provider="SQLOLEDB.1"
                        newPermission = null;
                    }
                }
                // else {
                // when Provider="SQLOLEDB" and target.Provider=""
                // return a non-null object so that later IsSubset calls fail
                //}
            }
            // else if ((null != thoseRestrictions) && (0 <= thoseRestrictions.Length)) {
            // when Provider="" and target.Provider="SQLOLEDB"
            // return a non-null object so that later IsSubset calls fail
            //}
            return(newPermission);
        }
        /// <include file='doc\OleDbPermission.uex' path='docs/doc[@for="OleDbPermission.Union"]/*' />
        override public IPermission Union(IPermission target)
        {
            OleDbPermission newPermission = (OleDbPermission)base.Union(target);

            if ((null != newPermission) && !newPermission.IsUnrestricted())
            {
                newPermission = UnionOleDb((target as OleDbPermission), newPermission);
            }
            return(newPermission);
        }
        /// <include file='doc\OleDbPermission.uex' path='docs/doc[@for="OleDbPermission.Intersect"]/*' />
        override public IPermission Intersect(IPermission target)   // used during Deny actions
        {
            OleDbPermission newPermission = (OleDbPermission)base.Intersect(target);

            if ((null != newPermission) && !newPermission.IsUnrestricted())
            {
                newPermission = IntersectOleDb((target as OleDbPermission), newPermission);
            }
            return(newPermission);
        }
		private void Check (string msg, OleDbPermission perm, bool blank, bool unrestricted, int count)
		{
			Assert.AreEqual (blank, perm.AllowBlankPassword, msg + ".AllowBlankPassword");
			Assert.AreEqual (unrestricted, perm.IsUnrestricted (), msg + ".IsUnrestricted");
			if (count == 0)
				Assert.IsNull (perm.ToXml ().Children, msg + ".Count != 0");
			else
				Assert.AreEqual (count, perm.ToXml ().Children.Count, msg + ".Count");
			Assert.AreEqual (String.Empty, perm.Provider, "Provider");
		}
		public void None ()
		{
			OleDbPermission perm = new OleDbPermission (PermissionState.None);
			Check ("None-1", perm, false, false, 0);
			perm.AllowBlankPassword = true;
			Check ("None-2", perm, true, false, 0);

			OleDbPermission copy = (OleDbPermission)perm.Copy ();
			Check ("Copy_None-1", copy, true, false, 0);
			copy.AllowBlankPassword = false;
			Check ("Copy_None-2", copy, false, false, 0);
		}
		public void None_Childs ()
		{
			OleDbPermission perm = new OleDbPermission (PermissionState.None);
			perm.Add ("data source=localhost;", String.Empty, KeyRestrictionBehavior.AllowOnly);
			perm.Add ("data source=127.0.0.1;", "password=;", KeyRestrictionBehavior.PreventUsage);

			Check ("None-Childs-1", perm, false, false, 2);
			perm.AllowBlankPassword = true;
			Check ("None-Childs-2", perm, true, false, 2);

			OleDbPermission copy = (OleDbPermission)perm.Copy ();
			Check ("Copy_None-Childs-1", copy, true, false, 2);
			copy.AllowBlankPassword = false;
			Check ("Copy_None-Childs-2", copy, false, false, 2);
		}
示例#11
0
 static internal PermissionSet CreatePermission(OleDbConnectionString constr) {
     OleDbPermission p = new OleDbPermission(constr);
     if (null == constr) {
         p.Add(ADP.StrEmpty, ADP.StrEmpty, KeyRestrictionBehavior.AllowOnly); // ExecuteOnly permission
     }
     PermissionSet permission;
     NamedPermissionSet fulltrust = new NamedPermissionSet("FullTrust"); // MDAC 83159
     fulltrust.Assert();
     try {
         permission = new PermissionSet(fulltrust);
         permission.AddPermission(p);
     }
     finally {
         CodeAccessPermission.RevertAssert();
     }
     return permission;
 }
        private bool IsSubsetOfOleDb(OleDbPermission target)
        {
            if (null != _providerRestriction)
            {
#if EMPTYFORALL
                if ((null != target._providerRestriction) && (0 < target._providerRestriction.Length))
                {
#else
                if (null != target._providerRestriction)
                {
#endif
                    int count = _providerRestriction.Length;
                    for (int i = 0; i < count; ++i)
                    {
                        if (0 > Array.BinarySearch(target._providerRestriction, _providerRestriction[i], InvariantComparer.Default))
                        {
                            // when Provider="SQLOLEDB" and target.Provider="SQLOLEDB.1"
                            // or when Provider="SQLOLEDB" and target.Provider="" but not when EMPTYFORALL
                            return(false);
                        }
                    }
                    // when Provider="SQLOLEDB" and target.Provider="SQLOLEDB"
                    // not when Provider="" and target.Provider="SQLOLEDB"
                    return(0 < count);
                }
#if EMPTYFORALL
                // when target.Provider="" or target.Provider=""
                return(true);
#else
                // when Provider="" or target.Provider=""
                return(0 == _providerRestriction.Length);
#endif
            }
            // when Provider="" and target.Provider=""
            // when Provider="" and target.Provider="SQLOLEDB"
            return(true); // MDAC 68928
        }
示例#13
0
 private OleDbPermission(OleDbPermission permission) : base(permission)
 {
 }
示例#14
0
        public override IPermission CreatePermission()
        {
            OleDbPermission p = new OleDbPermission(this);

            return(p);
        }
示例#15
0
 private OleDbPermission(OleDbPermission permission) : base(permission)   // for Copy
 {
 }
		public void Unrestricted ()
		{
			OleDbPermission perm = new OleDbPermission (PermissionState.Unrestricted);
			Check ("Unrestricted-1", perm, false, true, 0);
			perm.AllowBlankPassword = true;
			Check ("Unrestricted-2", perm, true, true, 0);

			OleDbPermission copy = (OleDbPermission)perm.Copy ();
			// note: Unrestricted is always created with default values (so AllowBlankPassword is false)
			Check ("Copy_Unrestricted-1", copy, false, true, 0);
			copy.AllowBlankPassword = true;
			Check ("Copy_Unrestricted-2", copy, true, true, 0);
		}
示例#17
0
		public override IPermission CreatePermission () 
		{
			OleDbPermission p = new OleDbPermission (this);
			return p;
		}
 private OleDbPermission(OleDbPermission permission) : base(permission) { // for Copy
 }
		public void PermissionState_Invalid ()
		{
			PermissionState ps = (PermissionState)Int32.MinValue;
			OleDbPermission perm = new OleDbPermission (ps);
		}
 private OleDbPermission(OleDbPermission permission) : base(permission)
 {
 }
		public void Provider ()
		{
			OleDbPermission perm = new OleDbPermission (PermissionState.None);
			perm.Provider = String.Empty;
			Assert.AreEqual (String.Empty, perm.Provider, "Empty");
			perm.Provider = "Mono";
			Assert.AreEqual ("Mono", perm.Provider, "Mono");
			perm.Provider = null;
			Assert.AreEqual (String.Empty, perm.Provider, "Empty(null)");
		}
		public void Unrestricted_Add ()
		{
			OleDbPermission perm = new OleDbPermission (PermissionState.Unrestricted);
			Check ("Unrestricted-NoChild", perm, false, true, 0);
			perm.Add ("data source=localhost;", String.Empty, KeyRestrictionBehavior.AllowOnly);
			// note: Lost unrestricted state when children was added
			Check ("Unrestricted-WithChild", perm, false, false, 1);
		}