1337.4.2
by Eric Day
Added MYSQL_PASSWORD() UDF. |
1 |
/* Copyright (C) 2010 Rackspace
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
|
15 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
16 |
#include <config.h> |
1337.4.2
by Eric Day
Added MYSQL_PASSWORD() UDF. |
17 |
#include "mysql_password.h" |
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
18 |
#include <drizzled/algorithm/sha1.h> |
19 |
#include <drizzled/util/convert.h> |
|
1337.4.2
by Eric Day
Added MYSQL_PASSWORD() UDF. |
20 |
|
21 |
using namespace std; |
|
1816.2.3
by Monty Taylor
Fixed some more ICC warnings. How did I get started on this this morning? |
22 |
|
1964.2.9
by Monty Taylor
All protocol stuff except for the buffer_length. WTF? |
23 |
namespace drizzle_plugin |
1816.2.3
by Monty Taylor
Fixed some more ICC warnings. How did I get started on this this morning? |
24 |
{
|
1337.4.2
by Eric Day
Added MYSQL_PASSWORD() UDF. |
25 |
|
26 |
const char* MySQLPasswordName = "mysql_password"; |
|
27 |
||
28 |
MySQLPassword::MySQLPassword(void): |
|
29 |
Item_str_func() |
|
30 |
{ } |
|
31 |
||
32 |
const char *MySQLPassword::func_name() const |
|
33 |
{
|
|
34 |
return MySQLPasswordName; |
|
35 |
}
|
|
36 |
||
37 |
void MySQLPassword::fix_length_and_dec() |
|
38 |
{
|
|
39 |
max_length= args[0]->max_length; |
|
40 |
}
|
|
41 |
||
42 |
bool MySQLPassword::check_argument_count(int n) |
|
43 |
{
|
|
44 |
return (n == 1); |
|
45 |
}
|
|
46 |
||
1964.2.9
by Monty Taylor
All protocol stuff except for the buffer_length. WTF? |
47 |
drizzled::String *MySQLPassword::val_str(drizzled::String *str) |
1337.4.2
by Eric Day
Added MYSQL_PASSWORD() UDF. |
48 |
{
|
1964.2.9
by Monty Taylor
All protocol stuff except for the buffer_length. WTF? |
49 |
drizzled::String argument; |
50 |
drizzled::String *password= args[0]->val_str(&argument); |
|
51 |
drizzled::SHA1_CTX ctx; |
|
1337.4.2
by Eric Day
Added MYSQL_PASSWORD() UDF. |
52 |
uint8_t hash_tmp1[SHA1_DIGEST_LENGTH]; |
53 |
uint8_t hash_tmp2[SHA1_DIGEST_LENGTH]; |
|
54 |
||
1964.2.9
by Monty Taylor
All protocol stuff except for the buffer_length. WTF? |
55 |
drizzled::SHA1Init(&ctx); |
56 |
drizzled::SHA1Update(&ctx, reinterpret_cast<uint8_t *>(password->ptr()), |
|
57 |
password->length()); |
|
58 |
drizzled::SHA1Final(hash_tmp1, &ctx); |
|
1337.4.2
by Eric Day
Added MYSQL_PASSWORD() UDF. |
59 |
|
1964.2.9
by Monty Taylor
All protocol stuff except for the buffer_length. WTF? |
60 |
drizzled::SHA1Init(&ctx); |
61 |
drizzled::SHA1Update(&ctx, hash_tmp1, SHA1_DIGEST_LENGTH); |
|
62 |
drizzled::SHA1Final(hash_tmp2, &ctx); |
|
1337.4.2
by Eric Day
Added MYSQL_PASSWORD() UDF. |
63 |
|
64 |
str->realloc(SHA1_DIGEST_LENGTH * 2); |
|
1964.2.9
by Monty Taylor
All protocol stuff except for the buffer_length. WTF? |
65 |
drizzled::drizzled_string_to_hex(str->ptr(), |
66 |
reinterpret_cast<const char*>(hash_tmp2), |
|
67 |
SHA1_DIGEST_LENGTH); |
|
1337.4.2
by Eric Day
Added MYSQL_PASSWORD() UDF. |
68 |
str->length(SHA1_DIGEST_LENGTH * 2); |
69 |
||
70 |
return str; |
|
71 |
}
|
|
1816.2.3
by Monty Taylor
Fixed some more ICC warnings. How did I get started on this this morning? |
72 |
|
1964.2.9
by Monty Taylor
All protocol stuff except for the buffer_length. WTF? |
73 |
} /* namespace drizzle_plugin */ |