MCPcopy Create free account
hub / github.com/Tencent/phxsql / check_grant_all_columns

Function check_grant_all_columns

phx_percona/percona/sql/sql_acl.cc:6202–6284  ·  view source on GitHub ↗

@brief check if a query can access a set of columns @param thd the current thread @param want_access_arg the privileges requested @param fields an iterator over the fields of a table reference. @return Operation status @retval 0 Success @retval 1 Falure @details This function walks over the columns of a table reference The columns may originate from different tables, de

Source from the content-addressed store, hash-verified

6200 to check the required access privileges for the fields requested from it.
6201*/
6202bool check_grant_all_columns(THD *thd, ulong want_access_arg,
6203 Field_iterator_table_ref *fields)
6204{
6205 Security_context *sctx= thd->security_ctx;
6206 ulong want_access= want_access_arg;
6207 const char *table_name= NULL;
6208
6209 const char* db_name;
6210 GRANT_INFO *grant;
6211 /* Initialized only to make gcc happy */
6212 GRANT_TABLE *grant_table= NULL;
6213 /*
6214 Flag that gets set if privilege checking has to be performed on column
6215 level.
6216 */
6217 bool using_column_privileges= FALSE;
6218
6219 mysql_rwlock_rdlock(&LOCK_grant);
6220
6221 for (; !fields->end_of_fields(); fields->next())
6222 {
6223 const char *field_name= fields->name();
6224
6225 if (table_name != fields->get_table_name())
6226 {
6227 table_name= fields->get_table_name();
6228 db_name= fields->get_db_name();
6229 grant= fields->grant();
6230 /* get a fresh one for each table */
6231 want_access= want_access_arg & ~grant->privilege;
6232 if (want_access)
6233 {
6234 /* reload table if someone has modified any grants */
6235 if (grant->version != grant_version)
6236 {
6237 grant->grant_table=
6238 table_hash_search(sctx->get_host()->ptr(), sctx->get_ip()->ptr(),
6239 db_name, sctx->priv_user,
6240 table_name, 0); /* purecov: inspected */
6241 grant->version= grant_version; /* purecov: inspected */
6242 }
6243
6244 grant_table= grant->grant_table;
6245 DBUG_ASSERT (grant_table);
6246 }
6247 }
6248
6249 if (want_access)
6250 {
6251 GRANT_COLUMN *grant_column=
6252 column_hash_search(grant_table, field_name,
6253 (uint) strlen(field_name));
6254 if (grant_column)
6255 using_column_privileges= TRUE;
6256 if (!grant_column || (~grant_column->rights & want_access))
6257 goto err;
6258 }
6259 }

Callers

nothing calls this directly

Calls 4

table_hash_searchFunction · 0.85
column_hash_searchFunction · 0.85
get_privilege_descFunction · 0.85
get_hostMethod · 0.80

Tested by

no test coverage detected