php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20857 snmpset does not work
Submitted: 2002-12-06 08:12 UTC Modified: 2003-07-22 02:11 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:2 (100.0%)
From: rs at epost dot de Assigned:
Status: Closed Package: SNMP related
PHP Version: 4.3.0RC2 OS: Linux RH 7.3
Private report: No CVE-ID: None
 [2002-12-06 08:12 UTC] rs at epost dot de
I use php-4.3.0RC2 with net-snmp-5.0.6. It works so far, but snmpset() always shows a warning "Could not add variable: " and the variable is not set.
I found out, that there is a bug in ext/snmp.c. Here, type and value of the varible are not passed to php_snmp_internal(), so these variables are always 0 and snmp_add_var() fails. So, as a solution, php_snmp and php_snmpv3 should pass type and value to php_snmp_internal ant everything is ok.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-06 18:37 UTC] sniper@php.net
Do you have a patch for this?

 [2002-12-07 04:35 UTC] rs at epost dot de
I tried this patch in diff -u format. Note that there is also a change in the php_error_docref-string, becaue the output was not very informative. Of course, I would prefer, that a php-snmp maintainer would have a look at it.

--- snmp.c.orig	Mon Nov 11 22:37:18 2002
+++ snmp.c	Sat Dec  7 11:23:24 2002
@@ -197,7 +197,7 @@
 static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS,
 		int st,
 		struct snmp_session *session,
-		char *objid) 
+		char *objid, char type, char* value) 
 {
 	struct snmp_session *ss;
 	struct snmp_pdu *pdu=NULL, *response;
@@ -211,8 +211,6 @@
 	char buf[2048];
 	char buf2[2048];
 	int keepwalking=1;
-	char type = (char) 0;
-	char *value = (char *) 0;
 	char *err;
 
 	if (st >= 2) { /* walk */
@@ -267,7 +265,12 @@
 		} else if (st == 11) {
 			pdu = snmp_pdu_create(SNMP_MSG_SET);
 			if (snmp_add_var(pdu, name, name_length, type, value)) {
-				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not add variable: %s", name);
+#ifdef HAVE_NET_SNMP
+				snprint_objid(buf, sizeof(buf), name, name_length);
+#else
+				sprint_objid(buf, name, name_length);
+#endif
+				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not add variable: %s %c %s", buf, type, value);
 				snmp_close(ss);
 				RETURN_FALSE;
 			}
@@ -466,7 +469,7 @@
 	
 	session.authenticator = NULL;
 
-	php_snmp_internal(INTERNAL_FUNCTION_PARAM_PASSTHRU, st, &session, Z_STRVAL_PP(a3));
+	php_snmp_internal(INTERNAL_FUNCTION_PARAM_PASSTHRU, st, &session, Z_STRVAL_PP(a3), type, value);
 }
 /* }}} */
 
@@ -849,7 +852,7 @@
 	session.retries = retries;
 	session.timeout = timeout;
 
-	php_snmp_internal(INTERNAL_FUNCTION_PARAM_PASSTHRU, st, &session, Z_STRVAL_PP(a8));
+	php_snmp_internal(INTERNAL_FUNCTION_PARAM_PASSTHRU, st, &session, Z_STRVAL_PP(a8), type, value);
 }
 /* }}} */
 [2003-01-09 08:18 UTC] steve at deinon dot com
This problem still exists for the php 4.3.0 release.  I am also using net-snmp 5.0.6

The patch posted by rs@epost.de fixed the problem.  I updated the offsets in his patch for the 4.3.0 sources.

The updated patch can be found at: http://www.deinon.com/php/php-4.3.0-snmpset.patch
 [2003-01-24 02:36 UTC] jirapat at nstda dot or dot th
on WinNT4, W2K
snmpset function said "Couldn't add variable" when I try to use it with version 4.3.0.
But if I use same script with php version 4.2.3 it's work fine in same environment.
I've found this error on CVS version both 4.3.x and 5.x too.
I tried to copy php_snmp.dll from version 4.2.3 to replace version 4.3.0 script is work again.
So I think this must come from snmp extension from 4.3.0 up.

PS there is no problem with snmpget and snmpwalk
 [2003-01-24 03:54 UTC] sniper@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


Patch applied, thanks!

 [2003-07-21 10:26 UTC] di98mha at student dot bth dot se
This bug still exist under 4.3.1!!
It seems like the patch is not added to this version.

The patch works perfectly fine if you add it in 4.3.1
 [2003-07-21 11:02 UTC] philip@php.net
PHP 4.3.0 == 4.3.1 with one slight change to the CGI.  So, this patch exists in PHP as of 4.3.2
 [2003-07-22 02:11 UTC] sniper@php.net
And actually only PHP 4.3.3RC2-dev (STABLE CVS) really works.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC