Esempio n. 1
0
        private DBConnectionString(DbConnectionOptions connectionOptions, string restrictions, KeyRestrictionBehavior behavior, Hashtable synonyms, bool mustCloneDictionary)
        { // used by DBDataPermission
            Debug.Assert(null != connectionOptions, "null connectionOptions");
            switch (behavior)
            {
            case KeyRestrictionBehavior.PreventUsage:
            case KeyRestrictionBehavior.AllowOnly:
                _behavior = behavior;
                break;

            default:
                throw ADP.InvalidKeyRestrictionBehavior(behavior);
            }

            // grab all the parsed details from DbConnectionOptions
            _encryptedUsersConnectionString = connectionOptions.UsersConnectionString(false);
            _hasPassword = connectionOptions.HasPasswordKeyword;
            _parsetable  = connectionOptions.Parsetable;
            _keychain    = connectionOptions.KeyChain;

            // we do not want to serialize out user password unless directed so by "persist security info=true"
            // otherwise all instances of user's password will be replaced with "*"
            if (_hasPassword && !connectionOptions.HasPersistablePassword)
            {
                if (mustCloneDictionary)
                {
                    // clone the hashtable to replace user's password/pwd value with "*"
                    // we only need to clone if coming from DbConnectionOptions and password exists
                    _parsetable = (Hashtable)_parsetable.Clone();
                }

                // different than Everett in that instead of removing password/pwd from
                // the hashtable, we replace the value with '*'.  This is okay since we
                // serialize out with '*' so already knows what we do.  Better this way
                // than to treat password specially later on which causes problems.
                const string star = "*";
                if (_parsetable.ContainsKey(KEY.Password))
                {
                    _parsetable[KEY.Password] = star;
                }
                if (_parsetable.ContainsKey(KEY.Pwd))
                {
                    _parsetable[KEY.Pwd] = star;
                }

                // replace user's password/pwd value with "*" in the linked list and build a new string
                _keychain = connectionOptions.ReplacePasswordPwd(out _encryptedUsersConnectionString, true);
            }

            if (!ADP.IsEmpty(restrictions))
            {
                _restrictionValues = ParseRestrictions(restrictions, synonyms);
                _restrictions      = restrictions;
            }
        }
Esempio n. 2
0
 private static void Verify(string[] restrictionValues)
 {
     if (null != restrictionValues)
     {
         for (int i = 1; i < restrictionValues.Length; ++i)
         {
             Debug.Assert(!ADP.IsEmpty(restrictionValues[i - 1]), "empty restriction");
             Debug.Assert(!ADP.IsEmpty(restrictionValues[i]), "empty restriction");
             Debug.Assert(0 >= StringComparer.Ordinal.Compare(restrictionValues[i - 1], restrictionValues[i]));
         }
     }
 }
Esempio n. 3
0
        private static string[] ParseRestrictions(string restrictions, Hashtable synonyms)
        {
#if DEBUG
            if (Bid.AdvancedOn)
            {
                Bid.Trace("<comm.DBConnectionString|INFO|ADV> Restrictions='%ls'\n", restrictions);
            }
#endif
            List <string> restrictionValues = new List <string>();
            StringBuilder buffer            = new StringBuilder(restrictions.Length);

            int nextStartPosition = 0;
            int endPosition       = restrictions.Length;
            while (nextStartPosition < endPosition)
            {
                int startPosition = nextStartPosition;

                string keyname, keyvalue; // since parsing restrictions ignores values, it doesn't matter if we use ODBC rules or OLEDB rules
                nextStartPosition = DbConnectionOptions.GetKeyValuePair(restrictions, startPosition, buffer, false, out keyname, out keyvalue);
                if (!ADP.IsEmpty(keyname))
                {
#if DEBUG
                    if (Bid.AdvancedOn)
                    {
                        Bid.Trace("<comm.DBConnectionString|INFO|ADV> KeyName='%ls'\n", keyname);
                    }
#endif
                    string realkeyname = ((null != synonyms) ? (string)synonyms[keyname] : keyname); // MDAC 85144
                    if (ADP.IsEmpty(realkeyname))
                    {
                        throw ADP.KeywordNotSupported(keyname);
                    }
                    restrictionValues.Add(realkeyname);
                }
            }
            return(RemoveDuplicates(restrictionValues.ToArray()));
        }