]> mj.ucw.cz Git - subauth.git/blob - server/subauthd.h
Database of users
[subauth.git] / server / subauthd.h
1 /*
2  *      Sub-authentication Daemon
3  *
4  *      (c) 2017 Martin Mares <mj@ucw.cz>
5  */
6
7 #include "autoconf.h"
8
9 #include <sys/types.h>
10
11 #include <ucw/clists.h>
12 #include <ucw/mainloop.h>
13 #include <ucw-json/json.h>
14
15 #define SOCKET_TIMEOUT 60000            // in ms
16 #define MAX_PACKET_SIZE 16384
17 #define MAX_OOB_DATA_SIZE 4096
18
19 struct client {
20   struct main_file socket;
21   struct main_timer timer;
22   int uid;
23   struct json_context *json;
24   struct json_node *request;
25   struct json_node *reply;
26 };
27
28 extern clist zone_list;                 // of struct auth_zone
29 extern char *database_name;
30
31 /* cmd.c */
32
33 void cmd_error(struct client *c, const char *err);
34 void cmd_dispatch(struct client *c);
35
36 const char *get_string(struct json_node *n, const char *key);
37 bool get_uint(struct json_node *n, const char *key, uint *dest);
38 struct json_node **get_array(struct json_node *n, const char *key);
39 struct json_node *get_object(struct json_node *n, const char *key);
40
41 /* auth.c */
42
43 struct auth_zone {
44   cnode n;
45   char *name;
46   uint auto_create_acct;
47   uint allow_passwd;
48   uint allow_tokens;
49 };
50
51 struct auth_user {
52   clist accounts;                       // of struct auth_acct
53   char login[1];
54 };
55
56 struct auth_acct {
57   cnode n;
58   struct auth_zone *zone;
59   clist tokens;                         // of struct auth_token
60 };
61
62 enum token_type {
63   TOKEN_PASSWORD,
64   TOKEN_GENERATED,
65   TOKEN_NUM_TYPES,
66 };
67
68 struct auth_token {
69   cnode n;
70   enum token_type type;
71   char *salt;
72   char *hash;
73   char *comment;
74   time_t last_modified;
75 };
76
77 void auth_init(void);
78 void db_write(void);