Skip to content

Commit

Permalink
Specify hostname in sasl_server_new.
Browse files Browse the repository at this point in the history
saslpasswd2 does something a little magical when initializing the
structure that's different from what happens if you just pass NULL.

The magic is too great for the tests as is, so this code does the same
thing saslpasswd2 does to determine the fqdn.
  • Loading branch information
dustin committed Jan 28, 2012
1 parent 39d59a9 commit b0a858c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,9 @@ static void init_sasl_conn(conn *c) {

if (!c->sasl_conn) {
int result=sasl_server_new("memcached",
NULL, NULL, NULL, NULL,
NULL,
my_sasl_hostname[0] ? my_sasl_hostname : NULL,
NULL, NULL,
NULL, 0, &c->sasl_conn);
if (result != SASL_OK) {
if (settings.verbose) {
Expand Down
10 changes: 10 additions & 0 deletions sasl_defs.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <string.h>
#include <sasl/saslplug.h>

char my_sasl_hostname[1025];

#ifdef HAVE_SASL_CB_GETCONF
/* The locations we may search for a SASL config file if the user didn't
* specify one in the environment variable SASL_CONF_PATH
Expand Down Expand Up @@ -169,6 +171,14 @@ void init_sasl(void) {
}
#endif

memset(my_sasl_hostname, 0, sizeof(my_sasl_hostname));
if (gethostname(my_sasl_hostname, sizeof(my_sasl_hostname)-1) == -1) {
if (settings.verbose) {
fprintf(stderr, "Error discovering hostname for SASL\n");
}
my_sasl_hostname[0] = '\0';
}

if (sasl_server_init(sasl_callbacks, "memcached") != SASL_OK) {
fprintf(stderr, "Error initializing sasl.\n");
exit(EXIT_FAILURE);
Expand Down
2 changes: 2 additions & 0 deletions sasl_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <sasl/sasl.h>
void init_sasl(void);

extern char my_sasl_hostname[1025];

#else /* End of SASL support */

typedef void* sasl_conn_t;
Expand Down

0 comments on commit b0a858c

Please sign in to comment.