Skip to content

Commit 4370c84

Browse files
committed
merge to trunk
2 parents 90ee486 + 261ef73 commit 4370c84

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3506
-1906
lines changed

.bzrignore

+2
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ client/rpl_tblmap.cc
412412
client/rpl_utility.h
413413
client/rpl_utility.cc
414414
client/select_test
415+
client/sql_commands_system_data.h
416+
client/sql_commands_system_tables.h
415417
client/sql_const.h
416418
client/sql_string.cpp
417419
client/ssl_test

client/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ TARGET_LINK_LIBRARIES(mysql_config_editor mysqlclient)
8888
MYSQL_ADD_EXECUTABLE(mysql_secure_installation mysql_secure_installation.cc)
8989
TARGET_LINK_LIBRARIES(mysql_secure_installation mysqlclient)
9090

91+
IF(UNIX)
92+
MYSQL_ADD_EXECUTABLE(mysql_install_db mysql_install_db.cc auth_utils.cc path.cc)
93+
TARGET_LINK_LIBRARIES(mysql_install_db mysqlclient)
94+
ADD_DEPENDENCIES(mysql_install_db GenBootstrapPriv)
95+
ENDIF(UNIX)
96+
9197
# "WIN32" also covers 64 bit. "echo" is used in some files below "mysql-test/".
9298
IF(WIN32)
9399
MYSQL_ADD_EXECUTABLE(echo echo.c)

client/auth_utils.cc

+129
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
3+
4+
This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; version 2 of the License.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License
14+
along with this program; if not, write to the Free Software
15+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16+
*/
17+
#include "client_priv.h"
18+
#include "my_rnd.h"
19+
#include "my_aes.h"
20+
#include <sstream>
21+
#include <fstream>
22+
#include <stdint.h>
23+
#include "auth_utils.h"
24+
25+
using namespace std;
26+
/**
27+
Lazy whitespace trimmer
28+
*/
29+
void trim(string *s)
30+
{
31+
stringstream trimmer;
32+
trimmer << *s;
33+
s->clear();
34+
trimmer >> *s;
35+
}
36+
37+
int parse_cnf_file(istream &sin, map<string, string > *options,
38+
const string &header)
39+
{
40+
string option_name;
41+
string option_value;
42+
string token_header;
43+
token_header.append("[").append(header).append("]");
44+
try{
45+
while(true)
46+
{
47+
string row;
48+
getline(sin, row);
49+
trim(&row);
50+
if (row == token_header)
51+
break;
52+
else if (sin.eof())
53+
return ERR_NO_SUCH_CATEGORY;
54+
}
55+
56+
while (!getline(sin, option_name, '=').eof())
57+
{
58+
trim(&option_name);
59+
if (option_name[0] == '[')
60+
break;
61+
getline(sin, option_value);
62+
trim(&option_value);
63+
if (option_name.length() > 0)
64+
options->insert(make_pair<string, string >(option_name, option_value));
65+
}
66+
return ALL_OK;
67+
} catch(...)
68+
{
69+
return ERR_SYNTAX;
70+
}
71+
}
72+
73+
#define MAX_CIPHER_LEN 4096
74+
#define MAX_CIPHER_STORE_LEN 4U
75+
#define LOGIN_KEY_LEN 20U
76+
77+
int decrypt_login_cnf_file(istream &fin, ostream &sout)
78+
{
79+
try {
80+
fin.seekg(MAX_CIPHER_STORE_LEN, fin.beg);
81+
char rkey[LOGIN_KEY_LEN];
82+
fin.read(rkey, LOGIN_KEY_LEN);
83+
while(true)
84+
{
85+
int len;
86+
char len_buf[MAX_CIPHER_STORE_LEN];
87+
char cipher[MAX_CIPHER_LEN];
88+
fin.read(len_buf, MAX_CIPHER_STORE_LEN);
89+
len= sint4korr(len_buf);
90+
if (len == 0 || fin.eof())
91+
break;
92+
if (len > MAX_CIPHER_LEN)
93+
return ERR_ENCRYPTION;
94+
fin.read(cipher, len);
95+
char plain[MAX_CIPHER_LEN+1];
96+
int aes_length;
97+
aes_length= my_aes_decrypt((const unsigned char *) cipher, len,
98+
(unsigned char *) plain,
99+
(const unsigned char *) rkey,
100+
LOGIN_KEY_LEN, my_aes_128_ecb, NULL);
101+
if (aes_length > MAX_CIPHER_LEN)
102+
return ERR_ENCRYPTION;
103+
plain[aes_length]= 0;
104+
sout << plain;
105+
}
106+
return ALL_OK;
107+
108+
} catch(...)
109+
{
110+
return ERR_ENCRYPTION;
111+
}
112+
}
113+
114+
const string g_allowed_pwd_chars("qwertyuiopasdfghjklzxcvbnm,.-1234567890+*"
115+
"QWERTYUIOPASDFGHJKLZXCVBNM;:_!#%&/()=?><");
116+
const string get_allowed_pwd_chars() { return g_allowed_pwd_chars; }
117+
118+
void generate_password(string *password, int size)
119+
{
120+
stringstream ss;
121+
rand_struct srnd;
122+
while(size > 0)
123+
{
124+
int ch= ((int)(my_rnd_ssl(&srnd)*100))%get_allowed_pwd_chars().size();
125+
ss << get_allowed_pwd_chars()[ch];
126+
--size;
127+
}
128+
password->assign(ss.str());
129+
}

