~patrick-crews/drizzle/qp-initial-cleanup

« back to all changes in this revision

Viewing changes to plugin/regex_policy/policy.h

added:
  plugin/regex_policy/tests/r/cache_overflow.result
  plugin/regex_policy/tests/t/cache_overflow-master.opt
  plugin/regex_policy/tests/t/cache_overflow.test
modified:
  plugin/regex_policy/module.cc
  plugin/regex_policy/policy.h
pending merge tips: (use -v to see all merge revisions)
  Clint Byrum 2012-03-16 fixing build failure caused by merge w/ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <boost/regex.hpp>
30
30
#include <boost/unordered_map.hpp>
31
31
#include <boost/thread/mutex.hpp>
 
32
#include <boost/thread/shared_mutex.hpp>
 
33
#include <boost/thread/locks.hpp>
32
34
 
33
35
#include <drizzled/configmake.h>
34
36
#include <drizzled/plugin/authorization.h>
39
41
 
40
42
static const fs::path DEFAULT_POLICY_FILE= SYSCONFDIR "/drizzle.policy";
41
43
 
 
44
static const uint64_t DEFAULT_MAX_LRU_LENGTH= 16384;
 
45
static const uint64_t DEFAULT_MAX_CACHE_BUCKETS= 4096;
 
46
 
42
47
static const char *comment_regex = "^[[:space:]]*#.*$";
43
48
static const char *empty_regex = "^[[:space:]]*$";
44
49
static const char *table_match_regex = "^([^ ]+) table\\=([^ ]+) (ACCEPT|DENY)$";
49
54
static const int MATCH_REGEX_OBJECT_POS= 2;
50
55
static const int MATCH_REGEX_ACTION_POS= 3;
51
56
 
 
57
 
52
58
typedef enum 
53
59
{
54
60
  POLICY_ACCEPT,
100
106
};
101
107
 
102
108
typedef std::list<PolicyItem *> PolicyItemList;
103
 
typedef boost::unordered_map<std::string, bool> CheckMap;
 
109
typedef std::vector<std::string> LruList;
 
110
typedef boost::unordered_map<std::string, bool> UnorderedCheckMap;
104
111
 
105
 
static boost::mutex check_cache_mutex;
 
112
class CheckMap
 
113
{
 
114
  LruList lru;
 
115
  boost::mutex lru_mutex;
 
116
  boost::shared_mutex map_mutex;
 
117
  UnorderedCheckMap map;
 
118
public:
 
119
  UnorderedCheckMap::iterator find(std::string const&k);
 
120
  UnorderedCheckMap::const_iterator end() const
 
121
  {
 
122
    return map.end();
 
123
  }
 
124
  void insert(std::string const &k, bool v);
 
125
};
106
126
 
107
127
class CheckItem
108
128
{
111
131
  std::string key;
112
132
  bool has_cached_result;
113
133
  bool cached_result;
114
 
  CheckMap **check_cache;
 
134
  CheckMap &check_cache;
115
135
public:
116
 
  CheckItem(const std::string &u, const std::string &obj, CheckMap **check_cache);
 
136
  CheckItem(const std::string &u, const std::string &obj, CheckMap &check_cache);
117
137
  bool operator()(PolicyItem *p);
118
138
  bool hasCachedResult() const
119
139
  {
149
169
public:
150
170
  Policy(const fs::path &f_path) :
151
171
    drizzled::plugin::Authorization("regex_policy"), policy_file(f_path), error(),
152
 
    table_check_cache(NULL), schema_check_cache(NULL), process_check_cache(NULL)
 
172
    table_check_cache(), schema_check_cache(), process_check_cache()
153
173
  { }
154
174
 
155
175
  virtual bool restrictSchema(const drizzled::identifier::User &user_ctx,
167
187
private:
168
188
  bool restrictObject(const drizzled::identifier::User &user_ctx,
169
189
                                   const std::string &obj, const PolicyItemList &policies,
170
 
                                   CheckMap **check_cache);
 
190
                                   CheckMap &check_cache);
171
191
  fs::path policy_file;
 
192
 
172
193
  std::stringstream error;
173
194
  PolicyItemList table_policies;
174
195
  PolicyItemList schema_policies;
175
196
  PolicyItemList process_policies;
176
 
  CheckMap *table_check_cache;
177
 
  CheckMap *schema_check_cache;
178
 
  CheckMap *process_check_cache;
 
197
  CheckMap table_check_cache;
 
198
  CheckMap schema_check_cache;
 
199
  CheckMap process_check_cache;
179
200
};
180
201
 
181
202
} /* namespace regex_policy */