Blame SOURCES/net-snmp-5.7.2-exec-cmdline.patch

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