1#ifndef USERS_H
2#define USERS_H
3
4#include <stdbool.h>
5#include <stddef.h>
6
7struct user {
8 char name[64];
9 char pass[128];
10
11 char** allow;
12 size_t allow_len;
13 size_t allow_cap;
14};
15
16struct users {
17 struct user* v;
18 size_t len;
19 size_t cap;
20};
21
22extern struct users users;
23
24/* Check whether relpath is permitted for a given user.
25 Returns true=permitted, false=not-permitted */
26bool user_allows_path(const struct user* u, const char* relpath);
27
28/* Add an allow prefix to the most recently pushed user
29 Returns 0=Success, -1=Failure */
30int users_add_allow(const char* prefix);
31
32/* Authenticate request using the "Authorization" header.
33 Returns NULL if authentication is disabled
34 Returns User Ptr=Success, NULL=Failure. */
35const struct user* users_auth_from_hdr(const char* hdr);
36
37/* Free all memory owned by the global user table. */
38void users_free(void);
39
40/* Create new user entry and append it to the global users table
41 Returns 0=Success, -1=Failure */
42int users_push(const char* name);
43
44/* Set the password for most recently pushed user
45 Empty password creates a passwordless user
46 Returns 0=Success, -1=Failure */
47int users_set_pass(const char* pass);
48
49#endif /* USERS_H */
50