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 KEYFILE_AUTH_H
30 #define KEYFILE_AUTH_H
31
32 #include "../public/auth.h"
33
34 #include <cx/map.h>
35 #include <inttypes.h>
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 typedef struct keyfile Keyfile;
42 typedef struct keyfile_user KeyfileUser;
43
44 enum KeyfileHashType {
45 KEYFILE_SSHA =
0,
46 KEYFILE_SSHA256,
47 KEYFILE_SSHA512
48 };
49
50 struct keyfile {
51 AuthDB authdb;
52 CxMap *users;
53 };
54
55 struct keyfile_user {
56 User user;
57 cxmutstr *groups;
58 size_t numgroups;
59 enum KeyfileHashType hash_type;
60 char *hash;
61 size_t hashlen;
62 };
63
64 Keyfile* keyfile_new(CxAllocator *a);
65
66 int keyfile_add_user(
67 Keyfile *keyfile,
68 cxmutstr user,
69 enum KeyfileHashType hash_type,
70 cxmutstr hash,
71 cxmutstr *groups,
72 size_t ngroups);
73
74 User* keyfile_get_user(AuthDB *db, Session *sn, Request *rq,
const char *user);
75 int keyfile_user_verify_password(User *user,
const char *password);
76 int keyfile_user_check_group(User *user,
const char *group);
77 void keyfile_user_free(User *user);
78
79
80 int ssha_verify(KeyfileUser *user,
const char *password);
81
82 #ifdef __cplusplus
83 }
84 #endif
85
86 #endif
87
88