1
/* Copyright (C) 2004 MySQL AB
1
/* Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
3
3
This program is free software; you can redistribute it and/or modify
4
4
it under the terms of the GNU General Public License as published by
1264
1265
if (!table->prelocking_placeholder &&
1265
1266
(old_lex->sql_command == SQLCOM_SELECT && old_lex->describe))
1267
if (check_table_access(thd, SELECT_ACL, view_tables, UINT_MAX, TRUE) &&
1268
check_table_access(thd, SHOW_VIEW_ACL, table, UINT_MAX, TRUE))
1269
The user we run EXPLAIN as (either the connected user who issued
1270
the EXPLAIN statement, or the definer of a SUID stored routine
1271
which contains the EXPLAIN) should have both SHOW_VIEW_ACL and
1272
SELECT_ACL on the view being opened as well as on all underlying
1273
views since EXPLAIN will disclose their structure. This user also
1274
should have SELECT_ACL on all underlying tables of the view since
1275
this EXPLAIN will disclose information about the number of rows in it.
1277
To perform this privilege check we create auxiliary TABLE_LIST object
1278
for the view in order a) to avoid trashing "table->grant" member for
1279
original table list element, which contents can be important at later
1280
stage for column-level privilege checking b) get TABLE_LIST object
1281
with "security_ctx" member set to 0, i.e. forcing check_table_access()
1282
to use active user's security context.
1284
There is no need for creating similar copies of TABLE_LIST elements
1285
for underlying tables since they just have been constructed and thus
1286
have TABLE_LIST::security_ctx == 0 and fresh TABLE_LIST::grant member.
1288
Finally at this point making sure we have SHOW_VIEW_ACL on the views
1289
will suffice as we implicitly require SELECT_ACL anyway.
1292
TABLE_LIST view_no_suid;
1293
bzero(static_cast<void *>(&view_no_suid), sizeof(TABLE_LIST));
1294
view_no_suid.db= table->db;
1295
view_no_suid.table_name= table->table_name;
1297
DBUG_ASSERT(view_tables == NULL || view_tables->security_ctx == NULL);
1299
if (check_table_access(thd, SELECT_ACL, view_tables, UINT_MAX, TRUE) ||
1300
check_table_access(thd, SHOW_VIEW_ACL, &view_no_suid, UINT_MAX, TRUE))
1270
1302
my_message(ER_VIEW_NO_EXPLAIN, ER(ER_VIEW_NO_EXPLAIN), MYF(0));
1396
1428
if (table->view_suid)
1399
Prepare a security context to check underlying objects of the view
1431
For suid views prepare a security context for checking underlying
1432
objects of the view.
1401
1434
if (!(table->view_sctx= (Security_context *)
1402
1435
thd->stmt_arena->alloc(sizeof(Security_context))))
1404
/* Assign the context to the tables referenced in the view */
1407
DBUG_ASSERT(view_tables_tail);
1408
for (tbl= view_tables; tbl != view_tables_tail->next_global;
1409
tbl= tbl->next_global)
1410
tbl->security_ctx= table->view_sctx;
1412
/* assign security context to SELECT name resolution contexts of view */
1413
for(SELECT_LEX *sl= lex->all_selects_list;
1415
sl= sl->next_select_in_list())
1416
sl->context.security_ctx= table->view_sctx;
1437
security_ctx= table->view_sctx;
1442
For non-suid views inherit security context from view's table list.
1443
This allows properly handle situation when non-suid view is used
1444
from within suid view.
1446
security_ctx= table->security_ctx;
1449
/* Assign the context to the tables referenced in the view */
1452
DBUG_ASSERT(view_tables_tail);
1453
for (tbl= view_tables; tbl != view_tables_tail->next_global;
1454
tbl= tbl->next_global)
1455
tbl->security_ctx= security_ctx;
1458
/* assign security context to SELECT name resolution contexts of view */
1459
for(SELECT_LEX *sl= lex->all_selects_list;
1461
sl= sl->next_select_in_list())
1462
sl->context.security_ctx= security_ctx;
1420
1465
Setup an error processor to hide error messages issued by stored