Blob Blame History Raw
842279 - Incomplete command line in UCD-SNMP-MIB::extCommand

commit e8e44b3faecdba5daedfb45d815fae65117d1b22
Author: Jan Safranek <jsafranek@users.sourceforge.net>
Date:   Mon Sep 10 13:25:38 2012 +0200

    CHANGES: snmpd: fixed value of UCD-SNMP-MIB::extCommand to contain full command line.
    
    MIB description of UCD-SNMP-MIB::extCommand suggests it should contail full command line.
    Also in Net-SNMP 5.3.2.2, whole command line was shown.

diff --git a/agent/mibgroup/agent/extend.c b/agent/mibgroup/agent/extend.c
index 085d762..0b2c660 100644
--- a/agent/mibgroup/agent/extend.c
+++ b/agent/mibgroup/agent/extend.c
@@ -44,6 +44,9 @@ unsigned int             num_compatability_entries = 0;
 unsigned int             max_compatability_entries = 50;
 netsnmp_old_extend *compatability_entries;
 
+char           *cmdlinebuf;
+size_t          cmdlinesize;
+
 WriteMethod fixExec2Error;
 FindVarMethod var_extensible_old;
 oid  old_extensible_variables_oid[] = { NETSNMP_UCDAVIS_MIB, NETSNMP_SHELLMIBNUM, 1 };
@@ -1354,6 +1357,23 @@ handle_nsExtendOutput2Table(netsnmp_mib_handler          *handler,
          *
          *************************/
 
+char * _get_cmdline(netsnmp_extend *extend)
+{
+    size_t          size;
+    
+    size = strlen(extend->command) + strlen(extend->args) + 2;
+    if (size > cmdlinesize) {
+        cmdlinebuf = realloc(cmdlinebuf, size);
+	if (!cmdlinebuf) {
+            cmdlinesize = 0;
+            return NULL;
+	}
+	cmdlinesize = size;
+    }
+    sprintf(cmdlinebuf, "%s %s", extend->command, extend->args);
+    return cmdlinebuf;
+}
+
 u_char *
 var_extensible_old(struct variable * vp,
                      oid * name,
@@ -1364,6 +1384,7 @@ var_extensible_old(struct variable * vp,
     netsnmp_old_extend *exten = NULL;
     static long     long_ret;
     unsigned int idx;
+    char         *cmdline;
 
     if (header_simple_table
         (vp, name, length, exact, var_len, write_method, num_compatability_entries))
@@ -1382,8 +1403,10 @@ var_extensible_old(struct variable * vp,
             *var_len = strlen(exten->exec_entry->token);
             return ((u_char *) (exten->exec_entry->token));
         case SHELLCOMMAND:
-            *var_len = strlen(exten->exec_entry->command);
-            return ((u_char *) (exten->exec_entry->command));
+            cmdline = _get_cmdline(exten->exec_entry);
+            if (cmdline)
+                *var_len = strlen(cmdline);
+            return ((u_char *) cmdline);
         case ERRORFLAG:        /* return code from the process */
             netsnmp_cache_check_and_reload( exten->exec_entry->cache );
             long_ret = exten->exec_entry->result;
@@ -1406,8 +1429,10 @@ var_extensible_old(struct variable * vp,
 
         case ERRORFIXCMD:
             if (exten->efix_entry) {
-                *var_len = strlen(exten->efix_entry->command);
-                return ((u_char *) exten->efix_entry->command);
+                cmdline = _get_cmdline(exten->efix_entry);
+		if (cmdline)
+                    *var_len = strlen(cmdline);
+                return ((u_char *) cmdline);
             } else {
                 *var_len = 0;
                 return ((u_char *) &long_return);  /* Just needs to be non-null! */