MCPcopy Create free account
hub / github.com/MariaDB/server / create_view_precheck

Function create_view_precheck

sql/sql_view.cc:255–373  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

253*/
254
255bool create_view_precheck(THD *thd, TABLE_LIST *tables, TABLE_LIST *view,
256 enum_view_create_mode mode)
257{
258 LEX *lex= thd->lex;
259 /* first table in list is target VIEW name => cut off it */
260 TABLE_LIST *tbl;
261 SELECT_LEX *select_lex= lex->first_select_lex();
262 SELECT_LEX *sl;
263 bool res= TRUE;
264 DBUG_ENTER("create_view_precheck");
265
266 /*
267 Privilege check for view creation:
268 - user has CREATE VIEW privilege on view table
269 - user has DROP privilege in case of ALTER VIEW or CREATE OR REPLACE
270 VIEW
271 - user has some (SELECT/UPDATE/INSERT/DELETE) privileges on columns of
272 underlying tables used on top of SELECT list (because it can be
273 (theoretically) updated, so it is enough to have UPDATE privilege on
274 them, for example)
275 - user has SELECT privilege on columns used in expressions of VIEW select
276 - for columns of underly tables used on top of SELECT list also will be
277 checked that we have not more privileges on correspondent column of view
278 table (i.e. user will not get some privileges by view creation)
279 */
280 if ((check_access(thd, CREATE_VIEW_ACL, view->db.str,
281 &view->grant.privilege,
282 &view->grant.m_internal,
283 0, 0) ||
284 check_grant(thd, CREATE_VIEW_ACL, view, FALSE, 1, FALSE)) ||
285 (mode != VIEW_CREATE_NEW &&
286 (check_access(thd, DROP_ACL, view->db.str,
287 &view->grant.privilege,
288 &view->grant.m_internal,
289 0, 0) ||
290 check_grant(thd, DROP_ACL, view, FALSE, 1, FALSE))))
291 goto err;
292
293 for (sl= select_lex; sl; sl= sl->next_select())
294 {
295 for (tbl= sl->get_table_list(); tbl; tbl= tbl->next_local)
296 {
297 if (!tbl->with && tbl->select_lex)
298 tbl->with= tbl->select_lex->find_table_def_in_with_clauses(tbl,
299 NULL);
300 /*
301 Ensure that we have some privileges on this table, more strict check
302 will be done on column level after preparation,
303 */
304 if (check_some_access(thd, VIEW_ANY_ACL, tbl))
305 {
306 my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0),
307 "ANY", thd->security_ctx->priv_user,
308 thd->security_ctx->priv_host,
309 tbl->db.str, tbl->table_name.str);
310 goto err;
311 }
312 /*

Callers 2

mysql_test_create_viewFunction · 0.85
mysql_create_viewFunction · 0.85

Calls 13

check_grantFunction · 0.85
my_errorFunction · 0.85
first_select_lexMethod · 0.80
next_selectMethod · 0.80
get_table_listMethod · 0.80
check_accessFunction · 0.70
check_some_accessFunction · 0.70
field_for_view_updateMethod · 0.45

Tested by

no test coverage detected