Skip to content

Commit

Permalink
SASL should only be used with the binary protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
Trond Norbye authored and dustin committed Oct 25, 2009
1 parent 7bad2d6 commit 991ea27
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
13 changes: 13 additions & 0 deletions memcached.c
Expand Up @@ -4214,6 +4214,7 @@ int main (int argc, char **argv) {

/* udp socket */
static int *u_socket = NULL;
bool protocol_specified = false;

/* handle SIGINT */
signal(SIGINT, sig_handler);
Expand Down Expand Up @@ -4362,6 +4363,7 @@ int main (int argc, char **argv) {
settings.backlog = atoi(optarg);
break;
case 'B':
protocol_specified = true;
if (strcmp(optarg, "auto") == 0) {
settings.binding_protocol = negotiating_prot;
} else if (strcmp(optarg, "binary") == 0) {
Expand Down Expand Up @@ -4417,6 +4419,17 @@ int main (int argc, char **argv) {
}
}

if (settings.sasl) {
if (!protocol_specified) {
settings.binding_protocol = binary_prot;
} else {
if (settings.binding_protocol != binary_prot) {
fprintf(stderr, "WARNING: You shouldn't allow the ASCII protocol while using SASL\n");
exit(EX_USAGE);
}
}
}

if (maxcore != 0) {
struct rlimit rlim_new;
/*
Expand Down
17 changes: 16 additions & 1 deletion t/binary-sasl.t
Expand Up @@ -12,7 +12,7 @@ my $supports_sasl = supports_sasl();
use Test::More;

if (supports_sasl()) {
plan tests => 20;
plan tests => 23;
} else {
plan tests => 1;
eval {
Expand All @@ -22,6 +22,21 @@ if (supports_sasl()) {
exit 0;
}

eval {
my $server = new_memcached("-S -B auto");
};
ok($@, "SASL shouldn't be used with protocol auto negotiate");

eval {
my $server = new_memcached("-S -B ascii");
};
ok($@, "SASL isn't implemented in the ascii protocol");

eval {
my $server = new_memcached("-S -B binary -B ascii");
};
ok($@, "SASL isn't implemented in the ascii protocol");

# Based almost 100% off testClient.py which is:
# Copyright (c) 2007 Dustin Sallings <dustin@spy.net>

Expand Down

0 comments on commit 991ea27

Please sign in to comment.