1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright 2011 Daniel Nichter
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.
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.
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
21
#include <drizzled/session.h>
22
#include <drizzled/plugin/authentication.h>
26
using namespace drizzled;
28
namespace drizzle_plugin {
29
namespace auth_schema {
31
class AuthSchema : public drizzled::plugin::Authentication
34
AuthSchema(bool enabled);
39
* Set the authentication table.
41
* @param[in] table Schema-qualified table name.
43
* @retval false Success, new auth table set
44
* @retval true Failure, auth table not changed
46
bool setTable(const string &table);
49
* These are the query_log system variables. So sysvar_enabled is
50
* auth_schema_enabled in SHOW VARIABLES, etc. They are all global
58
* Base class method to check authentication for a user.
60
bool authenticate(const identifier::User &sctx, const string &password);
64
* Verify that the client password matches the real password.
67
* This method compares two MySQL hashed passwords: one from the
68
* client who is trying to authenticate, and the other from an
69
* auth table with the real password. The client's password is
70
* hashed with the scramble bytes that Drizzle sent when the client
71
* connected, so we hash the real password with these bytes, too.
72
* This method is a modified copy of auth_file::verifyMySQLHash(),
73
* written by Eric Day, so credit the credit is his for the algos.
75
* @param[in] real_password Real password, double-hashed but not yet
76
* scrambled with the scramble bytes.
77
* @param[in] scramble_bytes Random bytes sent by Drizzle to client.
78
* @param[in] client_password Password sent by client, double-hashed and
79
* scrambled with the scramble bytes.
81
* @return True if the passwords match, else false.
83
bool verifyMySQLPassword(const string &real_password,
84
const string &scramble_bytes,
85
const string &client_password);
89
* Split, escape, and quote the auth table name.
92
* This function is called by setTable().
93
* The auth table name must be schema-qualified, so it should have
94
* the form schema.table or `schema`.`table`, etc. This function
95
* splits the table name on the period, checks each half (the schema
96
* name and the table name), and escapes and backtick quotes each
97
* if necessary. The result is that the auth table name is always
98
* finally of the form `schema`.`table`.
100
* @param[in] table Schema-qualified auth table name
102
* @return Escaped and backtick-quoted auth table name
104
string escapeQuoteAuthTable(const string &table);
108
* Escape and quote an identifier.
110
* @param[in] input Identifer, possibly already quoted
112
* @return Escaped and backtick-quoted identifier
114
string escapeQuoteIdentifier(const string &input);
118
* Escape a string for use as a single-quoted string value.
121
* The string is escaped so that it can be used as a value in single quotes, like:
122
* col='untrusted value'. Therefore, double quotes are not escaped because they're
123
* valid inside single-quoted values. Escaping helps avoid SQL injections.
125
* @param[in] input Untrusted string
127
* @return Escaped string
129
string escapeString(const string &input);
132
Session::shared_ptr _session; ///< Internal session for querying auth table
135
} /* end namespace drizzle_plugin::auth_schema */
136
} /* end namespace drizzle_plugin */