Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 117 lines (92 sloc) 2.65 kB
860827a @alobbs Adds X-Real-IP header support to all the FastCGI, SCGI, uWSGI, and CGI
alobbs authored
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* Cherokee
4 *
5 * Authors:
6 * Alvaro Lopez Ortega <alvaro@alobbs.com>
7 *
920e20b @alobbs Happy new year!
alobbs authored
8 * Copyright (C) 2001-2011 Alvaro Lopez Ortega
860827a @alobbs Adds X-Real-IP header support to all the FastCGI, SCGI, uWSGI, and CGI
alobbs authored
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * 02110-1301, USA.
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
23 */
860827a @alobbs Adds X-Real-IP header support to all the FastCGI, SCGI, uWSGI, and CGI
alobbs authored
24
25 #include "common-internal.h"
26 #include "xrealip.h"
27
28
29 ret_t
30 cherokee_x_real_ip_init (cherokee_x_real_ip_t *real_ip)
31 {
32 real_ip->enabled = false;
33 real_ip->access = NULL;
34 real_ip->access_all = false;
35
36 return ret_ok;
37 }
38
39
40 ret_t
41 cherokee_x_real_ip_mrproper (cherokee_x_real_ip_t *real_ip)
42 {
43 if (real_ip->access != NULL) {
44 cherokee_access_free (real_ip->access);
45 real_ip->access = NULL;
46 }
47
48 return ret_ok;
49 }
50
51
52 static ret_t
53 add_access (char *address, void *data)
54 {
55 ret_t ret;
56 cherokee_x_real_ip_t *real_ip = X_REAL_IP(data);
57
58 if (real_ip->access == NULL) {
59 ret = cherokee_access_new (&real_ip->access);
60 if (ret != ret_ok) {
61 return ret;
62 }
63 }
64
65 ret = cherokee_access_add (real_ip->access, address);
66 if (ret != ret_ok) {
67 return ret;
68 }
69
70 return ret_ok;
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
71
860827a @alobbs Adds X-Real-IP header support to all the FastCGI, SCGI, uWSGI, and CGI
alobbs authored
72 }
73
74
75 ret_t
76 cherokee_x_real_ip_configure (cherokee_x_real_ip_t *real_ip,
77 cherokee_config_node_t *config)
78 {
79 ret_t ret;
80 cherokee_config_node_t *subconf;
81
82 cherokee_config_node_read_bool (config, "x_real_ip_enabled", &real_ip->enabled);
83 cherokee_config_node_read_bool (config, "x_real_ip_access_all", &real_ip->access_all);
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
84
860827a @alobbs Adds X-Real-IP header support to all the FastCGI, SCGI, uWSGI, and CGI
alobbs authored
85 ret = cherokee_config_node_get (config, "x_real_ip_access", &subconf);
86 if (ret == ret_ok) {
87 ret = cherokee_config_node_read_list (subconf, NULL, add_access, real_ip);
88 if (ret != ret_ok) {
89 LOG_ERROR_S (CHEROKEE_ERROR_LOGGER_X_REAL_IP_PARSE);
90 return ret_error;
91 }
92 }
93
94 return ret_ok;
95 }
96
97
98 ret_t
99 cherokee_x_real_ip_is_allowed (cherokee_x_real_ip_t *real_ip,
100 cherokee_socket_t *sock)
101 {
102 ret_t ret;
103
104 if (! real_ip->access_all) {
105 if (real_ip->access == NULL) {
106 return ret_deny;
107 }
108
109 ret = cherokee_access_ip_match (real_ip->access, sock);
110 if (ret != ret_ok) {
111 return ret_deny;
112 }
113 }
114
115 return ret_ok;
116 }
Something went wrong with that request. Please try again.