Skip to content

Commit d94dc38

Browse files
committed
Merge branch 'wl9953-unix-sockets'
# Conflicts: # include/devapi/settings.h # include/mysql_xapi.h # xapi/mysqlx.cc # xapi/mysqlx_cc_internal.h # xapi/tests/test.h
2 parents b2b190d + 548161a commit d94dc38

File tree

20 files changed

+933
-294
lines changed

20 files changed

+933
-294
lines changed

cdk/core/session.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ struct Session_builder
6767
3. If a bail-out error was detected, throws that error.
6868
*/
6969

70-
Socket_base* connect(Socket_base*);
70+
template <class Conn>
71+
Conn* connect(Conn*);
7172

7273
bool operator() (const ds::TCPIP &ds, const ds::TCPIP::Options &options);
7374
#ifndef WIN32
@@ -81,8 +82,8 @@ struct Session_builder
8182
};
8283

8384

84-
Session_builder::Socket_base*
85-
Session_builder::connect(Session_builder::Socket_base* connection)
85+
template <class Conn>
86+
Conn* Session_builder::connect(Conn* connection)
8687
{
8788
m_attempts++;
8889

@@ -129,7 +130,7 @@ Session_builder::operator() (
129130
using foundation::connection::TCPIP;
130131
using foundation::connection::Socket_base;
131132

132-
Socket_base* connection = connect(new TCPIP(ds.host(), ds.port()));
133+
TCPIP* connection = connect(new TCPIP(ds.host(), ds.port()));
133134

134135
if (!connection)
135136
return false; // continue to next host if available
@@ -162,7 +163,7 @@ Session_builder::operator() (
162163
using foundation::connection::Unix_socket;
163164
using foundation::connection::Socket_base;
164165

165-
Socket_base* connection = connect(new Unix_socket(ds.path()));
166+
Unix_socket* connection = connect(new Unix_socket(ds.path()));
166167

167168
if (!connection)
168169
return false; // continue to next host if available

cdk/foundation/socket_detail.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ Socket connect(const char *path)
649649
catch (...)
650650
{
651651
close(socket);
652+
rethrow_error();
652653
}
653654
return socket;
654655
}

cdk/include/mysql/cdk/data_source.h

Lines changed: 43 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class Protocol_options
139139
public:
140140

141141
enum auth_method_t {
142+
DEFAULT,
142143
PLAIN,
143144
MYSQL41,
144145
EXTERNAL
@@ -149,73 +150,71 @@ class Protocol_options
149150
};
150151

151152

152-
class TCPIP::Options
153+
class Options
153154
: public ds::Options<Protocol_options>
154155
{
156+
protected:
157+
158+
auth_method_t m_auth_method = DEFAULT;
159+
160+
public:
161+
162+
Options()
163+
{}
164+
165+
Options(const string &usr, const std::string *pwd =NULL)
166+
: ds::Options<Protocol_options>(usr, pwd)
167+
{}
168+
169+
void set_auth_method(auth_method_t auth_method)
170+
{
171+
m_auth_method = auth_method;
172+
}
173+
174+
auth_method_t auth_method() const
175+
{
176+
return m_auth_method;
177+
}
178+
179+
};
180+
181+
182+
class TCPIP::Options
183+
: public ds::mysqlx::Options
184+
{
185+
public:
186+
187+
typedef cdk::connection::TLS::Options TLS_options;
188+
155189
private:
156190

157191
#ifdef WITH_SSL
158192
cdk::connection::TLS::Options m_tls_options;
159193
#endif
160-
bool m_auth_method_set;
161-
auth_method_t m_auth_method;
162194

163195
public:
164196

165-
Options() : m_auth_method_set(false),
166-
m_auth_method(auth_method_t::MYSQL41)
167-
{
168-
}
197+
Options()
198+
{}
169199

170200
Options(const string &usr, const std::string *pwd =NULL)
171-
: ds::Options<Protocol_options>(usr, pwd),
172-
m_auth_method_set(false),
173-
m_auth_method(auth_method_t::MYSQL41)
174-
{
175-
/*
176-
We don't know if the connection will be over SSL.
177-
Guessing unencrypted connection and MYSQL41 auth.
178-
*/
179-
}
201+
: ds::mysqlx::Options(usr, pwd)
202+
{}
180203

181204
#ifdef WITH_SSL
182205

183-
void set_tls(const cdk::connection::TLS::Options& options)
206+
void set_tls(const TLS_options& options)
184207
{
185208
m_tls_options = options;
186-
187-
/*
188-
The authentication method should not be changed
189-
if the user code set it specifically
190-
*/
191-
if (!m_auth_method_set)
192-
{
193-
// Use PLAIN auth for SSL connections
194-
if (options.ssl_mode() == cdk::connection::TLS::Options::SSL_MODE::DISABLED)
195-
m_auth_method = auth_method_t::MYSQL41;
196-
else
197-
m_auth_method = auth_method_t::PLAIN;
198-
}
199209
}
200210

201-
const cdk::connection::TLS::Options& get_tls() const
211+
const TLS_options& get_tls() const
202212
{
203213
return m_tls_options;
204214
}
205215

206216
#endif
207217

208-
void set_auth_method(auth_method_t auth_method)
209-
{
210-
m_auth_method = auth_method;
211-
m_auth_method_set = true;
212-
}
213-
214-
auth_method_t auth_method() const
215-
{
216-
return m_auth_method;
217-
}
218-
219218
};
220219

221220

@@ -227,8 +226,7 @@ class Unix_socket
227226

228227
public:
229228

230-
class Options;
231-
229+
using Options = ds::mysqlx::Options;
232230

233231
Unix_socket(const std::string &path)
234232
: m_path(path)
@@ -240,44 +238,12 @@ class Unix_socket
240238
virtual ~Unix_socket() {}
241239

242240
virtual const std::string& path() const { return m_path; }
243-
};
244-
245-
class Unix_socket::Options : public ds::Options<Protocol_options>
246-
{
247-
248-
public:
249-
250-
Options()
251-
{}
252-
253-
Options(const ds::Options<Protocol_options>& opt)
254-
: ds::Options<Protocol_options>(opt)
255-
{}
256-
257-
Options(const string &usr, const std::string *pwd =NULL)
258-
: ds::Options<Protocol_options>(usr, pwd)
259-
{}
260-
261-
void set_auth_method(auth_method_t auth_method)
262-
{
263-
m_auth_method = auth_method;
264-
}
265-
266-
private:
267-
auth_method_t m_auth_method = auth_method_t::PLAIN;
268-
269-
auth_method_t auth_method() const
270-
{
271-
return m_auth_method;
272-
}
273-
274-
275-
276241
};
277242
#endif //_WIN32
278243

279244
} // mysqlx
280245

