~drizzle-trunk/drizzle/development

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
16
#include "config.h"
17
#include "mysql_password.h"
1337.5.3 by Eric Day
Moved sha1 to algorithm directory.
18
#include "drizzled/algorithm/sha1.h"
1337.4.2 by Eric Day
Added MYSQL_PASSWORD() UDF.
19
#include "drizzled/util/convert.h"
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
23
namespace drizzled
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
47
String *MySQLPassword::val_str(String *str)
48
{
49
  String argument;
50
  String *password= args[0]->val_str(&argument);
51
  SHA1_CTX ctx;
52
  uint8_t hash_tmp1[SHA1_DIGEST_LENGTH];
53
  uint8_t hash_tmp2[SHA1_DIGEST_LENGTH];
54
55
  SHA1Init(&ctx);
56
  SHA1Update(&ctx, reinterpret_cast<uint8_t *>(password->ptr()),
57
             password->length());
58
  SHA1Final(hash_tmp1, &ctx);
59
60
  SHA1Init(&ctx);
61
  SHA1Update(&ctx, hash_tmp1, SHA1_DIGEST_LENGTH);
62
  SHA1Final(hash_tmp2, &ctx);
63
64
  str->realloc(SHA1_DIGEST_LENGTH * 2);
65
  drizzled_string_to_hex(str->ptr(), reinterpret_cast<const char*>(hash_tmp2),
66
                         SHA1_DIGEST_LENGTH);
67
  str->length(SHA1_DIGEST_LENGTH * 2);
68
69
  return str;
70
}
1816.2.3 by Monty Taylor
Fixed some more ICC warnings. How did I get started on this this morning?
71
72
}