~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/authorization.cc

  • Committer: Stewart Smith
  • Author(s): Marko Mäkelä, Stewart Smith
  • Date: 2010-11-17 05:52:09 UTC
  • mto: (2021.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1971.
  • Revision ID: stewart@flamingspork.com-20101117055209-69m035q6h7e1txrc
Merge Revision revid:marko.makela@oracle.com-20100629113248-fvl48lnzr44z94gg from MySQL InnoDB

Original revid:marko.makela@oracle.com-20100629113248-fvl48lnzr44z94gg

Original Authors: Marko Mkel <marko.makela@oracle.com>
Original commit message:
Bug#52199 utf32: mbminlen=4, mbmaxlen=4, type->mbminlen=0, type->mbmaxlen=4

Merge and adjust a forgotten change to fix this bug.
rb://393 approved by Jimmy Yang
  ------------------------------------------------------------------------
  r3794 | marko | 2009-01-07 14:14:53 +0000 (Wed, 07 Jan 2009) | 18 lines

  branches/6.0: Allow the minimum length of a multi-byte character to be
  up to 4 bytes. (Bug #35391)

  dtype_t, dict_col_t: Replace mbminlen:2, mbmaxlen:3 with mbminmaxlen:5.
  In this way, the 5 bits can hold two values of 0..4, and the storage size
  of the fields will not cross the 64-bit boundary.  Encode the values as
  DATA_MBMAX * mbmaxlen + mbminlen.  Define the auxiliary macros
  DB_MBMINLEN(mbminmaxlen), DB_MBMAXLEN(mbminmaxlen), and
  DB_MINMAXLEN(mbminlen, mbmaxlen).

  Try to trim and pad UTF-16 and UTF-32 with spaces as appropriate.

  Alexander Barkov suggested the use of cs->cset->fill(cs, buff, len, 0x20).
  ha_innobase::store_key_val_for_row() now does that, but the added function
  row_mysql_pad_col() does not, because it doesn't have the MySQL TABLE object.

  rb://49 approved by Heikki Tuuri
  ------------------------------------------------------------------------

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <vector>
24
24
 
25
25
#include "drizzled/plugin/authorization.h"
 
26
#include "drizzled/security_context.h"
26
27
#include "drizzled/identifier.h"
27
28
#include "drizzled/error.h"
28
29
#include "drizzled/session.h"
29
30
#include "drizzled/gettext.h"
30
31
 
 
32
using namespace std;
 
33
 
31
34
namespace drizzled
32
35
{
33
36
 
34
 
std::vector<plugin::Authorization *> authorization_plugins;
 
37
vector<plugin::Authorization *> authorization_plugins;
35
38
 
36
39
 
37
40
bool plugin::Authorization::addPlugin(plugin::Authorization *auth)
38
41
{
39
42
  if (auth != NULL)
40
43
    authorization_plugins.push_back(auth);
41
 
 
42
44
  return false;
43
45
}
44
46
 
46
48
{
47
49
  if (auth != NULL)
48
50
  {
49
 
    authorization_plugins.erase(std::find(authorization_plugins.begin(),
50
 
                                          authorization_plugins.end(),
51
 
                                          auth));
 
51
    authorization_plugins.erase(find(authorization_plugins.begin(),
 
52
                                     authorization_plugins.end(),
 
53
                                     auth));
52
54
  }
53
55
}
54
56
 
56
58
{
57
59
 
58
60
class RestrictDbFunctor :
59
 
  public std::unary_function<plugin::Authorization *, bool>
 
61
  public unary_function<plugin::Authorization *, bool>
60
62
{
61
 
  const identifier::User &user_ctx;
62
 
  identifier::Schema::const_reference schema;
63
 
 
 
63
  const SecurityContext &user_ctx;
 
64
  SchemaIdentifier &schema;
64
65
public:
65
 
  RestrictDbFunctor(const identifier::User &user_ctx_arg,
66
 
                    identifier::Schema::const_reference schema_arg) :
67
 
    std::unary_function<plugin::Authorization *, bool>(),
 
66
  RestrictDbFunctor(const SecurityContext &user_ctx_arg,
 
67
                    SchemaIdentifier &schema_arg) :
 
68
    unary_function<plugin::Authorization *, bool>(),
68
69
    user_ctx(user_ctx_arg),
69
70
    schema(schema_arg)
70
71
  { }
76
77
};
77
78
 
78
79
class RestrictTableFunctor :
79
 
  public std::unary_function<plugin::Authorization *, bool>
 
80
  public unary_function<plugin::Authorization *, bool>
80
81
{
81
 
  const identifier::User &user_ctx;
82
 
  identifier::Table &table;
 
82
  const SecurityContext &user_ctx;
 
83
  TableIdentifier &table;
83
84
public:
84
 
  RestrictTableFunctor(const identifier::User &user_ctx_arg,
85
 
                       identifier::Table &table_arg) :
86
 
    std::unary_function<plugin::Authorization *, bool>(),
 
85
  RestrictTableFunctor(const SecurityContext &user_ctx_arg,
 
86
                       TableIdentifier &table_arg) :
 
87
    unary_function<plugin::Authorization *, bool>(),
87
88
    user_ctx(user_ctx_arg),
88
89
    table(table_arg)
89
90
  { }
95
96
};
96
97
 
97
98
class RestrictProcessFunctor :
98
 
  public std::unary_function<plugin::Authorization *, bool>
 
99
  public 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) :
105
 
    std::unary_function<plugin::Authorization *, bool>(),
 
104
  RestrictProcessFunctor(const SecurityContext &user_ctx_arg,
 
105
                         const SecurityContext &session_ctx_arg) :
 
106
    unary_function<plugin::Authorization *, bool>(),
106
107
    user_ctx(user_ctx_arg),
107
108
    session_ctx(session_ctx_arg)
108
109
  { }
114
115
};
115
116
 
116
117
class PruneSchemaFunctor :
117
 
  public std::unary_function<identifier::Schema&, bool>
 
118
  public unary_function<SchemaIdentifier&, bool>
118
119
{
119
 
  drizzled::identifier::User::const_shared_ptr user_ctx;
 
120
  const SecurityContext &user_ctx;
120
121
public:
121
 
  PruneSchemaFunctor(drizzled::identifier::User::const_shared_ptr user_ctx_arg) :
122
 
    std::unary_function<identifier::Schema&, bool>(),
 
122
  PruneSchemaFunctor(const SecurityContext &user_ctx_arg) :
 
123
    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_shared_ptr user_ctx,
135
 
                                         identifier::Schema::const_reference schema_identifier,
136
 
                                         bool send_error)
137
 
{
138
 
  /* If we never loaded any authorization plugins, just return true */
139
 
  if (authorization_plugins.empty())
140
 
    return true;
141
 
 
142
 
  /* Use find_if instead of foreach so that we can collect return codes */
143
 
  std::vector<plugin::Authorization *>::const_iterator iter=
144
 
    std::find_if(authorization_plugins.begin(),
145
 
                 authorization_plugins.end(),
146
 
                 RestrictDbFunctor(*user_ctx, schema_identifier));
147
 
 
148
 
 
149
 
  /*
150
 
   * If iter is == end() here, that means that all of the plugins returned
151
 
   * false, which means that that each of them believe the user is authorized
152
 
   * to view the resource in question.
153
 
   */
154
 
  if (iter != authorization_plugins.end())
155
 
  {
156
 
    if (send_error)
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());
165
 
    }
166
 
    return false;
167
 
  }
168
 
  return true;
169
 
}
170
 
 
171
 
