Skip to content

Commit cab643f

Browse files
author
Boris Lytochkin
committed
* added detection and walkaround for net-snmp library bug (net-snmp BUGid 2027834)
* drop UCD-SNMP support, R.I.P.
1 parent 1368364 commit cab643f

File tree

6 files changed

+77
-159
lines changed

6 files changed

+77
-159
lines changed

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ UPGRADE NOTES - PHP X.Y
276276
- New constants added for use in snmp_set_oid_output_format()
277277
function.
278278
- Added feature-rich OO API (SNMP class)
279+
- Dropped UCD-SNMP compatibility code. Consider upgrading to
280+
net-snmp v5.3+. Net-SNMP v5.4+ is required for Windows version.
279281

280282

281283
d. no longer possible to disable

ext/snmp/CREDITS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
SNMP
2-
Rasmus Lerdorf, Harrie Hazewinkel, Mike Jackson, Steven Lawrance, Johann Hanne
2+
Rasmus Lerdorf, Harrie Hazewinkel, Mike Jackson, Steven Lawrance, Johann Hanne, Boris Lytochkin

ext/snmp/config.m4

Lines changed: 62 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,8 @@ PHP_ARG_WITH(snmp,for SNMP support,
88
PHP_ARG_WITH(openssl-dir,OpenSSL dir for SNMP,
99
[ --with-openssl-dir[=DIR] SNMP: openssl install prefix], no, no)
1010

11-
PHP_ARG_ENABLE(ucd-snmp-hack, whether to enable UCD SNMP hack,
12-
[ --enable-ucd-snmp-hack SNMP: Enable UCD SNMP hack], no, no)
13-
1411
if test "$PHP_SNMP" != "no"; then
1512

16-
dnl
17-
dnl Try net-snmp first
18-
dnl
1913
if test "$PHP_SNMP" = "yes"; then
2014
AC_PATH_PROG(SNMP_CONFIG,net-snmp-config,,[/usr/local/bin:$PATH])
2115
else
@@ -30,78 +24,12 @@ if test "$PHP_SNMP" != "no"; then
3024
if test -n "$SNMP_LIBS" && test -n "$SNMP_PREFIX"; then
3125
PHP_ADD_INCLUDE(${SNMP_PREFIX}/include)
3226
PHP_EVAL_LIBLINE($SNMP_LIBS, SNMP_SHARED_LIBADD)
33-
AC_DEFINE(HAVE_NET_SNMP,1,[ ])
3427
SNMP_LIBNAME=netsnmp
3528
else
3629
AC_MSG_ERROR([Could not find the required paths. Please check your net-snmp installation.])
3730
fi
3831
else
39-
40-
dnl
41-
dnl Try ucd-snmp if net-snmp test failed
42-
dnl
43-
44-
if test "$PHP_SNMP" = "yes"; then
45-
for i in /usr/include /usr/local/include; do
46-
test -f $i/snmp.h && SNMP_INCDIR=$i
47-
test -f $i/ucd-snmp/snmp.h && SNMP_INCDIR=$i/ucd-snmp
48-
test -f $i/snmp/snmp.h && SNMP_INCDIR=$i/snmp
49-
test -f $i/snmp/include/ucd-snmp/snmp.h && SNMP_INCDIR=$i/snmp/include/ucd-snmp
50-
done
51-
for i in /usr/$PHP_LIBDIR /usr/snmp/lib /usr/local/$PHP_LIBDIR /usr/local/lib /usr/local/snmp/lib; do
52-
test -f $i/libsnmp.a || test -f $i/libsnmp.$SHLIB_SUFFIX_NAME && SNMP_LIBDIR=$i
53-
done
54-
else
55-
SNMP_INCDIR=$PHP_SNMP/include
56-
test -d $PHP_SNMP/include/ucd-snmp && SNMP_INCDIR=$PHP_SNMP/include/ucd-snmp
57-
SNMP_LIBDIR=$PHP_SNMP/lib
58-
fi
59-
60-
if test -z "$SNMP_INCDIR"; then
61-
AC_MSG_ERROR(snmp.h not found. Check your SNMP installation.)
62-
elif test -z "$SNMP_LIBDIR"; then
63-
AC_MSG_ERROR(libsnmp not found. Check your SNMP installation.)
64-
fi
65-
66-
old_CPPFLAGS=$CPPFLAGS
67-
CPPFLAGS=-I$SNMP_INCDIR
68-
AC_CHECK_HEADERS(default_store.h)
69-
if test "$ac_cv_header_default_store_h" = "yes"; then
70-
AC_MSG_CHECKING(for OpenSSL support in SNMP libraries)
71-
AC_EGREP_CPP(yes,[
72-
#include <ucd-snmp-config.h>
73-
#if USE_OPENSSL
74-
yes
75-
#endif
76-
],[
77-
SNMP_SSL=yes
78-
],[
79-
SNMP_SSL=no
80-
])
81-
fi
82-
CPPFLAGS=$old_CPPFLAGS
83-
AC_MSG_RESULT($SNMP_SSL)
84-
85-
if test "$SNMP_SSL" = "yes"; then
86-
if test "$PHP_OPENSSL_DIR" != "no"; then
87-
PHP_OPENSSL=$PHP_OPENSSL_DIR
88-
fi
89-
90-
if test "$PHP_OPENSSL" = "no"; then
91-
AC_MSG_ERROR([The UCD-SNMP in this system is built with SSL support.
92-
93-
Add --with-openssl-dir=DIR to your configure line.])
94-
else
95-
PHP_SETUP_OPENSSL(SNMP_SHARED_LIBADD, [], [
96-
AC_MSG_ERROR([SNMP: OpenSSL check failed. Please check config.log for more information.])
97-
])
98-
fi
99-
fi
100-
101-
AC_CHECK_LIB(kstat, kstat_read, [ PHP_ADD_LIBRARY(kstat,,SNMP_SHARED_LIBADD) ])
102-
PHP_ADD_INCLUDE($SNMP_INCDIR)
103-
PHP_ADD_LIBRARY_WITH_PATH(snmp, $SNMP_LIBDIR, SNMP_SHARED_LIBADD)
104-
SNMP_LIBNAME=snmp
32+
AC_MSG_ERROR([Could not find net-snmp-config binary. Please check your net-snmp installation.])
10533
fi
10634

10735
dnl Check whether snmp_parse_oid() exists.
@@ -130,10 +58,68 @@ if test "$PHP_SNMP" != "no"; then
13058
$SNMP_SHARED_LIBADD
13159
])
13260

133-
if test "$PHP_UCD_SNMP_HACK" = "yes" ; then
134-
AC_DEFINE(UCD_SNMP_HACK, 1, [ ])
61+
dnl Check for buggy snmp_snprint_value() (net-snmp BUGid 2027834)
62+
AC_CACHE_CHECK([for buggy snmp_snprint_value], ac_cv_buggy_snprint_value,[
63+
save_CFLAGS="$CFLAGS"
64+
CFLAGS="$CFLAGS -I${SNMP_PREFIX}/include"
65+
AC_TRY_RUN( [
66+
#include <stdio.h>
67+
#include <stdlib.h>
68+
#include <string.h>
69+
#include <net-snmp/net-snmp-config.h>
70+
#include <net-snmp/net-snmp-includes.h>
71+
72+
u_char uname[] = "Linux nex1.php.net 2.6.18-194.32.1.el5 #1 SMP Wed Jan 5 17:53:09 EST 2011 i686";
73+
74+
int main(int argc, char **argv)
75+
{
76+
int result = 0;
77+
struct variable_list vars;
78+
char buf1[2048];
79+
char buf2[sizeof(buf1)];
80+
81+
memset(&(buf1[0]), 0, sizeof(buf1));
82+
memset(&(buf2[0]), 0, sizeof(buf2));
83+
memset(&vars, 0, sizeof(vars));
84+
vars.type = 4;
85+
vars.val.integer = (long *)&(uname[0]);
86+
vars.val.string = &(uname[0]);
87+
vars.val.bitstring = &(uname[0]);
88+
vars.val.counter64 = (struct counter64 *)&(uname[0]);
89+
vars.val.floatVal = (float *)&(uname[0]);
90+
vars.val_len = sizeof(uname),
91+
vars.name_loc[0] = 1;
92+
vars.name_loc[1] = 3;
93+
vars.name_loc[2] = 6;
94+
vars.name_loc[3] = 1;
95+
vars.name_loc[4] = 2;
96+
vars.name_loc[5] = 1;
97+
vars.name_loc[6] = 1;
98+
vars.name_loc[7] = 1;
99+
vars.name = (oid *)&(vars.name_loc);
100+
vars.name_length = 9;
101+
102+
init_snmp("snmpapp");
103+
104+
netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT, 0);
105+
106+
snprint_value(buf1, (sizeof(uname) + 32), vars.name, vars.name_length, &vars);
107+
snprint_value(buf2, sizeof(buf2), vars.name, vars.name_length, &vars);
108+
exit((strncmp(buf1, buf2, sizeof(buf1)) != 0));
109+
}
110+
],[
111+
ac_cv_buggy_snprint_value=no
112+
],[
113+
ac_cv_buggy_snprint_value=yes
114+
],[
115+
ac_cv_buggy_snprint_value=no
116+
])
117+
CFLAGS="$save_CFLAGS"
118+
])
119+
if test "ac_cv_buggy_snprint_value" = "yes"; then
120+
AC_DEFINE(BUGGY_SNMPRINT_VALUE, 1, [ ])
135121
fi
136-
122+
137123
PHP_NEW_EXTENSION(snmp, snmp.c, $ext_shared)
138124
PHP_SUBST(SNMP_SHARED_LIBADD)
139125
fi

ext/snmp/config.w32

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ if (PHP_SNMP != "no") {
1010
CHECK_LIB("libeay32.lib", "snmp", PHP_SNMP)
1111
AC_DEFINE('HAVE_SNMP', 1);
1212
AC_DEFINE("HAVE_NET_SNMP", 1);
13-
} else if (CHECK_LIB("libsnmp.lib", "snmp", PHP_SNMP)) {
14-
EXTENSION('snmp', 'snmp.c');
15-
AC_DEFINE('HAVE_SNMP', 1);
1613
} else {
1714
WARNING("snmp not enabled; libraries and headers not found");
1815
}

ext/snmp/php_snmp.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,8 @@ typedef struct _php_snmp_object {
8888
int max_oids;
8989
int valueretrieval;
9090
int quick_print;
91-
#ifdef HAVE_NET_SNMP
9291
int enum_print;
9392
int oid_output_format;
94-
#endif
9593
int snmp_errno;
9694
char snmp_errstr[128];
9795
} php_snmp_object;

0 commit comments

Comments
 (0)