xref: /lighttpd1.4/src/mod_auth_api.h (revision 71175df1)
1 /*
2  * mod_auth_api - HTTP auth backend registration, low-level shared funcs
3  *
4  * Fully-rewritten from original
5  * Copyright(c) 2016 Glenn Strauss gstrauss()gluelogic.com  All rights reserved
6  * License: BSD 3-clause (same as lighttpd)
7  */
8 #ifndef INCLUDED_MOD_AUTH_API_H
9 #define INCLUDED_MOD_AUTH_API_H
10 #include "first.h"
11 
12 #include "base_decls.h"
13 #include "buffer.h"
14 #include "array.h"
15 
16 __attribute_cold__
17 void http_auth_dumbdata_reset (void);
18 
19 typedef enum http_auth_digest_type {
20     HTTP_AUTH_DIGEST_NONE       = 0
21    ,HTTP_AUTH_DIGEST_SESS       = 0x01
22    ,HTTP_AUTH_DIGEST_MD5        = 0x02
23    ,HTTP_AUTH_DIGEST_SHA256     = 0x04
24    ,HTTP_AUTH_DIGEST_SHA512_256 = 0x08
25 } http_auth_digest_type;
26 
27 #define HTTP_AUTH_DIGEST_MD5_BINLEN        16 /* MD5_DIGEST_LENGTH */
28 #define HTTP_AUTH_DIGEST_SHA256_BINLEN     32 /* SHA256_DIGEST_LENGTH */
29 #define HTTP_AUTH_DIGEST_SHA512_256_BINLEN 32 /* SHA512_256_DIGEST_LENGTH */
30 
31 __attribute_const__
32 unsigned int http_auth_digest_len (int algo);
33 
34 struct http_auth_scheme_t;
35 struct http_auth_require_t;
36 struct http_auth_backend_t;
37 
38 typedef struct http_auth_require_t {
39     const struct http_auth_scheme_t *scheme;
40     const buffer *realm;
41     const buffer *nonce_secret;
42     uint8_t valid_user;
43     uint8_t userhash;
44     int algorithm;
45     array user;
46     array group;
47     array host;
48 } http_auth_require_t;
49 
50 __attribute_cold__
51 __attribute_malloc__
52 http_auth_require_t * http_auth_require_init (void);
53 
54 __attribute_cold__
55 void http_auth_require_free (http_auth_require_t *require);
56 
57 __attribute_pure__
58 int http_auth_match_rules (const http_auth_require_t *require, const char *user, const char *group, const char *host);
59 
60 typedef struct http_auth_info_t {
61     int dalgo;
62     unsigned int dlen;
63     const char *username;
64     size_t ulen;
65     const char *realm;
66     size_t rlen;
67     int userhash;
68     /*(must be >= largest binary digest length accepted above)*/
69     unsigned char digest[32];
70     char userbuf[256];
71 } http_auth_info_t;
72 
73 typedef struct http_auth_backend_t {
74     const char *name;
75     handler_t(*basic)(request_st *r, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw);
76     handler_t(*digest)(request_st *r, void *p_d, http_auth_info_t *ai);
77     void *p_d;
78 } http_auth_backend_t;
79 
80 typedef struct http_auth_scheme_t {
81     const char *name;
82     handler_t(*checkfn)(request_st *r, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend);
83     /*(backend is arg only because auth.backend is separate config directive)*/
84     void *p_d;
85 } http_auth_scheme_t;
86 
87 __attribute_cold__
88 __attribute_pure__
89 const http_auth_scheme_t * http_auth_scheme_get (const buffer *name);
90 
91 __attribute_cold__
92 void http_auth_scheme_set (const http_auth_scheme_t *scheme);
93 
94 __attribute_cold__
95 __attribute_pure__
96 const http_auth_backend_t * http_auth_backend_get (const buffer *name);
97 
98 __attribute_cold__
99 void http_auth_backend_set (const http_auth_backend_t *backend);
100 
101 void http_auth_setenv(request_st *r, const char *username, size_t ulen, const char *auth_type, size_t alen);
102 
103 #endif
104