bool plugin::Authorization::isAuthorized(drizzled::identifier::User::const_shared_ptr user_ctx,
172
 
                                         identifier::Table &table,
173
 
                                         bool send_error)
174
 
{
175
 
  /* If we never loaded any authorization plugins, just return true */
176
 
  if (authorization_plugins.empty())
177
 
    return true;
178
 
 
179
 
  /* Use find_if instead of foreach so that we can collect return codes */
180
 
  std::vector<plugin::Authorization *>::const_iterator iter=
181
 
    std::find_if(authorization_plugins.begin(),
182
 
            authorization_plugins.end(),
183
 
            RestrictTableFunctor(*user_ctx, table));
184
 
 
185
 
  /*
186
 
   * If iter is == end() here, that means that all of the plugins returned
187
 
   * false, which means that that each of them believe the user is authorized
188
 
   * to view the resource in question.
189
 
   */
190
 
  if (iter != authorization_plugins.end())
191
 
  {
192
 
    if (send_error)
193
 
    {
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());
201
 
    }
202
 
    return false;
203
 
  }
204
 
  return true;
205
 
}
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
 
 
214
 
bool plugin::Authorization::isAuthorized(drizzled::identifier::User::const_reference user_ctx,
215
 
                                         const Session *session,
216
 
                                         bool send_error)
217
 
