#ifndef _KIDMAP_PRIV_H
#define _KIDMAP_PRIV_H
#include <sys/avl.h>
#ifdef __cplusplus
extern "C" {
#endif
#define KIDMAP_HASH_SIZE (1<<8)
#define KIDMAP_HASH_MASK (KIDMAP_HASH_SIZE-1)
typedef struct sid2pid {
avl_node_t avl_link;
struct sid2pid *flink;
struct sid2pid *blink;
const char *sid_prefix;
uint32_t rid;
uid_t uid;
time_t uid_ttl;
gid_t gid;
time_t gid_ttl;
int is_user;
} sid2pid_t;
typedef struct pid2sid {
avl_node_t avl_link;
struct pid2sid *flink;
struct pid2sid *blink;
const char *sid_prefix;
uint32_t rid;
uid_t pid;
time_t ttl;
} pid2sid_t;
typedef struct idmap_sid2pid_cache {
avl_tree_t tree;
kmutex_t mutex;
struct sid2pid head;
time_t purge_time;
int uid_num;
int gid_num;
int pid_num;
} idmap_sid2pid_cache_t;
typedef struct idmap_pid2sid_cache {
avl_tree_t tree;
kmutex_t mutex;
struct pid2sid head;
time_t purge_time;
} idmap_pid2sid_cache_t;
typedef struct idmap_cache {
idmap_sid2pid_cache_t sid2pid_hash[KIDMAP_HASH_SIZE];
idmap_pid2sid_cache_t uid2sid_hash[KIDMAP_HASH_SIZE];
idmap_pid2sid_cache_t gid2sid_hash[KIDMAP_HASH_SIZE];
} idmap_cache_t;
void
kidmap_cache_create(idmap_cache_t *cache);
void
kidmap_cache_delete(idmap_cache_t *cache);
void
kidmap_cache_purge(idmap_cache_t *cache);
int
kidmap_cache_lookup_uidbysid(idmap_cache_t *cache, const char *sid_prefix,
uint32_t rid, uid_t *uid);
int
kidmap_cache_lookup_gidbysid(idmap_cache_t *cache, const char *sid_prefix,
uint32_t rid, gid_t *gid);
int
kidmap_cache_lookup_pidbysid(idmap_cache_t *cache, const char *sid_prefix,
uint32_t rid, uid_t *pid, int *is_user);
int
kidmap_cache_lookup_sidbyuid(idmap_cache_t *cache, const char **sid_prefix,
uint32_t *rid, uid_t uid);
int
kidmap_cache_lookup_sidbygid(idmap_cache_t *cache, const char **sid_prefix,
uint32_t *rid, gid_t gid);
void
kidmap_cache_add_sid2uid(idmap_cache_t *cache, const char *sid_prefix,
uint32_t rid, uid_t uid, int direction);
void
kidmap_cache_add_sid2gid(idmap_cache_t *cache, const char *sid_prefix,
uint32_t rid, gid_t gid, int direction);
void
kidmap_cache_add_sid2pid(idmap_cache_t *cache, const char *sid_prefix,
uint32_t rid, uid_t pid, int is_user, int direction);
void
kidmap_cache_get_data(idmap_cache_t *cache, size_t *uidbysid, size_t *gidbysid,
size_t *pidbysid, size_t *sidbyuid, size_t *sidbygid);
int
kidmap_start(void);
int
kidmap_stop(void);
void
kidmap_sid_prefix_store_init(void);
const char *
kidmap_find_sid_prefix(const char *sid_prefix);
#ifdef __cplusplus
}
#endif
#endif