source: branches/samhain_3_1/src/sh_readconf.c@ 522

Last change on this file since 522 was 432, checked in by katerina, 12 years ago

Fix for ticket #337 (negated conditionals in config file don't work).

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