{
218
 
  drizzled::identifier::User::const_shared_ptr session_ctx= session->user();
219
 
 
220
 
  /* If we never loaded any authorization plugins, just return true */
221
 
  if (authorization_plugins.empty())
222
 
    return true;
223
 
 
224
 
  /* Use find_if instead of foreach so that we can collect return codes */
225
 
  std::vector<plugin::Authorization *>::const_iterator iter=
226
 
    std::find_if(authorization_plugins.begin(),
227
 
                 authorization_plugins.end(),
228
 
                 RestrictProcessFunctor(user_ctx, *session_ctx));
 
135
bool plugin::Authorization::isAuthorized(const SecurityContext &user_ctx,
 
136
                                         SchemaIdentifier &schema_identifier,
 
137
                                         bool send_error)
 
138
{
 
139
  /* If we never loaded any authorization plugins, just return true */
 
140
  if (authorization_plugins.empty())
 
141
    return true;
 
142
 
 
143
  /* Use find_if instead of foreach so that we can collect return codes */
 
144
  vector<plugin::Authorization *>::const_iterator iter=
 
145
    find_if(authorization_plugins.begin(),
 
146
            authorization_plugins.end(),
 
147
            RestrictDbFunctor(user_ctx, schema_identifier));
 
148
 
 
149
 
 
150
  /*
 
151
   * If iter is == end() here, that means that all of the plugins returned
 
152
   * false, which means that that each of them believe the user is authorized
 
153
   * to view the resource in question.
 
154
   */
 
155
  if (iter != authorization_plugins.end())
 
156
  {
 
157
    if (send_error)
 
158
    {
 
159
      my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
 
160
               user_ctx.getUser().c_str(),
 
161
               user_ctx.getIp().c_str(),
 
162
               schema_identifier.getSQLPath().c_str());
 
163
    }
 
164
    return false;
 
165
  }
 
166
  return true;
 
167
}
 
168
 
 
169
bool plugin::Authorization::isAuthorized(const SecurityContext &user_ctx,
 
170
                                         TableIdentifier &table,
 
171
                                         bool send_error)
 
172
{
 
173
  /* If we never loaded any authorization plugins, just return true */
 
174
  if (authorization_plugins.empty())
 
175
    return true;
 
176
 
 
177
  /* Use find_if instead of foreach so that we can collect return codes */
 
178
  vector<plugin::Authorization *>::const_iterator iter=
 
179
    find_if(authorization_plugins.begin(),
 
180
            authorization_plugins.end(),
 
181
            RestrictTableFunctor(user_ctx, table));
 
182
 
 
183
  /*
 
184
   * If iter is == end() here, that means that all of the plugins returned
 
185
   * false, which means that that each of them believe the user is authorized
 
186
   * to view the resource in question.
 
187
   */
 
188
  if (iter != authorization_plugins.end())
 
189
  {
 
190
    if (send_error)
 
191
    {
 
192
      my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
 
193
               user_ctx.getUser().c_str(),
 
194
               user_ctx.getIp().c_str(),
 
195
               table.getSQLPath().c_str());
 
196
    }
 
197
    return false;
 
198
  }
 
199
  return true;
 
200
}
 
201
 
 
202
bool plugin::Authorization::isAuthorized(const SecurityContext &user_ctx,
 
203
                                         const Session *session,
 
204
                                         bool send_error)
 
205
{
 
206
  const SecurityContext &session_ctx= session->getSecurityContext();
 
207
 
 
208
  /* If we never loaded any authorization plugins, just return true */
 
209
  if (authorization_plugins.empty())
 
210
    return true;
 
211
 
 
212
  /* Use find_if instead of foreach so that we can collect return codes */
 
213
  vector<plugin::Authorization *>::const_iterator iter=
 
214
    find_if(authorization_plugins.begin(),
 
215
            authorization_plugins.end(),
 
216
            RestrictProcessFunctor(user_ctx, session_ctx));
229
217
 
230
218
  /*
231
219
   * If iter is == end() here, that means that all of the plugins returned
241
229
    }
242
230
    return false;
243
231
  }
244
 
 
245
232
  return true;
246
233
}
247
234
 
248
 
void plugin::Authorization::pruneSchemaNames(drizzled::identifier::User::const_shared_ptr user_ctx,
249
 
                                             identifier::Schema::vector &set_of_schemas)
 
235
void plugin::Authorization::pruneSchemaNames(const SecurityContext &user_ctx,
 
236
                                             SchemaIdentifiers &set_of_schemas)
250
237
{
251
238
  /* If we never loaded any authorization plugins, just return true */
252
239
  if (authorization_plugins.empty())
253
240
    return;
254
241
 
255
 
  set_of_schemas.erase(std::remove_if(set_of_schemas.begin(),
256
 
                                      set_of_schemas.end(),
257
 
                                      PruneSchemaFunctor(user_ctx)),
 
242
  set_of_schemas.erase(remove_if(set_of_schemas.begin(),
 
243
                                 set_of_schemas.end(),
 
244
                                 PruneSchemaFunctor(user_ctx)),
258
245
                       set_of_schemas.end());
259
246
}
260
247