MySQL  8.0.18
Source Code Documentation
sql_user_table.h
Go to the documentation of this file.
1 /* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 #ifndef SQL_USER_TABLE_INCLUDED
23 #define SQL_USER_TABLE_INCLUDED
24 
25 #include <stdarg.h>
26 #include <sys/types.h>
27 
28 #include "my_compiler.h"
29 #include "my_inttypes.h"
30 #include "my_loglevel.h"
31 #include "my_sys.h"
33 #include "mysqld_error.h"
34 #include "sql/derror.h" /* ER_DEFAULT */
35 #include "sql/log.h" /* error_log_printf */
36 #include "sql/table.h"
37 
38 class THD;
39 
40 /** Enum for ACL tables */
41 typedef enum ACL_TABLES {
52  LAST_ENTRY /* Must always be at the end */
53 } ACL_TABLES;
54 
55 /**
56  Class to validate the flawlessness of ACL table
57  before performing ACL operations.
58 */
60  public:
61  Acl_table_intact(THD *c_thd, enum loglevel log_level = ERROR_LEVEL)
62  : thd(c_thd), log_level_(log_level) {
63  has_keys = true;
64  }
65 
66  /**
67  Checks whether an ACL table is intact.
68 
69  Works in conjunction with @ref mysql_acl_table_defs and
70  Table_check_intact::check()
71 
72  @param table Table to check.
73  @param acl_table ACL Table "id"
74 
75  @retval false OK
76  @retval true There was an error.
77  */
78  bool check(TABLE *table, ACL_TABLES acl_table) {
79  return Table_check_intact::check(thd, table,
81  }
82 
83  protected:
84  void report_error(uint code, const char *fmt, ...)
85  MY_ATTRIBUTE((format(printf, 3, 4))) {
86  va_list args;
87  va_start(args, fmt);
88 
89  if (code == 0)
90  LogEvent()
92  .errcode(ER_SERVER_TABLE_CHECK_FAILED)
95  .messagev(fmt, args);
96  else if (code == ER_CANNOT_LOAD_FROM_TABLE_V2) {
97  char *db_name, *table_name;
98  db_name = va_arg(args, char *);
99  table_name = va_arg(args, char *);
100  my_error(code, MYF(0), db_name, table_name);
101  LogErr(log_level_, ER_SERVER_CANNOT_LOAD_FROM_TABLE_V2, db_name,
102  table_name);
103  } else {
104  my_printv_error(code, ER_THD_NONCONST(thd, code), MYF(0), args);
105  va_end(args);
106 
107  if (code == ER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE_V2)
108  code = ER_SERVER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE_V2;
109  else if (code == ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2)
110  code = ER_SERVER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2;
111  else
112  code = ER_SERVER_ACL_TABLE_ERROR;
113 
114  va_start(args, fmt);
115  LogEvent()
116  .prio(log_level_)
117  .errcode(code)
120  .messagev(fmt, args);
121  }
122 
123  va_end(args);
124  }
125 
126  private:
130 };
131 
132 int handle_grant_table(THD *thd, TABLE_LIST *tables, ACL_TABLES table_no,
133  bool drop, LEX_USER *user_from, LEX_USER *user_to);
134 
135 #endif /* SQL_USER_TABLE_INCLUDED */
THD * thd
Definition: sql_user_table.h:127
const char * db_name
Definition: rules_table_service.cc:54
Definition: my_loglevel.h:35
#define LOG_SUBSYSTEM_TAG
Definition: log_sink_test.cc:26
static const TABLE_FIELD_DEF mysql_acl_table_defs[]
keep in sync with ACL_TABLES
Definition: sql_user_table.h:128
void report_error(uint code, const char *fmt,...)
Definition: sql_user_table.h:84
Definition: sql_user_table.h:46
Some integer typedefs for easier portability.
void my_error(int nr, myf MyFlags,...)
Fill in and print a previously registered error message.
Definition: my_error.cc:215
Definition: sql_user_table.h:51
Definition: sql_user_table.h:43
Definition: sql_user_table.h:48
bool has_keys
Definition: table.h:572
Definition: table.h:1301
Definition: table.h:2367
Definition: sql_user_table.h:45
Definition: table.h:565
LogEvent & errcode(longlong val)
Append a numeric error code.
Definition: log_builtins.h:885
void my_printv_error(uint error, const char *format, myf MyFlags, va_list ap)
Print an error message.
Definition: my_error.cc:289
Definition: sql_user_table.h:52
Class to validate the flawlessness of ACL table before performing ACL operations. ...
Definition: sql_user_table.h:59
Header for compiler-dependent features.
ACL_TABLES
Enum for ACL tables.
Definition: sql_user_table.h:41
unsigned int uint
Definition: uca-dump.cc:29
#define MYF(v)
Definition: my_inttypes.h:114
enum loglevel log_level_
Definition: sql_user_table.h:129
Definition: sql_user_table.h:50
Definition: acl_table_base.h:31
Common header for many mysys elements.
Definition: sql_user_table.h:49
Definition of the global "loglevel" enumeration.
LogEvent & prio(longlong val)
Set error message priority.
Definition: log_builtins.h:1108
Definition: table.h:570
Definition: my_loglevel.h:34
Definition: sql_user_table.h:42
int handle_grant_table(THD *thd, TABLE_LIST *tables, ACL_TABLES table_no, bool drop, LEX_USER *user_from, LEX_USER *user_to)
Handle a privilege table.
Definition: sql_user_table.cc:1864
bool drop(THD *thd, const Table *tp)
Remove SDI for a table.
Definition: sdi.cc:584
#define LogErr(severity, ecode,...)
Definition: log_builtins.h:751
Acl_table_intact(THD *c_thd, enum loglevel log_level=ERROR_LEVEL)
Definition: sql_user_table.h:61
loglevel
Definition: my_loglevel.h:32
bool check(THD *thd, TABLE *table, const TABLE_FIELD_DEF *table_def)
Checks whether a table is intact.
Definition: table.cc:3706
Definition: sql_user_table.h:44
const char * ER_THD_NONCONST(const THD *thd, int mysql_errno)
Definition: derror.cc:111
LogEvent & source_file(const char *val)
Which source file was the problem detected in?
Definition: log_builtins.h:946
bool check(TABLE *table, ACL_TABLES acl_table)
Checks whether an ACL table is intact.
Definition: sql_user_table.h:78
Definition: table.h:2468
Error logging, slow query logging, general query logging: If it&#39;s server-internal, and it&#39;s logging, it&#39;s here.
#define MY_BASENAME
Definition: my_basename.h:39
LogEvent & subsys(const char *val)
Which subsystem in the source was the problem detected in? ("Repl"/"InnoDB"/"Server") ...
Definition: log_builtins.h:983
Modular logger: fluid API.
Definition: log_builtins.h:789
Definition: sql_user_table.h:47
LogEvent & messagev(const char *fmt, va_list ap)
Fill in a format string by substituting the % with the given arguments, then add the result as the ev...
Definition: log_builtins.h:1160
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:778
const char * table_name
Definition: rules_table_service.cc:55