[Nagios-devel] check_tcp bug

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[Nagios-devel] check_tcp bug

Post by Guest »

This is a multi-part message in MIME format.
--------------080308050005070709070608
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

I've noticed two small problems with the check_tcp plugin (nagiosplug
1.3b2) that prevent it from doing its proper default expect string
checking (i.e - if you are running check_smtp, by default you expect a
"220" return, etc).

First, the expect value for check_pop (and check_spop) is incorrect.
The expect is set to "110", which is just the port for POP. This never
actually gets returned when to do a tcp connect to POP. What you need
to get back to know that POP is working is "+OK".

Secondly, there is a bug in that, unless the user gives uses the -e
argument, none of the default expects will every be checked. Here is a
piece of the check_tcp code:

/* use default expect if none listed in process_arguments() */
if (EXPECT && server_expect_count == 0) {
! server_expect = malloc (1);
server_expect[server_expect_count - 1] = EXPECT;
}

Well, unless you are doing a check_nntp or the user gave a -e ,
the value of server_expect_count going into this is 0. So
server_expect[-1] is being stored and server_expect_count doesn't get
set to 1 anywhere. So later, when the code decides if it needs to check
against any expect strings, it sees that server_expect_count = 0, and
doesn't do any comparisons.

The way around this is:

/* use default expect if none listed in process_arguments() */
if (EXPECT && server_expect_count == 0) {
! server_expect = malloc (++server_expect_count);
server_expect[server_expect_count - 1] = EXPECT;
}

Now, server_expect_count is increased to 1 and the value is stored in
server_expect[0]. This will actually make check_tcp check the default
expect values. If you compare, this looks just like the section of code
where you set a user-defined expect string.

I have included a context diff that can be used as a patch. If you have
any questions, just email me back. Thanks.

-Russell Scibetti

--
Russell Scibetti
Quadrix Solutions, Inc.
http://www.quadrix.com
(732) 235-2335, ext. 7038


--------------080308050005070709070608
Content-Type: text/plain;
name="checktcp-diff.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="checktcp-diff.patch"

*** check_tcp.c Mon Nov 25 07:00:17 2002
--- new_check_tcp.c Wed Dec 18 17:53:56 2002
***************
*** 142,148 ****
asprintf (&PROGNAME, "check_pop");
asprintf (&SERVICE, "POP");
SEND = NULL;
! asprintf (&EXPECT, "110");
asprintf (&QUIT, "QUIT\r\n");
PROTOCOL = TCP_PROTOCOL;
PORT = 110;
--- 142,148 ----
asprintf (&PROGNAME, "check_pop");
asprintf (&SERVICE, "POP");
SEND = NULL;
! asprintf (&EXPECT, "+OK");
asprintf (&QUIT, "QUIT\r\n");
PROTOCOL = TCP_PROTOCOL;
PORT = 110;
***************
*** 171,177 ****
asprintf (&PROGNAME, "check_spop");
asprintf (&SERVICE, "SPOP");
SEND=NULL;
! asprintf (&EXPECT, "110");
asprintf (&QUIT, "QUIT\r\n");
PROTOCOL=TCP_PROTOCOL;
use_ssl=TRUE;
--- 171,177 ----
asprintf (&PROGNAME, "check_spop");
asprintf (&SERVICE, "SPOP");
SEND=NULL;
! asprintf (&EXPECT, "+OK");
asprintf (&QUIT, "QUIT\r\n");
PROTOCOL=TCP_PROTOCOL;
use_ssl=TRUE;
***************
*** 205,211 ****

/* use default expect if none listed in process_arguments() */
if (EXPECT && server_expect_count == 0) {
! server_expect = malloc (1);
server_expect[server_expect_count - 1] = EXPECT;
}

--- 205,211 ----

/* use default expect if none listed in process_arguments() */
if (EXPECT && server_expect_count == 0) {
! server_expect = malloc (++server_expect_count);
server_expect[server_expect_count - 1] = EXPECT;
}


--------------080308050005070709070608--






This post was automatically imported from historical nagios-devel mailing list archives
Original poster: russell@quadrix.com
Locked