Skip to content

Commit 0309b81

Browse files
committed
Merge remote-tracking branch 'origin/wl14711-jdbc' into jdbc
2 parents 4a0db70 + ddee57e commit 0309b81

13 files changed

+545
-99
lines changed

cppconn/connection.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
#define OPT_HOSTNAME "hostName"
5151
#define OPT_USERNAME "userName"
5252
#define OPT_PASSWORD "password"
53+
#define OPT_PASSWORD1 "password1"
54+
#define OPT_PASSWORD2 "password2"
55+
#define OPT_PASSWORD3 "password3"
5356
#define OPT_PORT "port"
5457
#define OPT_SOCKET "socket"
5558
#define OPT_PIPE "pipe"
@@ -129,6 +132,11 @@
129132
#define OPT_READ_DEFAULT_GROUP "readDefaultGroup"
130133
#define OPT_READ_DEFAULT_FILE "readDefaultFile"
131134

135+
/*
136+
Auth plugin options
137+
*/
138+
#define OPT_OCI_CONFIG_FILE "OPT_OCI_CONFIG_FILE"
139+
132140

133141
namespace sql
134142
{

driver/mysql_connection.cpp

Lines changed: 115 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -507,10 +507,13 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
507507
bool secure_auth= true;
508508
#endif
509509

510+
sql::ConnectOptionsMap::const_iterator it;
511+
510512
/* Port from options must be set as default for all hosts where port
511513
is not specified */
512514
{
513-
sql::ConnectOptionsMap::const_iterator it = properties.find("port");
515+
it = properties.find("port");
516+
514517
if (it != properties.end()) {
515518
try {
516519
p_i = (it->second).get< int >();
@@ -527,31 +530,56 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
527530

528531
/* Values set in properties individually should have priority over those
529532
we restore from Uri */
530-
sql::ConnectOptionsMap::const_iterator it = properties.find("hostName");
533+
{
534+
it = properties.find("hostName");
531535

532-
if (it != properties.end()) {
533-
try {
534-
p_s = (it->second).get< sql::SQLString >();
535-
} catch (sql::InvalidArgumentException&) {
536-
throw sql::InvalidArgumentException("Wrong type passed for userName expected sql::SQLString");
537-
}
538-
if (p_s) {
539-
/*
540-
Parsing uri prior to processing all parameters, so indivudually
541-
specified parameters precede over those in the uri
542-
*/
543-
if(!parseUri(*p_s, uri))
544-
throw sql::InvalidArgumentException("Invalid hostname URI");
536+
if (it != properties.end()) {
537+
try {
538+
p_s = (it->second).get< sql::SQLString >();
539+
} catch (sql::InvalidArgumentException&) {
540+
throw sql::InvalidArgumentException("Wrong type passed for userName expected sql::SQLString");
541+
}
542+
if (p_s) {
543+
/*
544+
Parsing uri prior to processing all parameters, so indivudually
545+
specified parameters precede over those in the uri
546+
*/
547+
if(!parseUri(*p_s, uri))
548+
throw sql::InvalidArgumentException("Invalid hostname URI");
545549

546-
} else {
547-
throw sql::InvalidArgumentException("No string value passed for hostName");
550+
} else {
551+
throw sql::InvalidArgumentException("No string value passed for hostName");
552+
}
548553
}
549554
}
550555

556+
/*
557+
Note: We set pluginDir option early because other options that are plugin
558+
specific might require loading plugins before they can be set.
559+
*/
551560

552-
#define PROCESS_CONN_OPTION(option_type, options_map) process_connection_option< option_type >(it, options_map, sizeof(options_map)/sizeof(String2IntMap), proxy)
561+
{
562+
it = properties.find(OPT_PLUGIN_DIR);
553563

554-
for (it = properties.begin(); it != properties.end(); ++it) {
564+
if (it != properties.end()) {
565+
try {
566+
p_s = (it->second).get< sql::SQLString >();
567+
} catch (sql::InvalidArgumentException&) {
568+
throw sql::InvalidArgumentException("Wrong type passed for pluginDir expected sql::SQLString");
569+
}
570+
if (p_s) {
571+
proxy->options(sql::mysql::MYSQL_PLUGIN_DIR, *p_s);
572+
}
573+
else {
574+
throw sql::InvalidArgumentException("No string value passed for pluginDir");
575+
}
576+
}
577+
}
578+
579+
#define PROCESS_CONN_OPTION(option_type, options_map) \
580+
process_connection_option< option_type >(it, options_map, sizeof(options_map)/sizeof(String2IntMap), proxy)
581+
582+
for (it = properties.begin(); it != properties.end(); ++it) {
555583
if (!it->first.compare(OPT_USERNAME)) {
556584
try {
557585
p_s = (it->second).get< sql::SQLString >();
@@ -574,6 +602,42 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
574602
} else {
575603
throw sql::InvalidArgumentException("No string value passed for password");
576604
}
605+
} else if (!it->first.compare(OPT_PASSWORD1)) {
606+
try {
607+
p_s = (it->second).get< sql::SQLString >();
608+
} catch (sql::InvalidArgumentException&) {
609+
throw sql::InvalidArgumentException("Wrong type passed for password1 expected sql::SQLString");
610+
}
611+
if (p_s) {
612+
int num = 1;
613+
proxy->options(sql::mysql::MYSQL_OPT_USER_PASSWORD, num, *p_s);
614+
} else {
615+
throw sql::InvalidArgumentException("No string value passed for password1");
616+
}
617+
} else if (!it->first.compare(OPT_PASSWORD2)) {
618+
try {
619+
p_s = (it->second).get< sql::SQLString >();
620+
} catch (sql::InvalidArgumentException&) {
621+
throw sql::InvalidArgumentException("Wrong type passed for password2 expected sql::SQLString");
622+
}
623+
if (p_s) {
624+
int num = 2;
625+
proxy->options(sql::mysql::MYSQL_OPT_USER_PASSWORD, num, *p_s);
626+
} else {
627+
throw sql::InvalidArgumentException("No string value passed for password2");
628+
}
629+
} else if (!it->first.compare(OPT_PASSWORD3)) {
630+
try {
631+
p_s = (it->second).get< sql::SQLString >();
632+
} catch (sql::InvalidArgumentException&) {
633+
throw sql::InvalidArgumentException("Wrong type passed for password3 expected sql::SQLString");
634+
}
635+
if (p_s) {
636+
int num = 3;
637+
proxy->options(sql::mysql::MYSQL_OPT_USER_PASSWORD, num, *p_s);
638+
} else {
639+
throw sql::InvalidArgumentException("No string value passed for password3");
640+
}
577641
} else if (!it->first.compare(OPT_PORT)) {
578642
try {
579643
p_i = (it->second).get< int >();
@@ -716,7 +780,7 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
716780
intern->defaultStatementResultType = static_cast< sql::ResultSet::enum_type >(*p_i);
717781
/* The connector is not ready for unbuffered as we need to refetch */
718782
} else if (!it->first.compare("defaultPreparedStatementResultType")) {
719-
#if WE_SUPPORT_USE_RESULT_WITH_PS
783+
#if WE_SUPPORT_USE_RESULT_WITH_PS
720784
try {
721785
p_i = (it->second).get< int >();
722786
} catch (sql::InvalidArgumentException&) {
@@ -739,10 +803,10 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
739803
throw sql::InvalidArgumentException(msg.str());
740804
} while (0);
741805
intern->defaultPreparedStatementResultType = static_cast< sql::ResultSet::enum_type >(*p_i);
742-
#else
806+
#else
743807
throw SQLException("defaultPreparedStatementResultType parameter still not implemented");
744808

745-
#endif
809+
#endif
746810
} else if (!it->first.compare(OPT_METADATA_INFO_SCHEMA)) {
747811
try {
748812
p_b = (it->second).get<bool>();
@@ -832,13 +896,13 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
832896
} catch (sql::InvalidArgumentException&) {
833897
throw sql::InvalidArgumentException("Wrong type passed for useLegacyAuth expected sql::SQLString");
834898
}
835-
#if MYCPPCONN_STATIC_MYSQL_VERSION_ID < 80000
899+
#if MYCPPCONN_STATIC_MYSQL_VERSION_ID < 80000
836900
if (p_b) {
837901
secure_auth= !*p_b;
838902
} else {
839903
throw sql::InvalidArgumentException("No bool value passed for useLegacyAuth");
840904
}
841-
#endif
905+
#endif
842906
} else if (!it->first.compare(OPT_CONNECT_ATTR_ADD)) {
843907
const std::map< sql::SQLString, sql::SQLString > *conVal;
844908
try {
@@ -874,27 +938,48 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
874938
} else if (!it->first.compare(OPT_CONNECT_ATTR_RESET)) {
875939
proxy->options(MYSQL_OPT_CONNECT_ATTR_RESET, 0);
876940

877-
#if MYCPPCONN_STATIC_MYSQL_VERSION_ID > 80000
941+
#if MYCPPCONN_STATIC_MYSQL_VERSION_ID > 80000
878942

879943
//Deprecated
880944
} else if (!it->first.compare("sslVerify")) {
881945

882946
ssl_mode ssl_mode_val = (it->second).get< bool >() ? SSL_MODE_VERIFY_CA
883-
: SSL_MODE_PREFERRED;
947+
: SSL_MODE_PREFERRED;
884948
proxy->options(MYSQL_OPT_SSL_MODE, &ssl_mode_val);
885949

886950
//Deprecated
887951
} else if (!it->first.compare("sslEnforce")) {
888952
ssl_mode ssl_mode_val = (it->second).get< bool >() ? SSL_MODE_REQUIRED
889-
: SSL_MODE_PREFERRED;
953+
: SSL_MODE_PREFERRED;
890954
proxy->options(MYSQL_OPT_SSL_MODE, &ssl_mode_val);
891955

892-
#endif
956+
#endif
957+
} else if (!it->first.compare(OPT_OCI_CONFIG_FILE)) {
958+
try {
959+
p_s= (it->second).get<sql::SQLString>();
960+
} catch (sql::InvalidArgumentException&) {
961+
throw sql::InvalidArgumentException("Wrong type passed for OPT_OCI_CONFIG_FILE. Expected sql::SQLString.");
962+
}
963+
964+
try {
965+
proxy->plugin_option(MYSQL_CLIENT_AUTHENTICATION_PLUGIN,
966+
"authentication_oci_client",
967+
"oci-config-file",
968+
*p_s);
969+
} catch (sql::InvalidArgumentException &e) {
970+
throw ::sql::SQLUnsupportedOptionException(
971+
"Failed to set config file for authentication_oci_client plugin",
972+
OPT_OCI_CONFIG_FILE
973+
);
974+
}
893975

976+
}
977+
else if (!it->first.compare(OPT_PLUGIN_DIR)) {
978+
// Nothing to do here: this option was handeld before the loop
894979

895980
/* If you need to add new integer connection option that should result in
896-
calling mysql_optiong - add its mapping to the intOptions array
897-
*/
981+
calling mysql_optiong - add its mapping to the intOptions array
982+
*/
898983
} else if (PROCESS_CONN_OPTION(int, intOptions)) {
899984
// Nothing to do here
900985

driver/mysql_connection_options.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ enum MySQL_Connection_Options
6868
MYSQL_OPT_TLS_CIPHERSUITES,
6969
MYSQL_OPT_COMPRESSION_ALGORITHMS,
7070
MYSQL_OPT_ZSTD_COMPRESSION_LEVEL,
71-
MYSQL_OPT_LOAD_DATA_LOCAL_DIR
71+
MYSQL_OPT_LOAD_DATA_LOCAL_DIR,
72+
MYSQL_OPT_USER_PASSWORD
7273
#else
7374
MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS, MYSQL_OPT_NAMED_PIPE,
7475
MYSQL_INIT_COMMAND, MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,

0 commit comments

Comments
 (0)