~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/test_authz/test_authz.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2010 Monty Taylor <mordred@inaugust.com>
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#include "config.h"
 
21
 
 
22
#include <string>
 
23
 
 
24
#include "drizzled/plugin/authorization.h"
 
25
#include "drizzled/security_context.h"
 
26
 
 
27
 
 
28
using namespace drizzled;
 
29
 
 
30
namespace authz
 
31
{
 
32
 
 
33
class Authz :
 
34
  public plugin::Authorization
 
35
{
 
36
public:
 
37
  Authz() :
 
38
    plugin::Authorization("test authz")
 
39
  { }
 
40
 
 
41
  /* I told you it was a silly plugin.
 
42
    If the db name is authz_no and the user is authz, then it's blocked
 
43
    If it's anything else, it's approved
 
44
  */
 
45
  virtual bool restrictSchema(const SecurityContext &user_ctx,
 
46
                              const std::string &db)
 
47
  {
 
48
    if (db == "authz_no" and user_ctx.getUser() == "authz")
 
49
      return true;
 
50
    return false;
 
51
  }
 
52
 
 
53
  virtual bool restrictProcess(const SecurityContext &user_ctx,
 
54
                               const SecurityContext &session_ctx)
 
55
  {
 
56
    if (user_ctx.getUser() == session_ctx.getUser())
 
57
      return false;
 
58
    if (user_ctx.getUser() == "authz")
 
59
      return true;
 
60
    return false;
 
61
  }
 
62
};
 
63
 
 
64
Authz *authz= NULL;
 
65
 
 
66
static int init(plugin::Registry &registry)
 
67
{
 
68
  authz= new Authz();
 
69
  registry.add(authz);
 
70
  return 0;
 
71
}
 
72
 
 
73
static int deinit(plugin::Registry &registry)
 
74
{
 
75
  registry.remove(authz);
 
76
  delete authz;
 
77
  return 0;
 
78
}
 
79
 
 
80
} /* namespace authz */
 
81
 
 
82
DRIZZLE_PLUGIN(authz::init, authz::deinit, NULL);