From 22eb4d600b237cee894c7f32c6cdc8d5594fb9e3 Mon Sep 17 00:00:00 2001 From: Pieter Hintjens Date: Tue, 17 Sep 2013 14:05:41 +0200 Subject: [PATCH] Revert "oblige the application to explicitely set the node type for PLAIN" This reverts commit 1206f4572b4b3bb405a14cc60605b75d53b819a0. --- include/zmq.h | 4 ++-- src/options.cpp | 16 +++++++++------- tests/test_security_curve.cpp | 4 ++-- tests/test_security_plain.cpp | 9 +++------ 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/include/zmq.h b/include/zmq.h index f80c26af..baaff432 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_NODE 44 +#define ZMQ_PLAIN_SERVER 44 #define ZMQ_PLAIN_USERNAME 45 #define ZMQ_PLAIN_PASSWORD 46 -#define ZMQ_CURVE_NODE 47 +#define ZMQ_CURVE_SERVER 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 687d79d7..d5bba9ce 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_NODE: - if (is_int && (value == ZMQ_CLIENT || value == ZMQ_SERVER)) { + case ZMQ_PLAIN_SERVER: + if (is_int && (value == 0 || value == 1)) { as_server = value; - mechanism = ZMQ_PLAIN; + mechanism = value? ZMQ_PLAIN: ZMQ_NULL; return 0; } break; @@ -291,6 +291,7 @@ 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; } @@ -304,6 +305,7 @@ 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; } @@ -318,7 +320,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_NODE: + case ZMQ_CURVE_SERVER: if (is_int && (value == ZMQ_CLIENT || value == ZMQ_SERVER)) { as_server = value; mechanism = ZMQ_CURVE; @@ -540,9 +542,9 @@ int zmq::options_t::getsockopt (int option_, void *optval_, size_t *optvallen_) } break; - case ZMQ_PLAIN_NODE: + case ZMQ_PLAIN_SERVER: if (is_int) { - *value = as_server; + *value = as_server && mechanism == ZMQ_PLAIN; return 0; } break; @@ -573,7 +575,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_NODE: + case ZMQ_CURVE_SERVER: if (is_int) { *value = as_server; return 0; diff --git a/tests/test_security_curve.cpp b/tests/test_security_curve.cpp index 436345e3..b8b16c4d 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_NODE, &as_server, sizeof (int)); + rc = zmq_setsockopt (server, ZMQ_CURVE_SERVER, &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_NODE, &as_server, sizeof (int)); + rc = zmq_setsockopt (client, ZMQ_CURVE_SERVER, &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 8522d593..99748d45 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 = ZMQ_SERVER; - rc = zmq_setsockopt (server, ZMQ_PLAIN_NODE, &as_server, sizeof (int)); + int as_server = 1; + rc = zmq_setsockopt (server, ZMQ_PLAIN_SERVER, &as_server, sizeof (int)); assert (rc == 0); rc = zmq_bind (server, "tcp://*:9998"); assert (rc == 0); @@ -99,9 +99,6 @@ 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); @@ -119,7 +116,7 @@ int main (void) client = zmq_socket (ctx, ZMQ_DEALER); assert (client); as_server = 1; - rc = zmq_setsockopt (client, ZMQ_PLAIN_NODE, &as_server, sizeof (int)); + rc = zmq_setsockopt (client, ZMQ_PLAIN_SERVER, &as_server, sizeof (int)); assert (rc == 0); rc = zmq_connect (client, "tcp://localhost:9998"); assert (rc == 0);