b5ae06
842279 - Incomplete command line in UCD-SNMP-MIB::extCommand
b5ae06
b5ae06
commit e8e44b3faecdba5daedfb45d815fae65117d1b22
b5ae06
Author: Jan Safranek <jsafranek@users.sourceforge.net>
b5ae06
Date:   Mon Sep 10 13:25:38 2012 +0200
b5ae06
b5ae06
    CHANGES: snmpd: fixed value of UCD-SNMP-MIB::extCommand to contain full command line.
b5ae06
    
b5ae06
    MIB description of UCD-SNMP-MIB::extCommand suggests it should contail full command line.
b5ae06
    Also in Net-SNMP 5.3.2.2, whole command line was shown.
b5ae06
b5ae06
diff --git a/agent/mibgroup/agent/extend.c b/agent/mibgroup/agent/extend.c
b5ae06
index 085d762..0b2c660 100644
b5ae06
--- a/agent/mibgroup/agent/extend.c
b5ae06
+++ b/agent/mibgroup/agent/extend.c
b5ae06
@@ -44,6 +44,9 @@ unsigned int             num_compatability_entries = 0;
b5ae06
 unsigned int             max_compatability_entries = 50;
b5ae06
 netsnmp_old_extend *compatability_entries;
b5ae06
 
b5ae06
+char           *cmdlinebuf;
b5ae06
+size_t          cmdlinesize;
b5ae06
+
b5ae06
 WriteMethod fixExec2Error;
b5ae06
 FindVarMethod var_extensible_old;
b5ae06
 oid  old_extensible_variables_oid[] = { NETSNMP_UCDAVIS_MIB, NETSNMP_SHELLMIBNUM, 1 };
b5ae06
@@ -1354,6 +1357,23 @@ handle_nsExtendOutput2Table(netsnmp_mib_handler          *handler,
b5ae06
          *
b5ae06
          *************************/
b5ae06
 
b5ae06
+char * _get_cmdline(netsnmp_extend *extend)
b5ae06
+{
b5ae06
+    size_t          size;
b5ae06
+    
b5ae06
+    size = strlen(extend->command) + strlen(extend->args) + 2;
b5ae06
+    if (size > cmdlinesize) {
b5ae06
+        cmdlinebuf = realloc(cmdlinebuf, size);
b5ae06
+	if (!cmdlinebuf) {
b5ae06
+            cmdlinesize = 0;
b5ae06
+            return NULL;
b5ae06
+	}
b5ae06
+	cmdlinesize = size;
b5ae06
+    }
b5ae06
+    sprintf(cmdlinebuf, "%s %s", extend->command, extend->args);
b5ae06
+    return cmdlinebuf;
b5ae06
+}
b5ae06
+
b5ae06
 u_char *
b5ae06
 var_extensible_old(struct variable * vp,
b5ae06
                      oid * name,
b5ae06
@@ -1364,6 +1384,7 @@ var_extensible_old(struct variable * vp,
b5ae06
     netsnmp_old_extend *exten = NULL;
b5ae06
     static long     long_ret;
b5ae06
     unsigned int idx;
b5ae06
+    char         *cmdline;
b5ae06
 
b5ae06
     if (header_simple_table
b5ae06
         (vp, name, length, exact, var_len, write_method, num_compatability_entries))
b5ae06
@@ -1382,8 +1403,10 @@ var_extensible_old(struct variable * vp,
b5ae06
             *var_len = strlen(exten->exec_entry->token);
b5ae06
             return ((u_char *) (exten->exec_entry->token));
b5ae06
         case SHELLCOMMAND:
b5ae06
-            *var_len = strlen(exten->exec_entry->command);
b5ae06
-            return ((u_char *) (exten->exec_entry->command));
b5ae06
+            cmdline = _get_cmdline(exten->exec_entry);
b5ae06
+            if (cmdline)
b5ae06
+                *var_len = strlen(cmdline);
b5ae06
+            return ((u_char *) cmdline);
b5ae06
         case ERRORFLAG:        /* return code from the process */
b5ae06
             netsnmp_cache_check_and_reload( exten->exec_entry->cache );
b5ae06
             long_ret = exten->exec_entry->result;
b5ae06
@@ -1406,8 +1429,10 @@ var_extensible_old(struct variable * vp,
b5ae06
 
b5ae06
         case ERRORFIXCMD:
b5ae06
             if (exten->efix_entry) {
b5ae06
-                *var_len = strlen(exten->efix_entry->command);
b5ae06
-                return ((u_char *) exten->efix_entry->command);
b5ae06
+                cmdline = _get_cmdline(exten->efix_entry);
b5ae06
+		if (cmdline)
b5ae06
+                    *var_len = strlen(cmdline);
b5ae06
+                return ((u_char *) cmdline);
b5ae06
             } else {
b5ae06
                 *var_len = 0;
b5ae06
                 return ((u_char *) &long_return);  /* Just needs to be non-null! */