~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/authorization.cc

  • Committer: Brian Aker
  • Date: 2011-01-12 06:45:23 UTC
  • mto: (2073.1.4 catalogs)
  • mto: This revision was merged to the branch mainline in revision 2080.
  • Revision ID: brian@tangent.org-20110112064523-rqhptaqbph22qmj1
RemoveĀ customĀ error.

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/identifier.h"
 
27
#include "drizzled/error.h"
 
28
#include "drizzled/session.h"
 
29
#include "drizzled/gettext.h"
30
30
 
31
31
namespace drizzled
32
32
{
59
59
  public std::unary_function<plugin::Authorization *, bool>
60
60
{
61
61
  const identifier::User &user_ctx;
62
 
  identifier::Schema::const_reference schema;
 
62
  SchemaIdentifier::const_reference schema;
63
63
 
64
64
public:
65
65
  RestrictDbFunctor(const identifier::User &user_ctx_arg,
66
 
                    identifier::Schema::const_reference schema_arg) :
 
66
                    SchemaIdentifier::const_reference 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 identifier::User &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 identifier::User &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)
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
  drizzled::identifier::User::const_shared_ptr user_ctx;
120
120
public:
121
 
  PruneSchemaFunctor(drizzled::identifier::User::const_reference user_ctx_arg) :
122
 
    std::unary_function<identifier::Schema&, bool>(),
 
121
  PruneSchemaFunctor(drizzled::identifier::User::const_shared_ptr 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(identifier::User::const_shared_ptr user_ctx,
 
135
                                         SchemaIdentifier::const_reference schema_identifier,
136
136
                                         bool send_error)
137
137
{
138
138
  /* If we never loaded any authorization plugins, just return true */
143
143
  std::vector<plugin::Authorization *>::const_iterator iter=
144
144
    std::find_if(authorization_plugins.begin(),
145
145
                 authorization_plugins.end(),
146
 
                 RestrictDbFunctor(user_ctx, schema_identifier));
 
146
                 RestrictDbFunctor(*user_ctx, schema_identifier));
147
147
 
148
148
 
149
149
  /*
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->username().c_str(),
 
163
               user_ctx->address().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(drizzled::identifier::User::const_shared_ptr 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->username().c_str(),
 
199
               user_ctx->address().c_str(),
 
200
               path.c_str());
189
201
    }
190
202
    return false;
191
203
  }
192
204
  return true;
193
205
}
194
206
 
 
207
bool plugin::Authorization::isAuthorized(drizzled::identifier::User::const_shared_ptr user_ctx,
 
208
                                         const Session *session,
 
209
                                         bool send_error)
 
210
{
 
211
  return isAuthorized(*user_ctx, session, send_error);
 
212
}
 
213
 
195
214
bool plugin::Authorization::isAuthorized(drizzled::identifier::User::const_reference user_ctx,
196
 
                                         Session::const_reference session,
 
215
                                         const Session *session,
197
216
                                         bool send_error)
198
217
{
 
218
  drizzled::identifier::User::const_shared_ptr session_ctx= session->user();
 
219
 
199
220
  /* If we never loaded any authorization plugins, just return true */
200
221
  if (authorization_plugins.empty())
201
222
    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
223
 
208
224
  /* Use find_if instead of foreach so that we can collect return codes */
209
225
  std::vector<plugin::Authorization *>::const_iterator iter=
221
237
  {
222
238
    if (send_error)
223
239
    {
224
 
      my_error(ER_KILL_DENIED_ERROR, MYF(0), session.thread_id);
 
240
      my_error(ER_KILL_DENIED_ERROR, MYF(0), session->thread_id);
225
241
    }
226
242
    return false;
227
243
  }
229
245
  return true;
230
246
}
231
247
 
232
 
void plugin::Authorization::pruneSchemaNames(drizzled::identifier::User::const_reference user_ctx,
233
 
                                             identifier::Schema::vector &set_of_schemas)
 
248
void plugin::Authorization::pruneSchemaNames(drizzled::identifier::User::const_shared_ptr user_ctx,
 
249
                                             SchemaIdentifier::vector &set_of_schemas)
234
250
{
235
251
  /* If we never loaded any authorization plugins, just return true */
236
252
  if (authorization_plugins.empty())