source: trunk/src/sh_readconf.c@ 211

Last change on this file since 211 was 211, checked in by katerina, 16 years ago

Allow shell expansion for cofiguration file values (ticket #137).

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