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

Contents of /hydra/src/config.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.21 - (show annotations)
Thu Mar 9 18:11:07 2006 UTC (18 years ago) by nmav
Branch: MAIN
CVS Tags: hydra_0_1_6_without_hic, hydra_0_1_8, HEAD
Changes since 1.20: +5 -14 lines
File MIME type: text/plain
Removed the HIC support.

1 /*
2 * Hydra, an http server
3 * Copyright (C) 1999 Larry Doolittle <ldoolitt@boa.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 1, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 */
20
21 /* $Id: config.c,v 1.20 2003/01/22 07:51:50 nmav Exp $*/
22
23 #include "boa.h"
24 #include "boa_grammar.h"
25 #include "access.h"
26 #include "parse.h"
27
28 int yyparse(void); /* Better match the output of lex */
29
30 #ifdef DEBUG
31 #define DBG(x) x
32 #else
33 #define DBG(x)
34 #endif
35
36 int server_port;
37 uid_t server_uid;
38 gid_t server_gid;
39 char *server_root;
40 char *server_name;
41 char *server_admin;
42 char *server_ip;
43 long int max_connections;
44 long int max_ssl_connections;
45
46 char * default_charset = NULL;
47
48 int max_files_cache = 256;
49 int max_file_size_cache = 100 * 1024;
50
51 int max_server_threads = 1;
52
53 char *server_cert;
54 char *server_key;
55 char *ca_cert = NULL;
56 int ssl_session_cache;
57 int ssl_verify = 0;
58 int boa_ssl = 0;
59 int ssl_port = 443;
60 int ssl_dh_bits = 1024; /* default value */
61 int ssl_session_timeout = 3600;
62 int maintenance_interval = 432000; /* every 5 days */
63
64 char *ssl_ciphers = NULL;
65 char *ssl_mac = NULL;
66 char *ssl_kx = NULL;
67 char *ssl_comp = NULL;
68 char *ssl_protocol = NULL;
69
70 char *default_type;
71 char *dirmaker;
72 char *cachedir;
73
74 char *tempdir;
75 int tempdir_len = 0;
76
77 char *cgi_path = NULL;
78 int cgi_umask = 027;
79 char *pid_file;
80
81 int single_post_limit = SINGLE_POST_LIMIT_DEFAULT;
82
83 int ka_timeout;
84 int ka_max;
85
86 /* These came from log.c */
87 char *error_log_name;
88 char *access_log_name;
89 char *cgi_log_name;
90
91 int use_localtime;
92
93 /* These are new */
94 static void c_set_user(char *v1, char* v2, char* v3, char* v4, void *t);
95 static void c_set_group(char *v1, char* v2, char* v3, char* v4, void *t);
96 static void c_set_string(char *v1, char* v2, char* v3, char* v4, void *t);
97 static void c_set_int(char *v1, char* v2, char* v3, char* v4, void *t);
98 static void c_set_longint(char *v1, char* v2, char* v3, char* v4, void *t);
99 static void c_set_unity(char *v1, char* v2, char* v3, char* v4, void *t);
100 static void c_add_type(char *v1, char* v2, char* v3, char* v4, void *t);
101 static void c_add_vhost(char *v1, char* v2, char* v3, char*v4, void *t);
102 static void c_set_documentroot(char *v1, char* v2, char* v3, char*v4, void *t);
103 static void c_add_alias(char *v1, char* v2, char* v3, char* v4, void *t);
104 static void c_add_dirindex(char *v1, char* v2, char* v3, char* v4, void *t);
105 static void c_add_cgi_action(char *v1, char* v2, char* v3, char* v4, void *t);
106 #ifdef ENABLE_ACCESS_LISTS
107 static void c_add_access(char *v1, char *v2, char* v3, char* v4, void *t);
108 #endif
109
110 /* Fakery to keep the value passed to action() a void *,
111 see usage in table and c_add_alias() below */
112 static int script_number = SCRIPTALIAS;
113 static int redirect_number = REDIRECT;
114 static int alias_number = ALIAS;
115 static uid_t current_uid=0;
116
117 /* Help keep the table below compact */
118 #define S0A STMT_NO_ARGS
119 #define S1A STMT_ONE_ARG
120 #define S2A STMT_TWO_ARGS
121 #define S3A STMT_THREE_ARGS
122 #define S4A STMT_FOUR_ARGS
123
124 struct ccommand clist[] = {
125 {"SSLVerifyClient", S1A, c_set_int, &ssl_verify},
126 {"SSLCiphers", S1A, c_set_string, &ssl_ciphers},
127 {"SSLKeyExchangeAlgorithms", S1A, c_set_string, &ssl_kx},
128 {"SSLMACAlgorithms", S1A, c_set_string, &ssl_mac},
129 {"SSLProtocols", S1A, c_set_string, &ssl_protocol},
130 {"SSLCompressionMethods", S1A, c_set_string, &ssl_comp},
131 {"SSLCertificate", S1A, c_set_string, &server_cert},
132 {"SSLCAList", S1A, c_set_string, &ca_cert},
133 {"SSLKey", S1A, c_set_string, &server_key},
134 {"SSLSessionCache", S1A, c_set_int, &ssl_session_cache},
135 {"SSL", S1A, c_set_int, &boa_ssl},
136 {"SSLPort", S1A, c_set_int, &ssl_port},
137 {"SSLDHBits", S1A, c_set_int, &ssl_dh_bits},
138 {"SSLSessionTimeout", S1A, c_set_int, &ssl_session_timeout},
139 {"MaintenanceInterval", S1A, c_set_int, &maintenance_interval},
140 {"Threads", S1A, c_set_int, &max_server_threads},
141 {"Port", S1A, c_set_int, &server_port},
142 {"Listen", S1A, c_set_string, &server_ip},
143 {"BackLog", S1A, c_set_int, &backlog},
144 {"User", S1A, c_set_user, NULL},
145 {"Group", S1A, c_set_group, NULL},
146 {"ServerAdmin", S1A, c_set_string, &server_admin},
147 {"ServerRoot", S1A, c_set_string, &server_root},
148 {"ErrorLog", S1A, c_set_string, &error_log_name},
149 {"AccessLog", S1A, c_set_string, &access_log_name},
150 {"UseLocaltime", S0A, c_set_unity, &use_localtime},
151 {"CgiLog", S1A, c_set_string, &cgi_log_name},
152 {"VerboseCGILogs", S0A, c_set_unity, &verbose_cgi_logs},
153 {"ServerName", S1A, c_set_string, &server_name},
154 {"DocumentRoot", S1A, c_set_documentroot, NULL},
155 {"DirectoryIndex", S1A, c_add_dirindex, NULL},
156 {"DirectoryMaker", S1A, c_set_string, &dirmaker},
157 {"DirectoryCache", S1A, c_set_string, &cachedir},
158 {"KeepAliveMax", S1A, c_set_int, &ka_max},
159 {"KeepAliveTimeout", S1A, c_set_int, &ka_timeout},
160 {"MimeTypes", S1A, c_set_string, &mime_types},
161 {"DefaultType", S1A, c_set_string, &default_type},
162 {"DefaultCharset", S1A, c_set_string, &default_charset},
163 {"AddType", S2A, c_add_type, NULL},
164 {"CGIAction", S2A, c_add_cgi_action, NULL},
165 {"ScriptAlias", S3A, c_add_alias, &script_number},
166 {"Redirect", S3A, c_add_alias, &redirect_number},
167 {"Alias", S3A, c_add_alias, &alias_number},
168 {"PidFile", S1A, c_set_string, &pid_file},
169 {"CGIumask", S1A, c_set_int, &cgi_umask},
170 {"CGILog", S1A, c_set_string, &cgi_log_name},
171 /* HOST - IP - DOCUMENT_ROOT - USER_DIR */
172 {"VirtualHost", S4A, c_add_vhost, NULL},
173 {"SinglePostLimit", S1A, c_set_int, &single_post_limit},
174 {"CGIPath", S1A, c_set_string, &cgi_path},
175 {"MaxSSLConnections", S1A, c_set_longint, &max_ssl_connections},
176 {"MaxConnections", S1A, c_set_longint, &max_connections},
177 {"MaxFilesCache", S1A, c_set_int, &max_files_cache},
178 {"MaxFileSizeCache", S1A, c_set_int, &max_file_size_cache},
179 #ifdef ENABLE_ACCESS_LISTS
180 {"Allow", S2A, c_add_access, (void*)ACCESS_ALLOW},
181 {"Deny", S2A, c_add_access, (void*)ACCESS_DENY},
182 #endif
183 };
184
185 static void c_set_user(char *v1, char* v2, char* v3, char* v4, void *t)
186 {
187 struct passwd *passwdbuf;
188 char *endptr;
189 int i;
190
191 DBG(printf("User %s = ", v1);
192 )
193 i = strtol(v1, &endptr, 0);
194 if (*v1 != '\0' && *endptr == '\0') {
195 server_uid = i;
196 } else {
197 passwdbuf = getpwnam(v1);
198 if (!passwdbuf) {
199 if (current_uid)
200 return;
201 fprintf(stderr, "No such user: %s\n", v1);
202 exit(1);
203 }
204 server_uid = passwdbuf->pw_uid;
205 }
206 DBG(printf("%d\n", server_uid);
207 )
208 }
209
210 static void c_set_group(char *v1, char* v2, char* v3, char* v4, void *t)
211 {
212 struct group *groupbuf;
213 char *endptr;
214 int i;
215 DBG(printf("Group %s = ", v1);
216 )
217 i = strtol(v1, &endptr, 0);
218 if (*v1 != '\0' && *endptr == '\0') {
219 server_gid = i;
220 } else {
221 groupbuf = getgrnam(v1);
222 if (!groupbuf) {
223 if (current_uid)
224 return;
225 fprintf(stderr, "No such group: %s\n", v1);
226 exit(1);
227 }
228 server_gid = groupbuf->gr_gid;
229 }
230 DBG(printf("%d\n", server_gid);
231 )
232 }
233
234 static void c_set_string(char *v1, char* v2, char* v3, char* v4, void *t)
235 {
236 char *s;
237 DBG(printf("Setting pointer %p to string %s ..", t, v1);
238 )
239 if (t) {
240 s = *(char **) t;
241 if (s)
242 free(s);
243 *(char **) t = strdup(v1);
244 if (!*(char **) t) {
245 DIE("Unable to strdup in c_set_string");
246 }
247 DBG(printf("done.\n");
248 )
249 } else {
250 DBG(printf("skipped.\n");
251 )
252 }
253 }
254
255 static void c_set_documentroot(char *v1, char* v2, char* v3, char* v4, void *t)
256 {
257 /* Add the "", which is the default virtual host */
258 add_virthost("", "*", v1, "");
259 }
260
261 static void c_set_int(char *v1, char* v2, char* v3, char* v4, void *t)
262 {
263 char *endptr;
264 int i;
265 DBG(printf("Setting pointer %p to integer string %s ..", t, v1);
266 )
267 if (t) {
268 i = strtol(v1, &endptr, 0); /* Automatic base 10/16/8 switching */
269 if (*v1 != '\0' && *endptr == '\0') {
270 *(int *) t = i;
271 DBG(printf(" Integer converted as %d, done\n", i);
272 )
273 } else {
274 /* XXX should tell line number to user */
275 fprintf(stderr, "Error: %s found where integer expected\n",
276 v1);
277 }
278 } else {
279 DBG(printf("skipped.\n");
280 )
281 }
282 }
283
284 static void c_set_longint(char *v1, char* v2, char* v3, char* v4, void *t)
285 {
286 char *endptr;
287 int i;
288 DBG(printf("Setting pointer %p to long integer string %s ..", t, v1);
289 )
290 if (t) {
291 i = strtol(v1, &endptr, 0); /* Automatic base 10/16/8 switching */
292 if (*v1 != '\0' && *endptr == '\0') {
293 *(long int *) t = i;
294 DBG(printf(" Integer converted as %d, done\n", i);
295 )
296 } else {
297 /* XXX should tell line number to user */
298 fprintf(stderr, "Error: %s found where integer expected\n",
299 v1);
300 }
301 } else {
302 DBG(printf("skipped.\n");
303 )
304 }
305 }
306
307 static void c_set_unity(char *v1, char* v2, char* v3, char* v4, void *t)
308 {
309 DBG(printf("Setting pointer %p to unity\n", t);
310 )
311 if (t)
312 *(int *) t = 1;
313 }
314
315 static void c_add_type(char *v1, char* v2, char* v3, char* v4, void *t)
316 {
317 add_mime_type(v2, v1);
318 }
319
320 static void c_add_cgi_action(char *v1, char* v2, char* v3, char* v4, void *t)
321 {
322 add_cgi_action(v1, v2);
323 }
324
325 static void c_add_dirindex(char *v1, char* v2, char* v3, char* v4, void *t)
326 {
327 add_directory_index(v1);
328 }
329
330 static void c_add_vhost(char *v1, char *v2, char* v3, char* v4, void *t)
331 {
332 add_virthost(v1, v2, v3, v4);
333 }
334
335
336 static void c_add_alias(char *v1, char *v2, char* v3, char* v4, void *t)
337 {
338 add_alias(v1, v2, v3, *(int *) t);
339 }
340
341 struct ccommand *lookup_keyword(char *c)
342 {
343 struct ccommand *p;
344 DBG(printf("Checking string '%s' against keyword list\n", c);
345 )
346 for (p = clist;
347 p < clist + (sizeof (clist) / sizeof (struct ccommand)); p++) {
348 if (strcmp(c, p->name) == 0)
349 return p;
350 }
351 return NULL;
352 }
353
354 /*
355 * Name: read_config_files
356 *
357 * Description: Reads config files via yyparse, then makes sure that
358 * all required variables were set properly.
359 */
360 void read_config_files(void)
361 {
362 current_uid = getuid();
363 yyin = fopen("hydra.conf", "r");
364
365 if (!yyin) {
366 fputs("Could not open hydra.conf for reading.\n", stderr);
367 exit(1);
368 }
369 if (yyparse()) {
370 fputs("Error parsing config files, exiting\n", stderr);
371 exit(1);
372 }
373
374 if (!server_name) {
375 struct hostent *he;
376 char temp_name[100];
377
378 if (gethostname(temp_name, 100) == -1) {
379 perror("gethostname:");
380 exit(1);
381 }
382
383 he = gethostbyname(temp_name);
384 if (he == NULL) {
385 perror("gethostbyname:");
386 exit(1);
387 }
388
389 server_name = strdup(he->h_name);
390 if (server_name == NULL) {
391 perror("strdup:");
392 exit(1);
393 }
394 }
395 tempdir = getenv("TMPDIR");
396 if (tempdir == NULL)
397 tempdir = "/tmp";
398 tempdir_len = strlen( tempdir);
399
400 if (single_post_limit < 0) {
401 fprintf(stderr, "Invalid value for single_post_limit: %d\n",
402 single_post_limit);
403 exit(1);
404 }
405
406 }
407
408 #ifdef ENABLE_ACCESS_LISTS
409 static void c_add_access(char *v1, char *v2, char* v3, char* v4, void *t)
410 {
411 access_add(v1, v2, (int)t);
412 }
413 #endif

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26