xref: /lighttpd1.4/src/mod_auth_api.h (revision 94edf7e8)
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     int valid_user;
43     int algorithm;
44     array user;
45     array group;
46     array host;
47 } http_auth_require_t;
48 
49 __attribute_cold__
50 __attribute_malloc__
51 http_auth_require_t * http_auth_require_init (void);
52 
53 __attribute_cold__
54 void http_auth_require_free (http_auth_require_t *require);
55 
56 __attribute_pure__
57 int http_auth_match_rules (const http_auth_require_t *require, const char *user, const char *group, const char *host);
58 
59 typedef struct http_auth_info_t {
60     int dalgo;
61     unsigned int dlen;
62     const char *username;
63     size_t ulen;
64     const char *realm;
65     size_t rlen;
66     /*(must be >= largest binary digest length accepted above)*/
67     unsigned char digest[32];
68 } http_auth_info_t;
69 
70 typedef struct http_auth_backend_t {
71     const char *name;
72     handler_t(*basic)(request_st *r, void *p_d, const http_auth_require_t *require, const buffer *username, const char *pw);
73     handler_t(*digest)(request_st *r, void *p_d, http_auth_info_t *ai);
74     void *p_d;
75 } http_auth_backend_t;
76 
77 typedef struct http_auth_scheme_t {
78     const char *name;
79     handler_t(*checkfn)(request_st *r, void *p_d, const struct http_auth_require_t *require, const struct http_auth_backend_t *backend);
80     /*(backend is arg only because auth.backend is separate config directive)*/
81     void *p_d;
82 } http_auth_scheme_t;
83 
84 __attribute_cold__
85 __attribute_pure__
86 const http_auth_scheme_t * http_auth_scheme_get (const buffer *name);
87 
88 __attribute_cold__
89 void http_auth_scheme_set (const http_auth_scheme_t *scheme);
90 
91 __attribute_cold__
92 __attribute_pure__
93 const http_auth_backend_t * http_auth_backend_get (const buffer *name);
94 
95 __attribute_cold__
96 void http_auth_backend_set (const http_auth_backend_t *backend);
97 
98 void http_auth_setenv(request_st *r, const char *username, size_t ulen, const char *auth_type, size_t alen);
99 
100 #endif
101