Code

Fixed buffer overflow in check_ntp/check_ntp_peer (#1999319, Ubuntu #291265)
[nagiosplug.git] / plugins / check_nwstat.c
index f93dee383376847ca70b406332aa59329764c4b1..b4fd3c733cf50ddf6c6304321ac20f0e930e02df 100644 (file)
@@ -1,26 +1,40 @@
-/******************************************************************************
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- $Id$
-******************************************************************************/
+/*****************************************************************************
+* 
+* Nagios check_nwstat plugin
+* 
+* License: GPL
+* Copyright (c) 2000-2007 Nagios Plugins Development Team
+* 
+* Last Modified: $Date$
+* 
+* Description:
+* 
+* This file contains the check_nwstat plugin
+* 
+* This plugin attempts to contact the MRTGEXT NLM running on a
+* Novell server to gather the requested system information.
+* 
+* 
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+* 
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+* 
+* You should have received a copy of the GNU General Public License
+* along with this program.  If not, see <http://www.gnu.org/licenses/>.
+* 
+* $Id$
+* 
+*****************************************************************************/
 
 const char *progname = "check_nwstat";
 const char *revision = "$Revision$";
-const char *copyright = "2000-2006";
+const char *copyright = "2000-2007";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
 #include "common.h"
@@ -156,6 +170,9 @@ main(int argc, char **argv) {
        bindtextdomain (PACKAGE, LOCALEDIR);
        textdomain (PACKAGE);
 
+       /* Parse extra opts if any */
+       argv=np_extra_opts(&argc, argv, progname);
+
        if (process_arguments(argc,argv) == ERROR)
                usage4 (_("Could not parse arguments"));
 
@@ -504,14 +521,14 @@ main(int argc, char **argv) {
                        result=STATE_OK;
                else
                        result=STATE_WARNING;
+
                close(sd);
                my_tcp_connect (server_address, server_port, &sd);
 
                send_buffer = strdup ("S13\r\n");
                result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
                temp_buffer=strtok(recv_buffer,"\r\n");
+
                asprintf (&output_message,_("Directory Services Database is %s (DS version %s)"),(result==STATE_OK)?"open":"closed",temp_buffer);
 
                /* check to see if logins are enabled */
@@ -579,7 +596,7 @@ main(int argc, char **argv) {
                        return result;
 
                max_packet_receive_buffers=atoi(recv_buffer);
+
                percent_used_packet_receive_buffers=(unsigned long)(((double)used_packet_receive_buffers/(double)max_packet_receive_buffers)*100.0);
 
                if (vars_to_check==UPRB) {
@@ -593,7 +610,7 @@ main(int argc, char **argv) {
                        else if (check_warning_value==TRUE && percent_used_packet_receive_buffers >= warning_value)
                                result=STATE_WARNING;
                }
+
                asprintf (&output_message,_("%lu of %lu (%lu%%) packet receive buffers used"),used_packet_receive_buffers,max_packet_receive_buffers,percent_used_packet_receive_buffers);
 
                /* check SAP table entries */
@@ -609,9 +626,9 @@ main(int argc, char **argv) {
                result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
                if (result!=STATE_OK)
                        return result;
+
                sap_entries=atoi(recv_buffer);
+
                if (check_critical_value==TRUE && sap_entries >= critical_value)
                        result=STATE_CRITICAL;
                else if (check_warning_value==TRUE && sap_entries >= warning_value)
@@ -797,9 +814,9 @@ main(int argc, char **argv) {
                result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
                if (result!=STATE_OK)
                        return result;
+
                open_files=atoi(recv_buffer);
+
                if (check_critical_value==TRUE && open_files >= critical_value)
                        result=STATE_CRITICAL;
                else if (check_warning_value==TRUE && open_files >= warning_value)
@@ -822,9 +839,9 @@ main(int argc, char **argv) {
                result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
                if (result!=STATE_OK)
                        return result;
+
                abended_threads=atoi(recv_buffer);
+
                if (check_critical_value==TRUE && abended_threads >= critical_value)
                        result=STATE_CRITICAL;
                else if (check_warning_value==TRUE && abended_threads >= warning_value)
@@ -846,9 +863,9 @@ main(int argc, char **argv) {
                result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
                if (result!=STATE_OK)
                        return result;
+
                max_service_processes=atoi(recv_buffer);
+
                close(sd);
                my_tcp_connect (server_address, server_port, &sd);
 
@@ -856,9 +873,9 @@ main(int argc, char **argv) {
                result=send_tcp_request(sd,send_buffer,recv_buffer,sizeof(recv_buffer));
                if (result!=STATE_OK)
                        return result;
+
                current_service_processes=atoi(recv_buffer);
+
                if (check_critical_value==TRUE && current_service_processes >= critical_value)
                        result=STATE_CRITICAL;
                else if (check_warning_value==TRUE && current_service_processes >= warning_value)
@@ -1338,7 +1355,7 @@ int process_arguments(int argc, char **argv) {
                switch (c)
                        {
                        case '?': /* print short usage statement if args not parsable */
-                       usage2 (_("Unknown argument"), optarg);
+                       usage5 ();
                        case 'h': /* help */
                                print_help();
                                exit(STATE_OK);
@@ -1593,85 +1610,77 @@ void print_help(void)
        print_usage();
 
        printf (_(UT_HELP_VRSN));
+       printf (_(UT_EXTRA_OPTS));
 
        printf (_(UT_HOST_PORT), 'p', myport);
 
-       printf (_("\
- -v, --variable=STRING\n\
-    Variable to check.  Valid variables include:\n\
-      LOAD1     = 1 minute average CPU load\n\
-      LOAD5     = 5 minute average CPU load\n\
-      LOAD15    = 15 minute average CPU load\n\
-      CSPROCS   = number of current service processes (NW 5.x only)\n\
-      ABENDS    = number of abended threads (NW 5.x only)\n\
-      UPTIME    = server uptime\n"));
-
-       printf (_("\
-      LTCH      = percent long term cache hits\n\
-      CBUFF     = current number of cache buffers\n\
-      CDBUFF    = current number of dirty cache buffers\n\
-      DCB       = dirty cache buffers as a percentage of the total\n\
-      TCB       = dirty cache buffers as a percentage of the original\n"));
-
-       printf (_("\
-      OFILES    = number of open files\n\
-      VMF<vol>  = MB of free space on Volume <vol>\n\
-      VMU<vol>  = MB used space on Volume <vol>\n\
-      VMP<vol>  = MB of purgeable space on Volume <vol>\n\
-      VPF<vol>  = percent free space on volume <vol>\n\
-      VKF<vol>  = KB of free space on volume <vol>\n\
-      VPP<vol>  = percent purgeable space on volume <vol>\n\
-      VKP<vol>  = KB of purgeable space on volume <vol>\n\
-      VPNP<vol> = percent not yet purgeable space on volume <vol>\n\
-      VKNP<vol> = KB of not yet purgeable space on volume <vol>\n"));
-
-       printf (_("\
-      LRUM      = LRU sitting time in minutes\n\
-      LRUS      = LRU sitting time in seconds\n\
-      DSDB      = check to see if DS Database is open\n\
-      DSVER     = NDS version\n\
-      UPRB      = used packet receive buffers\n\
-      PUPRB     = percent (of max) used packet receive buffers\n\
-      SAPENTRIES = number of entries in the SAP table\n\
-      SAPENTRIES<n> = number of entries in the SAP table for SAP type <n>\n"));
-
-       printf (_("\
-      TSYNC     = timesync status\n\
-      LOGINS    = check to see if logins are enabled\n\
-      CONNS     = number of currently licensed connections\n\
-      NRMH     = NRM Summary Status\n\
-      NRMP<stat> = Returns the current value for a NRM health item\n\
-      NRMM<stat> = Returns the current memory stats from NRM\n\
-      NRMS<stat> = Returns the current Swapfile stats from NRM\n\
-      NSS1<stat> = Statistics from _Admin:Manage_NSS\\GeneralStats.xml\n\
-      NSS2<stat> = Statistics from _Admin:Manage_NSS\\BufferCache.xml\n\
-      NSS3<stat> = Statistics from _Admin:Manage_NSS\\NameCache.xml\n\
-      NSS4<stat> = Statistics from _Admin:Manage_NSS\\FileStats.xml\n\
-      NSS5<stat> = Statistics from _Admin:Manage_NSS\\ObjectCache.xml\n\
-      NSS6<stat> = Statistics from _Admin:Manage_NSS\\Thread.xml\n\
-      NSS7<stat> = Statistics from _Admin:Manage_NSS\\AuthorizationCache.xml\n\
-      NLM:<nlm> = check if NLM is loaded and report version\n\
-                  (e.g. \"NLM:TSANDS.NLM\")\n"));
-
-       printf (_("\
- -w, --warning=INTEGER\n\
-    Threshold which will result in a warning status\n\
- -c, --critical=INTEGER\n\
-    Threshold which will result in a critical status\n\
- -o, --osversion\n\
-    Include server version string in results\n"));
+       printf (" %s\n", "-v, --variable=STRING");
+  printf ("   %s\n", _("Variable to check.  Valid variables include:"));
+  printf ("    %s\n", _("LOAD1     = 1 minute average CPU load"));
+  printf ("    %s\n", _("LOAD5     = 5 minute average CPU load"));
+  printf ("    %s\n", _("LOAD15    = 15 minute average CPU load"));
+  printf ("    %s\n", _("CSPROCS   = number of current service processes (NW 5.x only)"));
+  printf ("    %s\n", _("ABENDS    = number of abended threads (NW 5.x only)"));
+  printf ("    %s\n", _("UPTIME    = server uptime"));
+       printf ("    %s\n", _("LTCH      = percent long term cache hits"));
+  printf ("    %s\n", _("CBUFF     = current number of cache buffers"));
+  printf ("    %s\n", _("CDBUFF    = current number of dirty cache buffers"));
+  printf ("    %s\n", _("DCB       = dirty cache buffers as a percentage of the total"));
+  printf ("    %s\n", _("TCB       = dirty cache buffers as a percentage of the original"));
+       printf ("    %s\n", _("OFILES    = number of open files"));
+  printf ("    %s\n", _("    VMF<vol>  = MB of free space on Volume <vol>"));
+  printf ("    %s\n", _("    VMU<vol>  = MB used space on Volume <vol>"));
+  printf ("    %s\n", _("    VMP<vol>  = MB of purgeable space on Volume <vol>"));
+  printf ("    %s\n", _("    VPF<vol>  = percent free space on volume <vol>"));
+  printf ("    %s\n", _("    VKF<vol>  = KB of free space on volume <vol>"));
+  printf ("    %s\n", _("    VPP<vol>  = percent purgeable space on volume <vol>"));
+  printf ("    %s\n", _("    VKP<vol>  = KB of purgeable space on volume <vol>"));
+  printf ("    %s\n", _("    VPNP<vol> = percent not yet purgeable space on volume <vol>"));
+  printf ("    %s\n", _("    VKNP<vol> = KB of not yet purgeable space on volume <vol>"));
+  printf ("    %s\n", _("    LRUM      = LRU sitting time in minutes"));
+  printf ("    %s\n", _("    LRUS      = LRU sitting time in seconds"));
+  printf ("    %s\n", _("    DSDB      = check to see if DS Database is open"));
+  printf ("    %s\n", _("    DSVER     = NDS version"));
+  printf ("    %s\n", _("    UPRB      = used packet receive buffers"));
+  printf ("    %s\n", _("    PUPRB     = percent (of max) used packet receive buffers"));
+  printf ("    %s\n", _("    SAPENTRIES = number of entries in the SAP table"));
+  printf ("    %s\n", _("    SAPENTRIES<n> = number of entries in the SAP table for SAP type <n>"));
+  printf ("    %s\n", _("    TSYNC     = timesync status"));
+  printf ("    %s\n", _("    LOGINS    = check to see if logins are enabled"));
+  printf ("    %s\n", _("    CONNS     = number of currently licensed connections"));
+  printf ("    %s\n", _("    NRMH      = NRM Summary Status"));
+  printf ("    %s\n", _("    NRMP<stat> = Returns the current value for a NRM health item"));
+  printf ("    %s\n", _("    NRMM<stat> = Returns the current memory stats from NRM"));
+  printf ("    %s\n", _("    NRMS<stat> = Returns the current Swapfile stats from NRM"));
+  printf ("    %s\n", _("    NSS1<stat> = Statistics from _Admin:Manage_NSS\\GeneralStats.xml"));
+  printf ("    %s\n", _("    NSS3<stat> = Statistics from _Admin:Manage_NSS\\NameCache.xml"));
+  printf ("    %s\n", _("    NSS4<stat> = Statistics from _Admin:Manage_NSS\\FileStats.xml"));
+  printf ("    %s\n", _("    NSS5<stat> = Statistics from _Admin:Manage_NSS\\ObjectCache.xml"));
+  printf ("    %s\n", _("    NSS6<stat> = Statistics from _Admin:Manage_NSS\\Thread.xml"));
+  printf ("    %s\n", _("    NSS7<stat> = Statistics from _Admin:Manage_NSS\\AuthorizationCache.xml"));
+  printf ("    %s\n", _("    NLM:<nlm> = check if NLM is loaded and report version"));
+  printf ("    %s\n", _("                (e.g. NLM:TSANDS.NLM)"));
+  printf ("\n");
+       printf (" %s\n", "-w, --warning=INTEGER");
+  printf ("    %s\n", _("Threshold which will result in a warning status"));
+  printf (" %s\n", "-c, --critical=INTEGER");
+  printf ("    %s\n", _("Threshold which will result in a critical status"));
+  printf (" %s\n", "-o, --osversion");
+  printf ("    %s\n", _("Include server version string in results"));
 
        printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
 
   printf ("\n");
   printf ("%s\n", _("Notes:"));
-       printf (_("\
-- This plugin requres that the MRTGEXT.NLM file from James Drews' MRTG\n\
-  extension for NetWare be loaded on the Novell servers you wish to check.\n\
-  (available from http://www.engr.wisc.edu/~drews/mrtg/)\n\
-- Values for critical thresholds should be lower than warning thresholds\n\
-  when the following variables are checked: VPF, VKF, LTCH, CBUFF, DCB, \n\
-  TCB, LRUS and LRUM.\n"));
+       printf (" %s\n", _("- This plugin requres that the MRTGEXT.NLM file from James Drews' MRTG"));
+  printf (" %s\n", _("  extension for NetWare be loaded on the Novell servers you wish to check."));
+  printf (" %s\n", _("  (available from http://www.engr.wisc.edu/~drews/mrtg/)"));
+  printf (" %s\n", _("- Values for critical thresholds should be lower than warning thresholds"));
+  printf (" %s\n", _("  when the following variables are checked: VPF, VKF, LTCH, CBUFF, DCB, "));
+  printf (" %s\n", _("  TCB, LRUS and LRUM."));
+#ifdef NP_EXTRA_OPTS
+  printf (" -%s", _(UT_EXTRA_OPTS_NOTES));
+#endif
 
        printf (_(UT_SUPPORT));
 }