diff options
author | Alexander Barkov <bar@mariadb.com> | 2020-02-05 12:43:17 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2020-02-08 21:35:35 +0400 |
commit | 77c6382312535991d26c85e7eb5492f9b3a59e92 (patch) | |
tree | efcbf3c238aa8b67165031b5c7d9266c0082e7b4 /sql/grant.h | |
parent | 06b0623adb71f2b7918f69ab68660ec45736ebb5 (diff) | |
download | mariadb-git-77c6382312535991d26c85e7eb5492f9b3a59e92.tar.gz |
MDEV-21689 Add Sql_cmd for GRANT/REVOKE statements
Rewriting GRANT/REVOKE grammar to use more bison stack and use Sql_cmd_ style
1. Removing a few members from LEX:
- uint grant, grant_to_col, which_columns
- List<LEX_COLUMN> columns
- bool all_privileges
2. Adding classes Grand_object_name, Lex_grant_object_name
3. Adding classes Grand_privilege, Lex_grand_privilege
4. Adding struct Lex_column_list_privilege_st, class Lex_column_list_privilege
5. Rewriting the GRANT/REVOKE grammar to use new classes and pass them through
bison stack (rather than directly access LEX members)
6. Adding classes Sql_cmd_grant* and Sql_cmd_revoke*,
changing GRANT/REVOKE to use LEX::m_sql_cmd.
7. Adding the "sp_handler" grammar rule and removing some duplicate grammar
for GRANT/REVOKE for different kinds of SP objects.
8. Adding a new rule comma_separated_ident_list, reusing it in:
- with_column_list
- colum_list_privilege
Diffstat (limited to 'sql/grant.h')
-rw-r--r-- | sql/grant.h | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/sql/grant.h b/sql/grant.h new file mode 100644 index 00000000000..18b39ea0719 --- /dev/null +++ b/sql/grant.h @@ -0,0 +1,96 @@ +/* + Copyright (c) 2020, MariaDB Corporation. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#ifndef SQL_GRANT_INCLUDED +#define SQL_GRANT_INCLUDED + +#include "lex_string.h" + +class LEX_COLUMN; +class Lex_ident_sys; +class Table_ident; + +/* + Represents the object name in this standard SQL grammar: + GRANT <object privileges> ON <object name> +*/ +class Grant_object_name +{ +public: + enum Type + { + STAR, // ON * + IDENT_STAR, // ON db.* + STAR_STAR, // ON *.* + TABLE_IDENT // ON db.name + }; + Lex_cstring m_db; + Table_ident *m_table_ident; + Type m_type; +public: + Grant_object_name(Table_ident *table_ident) + :m_table_ident(table_ident), + m_type(TABLE_IDENT) + { } + Grant_object_name(const LEX_CSTRING &db, Type type) + :m_db(db), + m_table_ident(NULL), + m_type(type) + { } + uint all_privileges_by_type() const; +}; + + + +/* + Represents standard SQL statements described by: + - <grant privilege statement> + - <revoke privilege statement> +*/ +class Grant_privilege +{ +protected: + List<LEX_COLUMN> m_columns; + Lex_cstring m_db; + uint m_object_privilege; + uint m_column_privilege_total; + bool m_all_privileges; +public: + Grant_privilege() + :m_object_privilege(0), m_column_privilege_total(0), m_all_privileges(false) + { } + Grant_privilege(uint privilege, bool all_privileges) + :m_object_privilege(privilege), + m_column_privilege_total(0), + m_all_privileges(all_privileges) + { } + void add_object_privilege(uint privilege) + { + m_object_privilege|= privilege; + } + bool add_column_privilege(THD *thd, const Lex_ident_sys &col, + uint privilege); + bool add_column_list_privilege(THD *thd, List<Lex_ident_sys> &list, + uint privilege); + bool set_object_name(THD *thd, + const Grant_object_name &ident, + SELECT_LEX *sel, + uint with_grant_option); + const List<LEX_COLUMN> & columns() const { return m_columns; } +}; + + +#endif // SQL_GRANT_INCLUDED |