MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ndb_dist_priv_util.h
1 /*
2  Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #ifndef NDB_DIST_PRIV_UTIL_H
19 #define NDB_DIST_PRIV_UTIL_H
20 
22  size_t m_iter_curr_table;
23 public:
25  {
26  iter_reset();
27  }
28 
29  const char* database() const { return "mysql"; }
30 
31  // Iterator for distributed priv tables name
32  const char* iter_next_table()
33  {
34  static const char* tables[] =
35  { "user", "db", "tables_priv", "columns_priv", "procs_priv", "host",
36  "proxies_priv" };
37 
38  if (m_iter_curr_table >= (sizeof(tables) / sizeof(tables[0])))
39  return NULL;
40  m_iter_curr_table++;
41  return tables[m_iter_curr_table-1];
42  }
43 
44  // Reset iterator to start at first table name
45  void iter_reset() { m_iter_curr_table = 0; }
46 
47  // Determine if a given table name is in the list
48  // of distributed priv tables
49  static
50  bool
51  is_distributed_priv_table(const char *db, const char *table)
52  {
53  Ndb_dist_priv_util dist_priv;
54  if (strcmp(db, dist_priv.database()))
55  {
56  return false; // Ignore tables not in dist_priv database
57  }
58  const char* priv_table_name;
59  while((priv_table_name= dist_priv.iter_next_table()))
60  {
61  if (strcmp(table, priv_table_name) == 0)
62  {
63  return true;
64  }
65  }
66  return false;
67  }
68 
69 };
70 
71 #endif