~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/authorization.cc

  • Committer: Brian Aker
  • Date: 2010-12-16 20:06:09 UTC
  • Revision ID: brian@tangent.org-20101216200609-xigmi0vbldradofi
I've mentioned this to Paul. Once we have the bits in for session around
thread he will go in and fix what he needs to fix. 

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;
 
62
  const SecurityContext &user_ctx;
 
63
  SchemaIdentifier::const_reference schema;
63
64
 
64
65
public:
65
 
  RestrictDbFunctor(const identifier::User &user_ctx_arg,
66
 
                    identifier::Schema::const_reference schema_arg) :
 
66
  RestrictDbFunctor(const SecurityContext &user_ctx_arg,
 
67
                    SchemaIdentifier::const_reference schema_arg) :
67
68
    std::unary_function<plugin::Authorization *, bool>(),
68
69
    user_ctx(user_ctx_arg),
69
70
    schema(schema_arg)
78
79
class RestrictTableFunctor :
79
80
  public std::unary_function<plugin::Authorization *, bool>
80
81
{
81
 
  identifier::User::const_reference user_ctx;
82
 
  identifier::Table::const_reference table;
 
82
  const SecurityContext &user_ctx;
 
83
  TableIdentifier &table;
83
84
public:
84
 
  RestrictTableFunctor(identifier::User::const_reference user_ctx_arg,
85
 
                       identifier::Table::const_reference table_arg) :
 
85
  RestrictTableFunctor(const SecurityContext &user_ctx_arg,
 
86
                       TableIdentifier &table_arg) :
86
87
    std::unary_function<plugin::Authorization *, bool>(),
87
88
    user_ctx(user_ctx_arg),
88
89
    table(table_arg)
97
98
class RestrictProcessFunctor :
98
99
  public std::unary_function<plugin::Authorization *, bool>
99
100
{
100
 
  const identifier::User &user_ctx;
101
 
  const identifier::User &session_ctx;
 
101
  const SecurityContext &user_ctx;
 
102
  const SecurityContext &session_ctx;
102
103
public:
103
 
  RestrictProcessFunctor(const identifier::User &user_ctx_arg,
104
 
                         const identifier::User &session_ctx_arg) :
 
104
  RestrictProcessFunctor(const SecurityContext &user_ctx_arg,
 
105
                         const SecurityContext &session_ctx_arg) :
105
106
    std::unary_function<plugin::Authorization *, bool>(),
106
107
    user_ctx(user_ctx_arg),
107
108
    session_ctx(session_ctx_arg)
114
115
};
115
116
 
116
117
class PruneSchemaFunctor :
117
 
  public std::unary_function<identifier::Schema&, bool>
 
118
  public std::unary_function<SchemaIdentifier&, bool>
118
119
{
119
 
  drizzled::identifier::User::const_reference user_ctx;
 
120
  const SecurityContext &user_ctx;
120
121
public:
121
 
  PruneSchemaFunctor(drizzled::identifier::User::const_reference user_ctx_arg) :
122
 
    std::unary_function<identifier::Schema&, bool>(),
 
122
  PruneSchemaFunctor(const SecurityContext &user_ctx_arg) :
 
123
    std::unary_function<SchemaIdentifier&, bool>(),
123
124
    user_ctx(user_ctx_arg)
124
125
  { }
125
126
 
131
132
 
132
133
} /* namespace */
133
134
 
134
 
bool plugin::Authorization::isAuthorized(identifier::User::const_reference user_ctx,
135
 
                                         identifier::Schema::const_reference schema_identifier,
 
135
bool plugin::Authorization::isAuthorized(const SecurityContext &user_ctx,
 
136
                                         SchemaIdentifier::const_reference schema_identifier,
136
137
                                         bool send_error)
137
138
{
138
139
  /* If we never loaded any authorization plugins, just return true */
155
156
  {
156
157
    if (send_error)
157
158
    {
158
 
      error::access(user_ctx, schema_identifier);
 
159
      std::string path;
 
160
      schema_identifier.getSQLPath(path);
 
161
 
 
162
      my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
 
163
               user_ctx.getUser().c_str(),
 
164
               user_ctx.getIp().c_str(),
 
165
               path.c_str());
159
166
    }
160
167
    return false;
161
168
  }
162
169
  return true;
163
170
}
164
171
 
165
 
bool plugin::Authorization::isAuthorized(drizzled::identifier::User::const_reference user_ctx,
166
 
                                         identifier::Table::const_reference table_identifier,
 
172
bool plugin::Authorization::isAuthorized(const SecurityContext &user_ctx,
 
173
                                         TableIdentifier &table,
167
174
                                         bool send_error)
168
175
{
169
176
  /* If we never loaded any authorization plugins, just return true */
174
181
  std::vector<plugin::Authorization *>::const_iterator iter=
175
182
    std::find_if(authorization_plugins.begin(),
176
183
            authorization_plugins.end(),
177
 
            RestrictTableFunctor(user_ctx, table_identifier));
 
184
            RestrictTableFunctor(user_ctx, table));
178
185
 
179
186
  /*
180
187
   * If iter is == end() here, that means that all of the plugins returned
185
192
  {
186
193
    if (send_error)
187
194
    {
188
 
      error::access(user_ctx, table_identifier);
 
195
      std::string path;
 
196
      table.getSQLPath(path);
 
197
 
 
198
      my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
 
199
               user_ctx.getUser().c_str(),
 
200
               user_ctx.getIp().c_str(),
 
201
               path.c_str());
189
202
    }
190
203
    return false;
191
204
  }
192
205
  return true;
193
206
}
194
207
 
195
 
bool plugin::Authorization::isAuthorized(drizzled::identifier::User::const_reference user_ctx,
196
 
                                         Session::const_reference session,
 
208
bool plugin::Authorization::isAuthorized(const SecurityContext &user_ctx,
 
209
                                         const Session *session,
197
210
                                         bool send_error)
198
211
{
 
212
  const SecurityContext &session_ctx= session->getSecurityContext();
 
213
 
199
214
  /* If we never loaded any authorization plugins, just return true */
200
215
  if (authorization_plugins.empty())
201
216
    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
217
 
208
218
  /* Use find_if instead of foreach so that we can collect return codes */
209
219
  std::vector<plugin::Authorization *>::const_iterator iter=
210
220
    std::find_if(authorization_plugins.begin(),
211
221
                 authorization_plugins.end(),
212
 
                 RestrictProcessFunctor(user_ctx, *session_ctx));
 
222
                 RestrictProcessFunctor(user_ctx, session_ctx));
213
223
 
214
224
  /*
215
225
   * If iter is == end() here, that means that all of the plugins returned
221
231
  {
222
232
    if (send_error)
223
233
    {
224
 
      my_error(ER_KILL_DENIED_ERROR, MYF(0), session.thread_id);
 
234
      my_error(ER_KILL_DENIED_ERROR, MYF(0), session->thread_id);
225
235
    }
226
236
    return false;
227
237
  }
228
 
 
229
238
  return true;
230
239
}
231
240
 
232
 
void plugin::Authorization::pruneSchemaNames(drizzled::identifier::User::const_reference user_ctx,
233
 
                                             identifier::Schema::vector &set_of_schemas)
 
241
void plugin::Authorization::pruneSchemaNames(const SecurityContext &user_ctx,
 
242
                                             SchemaIdentifier::vector &set_of_schemas)
234
243
{
235
244
  /* If we never loaded any authorization plugins, just return true */
236
245
  if (authorization_plugins.empty())