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