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

Contents of /hydra/src/config.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (show annotations)
Mon Sep 30 17:16:54 2002 UTC (21 years, 6 months ago) by nmav
Branch: MAIN
CVS Tags: hydra_0_0_4, hydra_0_0_5
Changes since 1.11: +5 -3 lines
File MIME type: text/plain
Added support for multiple HIC threads.

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26