Imported Upstream version 2.4.3
[platform/upstream/audit.git] / audisp / plugins / prelude / prelude-config.c
1 /* prelude-config.c -- 
2  * Copyright 2008,2010-2011 Red Hat Inc., Durham, North Carolina.
3  * All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  * Authors:
20  *   Steve Grubb <sgrubb@redhat.com>
21  * 
22  */
23
24 #include "config.h"
25 #include <string.h>
26 #include <stdio.h>
27 #include <fcntl.h>
28 #include <sys/stat.h>
29 #include <errno.h>
30 #include <unistd.h>
31 #include <stdlib.h>
32 #include <syslog.h>
33 #include <ctype.h>
34 #include <pwd.h>
35 #include "prelude-config.h"
36
37 /* Local prototypes */
38 struct nv_pair
39 {
40         const char *name;
41         const char *value;
42         const char *option;
43 };
44
45 struct kw_pair 
46 {
47         const char *name;
48         int (*parser)(struct nv_pair *, int, prelude_conf_t *);
49         int max_options;
50 };
51
52 struct nv_list
53
54         const char *name;
55         int option;
56 };
57
58 static char *get_line(FILE *f, char *buf);
59 static int nv_split(char *buf, struct nv_pair *nv);
60 static const struct kw_pair *kw_lookup(const char *val);
61 static int profile_parser(struct nv_pair *nv, int line, 
62                 prelude_conf_t *config);
63 static int avc_parser(struct nv_pair *nv, int line, 
64                 prelude_conf_t *config);
65 static int avc_act_parser(struct nv_pair *nv, int line, 
66                 prelude_conf_t *config);
67 static int login_parser(struct nv_pair *nv, int line, 
68                 prelude_conf_t *config);
69 static int login_act_parser(struct nv_pair *nv, int line, 
70                 prelude_conf_t *config);
71 static int login_failure_parser(struct nv_pair *nv, int line, 
72                 prelude_conf_t *config);
73 static int login_failure_act_parser(struct nv_pair *nv, int line, 
74                 prelude_conf_t *config);
75 static int login_session_parser(struct nv_pair *nv, int line, 
76                 prelude_conf_t *config);
77 static int login_session_act_parser(struct nv_pair *nv, int line, 
78                 prelude_conf_t *config);
79 static int login_location_parser(struct nv_pair *nv, int line, 
80                 prelude_conf_t *config);
81 static int login_location_act_parser(struct nv_pair *nv, int line, 
82                 prelude_conf_t *config);
83 static int login_time_parser(struct nv_pair *nv, int line, 
84                 prelude_conf_t *config);
85 static int login_time_act_parser(struct nv_pair *nv, int line, 
86                 prelude_conf_t *config);
87 static int abends_parser(struct nv_pair *nv, int line, 
88                 prelude_conf_t *config);
89 static int abends_act_parser(struct nv_pair *nv, int line, 
90                 prelude_conf_t *config);
91 static int promiscuous_parser(struct nv_pair *nv, int line, 
92                 prelude_conf_t *config);
93 static int promiscuous_act_parser(struct nv_pair *nv, int line, 
94                 prelude_conf_t *config);
95 static int mac_status_parser(struct nv_pair *nv, int line, 
96                 prelude_conf_t *config);
97 static int mac_status_act_parser(struct nv_pair *nv, int line, 
98                 prelude_conf_t *config);
99 static int group_auth_parser(struct nv_pair *nv, int line, 
100                 prelude_conf_t *config);
101 static int group_auth_act_parser(struct nv_pair *nv, int line, 
102                 prelude_conf_t *config);
103 static int watched_acct_parser(struct nv_pair *nv, int line, 
104                 prelude_conf_t *config);
105 static int watched_acct_act_parser(struct nv_pair *nv, int line, 
106                 prelude_conf_t *config);
107 static int watched_accounts_parser(struct nv_pair *nv, int line, 
108                 prelude_conf_t *config);
109 static int watched_syscall_parser(struct nv_pair *nv, int line, 
110                 prelude_conf_t *config);
111 static int watched_syscall_act_parser(struct nv_pair *nv, int line, 
112                 prelude_conf_t *config);
113 static int watched_file_parser(struct nv_pair *nv, int line, 
114                 prelude_conf_t *config);
115 static int watched_file_act_parser(struct nv_pair *nv, int line, 
116                 prelude_conf_t *config);
117 static int watched_exec_parser(struct nv_pair *nv, int line, 
118                 prelude_conf_t *config);
119 static int watched_exec_act_parser(struct nv_pair *nv, int line, 
120                 prelude_conf_t *config);
121 static int watched_mk_exe_parser(struct nv_pair *nv, int line, 
122                 prelude_conf_t *config);
123 static int watched_mk_exe_act_parser(struct nv_pair *nv, int line, 
124                 prelude_conf_t *config);
125 static int tty_parser(struct nv_pair *nv, int line, 
126                 prelude_conf_t *config);
127 static int tty_act_parser(struct nv_pair *nv, int line, 
128                 prelude_conf_t *config);
129 static int sanity_check(prelude_conf_t *config, const char *file);
130
131 static const struct kw_pair keywords[] = 
132 {
133   {"profile",                    profile_parser,                0 },
134   {"detect_avc",                 avc_parser,                    0 },
135   {"avc_action",                 avc_act_parser,                0 },
136   {"detect_logins",              login_parser,                  0 },
137   {"login_action",               login_act_parser,              0 },
138   {"detect_login_fail_max",      login_failure_parser,          0 },
139   {"login_fail_max_action",      login_failure_act_parser,      0 },
140   {"detect_login_session_max",   login_session_parser,          0 },
141   {"login_session_max_action",   login_session_act_parser,      0 },
142   {"detect_login_location",      login_location_parser,         0 },
143   {"login_location_action",      login_location_act_parser,     0 },
144   {"detect_login_time",          login_time_parser,             0 },
145   {"login_time_action",          login_time_act_parser,         0 },
146   {"detect_abend",               abends_parser,                 0 },
147   {"abend_action",               abends_act_parser,             0 },
148   {"detect_promiscuous",         promiscuous_parser,            0 },
149   {"promiscuous_action",         promiscuous_act_parser,        0 },
150   {"detect_mac_status",          mac_status_parser,             0 },
151   {"mac_status_action",          mac_status_act_parser,         0 },
152   {"detect_group_auth",          group_auth_parser,             0 },
153   {"group_auth_action",          group_auth_act_parser,         0 },
154   {"detect_watched_acct",        watched_acct_parser,           0 },
155   {"watched_acct_action",        watched_acct_act_parser,       0 },
156   {"watched_accounts",           watched_accounts_parser,       1 },
157   {"detect_watched_syscall",     watched_syscall_parser,        0 },
158   {"watched_syscall_action",     watched_syscall_act_parser,    0 },
159   {"detect_watched_file",        watched_file_parser,           0 },
160   {"watched_file_action",        watched_file_act_parser,       0 },
161   {"detect_watched_exec",        watched_exec_parser,           0 },
162   {"watched_exec_action",        watched_exec_act_parser,       0 },
163   {"detect_watched_mk_exe",      watched_mk_exe_parser,         0 },
164   {"watched_mk_exe_action",      watched_mk_exe_act_parser,     0 },
165   {"detect_tty",                 tty_parser,            0 },
166   {"tty_action",                 tty_act_parser,        0 },
167   { NULL,             NULL }
168 };
169
170 static const struct nv_list enabler_words[] =
171 {
172   {"no",   E_NO },
173   {"yes",  E_YES },
174   { NULL,  0 }
175 };
176
177 static const struct nv_list action_words[] =
178 {
179   {"ignore",   A_IGNORE },
180   {"idmef",    A_IDMEF },
181 //  {"kill",     A_KILL },
182 //  {"session",  A_SESSION },
183 //  {"single",   A_SINGLE },
184 //  {"halt",     A_HALT },
185   { NULL,      0 }
186 };
187
188 /*
189  * Set everything to its default value
190 */
191 void clear_config(prelude_conf_t *config)
192 {
193         config->profile = strdup("auditd");
194         config->avcs = E_YES;
195         config->avcs_act = A_IDMEF;
196         config->logins = E_YES;
197         config->logins_act = A_IDMEF;
198         config->login_failure_max = E_YES;
199         config->login_failure_max_act = A_IDMEF;
200         config->login_session_max = E_YES;
201         config->login_session_max_act = A_IDMEF;
202         config->login_location = E_YES;
203         config->login_location_act = A_IDMEF;
204         config->login_time = E_YES;
205         config->login_time_act = A_IDMEF;
206         config->abends = E_YES;
207         config->abends_act = A_IDMEF;
208         config->promiscuous = E_YES;
209         config->promiscuous_act = A_IDMEF;
210         config->mac_status = E_YES;
211         config->mac_status_act = A_IDMEF;
212         config->group_auth = E_YES;
213         config->group_auth_act = A_IDMEF;
214         config->watched_acct = E_YES;
215         config->watched_acct_act = A_IDMEF;
216         config->watched_syscall = E_YES;
217         config->watched_syscall_act = A_IDMEF;
218         config->watched_file = E_YES;
219         config->watched_file_act = A_IDMEF;
220         config->watched_exec = E_YES;
221         config->watched_exec_act = A_IDMEF;
222         config->watched_mk_exe = E_YES;
223         config->watched_mk_exe_act = A_IDMEF;
224         config->tty = E_NO;
225         config->tty_act = A_IDMEF;
226         ilist_create(&config->watched_accounts);
227 }
228
229 int load_config(prelude_conf_t *config, const char *file)
230 {
231         int fd, rc, mode, lineno = 1;
232         struct stat st;
233         FILE *f;
234         char buf[128];
235
236         clear_config(config);
237
238         /* open the file */
239         mode = O_RDONLY;
240         rc = open(file, mode);
241         if (rc < 0) {
242                 free_config(config);
243                 if (errno != ENOENT) {
244                         syslog(LOG_ERR, "Error opening %s (%s)", file,
245                                 strerror(errno));
246                         return 1;
247                 }
248                 syslog(LOG_WARNING,
249                         "Config file %s doesn't exist, skipping", file);
250                 return 0;
251         }
252         fd = rc;
253
254         /* check the file's permissions: owned by root, not world writable,
255          * not symlink.
256          */
257         if (fstat(fd, &st) < 0) {
258                 free_config(config);
259                 syslog(LOG_ERR, "Error fstat'ing config file (%s)", 
260                         strerror(errno));
261                 close(fd);
262                 return 1;
263         }
264         if (st.st_uid != 0) {
265                 free_config(config);
266                 syslog(LOG_ERR, "Error - %s isn't owned by root", 
267                         file);
268                 close(fd);
269                 return 1;
270         }
271         if ((st.st_mode & S_IWOTH) == S_IWOTH) {
272                 free_config(config);
273                 syslog(LOG_ERR, "Error - %s is world writable", 
274                         file);
275                 close(fd);
276                 return 1;
277         }
278         if (!S_ISREG(st.st_mode)) {
279                 free_config(config);
280                 syslog(LOG_ERR, "Error - %s is not a regular file", 
281                         file);
282                 close(fd);
283                 return 1;
284         }
285
286         /* it's ok, read line by line */
287         f = fdopen(fd, "rm");
288         if (f == NULL) {
289                 free_config(config);
290                 syslog(LOG_ERR, "Error - fdopen failed (%s)", 
291                         strerror(errno));
292                 close(fd);
293                 return 1;
294         }
295
296         while (get_line(f, buf)) {
297                 // convert line into name-value pair
298                 const struct kw_pair *kw;
299                 struct nv_pair nv;
300                 rc = nv_split(buf, &nv);
301                 switch (rc) {
302                         case 0: // fine
303                                 break;
304                         case 1: // not the right number of tokens.
305                                 syslog(LOG_ERR, 
306                                 "Wrong number of arguments for line %d in %s", 
307                                         lineno, file);
308                                 break;
309                         case 2: // no '=' sign
310                                 syslog(LOG_ERR, 
311                                         "Missing equal sign for line %d in %s", 
312                                         lineno, file);
313                                 break;
314                         default: // something else went wrong... 
315                                 syslog(LOG_ERR, 
316                                         "Unknown error for line %d in %s", 
317                                         lineno, file);
318                                 break;
319                 }
320                 if (nv.name == NULL) {
321                         lineno++;
322                         continue;
323                 }
324                 if (nv.value == NULL) {
325                         free_config(config);
326                         fclose(f);
327                         return 1;
328                 }
329
330                 /* identify keyword or error */
331                 kw = kw_lookup(nv.name);
332                 if (kw->name == NULL) {
333                         free_config(config);
334                         syslog(LOG_ERR, 
335                                 "Unknown keyword \"%s\" in line %d of %s", 
336                                 nv.name, lineno, file);
337                         fclose(f);
338                         return 1;
339                 }
340
341                 /* Check number of options */
342                 if (kw->max_options == 0 && nv.option != NULL) {
343                         free_config(config);
344                         syslog(LOG_ERR, 
345                                 "Keyword \"%s\" has invalid option "
346                                 "\"%s\" in line %d of %s", 
347                                 nv.name, nv.option, lineno, file);
348                         fclose(f);
349                         return 1;
350                 }
351
352                 /* dispatch to keyword's local parser */
353                 rc = kw->parser(&nv, lineno, config);
354                 if (rc != 0) {
355                         free_config(config);
356                         fclose(f);
357                         return 1; // local parser puts message out
358                 }
359
360                 lineno++;
361         }
362
363         fclose(f);
364         if (lineno > 1)
365                 return sanity_check(config, file);
366         return 0;
367 }
368
369 static char *get_line(FILE *f, char *buf)
370 {
371         if (fgets_unlocked(buf, 128, f)) {
372                 /* remove newline */
373                 char *ptr = strchr(buf, 0x0a);
374                 if (ptr)
375                         *ptr = 0;
376                 return buf;
377         }
378         return NULL;
379 }
380
381 static int nv_split(char *buf, struct nv_pair *nv)
382 {
383         /* Get the name part */
384         char *ptr, *saved = NULL;
385
386         nv->name = NULL;
387         nv->value = NULL;
388         nv->option = NULL;
389         ptr = strtok_r(buf, " ", &saved);
390         if (ptr == NULL)
391                 return 0; /* If there's nothing, go to next line */
392         if (ptr[0] == '#')
393                 return 0; /* If there's a comment, go to next line */
394         nv->name = ptr;
395
396         /* Check for a '=' */
397         ptr = strtok_r(NULL, " ", &saved);
398         if (ptr == NULL)
399                 return 1;
400         if (strcmp(ptr, "=") != 0)
401                 return 2;
402
403         /* get the value */
404         ptr = strtok_r(NULL, " ", &saved);
405         if (ptr == NULL)
406                 return 1;
407         nv->value = ptr;
408
409         /* Everything is OK */
410         return 0;
411 }
412
413 static const struct kw_pair *kw_lookup(const char *val)
414 {
415         int i = 0;
416         while (keywords[i].name != NULL) {
417                 if (strcasecmp(keywords[i].name, val) == 0)
418                         break;
419                 i++;
420         }
421         return &keywords[i];
422 }
423  
424 static int profile_parser(struct nv_pair *nv, int line, 
425                 prelude_conf_t *config)
426 {
427         if (nv->value) {
428                 free((char*)config->profile);
429                 config->profile = strdup(nv->value);
430         }
431         return 0;
432 }
433
434 static int lookup_enabler(const char *value, enable_t *enabled)
435 {
436         int i;
437         for (i=0; enabler_words[i].name != NULL; i++) {
438                 if (strcasecmp(value, enabler_words[i].name) == 0) {
439                         *enabled = enabler_words[i].option;
440                         return 0;
441                 }
442         }
443         return 1;
444 }
445
446 static int lookup_action(const char *value, action_t *action)
447 {
448         int i;
449         for (i=0; action_words[i].name != NULL; i++) {
450                 if (strcasecmp(value, action_words[i].name) == 0) {
451                         *action = action_words[i].option;
452                         return 0;
453                 }
454         }
455         return 1;
456 }
457
458 static int avc_parser(struct nv_pair *nv, int line, prelude_conf_t *config)
459 {
460         if (lookup_enabler(nv->value, &config->avcs) == 0)
461                 return 0;
462         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
463         return 1;
464 }
465
466 static int avc_act_parser(struct nv_pair *nv, int line, prelude_conf_t *config)
467 {
468         if (lookup_action(nv->value, &config->avcs_act) == 0)
469                 return 0;
470         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
471         return 1;
472 }
473
474 static int login_parser(struct nv_pair *nv, int line, prelude_conf_t *config)
475 {
476         if (lookup_enabler(nv->value, &config->logins) == 0)
477                 return 0;
478         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
479         return 1;
480 }
481
482 static int login_act_parser(struct nv_pair *nv, int line,
483         prelude_conf_t *config)
484 {
485         if (lookup_action(nv->value, &config->logins_act) == 0)
486                 return 0;
487         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
488         return 1;
489 }
490
491 static int login_failure_parser(struct nv_pair *nv, int line,
492         prelude_conf_t *config)
493 {
494         if (lookup_enabler(nv->value, &config->login_failure_max) == 0)
495                 return 0;
496         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
497         return 1;
498 }
499
500 static int login_failure_act_parser(struct nv_pair *nv, int line,
501         prelude_conf_t *config)
502 {
503         if (lookup_action(nv->value, &config->login_failure_max_act) == 0)
504                 return 0;
505         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
506         return 1;
507 }
508
509 static int login_session_parser(struct nv_pair *nv, int line,
510         prelude_conf_t *config)
511 {
512         if (lookup_enabler(nv->value, &config->login_session_max) == 0)
513                 return 0;
514         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
515         return 1;
516 }
517
518 static int login_session_act_parser(struct nv_pair *nv, int line,
519         prelude_conf_t *config)
520 {
521         if (lookup_action(nv->value, &config->login_session_max_act) == 0)
522                 return 0;
523         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
524         return 1;
525 }
526
527 static int login_location_parser(struct nv_pair *nv, int line,
528         prelude_conf_t *config)
529 {
530         if (lookup_enabler(nv->value, &config->login_location) == 0)
531                 return 0;
532         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
533         return 1;
534 }
535
536 static int login_location_act_parser(struct nv_pair *nv, int line,
537         prelude_conf_t *config)
538 {
539         if (lookup_action(nv->value, &config->login_location_act) == 0)
540                 return 0;
541         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
542         return 1;
543 }
544
545 static int login_time_parser(struct nv_pair *nv, int line,
546         prelude_conf_t *config)
547 {
548         if (lookup_enabler(nv->value, &config->login_time) == 0)
549                 return 0;
550         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
551         return 1;
552 }
553
554 static int login_time_act_parser(struct nv_pair *nv, int line,
555         prelude_conf_t *config)
556 {
557         if (lookup_action(nv->value, &config->login_time_act) == 0)
558                 return 0;
559         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
560         return 1;
561 }
562
563 static int abends_parser(struct nv_pair *nv, int line, prelude_conf_t *config)
564 {
565         if (lookup_enabler(nv->value, &config->abends) == 0)
566                 return 0;
567         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
568         return 1;
569 }
570
571 static int abends_act_parser(struct nv_pair *nv, int line,
572         prelude_conf_t *config)
573 {
574         if (lookup_action(nv->value, &config->abends_act) == 0)
575                 return 0;
576         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
577         return 1;
578 }
579
580 static int promiscuous_parser(struct nv_pair *nv, int line,
581         prelude_conf_t *config)
582 {
583         if (lookup_enabler(nv->value, &config->promiscuous) == 0)
584                 return 0;
585         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
586         return 1;
587 }
588
589 static int promiscuous_act_parser(struct nv_pair *nv, int line,
590         prelude_conf_t *config)
591 {
592         if (lookup_action(nv->value, &config->promiscuous_act) == 0)
593                 return 0;
594         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
595         return 1;
596 }
597
598 static int mac_status_parser(struct nv_pair *nv, int line,
599         prelude_conf_t *config)
600 {
601         if (lookup_enabler(nv->value, &config->mac_status) == 0)
602                 return 0;
603         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
604         return 1;
605 }
606
607 static int mac_status_act_parser(struct nv_pair *nv, int line,
608         prelude_conf_t *config)
609 {
610         if (lookup_action(nv->value, &config->mac_status_act) == 0)
611                 return 0;
612         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
613         return 1;
614 }
615
616 static int group_auth_parser(struct nv_pair *nv, int line,
617         prelude_conf_t *config)
618 {
619         if (lookup_enabler(nv->value, &config->group_auth) == 0)
620                 return 0;
621         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
622         return 1;
623 }
624
625 static int group_auth_act_parser(struct nv_pair *nv, int line,
626         prelude_conf_t *config)
627 {
628         if (lookup_action(nv->value, &config->group_auth_act) == 0)
629                 return 0;
630         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
631         return 1;
632 }
633
634 static int watched_acct_parser(struct nv_pair *nv, int line,
635         prelude_conf_t *config)
636 {
637         if (lookup_enabler(nv->value, &config->watched_acct) == 0)
638                 return 0;
639         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
640         return 1;
641 }
642
643 static int watched_acct_act_parser(struct nv_pair *nv, int line,
644         prelude_conf_t *config)
645 {
646         if (lookup_action(nv->value, &config->watched_acct_act) == 0)
647                 return 0;
648         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
649         return 1;
650 }
651
652 static int string_is_numeric(const char *s)
653 {
654         if (*s == 0)
655                 return 0;
656         do {
657                 if (!isdigit(*s))
658                         return 0;
659                 s++;
660         } while (*s);
661         return 1;
662 }
663
664 static int watched_accounts_parser(struct nv_pair *nv, int line,
665         prelude_conf_t *config)
666 {
667         char *str = (char *)nv->value;
668         do {
669                 char *ptr = strchr(str, '-');
670                 if (ptr) {
671                         char *user1, *user2;
672                         int start, end, i;
673
674                         user1 = str;
675                         *ptr = 0;
676                         user2 = ptr+1;
677                         if (string_is_numeric(user1)) {
678                                 start = strtoul(user1, NULL, 10);
679                         } else {
680                                 struct passwd *pw;
681                                 pw = getpwnam(user1);
682                                 if (pw == NULL) {
683                                         syslog(LOG_ERR,
684                                 "user %s is invalid - line %d, skipping",
685                                                 user1, line);
686                                         continue;
687                                 }
688                                 start = pw->pw_uid;
689                         }
690                         i = strlen(user2);
691                         if (i>0 && user2[i-1] == ',')
692                                 user2[i-1] = 0;
693                         if (string_is_numeric(user2)) {
694                                 end = strtoul(user2, NULL, 10);
695                         } else {
696                                 struct passwd *pw;
697                                 pw = getpwnam(user2);
698                                 if (pw == NULL) {
699                                         syslog(LOG_ERR,
700                                 "user %s is invalid - line %d, skipping",
701                                                 user2, line);
702                                         continue;
703                                 }
704                                 end = pw->pw_uid;
705                         }
706                         if (start >= end) {
707                                 syslog(LOG_ERR,
708                         "%s is larger or equal to %s, please fix, skipping",
709                                         user1, user2);
710                                 continue;
711                         }
712                         for (i=start; i<=end; i++) {
713                                 ilist_add_if_uniq(
714                                                 &config->watched_accounts, i);
715                         }
716                 } else {
717                         int acct;
718                         if (string_is_numeric(str))
719                                 acct = strtoul(str, NULL, 10);
720                         else {
721                                 struct passwd *pw;
722                                 pw = getpwnam(str);
723                                 if (pw == NULL) {
724                                         syslog(LOG_ERR,
725                                 "user %s is invalid - line %d, skipping",
726                                                 str, line);
727                                         continue;
728                                 }
729                                 acct = pw->pw_uid;
730                         }
731                         ilist_add_if_uniq(&config->watched_accounts, acct);
732                 }
733                 str = strtok(NULL, ", ");
734         } while(str);
735
736         return 0;
737 }
738
739 static int watched_syscall_parser(struct nv_pair *nv, int line,
740         prelude_conf_t *config)
741 {
742         if (lookup_enabler(nv->value, &config->watched_syscall) == 0)
743                 return 0;
744         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
745         return 1;
746 }
747
748 static int watched_syscall_act_parser(struct nv_pair *nv, int line,
749         prelude_conf_t *config)
750 {
751         if (lookup_action(nv->value, &config->watched_syscall_act) == 0)
752                 return 0;
753         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
754         return 1;
755 }
756
757 static int watched_file_parser(struct nv_pair *nv, int line,
758         prelude_conf_t *config)
759 {
760         if (lookup_enabler(nv->value, &config->watched_file) == 0)
761                 return 0;
762         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
763         return 1;
764 }
765
766 static int watched_file_act_parser(struct nv_pair *nv, int line,
767         prelude_conf_t *config)
768 {
769         if (lookup_action(nv->value, &config->watched_file_act) == 0)
770                 return 0;
771         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
772         return 1;
773 }
774
775 static int watched_exec_parser(struct nv_pair *nv, int line,
776         prelude_conf_t *config)
777 {
778         if (lookup_enabler(nv->value, &config->watched_exec) == 0)
779                 return 0;
780         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
781         return 1;
782 }
783
784 static int watched_exec_act_parser(struct nv_pair *nv, int line,
785         prelude_conf_t *config)
786 {
787         if (lookup_action(nv->value, &config->watched_exec_act) == 0)
788                 return 0;
789         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
790         return 1;
791 }
792
793 static int watched_mk_exe_parser(struct nv_pair *nv, int line,
794         prelude_conf_t *config)
795 {
796         if (lookup_enabler(nv->value, &config->watched_mk_exe) == 0)
797                 return 0;
798         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
799         return 1;
800 }
801
802 static int watched_mk_exe_act_parser(struct nv_pair *nv, int line,
803         prelude_conf_t *config)
804 {
805         if (lookup_action(nv->value, &config->watched_mk_exe_act) == 0)
806                 return 0;
807         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
808         return 1;
809 }
810
811 static int tty_parser(struct nv_pair *nv, int line,
812         prelude_conf_t *config)
813 {
814         if (lookup_enabler(nv->value, &config->tty) == 0)
815                 return 0;
816         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
817         return 1;
818 }
819
820 static int tty_act_parser(struct nv_pair *nv, int line,
821         prelude_conf_t *config)
822 {
823         if (lookup_action(nv->value, &config->tty_act) == 0)
824                 return 0;
825         syslog(LOG_ERR, "Option %s not found - line %d", nv->value, line);
826         return 1;
827 }
828 /*
829  * This function is where we do the integrated check of the audispd config
830  * options. At this point, all fields have been read. Returns 0 if no
831  * problems and 1 if problems detected.
832  */
833 static int sanity_check(prelude_conf_t *config, const char *file)
834 {
835         /* Error checking */
836         return 0;
837 }
838
839 void free_config(prelude_conf_t *config)
840 {
841         free((void *)config->profile);
842         ilist_clear(&config->watched_accounts);
843 }
844