246+
281247
namespace mysql {
282248

283249
/*

cdk/include/mysql/cdk/foundation/connection_tcpip.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ class TCPIP
145145

146146
TCPIP(const std::string& host, unsigned short port);
147147

148+
bool is_secure() const
149+
{
150+
return false;
151+
}
152+
148153
private:
149154

150155
Socket_base::Impl& get_base_impl();
@@ -160,6 +165,11 @@ class Unix_socket
160165

161166
Unix_socket(const std::string& path);
162167

168+
bool is_secure() const
169+
{
170+
return true;
171+
}
172+
163173
private:
164174

165175
Socket_base::Impl& get_base_impl();

cdk/include/mysql/cdk/foundation/connection_yassl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class TLS
4747
TLS(Socket_base* tcpip,
4848
const Options& Opts);
4949

50+
bool is_secure() const
51+
{
52+
return true;
53+
}
5054

5155
class Read_op;
5256
class Read_some_op;

cdk/include/mysql/cdk/mysqlx/session.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ class Session
445445

446446
public:
447447

448-
cdk::api::Connection* get_connection();
448+
//cdk::api::Connection* get_connection();
449449

450450
typedef ds::Options<ds::mysqlx::Protocol_options> Options;
451451

@@ -466,7 +466,7 @@ class Session
466466
, m_nr_cols(0)
467467
{
468468
m_stmt_stats.clear();
469-
authenticate(options);
469+
authenticate(options, conn.is_secure());
470470
check_protocol_fields();
471471
}
472472

@@ -606,7 +606,7 @@ class Session
606606
Reply_init &set_command(Proto_op *cmd);
607607

608608
// Authentication (cdk::protocol::mysqlx::Auth_processor)
609-
void authenticate(const Options &options);
609+
void authenticate(const Options &options, bool secure = false);
610610
void auth_ok(bytes data);
611611
void auth_continue(bytes data);
612612
void auth_fail(bytes data);

cdk/mysqlx/session.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,20 @@ class AuthExternal
308308
*/
309309

310310

311-
void Session::authenticate( const Session::Options &options)
311+
void Session::authenticate(const Session::Options &options,
312+
bool secure_conn)
312313
{
313314

314315
delete m_auth_interface;
315316
m_auth_interface = NULL;
316317

317318
using cdk::ds::mysqlx::Protocol_options;
319+
auto am = options.auth_method();
318320

319-
switch (options.auth_method())
321+
if (Protocol_options::DEFAULT == am)
322+
am = secure_conn ? Protocol_options::PLAIN : Protocol_options::MYSQL41;
323+
324+
switch (am)
320325
{
321326
case Protocol_options::MYSQL41:
322327
m_auth_interface = new AuthMysql41(options);
@@ -327,6 +332,8 @@ void Session::authenticate( const Session::Options &options)
327332
case Protocol_options::EXTERNAL:
328333
m_auth_interface = new AuthExternal(options);
329334
break;
335+
case Protocol_options::DEFAULT:
336+
assert(false); // should not happen
330337
default:
331338
THROW("Unknown authentication method");
332339
}

0 commit comments

Comments
 (0)