[Nagiosplug-checkins] nagiosplug/plugins check_tcp.c,1.77,1.78 utils.c,1.44,1.45 utils.h,1.27,1.28
Ton Voon
tonvoon at users.sourceforge.net
Wed Mar 29 08:34:11 CEST 2006
Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16894/plugins
Modified Files:
check_tcp.c utils.c utils.h
Log Message:
New function to for escaped strings from command line for send/quit.
Adapted from Sebastian Wiesinger's patch (1292404)
Index: check_tcp.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_tcp.c,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -d -r1.77 -r1.78
--- check_tcp.c 24 Mar 2006 16:12:05 -0000 1.77
+++ check_tcp.c 29 Mar 2006 16:33:36 -0000 1.78
@@ -54,8 +54,6 @@
static char *server_address = NULL;
static char *server_send = NULL;
static char *server_quit = NULL;
-char *lineend = "";
-char *lineendquit = "\r\n";
static char **server_expect;
static size_t server_expect_count = 0;
static size_t maxbytes = 0;
@@ -246,6 +244,12 @@
}
if(flags & FLAG_VERBOSE) {
+ if (server_send) {
+ printf("Send string: %s\n", server_send);
+ }
+ if (server_quit) {
+ printf("Quit string: %s\n", server_quit);
+ }
printf("server_expect_count: %d\n", (int)server_expect_count);
for(i = 0; i < server_expect_count; i++)
printf("\t%d: %s\n", i, server_expect[i]);
@@ -364,6 +368,7 @@
process_arguments (int argc, char **argv)
{
int c;
+ int escape = 0;
int option = 0;
static struct option longopts[] = {
@@ -375,7 +380,7 @@
{"timeout", required_argument, 0, 't'},
{"protocol", required_argument, 0, 'P'},
{"port", required_argument, 0, 'p'},
- {"lineend", required_argument, 0, 'l'},
+ {"escape", required_argument, 0, 'E'},
{"send", required_argument, 0, 's'},
{"expect", required_argument, 0, 'e'},
{"maxbytes", required_argument, 0, 'm'},
@@ -417,7 +422,7 @@
}
while (1) {
- c = getopt_long (argc, argv, "+hVv46H:l:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:",
+ c = getopt_long (argc, argv, "+hVv46EH:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:",
longopts, &option);
if (c == -1 || c == EOF || c == 1)
@@ -485,30 +490,14 @@
else
server_port = atoi (optarg);
break;
- case 'l':
- switch (*optarg) {
- case 'n':
- lineend = strdup("\n");
- lineendquit = lineend;
- break;
- case 'r':
- lineend = strdup("\r");
- lineendquit = lineend;
- break;
- case 'b':
- lineend = strdup("\r\n");
- lineendquit = lineend;
- break;
- case 'e':
- lineend = strdup("");
- lineendquit = lineend;
- break;
- default:
- usage4 (_("Unrecognized option to -l, must be r, n, b or e"));
- }
+ case 'E':
+ escape = 1;
break;
case 's':
- asprintf(&server_send, "%s%s", optarg, lineend);
+ if (escape)
+ server_send = np_escaped_string(optarg);
+ else
+ asprintf(&server_send, "%s", optarg);
break;
case 'e': /* expect string (may be repeated) */
EXPECT = NULL;
@@ -525,7 +514,10 @@
else
maxbytes = strtol (optarg, NULL, 0);
case 'q':
- asprintf(&server_quit, "%s%s", optarg, lineendquit);
+ if (escape)
+ server_quit = np_escaped_string(optarg);
+ else
+ asprintf(&server_quit, "%s\r\n", optarg);
break;
case 'r':
if (!strncmp(optarg,"ok",2))
@@ -604,10 +596,9 @@
printf (_(UT_IPv46));
printf (_("\
- -l, --lineend=b|e|n|r\n\
- Ending on -s and -q strings. b - both: <cr><lf> style, e - empty no\n\
- end, n - newline: newline end, r - return: carriage return end\n\
- Default is \"-l e -s <send> -l b -q <quit>\".\n\
+ -E, --escape\n\
+ Can use \\n, \\r, \\t or \\ in send or quit string.\n\
+ Default: nothing added to send, \\r\\n added to end of quit\n\
-s, --send=STRING\n\
String to send to the server\n\
-e, --expect=STRING\n\
@@ -653,6 +644,6 @@
[-s <send string>] [-e <expect string>] [-q <quit string>]\n\
[-m <maximum bytes>] [-d <delay>] [-t <timeout seconds>]\n\
[-r <refuse state>] [-M <mismatch state>] [-v] [-4|-6] [-j]\n\
- [-D <days to cert expiry>] [-S <use SSL>] [-l <n|r|b|e>]\n", progname);
+ [-D <days to cert expiry>] [-S <use SSL>] [-E]\n", progname);
}
Index: utils.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/utils.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- utils.c 30 Jan 2006 22:24:31 -0000 1.44
+++ utils.c 29 Mar 2006 16:33:36 -0000 1.45
@@ -727,3 +727,33 @@
return data;
}
+
+char *np_escaped_string (const char *string) {
+ char *data;
+ int i, j=0;
+ data = strdup(string);
+ for (i=0; data[i]; i++) {
+ if (data[i] == '\\') {
+ switch(data[++i]) {
+ case 'n':
+ data[j++] = '\n';
+ break;
+ case 'r':
+ data[j++] = '\r';
+ break;
+ case 't':
+ data[j++] = '\t';
+ break;
+ case '\\':
+ data[j++] = '\\';
+ break;
+ default:
+ data[j++] = data[i];
+ }
+ } else {
+ data[j++] = data[i];
+ }
+ }
+ data[j] = '\0';
+ return data;
+}
Index: utils.h
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/utils.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- utils.h 31 Jan 2006 14:52:48 -0000 1.27
+++ utils.h 29 Mar 2006 16:33:36 -0000 1.28
@@ -132,6 +132,8 @@
int,
double);
+char *np_escaped_string (const char *);
+
/* The idea here is that, although not every plugin will use all of these,
most will or should. Therefore, for consistency, these very common
options should have only these meanings throughout the overall suite */
More information about the Commits
mailing list