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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
|
/*
* $Id: config.c,v 1.1 1998/05/17 23:48:09 elkner Exp $
*
* Author: Jens Elkner elkner@ivs.cs.uni-magdeburg.de
* Project: Jesred http://ivs.cs.uni-magdeburg.de/~elkner/webtools/jesred/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* http://www.gnu.org/copyleft/gpl.html or ./gpl.html
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<ctype.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#ifdef LOCAL_REGEX
#include "regex.h"
#else
#include<regex.h>
#endif
#include "log.h"
#include "path.h"
#include "main.h"
#include "ip_list.h"
#include "pattern_list.h"
#include "config.h"
#include "util.h"
char *CleanLine(const char *);
const char *const w_space = " \t\n\r";
void
read_allow(char **file, ip_acl **list) {
FILE *fd;
char *token = NULL;
char buff[BUFSIZE];
/* struct in_addr addr; */
fd = fopen(*file, "r");
if(fd == NULL) {
token = strerror(errno);
mylog(ERROR, "unable to open local addresses file %s: %s\n",
*file ? *file : "", token);
echo_mode = 1;
return;
}
mylog(INFO, "Loading IP List from %s\n",*file);
while( !echo_mode && (fgets(buff, BUFSIZE, fd) != NULL) ) {
token = CleanLine(buff);
if ( token == NULL )
continue;
addToIPACL(list, token);
}
fclose(fd);
safe_free(*file);
}
void
read_config(char **allow, char **rules, char **redirect, char **rewrite)
{
FILE *fd;
char *token, *token2;
char buff[BUFSIZE];
echo_mode = 0;
allow_siblings = 0;
strcpy(buff,DEFAULT_PATH);
strcat(buff,"/");
strcat(buff,"jesred.conf");
if ( (fd=fopen(buff,"r")) == NULL) {
token = strerror(errno);
fprintf(stderr,"Can't open config file %s for reading: %s\n"
"Using echo mode!!!\n",
buff, token);
echo_mode++;
return;
}
/* just to be sure */
safe_free(*allow);
safe_free(*rules);
safe_free(*redirect);
safe_free(*rewrite);
while (fgets(buff, BUFSIZE, fd) != NULL) {
token = CleanLine(buff);
if ( token == NULL )
continue;
token2 = strchr(token,'=');
if (token2) {
*token2 = '\0';
token = CleanLine(token);
if (! token)
continue;
token2++;
token2 = CleanLine(token2);
if (! token2)
continue;
if ( ! strcasecmp(token,"allow") )
*allow = strdup(token2);
else if ( ! strcasecmp(token,"rules"))
*rules = strdup(token2);
else if (! strcasecmp(token,"redirect_log"))
*redirect = strdup(token2);
else if (! strcasecmp(token,"rewrite_log"))
*rewrite = strdup(token2);
#ifdef DEBUG
else if ( (! strcasecmp(token,"debug")) &&
(! strcasecmp(token2,"true")) )
debug_mode++;
#endif
else if (! strcasecmp(token,"siblings")) {
if (! strcasecmp(token2,"true"))
allow_siblings++;
}
else
fprintf(stderr,
"Unknown keyword or value \"%s = %s\" - ignored\n",
token ? token : "", token2 ? token2 : "");
}
}
fclose(fd);
}
/* attention - it changes the original string */
char *
CleanLine(const char *line) {
char *token = NULL;
int i;
token = (char *) line;
if (token[strlen(line)-1] == '\n')
token[strlen(line)-1] = '\0';
/* skip leading and trailing white space of the line */
token += strspn(line, w_space);
if ( *token == '#' ) {
return (NULL);
}
for(i= strlen(token) -1 ; i >= 0; i--) {
if (token[i] != ' ')
break;
else
token[i] = '\0';
}
if ( *token == '\0' ) {
return (NULL);
}
return (token);
}
/* load the squirm.patterns into linked list */
void
read_rules(char **file, pattern_item **plist) {
char buff[BUFSIZE];
FILE *fd;
char *token = NULL;
if ( ! *file || (fd = fopen(*file, "rt")) == NULL ) {
echo_mode = 1;
token = strerror(errno);
mylog(ERROR, "unable to open redirect patterns file %s: %s\n",
*file ? *file : "", token);
return;
}
mylog(INFO, "Reading Patterns from config %s\n", *file);
while(!echo_mode && (fgets(buff, BUFSIZE, fd) != NULL)) {
/* skip blank lines and comments */
token = CleanLine(buff);
if ( ! token)
continue;
add_to_patterns(token, plist);
}
fclose(fd);
safe_free(*file);
}
|