#ifndef AUTH_H
#define AUTH_H
#include <sys/types.h>
#include <inttypes.h>
#include "../public/auth.h"
#include <cx/map.h>
#include <cx/string.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
User user;
char *authdb;
cxmutstr *groups;
size_t numgroups;
char *password;
uint32_t ref;
} CachedUser;
typedef struct user_cache_elm UserCacheElm;
struct user_cache_elm {
CachedUser *user;
UserCacheElm *next_user;
CxHashKey key;
size_t slot;
UserCacheElm *next_elm;
time_t created;
};
typedef struct {
UserCacheElm **map;
size_t size;
size_t count;
size_t max_users;
UserCacheElm *head;
UserCacheElm *trail;
} UserCache;
void auth_cache_init();
User* auth_cache_get(
char *authdb,
const char *user);
void auth_cache_add(
char *authdb,
User *user,
const char *password,
const char **groups,
size_t numgroups);
void auth_cache_remove_from_map(UserCacheElm *elm);
int cached_user_verify_password(CachedUser *user,
const char *password);
int cached_user_check_group(CachedUser *user,
const char *group);
void cached_user_unref(CachedUser *user);
void cached_user_delete(CachedUser *user);
#ifdef __cplusplus
}
#endif
#endif