diff options
Diffstat (limited to 'web/attachments/450270-nagios-plugins-1.4.15-snmp_conf_final.patch')
-rw-r--r-- | web/attachments/450270-nagios-plugins-1.4.15-snmp_conf_final.patch | 217 |
1 files changed, 217 insertions, 0 deletions
diff --git a/web/attachments/450270-nagios-plugins-1.4.15-snmp_conf_final.patch b/web/attachments/450270-nagios-plugins-1.4.15-snmp_conf_final.patch new file mode 100644 index 0000000..a1bb976 --- /dev/null +++ b/web/attachments/450270-nagios-plugins-1.4.15-snmp_conf_final.patch | |||
@@ -0,0 +1,217 @@ | |||
1 | # This patch remove the SNMP configuration verification and allow using null parameters. | ||
2 | # This allows the user to configure SNMP in /etc/snmp/snmp.conf and not use the command line | ||
3 | --- nagios-plugins-1.4.15/plugins/check_snmp.c.conf 2011-07-22 09:23:17.000000000 -0400 | ||
4 | +++ nagios-plugins-1.4.15/plugins/check_snmp.c 2011-07-26 16:47:28.000000000 -0400 | ||
5 | @@ -259,26 +259,29 @@ | ||
6 | asprintf (&command_line[4], "%d", retries); | ||
7 | command_line[5] = strdup ("-m"); | ||
8 | command_line[6] = strdup (miblist); | ||
9 | - command_line[7] = "-v"; | ||
10 | - command_line[8] = strdup (proto); | ||
11 | |||
12 | for (i = 0; i < numauthpriv; i++) { | ||
13 | - command_line[9 + i] = authpriv[i]; | ||
14 | + command_line[7 + i] = authpriv[i]; | ||
15 | } | ||
16 | |||
17 | - asprintf (&command_line[9 + numauthpriv], "%s:%s", server_address, port); | ||
18 | + asprintf (&command_line[7 + numauthpriv], "%s:%s", server_address, port); | ||
19 | |||
20 | /* This is just for display purposes, so it can remain a string */ | ||
21 | - asprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s -v %s %s %s:%s", | ||
22 | - snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]", | ||
23 | - server_address, port); | ||
24 | + if (proto != NULL) | ||
25 | + asprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s -v %s %s %s:%s", | ||
26 | + snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]", | ||
27 | + server_address, port); | ||
28 | + else | ||
29 | + asprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s %s %s:%s", | ||
30 | + snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", "[authpriv]", | ||
31 | + server_address, port); | ||
32 | |||
33 | for (i = 0; i < numoids; i++) { | ||
34 | - command_line[9 + numauthpriv + 1 + i] = oids[i]; | ||
35 | + command_line[7 + numauthpriv + 1 + i] = oids[i]; | ||
36 | asprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); | ||
37 | } | ||
38 | |||
39 | - command_line[9 + numauthpriv + 1 + numoids] = NULL; | ||
40 | + command_line[7 + numauthpriv + 1 + numoids] = NULL; | ||
41 | |||
42 | if (verbose) | ||
43 | printf ("%s\n", cl_hidden_auth); | ||
44 | @@ -808,9 +811,6 @@ | ||
45 | if (server_address == NULL) | ||
46 | server_address = argv[optind]; | ||
47 | |||
48 | - if (community == NULL) | ||
49 | - community = strdup (DEFAULT_COMMUNITY); | ||
50 | - | ||
51 | return validate_arguments (); | ||
52 | } | ||
53 | |||
54 | @@ -835,9 +835,36 @@ | ||
55 | |||
56 | |||
57 | |||
58 | +void addParam(char *flag, char*val) { | ||
59 | + // We are lazy. Verify if the value is null and, if not, add it | ||
60 | + if (flag != NULL && val != NULL) { | ||
61 | + // Raise the amount of space required for our array | ||
62 | + numauthpriv+=2; | ||
63 | + | ||
64 | + if (authpriv == NULL) | ||
65 | + authpriv = calloc(numauthpriv, sizeof(char *)); | ||
66 | + else | ||
67 | + authpriv = realloc(authpriv, numauthpriv * sizeof(char *)); | ||
68 | + | ||
69 | + authpriv[numauthpriv-2] = strdup(flag); | ||
70 | + authpriv[numauthpriv-1] = strdup(val); | ||
71 | + } | ||
72 | +} | ||
73 | + | ||
74 | +/* | ||
75 | +Protocol Security Params Reason | ||
76 | +NULL NULL -c,-a,-u,-A,-x,-X We don't know what the user wants. We overwrite anything provided. | ||
77 | +1 * -v,-c SNMP v1 supports only community | ||
78 | +2c * -v,-c SNMP v2c supports only community | ||
79 | +3 NULL -v,-u,-a,-A,-x,-X We don't know the security required in snmp.conf. We provide anything | ||
80 | +3 authPriv -v,-l,-u,-a,-A,-x,-X We overwrite any Authentication of privacy setting of snmp.conf by command line | ||
81 | +3 noAuthNoPriv -v,-l,-u We provide version, security level and security name | ||
82 | +3 authNoPriv -v,-l,-u,-a,-A We provide version, security level, security name and password | ||
83 | +*/ | ||
84 | int | ||
85 | validate_arguments () | ||
86 | { | ||
87 | + numauthpriv=0; | ||
88 | /* check whether to load locally installed MIBS (CPU/disk intensive) */ | ||
89 | if (miblist == NULL) { | ||
90 | if ( needmibs == TRUE ) { | ||
91 | @@ -855,75 +882,38 @@ | ||
92 | if (numoids == 0) | ||
93 | die(STATE_UNKNOWN, _("No OIDs specified\n")); | ||
94 | |||
95 | - if (proto == NULL) | ||
96 | - asprintf(&proto, DEFAULT_PROTOCOL); | ||
97 | |||
98 | - if ((strcmp(proto,"1") == 0) || (strcmp(proto, "2c")==0)) { /* snmpv1 or snmpv2c */ | ||
99 | - numauthpriv = 2; | ||
100 | - authpriv = calloc (numauthpriv, sizeof (char *)); | ||
101 | - authpriv[0] = strdup ("-c"); | ||
102 | - authpriv[1] = strdup (community); | ||
103 | - } | ||
104 | - else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */ | ||
105 | - if (seclevel == NULL) | ||
106 | - asprintf(&seclevel, "noAuthNoPriv"); | ||
107 | - | ||
108 | - if (strcmp(seclevel, "noAuthNoPriv") == 0) { | ||
109 | - numauthpriv = 2; | ||
110 | - authpriv = calloc (numauthpriv, sizeof (char *)); | ||
111 | - authpriv[0] = strdup ("-l"); | ||
112 | - authpriv[1] = strdup ("noAuthNoPriv"); | ||
113 | + if (proto == NULL || strcmp (proto, "3") == 0) { | ||
114 | + // No protocol will pass any valid parameter. See note before function for more explanation | ||
115 | + if (proto == NULL) { | ||
116 | + addParam("-c",community); | ||
117 | } else { | ||
118 | - if (! ( (strcmp(seclevel, "authNoPriv")==0) || (strcmp(seclevel, "authPriv")==0) ) ) { | ||
119 | - usage2 (_("Invalid seclevel"), seclevel); | ||
120 | - } | ||
121 | - | ||
122 | - if (authproto == NULL ) | ||
123 | - asprintf(&authproto, DEFAULT_AUTH_PROTOCOL); | ||
124 | - | ||
125 | - if (secname == NULL) | ||
126 | - die(STATE_UNKNOWN, _("Required parameter: %s\n"), "secname"); | ||
127 | - | ||
128 | - if (authpasswd == NULL) | ||
129 | - die(STATE_UNKNOWN, _("Required parameter: %s\n"), "authpasswd"); | ||
130 | - | ||
131 | - if ( strcmp(seclevel, "authNoPriv") == 0 ) { | ||
132 | - numauthpriv = 8; | ||
133 | - authpriv = calloc (numauthpriv, sizeof (char *)); | ||
134 | - authpriv[0] = strdup ("-l"); | ||
135 | - authpriv[1] = strdup ("authNoPriv"); | ||
136 | - authpriv[2] = strdup ("-a"); | ||
137 | - authpriv[3] = strdup (authproto); | ||
138 | - authpriv[4] = strdup ("-u"); | ||
139 | - authpriv[5] = strdup (secname); | ||
140 | - authpriv[6] = strdup ("-A"); | ||
141 | - authpriv[7] = strdup (authpasswd); | ||
142 | - } else if ( strcmp(seclevel, "authPriv") == 0 ) { | ||
143 | - if (privproto == NULL ) | ||
144 | - asprintf(&privproto, DEFAULT_PRIV_PROTOCOL); | ||
145 | - | ||
146 | - if (privpasswd == NULL) | ||
147 | - die(STATE_UNKNOWN, _("Required parameter: %s\n"), "privpasswd"); | ||
148 | - | ||
149 | - numauthpriv = 12; | ||
150 | - authpriv = calloc (numauthpriv, sizeof (char *)); | ||
151 | - authpriv[0] = strdup ("-l"); | ||
152 | - authpriv[1] = strdup ("authPriv"); | ||
153 | - authpriv[2] = strdup ("-a"); | ||
154 | - authpriv[3] = strdup (authproto); | ||
155 | - authpriv[4] = strdup ("-u"); | ||
156 | - authpriv[5] = strdup (secname); | ||
157 | - authpriv[6] = strdup ("-A"); | ||
158 | - authpriv[7] = strdup (authpasswd); | ||
159 | - authpriv[8] = strdup ("-x"); | ||
160 | - authpriv[9] = strdup (privproto); | ||
161 | - authpriv[10] = strdup ("-X"); | ||
162 | - authpriv[11] = strdup (privpasswd); | ||
163 | - } | ||
164 | + addParam("-v",proto); | ||
165 | } | ||
166 | + addParam("-u",secname); | ||
167 | |||
168 | - } | ||
169 | - else { | ||
170 | + if (seclevel == NULL || strcmp(seclevel, "authPriv")==0) { | ||
171 | + addParam("-l",seclevel); | ||
172 | + addParam("-a",authproto); | ||
173 | + addParam("-A",authpasswd); | ||
174 | + addParam("-x",privproto); | ||
175 | + addParam("-X",privpasswd); | ||
176 | + } else if (strcmp(seclevel, "noAuthNoPriv") == 0) { | ||
177 | + addParam("-v",proto); | ||
178 | + addParam("-l",seclevel); | ||
179 | + } else if (strcmp(seclevel, "authNoPriv")==0) { | ||
180 | + addParam("-v",proto); | ||
181 | + addParam("-l",seclevel); | ||
182 | + addParam("-a",authproto); | ||
183 | + addParam("-A",authpasswd); | ||
184 | + } else { | ||
185 | + usage2 (_("Invalid seclevel"), seclevel); | ||
186 | + } | ||
187 | + } else if ((strcmp(proto,"1") == 0) || (strcmp(proto, "2c")==0)) { /* snmpv1 or snmpv2c */ | ||
188 | + // If we specified protocol v2, the only param that is usefull is community string (if specified). | ||
189 | + addParam("-v",proto); | ||
190 | + addParam("-c",community); | ||
191 | + } else { | ||
192 | usage2 (_("Invalid SNMP version"), proto); | ||
193 | } | ||
194 | |||
195 | @@ -1011,12 +1001,11 @@ | ||
196 | printf (" %s\n", "-a, --authproto=[MD5|SHA]"); | ||
197 | printf (" %s\n", _("SNMPv3 auth proto")); | ||
198 | printf (" %s\n", "-x, --privproto=[DES|AES]"); | ||
199 | - printf (" %s\n", _("SNMPv3 priv proto (default DES)")); | ||
200 | + printf (" %s\n", _("SNMPv3 priv proto")); | ||
201 | |||
202 | /* Authentication Tokens*/ | ||
203 | printf (" %s\n", "-C, --community=STRING"); | ||
204 | printf (" %s ", _("Optional community string for SNMP communication")); | ||
205 | - printf ("(%s \"%s\")\n", _("default is") ,DEFAULT_COMMUNITY); | ||
206 | printf (" %s\n", "-U, --secname=USERNAME"); | ||
207 | printf (" %s\n", _("SNMPv3 username")); | ||
208 | printf (" %s\n", "-A, --authpassword=PASSWORD"); | ||
209 | @@ -1076,6 +1065,8 @@ | ||
210 | |||
211 | printf ("\n"); | ||
212 | printf ("%s\n", _("Notes:")); | ||
213 | + printf (" %s\n", _("- Default configurations are retrieved from /etc/snmp/snmp.conf. See man page of")); | ||
214 | + printf (" %s\n", _("snmp.conf for more information.")); | ||
215 | printf (" %s\n", _("- Multiple OIDs may be indicated by a comma or space-delimited list (lists with")); | ||
216 | printf (" %s %i %s\n", _("internal spaces must be quoted). Maximum:"), MAX_OIDS, _("OIDs.")); | ||
217 | |||