Thread: [Sysfence-commit] sysfence/parseopt Makefile,1.10,1.11 confread.c,1.6,1.7 lex.c,1.11,1.12 lex.h,1.6,
Status: Alpha
Brought to you by:
emes
|
From: Michal S. <em...@us...> - 2004-06-05 12:49:49
|
Update of /cvsroot/sysfence/sysfence/parseopt In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17425/parseopt Modified Files: Makefile confread.c lex.c lex.h parse.c parse.h Log Message: * bugfixes. nproc seems to be working Index: lex.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/parseopt/lex.h,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- lex.h 10 May 2004 13:53:17 -0000 1.6 +++ lex.h 5 Jun 2004 12:49:41 -0000 1.7 @@ -63,8 +63,6 @@ */ tokdata next_token (); -#ifdef DEBUG char * tok2string (token t); -#endif /* $Id$ */ Index: parse.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/parseopt/parse.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- parse.h 6 Feb 2004 22:55:59 -0000 1.4 +++ parse.h 5 Jun 2004 12:49:41 -0000 1.5 @@ -25,11 +25,7 @@ * Functions */ -#ifdef DEBUG void * parse_error (tokdata *tok, const char *func, const char *desc); -#else -void * parse_error (tokdata *tok); -#endif parserdata * get_logdata (tokdata *tok); parserdata * get_rundata (tokdata *tok); parserdata * expression_decompose (parserdata *left); Index: parse.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/parseopt/parse.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- parse.c 4 Jun 2004 13:07:04 -0000 1.18 +++ parse.c 5 Jun 2004 12:49:41 -0000 1.19 @@ -24,22 +24,14 @@ #include "../conditions.h" #include "parse.h" #include "../sys/users.h" -#ifdef DEBUG #include <syslog.h> -#include "../sys/log.h" -#endif #define ERRMSGBUF 128 -#ifdef DEBUG void * parse_error (tokdata *tok, const char *func, const char *desc) -#else -void * parse_error (tokdata *tok) -#endif { char *buf = (char *) xalloc (NULL, ERRMSGBUF); -#ifdef DEBUG snprintf ( buf, ERRMSGBUF - 1, @@ -49,14 +41,6 @@ func, desc ); -#else - snprintf ( - buf, - ERRMSGBUF - 1, - "at line %d", - tok->line - ); -#endif bail_out (EXIT_PARSE, buf); } @@ -82,17 +66,14 @@ * logdata := log [once] * */ - parserdata *res; - sf_logdata *log; /* helper */ - + sf_logdata *log; + parserdata *res = (parserdata *) xalloc (NULL, sizeof (parserdata)); + if (tok->type != KW_LOG) return NULL; - tok ++; - - /* that's log data. initialize structures */ - res = (parserdata *) xalloc (NULL, sizeof (parserdata)); - res->parsed = xalloc (NULL, sizeof (sf_logdata)); - log = (sf_logdata *) res->parsed; + + log = (sf_logdata *) xalloc (NULL, sizeof (sf_logdata)); + res->parsed = (void *) log; if (tok->type == KW_ONCE) { log->once = 1; tok ++; @@ -109,9 +90,8 @@ * rundata := run [once] "command" * */ -#ifdef DEBUG const char *thisfuncname = "get_rundata()"; -#endif + parserdata *res; sf_rundata *run; /* helper */ @@ -129,11 +109,7 @@ } else run->once = 0; if (tok->type != VA_STR) -#ifdef DEBUG parse_error (tok, thisfuncname, "run arg not string"); -#else - parse_error (tok); -#endif run->command = tok->val; tok ++; @@ -148,9 +124,8 @@ * stepdata := step <integer> * */ -#ifdef DEBUG const char *thisfuncname = "get_step()"; -#endif + parserdata *res = (parserdata *) xalloc (NULL, sizeof (parserdata)); res->parsed = xalloc (NULL, sizeof (unsigned int)); @@ -165,11 +140,7 @@ tok ++; if (tok->type != VA_INT) -#ifdef DEBUG parse_error (tok, thisfuncname, "step val not int"); -#else - parse_error (tok); -#endif res->parsed = tok->val; tok ++; @@ -184,9 +155,8 @@ parserdata * expression_decompose (parserdata *left) { -#ifdef DEBUG const char *thisfuncname = "expression_decompose()"; -#endif + sf_expression *resexp; parserdata *right, *res; tokdata *tok = left->ptr; @@ -207,11 +177,7 @@ */ right = get_expression (tok); if (right == NULL) -#ifdef DEBUG - parse_error (tok, thisfuncname, "no right arg"); -#else - parse_error (tok); -#endif + parse_error (tok, thisfuncname, "no right arg"); /* second argument is ok */ resexp->arg2 = right->parsed; res->ptr = right->ptr; @@ -228,9 +194,7 @@ * expression := <atomic> [<op> <expression>] * | <block_expression> [<op> <expression>] */ -#ifdef DEBUG const char *thisfuncname = "get_expression()"; -#endif parserdata *left; @@ -242,20 +206,14 @@ if (left != NULL) /* this is an atomic rule */ return expression_decompose (left); -#ifdef DEBUG parse_error (tok, thisfuncname, "neither block nor atomic"); -#else - parse_error (tok); -#endif } sf_list * get_uid_list_rec (tokdata **tok) { sf_list *res; uid_t *tmpuid; -#ifdef DEBUG char *thisfuncname = "get_uid_list_rec()"; -#endif switch ((*tok)->type) { case VA_INT: @@ -265,11 +223,7 @@ case VA_STR: tmpuid = username2uid ((char *) (*tok)->val); if (!tmpuid) { -#ifdef DEBUG parse_error (*tok, thisfuncname, "invalid username"); -#else - parse_error (*tok); -#endif } break; default: @@ -293,7 +247,7 @@ parserdata * get_uid_list (tokdata *tok) { - parserdata *res; + parserdata *res = (parserdata *) xalloc (NULL, sizeof (parserdata)); sf_list *list = get_uid_list_rec (&tok); res->ptr = tok - 1; @@ -301,9 +255,10 @@ return res; } -char get_states_rec (tokdata **tok) +char get_states_rec (tokdata **tok, int first) { char thisstate = 0; + char *thisfuncname = "get_states_rec()"; switch ((*tok)->type) { case PR_RUN: @@ -322,7 +277,11 @@ thisstate = PROC_ZOMBIE; break; default: - return 0; + /* we have already read some state descriptor(s) + * and separator. so we must have another state + * description here */ + if (!first) parse_error (*tok, thisfuncname, "expecting stste descriptor"); + else return 0; } *tok = *tok + 1; @@ -332,7 +291,7 @@ * go, fetch next state */ *tok = *tok + 1; - thisstate |= get_states_rec (tok); + thisstate |= get_states_rec (tok, 0); } return thisstate; @@ -343,7 +302,7 @@ parserdata *res = (parserdata *) xalloc (NULL, sizeof (parserdata)); char *states = (char *) xalloc (NULL, sizeof (char)); - *states = get_states_rec (&tok); + *states = get_states_rec (&tok, 1); if (*states == 0) *states = PROC_ANY; res->ptr = tok; @@ -353,9 +312,7 @@ parserdata * get_atomic (tokdata *tok) { -#ifdef DEBUG const char *thisfuncname = "get_atomic()"; -#endif sf_atomic *at = (sf_atomic *) xalloc (NULL, sizeof (sf_atomic)); tokdata *var = tok, *arg1 = NULL, @@ -370,7 +327,6 @@ switch (var->type) { - // temporary hack ? case ID_LA1: case ID_LA5: case ID_LA15: @@ -496,11 +452,7 @@ case ID_FSAVAIL: case ID_FSUSED: if (arg1->type != VA_STR) { -#ifdef DEBUG parse_error (tok, thisfuncname, "no path given"); -#else - parse_error (tok); -#endif } /* register fs in database */ add_fs_entry_to_list (&tmp_fs_db, (char *) arg1->val); @@ -519,11 +471,7 @@ case CO_GT: break; default: -#ifdef DEBUG - parse_error (tok, thisfuncname, "invalid op"); -#else - parse_error (tok); -#endif + parse_error (tok, thisfuncname, "invalid operator"); } /* check value type */ @@ -542,11 +490,7 @@ if (((at->thresh.type == INTEGER) && (val->type != VA_SIZ)) || ((at->thresh.type == DOUBLE) && (val->type != VA_DBL))) -#ifdef DEBUG parse_error (val, thisfuncname, "type mismatch"); -#else - parse_error (val); -#endif /* copy threshold value */ at->thresh.ptr = val->val; @@ -581,9 +525,7 @@ * */ -#ifdef DEBUG const char *thisfuncname = "get_block_expression()"; -#endif parserdata *expr; @@ -595,11 +537,7 @@ expr = get_expression (tok); if (expr == NULL) return NULL; if (expr->ptr->type != BL_END) -#ifdef DEBUG parse_error (tok, thisfuncname, "block not closed"); -#else - parse_error (tok); -#endif expr->ptr ++; return expr; @@ -613,9 +551,7 @@ * | 'if' [<string>] <block_expression> <logdata> [<rundata>] */ -#ifdef DEBUG const char *thisfuncname = "get_ruleset()"; -#endif int i; /* our result data */ @@ -640,33 +576,23 @@ /* ruleset begins with IF */ if (tok->type != KW_IF) -#ifdef DEBUG parse_error (tok, thisfuncname, "no if keyword"); -#else - parse_error (tok); -#endif else tok ++; /* then we have rule name */ if (tok->type == VA_STR) { rlst->name = tok->val; } else { -#ifdef DEBUG parse_error (tok, thisfuncname, "no rule name"); -#else - parse_error (tok); -#endif } tok ++; + syslog (LOG_DEBUG, "bbparsed=%x", res->parsed); /* next should be expression in block */ tmp = get_block_expression (tok); if (tmp == NULL) -#ifdef DEBUG parse_error (tok, thisfuncname, "no expr block"); -#else - parse_error (tok); -#endif + syslog (LOG_DEBUG, "pbparsed=%x", res->parsed); /* save expression and skip to next token */ rlst->expr = (sf_expression *) tmp->parsed; @@ -676,11 +602,7 @@ log = get_logdata (tok); /* no log or run data? */ if ((run == NULL) && (log == NULL)) -#ifdef DEBUG - parse_error (tok, thisfuncname, "no action"); -#else - parse_error (tok); -#endif + parse_error (tok, thisfuncname, "no action defined"); /* this is full ruleset now but we try to get next action data */ if (run != NULL) { Index: confread.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/parseopt/confread.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- confread.c 26 May 2004 17:54:53 -0000 1.6 +++ confread.c 5 Jun 2004 12:49:41 -0000 1.7 @@ -26,6 +26,7 @@ #include <stdlib.h> #include <errno.h> #include <fcntl.h> +#include <syslog.h> #define RULESETS 64 @@ -40,7 +41,7 @@ flen = lseek (fha, 0, SEEK_END); lseek (fha, 0, SEEK_SET); #ifdef DEBUG - printf ("%s: %d bytes to read\n", fname, flen); + syslog (LOG_DEBUG, "%s: %d bytes to read\n", fname, flen); #endif buf = (char *) xalloc (NULL, flen + 1); @@ -102,7 +103,7 @@ while (1) { /* get rulesets */ rule = get_ruleset (tok); - if (rule == NULL) break; + if (!rule) break; tok = rule->ptr; *(set + setpos) = (sf_rule *) rule->parsed; setpos ++; Index: lex.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/parseopt/lex.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- lex.c 31 May 2004 14:10:06 -0000 1.11 +++ lex.c 5 Jun 2004 12:49:41 -0000 1.12 @@ -66,7 +66,6 @@ unsigned int linenum = 1; -#ifdef DEBUG char * tok2string (token t) { switch (t) { @@ -109,7 +108,6 @@ case END: return "END"; } } -#endif /* * Error reporting function. Index: Makefile =================================================================== RCS file: /cvsroot/sysfence/sysfence/parseopt/Makefile,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Makefile 5 Jun 2004 10:40:14 -0000 1.10 +++ Makefile 5 Jun 2004 12:49:40 -0000 1.11 @@ -9,6 +9,11 @@ gcc -c -ggdb confread.c -o confread.o debug: + gcc -c -DDEBUG lex.c -o lex.o + gcc -c -DDEBUG parse.c -o parse.o + gcc -c -DDEBUG confread.c -o confread.o + +debugdb: gcc -c -ggdb -DDEBUG lex.c -o lex.o gcc -c -ggdb -DDEBUG parse.c -o parse.o gcc -c -ggdb -DDEBUG confread.c -o confread.o |