private static void RevokeAllGrants(IQuery queryContext, IMutableTable grantTable, DbObjectType objectType,
                                            ObjectName objectName, string revoker, string grantee, bool withOption = false)
        {
            var objectCol      = grantTable.GetResolvedColumnName(1);
            var paramCol       = grantTable.GetResolvedColumnName(2);
            var granteeCol     = grantTable.GetResolvedColumnName(3);
            var grantOptionCol = grantTable.GetResolvedColumnName(4);
            var granterCol     = grantTable.GetResolvedColumnName(5);

            ITable t1 = grantTable;

            // All that match the given object parameter
            // It's most likely this will reduce the search by the most so we do
            // it first.
            t1 = t1.SimpleSelect(queryContext, paramCol, SqlExpressionType.Equal,
                                 SqlExpression.Constant(Field.String(objectName.FullName)));

            // The next is a single exhaustive select through the remaining records.
            // It finds all grants that match either public or the grantee is the
            // user or role, and that match the object type.

            // Expression: ("grantee_col" = grantee)
            var userCheck = SqlExpression.Equal(SqlExpression.Reference(granteeCol),
                                                SqlExpression.Constant(Field.String(grantee)));

            // Expression: ("object_col" = object AND
            //              "grantee_col" = grantee)
            // All that match the given grantee or public and given object
            var expr =
                SqlExpression.And(
                    SqlExpression.Equal(SqlExpression.Reference(objectCol),
                                        SqlExpression.Constant(Field.BigInt((int)objectType))), userCheck);

            // Are we only searching for grant options?
            var grantOptionCheck = SqlExpression.Equal(SqlExpression.Reference(grantOptionCol),
                                                       SqlExpression.Constant(Field.Boolean(withOption)));

            expr = SqlExpression.And(expr, grantOptionCheck);

            // Make sure the granter matches up also
            var granterCheck = SqlExpression.Equal(SqlExpression.Reference(granterCol),
                                                   SqlExpression.Constant(Field.String(revoker)));

            expr = SqlExpression.And(expr, granterCheck);

            t1 = t1.ExhaustiveSelect(queryContext, expr);

            // Remove these rows from the table
            grantTable.Delete(t1);
        }
Beispiel #2
0
        public void DeleteCurrent(IMutableTable table, IRequest request)
        {
            AssertNotDisposed();
            AssertNotClosed();

            var pkey = request.Query.Session.Transaction.QueryTablePrimaryKey(table.TableInfo.TableName);

            if (pkey == null)
            {
                throw new MissingPrimaryKeyException(table.TableInfo.TableName);
            }

            var colIndexes = new int[pkey.ColumnNames.Length];

            for (int i = 0; i < colIndexes.Length; i++)
            {
                var colIdx = table.TableInfo.IndexOfColumn(pkey.ColumnNames[i]);
                colIndexes[i] = colIdx;
            }

            var currentRow = State.CurrentRow;

            var values = new Field[colIndexes.Length];

            for (int i = 0; i < colIndexes.Length; i++)
            {
                values[i] = currentRow.GetValue(colIndexes[i]);
            }

            ITable deleteSet = table;

            for (int i = 0; i < colIndexes.Length; i++)
            {
                deleteSet = deleteSet.SelectEqual(colIndexes[i], values[i]);
            }

            if (deleteSet.RowCount == 0)
            {
                return;
            }

            table.Delete(deleteSet, 1);
        }
Beispiel #3
0
        private static void RevokeAllGrants(IQuery queryContext, IMutableTable grantTable, DbObjectType objectType,
			ObjectName objectName, string revoker, string grantee, bool withOption = false)
        {
            var objectCol = grantTable.GetResolvedColumnName(1);
            var paramCol = grantTable.GetResolvedColumnName(2);
            var granteeCol = grantTable.GetResolvedColumnName(3);
            var grantOptionCol = grantTable.GetResolvedColumnName(4);
            var granterCol = grantTable.GetResolvedColumnName(5);

            ITable t1 = grantTable;

            // All that match the given object parameter
            // It's most likely this will reduce the search by the most so we do
            // it first.
            t1 = t1.SimpleSelect(queryContext, paramCol, SqlExpressionType.Equal,
                SqlExpression.Constant(Field.String(objectName.FullName)));

            // The next is a single exhaustive select through the remaining records.
            // It finds all grants that match either public or the grantee is the
            // user or role, and that match the object type.

            // Expression: ("grantee_col" = grantee)
            var userCheck = SqlExpression.Equal(SqlExpression.Reference(granteeCol),
                SqlExpression.Constant(Field.String(grantee)));

            // Expression: ("object_col" = object AND
            //              "grantee_col" = grantee)
            // All that match the given grantee or public and given object
            var expr =
                SqlExpression.And(
                    SqlExpression.Equal(SqlExpression.Reference(objectCol),
                        SqlExpression.Constant(Field.BigInt((int) objectType))), userCheck);

            // Are we only searching for grant options?
            var grantOptionCheck = SqlExpression.Equal(SqlExpression.Reference(grantOptionCol),
                SqlExpression.Constant(Field.Boolean(withOption)));
            expr = SqlExpression.And(expr, grantOptionCheck);

            // Make sure the granter matches up also
            var granterCheck = SqlExpression.Equal(SqlExpression.Reference(granterCol),
                SqlExpression.Constant(Field.String(revoker)));
            expr = SqlExpression.And(expr, granterCheck);

            t1 = t1.ExhaustiveSelect(queryContext, expr);

            // Remove these rows from the table
            grantTable.Delete(t1);
        }