summaryrefslogtreecommitdiff
path: root/vio
diff options
context:
space:
mode:
authorSergey Petrunya <psergey@askmonty.org>2009-09-08 00:50:10 +0400
committerSergey Petrunya <psergey@askmonty.org>2009-09-08 00:50:10 +0400
commit29f0dcb56337a3e352ad7a70dcff6b25bb605325 (patch)
tree84935c21dc958724ae7dcbeeca0c0f08986fc430 /vio
parent915a624cbcb58a10a2cfb2e2e4fd5029191fa86a (diff)
parent8a2454f8e9fce648272577fcf8006ae6e6806cf9 (diff)
downloadmariadb-git-29f0dcb56337a3e352ad7a70dcff6b25bb605325.tar.gz
Merge MySQL->MariaDB
* Finished Monty and Jani's merge * Some InnoDB tests still fail (because it's old xtradb code run against newer testsuite). They are expected to go after mergning with the latest xtradb.
Diffstat (limited to 'vio')
-rw-r--r--vio/viosocket.c22
-rw-r--r--vio/viosslfactories.c60
2 files changed, 57 insertions, 25 deletions
diff --git a/vio/viosocket.c b/vio/viosocket.c
index f0cf5c50055..4c6cc428c52 100644
--- a/vio/viosocket.c
+++ b/vio/viosocket.c
@@ -480,19 +480,22 @@ size_t vio_read_shared_memory(Vio * vio, uchar* buf, size_t size)
size_t length;
size_t remain_local;
char *current_postion;
+ HANDLE events[2];
+
DBUG_ENTER("vio_read_shared_memory");
DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf,
size));
remain_local = size;
current_postion=buf;
+
+ events[0]= vio->event_server_wrote;
+ events[1]= vio->event_conn_closed;
+
do
{
if (vio->shared_memory_remain == 0)
{
- HANDLE events[2];
- events[0]= vio->event_server_wrote;
- events[1]= vio->event_conn_closed;
/*
WaitForMultipleObjects can return next values:
WAIT_OBJECT_0+0 - event from vio->event_server_wrote
@@ -500,7 +503,7 @@ size_t vio_read_shared_memory(Vio * vio, uchar* buf, size_t size)
anything
WAIT_ABANDONED_0 and WAIT_TIMEOUT - fail. We can't read anything
*/
- if (WaitForMultipleObjects(2, (HANDLE*)&events,FALSE,
+ if (WaitForMultipleObjects(array_elements(events), events, FALSE,
vio->net->read_timeout*1000) != WAIT_OBJECT_0)
{
DBUG_RETURN(-1);
@@ -543,17 +546,22 @@ size_t vio_write_shared_memory(Vio * vio, const uchar* buf, size_t size)
size_t length, remain, sz;
HANDLE pos;
const uchar *current_postion;
+ HANDLE events[2];
+
DBUG_ENTER("vio_write_shared_memory");
DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %d", vio->sd, (long) buf,
size));
remain = size;
current_postion = buf;
+
+ events[0]= vio->event_server_read;
+ events[1]= vio->event_conn_closed;
+
while (remain != 0)
{
- if (WaitForSingleObject(vio->event_server_read,
- vio->net->write_timeout*1000) !=
- WAIT_OBJECT_0)
+ if (WaitForMultipleObjects(array_elements(events), events, FALSE,
+ vio->net->write_timeout*1000) != WAIT_OBJECT_0)
{
DBUG_RETURN((size_t) -1);
}
diff --git a/vio/viosslfactories.c b/vio/viosslfactories.c
index 9ffe600beb8..6a6e08818c6 100644
--- a/vio/viosslfactories.c
+++ b/vio/viosslfactories.c
@@ -73,9 +73,28 @@ report_errors()
DBUG_VOID_RETURN;
}
+static const char*
+ssl_error_string[] =
+{
+ "No error",
+ "Unable to get certificate",
+ "Unable to get private key",
+ "Private key does not match the certificate public key"
+ "SSL_CTX_set_default_verify_paths failed",
+ "Failed to set ciphers to use",
+ "SSL_CTX_new failed"
+};
+
+const char*
+sslGetErrString(enum enum_ssl_init_error e)
+{
+ DBUG_ASSERT(SSL_INITERR_NOERROR < e && e < SSL_INITERR_LASTERR);
+ return ssl_error_string[e];
+}
static int
-vio_set_cert_stuff(SSL_CTX *ctx, const char *cert_file, const char *key_file)
+vio_set_cert_stuff(SSL_CTX *ctx, const char *cert_file, const char *key_file,
+ enum enum_ssl_init_error* error)
{
DBUG_ENTER("vio_set_cert_stuff");
DBUG_PRINT("enter", ("ctx: 0x%lx cert_file: %s key_file: %s",
@@ -84,9 +103,10 @@ vio_set_cert_stuff(SSL_CTX *ctx, const char *cert_file, const char *key_file)
{
if (SSL_CTX_use_certificate_file(ctx, cert_file, SSL_FILETYPE_PEM) <= 0)
{
- DBUG_PRINT("error",("unable to get certificate from '%s'", cert_file));
+ *error= SSL_INITERR_CERT;
+ DBUG_PRINT("error",("%s from file '%s'", sslGetErrString(*error), cert_file));
DBUG_EXECUTE("error", ERR_print_errors_fp(DBUG_FILE););
- fprintf(stderr, "SSL error: Unable to get certificate from '%s'\n",
+ fprintf(stderr, "SSL error: %s from '%s'\n", sslGetErrString(*error),
cert_file);
fflush(stderr);
DBUG_RETURN(1);
@@ -97,9 +117,10 @@ vio_set_cert_stuff(SSL_CTX *ctx, const char *cert_file, const char *key_file)
if (SSL_CTX_use_PrivateKey_file(ctx, key_file, SSL_FILETYPE_PEM) <= 0)
{
- DBUG_PRINT("error", ("unable to get private key from '%s'", key_file));
+ *error= SSL_INITERR_KEY;
+ DBUG_PRINT("error", ("%s from file '%s'", sslGetErrString(*error), key_file));
DBUG_EXECUTE("error", ERR_print_errors_fp(DBUG_FILE););
- fprintf(stderr, "SSL error: Unable to get private key from '%s'\n",
+ fprintf(stderr, "SSL error: %s from '%s'\n", sslGetErrString(*error),
key_file);
fflush(stderr);
DBUG_RETURN(1);
@@ -111,12 +132,10 @@ vio_set_cert_stuff(SSL_CTX *ctx, const char *cert_file, const char *key_file)
*/
if (!SSL_CTX_check_private_key(ctx))
{
- DBUG_PRINT("error",
- ("Private key does not match the certificate public key"));
+ *error= SSL_INITERR_NOMATCH;
+ DBUG_PRINT("error", ("%s",sslGetErrString(*error)));
DBUG_EXECUTE("error", ERR_print_errors_fp(DBUG_FILE););
- fprintf(stderr,
- "SSL error: "
- "Private key does not match the certificate public key\n");
+ fprintf(stderr, "SSL error: %s\n", sslGetErrString(*error));
fflush(stderr);
DBUG_RETURN(1);
}
@@ -229,7 +248,8 @@ static void check_ssl_init()
static struct st_VioSSLFd *
new_VioSSLFd(const char *key_file, const char *cert_file,
const char *ca_file, const char *ca_path,
- const char *cipher, SSL_METHOD *method)
+ const char *cipher, SSL_METHOD *method,
+ enum enum_ssl_init_error* error)
{
DH *dh;
struct st_VioSSLFd *ssl_fd;
@@ -251,7 +271,8 @@ new_VioSSLFd(const char *key_file, const char *cert_file,
if (!(ssl_fd->ssl_context= SSL_CTX_new(method)))
{
- DBUG_PRINT("error", ("SSL_CTX_new failed"));
+ *error= SSL_INITERR_MEMFAIL;
+ DBUG_PRINT("error", ("%s", sslGetErrString(*error)));
report_errors();
my_free((void*)ssl_fd,MYF(0));
DBUG_RETURN(0);
@@ -265,7 +286,8 @@ new_VioSSLFd(const char *key_file, const char *cert_file,
if (cipher &&
SSL_CTX_set_cipher_list(ssl_fd->ssl_context, cipher) == 0)
{
- DBUG_PRINT("error", ("failed to set ciphers to use"));
+ *error= SSL_INITERR_CIPHERS;
+ DBUG_PRINT("error", ("%s", sslGetErrString(*error)));
report_errors();
SSL_CTX_free(ssl_fd->ssl_context);
my_free((void*)ssl_fd,MYF(0));
@@ -278,7 +300,8 @@ new_VioSSLFd(const char *key_file, const char *cert_file,
DBUG_PRINT("warning", ("SSL_CTX_load_verify_locations failed"));
if (SSL_CTX_set_default_verify_paths(ssl_fd->ssl_context) == 0)
{
- DBUG_PRINT("error", ("SSL_CTX_set_default_verify_paths failed"));
+ *error= SSL_INITERR_BAD_PATHS;
+ DBUG_PRINT("error", ("%s", sslGetErrString(*error)));
report_errors();
SSL_CTX_free(ssl_fd->ssl_context);
my_free((void*)ssl_fd,MYF(0));
@@ -286,7 +309,7 @@ new_VioSSLFd(const char *key_file, const char *cert_file,
}
}
- if (vio_set_cert_stuff(ssl_fd->ssl_context, cert_file, key_file))
+ if (vio_set_cert_stuff(ssl_fd->ssl_context, cert_file, key_file, error))
{
DBUG_PRINT("error", ("vio_set_cert_stuff failed"));
report_errors();
@@ -314,6 +337,7 @@ new_VioSSLConnectorFd(const char *key_file, const char *cert_file,
{
struct st_VioSSLFd *ssl_fd;
int verify= SSL_VERIFY_PEER;
+ enum enum_ssl_init_error dummy;
/*
Turn off verification of servers certificate if both
@@ -323,7 +347,7 @@ new_VioSSLConnectorFd(const char *key_file, const char *cert_file,
verify= SSL_VERIFY_NONE;
if (!(ssl_fd= new_VioSSLFd(key_file, cert_file, ca_file,
- ca_path, cipher, TLSv1_client_method())))
+ ca_path, cipher, TLSv1_client_method(), &dummy)))
{
return 0;
}
@@ -344,12 +368,12 @@ new_VioSSLConnectorFd(const char *key_file, const char *cert_file,
struct st_VioSSLFd *
new_VioSSLAcceptorFd(const char *key_file, const char *cert_file,
const char *ca_file, const char *ca_path,
- const char *cipher)
+ const char *cipher, enum enum_ssl_init_error* error)
{
struct st_VioSSLFd *ssl_fd;
int verify= SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE;
if (!(ssl_fd= new_VioSSLFd(key_file, cert_file, ca_file,
- ca_path, cipher, TLSv1_server_method())))
+ ca_path, cipher, TLSv1_server_method(), error)))
{
return 0;
}