1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #ifndef AUTH_H
30 #define AUTH_H
31
32 #include <sys/types.h>
33 #include <inttypes.h>
34 #include "../public/auth.h"
35
36 #include <cx/map.h>
37 #include <cx/string.h>
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 typedef struct {
44 User user;
45 char *authdb;
46 cxmutstr *groups;
47 size_t numgroups;
48 char *password;
49 uint32_t ref;
50 } CachedUser;
51
52 typedef struct user_cache_elm UserCacheElm;
53 struct user_cache_elm {
54 CachedUser *user;
55 UserCacheElm *next_user;
56 CxHashKey key;
57 size_t slot;
58 UserCacheElm *next_elm;
59 time_t created;
60 };
61
62 typedef struct {
63 UserCacheElm **map;
64 size_t size;
65 size_t count;
66 size_t max_users;
67 UserCacheElm *head;
68 UserCacheElm *trail;
69 } UserCache;
70
71 void auth_cache_init();
72
73 User* auth_cache_get(
char *authdb,
const char *user);
74 void auth_cache_add(
75 char *authdb,
76 User *user,
77 const char *password,
78 const char **groups,
79 size_t numgroups);
80
81 void auth_cache_remove_from_map(UserCacheElm *elm);
82
83 int cached_user_verify_password(CachedUser *user,
const char *password);
84 int cached_user_check_group(CachedUser *user,
const char *group);
85 void cached_user_unref(CachedUser *user);
86 void cached_user_delete(CachedUser *user);
87
88 #ifdef __cplusplus
89 }
90 #endif
91
92 #endif
93
94