set(ENABLE_SANITIZERS ""
CACHE STRING "sanitizers to enable (e.g. address undefined ...)")
+set(MEMCACHED_BINARY "/usr/bin/memcached"
+ CACHE FILEPATH "memcached binary")
+
# sasl
set(ENABLE_SASL OFF
#include "libmemcached/common.h"
#include <cassert>
+#include <atomic>
#if defined(LIBMEMCACHED_WITH_SASL_SUPPORT) && LIBMEMCACHED_WITH_SASL_SUPPORT
sasl_done();
}
-static volatile int sasl_startup_state= SASL_OK;
+static std::atomic<int> sasl_startup_state(SASL_OK);
pthread_mutex_t sasl_startup_state_LOCK= PTHREAD_MUTEX_INITIALIZER;
static pthread_once_t sasl_startup_once= PTHREAD_ONCE_INIT;
static void sasl_startup_function(void)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tmp_chroot)
-file(GENERATE OUTPUT ${CMAKE_BINARY_DIR}/libtool CONTENT
+file(WRITE ${CMAKE_BINARY_DIR}/libtool
"#!/bin/bash
shift
exec $@
")
if(UNIX)
- if (EXISTS ${CMAKE_BINARY_DIR}/libtool)
+ if(EXISTS ${CMAKE_BINARY_DIR}/libtool)
execute_process(COMMAND chmod +x ${CMAKE_BINARY_DIR}/libtool)
endif()
endif()
DRIZZLED_BINARY=\"drizzled\"
GEARMAND_BINARY=\"gearmand\"
- MEMCACHED_BINARY=\"/usr/bin/memcached\"
+ MEMCACHED_BINARY=\"${MEMCACHED_BINARY}\"
HAVE_MEMCACHED_BINARY=1
)
target_link_libraries(libtest PRIVATE Threads::Threads ${CMAKE_DL_LIBS})
}
else
{
- spawn_ret= posix_spawn(&_pid, built_argv[0], &file_actions, &spawnattr, &built_argv[0], NULL);
+ spawn_ret= posix_spawn(&_pid, built_argv[0], &file_actions, &spawnattr, &built_argv[0], environ);
}
posix_spawn_file_actions_destroy(&file_actions);
bool has_libmemcached_sasl(void)
{
+#ifdef LIBMEMCACHED_WITH_SASL_SUPPORT
+ return LIBMEMCACHED_WITH_SASL_SUPPORT;
+#else
return false;
+#endif
}
bool has_libmemcached(void)
virtual const char *sasl() const
{
- return NULL;
+ return "-S";
+ }
+
+ bool is_sasl() const
+ {
+ return _username.size() && _password.size();
}
const std::string& password() const
return false;
}
- if (is_socket())
+ if (is_socket() or is_sasl())
{
return _app.check();
}
char buffer[30];
snprintf(buffer, sizeof(buffer), "%d", int(arg));
app.add_option("-p", buffer);
- app.add_option("-U", buffer);
+
+ if(!is_sasl())
+ {
+ app.add_option("-U", buffer);
+ }
}
bool has_port_option() const
add_option("-M");
#endif
- if (sasl())
+ if (is_sasl())
{
add_option(sasl());
}
- //add_option("-vv");
+ //add_option("-vvv");
return true;
}
return NULL;
}
+libtest::Server *build_memcached_sasl(const std::string &hostname, const in_port_t try_port, const std::string &username, const std::string &password)
+{
+ if (has_memcached())
+ {
+ return new Memcached(hostname, try_port, false, username, password);
+ }
+
+ return NULL;
+}
+
} // namespace libtest
libtest::Server *build_memcached_socket(const std::string& socket_file, const in_port_t try_port);
+libtest::Server *build_memcached_sasl(const std::string &hostname, const in_port_t try_port, const std::string &username, const std::string &password);
+
}
server= build_memcached("localhost", try_port);
}
}
+ else if (server_type == "memcached-sasl")
+ {
+ server = build_memcached_sasl("localhost", try_port, _username, _password);
+ }
return server;
}
install(FILES libmemcached.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
+
+if(BUILD_TESTING)
+ set(LIBMEMCACHED_WITH_SASL_PWDB "MEMCACHED_SASL_PWDB=${CMAKE_CURRENT_BINARY_DIR}/memcached.pwdb" PARENT_SCOPE)
+ set(LIBMEMCACHED_WITH_SASL_CONF "SASL_CONF_PATH=${CMAKE_CURRENT_BINARY_DIR}" PARENT_SCOPE)
+
+ cmake_host_system_information(RESULT HOSTNAME QUERY HOSTNAME)
+ configure_file(memcached.pwdb.in memcached.pwdb @ONLY)
+ configure_file(memcached.conf.in memcached.conf @ONLY)
+endif()
--- /dev/null
+mech_list: plain
+log_level: 7
--- /dev/null
+memcached@@HOSTNAME@:memcached
static test_return_t pre_sasl(memcached_st *)
{
- SKIP_IF(true);
-#if 0
- SKIP_IF_(true, "currently we are not testing sasl support");
-#endif
SKIP_IF(LIBMEMCACHED_WITH_SASL_SUPPORT == 0);
return TEST_SUCCESS;
#include "tests/libmemcached_test_container.h"
+static char *sasl_pwdb = const_cast<char *>(LIBMEMCACHED_WITH_SASL_PWDB);
+static char *sasl_conf = const_cast<char *>(LIBMEMCACHED_WITH_SASL_CONF);
+
static void *world_create(libtest::server_startup_st& servers, test_return_t& error)
{
SKIP_UNLESS(libtest::has_libmemcached());
error= TEST_SKIPPED;
return NULL;
}
+
+ // provide conf and pwdb to memcached binary
+ putenv(sasl_pwdb);
+ putenv(sasl_conf);
}
for (uint32_t x= 0; x < servers.servers_to_run(); x++)