#ifndef NSS_MEMCACHE_H #define NSS_MEMCACHE_H //#define _LIBC 1 //#define NOT_IN_libc 1 #include //#include #include //#undef _LIBC //#undef NOT_IN_libc #include #include /* Longest character length of a (u|g)id */ #define MAX_ID_LEN 5 #define MAX_KEY_SIZE 251 //#define DEFINE_LOCK(l) __libc_lock_define_initialized(static __thread, lock_##l) //#define LOCK(l) __libc_lock_lock(lock_##l) //#define UNLOCK(l) __libc_lock_unlock(lock_##l) #define DEFINE_LOCK(l) static __thread pthread_mutex_t lock_##l = PTHREAD_MUTEX_INITIALIZER #define LOCK(l) pthread_mutex_lock(&lock_##l) #define UNLOCK(l) pthread_mutex_unlock(&lock_##l) #define FLIP(a) { \ LOCK(a); \ a = ! a; \ UNLOCK(a); \ } #define TEST_FOR(a) {\ LOCK(a); \ if (a) { \ UNLOCK(a); \ DLOG("lock taken [NSS_STATUS_UNAVAIL]"); \ DEXIT; \ return (NSS_STATUS_UNAVAIL); \ } \ UNLOCK(a); \ } #define CHECK_NULL(a, failval) { \ if (a == NULL) { \ DEXIT; \ return (failval); \ } \ } #define INFO(fmt, ...) { \ syslog(LOG_AUTHPRIV|LOG_INFO, \ "nss_memcache[%d]:%s:" fmt "\n", getpid(), __func__, ## __VA_ARGS__); \ } #define WARN(fmt, ...) { \ syslog(LOG_AUTHPRIV|LOG_WARNING, \ "nss_memcache[%d]:%s:" fmt "\n", getpid(), __func__, ## __VA_ARGS__); \ } #define CRIT(fmt, ...) { \ syslog(LOG_AUTHPRIV|LOG_CRIT, \ "nss_memcache[%d]:%s:" fmt "\n", getpid(), __func__, ## __VA_ARGS__); \ } #define ALERT(fmt, ...) { \ syslog(LOG_AUTHPRIV|LOG_ALERT, \ "nss_memcache[%d]:%s:" fmt "\n", getpid(), __func__, ## __VA_ARGS__); \ } #ifdef DEBUG # define DLOG(fmt, ...) { \ syslog(LOG_AUTHPRIV|LOG_DEBUG, \ "nss_memcache[%d]:%s:" fmt "\n", getpid(), __func__, ## __VA_ARGS__); \ } # define DENTER {DLOG("enter");} # define DEXIT {DLOG("exit");} #else # define DLOG(fmt, ...) {} # define DENTER {} # define DEXIT {} #endif #define dreturn(value) { \ DEXIT; \ return value; \ } #ifndef APPEND #define APPEND(a,b) a##b #endif #define NSMC(fn) APPEND(_nss_memcache_, fn) #define MIN(a,b) (a > b ? b : a) enum match_t { pw_pos, pw_neg }; enum return_t { RETURN_FAILURE = -1, RETURN_SUCCESS, RETURN_SKIP }; enum return_t _nss_memcache_initialize_connection(void); enum return_t _nss_memcache_destroy_connection(void); enum return_t NSMC(setup_socket)(void); void NSMC(check_and_reconnect_socket)(void); void NSMC(backend_add)(enum match_t type, char *key, char *data, size_t len); enum return_t NSMC(fallthrough_successful)(enum nss_status status, char **ptr); enum return_t NSMC(check_maximum_keysize)(const char *fn, const char *key); void NSMC(create_backend_key)(char *dst, const char *prefix, const char *key); #endif