From bbb4f679aef236c717d3938080ef2f184b63c6e9 Mon Sep 17 00:00:00 2001 From: Boris Lytochkin Date: Wed, 6 Apr 2011 06:58:25 +0000 Subject: [PATCH] * Net-SNMP version detection and proper processing * more UCD-SNMP-related code removal --- ext/snmp/config.m4 | 41 ++++++++++++++++++----------------- ext/snmp/snmp.c | 53 ++++++---------------------------------------- 2 files changed, 27 insertions(+), 67 deletions(-) diff --git a/ext/snmp/config.m4 b/ext/snmp/config.m4 index ea97451100..af53bbf141 100644 --- a/ext/snmp/config.m4 +++ b/ext/snmp/config.m4 @@ -20,23 +20,34 @@ if test "$PHP_SNMP" != "no"; then SNMP_LIBS=`$SNMP_CONFIG --netsnmp-libs` SNMP_LIBS="$SNMP_LIBS `$SNMP_CONFIG --external-libs`" SNMP_PREFIX=`$SNMP_CONFIG --prefix` - - if test -n "$SNMP_LIBS" && test -n "$SNMP_PREFIX"; then - PHP_ADD_INCLUDE(${SNMP_PREFIX}/include) - PHP_EVAL_LIBLINE($SNMP_LIBS, SNMP_SHARED_LIBADD) - SNMP_LIBNAME=netsnmp + snmp_full_version=`$SNMP_CONFIG --version` + ac_IFS=$IFS + IFS="." + set $snmp_full_version + IFS=$ac_IFS + SNMP_VERSION=`expr [$]1 \* 1000 + [$]2` + if test "$SNMP_VERSION" -ge "5003"; then + if test -n "$SNMP_LIBS" && test -n "$SNMP_PREFIX"; then + PHP_ADD_INCLUDE(${SNMP_PREFIX}/include) + PHP_EVAL_LIBLINE($SNMP_LIBS, SNMP_SHARED_LIBADD) + SNMP_LIBNAME=netsnmp + else + AC_MSG_ERROR([Could not find the required paths. Please check your net-snmp installation.]) + fi else - AC_MSG_ERROR([Could not find the required paths. Please check your net-snmp installation.]) + AC_MSG_ERROR([Net-SNMP version 5.3 or greater reqired (detected $snmp_full_version).]) fi else AC_MSG_ERROR([Could not find net-snmp-config binary. Please check your net-snmp installation.]) fi - dnl Check whether snmp_parse_oid() exists. - PHP_CHECK_LIBRARY($SNMP_LIBNAME, snmp_parse_oid, + dnl Test build. + PHP_CHECK_LIBRARY($SNMP_LIBNAME, init_snmp, [ - AC_DEFINE(HAVE_SNMP_PARSE_OID, 1, [ ]) - ], [], [ + AC_DEFINE(HAVE_SNMP,1,[ ]) + ], [ + AC_MSG_ERROR([SNMP sanity check failed. Please check config.log for more information.]) + ], [ $SNMP_SHARED_LIBADD ]) @@ -48,16 +59,6 @@ if test "$PHP_SNMP" != "no"; then $SNMP_SHARED_LIBADD ]) - dnl Test build. - PHP_CHECK_LIBRARY($SNMP_LIBNAME, init_snmp, - [ - AC_DEFINE(HAVE_SNMP,1,[ ]) - ], [ - AC_MSG_ERROR([SNMP sanity check failed. Please check config.log for more information.]) - ], [ - $SNMP_SHARED_LIBADD - ]) - dnl Check for buggy snmp_snprint_value() (net-snmp BUGid 2027834) AC_CACHE_CHECK([for buggy snmp_snprint_value], ac_cv_buggy_snprint_value,[ save_CFLAGS="$CFLAGS" diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c index 47080b6701..7d7f16be96 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -75,11 +75,6 @@ #include #include -/* Ugly macro, since the length of OIDs in UCD-SNMP and NET-SNMP - * is different and this way the code is not full of 'ifdef's. - */ -#define OIDSIZE(p) (sizeof(p)/sizeof(oid)) - #if PHP_VERSION_ID < 50300 #define Z_ADDREF_P(pz) pz->refcount++ #define Z_ISREF_PP(oid) (PZVAL_IS_REF(*(oid))) @@ -99,11 +94,6 @@ extern netsnmp_log_handler *logh_head; } #endif -/* For really old ucd-snmp versions.. */ -#ifndef HAVE_SNMP_PARSE_OID -#define snmp_parse_oid read_objid -#endif - #define SNMP_VALUE_LIBRARY 0 #define SNMP_VALUE_PLAIN 1 #define SNMP_VALUE_OBJECT 2 @@ -1092,11 +1082,7 @@ static int netsnmp_session_init(php_snmp_session **session_p, int version, char session->securityNameLen = strlen(session->securityName); } else { session->authenticator = NULL; -#ifdef UCD_SNMP_HACK - session->community = (u_char *)strdup(community); /* memory freed by SNMP library, strdup NOT estrdup */ -#else session->community = (u_char *)community; -#endif session->community_len = strlen(community); } @@ -1129,10 +1115,10 @@ static int netsnmp_session_set_auth_protocol(struct snmp_session *s, char *prot { if (!strcasecmp(prot, "MD5")) { s->securityAuthProto = usmHMACMD5AuthProtocol; - s->securityAuthProtoLen = OIDSIZE(usmHMACMD5AuthProtocol); + s->securityAuthProtoLen = USM_AUTH_PROTO_MD5_LEN; } else if (!strcasecmp(prot, "SHA")) { s->securityAuthProto = usmHMACSHA1AuthProtocol; - s->securityAuthProtoLen = OIDSIZE(usmHMACSHA1AuthProtocol); + s->securityAuthProtoLen = USM_AUTH_PROTO_SHA_LEN; } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown authentication protocol '%s'", prot); return (-1); @@ -1147,38 +1133,11 @@ static int netsnmp_session_set_sec_protocol(struct snmp_session *s, char *prot T { if (!strcasecmp(prot, "DES")) { s->securityPrivProto = usmDESPrivProtocol; - s->securityPrivProtoLen = OIDSIZE(usmDESPrivProtocol); + s->securityPrivProtoLen = USM_PRIV_PROTO_DES_LEN; #ifdef HAVE_AES - } else if (!strcasecmp(prot, "AES128") -#ifdef SNMP_VALIDATE_ERR -/* -* In Net-SNMP before 5.2, the following symbols exist: -* usmAES128PrivProtocol, usmAES192PrivProtocol, usmAES256PrivProtocol -* In an effort to be more standards-compliant, 5.2 removed the last two. -* As of 5.2, the symbols are: -* usmAESPrivProtocol, usmAES128PrivProtocol -* -* As we want this extension to compile on both versions, we use the latter -* symbol on purpose, as it's defined to be the same as the former. -* -* However, in 5.2 the type of usmAES128PrivProtocol is a pointer, not an -* array, so we cannot use the OIDSIZE macro because it uses sizeof(). -* -*/ - || !strcasecmp(prot, "AES")) { - s->securityPrivProto = usmAES128PrivProtocol; - s->securityPrivProtoLen = USM_PRIV_PROTO_AES128_LEN; -#else - ) { - s->securityPrivProto = usmAES128PrivProtocol; - s->securityPrivProtoLen = OIDSIZE(usmAES128PrivProtocol); - } else if (!strcasecmp(prot, "AES192")) { - s->securityPrivProto = usmAES192PrivProtocol; - s->securityPrivProtoLen = OIDSIZE(usmAES192PrivProtocol); - } else if (!strcasecmp(prot, "AES256")) { - s->securityPrivProto = usmAES256PrivProtocol; - s->securityPrivProtoLen = OIDSIZE(usmAES256PrivProtocol); -#endif + } else if (!strcasecmp(prot, "AES128") || !strcasecmp(prot, "AES")) { + s->securityPrivProto = usmAESPrivProtocol; + s->securityPrivProtoLen = USM_PRIV_PROTO_AES_LEN; #endif } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown security protocol '%s'", prot); -- 2.40.0