~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/authorization.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

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
 
  SchemaIdentifier::const_reference schema;
 
62
  identifier::Schema::const_reference schema;
63
63
 
64
64
public:
65
65
  RestrictDbFunctor(const identifier::User &user_ctx_arg,
66
 
                    SchemaIdentifier::const_reference schema_arg) :
 
66
                    identifier::Schema::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
 
  const identifier::User &user_ctx;
82
 
  TableIdentifier &table;
 
81
  identifier::User::const_reference user_ctx;
 
82
  identifier::Table::const_reference table;
83
83
public:
84
 
  RestrictTableFunctor(const identifier::User &user_ctx_arg,
85
 
                       TableIdentifier &table_arg) :
 
84
  RestrictTableFunctor(identifier::User::const_reference user_ctx_arg,
 
85
                       identifier::Table::const_reference 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<SchemaIdentifier&, bool>
 
117
  public std::unary_function<identifier::Schema&, bool>
118
118
{
119
 
  drizzled::identifier::User::const_shared_ptr user_ctx;
 
119
  drizzled::identifier::User::const_reference user_ctx;
120
120
public:
121
 
  PruneSchemaFunctor(drizzled::identifier::User::const_shared_ptr user_ctx_arg) :
122
 
    std::unary_function<SchemaIdentifier&, bool>(),
 
121
  PruneSchemaFunctor(drizzled::identifier::User::const_reference user_ctx_arg) :
 
122
    std::unary_function<identifier::Schema&, 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_shared_ptr user_ctx,
135
 
                                         SchemaIdentifier::const_reference schema_identifier,
 
134
bool plugin::Authorization::isAuthorized(identifier::User::const_reference user_ctx,
 
135
                                         identifier::Schema::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
 
      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());
 
158
      error::access(user_ctx, schema_identifier);
165
159
    }
166
160
    return false;
167
161
  }
168
162
  return true;
169
163
}
170
164
 
171
 
bool plugin::Authorization::isAuthorized(drizzled::identifier::User::const_shared_ptr user_ctx,
172
 
                                         TableIdentifier &table,
 
165
bool plugin::Authorization::isAuthorized(drizzled::identifier::User::const_reference user_ctx,
 
166
                                         identifier::Table::const_reference table_identifier,
173
167
                                         bool send_error)
174
168
{
175
169
  /* If we never loaded any authorization plugins, just return true */
180
174
  std::vector<plugin::Authorization *>::const_iterator iter=
181
175
    std::find_if(authorization_plugins.begin(),
182
176
            authorization_plugins.end(),
183
 
            RestrictTableFunctor(*user_ctx, table));
 
177
            RestrictTableFunctor(user_ctx, table_identifier));
184
178
 
185
179
  /*
186
180
   * If iter is == end() here, that means that all of the plugins returned
191
185
  {
192
186
    if (send_error)
193
187
    {
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());
 
188
      error::access(user_ctx, table_identifier);
201
189
    }
202
190
    return false;
203
191
  }
204
192
  return true;
205
193
}
206
194
 
207
 
bool plugin::Authorization::isAuthorized(drizzled::identifier::User::const_shared_ptr user_ctx,
208
 
                                         const Session *session,
 
195
bool plugin::Authorization::isAuthorized(drizzled::identifier::User::const_reference user_ctx,
 
196
                                         Session::const_reference session,
209
197
                                         bool send_error)
210
198
{
211
 
  drizzled::identifier::User::const_shared_ptr session_ctx= session->user();
212
 
 
213
199
  /* If we never loaded any authorization plugins, just return true */
214
200
  if (authorization_plugins.empty())
215
201
    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
 
216
207
 
217
208
  /* Use find_if instead of foreach so that we can collect return codes */
218
209
  std::vector<plugin::Authorization *>::const_iterator iter=
219
210
    std::find_if(authorization_plugins.begin(),
220
211
                 authorization_plugins.end(),
221
 
                 RestrictProcessFunctor(*user_ctx, *session_ctx));
 
212
                 RestrictProcessFunctor(user_ctx, *session_ctx));
222
213
 
223
214
  /*
224
215
   * If iter is == end() here, that means that all of the plugins returned
230
221
  {
231
222
    if (send_error)
232
223
    {
233
 
      my_error(ER_KILL_DENIED_ERROR, MYF(0), session->thread_id);
 
224
      my_error(ER_KILL_DENIED_ERROR, MYF(0), session.thread_id);
234
225
    }
235
226
    return false;
236
227
  }
 
228
 
237
229
  return true;
238
230
}
239
231
 
240
 
void plugin::Authorization::pruneSchemaNames(drizzled::identifier::User::const_shared_ptr user_ctx,
241
 
                                             SchemaIdentifier::vector &set_of_schemas)
 
232
void plugin::Authorization::pruneSchemaNames(drizzled::identifier::User::const_reference user_ctx,
 
233
                                             identifier::Schema::vector &set_of_schemas)
242
234
{
243
235
  /* If we never loaded any authorization plugins, just return true */
244
236
  if (authorization_plugins.empty())