├── protocol ├── mcbp │ ├── CMakeLists.txt │ ├── README.md │ └── libmcbp │ │ └── CMakeLists.txt ├── CMakeLists.txt └── connection │ └── CMakeLists.txt ├── tests ├── cert │ ├── client.p12 │ ├── client.key │ ├── parse-test.key │ ├── testapp.pem │ ├── testapp.cert │ ├── client.pem │ └── parse-test.pem ├── event │ └── CMakeLists.txt ├── function_chain │ └── CMakeLists.txt ├── privilege_test │ └── CMakeLists.txt ├── topkeys │ ├── CMakeLists.txt │ └── topkeys_bench.cc ├── engine_error │ └── CMakeLists.txt ├── error_map_sanity_check │ ├── CMakeLists.txt │ └── error_map_sanity_check.cc ├── sizes │ ├── CMakeLists.txt │ └── sizes.cc ├── cbsasl_strcmp_test │ └── CMakeLists.txt ├── config_util_test │ └── CMakeLists.txt ├── doc_server_api │ └── CMakeLists.txt ├── scripts_tests │ ├── jemalloc_allocator_stats.cc │ ├── CMakeLists.txt │ └── runtests.cmake ├── cbcrypto_test │ └── CMakeLists.txt ├── saslprep │ └── CMakeLists.txt ├── cbsasl_client_server_test │ └── CMakeLists.txt ├── cbsasl_server_tests │ └── CMakeLists.txt ├── datatype │ └── CMakeLists.txt ├── executor │ └── CMakeLists.txt ├── CMakeLists.txt ├── cbnt_tests │ ├── readme.md │ └── cbnt_test_list.yml ├── testapp │ ├── testapp_arithmetic.h │ ├── testapp_bucket.h │ ├── testapp_stats.h │ ├── ssl_impl.h │ ├── testapp_sasl.h │ ├── saslauthd_mock.h │ └── generate_test_cbsaslpw.cc ├── ssl_cert_test │ └── CMakeLists.txt ├── config_parse_test │ └── CMakeLists.txt ├── cbsasl_password_database_test │ └── CMakeLists.txt ├── logger_test │ ├── CMakeLists.txt │ └── logger_test_common.h ├── mcbp │ ├── CMakeLists.txt │ └── mcbp_test.h ├── memory_tracking_test │ ├── CMakeLists.txt │ └── memory_tracking_plugin.cc └── cbsasl_pwconv_test │ └── CMakeLists.txt ├── extensions ├── CMakeLists.txt ├── protocol │ └── CMakeLists.txt ├── daemon │ └── CMakeLists.txt ├── protocol_extension.h └── loggers │ ├── CMakeLists.txt │ ├── file_logger_utilities.h │ ├── blackhole_logger.cc │ └── file_logger_utilities.cc ├── etc ├── CMakeLists.txt ├── greenstack.ex.json └── memcached.ex.json ├── support-files ├── CMakeLists.txt └── smf │ ├── CMakeLists.txt │ └── couchbase.in ├── programs ├── mclogsplit │ └── CMakeLists.txt ├── moxi_hammer │ └── CMakeLists.txt ├── mcstat │ └── CMakeLists.txt ├── mcctl │ └── CMakeLists.txt ├── mctimings │ └── CMakeLists.txt ├── cbtrace │ ├── CMakeLists.txt │ └── memorymap.h ├── cbsasladm │ └── CMakeLists.txt ├── CMakeLists.txt ├── engine_testapp │ └── CMakeLists.txt └── hostname_utils.h ├── engines ├── crash_engine │ └── CMakeLists.txt ├── CMakeLists.txt ├── nobucket │ ├── CMakeLists.txt │ └── nobucket.h ├── ewouldblock_engine │ └── CMakeLists.txt ├── utilities │ └── CMakeLists.txt ├── default_engine.h └── default_engine │ ├── CMakeLists.txt │ └── assoc.h ├── auditd ├── CMakeLists.txt ├── etc │ ├── kv_commit_validation_module_descriptors.json │ ├── example_descriptor.json │ ├── module_descriptors.json │ └── auditd_descriptor.json ├── src │ ├── CMakeLists.txt │ ├── configureevent.h │ ├── configureevent.cc │ ├── event.h │ └── auditd.h └── generator │ └── CMakeLists.txt ├── testsuite ├── basic │ ├── CMakeLists.txt │ └── basic_engine_testsuite.h ├── CMakeLists.txt └── breakdancer │ ├── disable_optimize.h │ ├── suite_stubs.h │ └── CMakeLists.txt ├── daemon ├── cmdline.h ├── alloc_hooks.h ├── config_util.h ├── libevent_locking.h ├── memcached_openssl.h ├── mcbp_topkeys.h ├── ssl_utils.h ├── alloc_hooks_types.h ├── breakpad_dummy.cc ├── doc_pre_expiry.h ├── alloc_hooks_dummy.h ├── alloc_hooks_jemalloc.h ├── mc_time.h ├── protocol │ └── mcbp │ │ ├── dcp_add_failover_log.h │ │ ├── utilities.cc │ │ ├── dcp_deletion.h │ │ ├── dcp_expiration.h │ │ ├── unlock_context.cc │ │ ├── command_context.h │ │ ├── engine_errc_2_mcbp.h │ │ ├── dcp_set_vbucket_state_executor.cc │ │ ├── dcp_close_stream_executor.cc │ │ ├── collections_set_manifest_executor.cc │ │ ├── dcp_flush_executor.cc │ │ ├── dcp_add_failover_log.cc │ │ └── dcp_noop_executor.cc ├── net_buf.h ├── task.cc ├── alloc_hooks.def ├── breakpad.h ├── libevent_locking.cc ├── runtime.h ├── timing_interval.cc ├── cookie.cc ├── main.cc ├── executorpool.cc ├── darwin_zone.h ├── ssl_utils.cc ├── config_parse.h ├── mcbp_executors.h ├── ioctl.h ├── parent_monitor.h ├── dynamic_buffer.cc ├── mcbpdestroybuckettask.h └── subdocument.h ├── include ├── CMakeLists.txt ├── memcached │ ├── visibility.h │ ├── extension_loggers.h │ ├── vbucket.h │ ├── rbac.h │ ├── util.h │ ├── syslog.h │ ├── events.h │ ├── collections.h │ ├── openssl.h │ └── config_parser.h ├── mcbp │ ├── protocol │ │ ├── datatype.h │ │ └── magic.h │ └── mcbp.h └── cbsasl │ ├── visibility.h │ └── saslauthd_config.h ├── cbsasl ├── CMakeLists.txt ├── util.h ├── pwfile.h ├── strcmp.cc ├── plain │ ├── check_password.h │ └── plain.h ├── saslauthd_config.cc ├── strerror.cc ├── common.cc ├── log.cc └── scram-sha │ └── stringutils.h ├── utilities ├── protocol2text.h ├── CMakeLists.txt └── terminate_handler.h ├── time ├── CMakeLists.txt └── timestamp_test.cc ├── .mailmap ├── xattr └── CMakeLists.txt ├── rbac └── CMakeLists.txt ├── .gitignore ├── cbcrypto └── CMakeLists.txt ├── README.md ├── CONTRIBUTING.md ├── COPYING └── LICENSE /protocol/mcbp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_SUBDIRECTORY(libmcbp) 2 | -------------------------------------------------------------------------------- /protocol/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_SUBDIRECTORY(mcbp) 2 | ADD_SUBDIRECTORY(connection) 3 | -------------------------------------------------------------------------------- /tests/cert/client.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/couchbase/memcached/HEAD/tests/cert/client.p12 -------------------------------------------------------------------------------- /extensions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_SUBDIRECTORY(daemon) 2 | ADD_SUBDIRECTORY(loggers) 3 | ADD_SUBDIRECTORY(protocol) 4 | -------------------------------------------------------------------------------- /etc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(COPY memcached.ex.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) 2 | install(DIRECTORY error_maps DESTINATION etc) 3 | -------------------------------------------------------------------------------- /support-files/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | IF (CMAKE_SYSTEM_NAME MATCHES "SunOS") 2 | ADD_SUBDIRECTORY(smf) 3 | ENDIF (CMAKE_SYSTEM_NAME MATCHES "SunOS") 4 | -------------------------------------------------------------------------------- /programs/mclogsplit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(mclogsplit mclogsplit.cc) 2 | target_link_libraries(mclogsplit dirutils) 3 | install(TARGETS mclogsplit RUNTIME DESTINATION bin) 4 | -------------------------------------------------------------------------------- /tests/event/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(eventtest event.cc) 2 | TARGET_LINK_LIBRARIES(eventtest platform ${LIBEVENT_LIBRARIES} 3 | ${COUCHBASE_NETWORK_LIBS}) 4 | -------------------------------------------------------------------------------- /engines/crash_engine/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_LIBRARY(crash_engine SHARED crash_engine.cc) 2 | SET_TARGET_PROPERTIES(crash_engine PROPERTIES PREFIX "") 3 | TARGET_LINK_LIBRARIES(crash_engine engine_utilities platform) 4 | -------------------------------------------------------------------------------- /auditd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | INCLUDE_DIRECTORIES(BEFORE ${Platform_SOURCE_DIR}/include 2 | ${Memcached_BINARY_DIR}/auditd) 3 | 4 | ADD_SUBDIRECTORY(generator) 5 | ADD_SUBDIRECTORY(src) 6 | ADD_SUBDIRECTORY(tests) 7 | 8 | -------------------------------------------------------------------------------- /extensions/protocol/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_LIBRARY(testapp_extension SHARED testapp_extension.cc) 2 | SET_TARGET_PROPERTIES(testapp_extension PROPERTIES PREFIX "") 3 | TARGET_LINK_LIBRARIES(testapp_extension mcd_util platform ${COUCHBASE_NETWORK_LIBS}) 4 | -------------------------------------------------------------------------------- /programs/moxi_hammer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(moxi_hammer moxi_hammer.cc) 2 | target_link_libraries(moxi_hammer 3 | platform 4 | ${LIBEVENT_LIBRARIES} 5 | ${COUCHBASE_NETWORK_LIBS}) 6 | -------------------------------------------------------------------------------- /testsuite/basic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_LIBRARY(basic_engine_testsuite SHARED basic_engine_testsuite.cc) 2 | SET_TARGET_PROPERTIES(basic_engine_testsuite PROPERTIES PREFIX "") 3 | TARGET_LINK_LIBRARIES(basic_engine_testsuite mcd_util platform ${COUCHBASE_NETWORK_LIBS}) 4 | -------------------------------------------------------------------------------- /programs/mcstat/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(mcstat mcstat.cc) 2 | TARGET_LINK_LIBRARIES(mcstat 3 | platform 4 | mcutils 5 | mc_client_connection) 6 | INSTALL(TARGETS mcstat RUNTIME DESTINATION bin) 7 | -------------------------------------------------------------------------------- /engines/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # utilities must be first because other the engines may want to use it 2 | ADD_SUBDIRECTORY(utilities) 3 | 4 | ADD_SUBDIRECTORY(crash_engine) 5 | ADD_SUBDIRECTORY(default_engine) 6 | ADD_SUBDIRECTORY(ewouldblock_engine) 7 | ADD_SUBDIRECTORY(nobucket) 8 | -------------------------------------------------------------------------------- /daemon/cmdline.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | #ifndef DAEMON_CMDLINE_H 3 | #define DAEMON_CMDLINE_H 1 4 | 5 | void parse_arguments(int argc, char **argv); 6 | 7 | const char* get_config_file(void); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /programs/mcctl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(mcctl mcctl.cc) 2 | TARGET_LINK_LIBRARIES(mcctl 3 | mc_client_connection 4 | mcd_util 5 | mcutils 6 | platform) 7 | INSTALL(TARGETS mcctl RUNTIME DESTINATION bin) 8 | -------------------------------------------------------------------------------- /programs/mctimings/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(mctimings mctimings.cc) 2 | TARGET_LINK_LIBRARIES(mctimings 3 | mcutils 4 | mc_client_connection 5 | cJSON 6 | platform) 7 | INSTALL(TARGETS mctimings RUNTIME DESTINATION bin) 8 | -------------------------------------------------------------------------------- /testsuite/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_SUBDIRECTORY(basic) 2 | # Under threadsanitizer these tests are pretty slow, and they don't 3 | # really expose anything interesting from a threading pov, so skip 4 | # them if ThreadSanitizer enabled. 5 | IF(NOT CB_THREADSANITIZER) 6 | ADD_SUBDIRECTORY(breakdancer) 7 | ENDIF() 8 | -------------------------------------------------------------------------------- /engines/nobucket/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_LIBRARY(nobucket SHARED nobucket.cc) 2 | TARGET_LINK_LIBRARIES(nobucket engine_utilities platform) 3 | SET_TARGET_PROPERTIES(nobucket PROPERTIES PREFIX "") 4 | 5 | INSTALL(TARGETS nobucket 6 | RUNTIME DESTINATION bin 7 | LIBRARY DESTINATION lib 8 | ARCHIVE DESTINATION lib) 9 | -------------------------------------------------------------------------------- /protocol/mcbp/README.md: -------------------------------------------------------------------------------- 1 | # MCBP 2 | 3 | This directory contains helper functions for the Memcached Binary Protocol 4 | (aka MCBP). 5 | 6 | Given that this used to be the primary protocol in memcached we have not 7 | refactored the entire code and moved all methods in here (yet). New 8 | functions should however be located here. 9 | -------------------------------------------------------------------------------- /tests/function_chain/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(memcached_function_chain_test 2 | function_chain_test.cc) 3 | TARGET_LINK_LIBRARIES(memcached_function_chain_test gtest gtest_main) 4 | ADD_TEST(NAME memcached-function-chain-test 5 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 6 | COMMAND memcached_function_chain_test) -------------------------------------------------------------------------------- /engines/ewouldblock_engine/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_LIBRARY(ewouldblock_engine SHARED ewouldblock_engine.cc) 2 | TARGET_LINK_LIBRARIES(ewouldblock_engine 3 | dirutils 4 | engine_utilities 5 | mcd_util 6 | xattr) 7 | SET_TARGET_PROPERTIES(ewouldblock_engine PROPERTIES PREFIX "") 8 | -------------------------------------------------------------------------------- /extensions/daemon/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_LIBRARY(stdin_term_handler SHARED stdin_check.cc) 2 | SET_TARGET_PROPERTIES(stdin_term_handler PROPERTIES PREFIX "") 3 | TARGET_LINK_LIBRARIES(stdin_term_handler platform) 4 | INSTALL(TARGETS stdin_term_handler 5 | RUNTIME DESTINATION lib/memcached 6 | LIBRARY DESTINATION lib/memcached 7 | ARCHIVE DESTINATION lib/memcached) 8 | -------------------------------------------------------------------------------- /tests/privilege_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(memcached_privilege_test 2 | privilege_test.cc) 3 | 4 | TARGET_LINK_LIBRARIES(memcached_privilege_test cJSON memcached_rbac 5 | gtest gtest_main) 6 | ADD_TEST(NAME memcached-privilege-test 7 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 8 | COMMAND memcached_privilege_test) 9 | -------------------------------------------------------------------------------- /include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Project containing public headers exported by memcached. 2 | # Exists as a separate project from KVEngine to avoid circular 3 | # dependancies (e.g. couchstore depends on 4 | # , but ep.so depends on couchstore). 5 | # 6 | # Example usage: 7 | # INCLUDE_DIRECTORIES(${KVEngine_API_SOUCRE_DIR}/include) 8 | # 9 | project(KVEngineAPI) 10 | -------------------------------------------------------------------------------- /tests/topkeys/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(memcached_topkeys_bench 2 | ${PROJECT_SOURCE_DIR}/daemon/topkeys.cc 3 | topkeys_bench.cc) 4 | TARGET_LINK_LIBRARIES(memcached_topkeys_bench cJSON gtest gtest_main platform) 5 | ADD_TEST(NAME memcached_topkeys_bench 6 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 7 | COMMAND memcached_topkeys_bench) 8 | -------------------------------------------------------------------------------- /tests/engine_error/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | INCLUDE_DIRECTORIES(AFTER ${gtest_SOURCE_DIR}/include) 2 | ADD_EXECUTABLE(memcached-engine-error-test engine_error_test.cc) 3 | TARGET_LINK_LIBRARIES(memcached-engine-error-test engine_utilities gtest gtest_main) 4 | ADD_TEST(NAME memcached-engine-error-test 5 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 6 | COMMAND memcached-engine-error-test) 7 | -------------------------------------------------------------------------------- /daemon/alloc_hooks.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | #pragma once 3 | 4 | // Expose the compile-time selected allocator hooks implementation: 5 | 6 | #include "alloc_hooks_dummy.h" 7 | #include "alloc_hooks_jemalloc.h" 8 | 9 | #if defined(HAVE_JEMALLOC) 10 | using AllocHooks = JemallocHooks; 11 | #else 12 | using AllocHooks = DummyAllocHooks; 13 | #endif 14 | 15 | -------------------------------------------------------------------------------- /tests/error_map_sanity_check/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(memcached_errormap_sanity_check 2 | error_map_sanity_check.cc) 3 | 4 | TARGET_LINK_LIBRARIES(memcached_errormap_sanity_check memcached_daemon) 5 | 6 | ADD_TEST(NAME memcached_errormap_sanity_check 7 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 8 | COMMAND memcached_errormap_sanity_check ${Memcached_SOURCE_DIR}/etc/error_maps) 9 | -------------------------------------------------------------------------------- /tests/sizes/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(memcached_sizes 2 | sizes.cc 3 | ${Memcached_SOURCE_DIR}/utilities/protocol2text.cc) 4 | 5 | IF(ENABLE_DTRACE) 6 | ADD_DEPENDENCIES(memcached_sizes generate_memcached_dtrace_h) 7 | ENDIF(ENABLE_DTRACE) 8 | 9 | ADD_TEST(NAME memcached-sizes 10 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 11 | COMMAND memcached_sizes) 12 | -------------------------------------------------------------------------------- /tests/cbsasl_strcmp_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(cbsasl_strcmp_test strcmp_test.cc 2 | ${Memcached_SOURCE_DIR}/include/cbsasl/cbsasl.h 3 | ${Memcached_SOURCE_DIR}/include/cbsasl/visibility.h 4 | ${Memcached_SOURCE_DIR}/cbsasl/strcmp.cc) 5 | TARGET_LINK_LIBRARIES(cbsasl_strcmp_test platform) 6 | ADD_TEST(NAME cbsasl-strcmp 7 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 8 | COMMAND cbsasl_strcmp_test) 9 | -------------------------------------------------------------------------------- /cbsasl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_LIBRARY(cbsasl SHARED ${CBSASL_SOURCES}) 2 | SET_TARGET_PROPERTIES(cbsasl PROPERTIES SOVERSION 1.1.1) 3 | SET_TARGET_PROPERTIES(cbsasl PROPERTIES COMPILE_FLAGS -DBUILDING_CBSASL=1) 4 | TARGET_LINK_LIBRARIES(cbsasl cbcrypto dirutils cJSON platform ${OPENSSL_LIBRARIES}) 5 | 6 | INSTALL(TARGETS cbsasl 7 | RUNTIME DESTINATION bin 8 | LIBRARY DESTINATION lib 9 | ARCHIVE DESTINATION lib) 10 | -------------------------------------------------------------------------------- /testsuite/basic/basic_engine_testsuite.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | #ifndef BASIC_ENGINE_TESTSUITE_H 3 | #define BASIC_ENGINE_TESTSUITE_H 1 4 | 5 | #include 6 | 7 | extern "C" { 8 | MEMCACHED_PUBLIC_API 9 | engine_test_t* get_tests(void); 10 | 11 | MEMCACHED_PUBLIC_API 12 | bool setup_suite(struct test_harness *th); 13 | } 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /tests/config_util_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(memcached_config_util_test config_util_test.cc 2 | ${Memcached_SOURCE_DIR}/daemon/config_util.cc 3 | ${Memcached_SOURCE_DIR}/daemon/config_util.h) 4 | TARGET_LINK_LIBRARIES(memcached_config_util_test cJSON JSON_checker 5 | platform gtest gtest_main) 6 | ADD_TEST(NAME memcached-config 7 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 8 | COMMAND memcached_config_util_test) 9 | -------------------------------------------------------------------------------- /tests/doc_server_api/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | INCLUDE_DIRECTORIES(AFTER ${gtest_SOURCE_DIR}/include) 2 | ADD_EXECUTABLE(memcached-doc-server-api-test 3 | doc_pre_expiry_test.cc 4 | ${PROJECT_SOURCE_DIR}/daemon/doc_pre_expiry.cc) 5 | TARGET_LINK_LIBRARIES(memcached-doc-server-api-test xattr gtest gtest_main) 6 | ADD_TEST(NAME memcached-doc-server-api-test 7 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 8 | COMMAND memcached-doc-server-api-test) 9 | -------------------------------------------------------------------------------- /tests/scripts_tests/jemalloc_allocator_stats.cc: -------------------------------------------------------------------------------- 1 | // adapted from example program at 2 | // https://github.com/jemalloc/jemalloc/wiki/Getting-Started 3 | #include 4 | #include 5 | 6 | int main() { 7 | for (size_t i = 1; i < 1000; i++) { 8 | void* x = cb_malloc(i * 100); 9 | (void)x; 10 | } 11 | 12 | // Dump allocator statistics to stderr. 13 | je_malloc_stats_print(NULL, NULL, NULL); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /support-files/smf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/couchbase.xml.in 2 | ${CMAKE_CURRENT_BINARY_DIR}/couchbase.xml) 3 | 4 | CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/couchbase.in 5 | ${CMAKE_CURRENT_BINARY_DIR}/couchbase) 6 | 7 | 8 | INSTALL(FILES 9 | ${CMAKE_CURRENT_BINARY_DIR}/couchbase.xml 10 | DESTINATION smf) 11 | 12 | INSTALL(PROGRAMS 13 | ${CMAKE_CURRENT_BINARY_DIR}/couchbase 14 | DESTINATION smf) 15 | -------------------------------------------------------------------------------- /tests/cbcrypto_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(cbcrypto_test 2 | cbcrypto_test.cc 3 | ${Memcached_SOURCE_DIR}/include/cbcrypto/cbcrypto.h) 4 | 5 | TARGET_LINK_LIBRARIES(cbcrypto_test 6 | cbcrypto 7 | platform 8 | cJSON 9 | gtest gtest_main) 10 | 11 | ADD_TEST(NAME cbcrypto-test 12 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 13 | COMMAND cbcrypto_test) 14 | -------------------------------------------------------------------------------- /auditd/etc/kv_commit_validation_module_descriptors.json: -------------------------------------------------------------------------------- 1 | { 2 | "modules": [ 3 | { 4 | "auditd": { 5 | "startid": 4096, 6 | "file": "memcached/auditd/etc/auditd_descriptor.json", 7 | "header": "memcached/auditd/auditd_audit_events.h" 8 | } 9 | }, 10 | { 11 | "memcached": { 12 | "startid": 20480, 13 | "file": "memcached/etc/memcached_descriptor.json", 14 | "header": "memcached/memcached_audit_events.h" 15 | } 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /tests/saslprep/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | INCLUDE_DIRECTORIES(AFTER ${ICU_INCLUDE_DIR}) 2 | ADD_EXECUTABLE(cbsasl_saslprep_test 3 | ${Memcached_SOURCE_DIR}/cbsasl/scram-sha/stringutils.cc 4 | ${Memcached_SOURCE_DIR}/cbsasl/scram-sha/stringutils.h 5 | saslprep_test.cc) 6 | TARGET_LINK_LIBRARIES(cbsasl_saslprep_test platform gtest gtest_main) 7 | ADD_TEST(NAME cbsasl-saslprep-test 8 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 9 | COMMAND cbsasl_saslprep_test) 10 | -------------------------------------------------------------------------------- /engines/utilities/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_LIBRARY(engine_utilities SHARED engine_error.cc) 2 | TARGET_LINK_LIBRARIES(engine_utilities platform) 3 | 4 | GENERATE_EXPORT_HEADER(engine_utilities 5 | EXPORT_MACRO_NAME ENGINE_UTILITIES_PUBLIC_API 6 | EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/include/memcached/engine_utilities_visibility.h) 7 | 8 | INSTALL(TARGETS engine_utilities 9 | RUNTIME DESTINATION bin 10 | LIBRARY DESTINATION lib 11 | ARCHIVE DESTINATION lib) 12 | -------------------------------------------------------------------------------- /extensions/protocol_extension.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | #ifndef EXAMPLE_PROTOCOL_H 3 | #define EXAMPLE_PROTOCOL_H 4 | 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | MEMCACHED_PUBLIC_API 11 | EXTENSION_ERROR_CODE memcached_extensions_initialize(const char *config, 12 | GET_SERVER_API get_server_api); 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /tests/cbsasl_client_server_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(cbsasl_client_server_test cbsasl_test.cc 2 | ${Memcached_SOURCE_DIR}/include/cbcrypto/cbcrypto.h 3 | ${Memcached_SOURCE_DIR}/include/cbsasl/cbsasl.h 4 | ${Memcached_SOURCE_DIR}/include/cbsasl/visibility.h) 5 | TARGET_LINK_LIBRARIES(cbsasl_client_server_test cbcrypto cbsasl gtest gtest_main) 6 | ADD_TEST(NAME cbsasl-client-server 7 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 8 | COMMAND cbsasl_client_server_test) 9 | -------------------------------------------------------------------------------- /engines/default_engine.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | #ifndef MEMCACHED_DEFAULT_ENGINE_H 3 | #define MEMCACHED_DEFAULT_ENGINE_H 4 | 5 | #include "config.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | MEMCACHED_PUBLIC_API 12 | ENGINE_ERROR_CODE create_instance(uint64_t interface, 13 | GET_SERVER_API get_server_api, 14 | ENGINE_HANDLE **handle); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /etc/greenstack.ex.json: -------------------------------------------------------------------------------- 1 | { 2 | "threads" : 4, 3 | "interfaces" : 4 | [ 5 | { 6 | "port" : 11210, 7 | "backlog" : 1024, 8 | "host" : "*", 9 | "IPv6" : true, 10 | "maxconn" : 10000, 11 | "protocol" : "greenstack" 12 | }, 13 | { 14 | "port" : 11211, 15 | "backlog" : 1024, 16 | "host" : "*", 17 | "IPv6" : true, 18 | "maxconn" : 10000, 19 | "protocol" : "memcached" 20 | } 21 | ], 22 | "engine" : { 23 | "module" : "default_engine.so" 24 | }, 25 | "verbosity" : 1 26 | } 27 | -------------------------------------------------------------------------------- /tests/cbsasl_server_tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # We're using an "internal api" of the library in the test so we can't 2 | # use the library we just built 3 | ADD_EXECUTABLE(cbsasl_server_test sasl_server_test.cc ${CBSASL_SOURCES}) 4 | SET_TARGET_PROPERTIES(cbsasl_server_test PROPERTIES COMPILE_FLAGS -DBUILDING_CBSASL=1) 5 | TARGET_LINK_LIBRARIES(cbsasl_server_test cbcrypto platform cJSON ${OPENSSL_LIBRARIES} 6 | gtest gtest_main) 7 | ADD_TEST(NAME cbsasl-server-sasl 8 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 9 | COMMAND cbsasl_server_test) 10 | -------------------------------------------------------------------------------- /daemon/config_util.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | #pragma once 3 | 4 | typedef enum { 5 | CONFIG_SUCCESS, 6 | CONFIG_INVALID_ARGUMENTS, 7 | CONFIG_NO_SUCH_FILE, 8 | CONFIG_OPEN_FAILED, 9 | CONFIG_MALLOC_FAILED, 10 | CONFIG_IO_ERROR, 11 | CONFIG_PARSE_ERROR 12 | } config_error_t; 13 | 14 | /* Returns a string describing the given config_error_t. 15 | */ 16 | std::string config_strerror(const char *file, config_error_t error); 17 | config_error_t config_load_file(const char *file, cJSON **json); 18 | -------------------------------------------------------------------------------- /programs/cbtrace/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(cbtrace channel.h main.cc memorymap.cc memorymap.h pcap.cc pcap.h) 2 | TARGET_LINK_LIBRARIES(cbtrace mcd_util platform dirutils ${COUCHBASE_NETWORK_LIBS}) 3 | 4 | # The current state of the program is not good engough for it to be a part 5 | # of the product (it was written to solve a single problem and has not been 6 | # hardened to handle cases like tcp retransmit etc). Lets keep it in here 7 | # for us to continue to fix bugs and slowly make it usable. 8 | # 9 | #INSTALL(TARGETS cbtrace 10 | # RUNTIME DESTINATION bin) 11 | -------------------------------------------------------------------------------- /support-files/smf/couchbase.in: -------------------------------------------------------------------------------- 1 | #!/sbin/sh 2 | . /lib/svc/share/smf_include.sh 3 | 4 | PATH=${BIN_ROOT}/bin:$PATH:/opt/local/bin:/opt/local/gnu/bin 5 | export PATH 6 | 7 | case "$1" in 8 | 'start') 9 | coreadm -p "`svcprop -p couchbase/corepattern $SMF_FMRI`" $$ 10 | ${CMAKE_INSTALL_PREFIX}/bin/couchbase-server -- -noinput -detached & 11 | ;; 12 | 13 | 'stop') 14 | ${CMAKE_INSTALL_PREFIX}/bin/couchbase-server -k & 15 | ;; 16 | 17 | *) 18 | echo "Usage: $0 {start|stop}" 19 | exit 1 20 | ;; 21 | esac 22 | 23 | exit $SMF_EXIT_OK 24 | -------------------------------------------------------------------------------- /tests/datatype/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(memcached_datatype_test 2 | ${Memcached_SOURCE_DIR}/daemon/datatype.cc 3 | ${Memcached_SOURCE_DIR}/daemon/datatype.h 4 | ${Memcached_SOURCE_DIR}/daemon/settings.cc 5 | ${Memcached_SOURCE_DIR}/daemon/settings.h 6 | datatype_test.cc) 7 | TARGET_LINK_LIBRARIES(memcached_datatype_test gtest gtest_main memcached_daemon platform) 8 | ADD_TEST(NAME memcached_datatype-test 9 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 10 | COMMAND memcached_datatype_test) -------------------------------------------------------------------------------- /extensions/loggers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_LIBRARY(blackhole_logger SHARED blackhole_logger.cc) 2 | SET_TARGET_PROPERTIES(blackhole_logger PROPERTIES PREFIX "") 3 | 4 | ADD_LIBRARY(file_logger SHARED file_logger.cc 5 | file_logger_utilities.cc 6 | file_logger_utilities.h) 7 | SET_TARGET_PROPERTIES(file_logger PROPERTIES PREFIX "") 8 | TARGET_LINK_LIBRARIES(file_logger mcd_time platform dirutils) 9 | 10 | INSTALL(TARGETS file_logger 11 | RUNTIME DESTINATION lib/memcached 12 | LIBRARY DESTINATION lib/memcached 13 | ARCHIVE DESTINATION lib/memcached) 14 | -------------------------------------------------------------------------------- /include/memcached/visibility.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | #ifndef MEMCACHED_VISIBILITY_H 3 | #define MEMCACHED_VISIBILITY_H 1 4 | 5 | #if (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)) || (defined(__SUNPRO_CC) && (__SUNPRO_CC >= 0x550)) 6 | #define MEMCACHED_PUBLIC_API __global 7 | #elif defined __GNUC__ 8 | #define MEMCACHED_PUBLIC_API __attribute__ ((visibility("default"))) 9 | #elif defined(_MSC_VER) 10 | #define MEMCACHED_PUBLIC_API extern __declspec(dllexport) 11 | #else 12 | #define MEMCACHED_PUBLIC_API 13 | #endif 14 | 15 | #endif /* MEMCACHED_VISIBILITY_H */ 16 | -------------------------------------------------------------------------------- /programs/cbsasladm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(cbsasladm 2 | cbsasladm.cc 3 | ${Memcached_SOURCE_DIR}/cbsasl/log.cc 4 | ${Memcached_SOURCE_DIR}/cbsasl/pwconv.cc 5 | ${Memcached_SOURCE_DIR}/cbsasl/pwconv.h 6 | ${Memcached_SOURCE_DIR}/cbsasl/user.cc 7 | ${Memcached_SOURCE_DIR}/cbsasl/user.h) 8 | TARGET_LINK_LIBRARIES(cbsasladm 9 | cbsasl 10 | mc_client_connection 11 | mcd_util 12 | mcutils 13 | platform) 14 | INSTALL(TARGETS cbsasladm RUNTIME DESTINATION bin) 15 | -------------------------------------------------------------------------------- /protocol/mcbp/libmcbp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(mcbp STATIC 2 | ${Memcached_SOURCE_DIR}/include/mcbp/mcbp.h 3 | ${Memcached_SOURCE_DIR}/include/mcbp/protocol/datatype.h 4 | ${Memcached_SOURCE_DIR}/include/mcbp/protocol/magic.h 5 | ${Memcached_SOURCE_DIR}/include/mcbp/protocol/opcode.h 6 | ${Memcached_SOURCE_DIR}/include/mcbp/protocol/request.h 7 | ${Memcached_SOURCE_DIR}/include/mcbp/protocol/response.h 8 | ${Memcached_SOURCE_DIR}/include/mcbp/protocol/status.h 9 | dump.cc 10 | status_to_string.cc 11 | ) 12 | target_link_libraries(mcbp mcd_util) 13 | -------------------------------------------------------------------------------- /include/memcached/extension_loggers.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | #ifndef MEMCACHED_EXTENSION_LOGGERS_H 3 | #define MEMCACHED_EXTENSION_LOGGERS_H 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | MEMCACHED_PUBLIC_API EXTENSION_LOGGER_DESCRIPTOR* get_null_logger(void); 11 | 12 | MEMCACHED_PUBLIC_API EXTENSION_LOGGER_DESCRIPTOR* get_stderr_logger(void); 13 | 14 | MEMCACHED_PUBLIC_API 15 | EXTENSION_ERROR_CODE memcached_initialize_stderr_logger(GET_SERVER_API get_server_api); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | #endif /* MEMCACHED_EXTENSION_LOGGER_H */ 22 | -------------------------------------------------------------------------------- /auditd/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_LIBRARY(auditd SHARED 2 | audit.cc audit.h 3 | auditconfig.cc auditconfig.h 4 | auditd.cc auditd.h 5 | auditfile.cc auditfile.h 6 | configureevent.cc configureevent.h 7 | event.cc event.h 8 | eventdescriptor.cc 9 | eventdescriptor.h) 10 | SET_TARGET_PROPERTIES(auditd PROPERTIES SOVERSION 0.1.0) 11 | TARGET_LINK_LIBRARIES(auditd mcd_time cJSON JSON_checker platform dirutils) 12 | ADD_DEPENDENCIES(auditd generate_audit_descriptors) 13 | 14 | INSTALL(TARGETS auditd 15 | RUNTIME DESTINATION bin 16 | LIBRARY DESTINATION lib 17 | ARCHIVE DESTINATION lib) 18 | -------------------------------------------------------------------------------- /tests/scripts_tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | IF(NOT WIN32) 2 | INCLUDE_DIRECTORIES(${JEMALLOC_INCLUDE_DIR}) 3 | 4 | ADD_EXECUTABLE(jemalloc_allocator_stats 5 | jemalloc_allocator_stats.cc) 6 | 7 | TARGET_LINK_LIBRARIES(jemalloc_allocator_stats platform ${JEMALLOC_LIBRARIES}) 8 | 9 | ADD_TEST(NAME jemalloc_analyse 10 | COMMAND ${CMAKE_COMMAND} 11 | -DSRC_DIR=${CMAKE_CURRENT_SOURCE_DIR} 12 | -DJEMALLOC_ANALYSE=${PROJECT_SOURCE_DIR}/scripts/jemalloc/jemalloc_analyse.py 13 | -DTEST_PROGRAM=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/jemalloc_allocator_stats 14 | -P ${CMAKE_CURRENT_SOURCE_DIR}/runtests.cmake) 15 | ENDIF() -------------------------------------------------------------------------------- /utilities/protocol2text.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | #ifndef PROTOCOL2TEXT_H 3 | #define PROTOCOL2TEXT_H 4 | 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | MEMCACHED_PUBLIC_API 11 | const char *memcached_opcode_2_text(uint8_t opcode); 12 | MEMCACHED_PUBLIC_API 13 | uint8_t memcached_text_2_opcode(const char *txt); 14 | 15 | // Maps a status to a string that is a description and contains whitespace 16 | MEMCACHED_PUBLIC_API 17 | const char *memcached_status_2_text(protocol_binary_response_status status); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /time/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_LIBRARY(mcd_time SHARED 2 | isotime.cc 3 | ${PROJECT_SOURCE_DIR}/include/memcached/isotime.h) 4 | SET_TARGET_PROPERTIES(mcd_time PROPERTIES SOVERSION 1.0.0) 5 | TARGET_LINK_LIBRARIES(mcd_time platform) 6 | 7 | ADD_EXECUTABLE(memcached_timestamp_test timestamp_test.cc 8 | ${PROJECT_SOURCE_DIR}/include/memcached/isotime.h) 9 | TARGET_LINK_LIBRARIES(memcached_timestamp_test mcd_time) 10 | ADD_TEST(NAME memcached-timestamp-test 11 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 12 | COMMAND memcached_timestamp_test) 13 | 14 | INSTALL(TARGETS mcd_time 15 | RUNTIME DESTINATION bin 16 | LIBRARY DESTINATION lib 17 | ARCHIVE DESTINATION lib) 18 | -------------------------------------------------------------------------------- /tests/executor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(memcached_executor_test 2 | ${PROJECT_SOURCE_DIR}/daemon/executor.cc 3 | ${PROJECT_SOURCE_DIR}/daemon/executor.h 4 | ${PROJECT_SOURCE_DIR}/daemon/executorpool.cc 5 | ${PROJECT_SOURCE_DIR}/daemon/executorpool.h 6 | ${PROJECT_SOURCE_DIR}/daemon/task.cc 7 | ${PROJECT_SOURCE_DIR}/daemon/task.h 8 | executor_test.cc) 9 | TARGET_LINK_LIBRARIES(memcached_executor_test platform gtest) 10 | ADD_TEST(NAME memcached-executor-tests 11 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 12 | COMMAND memcached_executor_test) 13 | SET_TESTS_PROPERTIES(memcached-executor-tests PROPERTIES TIMEOUT 60) 14 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | Chris Goffinet Chris Goffinet 2 | Eric Lambert Eric Lambert 3 | Jayesh Jose Jayesh Jose 4 | Patrick Galbraith CaptTofu 5 | Patrick Galbraith Patrick Galbraith 6 | Paul Lindner Paul Lindner 7 | Paul Lindner Paul Lindner 8 | Trond Norbye Trond Norbye 9 | Trond Norbye Trond Norbye 10 | Victor Kirkebo Victor Kirkebo 11 | -------------------------------------------------------------------------------- /xattr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_LIBRARY(xattr SHARED 2 | ${PROJECT_SOURCE_DIR}/include/xattr/blob.h 3 | ${PROJECT_SOURCE_DIR}/include/xattr/key_validator.h 4 | ${PROJECT_SOURCE_DIR}/include/xattr/utils.h 5 | blob.cc 6 | key_validator.cc 7 | utils.cc) 8 | 9 | SET_TARGET_PROPERTIES(xattr PROPERTIES SOVERSION 0.1.0) 10 | TARGET_LINK_LIBRARIES(xattr cJSON platform) 11 | GENERATE_EXPORT_HEADER(xattr 12 | EXPORT_MACRO_NAME XATTR_PUBLIC_API 13 | EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/include/xattr/visibility.h) 14 | 15 | INSTALL(TARGETS xattr 16 | RUNTIME DESTINATION bin 17 | LIBRARY DESTINATION lib 18 | ARCHIVE DESTINATION lib) 19 | -------------------------------------------------------------------------------- /rbac/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(memcached_rbac SHARED 2 | privileges.cc 3 | privilege_database.cc 4 | ${PROJECT_SOURCE_DIR}/include/memcached/rbac/privilege_database.h 5 | ${PROJECT_SOURCE_DIR}/include/memcached/rbac.h 6 | ) 7 | 8 | set_target_properties(memcached_rbac PROPERTIES SOVERSION 1.0.0) 9 | target_link_libraries(memcached_rbac cbsasl cJSON platform) 10 | 11 | generate_export_header(memcached_rbac 12 | EXPORT_MACRO_NAME RBAC_PUBLIC_API 13 | EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/include/memcached/rbac/visibility.h) 14 | 15 | install(TARGETS memcached_rbac 16 | RUNTIME DESTINATION bin 17 | LIBRARY DESTINATION lib 18 | ARCHIVE DESTINATION lib) 19 | -------------------------------------------------------------------------------- /daemon/libevent_locking.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | void setup_libevent_locking(); -------------------------------------------------------------------------------- /daemon/memcached_openssl.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | void initialize_openssl(); 20 | void shutdown_openssl(); 21 | -------------------------------------------------------------------------------- /programs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_LIBRARY(mcutils STATIC 2 | hostname_utils.cc hostname_utils.h) 3 | TARGET_LINK_LIBRARIES(mcutils mcbp cbsasl ${COUCHBASE_NETWORK_LIBS}) 4 | 5 | ADD_EXECUTABLE(memcached-hostutils-test 6 | hostname_utils_test.cc) 7 | TARGET_LINK_LIBRARIES(memcached-hostutils-test 8 | mcutils 9 | platform 10 | gtest 11 | gtest_main) 12 | ADD_TEST(NAME memcached-hostutils-test 13 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 14 | COMMAND memcached-hostutils-test) 15 | 16 | 17 | ADD_SUBDIRECTORY(cbsasladm) 18 | ADD_SUBDIRECTORY(cbtrace) 19 | ADD_SUBDIRECTORY(engine_testapp) 20 | ADD_SUBDIRECTORY(mcctl) 21 | ADD_SUBDIRECTORY(mclogsplit) 22 | ADD_SUBDIRECTORY(mcstat) 23 | ADD_SUBDIRECTORY(mctimings) 24 | ADD_SUBDIRECTORY(moxi_hammer) 25 | -------------------------------------------------------------------------------- /utilities/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_LIBRARY(mcd_util SHARED 2 | config_parser.cc 3 | engine_loader.cc 4 | extension_loggers.cc 5 | protocol2text.cc 6 | util.cc) 7 | TARGET_LINK_LIBRARIES(mcd_util engine_utilities platform) 8 | SET_TARGET_PROPERTIES(mcd_util PROPERTIES SOVERSION 1.0.0) 9 | INSTALL(TARGETS mcd_util 10 | RUNTIME DESTINATION bin 11 | LIBRARY DESTINATION lib 12 | ARCHIVE DESTINATION lib) 13 | 14 | ADD_EXECUTABLE(utilities_testapp 15 | config_parser.cc 16 | string_utilities.cc 17 | util.cc 18 | util_test.cc) 19 | TARGET_LINK_LIBRARIES(utilities_testapp gtest gtest_main gmock platform) 20 | ADD_TEST(NAME memcached-utilities-tests 21 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 22 | COMMAND utilities_testapp) 23 | -------------------------------------------------------------------------------- /daemon/mcbp_topkeys.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | 22 | std::array& get_mcbp_topkeys(); 23 | -------------------------------------------------------------------------------- /daemon/ssl_utils.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | long decode_ssl_protocol(const std::string& protocol); 22 | -------------------------------------------------------------------------------- /protocol/connection/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | IF (MEMCACHED_USE_GREENSTACK) 2 | LIST(APPEND MEMCACHED_GREENSTACK_LIBS greenstack) 3 | LIST(APPEND MEMCACHED_GREENSTACK_SRC 4 | client_greenstack_connection.cc 5 | client_greenstack_connection.h) 6 | ENDIF (MEMCACHED_USE_GREENSTACK) 7 | 8 | ADD_LIBRARY(mc_client_connection STATIC 9 | ${MEMCACHED_GREENSTACK_SRC} 10 | client_connection.h 11 | client_connection.cc 12 | client_mcbp_commands.cc 13 | client_mcbp_commands.h 14 | client_mcbp_connection.cc 15 | client_mcbp_connection.h) 16 | 17 | TARGET_LINK_LIBRARIES(mc_client_connection 18 | mcbp 19 | cbsasl 20 | ${MEMCACHED_GREENSTACK_LIBS} 21 | ${COUCHBASE_NETWORK_LIBS} 22 | ${OPENSSL_LIBRARIES}) 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Keep the entries sorted to reduce the risk for a merge conflict 2 | *.[ao] 3 | *.dll 4 | *.dll.manifest 5 | *.dll.embed.manifest 6 | *.dll.embed.manifest.res 7 | *.dll.intermediate.manifest 8 | *.dll.resource.txt 9 | *.dylib 10 | *.exe 11 | *.exe.manifest 12 | *.exe.embed.manifest 13 | *.exe.embed.manifest.res 14 | *.exe.intermediate.manifest 15 | *.exe.resource.txt 16 | *.exp 17 | *.ilk 18 | *.lib 19 | *.pdb 20 | *.pyc 21 | *.so 22 | *.so.* 23 | *~ 24 | /CMakeCache.txt 25 | /CMakeFiles/ 26 | /CTestTestfile.cmake 27 | /Makefile 28 | /Testing/ 29 | /bucket_engine_testapp 30 | /cmake_install.cmake 31 | /engine_testapp 32 | /generated_breakdancer_testsuite.c 33 | /install_manifest.txt 34 | /cbsasladm 35 | /mcbasher 36 | /memcached 37 | /mcstat 38 | /mchello 39 | /mctimings 40 | /memcached_sizes 41 | /memcached_testapp 42 | /ssltest 43 | /timedrun 44 | /config.h 45 | /memcached*test 46 | /*_test 47 | .DS_Store 48 | -------------------------------------------------------------------------------- /include/memcached/vbucket.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | #ifndef MEMCACHED_VBUCKET_H 3 | #define MEMCACHED_VBUCKET_H 1 4 | 5 | #ifdef __cplusplus 6 | extern "C" 7 | { 8 | #endif 9 | 10 | typedef enum { 11 | vbucket_state_active = 1, /**< Actively servicing a vbucket. */ 12 | vbucket_state_replica, /**< Servicing a vbucket as a replica only. */ 13 | vbucket_state_pending, /**< Pending active. */ 14 | vbucket_state_dead /**< Not in use, pending deletion. */ 15 | } vbucket_state_t; 16 | 17 | #define is_valid_vbucket_state_t(state) \ 18 | (state == vbucket_state_active || \ 19 | state == vbucket_state_replica || \ 20 | state == vbucket_state_pending || \ 21 | state == vbucket_state_dead) 22 | 23 | typedef struct { 24 | uint64_t uuid; 25 | uint64_t seqno; 26 | } vbucket_failover_t; 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | #endif 32 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_SUBDIRECTORY(cbcrypto_test) 2 | ADD_SUBDIRECTORY(cbsasl_client_server_test) 3 | ADD_SUBDIRECTORY(cbsasl_password_database_test) 4 | ADD_SUBDIRECTORY(cbsasl_pwconv_test) 5 | ADD_SUBDIRECTORY(cbsasl_server_tests) 6 | ADD_SUBDIRECTORY(cbsasl_strcmp_test) 7 | ADD_SUBDIRECTORY(config_util_test) 8 | ADD_SUBDIRECTORY(config_parse_test) 9 | ADD_SUBDIRECTORY(datatype) 10 | ADD_SUBDIRECTORY(doc_server_api) 11 | ADD_SUBDIRECTORY(engine_error) 12 | ADD_SUBDIRECTORY(error_map_sanity_check) 13 | ADD_SUBDIRECTORY(event) 14 | ADD_SUBDIRECTORY(executor) 15 | ADD_SUBDIRECTORY(function_chain) 16 | ADD_SUBDIRECTORY(logger_test) 17 | ADD_SUBDIRECTORY(mcbp) 18 | ADD_SUBDIRECTORY(memory_tracking_test) 19 | ADD_SUBDIRECTORY(privilege_test) 20 | ADD_SUBDIRECTORY(saslprep) 21 | ADD_SUBDIRECTORY(scripts_tests) 22 | ADD_SUBDIRECTORY(sizes) 23 | ADD_SUBDIRECTORY(ssl_cert_test) 24 | ADD_SUBDIRECTORY(testapp) 25 | ADD_SUBDIRECTORY(topkeys) 26 | -------------------------------------------------------------------------------- /include/memcached/rbac.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | -------------------------------------------------------------------------------- /tests/cbnt_tests/readme.md: -------------------------------------------------------------------------------- 1 | This directory contains the Couchbase nightly test (CBNT) test config file. 2 | This is a performance testing infrastructure used as part of commit validation 3 | for both the memcached and ep-engine projects. 4 | 5 | The couchbase-based test harnesses require this yaml config file to know which 6 | tests to run. 7 | 8 | The config file follows the following format: 9 | 10 | ``` 11 | - test: testname1 12 | command: "command to run this test" 13 | output: 14 | - "outputfile1.xml" 15 | - "outputfile2.xml" 16 | - test: testname2 17 | command: "command to run this test" 18 | output: "outputfile.xml" 19 | ``` 20 | 21 | One really important thing to note about this config file is that all commands 22 | should be relative to the root of the couchbase build directory 23 | (i.e the directory which contains all of the projects; the result of a repo 24 | sync) so that it can appropriately find all of the required files. 25 | -------------------------------------------------------------------------------- /tests/testapp/testapp_arithmetic.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include "testapp.h" 20 | #include "testapp_client_test.h" 21 | 22 | class ArithmeticTest : public TestappClientTest { 23 | 24 | }; 25 | -------------------------------------------------------------------------------- /tests/cert/client.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXQIBAAKBgQDy4m12AFOCuUAYJIHoUVt2J4iMSvhn3e9ouWL5Qbb6lE5FjQ6T 3 | CzDQ5hZpNvDOLqJqgULxmaLGWLOue8tfFaOn9+QGEZe0bS9qSadLs6c2NEH2RUbL 4 | OhhkhZWBb0djidwZ1bx5hTEmLaH/IZXQO42XUGgW910avMnRtTz5fauv2wIDAQAB 5 | AoGACdUKs1UuDEOtiYyoyZvJhQ3ypCNAzQuZ7nZawFZdruUkCgK8zU0Nq9c0nwu/ 6 | Uclnf8I90IP0p+zdUTnnsLCykDzzbRwCni1OdJIqOoZP7GykxGniAxosjCuZQmJr 7 | cj0K1nUvdd/zOQyVGsB1WLQcVRsPCRXYZqMqAhnBuruHf1ECQQD5p1CD2cDXYVVT 8 | HGh7Jup9eJ026XRkTdflyP+0w+H5jn7KTOn/PuXOjVAybaJp1AyexHSY4HUwRI2U 9 | t9gDIt6DAkEA+Q8Pu+SIAEYiBsXgLVxs2niTkMi9MqcaQ5rpAjm4hLdpcbpWjUU8 10 | oH1ATBJbB/ODnK+uoqlfoeFL3ojAFzgpyQJBAIs6YS+3D9HN6WzZSfdsY5en3V2T 11 | YqLRutbeeqSQHYU0j8c4j8MWi8jejFwjQlFsvcEJZNEhVJmfkanfwWs2VgsCQQCM 12 | hOLrr9TL0sX/7ES/UxZXbRBU7+1PVtiKrCwrBUYGGzVy5R9QNXAvXHuacADMS6hG 13 | DxkIzWcXfnW/6If4kceBAkAHu5c8jtBI1tO2/hcLFLdD1erwPbVoDz35udWfVCXt 14 | VNQw5NajrtXDwFR8Wm3rF7BkJM3PYN0pzbxkSXgT+CQa 15 | -----END RSA PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /tests/cert/parse-test.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXQIBAAKBgQDK6UMYTIlTwmoVT/rE/wwHue4CPHXN3aPn/FXnF6z1bTvMEF5+ 3 | 1C/sMicGywj7wESej0nhx2YYWWMIrkJKPmNU4mpGyqXWBFTl04eg6DAiQb+s+Kvy 4 | fRQcRCWN/I7l7dm3lz7aY/qyoysvn9GwRw+s8HynqKxFW85j7uuY/12NfwIDAQAB 5 | AoGAVY75/Zr4JNtLQ+VPhhVNC0z48PRxb/bPEBi0WBcBlRMULb2ROsVZ16xmDFU8 6 | Wnr99CXTL2KWyBmYyqY/yXJ5Cydi0IGbGcOAjM8p3gcEbWVRqw1/rheXPntomeFf 7 | 5VrKZgbkqgMdU7UxMrsHhX/EVl1yLXbBhgII+0+ailzO1wECQQDvn+Kr1MBURVFU 8 | SFvCTcOxIxhsWFeG47ARFsQUtIJ80xX8D36cQow9OYcxsUII0IykhJeZa7H6ayhK 9 | n/qpTaRBAkEA2McYGLTHqUIaTubOj6yieNSa7fF8P8nCRiZmWwGMtx6GUjc5d/G+ 10 | 4MaLUhwzjaifb+03Kc/mhOo7up91ItvBvwJAG1/5pkW83yO4IdfOW8lEhPUMcjw5 11 | a5iRYbJnHjJtAdOfnFcs0K8tlEUBM+UbNSSWHKllJErQX1pklPnnyfWrwQJBAMmJ 12 | J6TohWudshnCyS2X4SEW/8bRqKMhL0XKs4ROR4WDkntjLkGN9djBnYtD/sXni/sh 13 | /hQYXgcaQVd6ogs7Zb8CQQDtGAf2j+sJqn9Mloduj8IuDIUHl9mWmlgFljJ8oUBE 14 | rFgyEWxEYvaM5RpD/8qg1IaHmbDWFWWnvkkYdkECBULH 15 | -----END RSA PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /tests/cert/testapp.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXQIBAAKBgQDAITD9ZqhF7qcEO76EQYxp7aaOAzZY/GCKAhoDnP1kb4+6SJvk 3 | oBb67b9MDPlq8TijS9PiQ9bizad8kgIfqJy0QsF45S1Ab9YAptJBl4GwqhmAwZt/ 4 | vHQXmQA6p7XtHBSCliAQ58ZjeGe4f3fHGc5WDjTzzz5GEPvSlVKn3XBgTwIDAQAB 5 | AoGBALHLRVGJ+ThV4/q36tLq8axo/pM2h8mLKy8rSLWFRrv1vTSu0oycVQe6kSco 6 | bns3ZKlAl4AwNR/HHjHZz9tKJk/S1gW+GPeo1O9LXi21I6pAGw+onxmfwZHMNQ/N 7 | 9BuE+RGEgPNh2RWgsrXVvS74fwFGzUVTwwnutW/K9Xa8mEZxAkEA6e58c2FeDw9o 8 | CK0zOl0ax92jhOd3OwtnuYIZQcFj47AtcV4/tZbmphtEJ9+l+5uqauveCrkQ/3pp 9 | ++M4CLtEZwJBANJBLT+59DEvHHwzU9agQUr54mnhBoFabgp6LNmlBS6ym4U3gNbA 10 | 4g7mdwzc6x4/qgN1NDTK+/LouBYNDCCKU9kCQCV0Tq62jzXAFLsW6BXXJFuNzAmS 11 | ec+VUuUrxFl32kNxSMVW/sJXR9Selvn/X/b6BH4cB7AV03fkJKX0ylrziM8CQFQt 12 | 8i7khac3hIEZj8SLjvi0yXi4toENsqcROWm+Ty/eJLQWf8f7m8Z5cUq+HIiU1r3h 13 | rBBDANLFaAa0HJneqCkCQQCHSrcG+/EJSH4JRYkRo6+lJ6dGGwJf0l6+x5Wh/lYV 14 | q4LTPx/onI9US0Mk/r6l1TYYmU+LQy1YghV3vyXVWv4a 15 | -----END RSA PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /programs/engine_testapp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(engine_testapp engine_testapp.cc 2 | mock_server.cc 3 | mock_server.h 4 | ${Memcached_SOURCE_DIR}/daemon/protocol/mcbp/engine_errc_2_mcbp.cc 5 | ${Memcached_SOURCE_DIR}/daemon/protocol/mcbp/engine_errc_2_mcbp.h 6 | ${Memcached_SOURCE_DIR}/daemon/doc_pre_expiry.cc 7 | ${Memcached_SOURCE_DIR}/utilities/terminate_handler.cc 8 | $) 9 | 10 | TARGET_LINK_LIBRARIES(engine_testapp mcd_util platform xattr 11 | ${MALLOC_LIBRARIES} ${COUCHBASE_NETWORK_LIBS}) 12 | INSTALL(TARGETS engine_testapp 13 | RUNTIME DESTINATION bin) 14 | 15 | ADD_TEST(NAME memcached-basic-engine-tests 16 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 17 | COMMAND engine_testapp -E default_engine.so 18 | -T basic_engine_testsuite.so) 19 | -------------------------------------------------------------------------------- /tests/ssl_cert_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(memcached_cert_test ssl_cert_test.cc 2 | ${Memcached_SOURCE_DIR}/daemon/settings.cc 3 | ${Memcached_SOURCE_DIR}/daemon/settings.h 4 | ${Memcached_SOURCE_DIR}/daemon/sslcert.cc 5 | ${Memcached_SOURCE_DIR}/daemon/sslcert.h 6 | ${Memcached_SOURCE_DIR}/daemon/ssl_utils.cc) 7 | 8 | TARGET_LINK_LIBRARIES(memcached_cert_test 9 | cJSON 10 | platform 11 | dirutils 12 | gtest gtest_main 13 | ${OPENSSL_LIBRARIES} 14 | ${COUCHBASE_NETWORK_LIBS}) 15 | ADD_TEST(NAME memcached_cert_test 16 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 17 | COMMAND memcached_cert_test) 18 | 19 | IF (ENABLE_DTRACE) 20 | ADD_DEPENDENCIES(memcached_cert_test generate_memcached_dtrace_h) 21 | ENDIF (ENABLE_DTRACE) 22 | -------------------------------------------------------------------------------- /daemon/alloc_hooks_types.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | 22 | typedef void (*malloc_new_hook_t)(const void *ptr, size_t sz); 23 | typedef void (*malloc_delete_hook_t)(const void *ptr); 24 | -------------------------------------------------------------------------------- /tests/testapp/testapp_bucket.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include "testapp.h" 20 | #include "testapp_client_test.h" 21 | 22 | class BucketTest : public TestappClientTest { 23 | public: 24 | protected: 25 | 26 | }; 27 | -------------------------------------------------------------------------------- /daemon/breakpad_dummy.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "config.h" 19 | #include "breakpad.h" 20 | #include 21 | 22 | void initialize_breakpad(const BreakpadSettings& settings) { 23 | } 24 | 25 | void destroy_breakpad(void) { 26 | } 27 | -------------------------------------------------------------------------------- /auditd/etc/example_descriptor.json: -------------------------------------------------------------------------------- 1 | { 2 | "version" : 1, 3 | "module" : "example", 4 | "events" : [ 5 | { "id" : 8192, 6 | "name" : "example event", 7 | "description" : "this is the full description of the example event", 8 | "sync" : false, 9 | "enabled" : true, 10 | "mandatory_fields" : { 11 | "timestamp" : "", 12 | "real_userid" : {"source" : "", "user" : ""} 13 | }, 14 | "optional_fields" : { 15 | "sessionid" : "", 16 | "remote" : {"ip" : "", "port" : 1}, 17 | "effective_userid" : {"source" : "", "user" : ""} 18 | } 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /cbcrypto/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_LIBRARY(cbcrypto SHARED 2 | cbcrypto.cc 3 | ${PROJECT_SOURCE_DIR}/include/cbcrypto/cbcrypto.h) 4 | SET_TARGET_PROPERTIES(cbcrypto PROPERTIES SOVERSION 1.0.0) 5 | 6 | if (APPLE) 7 | # Apple is using the Common Crypto Framework for all crypto functions 8 | TARGET_LINK_LIBRARIES(cbcrypto cJSON platform) 9 | elseif (WIN32) 10 | # Use the OpenSSL ones for all other platforms 11 | TARGET_LINK_LIBRARIES(cbcrypto cJSON platform Bcrypt) 12 | else() 13 | # Use the OpenSSL ones for all other platforms 14 | TARGET_LINK_LIBRARIES(cbcrypto cJSON platform ${OPENSSL_LIBRARIES}) 15 | endif () 16 | 17 | GENERATE_EXPORT_HEADER(cbcrypto 18 | EXPORT_MACRO_NAME CBCRYPTO_PUBLIC_API 19 | EXPORT_FILE_NAME ${PROJECT_BINARY_DIR}/include/cbcrypto/visibility.h) 20 | 21 | INSTALL(TARGETS cbcrypto 22 | RUNTIME DESTINATION bin 23 | LIBRARY DESTINATION lib 24 | ARCHIVE DESTINATION lib) 25 | -------------------------------------------------------------------------------- /tests/config_parse_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(memcached_config_parse_test config_parse_test.cc 2 | ${Memcached_SOURCE_DIR}/daemon/settings.cc 3 | ${Memcached_SOURCE_DIR}/daemon/settings.h 4 | ${Memcached_SOURCE_DIR}/daemon/sslcert.cc 5 | ${Memcached_SOURCE_DIR}/daemon/sslcert.h 6 | ${Memcached_SOURCE_DIR}/daemon/ssl_utils.cc) 7 | 8 | TARGET_LINK_LIBRARIES(memcached_config_parse_test 9 | cJSON 10 | JSON_checker 11 | platform 12 | dirutils 13 | gtest gtest_main 14 | ${OPENSSL_LIBRARIES} 15 | ${COUCHBASE_NETWORK_LIBS}) 16 | ADD_TEST(NAME memcache-config-parse 17 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 18 | COMMAND memcached_config_parse_test) 19 | 20 | IF (ENABLE_DTRACE) 21 | ADD_DEPENDENCIES(memcached_config_parse_test generate_memcached_dtrace_h) 22 | ENDIF (ENABLE_DTRACE) 23 | -------------------------------------------------------------------------------- /daemon/doc_pre_expiry.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | 22 | /** 23 | * Implementation of the pre_expiry hook in the `SERVER_DOCUMENT_API`. Check 24 | * the server API documentation for more information. 25 | */ 26 | bool document_pre_expiry(item_info& itm_info); 27 | -------------------------------------------------------------------------------- /tests/cbsasl_password_database_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(cbsasl_password_database_test 2 | password_database_test.cc 3 | ${Memcached_SOURCE_DIR}/include/cbcrypto/cbcrypto.h 4 | ${Memcached_SOURCE_DIR}/cbsasl/log.cc 5 | ${Memcached_SOURCE_DIR}/cbsasl/password_database.cc 6 | ${Memcached_SOURCE_DIR}/cbsasl/password_database.h 7 | ${Memcached_SOURCE_DIR}/cbsasl/pwconv.cc 8 | ${Memcached_SOURCE_DIR}/cbsasl/pwconv.h 9 | ${Memcached_SOURCE_DIR}/cbsasl/user.cc 10 | ${Memcached_SOURCE_DIR}/cbsasl/user.h) 11 | TARGET_LINK_LIBRARIES(cbsasl_password_database_test 12 | cbcrypto 13 | gtest 14 | cJSON 15 | dirutils 16 | platform 17 | ${OPENSSL_LIBRARIES}) 18 | ADD_TEST(NAME cbsasl-password-database 19 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 20 | COMMAND cbsasl_password_database_test) 21 | -------------------------------------------------------------------------------- /daemon/alloc_hooks_dummy.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "config.h" 21 | 22 | #include "alloc_hooks_types.h" 23 | #include 24 | 25 | class DummyAllocHooks { 26 | public: 27 | #define X(name, ret, args) static ret name args; 28 | #include "alloc_hooks.def" 29 | #undef X 30 | }; 31 | -------------------------------------------------------------------------------- /daemon/alloc_hooks_jemalloc.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "config.h" 21 | 22 | #include "alloc_hooks_types.h" 23 | #include 24 | 25 | class JemallocHooks { 26 | public: 27 | #define X(name, ret, args) static ret name args; 28 | #include "alloc_hooks.def" 29 | #undef X 30 | }; 31 | -------------------------------------------------------------------------------- /tests/logger_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(memcached_logger_test 2 | ${Memcached_SOURCE_DIR}/extensions/loggers/file_logger_utilities.h 3 | ${Memcached_SOURCE_DIR}/extensions/loggers/file_logger_utilities.cc 4 | logger_test_common.cc 5 | logger_test.cc) 6 | TARGET_LINK_LIBRARIES(memcached_logger_test gtest gtest_main mcd_util file_logger dirutils) 7 | ADD_TEST(NAME memcached-logger-test 8 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 9 | COMMAND memcached_logger_test) 10 | 11 | IF (NOT WIN32) 12 | # Test makes use of {get,set}rlimit() which don't exist on Windows. 13 | ADD_EXECUTABLE(memcached_logger_emfile_test 14 | logger_test_common.cc 15 | logger_emfile_test.cc) 16 | TARGET_LINK_LIBRARIES(memcached_logger_emfile_test mcd_util file_logger dirutils) 17 | ADD_TEST(NAME memcached-logger-emfile-test 18 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 19 | COMMAND memcached_logger_emfile_test) 20 | ENDIF (NOT WIN32) 21 | -------------------------------------------------------------------------------- /tests/cert/testapp.cert: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICuTCCAiKgAwIBAgIJAPNHqXQE9u4HMA0GCSqGSIb3DQEBCwUAMEgxCzAJBgNV 3 | BAYTAk5PMRYwFAYDVQQKEw1Db3VjaGJhc2UgSW5jMQ8wDQYDVQQLEwZrdiBlbmcx 4 | EDAOBgNVBAMTB1Jvb3QgQ0EwHhcNMTcwNDA2MTkxMTAwWhcNMjcwNDA0MTkxMTAw 5 | WjBIMQswCQYDVQQGEwJOTzEWMBQGA1UEChMNQ291Y2hiYXNlIEluYzEPMA0GA1UE 6 | CxMGa3YgZW5nMRAwDgYDVQQDEwdSb290IENBMIGfMA0GCSqGSIb3DQEBAQUAA4GN 7 | ADCBiQKBgQDAITD9ZqhF7qcEO76EQYxp7aaOAzZY/GCKAhoDnP1kb4+6SJvkoBb6 8 | 7b9MDPlq8TijS9PiQ9bizad8kgIfqJy0QsF45S1Ab9YAptJBl4GwqhmAwZt/vHQX 9 | mQA6p7XtHBSCliAQ58ZjeGe4f3fHGc5WDjTzzz5GEPvSlVKn3XBgTwIDAQABo4Gq 10 | MIGnMB0GA1UdDgQWBBTxKDXeM65ZUVsy1X7So6znuzRKBjB4BgNVHSMEcTBvgBTx 11 | KDXeM65ZUVsy1X7So6znuzRKBqFMpEowSDELMAkGA1UEBhMCTk8xFjAUBgNVBAoT 12 | DUNvdWNoYmFzZSBJbmMxDzANBgNVBAsTBmt2IGVuZzEQMA4GA1UEAxMHUm9vdCBD 13 | QYIJAPNHqXQE9u4HMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADgYEAUOSn 14 | QZ1o645HhNWk1mYgxlu6fq7XwhhoHgz0II2UsaO4gFZa7VP9pLfC707wkcLej6K7 15 | L6eM5rDC/KKF8aoMYXvqQp6DSB+SLyBIZqiKRqpOptm0SJmxGJ2rUqpeqRNiUKrc 16 | XgAmWuBjbXs08ZLaqaCYCbrVJY3t01eB8HihmOE= 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /tests/mcbp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(AFTER ${gtest_SOURCE_DIR}/include) 2 | ADD_DEFINITIONS(-DBUILDING_VALIDATORS_TEST) 3 | add_executable(memcached_mcbp_test 4 | mcbp_gat_test.cc 5 | mcbp_test.cc 6 | mcbp_test_collections.cc 7 | mcbp_test_meta.cc 8 | mcbp_test_subdoc.cc 9 | mcbp_test_subdoc_xattr.cc 10 | xattr_blob_test.cc 11 | xattr_blob_validator_test.cc 12 | xattr_key_validator_test.cc 13 | ${PROJECT_SOURCE_DIR}/utilities/protocol2text.cc 14 | ${PROJECT_SOURCE_DIR}/protocol/connection/client_mcbp_commands.cc) 15 | target_link_libraries(memcached_mcbp_test memcached_daemon platform 16 | gtest gtest_main) 17 | add_test(NAME memcached_mcbp_test COMMAND memcached_mcbp_test) 18 | 19 | # GTest can be slow to compile (due to all the template / macro 20 | # expansion). Disabling optimization can speed up by ~30%. 21 | target_compile_options(memcached_mcbp_test PRIVATE ${CB_CXX_FLAGS_NO_OPTIMIZE}) 22 | -------------------------------------------------------------------------------- /tests/cert/client.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICvjCCAiegAwIBAgIJALE2RC7jwGcyMA0GCSqGSIb3DQEBBQUAMEgxCzAJBgNV 3 | BAYTAk5PMRYwFAYDVQQKEw1Db3VjaGJhc2UgSW5jMQ8wDQYDVQQLEwZrdiBlbmcx 4 | EDAOBgNVBAMTB1Jvb3QgQ0EwHhcNMTcwNDA2MTkxMTAwWhcNMjcwNDA0MTkxMTAw 5 | WjBNMQswCQYDVQQGEwJOTzEWMBQGA1UEChMNQ291Y2hiYXNlIEluYzEPMA0GA1UE 6 | CxMGa3YgZW5nMRUwEwYDVQQDEwxUcm9uZCBOb3JieWUwgZ8wDQYJKoZIhvcNAQEB 7 | BQADgY0AMIGJAoGBAPLibXYAU4K5QBgkgehRW3YniIxK+Gfd72i5YvlBtvqUTkWN 8 | DpMLMNDmFmk28M4uomqBQvGZosZYs657y18Vo6f35AYRl7RtL2pJp0uzpzY0QfZF 9 | Rss6GGSFlYFvR2OJ3BnVvHmFMSYtof8hldA7jZdQaBb3XRq8ydG1PPl9q6/bAgMB 10 | AAGjgaowgacwHQYDVR0OBBYEFCm3v29TLBK1ZWS6XWaFrBW60No8MHgGA1UdIwRx 11 | MG+AFPEoNd4zrllRWzLVftKjrOe7NEoGoUykSjBIMQswCQYDVQQGEwJOTzEWMBQG 12 | A1UEChMNQ291Y2hiYXNlIEluYzEPMA0GA1UECxMGa3YgZW5nMRAwDgYDVQQDEwdS 13 | b290IENBggkA80epdAT27gcwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOB 14 | gQAwrL28a396u6PBIzgp/4DIXfDqV1TAfnovnKUh0dSf2N18vXoLx5svjqDMCt+G 15 | dkFXMXD5O8D1ovR1CksNBRFQHODMCALNvLoHlzKVPzZCTWPqPgx+laMz1JlRgAJL 16 | FEuLnhNhoXsbw7VZxcyrtFAK3FYMv4bBjZ4cMm999cwXZQ== 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /extensions/loggers/file_logger_utilities.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | /** 22 | * Find the first logfile id we may use 23 | * 24 | * @param basename the filename pattern (everything before the nnn.txt) 25 | * @return the highest number in use 26 | */ 27 | unsigned long find_first_logfile_id(const std::string& basename); 28 | -------------------------------------------------------------------------------- /include/memcached/util.h: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_H 2 | #define UTIL_H 3 | /* 4 | * Wrappers around strtoull/strtoll that are safer and easier to 5 | * use. For tests and assumptions, see internal_tests.c. 6 | * 7 | * str a NULL-terminated base decimal 10 unsigned integer 8 | * out out parameter, if conversion succeeded 9 | * 10 | * returns true if conversion succeeded. 11 | */ 12 | #include 13 | #include 14 | #include 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | MEMCACHED_PUBLIC_API bool safe_strtoull(const char *str, uint64_t *out) CB_ATTR_NONNULL(1,2); 21 | MEMCACHED_PUBLIC_API bool safe_strtoll(const char *str, int64_t *out) CB_ATTR_NONNULL(1,2); 22 | MEMCACHED_PUBLIC_API bool safe_strtoul(const char *str, uint32_t *out) CB_ATTR_NONNULL(1,2); 23 | MEMCACHED_PUBLIC_API bool safe_strtol(const char *str, int32_t *out) CB_ATTR_NONNULL(1,2); 24 | MEMCACHED_PUBLIC_API bool safe_strtof(const char *str, float *out) CB_ATTR_NONNULL(1,2); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif /* __cplusplus */ 29 | #endif 30 | -------------------------------------------------------------------------------- /tests/memory_tracking_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | IF (NOT MEMORY_ALLOCATOR STREQUAL "system") 2 | # Need to ensure that the directory containing 3 | # memcached_memory_tracking_test is added to the RPATH so we can 4 | # successfully dlopen() the plugin. 5 | LINK_DIRECTORIES(${Memcached_BINARY_DIR}) 6 | 7 | ADD_EXECUTABLE(memcached_memory_tracking_test 8 | $ 9 | ${Memcached_SOURCE_DIR}/utilities/extension_loggers.cc 10 | memory_tracking_test.cc) 11 | TARGET_LINK_LIBRARIES(memcached_memory_tracking_test platform gtest ${MALLOC_LIBRARIES}) 12 | ADD_TEST(NAME memcached-memory-tracking COMMAND memcached_memory_tracking_test) 13 | 14 | ADD_LIBRARY(memcached_memory_tracking_plugin MODULE 15 | memory_tracking_plugin.cc) 16 | TARGET_LINK_LIBRARIES(memcached_memory_tracking_plugin platform) 17 | SET_TARGET_PROPERTIES(memcached_memory_tracking_plugin PROPERTIES PREFIX "") 18 | IF(APPLE) 19 | SET_TARGET_PROPERTIES(memcached_memory_tracking_plugin PROPERTIES 20 | SUFFIX ".dylib") 21 | ENDIF(APPLE) 22 | ENDIF (NOT MEMORY_ALLOCATOR STREQUAL "system") 23 | -------------------------------------------------------------------------------- /include/mcbp/protocol/datatype.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | namespace cb { 22 | namespace mcbp { 23 | 24 | /** 25 | * Definition of the data types in the packet 26 | * See section 3.4 Data Types 27 | */ 28 | 29 | enum class Datatype : uint8_t { Raw = 0, JSON = 1, Snappy = 2, Xattr = 4 }; 30 | } // namespace mcbp 31 | } // namespace cb 32 | -------------------------------------------------------------------------------- /include/memcached/syslog.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | 3 | #ifndef SYSLOG_H 4 | #define SYSLOG_H 5 | 6 | /* 7 | * Defines the structures required to hold syslog compliant event. 8 | * As stated in the Syslog Protocol, (standardized by the IETF in RFC 5424). 9 | */ 10 | 11 | #include 12 | 13 | 14 | typedef enum { 15 | 16 | SYSLOG_EMERGENCY=0, 17 | SYSLOG_ALERT=1, 18 | SYSLOG_CRITICAL=2, 19 | SYSLOG_ERROR=3, 20 | SYSLOG_WARNING=4, 21 | SYSLOG_NOTICE=5, 22 | SYSLOG_INFORMATIONAL=6, 23 | SYSLOG_DEBUG=7, 24 | SYSLOG_UNKNOWN=8 25 | 26 | } SyslogSeverity; 27 | 28 | 29 | 30 | typedef struct { 31 | 32 | uint8_t prival; /* range 0...191 */ 33 | uint8_t version; /* 0...99 */ 34 | char hostname[256]; /* max 255 char */ 35 | char app_name[49]; /* max 48 char */ 36 | uint64_t procid; 37 | EventID msgid; 38 | time_t time; 39 | uint32_t time_secfrac; /* 0..999999 */ 40 | char msg[2048]; 41 | char sd[2048]; 42 | 43 | }SyslogEvent; 44 | 45 | #endif /*SYSLOG_EVENTS_H */ 46 | -------------------------------------------------------------------------------- /tests/cbnt_tests/cbnt_test_list.yml: -------------------------------------------------------------------------------- 1 | - test: perfsuite 2 | command: "build/memcached/engine_testapp -E build/ep-engine/ep.so -T build/ep-engine/ep_perfsuite.so -v -e dbname=./value_eviction_perf -f xml" 3 | output: 4 | - "output.1_bucket_1_thread_baseline.xml" 5 | - "output.1_buckets_4_threads_baseline.xml" 6 | - "output.2_buckets_2_threads_baseline.xml" 7 | - "output.4_buckets_4_threads_baseline.xml" 8 | - "output.DCP_In-memory_(BINARY-RAND)_[As_is_vs._Compress].xml" 9 | - "output.DCP_In-memory_(JSON-PADDED)_[As_is_vs._Compress].xml" 10 | - "output.DCP_In-memory_(JSON-RAND)_[As_is_vs._Compress].xml" 11 | - "output.With_background_DCP.xml" 12 | - "output.With_background_TAP.xml" 13 | - "output.With_constant_Expiry_pager.xml" 14 | - "output.With_constant_defragmention.xml" 15 | - test: hashtable 16 | command: 'build/ep-engine/ep-engine_hash_table_test --gtest_filter="*Add" --gtest_output=xml' 17 | output: "test_detail.xml" 18 | - test: subdoc_perf 19 | command: 'build/memcached/memcached_testapp -e --gtest_output=xml --gtest_filter="*Perf*"' 20 | output: "test_detail.xml" 21 | -------------------------------------------------------------------------------- /daemon/mc_time.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Time keeping for memcached. 4 | */ 5 | 6 | #include "memcached/types.h" 7 | 8 | #ifndef MC_TIME_H 9 | #define MC_TIME_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | /* 16 | * Initialise this module. 17 | */ 18 | void mc_time_init(struct event_base* ev_base); 19 | 20 | /* 21 | * Return a monotonically increasing value. 22 | * The value returned represents seconds since memcached started. 23 | */ 24 | rel_time_t mc_time_get_current_time(void); 25 | 26 | /* 27 | * Convert a relative time value to an absolute time. 28 | * 29 | * Note that the following usage approximates gettimeofday() 30 | * I.e. seconds since EPOCH without actually calling gettimeofday. 31 | * 32 | * time_convert_to_abs_time(time_get_current_time()); 33 | */ 34 | time_t mc_time_convert_to_abs_time(const rel_time_t rel_time); 35 | 36 | /* 37 | * Convert a time stamp to an absolute time stamp. 38 | */ 39 | rel_time_t mc_time_convert_to_real_time(const time_t t); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | #endif 45 | -------------------------------------------------------------------------------- /cbsasl/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Couchbase, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef CBSASL_UTIL_H_ 18 | #define CBSASL_UTIL_H_ 1 19 | 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /* Compare a and b without revealing their content by short-circuiting */ 27 | int cbsasl_secure_compare(const char* a, size_t alen, const char* b, 28 | size_t blen); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif /* CBSASL_UTIL_H_ */ 35 | -------------------------------------------------------------------------------- /daemon/protocol/mcbp/dcp_add_failover_log.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | /** Callback from the engine adding the response */ 23 | ENGINE_ERROR_CODE add_failover_log(vbucket_failover_t* entries, 24 | size_t nentries, 25 | const void* cookie); 26 | -------------------------------------------------------------------------------- /include/memcached/events.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2014 Couchbase, Inc 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef EVENTS_H 19 | #define EVENTS_H 20 | 21 | /* 22 | * Defines all the type of events that can be raised. 23 | * The types are outside of the syslog protocol standard. 24 | */ 25 | 26 | typedef enum { 27 | 28 | GENERIC_EVENT=0, 29 | STATE_CHANGE_EVENT=1, 30 | OUT_OF_MEMORY_EVENT=2 31 | 32 | } EventID; 33 | 34 | #endif /*EVENTS_H */ 35 | -------------------------------------------------------------------------------- /cbsasl/pwfile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Couchbase, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "cbsasl/cbsasl.h" 19 | #include "user.h" 20 | #include 21 | 22 | /** 23 | * Searches for a user entry for the specified user. 24 | * 25 | * @param user the username to search for 26 | * @param user updated with the user information if found 27 | * @return true if user exists, false otherwise 28 | */ 29 | bool find_user(const std::string& username, cb::sasl::User &user); 30 | 31 | cbsasl_error_t load_user_db(void); 32 | 33 | void free_user_ht(void); 34 | -------------------------------------------------------------------------------- /tests/cbsasl_pwconv_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(cbsasl_pwconv_test 2 | pwconv_test.cc 3 | 4 | ${Memcached_SOURCE_DIR}/include/cbcrypto/cbcrypto.h 5 | ${Memcached_SOURCE_DIR}/cbsasl/log.cc 6 | ${Memcached_SOURCE_DIR}/cbsasl/password_database.cc 7 | ${Memcached_SOURCE_DIR}/cbsasl/password_database.h 8 | ${Memcached_SOURCE_DIR}/cbsasl/plain/check_password.cc 9 | ${Memcached_SOURCE_DIR}/cbsasl/plain/check_password.h 10 | ${Memcached_SOURCE_DIR}/cbsasl/pwconv.cc 11 | ${Memcached_SOURCE_DIR}/cbsasl/pwconv.h 12 | ${Memcached_SOURCE_DIR}/cbsasl/user.cc 13 | ${Memcached_SOURCE_DIR}/cbsasl/user.h 14 | ${Memcached_SOURCE_DIR}/cbsasl/strcmp.cc 15 | ) 16 | TARGET_LINK_LIBRARIES(cbsasl_pwconv_test 17 | gtest_main 18 | gtest 19 | cbsasl 20 | platform 21 | cJSON) 22 | ADD_TEST(NAME cbsasl-pwconv-test 23 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 24 | COMMAND cbsasl_pwconv_test) 25 | -------------------------------------------------------------------------------- /daemon/net_buf.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | /** 22 | * The structure representing a network buffer 23 | */ 24 | struct net_buf { 25 | /** start of allocated buffer */ 26 | char* buf; 27 | /** but if we parsed some already, this is where we stopped */ 28 | char* curr; 29 | /** total allocated size of buf */ 30 | uint32_t size; 31 | /** how much data, starting from curr, do we have unparsed */ 32 | uint32_t bytes; 33 | }; 34 | -------------------------------------------------------------------------------- /programs/cbtrace/memorymap.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #ifdef WIN32 20 | #include 21 | #endif 22 | 23 | #include 24 | 25 | class MemoryMappedFile { 26 | public: 27 | MemoryMappedFile(); 28 | 29 | ~MemoryMappedFile(); 30 | 31 | void create(const char* file); 32 | 33 | void* root; 34 | size_t size; 35 | 36 | private: 37 | #ifdef WIN32 38 | HANDLE handle; 39 | HANDLE mapping; 40 | #else 41 | FILE* fp; 42 | #endif 43 | }; 44 | 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Welcome to the Couchbase _memcached_ project. 2 | 3 | This started as Couchbase's fork of the upstream `memcached` project. 4 | It has subsequently evolved since then, so while it shares a name with 5 | the upstream project many other things have changed, apart from the 6 | name :) For now it's simpler to consider this as the frontend of the 7 | Couchbase key-value engine. The primary backend of KV-engine is the 8 | eventually persistent engine - 9 | [ep-engine](https://github.com/couchbase/ep-engine). 10 | 11 | # Architecture 12 | 13 | * [KV-Engine Architecture](docs/Architecture.md) 14 | * [CBSASL](cbsasl/CBSASL.md) 15 | * [Audit](auditd/README.md) 16 | * [Error Handling Best Practices](docs/ErrorHandling.md) 17 | * [Event Tracing / Phosphor](docs/Tracing.md) 18 | * [Document attributes](docs/Document.md) 19 | * [Environment variables](docs/EnvironmentVariables.md) 20 | * [Role Based Access Control (RBAC)](docs/rbac.md) 21 | * [SSL Client Certificate](docs/ssl_client_cert.md) 22 | 23 | # Protocols 24 | 25 | * [Memcached Binary Protocol](docs/BinaryProtocol.md) 26 | * [SASL](docs/sasl.md) 27 | * [TAP](docs/TAP.md) 28 | 29 | # Tools 30 | 31 | * [Analyze jemalloc memory statistics](scripts/jemalloc/jemalloc_analyse.md) 32 | -------------------------------------------------------------------------------- /tests/cert/parse-test.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDKDCCApGgAwIBAgIJALE2RC7jwGczMA0GCSqGSIb3DQEBBQUAMEgxCzAJBgNV 3 | BAYTAk5PMRYwFAYDVQQKEw1Db3VjaGJhc2UgSW5jMQ8wDQYDVQQLEwZrdiBlbmcx 4 | EDAOBgNVBAMTB1Jvb3QgQ0EwHhcNMTcwNDA2MTkxMTAwWhcNMjcwNDA0MTkxMTAw 5 | WjBIMQswCQYDVQQGEwJOTzESMBAGA1UECgwJQ291Y2hiYXNlMQ8wDQYDVQQLDAZr 6 | dl9lbmcxFDASBgNVBAMMC3Rlc3RhcHBuYW1lMIGfMA0GCSqGSIb3DQEBAQUAA4GN 7 | ADCBiQKBgQDK6UMYTIlTwmoVT/rE/wwHue4CPHXN3aPn/FXnF6z1bTvMEF5+1C/s 8 | MicGywj7wESej0nhx2YYWWMIrkJKPmNU4mpGyqXWBFTl04eg6DAiQb+s+KvyfRQc 9 | RCWN/I7l7dm3lz7aY/qyoysvn9GwRw+s8HynqKxFW85j7uuY/12NfwIDAQABo4IB 10 | GDCCARQwHQYDVR0OBBYEFFsjC/b+7nt4jfIyDn+JMT1Qhvi+MHgGA1UdIwRxMG+A 11 | FPEoNd4zrllRWzLVftKjrOe7NEoGoUykSjBIMQswCQYDVQQGEwJOTzEWMBQGA1UE 12 | ChMNQ291Y2hiYXNlIEluYzEPMA0GA1UECxMGa3YgZW5nMRAwDgYDVQQDEwdSb290 13 | IENBggkA80epdAT27gcwDAYDVR0TBAUwAwEB/zBrBgNVHREEZDBihhB1cm46bGk6 14 | dGVzdHVybF8xhhllbWFpbDp0ZXN0YXBwQGV4YW1wbGUuY29thiVjb3VjaGJhc2U6 15 | Ly9teXVzZXJAbXljbHVzdGVyL215YnVja2V0ggxNeVNlcnZlck5hbWUwDQYJKoZI 16 | hvcNAQEFBQADgYEAF46N8Lj73MsxHhZnCnqCRwIK1aF6gfrTpclW1TlNypae2gBQ 17 | m9700fpqvG9aLe/s6OJXKimTyuHrbyszxNWjnpSL5XnU/a41VlvhxiMYwAKl4Vqr 18 | Qdh3YYP0j/6wDNi2r3H6q++S2wUC0Ek1ElTunoWZDZTVTP8XqGtNWqQDsAU= 19 | -----END CERTIFICATE----- 20 | -------------------------------------------------------------------------------- /daemon/task.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "task.h" 19 | #include "executor.h" 20 | 21 | void Task::makeRunnable() { 22 | if (executor == nullptr) { 23 | throw std::logic_error("task need to be scheduled"); 24 | } 25 | executor->makeRunnable(this); 26 | } 27 | 28 | void Task::makeRunnable(ProcessClock::time_point time) { 29 | if (executor == nullptr) { 30 | throw std::logic_error("task need to be scheduled"); 31 | } 32 | executor->makeRunnable(*this, time); 33 | } 34 | -------------------------------------------------------------------------------- /auditd/src/configureevent.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #ifndef CONFIGUREEVENT_H 18 | #define CONFIGUREEVENT_H 19 | 20 | #include "event.h" 21 | 22 | class Audit; 23 | 24 | class ConfigureEvent : public Event { 25 | public: 26 | const void *cookie; 27 | const std::string file; 28 | 29 | ConfigureEvent(const char* configfile, const void* c) 30 | : cookie(c), file(configfile) {} 31 | 32 | virtual bool process(Audit& audit) override; 33 | 34 | virtual ~ConfigureEvent() {} 35 | 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /daemon/alloc_hooks.def: -------------------------------------------------------------------------------- 1 | 2 | /* X-macros for static methods making up an alloc hooks class. 3 | * macro arguments: 4 | * method_name 5 | * return_type 6 | * arguments 7 | * 8 | * Example usage: 9 | * 10 | * class MyAllocHooks { 11 | * public: 12 | * #define X(name, ret, args) static ret name args; 13 | * #include "alloc_hooks.def" 14 | * #undef X 15 | * }; 16 | */ 17 | 18 | #if !defined(X) 19 | #error define an X(name, ret, args) macro before including this file. 20 | #endif 21 | 22 | X(initialize, void, ()) 23 | X(add_new_hook, bool, (void (* hook)(const void* ptr, size_t size))) 24 | X(remove_new_hook, bool, (void (* hook)(const void* ptr, size_t size))) 25 | X(add_delete_hook, bool, (void (* hook)(const void* ptr))) 26 | X(remove_delete_hook, bool, (void (* hook)(const void* ptr))) 27 | X(get_extra_stats_size, int, ()) 28 | X(get_allocator_stats, void, (allocator_stats* stats)) 29 | X(get_allocation_size, size_t, (const void* ptr)) 30 | X(get_detailed_stats, void, (char* buffer, int size)) 31 | X(release_free_memory, void, ()) 32 | X(enable_thread_cache, bool, (bool enable)) 33 | X(get_allocator_property, bool, (const char* name, size_t* value)) 34 | X(set_allocator_property, int, (const char* name, void* newp, size_t newlen)) 35 | -------------------------------------------------------------------------------- /include/memcached/collections.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #ifndef MEMCACHED_ENGINE_H 20 | #error "Please include memcached/engine.h instead" 21 | #endif 22 | 23 | #include 24 | #include "memcached/engine_error.h" 25 | 26 | struct collections_interface { 27 | /** 28 | * Inform the engine of the current collection manifest (a JSON document) 29 | */ 30 | cb::engine_error (*set_manifest)(ENGINE_HANDLE* handle, 31 | cb::const_char_buffer json); 32 | }; -------------------------------------------------------------------------------- /auditd/src/configureevent.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "configureevent.h" 19 | #include "audit.h" 20 | 21 | bool ConfigureEvent::process(Audit& audit) { 22 | // do the configuration 23 | audit.configfile.assign(file); 24 | if (audit.configure()) { 25 | audit.notify_io_complete(cookie, ENGINE_SUCCESS); 26 | return true; 27 | } else { 28 | Audit::log_error(AuditErrorCode::CONFIGURATION_ERROR); 29 | audit.notify_io_complete(cookie, ENGINE_FAILED); 30 | return false; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /daemon/breakpad.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include "config.h" 20 | #include "settings.h" 21 | 22 | /** 23 | * Initialize breakpad based on the specified settings struct. 24 | * 25 | * The function may be called multiple times and allow for reconfiguration 26 | * of the breakpad settings. 27 | */ 28 | void initialize_breakpad(const BreakpadSettings& settings); 29 | 30 | /** 31 | * Cleaning up when breakpad no longer needed 32 | * (Assuming it is enabled and has been initialized) 33 | */ 34 | void destroy_breakpad(void); 35 | -------------------------------------------------------------------------------- /testsuite/breakdancer/disable_optimize.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | #ifndef DISABLE_OPTIMIZE_H 3 | #define DISABLE_OPTIMIZE_H 1 4 | 5 | /* According to MB-11846 we have some misconfigured vm's unable to 6 | * compile the source code without enabling optimization. Add a workaround 7 | * for those vm's until they're fixed 8 | */ 9 | #ifndef COUCHBASE_OPTIMIZE_BREAKDANCER_TEST 10 | 11 | /* avoid wasting time trying to optimize those countless test functions */ 12 | #if defined(__clang__) 13 | 14 | 15 | /* 16 | * Works for Alk since clang-3.5. 17 | * Unfortunately it looks like Apple have their own versioning scheme for 18 | * clang, because mine (Trond) reports itself as 5.1 and does not have 19 | * the pragma. 20 | */ 21 | 22 | #if ((__clang_major__ * 0x100 + __clang_minor) >= 0x305) && !defined(__APPLE__) 23 | #pragma clang optimize off 24 | #endif 25 | 26 | #elif defined(__GNUC__) 27 | /* 28 | * gcc docs indicate that pragma optimize is supported since 4.4. Earlier 29 | * versions will emit harmless warning. 30 | */ 31 | #if ((__GNUC__ * 0x100 + __GNUC_MINOR__) >= 0x0404) 32 | #pragma GCC optimize ("O0") 33 | #endif 34 | 35 | #endif /* __GNUC__ */ 36 | 37 | #endif /* COUCHBASE_OPTIMIZE_BREAKDANCER_TEST */ 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /cbsasl/strcmp.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2014 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include 19 | #include "util.h" 20 | 21 | int cbsasl_secure_compare(const char *a, size_t alen, 22 | const char *b, size_t blen) 23 | { 24 | size_t xx; 25 | size_t yi = 0; 26 | size_t bi = 0; 27 | int acc = (int)alen ^ (int)blen; 28 | 29 | for (xx = 0; xx < alen; ++xx) { 30 | acc |= a[xx] ^ b[bi]; 31 | if (bi < blen) { 32 | ++bi; 33 | } else { 34 | ++yi; 35 | } 36 | } 37 | 38 | return acc; 39 | } 40 | -------------------------------------------------------------------------------- /testsuite/breakdancer/suite_stubs.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | #ifndef TESTSUITE_H 3 | #define TESTSUITE_H 1 4 | 5 | #include "disable_optimize.h" 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | MEMCACHED_PUBLIC_API 16 | engine_test_t* get_tests(void); 17 | 18 | MEMCACHED_PUBLIC_API 19 | bool setup_suite(struct test_harness *th); 20 | 21 | 22 | bool test_setup(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1); 23 | bool teardown(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1); 24 | void delay(int amt); 25 | void add(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1); 26 | void flush(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1); 27 | void del(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1); 28 | void set(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1); 29 | 30 | void checkValue(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char* exp); 31 | void assertNotExists(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1); 32 | 33 | #define assertHasError() cb_assert(hasError) 34 | #define assertHasNoError() cb_assert(!hasError) 35 | 36 | extern int expiry; 37 | extern bool hasError; 38 | extern struct test_harness testHarness; 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif /* SUITE_STUBS_H */ 45 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | STEPS FOR CONTRIBUTING CODE 2 | 3 | Github "pull requests" may (unfortunately?) not be used to submit a fix 4 | to this project. Code changes needs to go through our code review system 5 | and our commit validation system. 6 | 7 | # Sign our Contributor License Agreement 8 | 9 | Contributor License Agreements (CLAs) are common for projects under the 10 | Apache license, and typically serve to grant control of the code to a central 11 | entity. Because our code is available under the Apache License, signing the 12 | CLA doesn’t prevent you from using your code however you like, but it does 13 | give Couchbase the ability to defend the source legally and build and maintain 14 | a business around the technology. 15 | 16 | 1) [Join our review site](http://review.couchbase.org/) 17 | 2) Log into the review site. 18 | 3) [Fill out the agreement](http://review.couchbase.org/#/settings/agreements) 19 | under *Settings* > *Agreements* 20 | 21 | # Make your changes and upload your changes 22 | 23 | Once you're happy with your code changes upload your changes to the review site 24 | and add "kv_engine_dev" as the reviewers. The commit validation system will 25 | automatically build your change and run the unit tests. 26 | 27 | For more information, see [Couchbase Open Source Projects](http://developer.couchbase.com/open-source-projects) 28 | -------------------------------------------------------------------------------- /auditd/src/event.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #ifndef EVENT_H 18 | #define EVENT_H 19 | 20 | #include 21 | #include 22 | 23 | class Audit; 24 | 25 | class Event { 26 | public: 27 | const uint32_t id; 28 | const std::string payload; 29 | 30 | // Constructor required for ConfigureEvent 31 | Event() 32 | : id(0) {} 33 | 34 | Event(const uint32_t event_id, const char* p, 35 | size_t length) 36 | : id(event_id), 37 | payload(p,length) {} 38 | 39 | virtual bool process(Audit& audit); 40 | 41 | virtual ~Event() {} 42 | 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /include/mcbp/protocol/magic.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | namespace cb { 22 | namespace mcbp { 23 | /** 24 | * Definition of the legal "magic" values used in a packet. 25 | * See section 3.1 Magic byte 26 | */ 27 | enum class Magic : uint8_t { 28 | /// Request packet from client to server 29 | ClientRequest = 0x80, 30 | /// Response packet from server to client 31 | ClientResponse = 0x81, 32 | /// Request packet from server to client 33 | ServerRequest = 0x82, 34 | /// Response packet from client to server 35 | ServerResponse = 0x83 36 | }; 37 | } // namespace mcbp 38 | } // namespace cb 39 | -------------------------------------------------------------------------------- /extensions/loggers/blackhole_logger.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | #include "config.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "extensions/protocol_extension.h" 8 | 9 | static const char *get_name(void) { 10 | return "blackhole"; 11 | } 12 | 13 | static void logger_log(EXTENSION_LOG_LEVEL severity, 14 | const void* client_cookie, 15 | const char *fmt, ...) 16 | { 17 | (void)severity; 18 | (void)client_cookie; 19 | (void)fmt; 20 | } 21 | 22 | static void logger_shutdown(bool force) { 23 | /* EMPTY */ 24 | } 25 | 26 | static EXTENSION_LOGGER_DESCRIPTOR descriptor; 27 | 28 | MEMCACHED_PUBLIC_API 29 | EXTENSION_ERROR_CODE memcached_extensions_initialize(const char *config, 30 | GET_SERVER_API get_server_api) { 31 | SERVER_HANDLE_V1 *sapi = get_server_api(); 32 | descriptor.get_name = get_name; 33 | descriptor.log = logger_log; 34 | descriptor.shutdown = logger_shutdown; 35 | 36 | (void)config; 37 | if (sapi == NULL) { 38 | return EXTENSION_FATAL; 39 | } 40 | 41 | if (!sapi->extension->register_extension(EXTENSION_LOGGER, &descriptor)) { 42 | return EXTENSION_FATAL; 43 | } 44 | 45 | return EXTENSION_SUCCESS; 46 | } 47 | -------------------------------------------------------------------------------- /daemon/libevent_locking.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #include "libevent_locking.h" 18 | 19 | #include 20 | #include 21 | 22 | void setup_libevent_locking() { 23 | bool failed; 24 | #if defined(EVTHREAD_USE_WINDOWS_THREADS_IMPLEMENTED) 25 | failed = evthread_use_windows_threads() == -1; 26 | #elif defined(EVTHREAD_USE_PTHREADS_IMPLEMENTED) 27 | failed = evthread_use_pthreads() == -1; 28 | #else 29 | #error "No locking mechanism for libevent available!" 30 | #endif 31 | 32 | if (failed) { 33 | std::cerr << "Failed to enable libevent locking. Terminating program" 34 | << std::endl; 35 | exit(EXIT_FAILURE); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /daemon/protocol/mcbp/utilities.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #include "utilities.h" 18 | 19 | McbpConnection* cookie2mcbp(const void* void_cookie, const char* function) { 20 | const auto * cookie = reinterpret_cast(void_cookie); 21 | if (cookie == nullptr) { 22 | throw std::invalid_argument(std::string(function) + 23 | ": cookie is nullptr"); 24 | } 25 | cookie->validate(); 26 | auto* c = dynamic_cast(cookie->connection); 27 | if (c == nullptr) { 28 | throw std::invalid_argument(std::string(function) + 29 | ": connection is nullptr"); 30 | } 31 | return c; 32 | } 33 | -------------------------------------------------------------------------------- /include/cbsasl/visibility.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2013 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #ifndef CBSASL_VISIBILITY_H 18 | #define CBSASL_VISIBILITY_H 1 19 | 20 | #ifdef BUILDING_CBSASL 21 | 22 | #if defined (__SUNPRO_C) && (__SUNPRO_C >= 0x550) 23 | #define CBSASL_PUBLIC_API __global 24 | #elif defined __GNUC__ 25 | #define CBSASL_PUBLIC_API __attribute__ ((visibility("default"))) 26 | #elif defined(_MSC_VER) 27 | #define CBSASL_PUBLIC_API extern __declspec(dllexport) 28 | #else 29 | /* unknown compiler */ 30 | #define CBSASL_PUBLIC_API 31 | #endif 32 | 33 | #else 34 | 35 | #if defined(_MSC_VER) 36 | #define CBSASL_PUBLIC_API extern __declspec(dllimport) 37 | #else 38 | #define CBSASL_PUBLIC_API 39 | #endif 40 | 41 | #endif 42 | 43 | #endif /* CBSASL_VISIBILITY_H */ 44 | -------------------------------------------------------------------------------- /daemon/runtime.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * Due to the fact that the memcached daemon is written in C we need 20 | * this little wrapper to provide atomics functionality without having 21 | * to reinvent the wheel 22 | */ 23 | #pragma once 24 | 25 | #include 26 | #include 27 | 28 | bool is_server_initialized(void); 29 | 30 | void set_server_initialized(bool enable); 31 | 32 | void set_ssl_cipher_list(const std::string& new_list); 33 | 34 | void set_ssl_ctx_cipher_list(SSL_CTX* ctx); 35 | 36 | void set_ssl_protocol_mask(const std::string& mask); 37 | 38 | void set_ssl_ctx_protocol_mask(SSL_CTX* ctx); 39 | 40 | class Audit; 41 | 42 | void set_audit_handle(Audit*); 43 | Audit* get_audit_handle(void); 44 | -------------------------------------------------------------------------------- /daemon/protocol/mcbp/dcp_deletion.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include "../../memcached.h" 20 | 21 | void dcp_deletion_executor(McbpConnection* c, void* packet); 22 | 23 | ENGINE_ERROR_CODE dcp_message_deletion(const void* void_cookie, 24 | uint32_t opaque, 25 | item* it, 26 | uint16_t vbucket, 27 | uint64_t by_seqno, 28 | uint64_t rev_seqno, 29 | const void* meta, 30 | uint16_t nmeta, 31 | uint8_t collection_len); 32 | -------------------------------------------------------------------------------- /daemon/timing_interval.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "timing_interval.h" 19 | 20 | using namespace cb::sampling; 21 | 22 | Interval& Interval::operator+=(const Interval& other) { 23 | count += other.count; 24 | duration_ns += other.duration_ns; 25 | return *this; 26 | } 27 | 28 | void Interval::reset() { 29 | count = 0; 30 | duration_ns = 0; 31 | } 32 | 33 | void IntervalSeries::reset() { 34 | intervals.reset(); 35 | } 36 | 37 | Interval IntervalSeries::getAggregate() const { 38 | Interval ret; 39 | for (auto& i : intervals) { 40 | ret += i; 41 | } 42 | return ret; 43 | } 44 | 45 | void IntervalSeries::sample(const Interval& stats) { 46 | intervals.push_back(stats); 47 | } 48 | -------------------------------------------------------------------------------- /tests/logger_test/logger_test_common.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | 22 | #include 23 | #include 24 | 25 | extern EXTENSION_LOGGER_DESCRIPTOR *logger; 26 | 27 | extern "C" { 28 | EXTENSION_LOG_LEVEL get_log_level(void); 29 | bool register_extension(extension_type_t type, void *extension); 30 | void register_callback(ENGINE_HANDLE *eh, 31 | ENGINE_EVENT_TYPE type, 32 | EVENT_CALLBACK cb, 33 | const void *cb_data); 34 | SERVER_HANDLE_V1 *get_server_api(void); 35 | } 36 | 37 | // Removes all files in the specified vector 38 | void remove_files(std::vector &files); 39 | -------------------------------------------------------------------------------- /daemon/protocol/mcbp/dcp_expiration.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include "../../memcached.h" 20 | 21 | void dcp_expiration_executor(McbpConnection* c, void* packet); 22 | 23 | ENGINE_ERROR_CODE dcp_message_expiration(const void* void_cookie, 24 | uint32_t opaque, 25 | item* it, 26 | uint16_t vbucket, 27 | uint64_t by_seqno, 28 | uint64_t rev_seqno, 29 | const void* meta, 30 | uint16_t nmeta, 31 | uint8_t collection_len); 32 | -------------------------------------------------------------------------------- /tests/mcbp/mcbp_test.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | /* 21 | * Memcached binary protocol validator tests. 22 | */ 23 | 24 | #include "config.h" 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | namespace BinaryProtocolValidator { 31 | 32 | class ValidatorTest : public ::testing::Test { 33 | public: 34 | ValidatorTest(); 35 | ~ValidatorTest(); 36 | 37 | virtual void SetUp() override; 38 | 39 | protected: 40 | protocol_binary_response_status validate(protocol_binary_command opcode, void* request); 41 | 42 | McbpValidatorChains validatorChains; 43 | event_base* ev; 44 | McbpConnection connection; 45 | }; 46 | 47 | } // namespace BinaryProtocolValidator 48 | -------------------------------------------------------------------------------- /tests/testapp/testapp_stats.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include "testapp_client_test.h" 20 | 21 | class StatsTest : public TestappClientTest { 22 | public: 23 | void SetUp() { 24 | TestappClientTest::SetUp(); 25 | // Let all tests start with an empty set of stats (There is 26 | // a special test case that tests that reset actually work) 27 | resetBucket(); 28 | } 29 | 30 | protected: 31 | void resetBucket() { 32 | MemcachedConnection& conn = getConnection(); 33 | ASSERT_NO_THROW(conn.authenticate("@admin", "password", "PLAIN")); 34 | ASSERT_NO_THROW(conn.selectBucket("default")); 35 | ASSERT_NO_THROW(conn.stats("reset")); 36 | ASSERT_NO_THROW(conn.reconnect()); 37 | } 38 | }; 39 | -------------------------------------------------------------------------------- /daemon/cookie.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "cookie.h" 19 | #include 20 | 21 | const std::string& Cookie::getErrorJson() { 22 | json_message.clear(); 23 | if (error_context.empty() && event_id.empty()) { 24 | return json_message; 25 | } 26 | 27 | unique_cJSON_ptr root(cJSON_CreateObject()); 28 | unique_cJSON_ptr error(cJSON_CreateObject()); 29 | if (!error_context.empty()) { 30 | cJSON_AddStringToObject(error.get(), "context", error_context.c_str()); 31 | } 32 | if (!event_id.empty()) { 33 | cJSON_AddStringToObject(error.get(), "ref", event_id.c_str()); 34 | } 35 | cJSON_AddItemToObject(root.get(), "error", error.release()); 36 | json_message = to_string(root, false); 37 | return json_message; 38 | } 39 | -------------------------------------------------------------------------------- /cbsasl/plain/check_password.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | namespace cb { 23 | namespace sasl { 24 | namespace plain { 25 | 26 | /** 27 | * Check if the supplied password match what's stored in the 28 | * provided user object 29 | * 30 | * @param conn the connection object trying to perform authentication 31 | * @param user the user object to check 32 | * @param password the password to compare 33 | * @return CBSASL_OK if the provided password match the supplied 34 | * password. 35 | */ 36 | cbsasl_error_t check_password(cbsasl_conn_t* conn, 37 | const cb::sasl::User& user, 38 | const std::string& password); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /include/cbsasl/saslauthd_config.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | namespace cb { 23 | namespace sasl { 24 | namespace saslauthd { 25 | 26 | /** 27 | * Set the path to use to access access saslauthd 28 | */ 29 | CBSASL_PUBLIC_API 30 | void set_socketpath(const std::string& path); 31 | 32 | /** 33 | * Get the path to the saslauthd socketpath 34 | */ 35 | 36 | CBSASL_PUBLIC_API 37 | std::string get_socketpath(); 38 | 39 | /** 40 | * Is saslauthd configured or not (may be used if you just want to 41 | * know if it exists or not (it grabs the socketpath and verifies 42 | * that it exists) 43 | */ 44 | CBSASL_PUBLIC_API 45 | bool is_configured(); 46 | } // namespace saslauthd 47 | } // namespace sasl 48 | } // namespace cb 49 | -------------------------------------------------------------------------------- /utilities/terminate_handler.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "config.h" 21 | 22 | #include 23 | 24 | /** 25 | * Interposes our own C++ terminate handler to print backtrace upon failures. 26 | * Chains to the default handler (if exists) after printing the backtrace, 27 | * then calls std::abort(). 28 | * @param logger the logger descriptor to use to print the backtrace in the 29 | * event of termination. If nullptr then will log directly to 30 | * stderr. 31 | */ 32 | void install_backtrace_terminate_handler(EXTENSION_LOGGER_DESCRIPTOR* logger = nullptr); 33 | 34 | /** 35 | * Control if our C++ terminate handler should include a backtrace or not. 36 | */ 37 | void set_terminate_handler_print_backtrace(bool print); 38 | -------------------------------------------------------------------------------- /auditd/etc/module_descriptors.json: -------------------------------------------------------------------------------- 1 | { 2 | "modules" : [ 3 | { 4 | "auditd" : { 5 | "startid" : 4096, 6 | "file" : "memcached/auditd/etc/auditd_descriptor.json", 7 | "header" : "memcached/auditd/auditd_audit_events.h" 8 | 9 | } 10 | }, 11 | { 12 | "ns_server" : { 13 | "startid" : 8192, 14 | "file" : "ns_server/etc/audit_descriptor.json" 15 | } 16 | }, 17 | { 18 | "xdcr" : { 19 | "startid" : 16384, 20 | "file" : "goproj/src/github.com/couchbase/goxdcr/etc/audit_descriptor.json" 21 | } 22 | }, 23 | { 24 | "memcached" : { 25 | "startid" : 20480, 26 | "file" : "memcached/etc/memcached_descriptor.json", 27 | "header":"memcached/memcached_audit_events.h" 28 | } 29 | }, 30 | { 31 | "fts" : { 32 | "startid" :24576, 33 | "file" : "goproj/src/github.com/couchbase/cbft/etc/audit_descriptor.json" 34 | } 35 | } 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /engines/default_engine/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_LIBRARY(default_engine SHARED 2 | assoc.cc 3 | assoc.h 4 | default_engine.cc 5 | default_engine_internal.h 6 | engine_manager.cc 7 | engine_manager.h 8 | items.cc 9 | items.h 10 | scrubber_task.cc 11 | scrubber_task.h 12 | slabs.cc 13 | slabs.h) 14 | 15 | SET_TARGET_PROPERTIES(default_engine PROPERTIES PREFIX "") 16 | 17 | IF (ENABLE_DTRACE) 18 | ADD_DEPENDENCIES(default_engine generate_memcached_dtrace_h) 19 | IF (DTRACE_NEED_INSTRUMENT) 20 | ADD_CUSTOM_COMMAND(TARGET default_engine PRE_LINK 21 | COMMAND 22 | ${DTRACE} -o de_dtrace.o 23 | -G 24 | -s ${Memcached_SOURCE_DIR}/memcached_dtrace.d 25 | *.o 26 | WORKING_DIRECTORY ${Memcached_BINARY_DIR}/engines/default_engine/CMakeFiles/default_engine.dir) 27 | SET_TARGET_PROPERTIES(default_engine PROPERTIES LINK_FLAGS 28 | "${Memcached_BINARY_DIR}/engines/default_engine/CMakeFiles/default_engine.dir/de_dtrace.o") 29 | ENDIF (DTRACE_NEED_INSTRUMENT) 30 | ENDIF (ENABLE_DTRACE) 31 | 32 | TARGET_LINK_LIBRARIES(default_engine engine_utilities mcd_util platform ${COUCHBASE_NETWORK_LIBS}) 33 | 34 | INSTALL(TARGETS default_engine 35 | RUNTIME DESTINATION bin 36 | LIBRARY DESTINATION lib 37 | ARCHIVE DESTINATION lib) 38 | -------------------------------------------------------------------------------- /engines/nobucket/nobucket.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* The "nobucket" is a bucket that just returnes "ENGINE_NO_BUCKET". This 19 | * bucket may be set as the "default" bucket for connections to avoid 20 | * having to check if a bucket is selected or not. 21 | */ 22 | #pragma once 23 | 24 | #include "config.h" 25 | #include 26 | #include 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | MEMCACHED_PUBLIC_API 33 | ENGINE_ERROR_CODE create_no_bucket_instance(uint64_t interface, 34 | GET_SERVER_API get_server_api, 35 | ENGINE_HANDLE **handle); 36 | 37 | 38 | MEMCACHED_PUBLIC_API 39 | void destroy_engine(void); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /daemon/main.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | extern "C" int memcached_main(int argc, char** argv); 18 | 19 | /** 20 | * This is the program entry point for memcached. We're building the 21 | * memcached source as a static archive so that we may link it into other 22 | * programs (like memcached_testapp) and run it inside the process. The 23 | * main motivation for doing so is to make the life a lot easier when 24 | * trying to debug a unit test case (so that you can set breakpoints in 25 | * the same IDE rather than having to add spin locks and attach another 26 | * debugger to the memcached process spawned by the test case etc) 27 | * 28 | * @param argc argument count 29 | * @param argv argument vector 30 | * @return the process exit number 31 | */ 32 | int main(int argc, char** argv) { 33 | return memcached_main(argc, argv); 34 | } 35 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 2003, Danga Interactive, Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following disclaimer 13 | in the documentation and/or other materials provided with the 14 | distribution. 15 | 16 | * Neither the name of the Danga Interactive nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2003, Danga Interactive, Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above 12 | copyright notice, this list of conditions and the following disclaimer 13 | in the documentation and/or other materials provided with the 14 | distribution. 15 | 16 | * Neither the name of the Danga Interactive nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /engines/default_engine/assoc.h: -------------------------------------------------------------------------------- 1 | #ifndef ASSOC_H 2 | #define ASSOC_H 3 | 4 | struct assoc { 5 | /* how many powers of 2's worth of buckets we use */ 6 | unsigned int hashpower; 7 | 8 | 9 | /* Main hash table. This is where we look except during expansion. */ 10 | hash_item** primary_hashtable; 11 | 12 | /* 13 | * Previous hash table. During expansion, we look here for keys that haven't 14 | * been moved over to the primary yet. 15 | */ 16 | hash_item** old_hashtable; 17 | 18 | /* Number of items in the hash table. */ 19 | unsigned int hash_items; 20 | 21 | /* Flag: Are we in the middle of expanding now? */ 22 | bool expanding; 23 | 24 | /* 25 | * During expansion we migrate values with bucket granularity; this is how 26 | * far we've gotten so far. Ranges from 0 .. hashsize(hashpower - 1) - 1. 27 | */ 28 | unsigned int expand_bucket; 29 | 30 | 31 | /* 32 | * serialise access to the hashtable 33 | */ 34 | cb_mutex_t lock; 35 | }; 36 | 37 | /* associative array */ 38 | ENGINE_ERROR_CODE assoc_init(struct default_engine *engine); 39 | void assoc_destroy(void); 40 | hash_item *assoc_find(struct default_engine *engine, uint32_t hash, 41 | const hash_key* key); 42 | int assoc_insert(struct default_engine *engine, uint32_t hash, 43 | hash_item *item); 44 | void assoc_delete(struct default_engine *engine, uint32_t hash, 45 | const hash_key* key); 46 | int start_assoc_maintenance_thread(struct default_engine *engine); 47 | void stop_assoc_maintenance_thread(struct default_engine *engine); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /include/mcbp/mcbp.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | 27 | // This file contains various methods for the Memcached Binary Protocol 28 | // used for backwards source compatibility 29 | #include 30 | 31 | 32 | #include 33 | #include 34 | 35 | namespace cb { 36 | namespace mcbp { 37 | 38 | /** 39 | * Dump a raw packet to the named stream (the packet is expected to contain 40 | * a valid packet) 41 | * 42 | * @param packet pointer to the first byte of a correctly encoded mcbp packet 43 | * @param out where to dump the bytes 44 | */ 45 | void dump(const uint8_t* packet, std::ostream& out); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tests/scripts_tests/runtests.cmake: -------------------------------------------------------------------------------- 1 | FILE(GLOB SAMPLE_ALLOCATOR_STATS 2 | ${SRC_DIR}/jemalloc_*.log 3 | ) 4 | FILE(COPY ${SAMPLE_ALLOCATOR_STATS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) 5 | 6 | IF("${COUCHBASE_MEMORY_ALLOCATOR}" STREQUAL "jemalloc") 7 | EXECUTE_PROCESS( 8 | COMMAND ${TEST_PROGRAM} 9 | ERROR_FILE ${CMAKE_CURRENT_BINARY_DIR}/jemalloc_current.log 10 | ) 11 | ENDIF() 12 | 13 | FOREACH(version 3.6 4.3.1 current) 14 | SET(INPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/jemalloc_${version}.log) 15 | SET(OUTPUT_FILE 16 | ${CMAKE_CURRENT_BINARY_DIR}/jemalloc_output_${version}.log) 17 | SET(COMPARISON_FILE 18 | ${SRC_DIR}/jemalloc_analyse_expected_output_${version}.log) 19 | 20 | IF(EXISTS ${INPUT_FILE}) 21 | EXECUTE_PROCESS( 22 | COMMAND ${PYTHON_EXECUTABLE} ${JEMALLOC_ANALYSE} 23 | INPUT_FILE ${INPUT_FILE} 24 | OUTPUT_FILE ${OUTPUT_FILE} 25 | ) 26 | 27 | EXECUTE_PROCESS( 28 | COMMAND ${CMAKE_COMMAND} -E compare_files 29 | ${OUTPUT_FILE} 30 | ${COMPARISON_FILE} 31 | RESULT_VARIABLE result 32 | ) 33 | 34 | IF(NOT "${result}" STREQUAL "0") 35 | message(FATAL_ERROR "jemalloc_analyse output does not " 36 | "match expected for version ${version}") 37 | ENDIF() 38 | ENDIF() 39 | ENDFOREACH() 40 | -------------------------------------------------------------------------------- /daemon/executorpool.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "executorpool.h" 19 | #include "task.h" 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | ExecutorPool::ExecutorPool(size_t sz) { 26 | roundRobin.store(0); 27 | executors.reserve(sz); 28 | for (size_t ii = 0; ii < sz; ++ii) { 29 | executors.emplace_back(createWorker()); 30 | } 31 | } 32 | 33 | void ExecutorPool::schedule(std::shared_ptr& task, bool runnable) { 34 | if (task->getMutex().try_lock()) { 35 | task->getMutex().unlock(); 36 | throw std::logic_error( 37 | "The mutex should be held when trying to schedule a event"); 38 | } 39 | 40 | executors[++roundRobin % executors.size()]->schedule(task, runnable); 41 | } 42 | 43 | void ExecutorPool::clockTick() { 44 | for (const auto& executor : executors) { 45 | executor->clockTick(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /daemon/darwin_zone.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2010 Couchbase, Inc 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * Support for replacing the default malloc zone on OS X, when using jemalloc 20 | * as the memory allocator. This is needed to allow us to insert wrappers 21 | * around (je)malloc & friends to perform allocation tracking for mem_used. 22 | */ 23 | 24 | #ifndef DARWIN_ZONE_H_ 25 | #define DARWIN_ZONE_H_ 26 | 27 | #include "alloc_hooks_types.h" 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | /* Register our wrapper zone as the system default allocator. The wrapper zone 34 | * simply forwards all requests to the "real" default allocator, adding in 35 | * memory tracking calls to the specified new_hook & delete_hook where necessary. 36 | */ 37 | void register_wrapper_zone(malloc_new_hook_t* new_hook, 38 | malloc_delete_hook_t* delete_hook); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif 43 | 44 | #endif /* DARWIN_ZONE_H_ */ 45 | -------------------------------------------------------------------------------- /auditd/etc/auditd_descriptor.json: -------------------------------------------------------------------------------- 1 | { 2 | "version" : 1, 3 | "module" : "auditd", 4 | "events" : [ 5 | { "id" : 4096, 6 | "name" : "configured audit daemon", 7 | "description" : "loaded configuration file for audit daemon", 8 | "sync" : false, 9 | "enabled" : true, 10 | "mandatory_fields" : { 11 | "timestamp" : "", 12 | "real_userid" : {"source" : "", "user" : ""}, 13 | "hostname" : "", 14 | "version" : 1, 15 | "auditd_enabled" : true, 16 | "rotate_interval" : 1, 17 | "log_path" : "", 18 | "descriptors_path" : "" 19 | }, 20 | "optional_fields" : {} 21 | }, 22 | 23 | { "id" : 4097, 24 | "name" : "shutting down audit daemon", 25 | "description" : "The audit daemon is being shutdown", 26 | "sync" : false, 27 | "enabled" : true, 28 | "mandatory_fields" : { 29 | "timestamp" : "", 30 | "real_userid" : {"source" : "", "user" : ""} 31 | }, 32 | "optional_fields" : {} 33 | } 34 | 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /daemon/protocol/mcbp/unlock_context.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #include "engine_wrapper.h" 18 | #include "unlock_context.h" 19 | 20 | #include 21 | #include 22 | 23 | ENGINE_ERROR_CODE UnlockCommandContext::unlock() { 24 | auto ret = bucket_unlock(connection, key, vbucket, cas); 25 | if (ret == ENGINE_SUCCESS) { 26 | update_topkeys(key, &connection); 27 | mcbp_write_packet(&connection, PROTOCOL_BINARY_RESPONSE_SUCCESS); 28 | state = State::Done; 29 | } 30 | 31 | return ret; 32 | } 33 | 34 | ENGINE_ERROR_CODE UnlockCommandContext::step() { 35 | ENGINE_ERROR_CODE ret; 36 | do { 37 | switch (state) { 38 | case State::Unlock: 39 | ret = unlock(); 40 | break; 41 | case State::Done: 42 | return ENGINE_SUCCESS; 43 | } 44 | } while (ret == ENGINE_SUCCESS); 45 | 46 | return ret; 47 | } 48 | -------------------------------------------------------------------------------- /cbsasl/saslauthd_config.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #ifndef WIN32 22 | #include 23 | #endif 24 | 25 | cb::RWLock rwlock; 26 | std::string socketpath; 27 | 28 | CBSASL_PUBLIC_API 29 | void cb::sasl::saslauthd::set_socketpath(const std::string& path) { 30 | std::lock_guard guard(rwlock.writer()); 31 | socketpath.assign(path); 32 | } 33 | 34 | CBSASL_PUBLIC_API 35 | std::string cb::sasl::saslauthd::get_socketpath() { 36 | std::lock_guard guard(rwlock.reader()); 37 | return socketpath; 38 | } 39 | 40 | CBSASL_PUBLIC_API 41 | bool cb::sasl::saslauthd::is_configured() { 42 | #ifdef WIN32 43 | // saslauthd do not work on win32 44 | return false; 45 | #else 46 | const auto path = get_socketpath(); 47 | return !(path.empty() || access(path.c_str(), F_OK) == -1); 48 | #endif 49 | } 50 | -------------------------------------------------------------------------------- /tests/error_map_sanity_check/error_map_sanity_check.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Couchbase, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | 20 | /** 21 | * Small standalone program used to load and parse all of the error maps. 22 | * The motivation behind this program is to easily detect syntax errors 23 | * etc in one of the error_maps when being run from the commit validators 24 | * (as we normally run memcached with the blackhole logger so that the 25 | * error messages printed out by memcached wouldn't be shown anywhere). 26 | */ 27 | int main(int argc, char** argv) { 28 | if (argc != 2) { 29 | std::cerr << "Usage: " << argv[0] << " 20 | #include 21 | #include 22 | #include 23 | #include "ssl_utils.h" 24 | 25 | long decode_ssl_protocol(const std::string& protocol) { 26 | /* MB-12359 - Disable SSLv2 & SSLv3 due to POODLE */ 27 | long disallow = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3; 28 | 29 | std::string minimum(protocol); 30 | std::transform(minimum.begin(), minimum.end(), minimum.begin(), tolower); 31 | 32 | if (minimum.empty() || minimum == "tlsv1") { 33 | // nothing 34 | } else if (minimum == "tlsv1.1" || minimum == "tlsv1_1") { 35 | disallow |= SSL_OP_NO_TLSv1; 36 | } else if (minimum == "tlsv1.2" || minimum == "tlsv1_2") { 37 | disallow |= SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1; 38 | } else { 39 | throw std::invalid_argument("Unknown protocol: " + minimum); 40 | } 41 | 42 | return disallow; 43 | } 44 | -------------------------------------------------------------------------------- /tests/testapp/ssl_impl.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | /* 20 | * This file hides the #ifdef's and select the appropriate SSL 21 | * implementation to use. All of the different backends MUST provide 22 | * the following methods: 23 | */ 24 | 25 | /** 26 | * Create and connect the ssl_socket to the given port 27 | */ 28 | SOCKET create_connect_ssl_socket(in_port_t port); 29 | 30 | /** 31 | * Destroy and clean up the global ssl connection 32 | */ 33 | void destroy_ssl_socket(); 34 | 35 | /** 36 | * Send the provided buffer 37 | * 38 | * @param buf The data to send 39 | * @param len The size of the buffer 40 | * @return the number of bytes sent 41 | */ 42 | ssize_t phase_send_ssl(const void *buf, size_t len); 43 | 44 | /** 45 | * Receive the requested number of bytes 46 | * 47 | * @param buf Where to store the data 48 | * @param len The number of bytes to read 49 | * @return the number of bytes received 50 | */ 51 | ssize_t phase_recv_ssl(void *buf, size_t len); 52 | -------------------------------------------------------------------------------- /programs/hostname_utils.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #ifdef WIN32 23 | #include 24 | #else 25 | #include // sa_family_t 26 | #include // in_port_t 27 | #endif 28 | 29 | namespace cb { 30 | namespace inet { 31 | 32 | using HostSpec = std::tuple; 33 | 34 | /** 35 | * Parse an internet address in IPv4 or IPv6 format into a 36 | * host, port and family. 37 | * 38 | * IPv4 address is specified as: hostname:port 39 | * IPv6 address is specified as: [::]:port 40 | * 41 | * @param host The string to parse; 42 | * @param port The port is used if none is specified in hostname 43 | * @returns hostname, port number and family of the resolved address 44 | * @throws std::runtime_exception if the port number cannot be determined 45 | */ 46 | HostSpec parse_hostname(const std::string& hostname, 47 | const std::string& port); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /time/timestamp_test.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | static char env[80]; 26 | 27 | int main(void) 28 | { 29 | time_t now = 1426239360; 30 | std::string expected("2015-03-13T02:36:00.000000-07:00"); 31 | std::string timezone("TZ=America/Los_Angeles"); 32 | 33 | #ifdef _MSC_VER 34 | timezone.assign("TZ=PST8PDT"); 35 | #endif 36 | 37 | strcpy(env, timezone.c_str()); 38 | putenv(env); 39 | 40 | tzset(); 41 | 42 | std::string timestamp = ISOTime::generatetimestamp(now, 0); 43 | if (timestamp != expected) { 44 | std::cerr << "Comparison failed" << std::endl 45 | << " Expected [" << expected << "]" << std::endl 46 | << " got [" << timestamp << "]" << std::endl; 47 | return EXIT_FAILURE; 48 | } 49 | 50 | return EXIT_SUCCESS; 51 | } 52 | -------------------------------------------------------------------------------- /cbsasl/strerror.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include 19 | #include "cbsasl_internal.h" 20 | 21 | 22 | CBSASL_PUBLIC_API 23 | const char* cbsasl_strerror(cbsasl_conn_t* conn, 24 | cbsasl_error_t error) 25 | { 26 | switch (error) { 27 | case CBSASL_OK: 28 | return "Success"; 29 | case CBSASL_CONTINUE: 30 | return "Continue"; 31 | case CBSASL_FAIL: 32 | return "Fail"; 33 | case CBSASL_NOMEM: 34 | return "No memory"; 35 | case CBSASL_BADPARAM: 36 | return "Invalid parameters"; 37 | case CBSASL_NOMECH: 38 | return "No such mechanism"; 39 | case CBSASL_NOUSER: 40 | return "No such user"; 41 | case CBSASL_PWERR: 42 | return "Invalid password"; 43 | case CBSASL_NO_RBAC_PROFILE: 44 | return "User not defined in Couchbase"; 45 | } 46 | 47 | conn->errormsg.assign("Unknown error: " + std::to_string(error)); 48 | return conn->errormsg.c_str(); 49 | } 50 | -------------------------------------------------------------------------------- /extensions/loggers/file_logger_utilities.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #include 18 | #include "file_logger_utilities.h" 19 | 20 | unsigned long find_first_logfile_id(const std::string& basename) { 21 | unsigned long id = 0; 22 | 23 | auto files = cb::io::findFilesWithPrefix(basename); 24 | for (auto& file : files) { 25 | // the format of the name should be: 26 | // fnm.number.txt 27 | auto index = file.rfind(".txt"); 28 | if (index == std::string::npos) { 29 | continue; 30 | } 31 | 32 | file.resize(index); 33 | index = file.rfind('.'); 34 | if (index != std::string::npos) { 35 | try { 36 | unsigned long value = std::stoul(file.substr(index + 1)); 37 | if (value > id) { 38 | id = value + 1; 39 | } 40 | } catch (...) { 41 | // Ignore 42 | } 43 | } 44 | } 45 | 46 | return id; 47 | } 48 | -------------------------------------------------------------------------------- /daemon/config_parse.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2014 Couchbase, Inc 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * Configuration file parsing and handling. 20 | */ 21 | 22 | #ifndef CONFIG_PARSE_H 23 | #define CONFIG_PARSE_H 24 | 25 | #include 26 | 27 | #include "config.h" 28 | #include "memcached.h" 29 | 30 | void load_config_file(const char *filename, Settings& settings); 31 | 32 | /* Given a new, proposed config, check if it can be applied to the running 33 | * config. Returns true if all differences between new_cfg and the live config 34 | * can be applied, else returns false and updates error_msg to list of messages 35 | * describing what could not be applied. 36 | */ 37 | bool validate_proposed_config_changes(const char* new_cfg, cJSON* errors); 38 | 39 | 40 | /* perform a reload of the config file initially specified on the command-line. 41 | * Re-parses the file, and for settings which are permitted to be dynamically 42 | * changed, update the running memcached settings. 43 | */ 44 | void reload_config_file(void); 45 | 46 | #endif /* CONFIG_PARSE_H */ 47 | -------------------------------------------------------------------------------- /daemon/mcbp_executors.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | /* 20 | * The mcbp_executors files contains the implementation of the execution 21 | * callbacks for the memcached binary protocol. 22 | */ 23 | 24 | #include 25 | #include 26 | #include "connection_mcbp.h" 27 | 28 | typedef void (* mcbp_package_execute)(McbpConnection *c, void* packet); 29 | 30 | /** 31 | * Get the memcached binary protocol executors 32 | * 33 | * @return the array of 0x100 entries for the package 34 | * executors 35 | */ 36 | std::array& get_mcbp_executors(); 37 | 38 | void mcbp_complete_nread(McbpConnection *c); 39 | 40 | int try_read_mcbp_command(McbpConnection *c); 41 | 42 | void initialize_mbcp_lookup_map(void); 43 | 44 | void ship_mcbp_tap_log(McbpConnection* c); 45 | void ship_mcbp_dcp_log(McbpConnection* c); 46 | void setup_mcbp_lookup_cmd( 47 | EXTENSION_BINARY_PROTOCOL_DESCRIPTOR* descriptor, 48 | uint8_t cmd, 49 | BINARY_COMMAND_CALLBACK new_handler); 50 | -------------------------------------------------------------------------------- /daemon/ioctl.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2014 Couchbase, Inc 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef DAEMON_IOCTL_H 19 | #define DAEMON_IOCTL_H 20 | 21 | #include "config.h" 22 | 23 | #include 24 | #include 25 | 26 | #include "memcached.h" 27 | 28 | /* Attempts to read the given property. 29 | * If the property could be read, return ENGINE_SUCCESS and writes 30 | * the value into `value` 31 | * Otherwise returns a status code indicating why the read failed. 32 | */ 33 | ENGINE_ERROR_CODE ioctl_get_property(Connection* c, 34 | const std::string& key, 35 | std::string& value); 36 | 37 | /* Attempts to set property `key` to the value `value`. 38 | * If the property could be written, return ENGINE_SUCCESS. 39 | * Otherwise returns a status code indicating why the write failed. 40 | */ 41 | ENGINE_ERROR_CODE ioctl_set_property(Connection* c, 42 | const std::string& key, 43 | const std::string& value); 44 | 45 | #endif /* DAEMON_IOCTL_H */ 46 | -------------------------------------------------------------------------------- /daemon/parent_monitor.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "config.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | /* Class which monitors the parent process and will terminate this 28 | * process if the parent ever dies. 29 | */ 30 | class ParentMonitor { 31 | public: 32 | /* Creates a ParentMonitor which will use a background thread to 33 | * periodically verify the existence of the specified parent_ID 34 | * (pid on *ix, processID on Windows). 35 | */ 36 | ParentMonitor(int parent_id); 37 | 38 | /* Shuts down the background thread */ 39 | ~ParentMonitor(); 40 | 41 | protected: 42 | /* Main function for the background thread. */ 43 | static void thread_main(void* arg); 44 | 45 | cb_thread_t thread; 46 | std::mutex mutex; 47 | std::condition_variable shutdown_cv; 48 | std::atomic active; 49 | const cb_pid_t parent_pid; 50 | 51 | #ifdef WIN32 52 | HANDLE handle; 53 | #endif 54 | }; 55 | 56 | -------------------------------------------------------------------------------- /daemon/dynamic_buffer.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #include "config.h" 18 | #include "dynamic_buffer.h" 19 | 20 | #include 21 | 22 | bool DynamicBuffer::grow(size_t needed) { 23 | size_t nsize = size; 24 | size_t available = nsize - offset; 25 | bool rv = true; 26 | 27 | /* Special case: No buffer -- need to allocate fresh */ 28 | if (buffer == NULL) { 29 | nsize = 1024; 30 | available = size = offset = 0; 31 | } 32 | 33 | while (needed > available) { 34 | cb_assert(nsize > 0); 35 | nsize = nsize << 1; 36 | available = nsize - offset; 37 | } 38 | 39 | if (nsize != size) { 40 | char* ptr = reinterpret_cast(cb_realloc(buffer, nsize)); 41 | if (ptr) { 42 | buffer = ptr; 43 | size = nsize; 44 | } else { 45 | rv = false; 46 | } 47 | } 48 | 49 | return rv; 50 | } 51 | 52 | void DynamicBuffer::clear() { 53 | cb_free(buffer); 54 | buffer = nullptr; 55 | size = 0; 56 | offset = 0; 57 | } 58 | -------------------------------------------------------------------------------- /daemon/protocol/mcbp/command_context.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | /** 22 | * A command may need to store command specific context during the duration 23 | * of a command (you might for instance want to keep state between multiple 24 | * calls that returns EWOULDBLOCK). 25 | * 26 | * The implementation of such commands should subclass this class and 27 | * allocate an instance and store in the commands commandContext member (which 28 | * will be deleted and set to nullptr between each command being processed). 29 | */ 30 | class CommandContext { 31 | public: 32 | virtual ~CommandContext(){}; 33 | 34 | /** 35 | * The `pre_link_document()` is a hook called from the underlying engine 36 | * as part of the `store()` method in the engine API. See the `pre_link()` 37 | * method in the `SERVER_DOCUMENT_API` provided by the server for a 38 | * detailed description. 39 | */ 40 | virtual ENGINE_ERROR_CODE pre_link_document(item_info&) { 41 | return ENGINE_SUCCESS; 42 | } 43 | }; 44 | -------------------------------------------------------------------------------- /daemon/protocol/mcbp/engine_errc_2_mcbp.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #include 18 | #include 19 | 20 | namespace mcbp { 21 | /** 22 | * Convert an engine error code to a status code as used in the memcached 23 | * binary protocol. 24 | * 25 | * @param code The engine error code specified 26 | * @return the response message for that engine error code 27 | * @throws std::logic_error for error codes it doesn't make any sense to 28 | * try to convert 29 | * std::invalid_argument for unknown error codes 30 | */ 31 | protocol_binary_response_status to_status(cb::engine_errc code); 32 | } 33 | 34 | /** 35 | * Convert an error code generated from the storage engine to the corresponding 36 | * error code used by the protocol layer. 37 | * @param e the error code as used in the engine 38 | * @return the error code as used by the protocol layer 39 | */ 40 | static inline protocol_binary_response_status engine_error_2_mcbp_protocol_error( 41 | ENGINE_ERROR_CODE e) { 42 | return mcbp::to_status(cb::engine_errc(e)); 43 | } 44 | -------------------------------------------------------------------------------- /include/memcached/openssl.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | /* 20 | * Unfortunately Apple deprecated the use of OpenSSL in (at least) Mavericks 21 | * and added attributes to the methods in the header causing the code to 22 | * emit a ton of warnings. I guess I should wrap all of the methods we're 23 | * using into another library so that I don't have to disable the deprecation 24 | * warnings for other code. We know of this one, but we don't want to make 25 | * an apple specific version (I guess the other option would be to drop the 26 | * support for ssl on mac ;-) 27 | */ 28 | #if defined(__APPLE__) && defined(__clang__) 29 | #pragma clang diagnostic push 30 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" 31 | #endif 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | namespace cb { 40 | namespace openssl { 41 | struct X509deletor { 42 | void operator()(X509* cert) { 43 | X509_free(cert); 44 | } 45 | }; 46 | 47 | using unique_x509_ptr = std::unique_ptr; 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /tests/testapp/testapp_sasl.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include "testapp.h" 20 | #include "testapp_client_test.h" 21 | 22 | #include 23 | 24 | class SaslTest : public TestappClientTest { 25 | 26 | public: 27 | SaslTest() { 28 | mechanisms.push_back("PLAIN"); 29 | #if defined(HAVE_PKCS5_PBKDF2_HMAC_SHA1) || defined(__APPLE__) 30 | mechanisms.push_back("SCRAM-SHA1"); 31 | #endif 32 | #if defined(HAVE_PKCS5_PBKDF2_HMAC) || defined(__APPLE__) 33 | mechanisms.push_back("SCRAM-SHA256"); 34 | mechanisms.push_back("SCRAM-SHA512"); 35 | #endif 36 | } 37 | 38 | virtual void SetUp(); 39 | 40 | virtual void TearDown(); 41 | 42 | protected: 43 | void testMixStartingFrom(const std::string& mech); 44 | void testIllegalLogin(const std::string &user, const std::string& mech); 45 | void testUnknownUser(const std::string& mech) { 46 | testIllegalLogin("wtf", mech); 47 | } 48 | void testWrongPassword(const std::string& mech) { 49 | testIllegalLogin("@admin", mech); 50 | } 51 | 52 | std::vector mechanisms; 53 | }; 54 | -------------------------------------------------------------------------------- /daemon/mcbpdestroybuckettask.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #pragma once 19 | 20 | #include "buckets.h" 21 | #include "connection.h" 22 | #include "memcached/server_api.h" 23 | #include "task.h" 24 | 25 | #include 26 | 27 | 28 | class McbpDestroyBucketTask : public Task { 29 | public: 30 | McbpDestroyBucketTask(const std::string& name_, 31 | bool force_, 32 | Connection* connection_) 33 | : thread(name_, force_, connection_, this) { 34 | } 35 | 36 | // start the bucket deletion 37 | // May throw std::bad_alloc if we're failing to start the thread 38 | void start() { 39 | thread.start(); 40 | } 41 | 42 | virtual bool execute() override { 43 | return true; 44 | } 45 | 46 | virtual void notifyExecutionComplete() override { 47 | if (thread.getConnection() != nullptr) { 48 | // @todo i need to fix this for greenstack 49 | Cookie cookie(thread.getConnection()); 50 | notify_io_complete(&cookie, thread.getResult()); 51 | } 52 | } 53 | 54 | DestroyBucketThread thread; 55 | }; 56 | -------------------------------------------------------------------------------- /tests/testapp/saslauthd_mock.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | #include 21 | 22 | #ifdef WIN32 23 | #error "This file should not be included on windows" 24 | #endif 25 | 26 | 27 | class SaslauthdMock { 28 | public: 29 | SaslauthdMock(); 30 | 31 | SaslauthdMock(const SaslauthdMock&) = delete; 32 | 33 | ~SaslauthdMock(); 34 | 35 | void processOne(); 36 | 37 | const std::string& getSockfile() const { 38 | return sockfile; 39 | } 40 | 41 | protected: 42 | void sendResult(int client, const std::string& msg); 43 | void retrySend(int client, const std::vector& bytes); 44 | 45 | int sock; 46 | 47 | /** 48 | * The unix domain socket filename for the saslauthd. This is 49 | * /tmp/saslauthdmock.[pid]. The reason it is hardcoded 50 | * to that (and not using mktmp) is that there is a potential race 51 | * by using mktmp as I have to remove the filename before calling 52 | * bind and at that time someone else could try to create 53 | * the file. 54 | */ 55 | std::string sockfile; 56 | }; 57 | -------------------------------------------------------------------------------- /auditd/generator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(auditevent_generator auditevent_generator.cc 2 | auditevent_generator.h) 3 | TARGET_LINK_LIBRARIES(auditevent_generator cJSON platform) 4 | 5 | # When we're running the commit validation for memcached we don't 6 | # download all of the external modules so we'll just use a 7 | # subset of the audit descriptors. 8 | IF (COUCHBASE_KV_COMMIT_VALIDATION) 9 | SET(MODULE_DESCRIPTION ${Memcached_SOURCE_DIR}/auditd/etc/kv_commit_validation_module_descriptors.json) 10 | ELSE () 11 | SET(MODULE_DESCRIPTION ${Memcached_SOURCE_DIR}/auditd/etc/module_descriptors.json) 12 | ENDIF (COUCHBASE_KV_COMMIT_VALIDATION) 13 | 14 | 15 | ADD_CUSTOM_COMMAND(OUTPUT 16 | ${Memcached_BINARY_DIR}/auditd/audit_events.json 17 | ${Memcached_BINARY_DIR}/auditd/auditd_audit_events.h 18 | COMMAND 19 | auditevent_generator 20 | -r ${CMAKE_SOURCE_DIR} 21 | -b ${CMAKE_BINARY_DIR} 22 | -o ${Memcached_BINARY_DIR}/auditd/audit_events.json 23 | -i ${MODULE_DESCRIPTION} 24 | DEPENDS 25 | auditevent_generator 26 | ${Memcached_SOURCE_DIR}/auditd/etc/module_descriptors.json 27 | ${Memcached_SOURCE_DIR}/auditd/etc/auditd_descriptor.json 28 | ${Memcached_SOURCE_DIR}/etc/memcached_descriptor.json 29 | COMMENT "Generating audit descriptor definitions" 30 | VERBATIM) 31 | 32 | ADD_CUSTOM_TARGET(generate_audit_descriptors ALL 33 | DEPENDS ${Memcached_BINARY_DIR}/auditd/audit_events.json) 34 | 35 | INSTALL(FILES 36 | ${Memcached_BINARY_DIR}/auditd/audit_events.json 37 | DESTINATION etc/security) 38 | -------------------------------------------------------------------------------- /auditd/src/auditd.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2014 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #ifndef AUDITD_H 18 | #define AUDITD_H 19 | 20 | enum class AuditErrorCode { 21 | AUDIT_EXTENSION_DATA_ERROR, 22 | FILE_OPEN_ERROR, 23 | FILE_RENAME_ERROR, 24 | FILE_REMOVE_ERROR, 25 | MEMORY_ALLOCATION_ERROR, 26 | JSON_PARSING_ERROR, 27 | JSON_MISSING_DATA_ERROR, 28 | JSON_MISSING_OBJECT_ERROR, 29 | JSON_KEY_ERROR, 30 | JSON_ID_ERROR, 31 | JSON_UNKNOWN_FIELD_ERROR, 32 | CB_CREATE_THREAD_ERROR, 33 | EVENT_PROCESSING_ERROR, 34 | PROCESSING_EVENT_FIELDS_ERROR, 35 | TIMESTAMP_MISSING_ERROR, 36 | TIMESTAMP_FORMAT_ERROR, 37 | EVENT_ID_ERROR, 38 | VERSION_ERROR, 39 | VALIDATE_PATH_ERROR, 40 | ROTATE_INTERVAL_BELOW_MIN_ERROR, 41 | ROTATE_INTERVAL_EXCEEDS_MAX_ERROR, 42 | OPEN_AUDITFILE_ERROR, 43 | SETTING_AUDITFILE_OPEN_TIME_ERROR, 44 | WRITING_TO_DISK_ERROR, 45 | WRITE_EVENT_TO_DISK_ERROR, 46 | UNKNOWN_EVENT_ERROR, 47 | CONFIG_INPUT_ERROR, 48 | CONFIGURATION_ERROR, 49 | MISSING_AUDIT_EVENTS_FILE_ERROR, 50 | ROTATE_INTERVAL_SIZE_TOO_BIG, 51 | AUDIT_DIRECTORY_DONT_EXIST, 52 | INITIALIZATION_ERROR 53 | }; 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /include/memcached/config_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIG_PARSER_H 2 | #define CONFIG_PARSER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | typedef long mc_ssize_t; 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | /** 17 | * The supported datatypes the config file parser can handle 18 | */ 19 | enum config_datatype { 20 | DT_SIZE, 21 | DT_SSIZE, 22 | DT_FLOAT, 23 | DT_BOOL, 24 | DT_STRING, 25 | DT_CONFIGFILE 26 | }; 27 | 28 | /** 29 | * I don't like casting, so let's create a union to keep all the values in 30 | */ 31 | union config_value { 32 | size_t *dt_size; 33 | mc_ssize_t *dt_ssize; 34 | float *dt_float; 35 | bool *dt_bool; 36 | // Allocated via cb_malloc. Should be freed with cb_free(). 37 | char **dt_string; 38 | }; 39 | 40 | /** 41 | * An entry for a single item in the config file. 42 | */ 43 | struct config_item { 44 | /** The name of the key */ 45 | const char* key; 46 | /** The datatype for the value */ 47 | enum config_datatype datatype; 48 | /** Where to store the value from the config file */ 49 | union config_value value; 50 | /** If the item was found in the config file or not */ 51 | bool found; 52 | }; 53 | 54 | /** 55 | * Parse the configuration argument and populate the values into the 56 | * config items. 57 | * 58 | * @param str the encoded configuration string 59 | * @param items the config items to look for 60 | * @param error stream to write error messages to 61 | * @return 0 if config successfully parsed 62 | * 1 if config successfully parsed, but unknown tokens found 63 | * -1 if illegal values was found in the config 64 | */ 65 | MEMCACHED_PUBLIC_API int parse_config(const char *str, struct config_item items[], FILE *error); 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /daemon/protocol/mcbp/dcp_set_vbucket_state_executor.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "executors.h" 19 | 20 | void dcp_set_vbucket_state_executor(McbpConnection* c, void* packet) { 21 | auto* req = reinterpret_cast(packet); 22 | ENGINE_ERROR_CODE ret = c->getAiostat(); 23 | c->setAiostat(ENGINE_SUCCESS); 24 | c->setEwouldblock(false); 25 | 26 | if (ret == ENGINE_SUCCESS) { 27 | vbucket_state_t state = (vbucket_state_t)req->message.body.state; 28 | ret = c->getBucketEngine()->dcp.set_vbucket_state( 29 | c->getBucketEngineAsV0(), c->getCookie(), 30 | c->binary_header.request.opaque, 31 | c->binary_header.request.vbucket, 32 | state); 33 | } 34 | 35 | switch (ret) { 36 | case ENGINE_SUCCESS: 37 | c->setState(conn_ship_log); 38 | break; 39 | case ENGINE_DISCONNECT: 40 | c->setState(conn_closing); 41 | break; 42 | 43 | case ENGINE_EWOULDBLOCK: 44 | c->setEwouldblock(true); 45 | break; 46 | 47 | default: 48 | c->setState(conn_closing); 49 | break; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /cbsasl/plain/plain.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Couchbase, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #pragma once 17 | 18 | #include "cbsasl/cbsasl.h" 19 | #include "cbsasl/cbsasl_internal.h" 20 | #include "cbsasl/user.h" 21 | #include 22 | 23 | #define MECH_NAME_PLAIN "PLAIN" 24 | 25 | class PlainServerBackend : public MechanismBackend { 26 | public: 27 | PlainServerBackend(cbsasl_conn_t& conn) 28 | : MechanismBackend(MECH_NAME_PLAIN, conn) { 29 | 30 | } 31 | 32 | virtual cbsasl_error_t start(const char* input, 33 | unsigned inputlen, 34 | const char** output, 35 | unsigned* outputlen) override; 36 | }; 37 | 38 | class PlainClientBackend : public MechanismBackend { 39 | public: 40 | PlainClientBackend(cbsasl_conn_t& conn) 41 | : MechanismBackend(MECH_NAME_PLAIN, conn) { 42 | 43 | } 44 | 45 | virtual cbsasl_error_t start(const char* input, 46 | unsigned inputlen, 47 | const char** output, 48 | unsigned* outputlen) override; 49 | 50 | private: 51 | /** 52 | * Where to store the encoded string: 53 | * "\0username\0password" 54 | */ 55 | std::vector buffer; 56 | }; 57 | -------------------------------------------------------------------------------- /daemon/subdocument.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Sub-document API support. 20 | */ 21 | 22 | #pragma once 23 | 24 | #include "config.h" 25 | 26 | class McbpConnection; 27 | 28 | /* Subdocument executor functions. */ 29 | void subdoc_get_executor(McbpConnection *c, void *packet); 30 | void subdoc_exists_executor(McbpConnection *c, void *packet); 31 | void subdoc_dict_add_executor(McbpConnection *c, void *packet); 32 | void subdoc_dict_upsert_executor(McbpConnection *c, void *packet); 33 | void subdoc_delete_executor(McbpConnection *c, void *packet); 34 | void subdoc_replace_executor(McbpConnection *c, void *packet); 35 | void subdoc_array_push_last_executor(McbpConnection *c, void *packet); 36 | void subdoc_array_push_first_executor(McbpConnection *c, void *packet); 37 | void subdoc_array_insert_executor(McbpConnection * c, void* packet); 38 | void subdoc_array_add_unique_executor(McbpConnection * c, void* packet); 39 | void subdoc_counter_executor(McbpConnection *c, void *packet); 40 | void subdoc_get_count_executor(McbpConnection *c, void *packet); 41 | void subdoc_multi_lookup_executor(McbpConnection *c, void *packet); 42 | void subdoc_multi_mutation_executor(McbpConnection *c, void *packet); 43 | -------------------------------------------------------------------------------- /daemon/protocol/mcbp/dcp_close_stream_executor.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include 19 | #include "executors.h" 20 | 21 | void dcp_close_stream_executor(McbpConnection* c, void* packet) { 22 | auto* req = reinterpret_cast(packet); 23 | ENGINE_ERROR_CODE ret = c->getAiostat(); 24 | c->setAiostat(ENGINE_SUCCESS); 25 | c->setEwouldblock(false); 26 | 27 | if (ret == ENGINE_SUCCESS) { 28 | uint16_t vbucket = ntohs(req->message.header.request.vbucket); 29 | uint32_t opaque = ntohl(req->message.header.request.opaque); 30 | ret = c->getBucketEngine()->dcp.close_stream( 31 | c->getBucketEngineAsV0(), c->getCookie(), 32 | opaque, vbucket); 33 | } 34 | 35 | switch (ret) { 36 | case ENGINE_SUCCESS: 37 | mcbp_write_packet(c, PROTOCOL_BINARY_RESPONSE_SUCCESS); 38 | break; 39 | 40 | case ENGINE_DISCONNECT: 41 | c->setState(conn_closing); 42 | break; 43 | 44 | case ENGINE_EWOULDBLOCK: 45 | c->setEwouldblock(true); 46 | break; 47 | 48 | default: 49 | mcbp_write_packet(c, engine_error_2_mcbp_protocol_error(ret)); 50 | } 51 | } 52 | 53 | -------------------------------------------------------------------------------- /tests/topkeys/topkeys_bench.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2015 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #include "daemon/topkeys.h" 18 | 19 | #include 20 | #include 21 | 22 | 23 | class TopKeysTest : public ::testing::Test { 24 | protected: 25 | void SetUp() { 26 | topkeys.reset(new TopKeys(10)); 27 | } 28 | 29 | std::unique_ptr topkeys; 30 | }; 31 | 32 | static void dump_key(const char* key, const uint16_t klen, 33 | const char* val, const uint32_t vlen, 34 | const void* cookie) { 35 | size_t* count = static_cast(const_cast(cookie)); 36 | (*count)++; 37 | } 38 | 39 | TEST_F(TopKeysTest, Basic) { 40 | // build list of keys 41 | std::vector keys; 42 | for (int ii = 0; ii < 160; ii++) { 43 | keys.emplace_back("topkey_test_" + std::to_string(ii)); 44 | } 45 | 46 | // loop inserting keys 47 | for (int jj = 0; jj < 20000; jj++) { 48 | for (auto& key : keys) { 49 | topkeys->updateKey(key.c_str(), key.size(), jj); 50 | } 51 | } 52 | 53 | // Verify we hit all shards inside TopKeys 54 | size_t count = 0; 55 | topkeys->stats(&count, 0, dump_key); 56 | EXPECT_EQ(80, count); 57 | } 58 | -------------------------------------------------------------------------------- /testsuite/breakdancer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | IF(${COUCHBASE_PYTHON}) 2 | FOREACH(ID RANGE 9) 3 | LIST(APPEND GENERATED_SRCS ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_${ID}.cc) 4 | ENDFOREACH() 5 | 6 | ADD_CUSTOM_COMMAND(OUTPUT ${GENERATED_SRCS} 7 | COMMAND 8 | ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/engine_test.py 9 | DEPENDS 10 | engine_test.py 11 | breakdancer.py 12 | COMMENT "Generating testsuite") 13 | 14 | # Dummy target to prevent cmake trying to run multiple instances of the 15 | # above "Generating testsuite" command. The actual shared libraries 16 | # below in turn depend on this, causing them to be 'blocked' behind this. 17 | ADD_CUSTOM_TARGET(DUMMY_generated_suite 18 | DEPENDS ${GENERATED_SRCS} 19 | COMMENT "Waiting for testsuite generation to complete") 20 | 21 | FOREACH(ID RANGE 9) 22 | ADD_LIBRARY(memcached_generated_testsuite_${ID} SHARED 23 | suite_stubs.cc 24 | ${CMAKE_CURRENT_BINARY_DIR}/generated_suite_${ID}.cc) 25 | SET_TARGET_PROPERTIES(memcached_generated_testsuite_${ID} PROPERTIES PREFIX "") 26 | TARGET_LINK_LIBRARIES(memcached_generated_testsuite_${ID} platform) 27 | ADD_DEPENDENCIES(memcached_generated_testsuite_${ID} 28 | DUMMY_generated_suite) 29 | TARGET_COMPILE_OPTIONS(memcached_generated_testsuite_${ID} 30 | PRIVATE ${CB_C_FLAGS_NO_OPTIMIZE}) 31 | 32 | ADD_TEST(NAME memcached-breakdancer-engine-tests_${ID} 33 | WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} 34 | COMMAND engine_testapp -E default_engine.so 35 | -T memcached_generated_testsuite_${ID}.so) 36 | ENDFOREACH() 37 | ENDIF(${COUCHBASE_PYTHON}) 38 | -------------------------------------------------------------------------------- /daemon/protocol/mcbp/collections_set_manifest_executor.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "../../mcbp.h" 19 | #include "executors.h" 20 | 21 | void collections_set_manifest_executor(McbpConnection* c, void* packet) { 22 | auto* req = 23 | reinterpret_cast(packet); 24 | 25 | ENGINE_ERROR_CODE ret = c->getAiostat(); 26 | c->setAiostat(ENGINE_SUCCESS); 27 | c->setEwouldblock(false); 28 | 29 | if (ret == ENGINE_SUCCESS) { 30 | const uint32_t valuelen = ntohl(req->message.header.request.bodylen); 31 | cb::const_char_buffer jsonBuffer{ 32 | reinterpret_cast(req->bytes + sizeof(req->bytes)), 33 | valuelen}; 34 | ret = ENGINE_ERROR_CODE( 35 | c->getBucketEngine() 36 | ->collections 37 | .set_manifest(c->getBucketEngineAsV0(), jsonBuffer) 38 | .code() 39 | .value()); 40 | } 41 | 42 | if (ret == ENGINE_SUCCESS) { 43 | mcbp_write_packet(c, PROTOCOL_BINARY_RESPONSE_SUCCESS); 44 | } else { 45 | mcbp_write_packet(c, engine_error_2_mcbp_protocol_error(ret)); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /daemon/protocol/mcbp/dcp_flush_executor.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include 19 | #include "executors.h" 20 | 21 | void dcp_flush_executor(McbpConnection* c, void* packet) { 22 | auto* req = reinterpret_cast(packet); 23 | 24 | ENGINE_ERROR_CODE ret = c->getAiostat(); 25 | c->setAiostat(ENGINE_SUCCESS); 26 | c->setEwouldblock(false); 27 | 28 | if (ret == ENGINE_SUCCESS) { 29 | ret = c->getBucketEngine()->dcp.flush(c->getBucketEngineAsV0(), 30 | c->getCookie(), 31 | req->message.header.request.opaque, 32 | ntohs( 33 | req->message.header.request.vbucket)); 34 | } 35 | 36 | switch (ret) { 37 | case ENGINE_SUCCESS: 38 | c->setState(conn_new_cmd); 39 | break; 40 | 41 | case ENGINE_DISCONNECT: 42 | c->setState(conn_closing); 43 | break; 44 | 45 | case ENGINE_EWOULDBLOCK: 46 | c->setEwouldblock(true); 47 | break; 48 | 49 | default: 50 | mcbp_write_packet(c, engine_error_2_mcbp_protocol_error(ret)); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/memory_tracking_test/memory_tracking_plugin.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include "config.h" 19 | #include 20 | #include 21 | #include 22 | 23 | /* 24 | * Plugin (shared object / DLL) loaded at runtime by memory_tracking_test 25 | * to verify memory tracking across shared objects. 26 | */ 27 | 28 | extern "C" EXPORT_SYMBOL void* plugin_malloc(size_t size); 29 | extern "C" EXPORT_SYMBOL void plugin_free(void* ptr); 30 | extern "C" EXPORT_SYMBOL char* plugin_new_char_array(size_t len); 31 | extern "C" EXPORT_SYMBOL void plugin_delete_array(char* ptr); 32 | extern "C" EXPORT_SYMBOL std::string* plugin_new_string(const char* str); 33 | extern "C" EXPORT_SYMBOL void plugin_delete_string(std::string* ptr); 34 | 35 | void* plugin_malloc(size_t size) { 36 | return cb_malloc(size); 37 | } 38 | 39 | void plugin_free(void* ptr) { 40 | cb_free(ptr); 41 | } 42 | 43 | char* plugin_new_char_array(size_t len) { 44 | return new char[len]; 45 | } 46 | 47 | void plugin_delete_array(char* ptr) { 48 | delete[] ptr; 49 | } 50 | 51 | std::string* plugin_new_string(const char* str) { 52 | return new std::string(str); 53 | } 54 | 55 | void plugin_delete_string(std::string* str) { 56 | delete str; 57 | } 58 | -------------------------------------------------------------------------------- /daemon/protocol/mcbp/dcp_add_failover_log.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #include "config.h" 18 | 19 | #include 20 | #include "dcp_add_failover_log.h" 21 | 22 | /** Callback from the engine adding the response */ 23 | ENGINE_ERROR_CODE add_failover_log(vbucket_failover_t* entries, 24 | size_t nentries, 25 | const void* cookie) { 26 | ENGINE_ERROR_CODE ret; 27 | size_t ii; 28 | for (ii = 0; ii < nentries; ++ii) { 29 | entries[ii].uuid = htonll(entries[ii].uuid); 30 | entries[ii].seqno = htonll(entries[ii].seqno); 31 | } 32 | 33 | if (mcbp_response_handler(NULL, 0, NULL, 0, entries, 34 | (uint32_t)(nentries * sizeof(vbucket_failover_t)), 35 | PROTOCOL_BINARY_RAW_BYTES, 36 | PROTOCOL_BINARY_RESPONSE_SUCCESS, 0, 37 | (void*)cookie)) { 38 | ret = ENGINE_SUCCESS; 39 | } else { 40 | ret = ENGINE_ENOMEM; 41 | } 42 | 43 | for (ii = 0; ii < nentries; ++ii) { 44 | entries[ii].uuid = htonll(entries[ii].uuid); 45 | entries[ii].seqno = htonll(entries[ii].seqno); 46 | } 47 | 48 | return ret; 49 | } -------------------------------------------------------------------------------- /tests/testapp/generate_test_cbsaslpw.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | int main(void) { 26 | std::ofstream isaslpw("isasl.pw"); 27 | 28 | isaslpw << "@admin password" << std::endl 29 | << "bucket-1 1S|=,%#x1" << std::endl 30 | << "bucket-2 secret" << std::endl 31 | << "smith smithpassword" << std::endl 32 | << "jones jonespassword" << std::endl 33 | << "larry larrypassword" << std::endl 34 | << "legacy;legacy legacy" << std::endl 35 | << "legacy new" << std::endl; 36 | 37 | 38 | isaslpw.close(); 39 | 40 | cb::sasl::UserFactory::setDefaultHmacIterationCount(10); 41 | 42 | int exitcode = EXIT_SUCCESS; 43 | 44 | try { 45 | cbsasl_pwconv("isasl.pw", "cbsaslpw.json"); 46 | } catch (const std::exception &e) { 47 | std::cerr << "FATAL: Failed to write cbsaslpw.json: " << e.what() 48 | << std::endl; 49 | exitcode = EXIT_FAILURE; 50 | } 51 | 52 | // Remove the input file 53 | std::remove("isasl.pw"); 54 | 55 | return exitcode; 56 | } 57 | -------------------------------------------------------------------------------- /cbsasl/common.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Couchbase, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "cbsasl/cbsasl_internal.h" 18 | 19 | #include 20 | 21 | CBSASL_PUBLIC_API 22 | void cbsasl_dispose(cbsasl_conn_t** conn) { 23 | if (conn != nullptr) { 24 | delete *conn; 25 | *conn = nullptr; 26 | } 27 | } 28 | 29 | CBSASL_PUBLIC_API 30 | cb::sasl::Domain cb::sasl::to_domain(const std::string& domain) { 31 | if (domain == "local") { 32 | return cb::sasl::Domain::Local; 33 | } else if (domain == "external") { 34 | return cb::sasl::Domain::External; 35 | } 36 | throw std::invalid_argument("cb::sasl::to_domain: invalid domain " + 37 | domain); 38 | } 39 | 40 | CBSASL_PUBLIC_API 41 | std::string cb::sasl::to_string(cb::sasl::Domain domain) { 42 | switch (domain) { 43 | case cb::sasl::Domain::Local: 44 | return "local"; 45 | case cb::sasl::Domain::External: 46 | return "external"; 47 | } 48 | throw std::invalid_argument("cb::sasl::to_string: invalid domain " + 49 | std::to_string(int(domain))); 50 | } 51 | 52 | CBSASL_PUBLIC_API 53 | std::string& cb::sasl::get_uuid(cbsasl_conn_t* conn) { 54 | if (conn == nullptr) { 55 | throw std::invalid_argument("cb::sasl::get_uuid: conn can't be null"); 56 | } 57 | return conn->uuid; 58 | } 59 | -------------------------------------------------------------------------------- /daemon/protocol/mcbp/dcp_noop_executor.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2017 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include 19 | #include "executors.h" 20 | #include "utilities.h" 21 | 22 | void dcp_noop_executor(McbpConnection* c, void*) { 23 | ENGINE_ERROR_CODE ret = c->getAiostat(); 24 | c->setAiostat(ENGINE_SUCCESS); 25 | c->setEwouldblock(false); 26 | 27 | if (ret == ENGINE_SUCCESS) { 28 | // NOOP may be sent to a consumer or a producer... 29 | ret = mcbp::haveDcpPrivilege(*c); 30 | if (ret == ENGINE_SUCCESS) { 31 | ret = c->getBucketEngine()->dcp.noop(c->getBucketEngineAsV0(), 32 | c->getCookie(), 33 | c->binary_header.request.opaque); 34 | } 35 | } 36 | 37 | ret = c->remapErrorCode(ret); 38 | switch (ret) { 39 | case ENGINE_SUCCESS: 40 | mcbp_write_packet(c, PROTOCOL_BINARY_RESPONSE_SUCCESS); 41 | break; 42 | 43 | case ENGINE_DISCONNECT: 44 | c->setState(conn_closing); 45 | break; 46 | 47 | case ENGINE_EWOULDBLOCK: 48 | c->setEwouldblock(true); 49 | break; 50 | 51 | default: 52 | mcbp_write_packet(c, engine_error_2_mcbp_protocol_error(ret)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tests/sizes/sizes.cc: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | #include 3 | 4 | #include "daemon/memcached.h" 5 | #include "utilities/protocol2text.h" 6 | 7 | static void display(const char *name, size_t size) { 8 | printf("%s\t%d\n", name, (int)size); 9 | } 10 | 11 | static long calc_conn_size(void) { 12 | long ret = sizeof(Connection); 13 | ret += (sizeof(char *) * TEMP_ALLOC_LIST_INITIAL); 14 | ret += (sizeof(struct iovec) * IOV_LIST_INITIAL); 15 | ret += (sizeof(struct msghdr) * MSG_LIST_INITIAL); 16 | return ret; 17 | } 18 | 19 | static unsigned int count_used_opcodes(void) { 20 | unsigned int used_opcodes = 0; 21 | for (uint8_t opcode = 0; opcode < 255; opcode++) { 22 | if (memcached_opcode_2_text(opcode) != NULL) { 23 | used_opcodes++; 24 | } 25 | } 26 | return used_opcodes; 27 | } 28 | 29 | static void display_used_opcodes(void) { 30 | printf("Opcode map: (# = Used, . = Free)\n\n"); 31 | printf(" 0123456789abcdef"); 32 | for (unsigned int opcode = 0; opcode < 256; opcode++) { 33 | if (opcode % 16 == 0) { 34 | printf("\n%02x ", opcode & ~0xf); 35 | } 36 | if (memcached_opcode_2_text(opcode) != NULL) { 37 | putchar('X'); 38 | } else { 39 | putchar('.'); 40 | } 41 | } 42 | putchar('\n'); 43 | } 44 | 45 | int main(int argc, char **argv) { 46 | display("Thread stats", sizeof(struct thread_stats)); 47 | display("Global stats", sizeof(struct stats)); 48 | display("Settings", sizeof(Settings)); 49 | display("Libevent thread", 50 | sizeof(LIBEVENT_THREAD)); 51 | display("Connection", calc_conn_size()); 52 | 53 | printf("----------------------------------------\n"); 54 | 55 | display("libevent thread cumulative", sizeof(LIBEVENT_THREAD)); 56 | display("Thread stats cumulative\t", sizeof(struct thread_stats)); 57 | printf("Binary protocol opcodes used\t%u / %u\n", 58 | count_used_opcodes(), 256); 59 | display_used_opcodes(); 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /cbsasl/log.cc: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #include "cbsasl/cbsasl_internal.h" 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | namespace cb { 24 | namespace sasl { 25 | namespace logging { 26 | 27 | Couchbase::RelaxedAtomic callback; 28 | 29 | using LogCallback = void (*)(Level level, const std::string& message); 30 | 31 | void set_log_callback(LogCallback logCallback) { 32 | callback.store(logCallback); 33 | } 34 | 35 | void log(cbsasl_conn_t& connection, Level level, const std::string& message) { 36 | auto logger = callback.load(); 37 | if (logger == nullptr) { 38 | return; 39 | } 40 | 41 | if (level == Level::Error) { 42 | // We need to generate UUID 43 | auto& uuid = connection.get_uuid(); 44 | std::string full; 45 | full.reserve(message.size() + uuid.size() + 10); 46 | full = "UUID:[" + uuid + "] " + message; 47 | callback.load()(level, full); 48 | } else { 49 | callback.load()(level, message); 50 | } 51 | } 52 | 53 | void log(Level level, const std::string& message) { 54 | auto logger = callback.load(); 55 | if (logger == nullptr) { 56 | return; 57 | } 58 | 59 | callback.load()(level, message); 60 | } 61 | } // namespace logging 62 | } // namespace sasl 63 | } // namespace cb 64 | -------------------------------------------------------------------------------- /etc/memcached.ex.json: -------------------------------------------------------------------------------- 1 | { 2 | "root" : "/opt/couchbase", 3 | "admin" : "_admin", 4 | "breakpad" : 5 | { 6 | "enabled" : true, 7 | "minidump_dir" : "/opt/couchbase/var/crash", 8 | "content" : "default" 9 | }, 10 | "require_init" : true, 11 | "audit_file" : "/opt/couchbase/etc/security/audit.json", 12 | "ssl_cipher_list" : "HIGH", 13 | "threads" : 4, 14 | "interfaces" : 15 | [ 16 | { 17 | "host" : "*", 18 | "port" : 11209, 19 | "IPv4" : true, 20 | "IPv6" : true, 21 | "maxconn" : 10000, 22 | "backlog" : 1024, 23 | "tcp_nodelay" : true, 24 | "ssl" : 25 | { 26 | "key" : "/etc/memcached/pkey", 27 | "cert" : "/etc/memcached/cert" 28 | }, 29 | "protocol" : "memcached" 30 | }, 31 | { 32 | "host" : "*", 33 | "port" : 11210, 34 | "IPv4" : true, 35 | "IPv6" : true, 36 | "maxconn" : 10000, 37 | "backlog" : 1024, 38 | "tcp_nodelay" : true, 39 | "ssl" : 40 | { 41 | "key" : "/etc/memcached/pkey", 42 | "cert" : "/etc/memcached/cert" 43 | }, 44 | "protocol" : "greenstack" 45 | } 46 | ], 47 | "extensions" : 48 | [ 49 | { 50 | "module" : "stdin_term_handler.so", 51 | "config" : "" 52 | }, 53 | { 54 | "module" : "file_logger.so", 55 | "config" : "cyclesize=10485760;sleeptime=19;filename=data/n_0/logs/memcached.log" 56 | } 57 | ], 58 | "require_sasl" : false, 59 | "default_reqs_per_event" : 20, 60 | "reqs_per_event_high_priority" : 40, 61 | "reqs_per_event_med_priority" : 20, 62 | "reqs_per_event_low_priority" : 10, 63 | "verbosity" : 2, 64 | "datatype_json" : true, 65 | "datatype_snappy" : true, 66 | "max_packet_size" : 25, 67 | "bio_drain_buffer_sz" : 8192 68 | } 69 | -------------------------------------------------------------------------------- /cbsasl/scram-sha/stringutils.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 | /* 3 | * Copyright 2016 Couchbase, Inc. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #pragma once 18 | 19 | #include 20 | 21 | /** 22 | * Apply https://www.ietf.org/rfc/rfc4013.txt to the input string 23 | * 24 | * The input string is supposed to be UTF-8 (but given that we don't 25 | * support bucket names with multibyte characters, we only support 26 | * single-byte UTF-8 characters ;-)) 27 | * 28 | * @param string The string to run stringprep with the SASL profile on 29 | * @return a SASLPrep'd string 30 | * @throws std::runtime_error if we encounter a multibyte character 31 | */ 32 | std::string SASLPrep(const std::string& string); 33 | 34 | /** 35 | * According to https://www.ietf.org/rfc/rfc5802.txt all occurrences 36 | * of ',' and '=' needs to be transferred as =2C and =3D. 37 | * 38 | * @param username the username to encode 39 | * @return the escaped string 40 | */ 41 | std::string encodeUsername(const std::string& username); 42 | 43 | /** 44 | * According to https://www.ietf.org/rfc/rfc5802.txt all occurrences 45 | * of ',' and '=' needs to be transferred as =2C and =3D. This method 46 | * decodes that encoding 47 | * 48 | * @param username the username to decode 49 | * @return the decoded username 50 | * @throws std::runtime_error if the username contains an illegal 51 | * sequence of characters. 52 | */ 53 | std::string decodeUsername(const std::string& username); 54 | --------------------------------------------------------------------------------