Commit 1206f457 authored by Laurent Alebarde's avatar Laurent Alebarde

oblige the application to explicitely set the node type for PLAIN

parent bfd472f9
......@@ -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
......
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment