~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/authorization.cc

  • Committer: Monty Taylor
  • Date: 2010-12-06 21:17:06 UTC
  • mto: (1977.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1980.
  • Revision ID: mordred@inaugust.com-20101206211706-iiuzzkxhh3fm10zf
Add ability to add a validation function to any sys_var. duh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include <config.h>
 
21
#include "config.h"
22
22
 
23
23
#include <vector>
24
24
 
25
 
#include <drizzled/plugin/authorization.h>
26
 
#include <drizzled/identifier.h>
27
 
#include <drizzled/error.h>
28
 
#include <drizzled/session.h>
29
 
#include <drizzled/gettext.h>
 
25
#include "drizzled/plugin/authorization.h"
 
26
#include "drizzled/security_context.h"
 
27
#include "drizzled/identifier.h"
 
28
#include "drizzled/error.h"
 
29
#include "drizzled/session.h"
 
30
#include "drizzled/gettext.h"
30
31
 
31
32
namespace drizzled
32
33
{
58
59
class RestrictDbFunctor :
59
60
  public std::unary_function<plugin::Authorization *, bool>
60
61
{
61
 
  const identifier::User &user_ctx;
62
 
  identifier::Schema::const_reference schema;
63
 
 
 
62
  const SecurityContext &user_ctx;
 
63
  SchemaIdentifier &schema;
64
64
public:
65
 
  RestrictDbFunctor(const identifier::User &user_ctx_arg,
66
 
                    identifier::Schema::const_reference schema_arg) :
 
65
  RestrictDbFunctor(const SecurityContext &user_ctx_arg,
 
66
                    SchemaIdentifier &schema_arg) :
67
67
    std::unary_function<plugin::Authorization *, bool>(),
68
68
    user_ctx(user_ctx_arg),
69
69
    schema(schema_arg)
78
78
class RestrictTableFunctor :
79
79
  public std::unary_function<plugin::Authorization *, bool>
80
80
{
81
 
  identifier::User::const_reference user_ctx;
82
 
  identifier::Table::const_reference table;
 
81
  const SecurityContext &user_ctx;
 
82
  TableIdentifier &table;
83
83
public:
84
 
  RestrictTableFunctor(identifier::User::const_reference user_ctx_arg,
85
 
                       identifier::Table::const_reference table_arg) :
 
84
  RestrictTableFunctor(const SecurityContext &user_ctx_arg,
 
85
                       TableIdentifier &table_arg) :
86
86
    std::unary_function<plugin::Authorization *, bool>(),
87
87
    user_ctx(user_ctx_arg),
88
88
    table(table_arg)
97
97
class RestrictProcessFunctor :
98
98
  public std::unary_function<plugin::Authorization *, bool>
99
99
{
100
 
  const identifier::User &user_ctx;
101
 
  const identifier::User &session_ctx;
 
100
  const SecurityContext &user_ctx;
 
101
  const SecurityContext &session_ctx;
102
102
public:
103
 
  RestrictProcessFunctor(const identifier::User &user_ctx_arg,
104
 
                         const identifier::User &session_ctx_arg) :
 
103
  RestrictProcessFunctor(const SecurityContext &user_ctx_arg,
 
104
                         const SecurityContext &session_ctx_arg) :
105
105
    std::unary_function<plugin::Authorization *, bool>(),
106
106
    user_ctx(user_ctx_arg),
107
107
    session_ctx(session_ctx_arg)
114
114
};
115
115
 
116
116
class PruneSchemaFunctor :
117
 
  public std::unary_function<identifier::Schema&, bool>
 
117
  public std::unary_function<SchemaIdentifier&, bool>
118
118
{
119
 
  drizzled::identifier::User::const_reference user_ctx;
 
119
  const SecurityContext &user_ctx;
120
120
public:
121
 
  PruneSchemaFunctor(drizzled::identifier::User::const_reference user_ctx_arg) :
122
 
    std::unary_function<identifier::Schema&, bool>(),
 
121
  PruneSchemaFunctor(const SecurityContext &user_ctx_arg) :
 
122
    std::unary_function<SchemaIdentifier&, bool>(),
123
123
    user_ctx(user_ctx_arg)
124
124
  { }
125
125
 
131
131
 
132
132
} /* namespace */
133
133
 
134
 
bool plugin::Authorization::isAuthorized(identifier::User::const_reference user_ctx,
135
 
                                         identifier::Schema::const_reference schema_identifier,
 
134
bool plugin::Authorization::isAuthorized(const SecurityContext &user_ctx,
 
135
                                         SchemaIdentifier &schema_identifier,
136
136
                                         bool send_error)
137
137
{
138
138
  /* If we never loaded any authorization plugins, just return true */
155
155
  {
156
156
    if (send_error)
157
157
    {
158
 
      error::access(user_ctx, schema_identifier);
 
158
      std::string path;
 
159
      schema_identifier.getSQLPath(path);
 
160
 
 
161
      my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
 
162
               user_ctx.getUser().c_str(),
 
163
               user_ctx.getIp().c_str(),
 
164
               path.c_str());
159
165
    }
160
166
    return false;
161
167
  }
162
168
  return true;
163
169
}
164
170
 
165
 
bool plugin::Authorization::isAuthorized(drizzled::identifier::User::const_reference user_ctx,
166
 
                                         identifier::Table::const_reference table_identifier,
 
171
bool plugin::Authorization::isAuthorized(const SecurityContext &user_ctx,
 
172
                                         TableIdentifier &table,
167
173
                                         bool send_error)
168
174
{
169
175
  /* If we never loaded any authorization plugins, just return true */
174
180
  std::vector<plugin::Authorization *>::const_iterator iter=
175
181
    std::find_if(authorization_plugins.begin(),
176
182
            authorization_plugins.end(),
177
 
            RestrictTableFunctor(user_ctx, table_identifier));
 
183
            RestrictTableFunctor(user_ctx, table));
178
184
 
179
185
  /*
180
186
   * If iter is == end() here, that means that all of the plugins returned
185
191
  {
186
192
    if (send_error)
187
193
    {
188
 
      error::access(user_ctx, table_identifier);
 
194
      std::string path;
 
195
      table.getSQLPath(path);
 
196
 
 
197
      my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
 
198
               user_ctx.getUser().c_str(),
 
199
               user_ctx.getIp().c_str(),
 
200
               path.c_str());
189
201
    }
190
202
    return false;
191
203
  }
192
204
  return true;
193
205
}
194
206
 
195
 
bool plugin::Authorization::isAuthorized(drizzled::identifier::User::const_reference user_ctx,
196
 
                                         Session::const_reference session,
 
207
bool plugin::Authorization::isAuthorized(const SecurityContext &user_ctx,
 
208
                                         const Session *session,
197
209
                                         bool send_error)
198
210
{
 
211
  const SecurityContext &session_ctx= session->getSecurityContext();
 
212
 
199
213
  /* If we never loaded any authorization plugins, just return true */
200
214
  if (authorization_plugins.empty())
201
215
    return true;
202
 
  
203
 
  // To make sure we hold the user structure we need to have a shred_ptr so
204
 
  // that we increase the count on the object.
205
 
  drizzled::identifier::User::const_shared_ptr session_ctx= session.user();
206
 
 
207
216
 
208
217
  /* Use find_if instead of foreach so that we can collect return codes */
209
218
  std::vector<plugin::Authorization *>::const_iterator iter=
210
219
    std::find_if(authorization_plugins.begin(),
211
220
                 authorization_plugins.end(),
212
 
                 RestrictProcessFunctor(user_ctx, *session_ctx));
 
221
                 RestrictProcessFunctor(user_ctx, session_ctx));
213
222
 
214
223
  /*
215
224
   * If iter is == end() here, that means that all of the plugins returned
221
230
  {
222
231
    if (send_error)
223
232
    {
224
 
      my_error(ER_KILL_DENIED_ERROR, MYF(0), session.thread_id);
 
233
      my_error(ER_KILL_DENIED_ERROR, MYF(0), session->thread_id);
225
234
    }
226
235
    return false;
227
236
  }
228
 
 
229
237
  return true;
230
238
}
231
239
 
232
 
void plugin::Authorization::pruneSchemaNames(drizzled::identifier::User::const_reference user_ctx,
233
 
                                             identifier::Schema::vector &set_of_schemas)
 
240
void plugin::Authorization::pruneSchemaNames(const SecurityContext &user_ctx,
 
241
                                             SchemaIdentifier::vector &set_of_schemas)
234
242
{
235
243
  /* If we never loaded any authorization plugins, just return true */
236
244
  if (authorization_plugins.empty())