2425.1.1
by Daniel Nichter
auth_schema (auth_db) working prototype. |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright 2011 Daniel Nichter
|
|
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> |
|
2425.1.2
by Daniel
Add auth_schema_enabled sysvar. Use drizzle_plugin::auth_schema namespace. Add user docs and document code. |
21 |
#include <drizzled/item.h> |
2425.1.1
by Daniel Nichter
auth_schema (auth_db) working prototype. |
22 |
#include <drizzled/plugin.h> |
23 |
#include <drizzled/module/option_map.h> |
|
2425.1.2
by Daniel
Add auth_schema_enabled sysvar. Use drizzle_plugin::auth_schema namespace. Add user docs and document code. |
24 |
#include <boost/program_options.hpp> |
2425.1.1
by Daniel Nichter
auth_schema (auth_db) working prototype. |
25 |
#include "auth_schema.h" |
26 |
||
27 |
namespace po= boost::program_options; |
|
28 |
||
29 |
using namespace std; |
|
30 |
||
2425.1.2
by Daniel
Add auth_schema_enabled sysvar. Use drizzle_plugin::auth_schema namespace. Add user docs and document code. |
31 |
namespace drizzle_plugin { |
2425.1.1
by Daniel Nichter
auth_schema (auth_db) working prototype. |
32 |
namespace auth_schema { |
33 |
||
2425.1.2
by Daniel
Add auth_schema_enabled sysvar. Use drizzle_plugin::auth_schema namespace. Add user docs and document code. |
34 |
/**
|
35 |
* Forward declarations.
|
|
36 |
*/
|
|
2425.1.1
by Daniel Nichter
auth_schema (auth_db) working prototype. |
37 |
bool update_table(Session *, set_var *var); |
38 |
||
2425.1.2
by Daniel
Add auth_schema_enabled sysvar. Use drizzle_plugin::auth_schema namespace. Add user docs and document code. |
39 |
/**
|
40 |
* Singleton instance of the plugin.
|
|
41 |
*/
|
|
42 |
static AuthSchema *auth_schema= NULL; |
|
2425.1.1
by Daniel Nichter
auth_schema (auth_db) working prototype. |
43 |
|
44 |
bool update_table(Session *, set_var *var) |
|
45 |
{
|
|
2425.1.4
by Daniel
Escape user in SQL statement to avoid SQL injection. Verify auth table name. Include auth query in error message. Tweak formatting to match coding standards. |
46 |
if (not var->value->str_value.data()) |
47 |
{
|
|
48 |
errmsg_printf(error::ERROR, _("auth_schema table cannot be NULL")); |
|
49 |
return true; // error |
|
50 |
}
|
|
51 |
const string table(var->value->str_value.data()); |
|
52 |
return auth_schema->setTable(table); |
|
2425.1.1
by Daniel Nichter
auth_schema (auth_db) working prototype. |
53 |
}
|
54 |
||
2425.1.2
by Daniel
Add auth_schema_enabled sysvar. Use drizzle_plugin::auth_schema namespace. Add user docs and document code. |
55 |
static void init_options(module::option_context &context) |
2425.1.1
by Daniel Nichter
auth_schema (auth_db) working prototype. |
56 |
{
|
2425.1.5
by Daniel
Enable plugin by default. Always escape and backtick quote the auth table name. |
57 |
auth_schema= new AuthSchema(true); |
2425.1.1
by Daniel Nichter
auth_schema (auth_db) working prototype. |
58 |
|
59 |
context("table", |
|
2425.1.2
by Daniel
Add auth_schema_enabled sysvar. Use drizzle_plugin::auth_schema namespace. Add user docs and document code. |
60 |
po::value<string>(&auth_schema->sysvar_table)->default_value("auth.users"), |
2425.1.1
by Daniel Nichter
auth_schema (auth_db) working prototype. |
61 |
N_("Database-qualified auth table name")); |
62 |
}
|
|
63 |
||
64 |
static int init(module::Context &context) |
|
65 |
{
|
|
66 |
const module::option_map &vm= context.getOptions(); |
|
67 |
||
68 |
if (not vm["table"].as<string>().empty()) |
|
2425.1.4
by Daniel
Escape user in SQL statement to avoid SQL injection. Verify auth table name. Include auth query in error message. Tweak formatting to match coding standards. |
69 |
auth_schema->setTable(vm["table"].as<string>()); |
2425.1.1
by Daniel Nichter
auth_schema (auth_db) working prototype. |
70 |
|
71 |
context.add(auth_schema); |
|
72 |
||
73 |
context.registerVariable( |
|
2425.1.2
by Daniel
Add auth_schema_enabled sysvar. Use drizzle_plugin::auth_schema namespace. Add user docs and document code. |
74 |
new sys_var_bool_ptr("enabled", &auth_schema->sysvar_enabled)); |
75 |
||
76 |
context.registerVariable( |
|
77 |
new sys_var_std_string("table", auth_schema->sysvar_table, NULL, &update_table)); |
|
2425.1.1
by Daniel Nichter
auth_schema (auth_db) working prototype. |
78 |
|
79 |
return 0; |
|
80 |
}
|
|
81 |
||
2425.1.2
by Daniel
Add auth_schema_enabled sysvar. Use drizzle_plugin::auth_schema namespace. Add user docs and document code. |
82 |
} /* end namespace drizzle_plugin::auth_schema */ |
83 |
} /* end namespace drizzle_plugin */ |
|
2425.1.1
by Daniel Nichter
auth_schema (auth_db) working prototype. |
84 |
|
2425.1.2
by Daniel
Add auth_schema_enabled sysvar. Use drizzle_plugin::auth_schema namespace. Add user docs and document code. |
85 |
DRIZZLE_PLUGIN( |
86 |
drizzle_plugin::auth_schema::init, |
|
87 |
NULL, |
|
88 |
drizzle_plugin::auth_schema::init_options |
|
89 |
);
|