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

Contents of /hydra/src/config.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.15 - (show annotations)
Mon Oct 21 18:46:26 2002 UTC (21 years, 5 months ago) by nmav
Branch: MAIN
CVS Tags: hydra_0_0_8
Changes since 1.14: +7 -36 lines
File MIME type: text/plain
Added several stuff from Boa 0.94.14rc1

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26