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, version 2.0,
6    as published by the Free Software Foundation.
7 
8    This program is also distributed with certain software (including
9    but not limited to OpenSSL) that is licensed under separate terms,
10    as designated in a particular file or component or in included license
11    documentation.  The authors of MySQL hereby grant you an additional
12    permission to link the program and your derivative works with the
13    separately licensed software that they have included with MySQL.
14 
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License, version 2.0, for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24 
25 #ifndef NDB_DIST_PRIV_UTIL_H
26 #define NDB_DIST_PRIV_UTIL_H
27 
28 class Ndb_dist_priv_util {
29   size_t m_iter_curr_table;
30 public:
Ndb_dist_priv_util()31   Ndb_dist_priv_util()
32   {
33     iter_reset();
34   }
35 
database()36   const char* database() const { return "mysql"; }
37 
38   // Iterator for distributed priv tables name
iter_next_table()39   const char* iter_next_table()
40   {
41     static const char* tables[] =
42       { "user", "db", "tables_priv", "columns_priv", "procs_priv", "host",
43         "proxies_priv" };
44 
45     if (m_iter_curr_table >= (sizeof(tables) / sizeof(tables[0])))
46       return NULL;
47     m_iter_curr_table++;
48     return tables[m_iter_curr_table-1];
49   }
50 
51   // Reset iterator to start at first table name
iter_reset()52   void iter_reset() { m_iter_curr_table = 0; }
53 
54   // Determine if a given table name is in the list
55   // of distributed priv tables
56   static
57   bool
is_distributed_priv_table(const char * db,const char * table)58   is_distributed_priv_table(const char *db, const char *table)
59   {
60     Ndb_dist_priv_util dist_priv;
61     if (strcmp(db, dist_priv.database()))
62     {
63       return false; // Ignore tables not in dist_priv database
64     }
65     const char* priv_table_name;
66     while((priv_table_name= dist_priv.iter_next_table()))
67     {
68       if (strcmp(table, priv_table_name) == 0)
69       {
70         return true;
71       }
72     }
73     return false;
74   }
75 
76 };
77 
78 #endif
79