client/auth_utils.h

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
3+
4+
This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; version 2 of the License.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License
14+
along with this program; if not, write to the Free Software
15+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16+
*/
17+
#ifndef AUTH_UTILS_INCLUDED
18+
#define AUTH_UTILS_INCLUDED
19+
#include <string>
20+
#include <iostream>
21+
#include <map>
22+
23+
#define ERR_FILE 1 // File related error
24+
#define ERR_ENCRYPTION 2 // Encryption related error
25+
#define ERR_SYNTAX 3 // Syntax and parsing related error
26+
#define ERR_OTHER 4 // Unspecified error
27+
#define ERR_NO_SUCH_CATEGORY 5 // The specified category isn't present
28+
#define ALL_OK 0 // Reporting success and good fortune
29+
30+
/**
31+
Trivial parser for the login.cnf file which assumes that first entry
32+
is a [client] header followed by some attribute/value -pairs
33+
34+
@param sin Input stream
35+
@param[out] options Output map
36+
@return success rate
37+
@retval ALL_OK Reporting success and good fortune
38+
@retval ERR_SYNTAX Failed to parse the stream
39+
*/
40+
int parse_cnf_file(std::istream &sin,
41+
std::map<std::string, std::string > *options,
42+
const std::string &header);
43+
/**
44+
Decrypts a file and produces a stringstream.
45+
46+
@param fin Input stream
47+
@param[out] sout Output stream
48+
@return success rate
49+
@retval ALL_OK Reporting success and good fortune
50+
@retval ERR_ENCRYPTION Failed to decrypt the input stream
51+
*/
52+
int decrypt_login_cnf_file(std::istream &fin, std::ostream &sout);
53+
54+
void generate_password(std::string *password, int size);
55+
void trim(std::string *s);
56+
const std::string get_allowed_pwd_chars();
57+
58+
/**
59+
An experimental uniform representation of access privileges in MySQL
60+
*/
61+
class Access_privilege
62+
{
63+
public:
64+
Access_privilege() : m_priv(0) {}
65+
Access_privilege(uint64_t privileges) : m_priv(privileges) {}
66+
Access_privilege(const Access_privilege &priv) : m_priv(priv.m_priv) {}
67+
bool has_select_ac() { return (m_priv & (1L)) > 0; }
68+
bool has_insert_ac() { return (m_priv & (1L << 1)) > 0; }
69+
bool has_update_ac() { return (m_priv & (1L << 2)) > 0; }
70+
bool has_delete_ac() { return (m_priv & (1L << 3)) > 0; }
71+
bool has_create_ac() { return (m_priv & (1L << 4)) > 0; }
72+
bool has_drop_ac() { return (m_priv & (1L << 5)) > 0; }
73+
bool has_relead_ac() { return (m_priv & (1L << 6)) > 0; }
74+
bool has_shutdown_ac() { return (m_priv & (1L << 7)) > 0; }
75+
bool has_process_ac() { return (m_priv & (1L << 8)) > 0; }
76+
bool has_file_ac() { return (m_priv & (1L << 9)) > 0; }
77+
bool has_grant_ac() { return (m_priv & (1L << 10)) > 0; }
78+
bool has_references_ac() { return (m_priv & (1L << 11)) > 0; }
79+
bool has_index_ac() { return (m_priv & (1L << 12)) > 0; }
80+
bool has_alter_ac() { return (m_priv & (1L << 13)) > 0; }
81+
bool has_show_db_ac() { return (m_priv & (1L << 14)) > 0; }
82+
bool has_super_ac() { return (m_priv & (1L << 15)) > 0; }
83+
bool has_create_tmp_ac() { return (m_priv & (1L << 16)) > 0; }
84+
bool has_lock_tables_ac() { return (m_priv & (1L << 17)) > 0; }
85+
bool has_execute_ac() { return (m_priv & (1L << 18)) > 0; }
86+
bool has_repl_slave_ac() { return (m_priv & (1L << 19)) > 0; }
87+
bool has_repl_client_ac() { return (m_priv & (1L << 20)) > 0; }
88+
bool has_create_view_ac() { return (m_priv & (1L << 21)) > 0; }
89+
bool has_show_view_ac() { return (m_priv & (1L << 22)) > 0; }
90+
bool has_create_proc_ac() { return (m_priv & (1L << 23)) > 0; }
91+
bool has_alter_proc_ac() { return (m_priv & (1L << 24)) > 0; }
92+
bool has_create_user_ac() { return (m_priv & (1L << 25)) > 0; }
93+
bool has_event_ac() { return (m_priv & (1L << 26)) > 0; }
94+
bool has_trigger_ac() { return (m_priv & (1L << 27)) > 0; }
95+
bool has_create_tablespace_ac() { return (m_priv & (1L << 28)) > 0; }
96+
inline static uint64_t select_ac() { return (1L); }
97+
inline uint64_t insert_ac() { return (1L << 1); }
98+
inline uint64_t update_ac() { return (1L << 2); }
99+
inline uint64_t delete_ac() { return (1L << 3); }
100+
inline static uint64_t create_ac() { return (1L << 4); }
101+
inline static uint64_t drop_ac() { return (1L << 5); }
102+
inline static uint64_t relead_ac() { return (1L << 6); }
103+
inline static uint64_t shutdown_ac() { return (1L << 7); }
104+
inline static uint64_t process_ac() { return (1L << 8); }
105+
inline static uint64_t file_ac() { return (1L << 9); }
106+
inline static uint64_t grant_ac() { return (1L << 10); }
107+
inline static uint64_t references_ac() { return (1L << 11); }
108+
inline static uint64_t index_ac() { return (1L << 12); }
109+
inline static uint64_t alter_ac() { return (1L << 13); }
110+
inline static uint64_t show_db_ac() { return (1L << 14); }
111+
inline static uint64_t super_ac() { return (1L << 15); }
112+
inline static uint64_t create_tmp_ac() { return (1L << 16); }
113+
inline static uint64_t lock_tables_ac() { return (1L << 17); }
114+
inline static uint64_t execute_ac() { return (1L << 18); }
115+
inline static uint64_t repl_slave_ac() { return (1L << 19); }
116+
inline static uint64_t repl_client_ac() { return (1L << 20); }
117+
inline static uint64_t create_view_ac() { return (1L << 21); }
118+
inline static uint64_t show_view_ac() { return (1L << 22); }
119+
inline static uint64_t create_proc_ac() { return (1L << 23); }
120+
inline static uint64_t alter_proc_ac() { return (1L << 24); }
121+
inline static uint64_t create_user_ac() { return (1L << 25); }
122+
inline static uint64_t event_ac() { return (1L << 26); }
123+
inline static uint64_t trigger_ac() { return (1L << 27); }
124+
inline static uint64_t create_tablespace_ac() { return (1L << 28); }
125+
inline static uint64_t acl_all() { return 0xfffffff; }
126+
uint64_t to_int() const { return m_priv; };
127+
private:
128+
uint64_t m_priv;
129+
};
130+
#endif

