Hi All, I am new to memcached and have started working on it for the past couple weeks. *My use case is creating a SASL enabled client and successfully get/set into memcache server using authentication.*
I have enabled SASL and enabled SASL-PWDB in the brew install itself:
brew install memcached --enable-sasl --enable-sasl-pwdb
I have written a simple memcached client using libmemcached which looks
like this: (Using: memcached_set_sasl_auth_data)
/*
* Test that libmemcached is built with SASL support.
*/
#include <stdio.h>
#include <string.h>
#include <libmemcached/memcached.h>
const char* key = "abc";
const char* value = "value";
// test basic get/set operation works.
void test_getset(memcached_st* cache)
{
char* r_value;
uint32_t flags = 0;
uint32_t r_flags = 0;
size_t val_length;
memcached_return_t rc;
rc = memcached_set(cache, key, strlen(key), value, strlen(value),
(time_t)0, flags);
if (rc == MEMCACHED_TIMEOUT) {
fprintf(stderr, "Set timeout\n");
return;
} else if (rc != MEMCACHED_SUCCESS) {
fprintf(stderr, "Set failed: %s\n", memcached_strerror(cache, rc));
return;
}
r_value = memcached_get(cache, key, strlen(key), &val_length, &r_flags,
&rc);
if (rc == MEMCACHED_TIMEOUT) {
fprintf(stderr, "Get timeout\n");
return;
} else if (rc != MEMCACHED_SUCCESS) {
fprintf(stderr, "Get failed: %s\n", memcached_strerror(cache, rc));
return;
}
if (strcmp(value, r_value) != 0) {
fprintf(stderr, "Get returned bad value! (%s != %s)!\n", value,
r_value);
}
if (r_flags != flags) {
fprintf(stderr, "Get returned bad flags! (%u != %u)!\n", flags,
r_flags);
}
fprintf(stdout, "Get/Set success!\n");
}
// connect with SASL.
void authTest(const char* user, const char* pass, const char* server)
{
memcached_server_st *servers = NULL;
memcached_return_t rc;
memcached_st *cache;
cache = memcached_create(NULL);
rc = memcached_set_sasl_auth_data(cache, user, pass);
if (rc != MEMCACHED_SUCCESS)
fprintf(stderr, "Couldn't setup SASL auth: %s\n",
memcached_strerror(cache, rc));
rc = memcached_behavior_set(cache, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
if (rc != MEMCACHED_SUCCESS)
fprintf(stderr, "Couldn't use the binary protocol: %s\n",
memcached_strerror(cache, rc));
rc = memcached_behavior_set(cache, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT,
10000);
if (rc != MEMCACHED_SUCCESS)
fprintf(stderr, "Couldn't set the connect timeout: %s\n",
memcached_strerror(cache, rc));
servers = memcached_server_list_append(servers, "localhost", 11211, &rc);
rc = memcached_server_push(cache, servers);
if (rc != MEMCACHED_SUCCESS)
fprintf(stderr, "Couldn't add server: %s\n", memcached_strerror(cache,
rc));
test_getset(cache);
memcached_free(cache);
}
// start program.
int main(int argv, char *args[])
{
if (argv != 4) {
fprintf(stderr, "ERROR: usage => %s [username] [password] [server]\n",
args[0]);
return 1;
}
authTest(args[1], args[2], args[3]);
return 0;
}
Now when I run the memcached server using:
memcached -S -vv
and then try to run my client, I get the following error on the server:
OKALE-M-33H5:memcached-1.5.7 okale$ ./memcached -S -v
Reading configuration from:
</Users/okale/Library/Caches/Homebrew/memcached-1.5.7/memcached.conf>
Initialized SASL.
mech: ``SRP'' with 15 bytes of data
SASL (severity 2): no secret in database
sasl result code: -4
Unknown sasl response: -4
On the client side, I see the following:
OKALE-M-33H5:mycode okale$ ./testsasl ok hello localhost
Set failed: AUTHENTICATION FAILURE
OKALE-M-33H5:mycode okale$
I have added my username, password in a file called memcached-sasl-pwdb
which is located at
/Users/okale/Library/Caches/Homebrew/memcached-1.5.7/memcached-sasl-pwdb
OKALE-M-33H5:memcached-1.5.7 okale$ cat memcached-sasl-pwdb
ok:hello
My memcached.conf located at
/Users/okale/Library/Caches/Homebrew/memcached-1.5.7/memcached.conf and
contains:
OKALE-M-33H5:memcached-1.5.7 okale$ cat memcached.conf
mech_list: plain
I have a couple of questions:
1. How can the memcached server on start up know the configured users and
the username:password details. (Does it read it from memcached-sasl-pwdb?
If yes, how do I configure it/point to it?)
2. What's the use of the memcached.conf file in the "Reading configuration
from:
</Users/okale/Library/Caches/Homebrew/memcached-1.5.7/memcached.conf>" in
the output. I am presuming this read will tell the memcached server the
username:password details. If yes, what should be the location of this file
3. Do I need to install/point to any additional ssl libraries during server
bring up?
Please refer attachment for the verbose memcached server log.
Help will be much appreciated.
Thanks and Regards,
Om Kale
--
---
You received this message because you are subscribed to the Google Groups
"memcached" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
memcachedserververbose.rtf
Description: RTF file
