diff --git a/memcached.c b/memcached.c index 8d4c3d760b..b121e161ac 100644 --- a/memcached.c +++ b/memcached.c @@ -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) { diff --git a/sasl_defs.c b/sasl_defs.c index 0f405d0253..7922f66b48 100644 --- a/sasl_defs.c +++ b/sasl_defs.c @@ -5,6 +5,8 @@ #include #include +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 @@ -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); diff --git a/sasl_defs.h b/sasl_defs.h index 65f8d80521..f36c694432 100644 --- a/sasl_defs.h +++ b/sasl_defs.h @@ -9,6 +9,8 @@ #include void init_sasl(void); +extern char my_sasl_hostname[1025]; + #else /* End of SASL support */ typedef void* sasl_conn_t;