source: trunk/src/sh_readconf.c@ 263

Last change on this file since 263 was 254, checked in by katerina, 15 years ago

Fix for ticket #171 (..namedfork/rsrc deprecated on Mac OS X).

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