~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/authorization.cc

updating to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
class RestrictTableFunctor :
79
79
  public std::unary_function<plugin::Authorization *, bool>
80
80
{
81
 
  const identifier::User &user_ctx;
82
 
  identifier::Table &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
 
                       identifier::Table &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)
116
116
class PruneSchemaFunctor :
117
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) :
 
121
  PruneSchemaFunctor(drizzled::identifier::User::const_reference user_ctx_arg) :
122
122
    std::unary_function<identifier::Schema&, bool>(),
123
123
    user_ctx(user_ctx_arg)
124
124
  { }
131
131
 
132
132
} /* namespace */
133
133
 
134
 
bool plugin::Authorization::isAuthorized(identifier::User::const_shared_ptr user_ctx,
 
134
bool plugin::Authorization::isAuthorized(identifier::User::const_reference user_ctx,
135
135
                                         identifier::Schema::const_reference schema_identifier,
136
136
                                         bool send_error)
137
137
{
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
 
                                         identifier::Table &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,
209
 
                                         bool send_error)
210
 
{
211
 
  return isAuthorized(*user_ctx, session, send_error);
212
 
}
213
 
 
214
195
bool plugin::Authorization::isAuthorized(drizzled::identifier::User::const_reference user_ctx,
215
 
                                         const Session *session,
 
196
                                         Session::const_reference session,
216
197
                                         bool send_error)
217
198
{
218
 
  drizzled::identifier::User::const_shared_ptr session_ctx= session->user();
219
 
 
220
199
  /* If we never loaded any authorization plugins, just return true */
221
200
  if (authorization_plugins.empty())
222
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
 
223
207
 
224
208
  /* Use find_if instead of foreach so that we can collect return codes */
225
209
  std::vector<plugin::Authorization *>::const_iterator iter=
237
221
  {
238
222
    if (send_error)
239
223
    {
240
 
      my_error(ER_KILL_DENIED_ERROR, MYF(0), session->thread_id);
 
224
      my_error(ER_KILL_DENIED_ERROR, MYF(0), session.thread_id);
241
225
    }
242
226
    return false;
243
227
  }
245
229
  return true;
246
230
}
247
231
 
248
 
void plugin::Authorization::pruneSchemaNames(drizzled::identifier::User::const_shared_ptr user_ctx,
 
232
void plugin::Authorization::pruneSchemaNames(drizzled::identifier::User::const_reference user_ctx,
249
233
                                             identifier::Schema::vector &set_of_schemas)
250
234
{
251
235
  /* If we never loaded any authorization plugins, just return true */