source: trunk/src/sh_readconf.c@ 390

Last change on this file since 390 was 383, checked in by katerina, 13 years ago

Fix for ticket #281 (warnings from clang static analyzer).

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