1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
--- plugins/check_procs.c.orig Tue Jun 11 09:08:00 2002
+++ plugins/check_procs.c Tue Jun 11 13:47:52 2002
@@ -68,6 +68,14 @@
char *format = NULL;
char tmp[MAX_INPUT_BUFFER];
+#ifdef HAVE_REGEX_H
+#include <regex.h>
+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,34 @@
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
+ 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);
+ 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 +310,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 +320,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 +469,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 +558,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"
|