source: trunk/src/sh_readconf.c@ 327

Last change on this file since 327 was 315, checked in by katerina, 14 years ago

Fix for ticket #236 (blocking on NFS mounts).

File size: 39.4 KB
Line 
1/* SAMHAIN file system integrity testing */
2/* Copyright (C) 1999, 2000 Rainer Wichmann */
3/* */
4/* This program is free software; you can redistribute it */
5/* and/or modify */
6/* it under the terms of the GNU General Public License as */
7/* published by */
8/* the Free Software Foundation; either version 2 of the License, or */
9/* (at your option) 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#include "config_xor.h"
21
22
23#include <stdlib.h>
24#include <stdio.h>
25#include <string.h>
26#include <ctype.h>
27
28
29#include "samhain.h"
30#include "sh_calls.h"
31#include "sh_error.h"
32#include "sh_extern.h"
33#include "sh_files.h"
34#include "sh_forward.h"
35#include "sh_gpg.h"
36#include "sh_hash.h"
37#include "sh_ignore.h"
38#include "sh_database.h"
39#include "sh_mail.h"
40#include "sh_modules.h"
41#include "sh_nmail.h"
42#include "sh_prelink.h"
43#ifdef HAVE_LIBPRELUDE
44#include "sh_prelude.h"
45#endif
46#include "sh_tiger.h"
47#include "sh_tools.h"
48#include "sh_unix.h"
49#include "sh_utils.h"
50#include "sh_restrict.h"
51
52
53extern int set_reverse_lookup (const char * c);
54
55#undef FIL__
56#define FIL__ _("sh_readconf.c")
57
58typedef enum {
59 SH_SECTION_NONE,
60 SH_SECTION_LOG,
61 SH_SECTION_MISC,
62 SH_SECTION_ATTRIBUTES,
63 SH_SECTION_READONLY,
64 SH_SECTION_LOGFILES,
65 SH_SECTION_LOGGROW,
66 SH_SECTION_NOIGNORE,
67 SH_SECTION_ALLIGNORE,
68 SH_SECTION_USER0,
69 SH_SECTION_USER1,
70 SH_SECTION_USER2,
71 SH_SECTION_USER3,
72 SH_SECTION_USER4,
73 SH_SECTION_PRELINK,
74#if defined (SH_WITH_MAIL)
75 SH_SECTION_MAIL,
76#endif
77#if defined (SH_WITH_CLIENT)
78 SH_SECTION_CLT,
79#endif
80#ifdef WITH_EXTERNAL
81 SH_SECTION_EXTERNAL,
82#endif
83#ifdef WITH_DATABASE
84 SH_SECTION_DATABASE,
85#endif
86#if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
87 SH_SECTION_OTHER,
88#endif
89#ifdef SH_WITH_SERVER
90 SH_SECTION_CLIENTS,
91 SH_SECTION_SRV,
92#endif
93 SH_SECTION_THRESHOLD
94} ShSectionType;
95
96typedef struct str_ListSections {
97 const char * name;
98 int type;
99} sh_str_ListSections;
100
101struct str_ListSections tab_ListSections[] = {
102 { N_("[Log]"), SH_SECTION_LOG},
103 { N_("[Misc]"), SH_SECTION_MISC},
104 { N_("[Attributes]"), SH_SECTION_ATTRIBUTES},
105 { N_("[ReadOnly]"), SH_SECTION_READONLY},
106 { N_("[LogFiles]"), SH_SECTION_LOGFILES},
107 { N_("[GrowingLogFiles]"), SH_SECTION_LOGGROW},
108 { N_("[IgnoreAll]"), SH_SECTION_ALLIGNORE},
109 { N_("[IgnoreNone]"), SH_SECTION_NOIGNORE},
110 { N_("[User0]"), SH_SECTION_USER0},
111 { N_("[User1]"), SH_SECTION_USER1},
112 { N_("[User2]"), SH_SECTION_USER2},
113 { N_("[User3]"), SH_SECTION_USER3},
114 { N_("[User4]"), SH_SECTION_USER4},
115 { N_("[Prelink]"), SH_SECTION_PRELINK},
116#ifdef WITH_EXTERNAL
117 { N_("[External]"), SH_SECTION_EXTERNAL},
118#endif
119#ifdef WITH_DATABASE
120 { N_("[Database]"), SH_SECTION_DATABASE},
121#endif
122 { N_("[EventSeverity]"), SH_SECTION_THRESHOLD},
123#ifdef SH_WITH_SERVER
124 { N_("[Clients]"), SH_SECTION_CLIENTS},
125 { N_("[Server]"), SH_SECTION_SRV},
126#endif
127#if defined (SH_WITH_CLIENT)
128 { N_("[Client]"), SH_SECTION_CLT},
129#endif
130#if defined (SH_WITH_MAIL)
131 { N_("[Mail]"), SH_SECTION_MAIL},
132#endif
133 { NULL, SH_SECTION_NONE}
134};
135
136static char * sh_readconf_expand_value (const char * str)
137{
138 char * tmp = (char*)str;
139 char * out;
140
141 while (tmp && isspace((int)*tmp)) ++tmp;
142
143 if (tmp[0] == '$' && tmp[1] == '(')
144 {
145 size_t len = strlen(tmp);
146 while (isspace((int) tmp[len-1])) { tmp[len-1] = '\0'; --len; }
147 if (tmp[len-1] == ')')
148 {
149 tmp[len-1] = '\0';
150 out = sh_ext_popen_str(&tmp[2]);
151 return out;
152 }
153 }
154 return sh_util_strdup(str);
155}
156
157enum {
158 SH_RC_ANY = 0,
159 SH_RC_HOST = 1,
160 SH_RC_SYSTEM = 2,
161 SH_RC_FILE = 3,
162 SH_RC_IFACE = 4,
163 SH_RC_CMD = 5
164};
165
166
167static int sh_readconf_cond_match(char * str, int line)
168{
169 int match = 0;
170 int negate = 1;
171 int cond_type = SH_RC_ANY;
172 char myident[3*SH_MINIBUF+3];
173 struct stat buf;
174
175 char * p = str;
176
177 if (*p == '!') { negate = 0; ++p; }
178 if (*p == '$') {
179 cond_type = SH_RC_SYSTEM; ++p; /* [!]$system */
180 }
181 else { /* *p == '@' */
182
183 ++p; while (isspace((int)*p)) ++p;
184
185 if (0 != strncasecmp(p, _("if "), 3)) {
186 cond_type = SH_RC_HOST; /* [!]$host */
187 }
188
189 else {
190
191 p += 3; while (isspace((int)*p)) ++p; /* skip the 'if\s+' */
192
193 if (0 == strncasecmp(p, _("not "), 4))
194 {
195 p += 4; while (isspace((int)*p)) ++p;
196 negate = 0;
197 }
198 else if (0 == strncmp(p, _("!"), 1))
199 {
200 ++p; while (isspace((int)*p)) ++p;
201 negate = 0;
202 }
203
204 if (0 == strncasecmp(p, _("file_exists "), 12))
205 {
206 p += 12; cond_type = SH_RC_FILE;
207 }
208 else if (0 == strncasecmp(p, _("interface_exists "), 17))
209 {
210 p += 17; cond_type = SH_RC_IFACE;
211 }
212 else if (0 == strncasecmp(p, _("hostname_matches "), 17))
213 {
214 p += 17; cond_type = SH_RC_HOST;
215 }
216 else if (0 == strncasecmp(p, _("system_matches "), 15))
217 {
218 p += 15; cond_type = SH_RC_SYSTEM;
219 }
220 else if (0 == strncasecmp(p, _("command_succeeds "), 17))
221 {
222 p += 17; cond_type = SH_RC_CMD;
223 }
224 else
225 {
226 char errbuf[SH_ERRBUF_SIZE];
227 sl_snprintf(errbuf, sizeof(errbuf),
228 _("Unsupported test at line %d of configuration file"),
229 line);
230 sh_error_handle(SH_ERR_ERR, FIL__, __LINE__, 0, MSG_E_SUBGEN,
231 errbuf,
232 _("sh_readconf_cond_match"));
233 return 0;
234 }
235 }
236 }
237
238 while (isspace((int)*p)) ++p;
239
240 switch (cond_type)
241 {
242 case SH_RC_HOST:
243 if (sl_strncmp (p, sh.host.name, strlen(sh.host.name)) == 0
244#ifdef HAVE_REGEX_H
245 || sh_util_regcmp (p, sh.host.name) == 0
246#endif
247 )
248 match = negate;
249 break;
250 case SH_RC_SYSTEM:
251 /*
252 * The system type, release, and machine.
253 */
254 sl_snprintf(myident, sizeof(myident), _("%s:%s:%s"),
255 sh.host.system, /* flawfinder: ignore */
256 sh.host.release, sh.host.machine);
257
258 if (sl_strncmp (p, myident, strlen(myident)) == 0
259#ifdef HAVE_REGEX_H
260 || sh_util_regcmp (p, myident) == 0
261#endif
262 )
263 match = negate;
264 break;
265 case SH_RC_FILE:
266 if (0 == retry_lstat(FIL__, __LINE__, p, &buf))
267 match = negate;
268 break;
269 case SH_RC_IFACE:
270 if (sh_tools_iface_is_present(p))
271 match = negate;
272 break;
273 case SH_RC_CMD:
274 if (0 == sh_unix_run_command(p))
275 match = negate;
276 break;
277 default:
278 match = 0;
279 }
280 return match;
281}
282
283static int sh_readconf_is_end (char * str)
284{
285 int retval = 0;
286
287 if (str[0] == '@' || str[0] == '$')
288 {
289 char * p = str;
290 ++p; while (isspace((int)*p)) ++p;
291 if (
292 (0 == strncasecmp (p, _("end"), 3) && (p[3] == '\0' || isspace((int)p[3]))) ||
293 (0 == strncasecmp (p, _("fi"), 2) && (p[2] == '\0' || isspace((int)p[2])))
294 )
295 {
296 return 1;
297 }
298 }
299 return retval;
300}
301
302static int sh_readconf_is_else (char * str)
303{
304 int retval = 0;
305
306 if (str[0] == '@')
307 {
308 char * p = str;
309 ++p; while (isspace((int)*p)) ++p;
310 if ( 0 == strncasecmp (p, _("else"), 4) && (p[4] == '\0' || isspace((int)p[4])) )
311 {
312 return 1;
313 }
314 }
315 return retval;
316}
317
318static int sh_readconfig_line (char * line);
319
320static ShSectionType read_mode = SH_SECTION_NONE;
321
322static int conf_line = 0;
323
324/* --- Read the configuration file. ---
325 */
326int sh_readconf_read (void)
327{
328#if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
329 /* This is for modules.
330 */
331 int modnum;
332#endif
333
334 int i;
335
336 SL_TICKET fd = -1;
337#if defined(SH_STEALTH) && !defined(SH_STEALTH_MICRO)
338 SL_TICKET fdTmp = -1;
339 SL_TICKET open_tmp (void);
340#endif
341 char * tmp;
342
343#define SH_LINE_IN 16384
344 char * line_in;
345 char * line;
346
347 /* This is for nested conditionals.
348 */
349 int cond_depth = 0;
350 int cond_excl = 0;
351
352 int local_file = 1;
353 char local_flag = 'R';
354
355#if defined(WITH_GPG) || defined(WITH_PGP)
356 int signed_content = S_FALSE;
357 int true_content = S_FALSE;
358#endif
359#if defined(SH_STEALTH) && !defined(SH_STEALTH_MICRO)
360 int hidden_count = 0;
361#endif
362 uid_t euid;
363 char hashbuf[KEYBUF_SIZE];
364
365 SL_ENTER(_("sh_readconf_read"));
366
367 /* --- Open config file, exit on failure. ---
368 */
369#if defined(SH_WITH_CLIENT)
370 if (0 == sl_strcmp(file_path('C', 'R'), _("REQ_FROM_SERVER")))
371 {
372 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_D_START);
373
374 fd = sh_forward_req_file(_("CONF"));
375
376 if (!SL_ISERROR(fd))
377 {
378 local_file = 0;
379 }
380 else if (sh.flag.checkSum != SH_CHECK_INIT)
381 {
382 aud_exit (FIL__, __LINE__, EXIT_FAILURE);
383 }
384 else
385 {
386 sh_error_handle ((-1), FIL__, __LINE__, fd, MSG_D_FAIL);
387 local_file = 1;
388 local_flag = 'I';
389 }
390 }
391#endif
392
393 /* Use a local configuration file.
394 */
395 if (local_file == 1)
396 {
397 if (0 != tf_trust_check (file_path('C', local_flag), SL_YESPRIV))
398 {
399 sl_get_euid(&euid);
400 dlog(1, FIL__, __LINE__,
401 _("The configuration file: %s is untrusted, i.e. an\nuntrusted user owns or can write to some directory in the path.\n"),
402 ( (NULL == file_path('C', local_flag))
403 ? _("(null)") : file_path('C', local_flag) ));
404 sh_error_handle ((-1), FIL__, __LINE__, EACCES, MSG_TRUST,
405 (long) euid,
406 ( (NULL == file_path('C', local_flag))
407 ? _("(null)") : file_path('C', local_flag) )
408 );
409 aud_exit (FIL__, __LINE__, EXIT_FAILURE);
410 }
411 if (SL_ISERROR(fd = sl_open_read(FIL__, __LINE__,
412 file_path('C',local_flag),SL_YESPRIV)))
413 {
414 sl_get_euid(&euid);
415 dlog(1, FIL__, __LINE__,
416 _("Could not open the local configuration file for reading because\nof the following error: %s (errnum = %ld)\nIf this is a permission problem, you need to change file permissions\nto make the file readable for the effective UID: %d\n"),
417 sl_get_errmsg(), fd, (int) euid);
418 sh_error_handle ((-1), FIL__, __LINE__, fd, MSG_NOACCESS,
419 (long) euid,
420 ( (NULL == file_path('C', local_flag))
421 ? _("(null)") : file_path('C', local_flag) )
422 );
423 aud_exit (FIL__, __LINE__, EXIT_FAILURE);
424 }
425 }
426
427 /* Compute the checksum of the open file.
428 */
429 sl_strlcpy(sh.conf.hash,
430 sh_tiger_hash(file_path('C',local_flag), fd, TIGER_NOLIM,
431 hashbuf, sizeof(hashbuf)),
432 KEY_LEN+1);
433 sl_rewind (fd);
434
435 line_in = SH_ALLOC(SH_LINE_IN);
436
437#if defined(SH_STEALTH) && !defined(SH_STEALTH_MICRO)
438 /* extract the data and copy to temporary file
439 */
440 fdTmp = open_tmp();
441
442 sh_unix_getline_stealth (0, NULL, 0); /* initialize */
443
444 while ( sh_unix_getline_stealth (fd, line_in, SH_LINE_IN-2) > 0) {
445 hidden_count++;
446 if (line_in[0] == '\n')
447 {
448 sl_write(fdTmp, line_in, 1);
449 }
450 else
451 {
452 sl_write_line(fdTmp, line_in, sl_strlen(line_in));
453 }
454#if defined(WITH_GPG) || defined(WITH_PGP)
455 if (0 == sl_strncmp(line_in, _("-----END PGP SIGNATURE-----"), 25))
456 break;
457#else
458 if (0 == sl_strncmp(line_in, _("[EOF]"), 5))
459 break;
460#endif
461 if (hidden_count > 1048576) /* arbitrary safeguard, 1024*1024 */
462 break;
463 }
464 sl_close(fd);
465 fd = fdTmp;
466 sl_rewind (fd);
467#endif
468
469
470 /* --- Start reading lines. ---
471 */
472 conf_line = 0;
473
474 while ( sh_unix_getline (fd, line_in, SH_LINE_IN-2) > 0) {
475
476 ++conf_line;
477
478 line = &(line_in[0]);
479
480 /* fprintf(stderr, "<%s>\n", line); */
481
482 /* Sun May 27 18:40:05 CEST 2001
483 */
484#if defined(WITH_GPG) || defined(WITH_PGP)
485 if (signed_content == S_FALSE)
486 {
487 if (0 == sl_strcmp(line, _("-----BEGIN PGP SIGNED MESSAGE-----")))
488 signed_content = S_TRUE;
489 else
490 continue;
491 }
492 else if (true_content == S_FALSE)
493 {
494 if (line[0] == '\n')
495 true_content = S_TRUE;
496 else
497 continue;
498 }
499 else if (signed_content == S_TRUE)
500 {
501 if (0 == sl_strcmp(line, _("-----BEGIN PGP SIGNATURE-----")))
502 break;
503 else if (0 == sl_strcmp(line, _("-----BEGIN PGP SIGNED MESSAGE-----")))
504 {
505 sh_error_handle((-1), FIL__, __LINE__, 0, MSG_E_SUBGEN,
506 _("second signed message in file"),
507 _("sh_readconf_read"));
508 dlog(1, FIL__, __LINE__,
509 _("There seems to be more than one signed message in the configuration\nfile. Please make sure there is only one signed message.\n"));
510 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_EXIT_ABORT1,
511 sh.prg_name);
512 SH_FREE(line_in);
513 aud_exit (FIL__, __LINE__,EXIT_FAILURE);
514 }
515 }
516#endif
517
518 /* Skip leading white space.
519 */
520 while (isspace((int)*line)) ++line;
521
522
523 /* Skip header etc.
524 */
525 if (line[0] == '#' || line[0] == '\0' || line[0] == ';' ||
526 (line[0] == '/' && line[1] == '/'))
527 continue;
528
529 /* Clip off trailing white space.
530 */
531 tmp = line + sl_strlen( line ); --tmp;
532 while( isspace((int) *tmp ) && tmp >= line ) *tmp-- = '\0';
533
534
535 /* --- an @host/@if/$system directive -------------- */
536
537 if (line[0] == '@' || (line[0] == '!' && line[1] == '@') ||
538 line[0] == '$' || (line[0] == '!' && line[1] == '$'))
539 {
540 if (sh_readconf_is_end(line))
541 {
542 if (0 == cond_depth) {
543 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_EINVALD,
544 _("config file"),
545 (long) conf_line);
546 }
547 else {
548 if (cond_excl == cond_depth)
549 cond_excl = 0;
550 --cond_depth;
551 }
552 }
553 else if (sh_readconf_is_else(line))
554 {
555 if (0 == cond_depth) {
556 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_EINVALD,
557 _("config file"),
558 (long) conf_line);
559 }
560 else if (cond_excl == cond_depth) {
561 cond_excl = 0;
562 }
563 else if (cond_excl == 0) {
564 cond_excl = cond_depth;
565 }
566 }
567 else
568 {
569 if (sh_readconf_cond_match(line, conf_line)) {
570 ++cond_depth;
571 }
572 else {
573 ++cond_depth;
574 if (cond_excl == 0)
575 cond_excl = cond_depth;
576 }
577 }
578 continue;
579 }
580
581 /****************************************************
582 *
583 * Only carry on if this section is intended for us
584 *
585 ****************************************************/
586
587 if (cond_excl != 0) {
588 continue;
589 }
590
591 /* ------- starts a section ------------ */
592
593 else if (line[0] == '[')
594 {
595 read_mode = SH_SECTION_NONE;
596
597 if (0 == sl_strncasecmp (line, _("[EOF]"), 5)) {
598 goto nopel;
599 }
600
601 i = 0;
602
603 while (tab_ListSections[i].name != 0)
604 {
605 if (sl_strncasecmp (line, _(tab_ListSections[i].name),
606 sl_strlen(tab_ListSections[i].name)) == 0)
607 {
608 read_mode = tab_ListSections[i].type;
609 break;
610 }
611 ++i;
612 }
613
614#if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
615 if (read_mode == SH_SECTION_NONE)
616 {
617 for (modnum = 0; modList[modnum].name != NULL; ++modnum)
618 {
619 if (0 == sl_strncasecmp (line, _(modList[modnum].conf_section),
620 sl_strlen(modList[modnum].conf_section)) )
621 read_mode = SH_SECTION_OTHER;
622 }
623 }
624#endif
625 if (read_mode == SH_SECTION_NONE)
626 {
627 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_EINVALHEAD,
628 (long) conf_line);
629 }
630 }
631
632 /* --- an %schedule directive ------------ */
633
634 else if (line[0] == '%' || (line[0] == '!' && line[1] == '%'))
635 {
636#if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
637 if (line[0] == '!' && 0 == sl_strcasecmp(&(line[2]), _("SCHEDULE_TWO")))
638 set_dirList(1);
639 else if (0 == sl_strcasecmp(&(line[1]), _("SCHEDULE_TWO")))
640 set_dirList(2);
641#else
642 ;
643#endif
644 }
645
646 /* ------ no new section -------------- */
647
648
649 else if (read_mode != SH_SECTION_NONE)
650 {
651 if (0 != sh_readconfig_line (line))
652 {
653 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_EINVALCONF,
654 (long) conf_line);
655 }
656 }
657 } /* while getline() */
658
659 nopel:
660
661 if (0 != cond_depth)
662 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_EINVALDD,
663 _("config file"),
664 (long) conf_line);
665
666#if defined(WITH_GPG) || defined(WITH_PGP)
667 /* Validate signature of open file.
668 */
669 sl_rewind (fd);
670 if (0 != sh_gpg_check_sign (fd, 0, 1))
671 {
672 SH_FREE(line_in);
673 aud_exit (FIL__, __LINE__, EXIT_FAILURE);
674 }
675#endif
676
677 sl_close (fd);
678
679 sh_error_fixup();
680
681 read_mode = SH_SECTION_NONE; /* reset b/o sighup reload */
682
683 SH_FREE(line_in);
684 SL_RETURN( 0, _("sh_readconf_read"));
685}
686
687int sh_readconf_set_path (char * which, const char * what)
688{
689 int len;
690 SL_ENTER( _("sh_readconf_set_path"));
691
692 if (which == NULL || what == NULL)
693 {
694 TPT((0, FIL__, __LINE__ , _("msg=<Input error>\n")));
695 SL_RETURN( -1, _("sh_readconf_set_path"));
696 }
697
698 if (0 == sl_strcmp(what, _("AUTO")))
699 {
700 len = sl_strlen(which);
701 if ( (len + sl_strlen(sh.host.name) + 2) > SH_PATHBUF)
702 {
703 TPT((0, FIL__, __LINE__ , _("msg=<Path too large: %s:%s>\n"),
704 which, sh.host.name));
705 SL_RETURN( -1, _("sh_readconf_set_path"));
706 }
707 else
708 {
709 which[len] = ':'; which[len+1] = '\0';
710 sl_strlcat(which, sh.host.name, SH_PATHBUF);
711 }
712 }
713 else /* not auto */
714 {
715 if (sl_strlen(what) > (SH_PATHBUF-1))
716 {
717 TPT((0, FIL__, __LINE__ , _("msg=<Path too large: %s>\n"), what));
718 SL_RETURN( -1, _("sh_readconf_set_path"));
719 }
720 else
721 {
722 sl_strlcpy(which, what, SH_PATHBUF);
723 }
724 }
725 SL_RETURN( 0, _("sh_readconf_set_path"));
726}
727
728int sh_readconf_set_database_path (const char * what)
729{
730 return (sh_readconf_set_path(sh.data.path, what));
731}
732
733int sh_readconf_set_logfile_path (const char * what)
734{
735 return (sh_readconf_set_path(sh.srvlog.name, what));
736}
737
738int sh_readconf_set_lockfile_path (const char * what)
739{
740 return( sh_readconf_set_path(sh.srvlog.alt, what));
741}
742
743
744
745
746typedef enum {
747 SET_MAILTIME,
748 SET_FILETIME
749} ShTimerItem;
750
751
752int sh_readconf_setTime (const char * str, ShTimerItem what)
753{
754 unsigned long i = atoi (str);
755
756 SL_ENTER( _("sh_readconf_setTime"));
757
758 if (i < LONG_MAX)
759 {
760 if (what == SET_MAILTIME)
761 {
762 TPT((0, FIL__, __LINE__, _("msg=<Set mail timer to %ld>\n"), i));
763 sh.mailTime.alarm_interval = i;
764 }
765 else if (what == SET_FILETIME)
766 {
767 TPT((0, FIL__, __LINE__, _("msg=<Set filecheck timer to %ld>\n"),i));
768 sh.fileCheck.alarm_interval = i;
769 }
770
771 SL_RETURN( 0, _("sh_readconf_setTime"));
772 }
773 else
774 {
775 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_EINVALL,
776 _("set timer"), (long) i);
777 SL_RETURN( (-1), _("sh_readconf_setTime"));
778 }
779}
780
781int sh_readconf_setMailtime (const char * c)
782{
783 return sh_readconf_setTime (c, SET_MAILTIME);
784}
785
786int sh_readconf_setFiletime (const char * c)
787{
788 return sh_readconf_setTime (c, SET_FILETIME);
789}
790
791int sh_readconf_set_nice (const char * c)
792{
793 long val;
794
795 SL_ENTER(_("sh_readconf_set_nice"));
796
797 val = strtol (c, (char **)NULL, 10);
798 if (val < -20 || val > 20)
799 {
800 SL_RETURN((-1), _("sh_readconf_set_nice"));
801 }
802
803 val = (val < -19 ? -19 : val);
804 val = (val > 19 ? 19 : val);
805
806 sh.flag.nice = val;
807 SL_RETURN((0), _("sh_readconf_set_nice"));
808}
809
810#ifdef FANCY_LIBCAP
811int sh_readconf_setCaps(const char * c)
812{
813 int i;
814 SL_ENTER(_("sh_readconf_setCaps"));
815
816 i = sh_util_flagval(c, &sl_useCaps);
817 SL_RETURN((i), _("sh_readconf_setCaps"));
818}
819#endif
820
821typedef struct _cfg_options {
822 const char * optname;
823 ShSectionType section;
824 ShSectionType alt_section;
825 int (*func)(const char * opt);
826} cfg_options;
827
828#if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
829extern int sh_set_schedule_one(const char * str);
830extern int sh_set_schedule_two(const char * str);
831#endif
832#if defined (SH_WITH_SERVER)
833extern int sh_socket_use (const char * c);
834extern int sh_socket_uid (const char * c);
835extern int sh_socket_password (const char * c);
836#endif
837
838cfg_options ext_table[] = {
839#if defined(WITH_EXTERNAL)
840 { N_("opencommand"), SH_SECTION_EXTERNAL, SH_SECTION_NONE,
841 sh_ext_setcommand },
842 { N_("closecommand"), SH_SECTION_EXTERNAL, SH_SECTION_NONE,
843 sh_ext_close_command },
844 { N_("setcommandline"), SH_SECTION_EXTERNAL, SH_SECTION_NONE,
845 sh_ext_add_argv },
846 { N_("setchecksum"), SH_SECTION_EXTERNAL, SH_SECTION_NONE,
847 sh_ext_checksum },
848 { N_("setdefault"), SH_SECTION_EXTERNAL, SH_SECTION_NONE,
849 sh_ext_add_default },
850 { N_("setenviron"), SH_SECTION_EXTERNAL, SH_SECTION_NONE,
851 sh_ext_add_environ },
852 { N_("setdeadtime"), SH_SECTION_EXTERNAL, SH_SECTION_NONE,
853 sh_ext_deadtime },
854 { N_("settype"), SH_SECTION_EXTERNAL, SH_SECTION_NONE,
855 sh_ext_type },
856 { N_("setcredentials"), SH_SECTION_EXTERNAL, SH_SECTION_NONE,
857 sh_ext_priv },
858 { N_("setfilternot"), SH_SECTION_EXTERNAL, SH_SECTION_NONE,
859 sh_ext_add_not },
860 { N_("setfilterand"), SH_SECTION_EXTERNAL, SH_SECTION_NONE,
861 sh_ext_add_and },
862 { N_("setfilteror"), SH_SECTION_EXTERNAL, SH_SECTION_NONE,
863 sh_ext_add_or },
864 { N_("externalseverity"),SH_SECTION_LOG, SH_SECTION_EXTERNAL,
865 sh_error_set_external },
866 { N_("externalclass"), SH_SECTION_LOG, SH_SECTION_EXTERNAL,
867 sh_error_external_mask },
868#endif
869
870#if defined(WITH_DATABASE)
871 { N_("usepersistent"), SH_SECTION_DATABASE, SH_SECTION_NONE,
872 sh_database_use_persistent },
873 { N_("setdbname"), SH_SECTION_DATABASE, SH_SECTION_NONE,
874 sh_database_set_database },
875 { N_("setdbtable"), SH_SECTION_DATABASE, SH_SECTION_NONE,
876 sh_database_set_table },
877 { N_("setdbhost"), SH_SECTION_DATABASE, SH_SECTION_NONE,
878 sh_database_set_host },
879 { N_("setdbuser"), SH_SECTION_DATABASE, SH_SECTION_NONE,
880 sh_database_set_user },
881 { N_("setdbpassword"), SH_SECTION_DATABASE, SH_SECTION_NONE,
882 sh_database_set_password },
883 { N_("addtodbhash"), SH_SECTION_DATABASE, SH_SECTION_NONE,
884 sh_database_add_to_hash },
885 { N_("databaseseverity"),SH_SECTION_LOG, SH_SECTION_DATABASE,
886 sh_error_set_database },
887 { N_("databaseclass"), SH_SECTION_LOG, SH_SECTION_DATABASE,
888 sh_error_database_mask },
889 { N_("setdbservertstamp"), SH_SECTION_DATABASE, SH_SECTION_NONE,
890 set_enter_wrapper },
891#endif
892
893
894#if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
895 { N_("dir"), SH_SECTION_ATTRIBUTES, SH_SECTION_NONE,
896 sh_files_pushdir_attr },
897 { N_("file"), SH_SECTION_ATTRIBUTES, SH_SECTION_NONE,
898 sh_files_pushfile_attr },
899 { N_("dir"), SH_SECTION_READONLY, SH_SECTION_NONE,
900 sh_files_pushdir_ro },
901 { N_("file"), SH_SECTION_READONLY, SH_SECTION_NONE,
902 sh_files_pushfile_ro },
903 { N_("dir"), SH_SECTION_LOGFILES, SH_SECTION_NONE,
904 sh_files_pushdir_log },
905 { N_("file"), SH_SECTION_LOGFILES, SH_SECTION_NONE,
906 sh_files_pushfile_log },
907 { N_("dir"), SH_SECTION_LOGGROW, SH_SECTION_NONE,
908 sh_files_pushdir_glog },
909 { N_("file"), SH_SECTION_LOGGROW, SH_SECTION_NONE,
910 sh_files_pushfile_glog },
911 { N_("dir"), SH_SECTION_NOIGNORE, SH_SECTION_NONE,
912 sh_files_pushdir_noig },
913 { N_("file"), SH_SECTION_NOIGNORE, SH_SECTION_NONE,
914 sh_files_pushfile_noig },
915 { N_("dir"), SH_SECTION_ALLIGNORE, SH_SECTION_NONE,
916 sh_files_pushdir_allig },
917 { N_("file"), SH_SECTION_ALLIGNORE, SH_SECTION_NONE,
918 sh_files_pushfile_allig },
919
920 { N_("dir"), SH_SECTION_USER0, SH_SECTION_NONE,
921 sh_files_pushdir_user0 },
922 { N_("file"), SH_SECTION_USER0, SH_SECTION_NONE,
923 sh_files_pushfile_user0 },
924 { N_("dir"), SH_SECTION_USER1, SH_SECTION_NONE,
925 sh_files_pushdir_user1 },
926 { N_("file"), SH_SECTION_USER1, SH_SECTION_NONE,
927 sh_files_pushfile_user1 },
928 { N_("dir"), SH_SECTION_USER2, SH_SECTION_NONE,
929 sh_files_pushdir_user2 },
930 { N_("file"), SH_SECTION_USER2, SH_SECTION_NONE,
931 sh_files_pushfile_user2 },
932 { N_("dir"), SH_SECTION_USER3, SH_SECTION_NONE,
933 sh_files_pushdir_user3 },
934 { N_("file"), SH_SECTION_USER3, SH_SECTION_NONE,
935 sh_files_pushfile_user3 },
936 { N_("dir"), SH_SECTION_USER4, SH_SECTION_NONE,
937 sh_files_pushdir_user4 },
938 { N_("file"), SH_SECTION_USER4, SH_SECTION_NONE,
939 sh_files_pushfile_user4 },
940 { N_("dir"), SH_SECTION_PRELINK, SH_SECTION_NONE,
941 sh_files_pushdir_prelink },
942 { N_("file"), SH_SECTION_PRELINK, SH_SECTION_NONE,
943 sh_files_pushfile_prelink },
944
945 { N_("ignoreadded"), SH_SECTION_MISC, SH_SECTION_NONE,
946 sh_ignore_add_new },
947 { N_("ignoremissing"), SH_SECTION_MISC, SH_SECTION_NONE,
948 sh_ignore_add_del },
949
950 { N_("skipchecksum"), SH_SECTION_MISC, SH_SECTION_NONE,
951 sh_restrict_define },
952 { N_("filetype"), SH_SECTION_MISC, SH_SECTION_NONE,
953 sh_restrict_add_ftype },
954
955
956 { N_("filecheckscheduleone"), SH_SECTION_MISC, SH_SECTION_NONE,
957 sh_set_schedule_one },
958 { N_("filecheckscheduletwo"), SH_SECTION_MISC, SH_SECTION_NONE,
959 sh_set_schedule_two },
960
961 { N_("usehardlinkcheck"), SH_SECTION_MISC, SH_SECTION_NONE,
962 sh_files_check_hardlinks },
963 { N_("usersrccheck"), SH_SECTION_MISC, SH_SECTION_NONE,
964 sh_files_use_rsrc },
965 { N_("hardlinkoffset"), SH_SECTION_MISC, SH_SECTION_NONE,
966 sh_files_hle_reg },
967#if defined(USE_XATTR)
968 { N_("useselinuxcheck"), SH_SECTION_MISC, SH_SECTION_NONE,
969 sh_unix_setcheckselinux },
970#endif
971#if defined(USE_ACL)
972 { N_("useaclcheck"), SH_SECTION_MISC, SH_SECTION_NONE,
973 sh_unix_setcheckacl },
974#endif
975 { N_("loosedircheck"), SH_SECTION_MISC, SH_SECTION_NONE,
976 sh_hash_loosedircheck },
977 { N_("addokchars"), SH_SECTION_MISC, SH_SECTION_NONE,
978 sh_util_obscure_ok },
979 { N_("filenamesareutf8"), SH_SECTION_MISC, SH_SECTION_NONE,
980 sh_util_obscure_utf8 },
981 { N_("setrecursionlevel"), SH_SECTION_MISC, SH_SECTION_NONE,
982 sh_files_setrecursion },
983 { N_("checksumtest"), SH_SECTION_MISC, SH_SECTION_NONE,
984 sh_util_setchecksum },
985 { N_("reportonlyonce"), SH_SECTION_MISC, SH_SECTION_NONE,
986 sh_files_reportonce },
987 { N_("reportfulldetail"), SH_SECTION_MISC, SH_SECTION_NONE,
988 sh_files_fulldetail },
989 { N_("uselocaltime"), SH_SECTION_MISC, SH_SECTION_NONE,
990 sh_unix_uselocaltime },
991
992 { N_("setnicelevel"), SH_SECTION_MISC, SH_SECTION_NONE,
993 sh_readconf_set_nice },
994
995#if defined(FANCY_LIBCAP)
996 { N_("usecaps"), SH_SECTION_MISC, SH_SECTION_NONE,
997 sh_readconf_setCaps },
998#endif
999
1000 { N_("setdropcache"), SH_SECTION_MISC, SH_SECTION_NONE,
1001 sl_set_drop_cache },
1002
1003 { N_("setiolimit"), SH_SECTION_MISC, SH_SECTION_NONE,
1004 sh_unix_set_io_limit },
1005
1006 { N_("versionstring"), SH_SECTION_MISC, SH_SECTION_NONE,
1007 sh_hash_version_string },
1008
1009 { N_("digestalgo"), SH_SECTION_MISC, SH_SECTION_NONE,
1010 sh_tiger_hashtype },
1011
1012 { N_("redefreadonly"), SH_SECTION_MISC, SH_SECTION_NONE,
1013 sh_files_redef_readonly },
1014
1015 { N_("redeflogfiles"), SH_SECTION_MISC, SH_SECTION_NONE,
1016 sh_files_redef_logfiles },
1017
1018 { N_("redefgrowinglogfiles"), SH_SECTION_MISC, SH_SECTION_NONE,
1019 sh_files_redef_loggrow },
1020
1021 { N_("redefattributes"), SH_SECTION_MISC, SH_SECTION_NONE,
1022 sh_files_redef_attributes },
1023
1024 { N_("redefignorenone"), SH_SECTION_MISC, SH_SECTION_NONE,
1025 sh_files_redef_noignore },
1026
1027 { N_("redefignoreall"), SH_SECTION_MISC, SH_SECTION_NONE,
1028 sh_files_redef_allignore },
1029
1030 { N_("redefuser0"), SH_SECTION_MISC, SH_SECTION_NONE,
1031 sh_files_redef_user0 },
1032
1033 { N_("redefuser1"), SH_SECTION_MISC, SH_SECTION_NONE,
1034 sh_files_redef_user1 },
1035
1036 { N_("redefuser2"), SH_SECTION_MISC, SH_SECTION_NONE,
1037 sh_files_redef_user2 },
1038
1039 { N_("redefuser3"), SH_SECTION_MISC, SH_SECTION_NONE,
1040 sh_files_redef_user3 },
1041
1042 { N_("redefuser4"), SH_SECTION_MISC, SH_SECTION_NONE,
1043 sh_files_redef_user4 },
1044
1045 { N_("redefprelink"), SH_SECTION_MISC, SH_SECTION_NONE,
1046 sh_files_redef_prelink },
1047
1048
1049 { N_("setprelinkpath"), SH_SECTION_MISC, SH_SECTION_NONE,
1050 sh_prelink_set_path },
1051 { N_("setprelinkchecksum"), SH_SECTION_MISC, SH_SECTION_NONE,
1052 sh_prelink_set_hash },
1053
1054 /* client or standalone
1055 */
1056#endif
1057
1058#ifdef SH_WITH_SERVER
1059#ifdef INET_SYSLOG
1060 { N_("setudpactive"), SH_SECTION_SRV, SH_SECTION_MISC,
1061 set_syslog_active },
1062#endif
1063 { N_("setusesocket"), SH_SECTION_SRV, SH_SECTION_MISC,
1064 sh_socket_use },
1065 { N_("setsocketallowuid"), SH_SECTION_SRV, SH_SECTION_MISC,
1066 sh_socket_uid },
1067 { N_("setsocketpassword"), SH_SECTION_SRV, SH_SECTION_MISC,
1068 sh_socket_password },
1069 { N_("setstripdomain"), SH_SECTION_SRV, SH_SECTION_MISC,
1070 sh_forward_set_strip },
1071 { N_("useseparatelogs"), SH_SECTION_SRV, SH_SECTION_MISC,
1072 set_flag_sep_log },
1073 { N_("setchrootdir"), SH_SECTION_SRV, SH_SECTION_MISC,
1074 sh_unix_set_chroot },
1075 { N_("setclienttimelimit"), SH_SECTION_SRV, SH_SECTION_MISC,
1076 sh_forward_set_time_limit },
1077 { N_("setconnectiontimeout"),SH_SECTION_SRV, SH_SECTION_MISC,
1078 sh_forward_set_timeout },
1079 { N_("useclientseverity"), SH_SECTION_SRV, SH_SECTION_MISC,
1080 sh_forward_use_clt_sev },
1081 { N_("useclientclass"), SH_SECTION_SRV, SH_SECTION_MISC,
1082 sh_forward_use_clt_class },
1083 { N_("severitylookup"), SH_SECTION_SRV, SH_SECTION_MISC,
1084 sh_forward_lookup_level },
1085 { N_("setclientfromaccept"), SH_SECTION_SRV, SH_SECTION_MISC,
1086 set_socket_peer },
1087 { N_("setserverport"), SH_SECTION_SRV, SH_SECTION_MISC,
1088 sh_forward_set_port },
1089 { N_("setserverinterface"), SH_SECTION_SRV, SH_SECTION_MISC,
1090 sh_forward_set_interface },
1091 { N_("client"), SH_SECTION_CLIENTS, SH_SECTION_NONE,
1092 sh_forward_register_client },
1093#endif
1094
1095#if defined(SH_WITH_CLIENT) || defined(SH_WITH_SERVER)
1096 { N_("exportseverity"), SH_SECTION_LOG, SH_SECTION_NONE,
1097 sh_error_setexport },
1098 { N_("exportclass"), SH_SECTION_LOG, SH_SECTION_NONE,
1099 sh_error_export_mask },
1100#if defined(SH_WITH_SERVER)
1101 { N_("setlogserver"), SH_SECTION_SRV, SH_SECTION_MISC,
1102 sh_forward_setlogserver },
1103#else
1104 { N_("setlogserver"), SH_SECTION_CLT, SH_SECTION_MISC,
1105 sh_forward_setlogserver },
1106 { N_("setthrottle"), SH_SECTION_CLT, SH_SECTION_MISC,
1107 sh_forward_set_throttle_delay},
1108#endif
1109#endif
1110 { N_("setfilechecktime"), SH_SECTION_MISC, SH_SECTION_NONE,
1111 sh_readconf_setFiletime },
1112 { N_("setlooptime"), SH_SECTION_MISC, SH_SECTION_NONE,
1113 sh_util_setlooptime },
1114
1115#ifdef SH_WITH_MAIL
1116 { N_("mailseverity"), SH_SECTION_LOG, SH_SECTION_NONE,
1117 sh_error_setseverity },
1118 { N_("mailclass"), SH_SECTION_LOG, SH_SECTION_NONE,
1119 sh_error_mail_mask },
1120 { N_("setmailtime"), SH_SECTION_MAIL, SH_SECTION_MISC,
1121 sh_readconf_setMailtime },
1122 { N_("setmailnum"), SH_SECTION_MAIL, SH_SECTION_MISC,
1123 sh_mail_setNum },
1124 { N_("setmailrelay"), SH_SECTION_MAIL, SH_SECTION_MISC,
1125 sh_mail_set_relay },
1126 { N_("setmailport"), SH_SECTION_MAIL, SH_SECTION_MISC,
1127 sh_mail_set_port },
1128 { N_("mailsingle"), SH_SECTION_MAIL, SH_SECTION_MISC,
1129 sh_mail_setFlag },
1130 { N_("mailsubject"), SH_SECTION_MAIL, SH_SECTION_MISC,
1131 set_mail_subject },
1132 { N_("setmailsender"), SH_SECTION_MAIL, SH_SECTION_MISC,
1133 sh_mail_set_sender },
1134 { N_("setmailalias"), SH_SECTION_MAIL, SH_SECTION_MISC,
1135 sh_nmail_add_alias },
1136 { N_("setmailaddress"), SH_SECTION_MAIL, SH_SECTION_MISC,
1137 sh_nmail_add_recipient },
1138 { N_("closeaddress"), SH_SECTION_MAIL, SH_SECTION_MISC,
1139 sh_nmail_close_recipient },
1140 { N_("setaddrseverity"), SH_SECTION_MAIL, SH_SECTION_MISC,
1141 sh_nmail_set_severity },
1142 { N_("setmailfilternot"), SH_SECTION_MAIL, SH_SECTION_MISC,
1143 sh_nmail_add_not },
1144 { N_("setmailfilterand"), SH_SECTION_MAIL, SH_SECTION_MISC,
1145 sh_nmail_add_and },
1146 { N_("setmailfilteror"), SH_SECTION_MAIL, SH_SECTION_MISC,
1147 sh_nmail_add_or },
1148#endif
1149 { N_("setbindaddress"), SH_SECTION_MISC, SH_SECTION_NONE,
1150 sh_calls_set_bind_addr },
1151 { N_("daemon"), SH_SECTION_MISC, SH_SECTION_NONE,
1152 sh_unix_setdeamon },
1153 { N_("samhainpath"), SH_SECTION_MISC, SH_SECTION_NONE,
1154 sh_unix_self_hash },
1155 { N_("trusteduser"), SH_SECTION_MISC, SH_SECTION_NONE,
1156 tf_add_trusted_user },
1157 { N_("settimeserver"), SH_SECTION_MISC, SH_SECTION_NONE,
1158 sh_unix_settimeserver },
1159
1160 { N_("printseverity"), SH_SECTION_LOG, SH_SECTION_NONE,
1161 sh_error_setprint },
1162 { N_("printclass"), SH_SECTION_LOG, SH_SECTION_NONE,
1163 sh_error_print_mask },
1164
1165 { N_("logseverity"), SH_SECTION_LOG, SH_SECTION_NONE,
1166 sh_error_setlog },
1167 { N_("logclass"), SH_SECTION_LOG, SH_SECTION_NONE,
1168 sh_error_log_mask },
1169
1170 { N_("syslogseverity"), SH_SECTION_LOG, SH_SECTION_NONE,
1171 sh_error_set_syslog },
1172 { N_("syslogclass"), SH_SECTION_LOG, SH_SECTION_NONE,
1173 sh_error_syslog_mask },
1174#ifdef HAVE_LIBPRELUDE
1175 { N_("preludeseverity"), SH_SECTION_LOG, SH_SECTION_NONE,
1176 sh_error_set_prelude },
1177 { N_("preludeclass"), SH_SECTION_LOG, SH_SECTION_NONE,
1178 sh_error_prelude_mask },
1179 { N_("preludeprofile"), SH_SECTION_MISC, SH_SECTION_NONE,
1180 sh_prelude_set_profile },
1181 { N_("preludemaptoinfo"), SH_SECTION_MISC, SH_SECTION_NONE,
1182 sh_prelude_map_info },
1183 { N_("preludemaptolow"), SH_SECTION_MISC, SH_SECTION_NONE,
1184 sh_prelude_map_low },
1185 { N_("preludemaptomedium"), SH_SECTION_MISC, SH_SECTION_NONE,
1186 sh_prelude_map_medium },
1187 { N_("preludemaptohigh"), SH_SECTION_MISC, SH_SECTION_NONE,
1188 sh_prelude_map_high },
1189#endif
1190
1191 { N_("logcalls"), SH_SECTION_LOG, SH_SECTION_NONE,
1192 sh_aud_set_functions },
1193
1194 { N_("messageheader"), SH_SECTION_MISC, SH_SECTION_NONE,
1195 sh_error_ehead },
1196
1197 { N_("setconsole"), SH_SECTION_MISC, SH_SECTION_NONE,
1198 sh_log_set_console },
1199
1200#ifdef WITH_MESSAGE_QUEUE
1201 { N_("messagequeueactive"),SH_SECTION_MISC, SH_SECTION_NONE,
1202 enable_msgq },
1203#endif
1204
1205 { N_("setreverselookup"), SH_SECTION_MISC, SH_SECTION_NONE,
1206 set_reverse_lookup },
1207
1208 { N_("setdatabasepath"), SH_SECTION_MISC, SH_SECTION_NONE,
1209 sh_readconf_set_database_path },
1210
1211 { N_("setlogfilepath"), SH_SECTION_MISC, SH_SECTION_NONE,
1212 sh_readconf_set_logfile_path },
1213
1214 { N_("setlockfilepath"), SH_SECTION_MISC, SH_SECTION_NONE,
1215 sh_readconf_set_lockfile_path },
1216
1217 { N_("hidesetup"), SH_SECTION_MISC, SH_SECTION_NONE,
1218 sh_util_hidesetup },
1219
1220 { N_("syslogfacility"), SH_SECTION_LOG, SH_SECTION_MISC,
1221 sh_log_set_facility },
1222
1223 { N_("syslogmapstampto"), SH_SECTION_LOG, SH_SECTION_MISC,
1224 sh_log_set_stamp_priority },
1225
1226 { N_("mactype"), SH_SECTION_MISC, SH_SECTION_NONE,
1227 sh_util_sigtype },
1228
1229 { N_("avoidblock"), SH_SECTION_MISC, SH_SECTION_NONE,
1230 sh_calls_set_sub },
1231
1232 { NULL, 0, 0, NULL}
1233};
1234
1235
1236
1237
1238static int sh_readconfig_line (char * line)
1239{
1240 char * key;
1241 const char * value;
1242 char * tmp;
1243 int i;
1244 int good_opt = -1;
1245
1246#if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
1247 int modnum, modkey;
1248#endif
1249
1250 static const char *dummy = N_("dummy");
1251
1252 static const char *closing[] = {
1253 N_("closecommand"),
1254 N_("closeaddress"),
1255 N_("logmonendgroup"),
1256 N_("logmonendhost"),
1257 NULL
1258 };
1259
1260 static const char *ident[] = {
1261 N_("severityreadonly"),
1262 N_("severitylogfiles"),
1263 N_("severitygrowinglogs"),
1264 N_("severityignorenone"),
1265 N_("severityignoreall"),
1266 N_("severityattributes"),
1267 N_("severitydirs"),
1268 N_("severityfiles"),
1269 N_("severitynames"),
1270 N_("severityuser0"),
1271 N_("severityuser1"),
1272 N_("severityuser2"),
1273 N_("severityuser3"),
1274 N_("severityuser4"),
1275 N_("severityprelink"),
1276 NULL
1277 };
1278
1279 static int identnum[] = {
1280 SH_ERR_T_RO,
1281 SH_ERR_T_LOGS,
1282 SH_ERR_T_GLOG,
1283 SH_ERR_T_NOIG,
1284 SH_ERR_T_ALLIG,
1285 SH_ERR_T_ATTR,
1286 SH_ERR_T_DIR,
1287 SH_ERR_T_FILE,
1288 SH_ERR_T_NAME,
1289 SH_ERR_T_USER0,
1290 SH_ERR_T_USER1,
1291 SH_ERR_T_USER2,
1292 SH_ERR_T_USER3,
1293 SH_ERR_T_USER4,
1294 SH_ERR_T_PRELINK,
1295 };
1296
1297 SL_ENTER(_("sh_readconf_line"));
1298
1299 /* convert to lowercase */
1300
1301 tmp = line;
1302 while (*tmp != '=' && *tmp != '\0')
1303 {
1304 *tmp = tolower( (int) *tmp);
1305 ++tmp;
1306 }
1307
1308 key = line;
1309
1310 /* interpret line */
1311
1312 value = strchr(line, '=');
1313
1314 if (value == NULL || (*value) == '\0')
1315 {
1316 if (key != NULL)
1317 {
1318 i = 0;
1319 while (closing[i] != NULL)
1320 {
1321 if (sl_strncmp(key,_(closing[i]),sl_strlen(closing[i])-1) == 0)
1322 {
1323 value = dummy;
1324 goto ok_novalue;
1325 }
1326 ++i;
1327 }
1328
1329 TPT(( 0, FIL__, __LINE__, _("msg=<ConfigFile: not key=value: %s>\n"),
1330 line));
1331 }
1332 SL_RETURN(good_opt, _("sh_readconf_line"));
1333 }
1334 else
1335 ++value;
1336
1337 /* skip leading whitespace
1338 */
1339 while ((*value) == ' ' || (*value) == '\t')
1340 ++value;
1341
1342 if ((*value) == '\0') /* no value */
1343 {
1344 if (key != NULL)
1345 {
1346 TPT(( 0, FIL__, __LINE__, _("msg=<ConfigFile: not key=value: %s>\n"),
1347 line));
1348 }
1349 SL_RETURN(good_opt, _("sh_readconf_line"));
1350 }
1351
1352 ok_novalue:
1353
1354 if (!sl_is_suid())
1355 {
1356 TPT(( 0, FIL__, __LINE__, _("msg=<ConfigFile: %s>\n"), line));
1357 }
1358
1359 /* Expand shell expressions. This return allocated memory which we must free.
1360 */
1361 value = sh_readconf_expand_value(value);
1362
1363 if (!value || (*value) == '\0')
1364 {
1365 TPT(( 0, FIL__, __LINE__, _("msg=<ConfigFile: empty after shell expansion: %s>\n"),
1366 line));
1367 SL_RETURN(good_opt, _("sh_readconf_line"));
1368 }
1369
1370#if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
1371 if (read_mode == SH_SECTION_OTHER)
1372 {
1373 for (modnum = 0; modList[modnum].name != NULL; ++modnum)
1374 {
1375 for (modkey = 0; modList[modnum].conf_table[modkey].the_opt != NULL;
1376 ++modkey)
1377 {
1378 if (sl_strncmp (key,
1379 _(modList[modnum].conf_table[modkey].the_opt),
1380 sl_strlen(modList[modnum].conf_table[modkey].the_opt) ) == 0)
1381 {
1382 good_opt = 0;
1383 if (0 != modList[modnum].conf_table[modkey].func(value))
1384 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_EINVALS,
1385 _(modList[modnum].conf_table[modkey].the_opt), value);
1386 if (!sl_is_suid())
1387 {
1388 TPT(( 0, FIL__, __LINE__,
1389 _("msg=<line = %s, option = %s>\n"), line,
1390 _(modList[modnum].conf_table[modkey].the_opt)));
1391 }
1392 goto outburst;
1393 }
1394 }
1395 }
1396 }
1397 outburst:
1398#endif
1399
1400
1401 if (read_mode == SH_SECTION_THRESHOLD)
1402 {
1403 i = 0;
1404 while (ident[i] != NULL) {
1405 if (sl_strncmp (key, _(ident[i]), sl_strlen(ident[i])) == 0)
1406 {
1407 good_opt = 0;
1408 sh_error_set_iv (identnum[i], value);
1409 break;
1410 }
1411 ++i;
1412 }
1413 }
1414 else
1415 {
1416 i = 0;
1417 while (ext_table[i].optname != NULL)
1418 {
1419 if ((ext_table[i].section == read_mode ||
1420 ext_table[i].alt_section == read_mode) &&
1421 sl_strncmp (key, _(ext_table[i].optname),
1422 sl_strlen(ext_table[i].optname)) == 0)
1423 {
1424 good_opt = 0;
1425 if (0 != ext_table[i].func (value))
1426 sh_error_handle ((-1), FIL__, __LINE__, 0, MSG_EINVALS,
1427 _(ext_table[i].optname), value);
1428 break;
1429 }
1430 ++i;
1431 }
1432 }
1433
1434 SH_FREE((char*)value);
1435
1436 SL_RETURN(good_opt, _("sh_readconf_line"));
1437}
1438
1439
Note: See TracBrowser for help on using the repository browser.