@@ -654,7 +654,7 @@ static void php_free_objid_query(struct objid_query *objid_query, HashTable* oid
654654static bool php_snmp_parse_oid (
655655 zval * object , int st , struct objid_query * objid_query , zend_string * oid_str , HashTable * oid_ht ,
656656 zend_string * type_str , HashTable * type_ht , zend_string * value_str , HashTable * value_ht ,
657- uint32_t oid_argument_offset , uint32_t type_argument_offset , uint32_t value_argument_offset
657+ uint32_t oid_arg_num , uint32_t type_arg_num , uint32_t value_arg_num
658658) {
659659 char * pptr ;
660660 uint32_t idx_type = 0 , idx_value = 0 ;
@@ -681,7 +681,7 @@ static bool php_snmp_parse_oid(
681681 ZEND_ASSERT (type_str && value_str );
682682
683683 if (ZSTR_LEN (type_str ) != 1 ) {
684- zend_argument_value_error (type_argument_offset , "must be a single character" );
684+ zend_argument_value_error (type_arg_num , "must be a single character" );
685685 efree (objid_query -> vars );
686686 return false;
687687 }
@@ -692,7 +692,7 @@ static bool php_snmp_parse_oid(
692692 objid_query -> count ++ ;
693693 } else if (oid_ht ) { /* we got objid array */
694694 if (zend_hash_num_elements (oid_ht ) == 0 ) {
695- zend_argument_value_error (oid_argument_offset , "must not be empty when passed as an array" );
695+ zend_argument_value_error (oid_arg_num , "must not be empty when passed as an array" );
696696 return false;
697697 }
698698 objid_query -> vars = (snmpobjarg * )safe_emalloc (sizeof (snmpobjarg ), zend_hash_num_elements (oid_ht ), 0 );
@@ -737,14 +737,14 @@ static bool php_snmp_parse_oid(
737737 char ptype = * ZSTR_VAL (type );
738738 zend_string_release (type );
739739 if (len != 1 ) {
740- zend_argument_value_error (type_argument_offset , "must be a single character" );
740+ zend_argument_value_error (type_arg_num , "must be a single character" );
741741 php_free_objid_query (objid_query , oid_ht , value_ht , st );
742742 return false;
743743 }
744744 objid_query -> vars [objid_query -> count ].type = ptype ;
745745 idx_type ++ ;
746746 } else {
747- zend_argument_value_error (type_argument_offset , "must contain a type for object ID '%s'" , ZSTR_VAL (tmp ));
747+ zend_argument_value_error (type_arg_num , "must contain a type for object ID '%s'" , ZSTR_VAL (tmp ));
748748 php_free_objid_query (objid_query , oid_ht , value_ht , st );
749749 return false;
750750 }
@@ -779,7 +779,7 @@ static bool php_snmp_parse_oid(
779779 objid_query -> vars [objid_query -> count ].value = ZSTR_VAL (tmp );
780780 idx_value ++ ;
781781 } else {
782- zend_argument_value_error (value_argument_offset , "must contain a value for object ID '%s'" , ZSTR_VAL (tmp ));
782+ zend_argument_value_error (value_arg_num , "must contain a value for object ID '%s'" , ZSTR_VAL (tmp ));
783783 php_free_objid_query (objid_query , oid_ht , value_ht , st );
784784 return false;
785785 }
@@ -826,7 +826,7 @@ static bool php_snmp_parse_oid(
826826/* {{{ snmp_session_init
827827 allocates memory for session and session->peername, caller should free it manually using snmp_session_free() and efree()
828828*/
829- static bool snmp_session_init (php_snmp_session * * session_p , int version , zend_string * hostname , zend_string * community , zend_long timeout , zend_long retries , int hostname_argument_offset , int timeout_argument_offset )
829+ static bool snmp_session_init (php_snmp_session * * session_p , int version , zend_string * hostname , zend_string * community , zend_long timeout , zend_long retries , uint32_t hostname_arg_num , uint32_t timeout_arg_num )
830830{
831831 php_snmp_session * session ;
832832 char * pptr , * host_ptr ;
@@ -841,23 +841,23 @@ static bool snmp_session_init(php_snmp_session **session_p, int version, zend_st
841841 ZEND_ASSERT (community != NULL );
842842
843843 if (ZSTR_LEN (hostname ) >= MAX_NAME_LEN ) {
844- zend_argument_value_error (hostname_argument_offset , "length must be lower than %d" , MAX_NAME_LEN );
844+ zend_argument_value_error (hostname_arg_num , "length must be lower than %d" , MAX_NAME_LEN );
845845 return false;
846846 }
847847
848848 if (ZSTR_LEN (community ) == 0 ) {
849- zend_argument_must_not_be_empty_error (hostname_argument_offset + 1 );
849+ zend_argument_must_not_be_empty_error (hostname_arg_num + 1 );
850850 return false;
851851 }
852852
853- if (timeout_argument_offset != -1 ) {
853+ if (timeout_arg_num != 0 ) {
854854 if (timeout < -1 || timeout > LONG_MAX ) {
855- zend_argument_value_error (timeout_argument_offset , "must be between -1 and %ld" , LONG_MAX );
855+ zend_argument_value_error (timeout_arg_num , "must be between -1 and %ld" , LONG_MAX );
856856 return false;
857857 }
858858
859859 if (retries < -1 || retries > INT_MAX ) {
860- zend_argument_value_error (timeout_argument_offset + 1 , "must be between -1 and %d" , INT_MAX );
860+ zend_argument_value_error (timeout_arg_num + 1 , "must be between -1 and %d" , INT_MAX );
861861 return false;
862862 }
863863 }
@@ -888,22 +888,22 @@ static bool snmp_session_init(php_snmp_session **session_p, int version, zend_st
888888 char * pport = pptr + 2 ;
889889 tmp_port = atoi (pport );
890890 if (tmp_port < 0 || tmp_port > USHRT_MAX ) {
891- zend_argument_value_error (hostname_argument_offset , "remote port must be between 0 and %u" , USHRT_MAX );
891+ zend_argument_value_error (hostname_arg_num , "remote port must be between 0 and %u" , USHRT_MAX );
892892 return false;
893893 }
894894 remote_port = (unsigned short )tmp_port ;
895895 }
896896 * pptr = '\0' ;
897897 } else {
898- zend_argument_value_error (hostname_argument_offset , "has a malformed IPv6 address, closing square bracket missing" );
898+ zend_argument_value_error (hostname_arg_num , "has a malformed IPv6 address, closing square bracket missing" );
899899 return false;
900900 }
901901 } else { /* IPv4 address */
902902 if ((pptr = strchr (host_ptr , ':' ))) {
903903 char * pport = pptr + 1 ;
904904 tmp_port = atoi (pport );
905905 if (tmp_port < 0 || tmp_port > USHRT_MAX ) {
906- zend_argument_value_error (hostname_argument_offset , "remote port must be between 0 and %u" , USHRT_MAX );
906+ zend_argument_value_error (hostname_arg_num , "remote port must be between 0 and %u" , USHRT_MAX );
907907 return false;
908908 }
909909 remote_port = (unsigned short )tmp_port ;
@@ -1112,13 +1112,13 @@ static ZEND_ATTRIBUTE_NONNULL bool snmp_session_gen_sec_key(struct snmp_session
11121112/* }}} */
11131113
11141114/* {{{ Set context Engine Id in the snmpv3 session */
1115- static bool snmp_session_set_contextEngineID (struct snmp_session * s , zend_string * contextEngineID , uint32_t contextEngineID_argument_offset )
1115+ static bool snmp_session_set_contextEngineID (struct snmp_session * s , zend_string * contextEngineID , uint32_t context_engine_id_arg_num )
11161116{
11171117 size_t ebuf_len = 32 , eout_len = 0 ;
11181118 uint8_t * ebuf = (uint8_t * ) emalloc (ebuf_len );
11191119
11201120 if (!snmp_hex_to_binary (& ebuf , & ebuf_len , & eout_len , 1 , ZSTR_VAL (contextEngineID ))) {
1121- zend_argument_value_error (contextEngineID_argument_offset , "must be a valid context engine ID" );
1121+ zend_argument_value_error (context_engine_id_arg_num , "must be a valid context engine ID" );
11221122 efree (ebuf );
11231123 return false;
11241124 }
@@ -1134,13 +1134,13 @@ static bool snmp_session_set_contextEngineID(struct snmp_session *s, zend_string
11341134/* }}} */
11351135
11361136/* {{{ Set all snmpv3-related security options
1137- * auth_protocol_argnum and contextEngineID_argument_offset are the userland
1137+ * auth_protocol_arg_num and context_engine_id_arg_num are the userland
11381138 * argument numbers used for error reporting.
11391139 */
11401140static ZEND_ATTRIBUTE_NONNULL_ARGS (2 ) bool snmp_session_set_security (struct snmp_session * session , zend_string * sec_level ,
11411141 zend_string * auth_protocol , zend_string * auth_passphrase , zend_string * priv_protocol ,
11421142 zend_string * priv_passphrase , zend_string * contextName , zend_string * contextEngineID ,
1143- uint32_t auth_protocol_argnum , uint32_t contextEngineID_argument_offset )
1143+ uint32_t auth_protocol_arg_num , uint32_t context_engine_id_arg_num )
11441144{
11451145
11461146 /* Setting the security level. */
@@ -1152,7 +1152,7 @@ static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool snmp_session_set_security(struct snmp
11521152 if (session -> securityLevel == SNMP_SEC_LEVEL_AUTHNOPRIV || session -> securityLevel == SNMP_SEC_LEVEL_AUTHPRIV ) {
11531153
11541154 if (!auth_protocol ) {
1155- zend_argument_value_error (auth_protocol_argnum , "cannot be null when security level is \"authNoPriv\" or \"authPriv\"" );
1155+ zend_argument_value_error (auth_protocol_arg_num , "cannot be null when security level is \"authNoPriv\" or \"authPriv\"" );
11561156 return false;
11571157 }
11581158
@@ -1163,7 +1163,7 @@ static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool snmp_session_set_security(struct snmp
11631163 }
11641164
11651165 if (!auth_passphrase ) {
1166- zend_argument_value_error (auth_protocol_argnum + 1 , "cannot be null when security level is \"authNoPriv\" or \"authPriv\"" );
1166+ zend_argument_value_error (auth_protocol_arg_num + 1 , "cannot be null when security level is \"authNoPriv\" or \"authPriv\"" );
11671167 return false;
11681168 }
11691169
@@ -1176,7 +1176,7 @@ static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool snmp_session_set_security(struct snmp
11761176 if (session -> securityLevel == SNMP_SEC_LEVEL_AUTHPRIV ) {
11771177
11781178 if (!priv_protocol ) {
1179- zend_argument_value_error (auth_protocol_argnum + 2 , "cannot be null when security level is \"authPriv\"" );
1179+ zend_argument_value_error (auth_protocol_arg_num + 2 , "cannot be null when security level is \"authPriv\"" );
11801180 return false;
11811181 }
11821182
@@ -1187,7 +1187,7 @@ static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool snmp_session_set_security(struct snmp
11871187 }
11881188
11891189 if (!priv_passphrase ) {
1190- zend_argument_value_error (auth_protocol_argnum + 3 , "cannot be null when security level is \"authPriv\"" );
1190+ zend_argument_value_error (auth_protocol_arg_num + 3 , "cannot be null when security level is \"authPriv\"" );
11911191 return false;
11921192 }
11931193
@@ -1206,7 +1206,7 @@ static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool snmp_session_set_security(struct snmp
12061206 }
12071207
12081208 /* Setting contextEngineIS if specified */
1209- if (contextEngineID && ZSTR_LEN (contextEngineID ) && !snmp_session_set_contextEngineID (session , contextEngineID , contextEngineID_argument_offset )) {
1209+ if (contextEngineID && ZSTR_LEN (contextEngineID ) && !snmp_session_set_contextEngineID (session , contextEngineID , context_engine_id_arg_num )) {
12101210 /* Warning message sent already, just bail out */
12111211 return false;
12121212 }
@@ -1226,15 +1226,17 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
12261226{
12271227 zend_string * oid_str , * type_str = NULL , * value_str = NULL ;
12281228 HashTable * oid_ht , * type_ht = NULL , * value_ht = NULL ;
1229- zend_string * a1 = NULL , * a2 = NULL , * a3 = NULL , * a4 = NULL , * a5 = NULL , * a6 = NULL , * a7 = NULL ;
1229+ zend_string * hostname = NULL , * community_or_security_name = NULL ;
1230+ zend_string * security_level = NULL , * auth_protocol = NULL , * auth_passphrase = NULL ;
1231+ zend_string * privacy_protocol = NULL , * privacy_passphrase = NULL ;
12301232 bool use_orignames = 0 , suffix_keys = 0 ;
12311233 zend_long timeout = SNMP_DEFAULT_TIMEOUT ;
12321234 zend_long retries = SNMP_DEFAULT_RETRIES ;
12331235 struct objid_query objid_query ;
12341236 php_snmp_session * session ;
12351237 int session_less_mode = (getThis () == NULL );
1236- int timeout_argument_offset = -1 ;
1237- uint32_t oid_argument_offset = 1 , type_argument_offset = 0 , value_argument_offset = 0 ;
1238+ uint32_t timeout_arg_num = 0 ;
1239+ uint32_t oid_arg_num = 1 , type_arg_num = 0 , value_arg_num = 0 ;
12381240 php_snmp_object * snmp_object ;
12391241 php_snmp_object glob_snmp_object ;
12401242
@@ -1247,13 +1249,13 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
12471249 if (version == SNMP_VERSION_3 ) {
12481250 if (st & SNMP_CMD_SET ) {
12491251 ZEND_PARSE_PARAMETERS_START (10 , 12 )
1250- Z_PARAM_PATH_STR (a1 )
1251- Z_PARAM_PATH_STR (a2 )
1252- Z_PARAM_STR (a3 )
1253- Z_PARAM_STR (a4 )
1254- Z_PARAM_STR (a5 )
1255- Z_PARAM_STR (a6 )
1256- Z_PARAM_STR (a7 )
1252+ Z_PARAM_PATH_STR (hostname )
1253+ Z_PARAM_PATH_STR (community_or_security_name )
1254+ Z_PARAM_STR (security_level )
1255+ Z_PARAM_STR (auth_protocol )
1256+ Z_PARAM_STR (auth_passphrase )
1257+ Z_PARAM_STR (privacy_protocol )
1258+ Z_PARAM_STR (privacy_passphrase )
12571259 Z_PARAM_ARRAY_HT_OR_STR (oid_ht , oid_str )
12581260 Z_PARAM_ARRAY_HT_OR_STR (type_ht , type_str )
12591261 Z_PARAM_ARRAY_HT_OR_STR (value_ht , value_str )
@@ -1262,37 +1264,37 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
12621264 Z_PARAM_LONG (retries )
12631265 ZEND_PARSE_PARAMETERS_END ();
12641266
1265- timeout_argument_offset = 10 ;
1266- oid_argument_offset = 8 ;
1267- type_argument_offset = 9 ;
1268- value_argument_offset = 10 ;
1267+ timeout_arg_num = 10 ;
1268+ oid_arg_num = 8 ;
1269+ type_arg_num = 9 ;
1270+ value_arg_num = 10 ;
12691271 } else {
12701272 /* SNMP_CMD_GET
12711273 * SNMP_CMD_GETNEXT
12721274 * SNMP_CMD_WALK
12731275 */
12741276 ZEND_PARSE_PARAMETERS_START (8 , 10 )
1275- Z_PARAM_PATH_STR (a1 )
1276- Z_PARAM_PATH_STR (a2 )
1277- Z_PARAM_STR (a3 )
1278- Z_PARAM_STR (a4 )
1279- Z_PARAM_STR (a5 )
1280- Z_PARAM_STR (a6 )
1281- Z_PARAM_STR (a7 )
1277+ Z_PARAM_PATH_STR (hostname )
1278+ Z_PARAM_PATH_STR (community_or_security_name )
1279+ Z_PARAM_STR (security_level )
1280+ Z_PARAM_STR (auth_protocol )
1281+ Z_PARAM_STR (auth_passphrase )
1282+ Z_PARAM_STR (privacy_protocol )
1283+ Z_PARAM_STR (privacy_passphrase )
12821284 Z_PARAM_ARRAY_HT_OR_STR (oid_ht , oid_str )
12831285 Z_PARAM_OPTIONAL
12841286 Z_PARAM_LONG (timeout )
12851287 Z_PARAM_LONG (retries )
12861288 ZEND_PARSE_PARAMETERS_END ();
12871289
1288- timeout_argument_offset = 9 ;
1289- oid_argument_offset = 8 ;
1290+ timeout_arg_num = 9 ;
1291+ oid_arg_num = 8 ;
12901292 }
12911293 } else {
12921294 if (st & SNMP_CMD_SET ) {
12931295 ZEND_PARSE_PARAMETERS_START (5 , 7 )
1294- Z_PARAM_PATH_STR (a1 )
1295- Z_PARAM_PATH_STR (a2 )
1296+ Z_PARAM_PATH_STR (hostname )
1297+ Z_PARAM_PATH_STR (community_or_security_name )
12961298 Z_PARAM_ARRAY_HT_OR_STR (oid_ht , oid_str )
12971299 Z_PARAM_ARRAY_HT_OR_STR (type_ht , type_str )
12981300 Z_PARAM_ARRAY_HT_OR_STR (value_ht , value_str )
@@ -1301,26 +1303,26 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
13011303 Z_PARAM_LONG (retries )
13021304 ZEND_PARSE_PARAMETERS_END ();
13031305
1304- timeout_argument_offset = 6 ;
1305- oid_argument_offset = 3 ;
1306- type_argument_offset = 4 ;
1307- value_argument_offset = 5 ;
1306+ timeout_arg_num = 6 ;
1307+ oid_arg_num = 3 ;
1308+ type_arg_num = 4 ;
1309+ value_arg_num = 5 ;
13081310 } else {
13091311 /* SNMP_CMD_GET
13101312 * SNMP_CMD_GETNEXT
13111313 * SNMP_CMD_WALK
13121314 */
13131315 ZEND_PARSE_PARAMETERS_START (3 , 5 )
1314- Z_PARAM_PATH_STR (a1 )
1315- Z_PARAM_PATH_STR (a2 )
1316+ Z_PARAM_PATH_STR (hostname )
1317+ Z_PARAM_PATH_STR (community_or_security_name )
13161318 Z_PARAM_ARRAY_HT_OR_STR (oid_ht , oid_str )
13171319 Z_PARAM_OPTIONAL
13181320 Z_PARAM_LONG (timeout )
13191321 Z_PARAM_LONG (retries )
13201322 ZEND_PARSE_PARAMETERS_END ();
13211323
1322- timeout_argument_offset = 4 ;
1323- oid_argument_offset = 3 ;
1324+ timeout_arg_num = 4 ;
1325+ oid_arg_num = 3 ;
13241326 }
13251327 }
13261328 } else {
@@ -1330,8 +1332,8 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
13301332 Z_PARAM_ARRAY_HT_OR_STR (type_ht , type_str )
13311333 Z_PARAM_ARRAY_HT_OR_STR (value_ht , value_str )
13321334 ZEND_PARSE_PARAMETERS_END ();
1333- type_argument_offset = 2 ;
1334- value_argument_offset = 3 ;
1335+ type_arg_num = 2 ;
1336+ value_arg_num = 3 ;
13351337 } else if (st & SNMP_CMD_WALK ) {
13361338 ZEND_PARSE_PARAMETERS_START (1 , 4 )
13371339 Z_PARAM_ARRAY_HT_OR_STR (oid_ht , oid_str )
@@ -1362,17 +1364,17 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
13621364 }
13631365
13641366 if (!php_snmp_parse_oid (getThis (), st , & objid_query , oid_str , oid_ht , type_str , type_ht , value_str , value_ht ,
1365- oid_argument_offset , type_argument_offset , value_argument_offset )) {
1367+ oid_arg_num , type_arg_num , value_arg_num )) {
13661368 RETURN_FALSE ;
13671369 }
13681370
13691371 if (session_less_mode ) {
1370- if (!snmp_session_init (& session , version , a1 , a2 , timeout , retries , 1 , timeout_argument_offset )) {
1372+ if (!snmp_session_init (& session , version , hostname , community_or_security_name , timeout , retries , 1 , timeout_arg_num )) {
13711373 php_free_objid_query (& objid_query , oid_ht , value_ht , st );
13721374 snmp_session_free (& session );
13731375 RETURN_FALSE ;
13741376 }
1375- if (version == SNMP_VERSION_3 && !snmp_session_set_security (session , a3 , a4 , a5 , a6 , a7 , NULL , NULL , 4 , 0 )) {
1377+ if (version == SNMP_VERSION_3 && !snmp_session_set_security (session , security_level , auth_protocol , auth_passphrase , privacy_protocol , privacy_passphrase , NULL , NULL , 4 , 0 )) {
13761378 php_free_objid_query (& objid_query , oid_ht , value_ht , st );
13771379 snmp_session_free (& session );
13781380 /* An error has already been emitted, just bail out. */
@@ -1729,20 +1731,23 @@ PHP_METHOD(SNMP, setSecurity)
17291731{
17301732 php_snmp_object * snmp_object ;
17311733 zval * object = ZEND_THIS ;
1732- zend_string * a1 = NULL , * a2 = NULL , * a3 = NULL , * a4 = NULL , * a5 = NULL , * a6 = NULL , * a7 = NULL ;
1734+ zend_string * security_level = NULL , * auth_protocol = NULL , * auth_passphrase = NULL ;
1735+ zend_string * privacy_protocol = NULL , * privacy_passphrase = NULL ;
1736+ zend_string * context_name = NULL , * context_engine_id = NULL ;
1737+ uint32_t auth_protocol_arg_num = 2 ;
1738+ uint32_t context_engine_id_arg_num = 7 ;
17331739
17341740 snmp_object = Z_SNMP_P (object );
17351741 if (!snmp_object -> session ) {
17361742 zend_throw_error (NULL , "Invalid or uninitialized SNMP object" );
17371743 RETURN_THROWS ();
17381744 }
17391745
1740- if (zend_parse_parameters (ZEND_NUM_ARGS (), "S|SSSSSS" , & a1 , & a2 , & a3 , & a4 , & a5 , & a6 , & a7 ) == FAILURE ) {
1746+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "S|SSSSSS" , & security_level , & auth_protocol , & auth_passphrase , & privacy_protocol , & privacy_passphrase , & context_name , & context_engine_id ) == FAILURE ) {
17411747 RETURN_THROWS ();
17421748 }
17431749
1744- /* authProtocol is argument #2 and contextEngineId is argument #7. */
1745- if (!snmp_session_set_security (snmp_object -> session , a1 , a2 , a3 , a4 , a5 , a6 , a7 , 2 , 7 )) {
1750+ if (!snmp_session_set_security (snmp_object -> session , security_level , auth_protocol , auth_passphrase , privacy_protocol , privacy_passphrase , context_name , context_engine_id , auth_protocol_arg_num , context_engine_id_arg_num )) {
17461751 /* An error has already been emitted, just bail out. */
17471752 RETURN_FALSE ;
17481753 }
0 commit comments