-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathaccess.c
100 lines (82 loc) · 2.62 KB
/
access.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* Copyright (C) 2004-2008 Christos Tsantilas
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA.
*/
#include "common.h"
#include "c-icap.h"
#include "request.h"
#include "request_util.h"
#include "module.h"
#include "cfg_param.h"
#include "debug.h"
#include "access.h"
#include "acl.h"
#include "net_io.h"
/********************************************************************************************/
extern access_control_module_t default_acl;
access_control_module_t *default_access_controllers[] = {
&default_acl,
NULL
};
access_control_module_t **used_access_controllers = default_access_controllers;
int access_reset()
{
used_access_controllers = default_access_controllers;
return 1;
}
int access_check_client(ci_request_t *req)
{
int i = 0, res;
if (!used_access_controllers)
return CI_ACCESS_ALLOW;
i = 0;
while (used_access_controllers[i] != NULL) {
if (used_access_controllers[i]->client_access) {
res =
used_access_controllers[i]->client_access(req);
if (res != CI_ACCESS_UNKNOWN)
return res;
}
i++;
}
return CI_ACCESS_ALLOW;
}
int check_request(ci_request_t * req)
{
int res, i = 0;
while (used_access_controllers[i] != NULL) {
if (used_access_controllers[i]->request_access) {
res = used_access_controllers[i]->request_access(req);
if (res != CI_ACCESS_UNKNOWN)
return res;
}
i++;
}
return CI_ACCESS_ALLOW;
}
int access_check_request(ci_request_t * req)
{
int res;
if (!used_access_controllers)
return CI_ACCESS_ALLOW;
ci_debug_printf(9,"Going to check request for access control restrictions\n");
res = check_request(req);
ci_debug_printf(9,"Access control: %s\n", (res == CI_ACCESS_ALLOW?
"ALLOW":
(res == CI_ACCESS_DENY?"DENY":"UNKNOWN")));
return res;
}