--- plugins/check_procs.c.orig Tue Jun 11 09:08:00 2002 +++ plugins/check_procs.c Tue Jun 11 13:22:15 2002 @@ -68,6 +68,14 @@ char *format = NULL; char tmp[MAX_INPUT_BUFFER]; +#ifdef HAVE_REGEX_H +#include +regex_t argsre, progre; +int cflags = 0; +char errbuf[MAX_INPUT_BUFFER]; +int excode; +#endif + int main (int argc, char **argv) { @@ -91,6 +99,21 @@ if (process_arguments (argc, argv) == ERROR) usage ("Unable to parse command line\n"); +#if HAVE_REGEX_H + if ((options & ARGS) && cflags) { + if ((excode = regcomp (&argsre, args, cflags)) != 0) { + printf ("Could Not Compile Regular Expression\n"); + return STATE_UNKNOWN; + } + } + if ((options & PROG) && cflags) { + if ((excode = regcomp (&progre, prog, cflags)) != 0) { + printf ("Could Not Compile Regular Expression\n"); + return STATE_UNKNOWN; + } + } +#endif + /* run the command */ if (verbose) printf ("%s\n", PS_COMMAND); @@ -121,10 +144,37 @@ strip (procargs); if ((options & STAT) && (strstr (statopts, procstat))) resultsum |= STAT; - if ((options & ARGS) && (strstr (procargs, args) == procargs)) + if ((options & ARGS) && !cflags && (strstr (procargs, args) == procargs)) resultsum |= ARGS; - if ((options & PROG) && (strcmp (prog, procprog) == 0)) + if ((options & PROG) && !cflags && (strcmp (prog, procprog) == 0)) resultsum |= PROG; +#if HAVE_REGEX_H + /* XXX Add error tests */ + // if ((options & ARGS) && cflags && ((excode = regexec (&argsre, procargs, (size_t) 0, NULL, 0)) == 0)) + if ((options & ARGS) && cflags) { + excode = regexec (&argsre, procargs, (size_t) 0, NULL, 0); + if (excode == 0) { + resultsum |= ARGS; + } + else if (excode != REG_NOMATCH) { + regerror (excode, &argsre, errbuf, MAX_INPUT_BUFFER); + printf ("Execute Error: %s\n", errbuf); + exit (STATE_CRITICAL); + } + } + // if ((options & PROG) && cflags && ((excode = regexec (&progre, procprog, (size_t) 0, NULL, 0)) == 0)) + if ((options & PROG) && cflags) { + excode = regexec (&progre, procprog, (size_t) 0, NULL, 0); + if (excode == 0) { + resultsum |= PROG; + } + else if (excode != REG_NOMATCH) { + regerror (excode, &argsre, errbuf, MAX_INPUT_BUFFER); + printf ("Execute Error: %s\n", errbuf); + exit (STATE_CRITICAL); + } + } +#endif if ((options & PPID) && (procppid == ppid)) resultsum |= PPID; if ((options & USER) && (procuid == uid)) @@ -263,6 +313,9 @@ {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, {"verbose", no_argument, 0, 'v'}, + {"regex", no_argument, 0, 'r'}, + {"ereg", no_argument, 0, 'r'}, + {"eregi", no_argument, 0, 'R'}, {0, 0, 0, 0} }; #endif @@ -270,10 +323,10 @@ while (1) { #ifdef HAVE_GETOPT_H c = - getopt_long (argc, argv, "+Vvht:c:w:p:s:u:C:a:", long_options, + getopt_long (argc, argv, "+VvhRrt:c:w:p:s:u:C:a:", long_options, &option_index); #else - c = getopt (argc, argv, "+Vvht:c:w:p:s:u:C:a:"); + c = getopt (argc, argv, "+VvhRrt:c:w:p:s:u:C:a:"); #endif if (c == EOF) @@ -419,6 +472,22 @@ case 'v': /* command */ verbose = TRUE; break; + case 'R': /* regex */ +#ifdef HAVE_REGEX_H + cflags = REG_ICASE | REG_EXTENDED | REG_NOSUB | REG_NEWLINE; +#else + printf ("PROCS UNKNOWN: call for regex which was not a compiled option"); + exit (STATE_UNKNOWN); +#endif + break; + case 'r': /* regex */ +#ifdef HAVE_REGEX_H + cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE; +#else + printf ("PROCS UNKNOWN: call for regex which was not a compiled option"); + exit (STATE_UNKNOWN); +#endif + break; } } return i; @@ -492,7 +561,11 @@ " -a, --argument-array=STRING\n" " Only scan for ARGS that match up to the length of the given STRING\n" " -C, --command=COMMAND\n" - " Only scan for exact matches to the named COMMAND.\n\n" + " Only scan for exact matches to the named COMMAND.\n" + " -r, --ereg\n" + " Treat the -a or -C argument as an extended regular expression\n" + " -R, --eregi\n" + " Treat the -a or -C argument as a case-insensitive extended regular expression\n\n" "RANGEs are specified 'min:max' or 'min:' or ':max' (or 'max'). If\n" "specified 'max:min', a warning status will be generated if the\n"