/[hydra]/hydra/src/access.c
ViewVC logotype

Contents of /hydra/src/access.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Sun Jan 26 11:25:39 2003 UTC (18 years, 10 months ago) by nmav
Branch: MAIN
CVS Tags: hydra_0_1_6_without_hic, hydra_0_1_7, hydra_0_1_6, hydra_0_1_4, hydra_0_1_8, HEAD
Changes since 1.2: +41 -40 lines
File MIME type: text/plain
Better large file support (now uses the included autoconf macros).
(++some indentation)

1 /*
2 * Boa, an http server
3 * Copyright (C) 2002 Nikos Mavroyanopoulos <nmav@gnutls.org>
4 * Based on patch for Boa by Peter Korsgaard <jacmet@sunsite.dk>
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 1, or (at your option)
9 * 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
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 /* $Id: access.c,v 1.2 2002/11/29 14:56:36 andreou Exp $ */
22
23 #include "boa.h"
24 #include "access.h"
25
26 #ifdef ENABLE_ACCESS_LISTS
27
28 #include <fnmatch.h>
29
30 void access_add(const char *hostname, const char *pattern, const int type)
31 {
32 virthost *vhost;
33
34 if (hostname == NULL || pattern == NULL) {
35 DIE("NULL values sent to access_add");
36 }
37
38 vhost = find_virthost(hostname, 0);
39 if (vhost == NULL) {
40 fprintf(stderr, "Tried to add Access for non-existing host %s.\n",
41 hostname);
42 exit(1);
43 }
44
45 vhost->n_access++;
46 vhost->access_nodes =
47 realloc(vhost->access_nodes,
48 vhost->n_access * sizeof(struct access_node));
49
50 if (vhost->access_nodes == NULL) {
51 DIE("out of memory");
52 }
53
54 vhost->access_nodes[vhost->n_access - 1].type = type;
55 vhost->access_nodes[vhost->n_access - 1].pattern = strdup(pattern);
56
57 } /* access_add */
58
59
60 int access_allow(const char *hostname, const char *file)
61 {
62 int i;
63 virthost *vhost = NULL;
64
65 vhost = find_virthost(hostname, 0);
66 if (vhost == NULL) {
67 return ACCESS_ALLOW;
68 }
69
70 /* find first match in allow/deny rules */
71 for (i = 0; i < vhost->n_access; i++) {
72 if (fnmatch(vhost->access_nodes[i].pattern, file, 0) == 0) {
73 return vhost->access_nodes[i].type;
74 }
75 }
76 /* default to allow *//* FIXME-andreou */
77 return ACCESS_ALLOW;
78 } /* access_allow */
79
80 #endif /* ENABLE_ACCESS_LISTS */
81
82 /* EOF */

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26