From 1206f4572b4b3bb405a14cc60605b75d53b819a0 Mon Sep 17 00:00:00 2001 From: Laurent Alebarde Date: Tue, 17 Sep 2013 12:47:21 +0200 Subject: [PATCH] oblige the application to explicitely set the node type for PLAIN --- include/zmq.h | 4 ++-- src/options.cpp | 16 +++++++--------- tests/test_security_curve.cpp | 4 ++-- tests/test_security_plain.cpp | 9 ++++++--- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/include/zmq.h b/include/zmq.h index baaff432..f80c26af 100644 --- a/include/zmq.h +++ b/include/zmq.h @@ -269,10 +269,10 @@ ZMQ_EXPORT int zmq_msg_set (zmq_msg_t *msg, int option, int optval); #define ZMQ_ROUTER_RAW 41 #define ZMQ_IPV6 42 #define ZMQ_MECHANISM 43 -#define ZMQ_PLAIN_SERVER 44 +#define ZMQ_PLAIN_NODE 44 #define ZMQ_PLAIN_USERNAME 45 #define ZMQ_PLAIN_PASSWORD 46 -#define ZMQ_CURVE_SERVER 47 +#define ZMQ_CURVE_NODE 47 #define ZMQ_CURVE_OUR_PERMA_PUB_KEY 48 #define ZMQ_CURVE_OUR_PERMA_SEC_KEY 49 #define ZMQ_CURVE_PEER_PERMA_PUB_KEY 50 diff --git a/src/options.cpp b/src/options.cpp index d5bba9ce..687d79d7 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -275,10 +275,10 @@ int zmq::options_t::setsockopt (int option_, const void *optval_, } break; - case ZMQ_PLAIN_SERVER: - if (is_int && (value == 0 || value == 1)) { + case ZMQ_PLAIN_NODE: + if (is_int && (value == ZMQ_CLIENT || value == ZMQ_SERVER)) { as_server = value; - mechanism = value? ZMQ_PLAIN: ZMQ_NULL; + mechanism = ZMQ_PLAIN; return 0; } break; @@ -291,7 +291,6 @@ int zmq::options_t::setsockopt (int option_, const void *optval_, else if (optvallen_ > 0 && optvallen_ < 256 && optval_ != NULL) { plain_username.assign ((const char *) optval_, optvallen_); - as_server = 0; mechanism = ZMQ_PLAIN; return 0; } @@ -305,7 +304,6 @@ int zmq::options_t::setsockopt (int option_, const void *optval_, else if (optvallen_ > 0 && optvallen_ < 256 && optval_ != NULL) { plain_password.assign ((const char *) optval_, optvallen_); - as_server = 0; mechanism = ZMQ_PLAIN; return 0; } @@ -320,7 +318,7 @@ int zmq::options_t::setsockopt (int option_, const void *optval_, // If libsodium isn't installed, these options provoke EINVAL # ifdef HAVE_LIBSODIUM - case ZMQ_CURVE_SERVER: + case ZMQ_CURVE_NODE: if (is_int && (value == ZMQ_CLIENT || value == ZMQ_SERVER)) { as_server = value; mechanism = ZMQ_CURVE; @@ -542,9 +540,9 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_) } break; - case ZMQ_PLAIN_SERVER: + case ZMQ_PLAIN_NODE: if (is_int) { - *value = as_server && mechanism == ZMQ_PLAIN; + *value = as_server; return 0; } break; @@ -575,7 +573,7 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_) // If libsodium isn't installed, these options provoke EINVAL # ifdef HAVE_LIBSODIUM - case ZMQ_CURVE_SERVER: + case ZMQ_CURVE_NODE: if (is_int) { *value = as_server; return 0; diff --git a/tests/test_security_curve.cpp b/tests/test_security_curve.cpp index b8b16c4d..436345e3 100644 --- a/tests/test_security_curve.cpp +++ b/tests/test_security_curve.cpp @@ -103,7 +103,7 @@ int main (void) void *server = zmq_socket (ctx, ZMQ_DEALER); assert (server); int as_server = ZMQ_SERVER; - rc = zmq_setsockopt (server, ZMQ_CURVE_SERVER, &as_server, sizeof (int)); + rc = zmq_setsockopt (server, ZMQ_CURVE_NODE, &as_server, sizeof (int)); assert (rc == 0); rc = zmq_setsockopt (server, ZMQ_CURVE_OUR_PERMA_SEC_KEY, server_secret, 40); assert (rc == 0); @@ -116,7 +116,7 @@ int main (void) void *client = zmq_socket (ctx, ZMQ_DEALER); assert (client); as_server = ZMQ_CLIENT; - rc = zmq_setsockopt (client, ZMQ_CURVE_SERVER, &as_server, sizeof (int)); + rc = zmq_setsockopt (client, ZMQ_CURVE_NODE, &as_server, sizeof (int)); assert (rc == 0); rc = zmq_setsockopt (client, ZMQ_CURVE_PEER_PERMA_PUB_KEY, server_public, 40); assert (rc == 0); diff --git a/tests/test_security_plain.cpp b/tests/test_security_plain.cpp index 99748d45..8522d593 100644 --- a/tests/test_security_plain.cpp +++ b/tests/test_security_plain.cpp @@ -87,8 +87,8 @@ int main (void) assert (server); int rc = zmq_setsockopt (server, ZMQ_IDENTITY, "IDENT", 6); assert (rc == 0); - int as_server = 1; - rc = zmq_setsockopt (server, ZMQ_PLAIN_SERVER, &as_server, sizeof (int)); + int as_server = ZMQ_SERVER; + rc = zmq_setsockopt (server, ZMQ_PLAIN_NODE, &as_server, sizeof (int)); assert (rc == 0); rc = zmq_bind (server, "tcp://*:9998"); assert (rc == 0); @@ -99,6 +99,9 @@ int main (void) // Check PLAIN security with correct username/password void *client = zmq_socket (ctx, ZMQ_DEALER); assert (client); + as_server = ZMQ_CLIENT; + rc = zmq_setsockopt (server, ZMQ_PLAIN_NODE, &as_server, sizeof (int)); + assert (rc == 0); strcpy (username, "admin"); rc = zmq_setsockopt (client, ZMQ_PLAIN_USERNAME, username, strlen (username)); assert (rc == 0); @@ -116,7 +119,7 @@ int main (void) client = zmq_socket (ctx, ZMQ_DEALER); assert (client); as_server = 1; - rc = zmq_setsockopt (client, ZMQ_PLAIN_SERVER, &as_server, sizeof (int)); + rc = zmq_setsockopt (client, ZMQ_PLAIN_NODE, &as_server, sizeof (int)); assert (rc == 0); rc = zmq_connect (client, "tcp://localhost:9998"); assert (rc == 0);