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