1 /* tinyproxy - A fast light-weight HTTP proxy
2  * Copyright (C) 1998 Steven Young <sdyoung@miranda.org>
3  * Copyright (C) 1999-2005 Robert James Kaes <rjkaes@users.sourceforge.net>
4  * Copyright (C) 2009 Michael Adam <obnox@samba.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #include "connect-ports.h"
22 #include "log.h"
23 
24 /*
25  * Now, this routine adds a "port" to the list.  It also creates the list if
26  * it hasn't already by done.
27  */
add_connect_port_allowed(int port,sblist ** connect_ports)28 void add_connect_port_allowed (int port, sblist **connect_ports)
29 {
30         if (!*connect_ports) {
31                 *connect_ports = sblist_new (sizeof(int), 16);
32                 if (!*connect_ports) {
33                         log_message (LOG_WARNING,
34                                      "Could not create a list of allowed CONNECT ports");
35                         return;
36                 }
37         }
38 
39         log_message (LOG_INFO,
40                      "Adding Port [%d] to the list allowed by CONNECT", port);
41         sblist_add (*connect_ports, &port);
42 }
43 
44 /*
45  * This routine checks to see if a port is allowed in the CONNECT method.
46  *
47  * Returns: 1 if allowed
48  *          0 if denied
49  */
check_allowed_connect_ports(int port,sblist * connect_ports)50 int check_allowed_connect_ports (int port, sblist *connect_ports)
51 {
52         size_t i;
53         int *data;
54 
55         /*
56 	 * The absence of ConnectPort options in the config file
57 	 * meanas that all ports are allowed for CONNECT.
58          */
59         if (!connect_ports)
60                 return 1;
61 
62         for (i = 0; i < sblist_getsize (connect_ports); ++i) {
63                 data = sblist_get (connect_ports, i);
64                 if (data && *data == port)
65                         return 1;
66         }
67 
68         return 0;
69 }
70 
71 /**
72  * Free a connect_ports list.
73  */
free_connect_ports_list(sblist * connect_ports)74 void free_connect_ports_list (sblist *connect_ports)
75 {
76         sblist_free (connect_ports);
77 }
78