~ubuntu-branches/ubuntu/trusty/mysql-5.6/trusty

« back to all changes in this revision

Viewing changes to sql/ndb_dist_priv_util.h

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-02-12 11:54:27 UTC
  • Revision ID: package-import@ubuntu.com-20140212115427-oq6tfsqxl1wuwehi
Tags: upstream-5.6.15
ImportĀ upstreamĀ versionĀ 5.6.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (c) 2011, 2012, 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
 
 
21
class Ndb_dist_priv_util {
 
22
  size_t m_iter_curr_table;
 
23
public:
 
24
  Ndb_dist_priv_util()
 
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