My Project
ndb_dist_priv_util.h
00001 /*
00002    Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
00003 
00004    This program is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; version 2 of the License.
00007 
00008    This program is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011    GNU General Public License for more details.
00012 
00013    You should have received a copy of the GNU General Public License
00014    along with this program; if not, write to the Free Software
00015    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
00016 */
00017 
00018 #ifndef NDB_DIST_PRIV_UTIL_H
00019 #define NDB_DIST_PRIV_UTIL_H
00020 
00021 class Ndb_dist_priv_util {
00022   size_t m_iter_curr_table;
00023 public:
00024   Ndb_dist_priv_util()
00025   {
00026     iter_reset();
00027   }
00028 
00029   const char* database() const { return "mysql"; }
00030 
00031   // Iterator for distributed priv tables name
00032   const char* iter_next_table()
00033   {
00034     static const char* tables[] =
00035       { "user", "db", "tables_priv", "columns_priv", "procs_priv", "host",
00036         "proxies_priv" };
00037 
00038     if (m_iter_curr_table >= (sizeof(tables) / sizeof(tables[0])))
00039       return NULL;
00040     m_iter_curr_table++;
00041     return tables[m_iter_curr_table-1];
00042   }
00043 
00044   // Reset iterator to start at first table name
00045   void iter_reset() { m_iter_curr_table = 0; }
00046 
00047   // Determine if a given table name is in the list
00048   // of distributed priv tables
00049   static
00050   bool
00051   is_distributed_priv_table(const char *db, const char *table)
00052   {
00053     Ndb_dist_priv_util dist_priv;
00054     if (strcmp(db, dist_priv.database()))
00055     {
00056       return false; // Ignore tables not in dist_priv database
00057     }
00058     const char* priv_table_name;
00059     while((priv_table_name= dist_priv.iter_next_table()))
00060     {
00061       if (strcmp(table, priv_table_name) == 0)
00062       {
00063         return true;
00064       }
00065     }
00066     return false;
00067   }
00068 
00069 };
00070 
00071 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines