1 #ifndef _HTTP_AUTH_H_
2 #define _HTTP_AUTH_H_
3 
4 #include "server.h"
5 #include "plugin.h"
6 
7 #if defined(HAVE_LDAP_H) && defined(HAVE_LBER_H) && defined(HAVE_LIBLDAP) && defined(HAVE_LIBLBER)
8 # define USE_LDAP
9 # include <ldap.h>
10 #endif
11 
12 typedef enum {
13 	AUTH_BACKEND_UNSET,
14 	AUTH_BACKEND_PLAIN,
15 	AUTH_BACKEND_LDAP,
16 	AUTH_BACKEND_HTPASSWD,
17 	AUTH_BACKEND_HTDIGEST
18 } auth_backend_t;
19 
20 typedef struct {
21 	/* auth */
22 	array  *auth_require;
23 
24 	buffer *auth_plain_groupfile;
25 	buffer *auth_plain_userfile;
26 
27 	buffer *auth_htdigest_userfile;
28 	buffer *auth_htpasswd_userfile;
29 
30 	buffer *auth_backend_conf;
31 
32 	buffer *auth_ldap_hostname;
33 	buffer *auth_ldap_basedn;
34 	buffer *auth_ldap_binddn;
35 	buffer *auth_ldap_bindpw;
36 	buffer *auth_ldap_filter;
37 	buffer *auth_ldap_cafile;
38 	unsigned short auth_ldap_starttls;
39 	unsigned short auth_ldap_allow_empty_pw;
40 
41 	unsigned short auth_debug;
42 
43 	/* generated */
44 	auth_backend_t auth_backend;
45 
46 #ifdef USE_LDAP
47 	LDAP *ldap;
48 
49 	buffer *ldap_filter_pre;
50 	buffer *ldap_filter_post;
51 #endif
52 } mod_auth_plugin_config;
53 
54 typedef struct {
55 	PLUGIN_DATA;
56 	buffer *tmp_buf;
57 
58 	buffer *auth_user;
59 
60 #ifdef USE_LDAP
61 	buffer *ldap_filter;
62 #endif
63 
64 	mod_auth_plugin_config **config_storage;
65 
66 	mod_auth_plugin_config conf, *anon_conf; /* this is only used as long as no handler_ctx is setup */
67 } mod_auth_plugin_data;
68 
69 int http_auth_basic_check(server *srv, connection *con, mod_auth_plugin_data *p, array *req, buffer *url, const char *realm_str);
70 int http_auth_digest_check(server *srv, connection *con, mod_auth_plugin_data *p, array *req, buffer *url, const char *realm_str);
71 int http_auth_digest_generate_nonce(server *srv, mod_auth_plugin_data *p, buffer *fn, char hh[33]);
72 
73 #endif
74