source: trunk/src/sh_readconf.c@ 580

Last change on this file since 580 was 580, checked in by katerina, 12 months ago

Fix for ticket #468 (file attributes). Also add option to switch off check.

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