client/infix_ostream_it.h

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
3+
4+
This program is free software; you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation; version 2 of the License.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
GNU General Public License for more details.
12+
13+
You should have received a copy of the GNU General Public License
14+
along with this program; if not, write to the Free Software
15+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16+
*/
17+
#ifndef INFIX_OSTREAM_IT_INCLUDED
18+
#define INFIX_OSTREAM_IT_INCLUDED
19+
#include <ostream>
20+
#include <iterator>
21+
#include <string>
22+
23+
template <class T >
24+
class infix_ostream_iterator :
25+
public std::iterator<std::output_iterator_tag, T >
26+
{
27+
public:
28+
infix_ostream_iterator(std::ostream &s)
29+
: m_os(&s)
30+
{}
31+
32+
infix_ostream_iterator(std::ostream &s, const char *d)
33+
: m_os(&s), m_delimiter(d)
34+
{}
35+
36+
infix_ostream_iterator<T > &operator=(T const &item)
37+
{
38+
*m_os << m_curr_delimiter << item;
39+
m_curr_delimiter = m_delimiter;
40+
return *this;
41+
}
42+
43+
infix_ostream_iterator<T > &operator*()
44+
{
45+
return *this;
46+
}
47+
48+
infix_ostream_iterator<T > &operator++()
49+
{
50+
return *this;
51+
}
52+
53+
infix_ostream_iterator<T > &operator++(int)
54+
{
55+
return *this;
56+
}
57+
private:
58+
std::ostream *m_os;
59+
std::string m_curr_delimiter;
60+
std::string m_delimiter;
61+
};
62+
63+
#endif
64+

0 commit comments

Comments
 (0)