summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Peter Banyard <girgias@php.net>2020-09-08 16:59:35 +0200
committerGeorge Peter Banyard <girgias@php.net>2020-09-15 13:08:07 +0200
commit62c20c662a961f030178a15311bfe37591c10316 (patch)
treef182569d4789ae8ef9ce0ce8c2d0e2bd6be40ddf
parent1a8936cde3a14a1fdcd0f2a4cd567e5a3e206e65 (diff)
downloadphp-git-62c20c662a961f030178a15311bfe37591c10316.tar.gz
Promote warnings to Error in SNMP extension
-rw-r--r--ext/snmp/snmp.c99
-rw-r--r--ext/snmp/tests/snmp-object-error.phpt44
-rw-r--r--ext/snmp/tests/snmp-object-properties.phpt44
-rw-r--r--ext/snmp/tests/snmp-object-setSecurity_error.phpt43
-rw-r--r--ext/snmp/tests/snmp2_get.phpt10
-rw-r--r--ext/snmp/tests/snmp2_set.phpt73
-rw-r--r--ext/snmp/tests/snmp3-error.phpt54
-rw-r--r--ext/snmp/tests/snmp_get_valueretrieval.phpt10
-rw-r--r--ext/snmp/tests/snmp_set_oid_output_format.phpt12
-rw-r--r--ext/snmp/tests/snmpset.phpt60
10 files changed, 265 insertions, 184 deletions
diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c
index b0ad6cf47e..5eb8d0b338 100644
--- a/ext/snmp/snmp.c
+++ b/ext/snmp/snmp.c
@@ -659,7 +659,6 @@ retry:
*
* OID parser (and type, value for SNMP_SET command)
*/
-
static int php_snmp_parse_oid(
zval *object, int st, struct objid_query *objid_query, zend_string *oid_str, HashTable *oid_ht,
zend_string *type_str, HashTable *type_ht, zend_string *value_str, HashTable *value_ht
@@ -674,25 +673,33 @@ static int php_snmp_parse_oid(
objid_query->vars = (snmpobjarg *)emalloc(sizeof(snmpobjarg));
objid_query->vars[objid_query->count].oid = ZSTR_VAL(oid_str);
if (st & SNMP_CMD_SET) {
- if (type_str && value_str) {
- if (ZSTR_LEN(type_str) != 1) {
- php_error_docref(NULL, E_WARNING, "Bogus type '%s', should be single char, got %zu", ZSTR_VAL(type_str), ZSTR_LEN(type_str));
- efree(objid_query->vars);
- return FALSE;
- }
- pptr = ZSTR_VAL(type_str);
- objid_query->vars[objid_query->count].type = *pptr;
- objid_query->vars[objid_query->count].value = ZSTR_VAL(value_str);
- } else {
- php_error_docref(NULL, E_WARNING, "Single objid and multiple type or values are not supported");
+ if (type_ht) {
+ zend_type_error("Type must be of type string when object ID is a string");
+ efree(objid_query->vars);
+ return FALSE;
+ }
+ if (value_ht) {
+ zend_type_error("Value must be of type string when object ID is a string");
efree(objid_query->vars);
return FALSE;
}
+
+ /* Both type and value must be valid strings */
+ ZEND_ASSERT(type_str && value_str);
+
+ if (ZSTR_LEN(type_str) != 1) {
+ zend_value_error("Type must be a single character");
+ efree(objid_query->vars);
+ return FALSE;
+ }
+ pptr = ZSTR_VAL(type_str);
+ objid_query->vars[objid_query->count].type = *pptr;
+ objid_query->vars[objid_query->count].value = ZSTR_VAL(value_str);
}
objid_query->count++;
} else if (oid_ht) { /* we got objid array */
if (zend_hash_num_elements(oid_ht) == 0) {
- php_error_docref(NULL, E_WARNING, "Got empty OID array");
+ zend_value_error("Array of object IDs cannot be empty");
return FALSE;
}
objid_query->vars = (snmpobjarg *)safe_emalloc(sizeof(snmpobjarg), zend_hash_num_elements(oid_ht), 0);
@@ -715,7 +722,7 @@ static int php_snmp_parse_oid(
if (idx_type < type_ht->nNumUsed) {
convert_to_string_ex(tmp_type);
if (Z_STRLEN_P(tmp_type) != 1) {
- php_error_docref(NULL, E_WARNING, "'%s': bogus type '%s', should be single char, got %zu", Z_STRVAL_P(tmp_oid), Z_STRVAL_P(tmp_type), Z_STRLEN_P(tmp_type));
+ zend_value_error("Type must be a single character");
efree(objid_query->vars);
return FALSE;
}
@@ -916,6 +923,7 @@ static int netsnmp_session_set_sec_level(struct snmp_session *s, char *level)
} else if (!strcasecmp(level, "authPriv") || !strcasecmp(level, "ap")) {
s->securityLevel = SNMP_SEC_LEVEL_AUTHPRIV;
} else {
+ zend_value_error("Security level must be one of \"noAuthNoPriv\", \"authNoPriv\", or \"authPriv\"");
return (-1);
}
return (0);
@@ -933,7 +941,7 @@ static int netsnmp_session_set_auth_protocol(struct snmp_session *s, char *prot)
s->securityAuthProto = usmHMACSHA1AuthProtocol;
s->securityAuthProtoLen = USM_AUTH_PROTO_SHA_LEN;
} else {
- php_error_docref(NULL, E_WARNING, "Unknown authentication protocol '%s'", prot);
+ zend_value_error("Authentication protocol must be either MD5 or SHA");
return (-1);
}
return (0);
@@ -953,7 +961,11 @@ static int netsnmp_session_set_sec_protocol(struct snmp_session *s, char *prot)
s->securityPrivProtoLen = USM_PRIV_PROTO_AES_LEN;
#endif
} else {
- php_error_docref(NULL, E_WARNING, "Unknown security protocol '%s'", prot);
+#ifdef HAVE_AES
+ zend_value_error("Security protocol must be one of DES, AES128, or AES");
+#else
+ zend_value_error("Security protocol must be DES");
+#endif
return (-1);
}
return (0);
@@ -987,7 +999,7 @@ static int netsnmp_session_gen_sec_key(struct snmp_session *s, char *pass)
(u_char *)pass, strlen(pass),
s->securityPrivKey, &(s->securityPrivKeyLen)))) {
php_error_docref(NULL, E_WARNING, "Error generating a key for privacy pass phrase '%s': %s", pass, snmp_api_errstring(snmp_errno));
- return (-2);
+ return (-1);
}
return (0);
}
@@ -1001,6 +1013,7 @@ static int netsnmp_session_set_contextEngineID(struct snmp_session *s, char * co
u_char *ebuf = (u_char *) emalloc(ebuf_len);
if (!snmp_hex_to_binary(&ebuf, &ebuf_len, &eout_len, 1, contextEngineID)) {
+ // TODO Promote to Error?
php_error_docref(NULL, E_WARNING, "Bad engine ID value '%s'", contextEngineID);
efree(ebuf);
return (-1);
@@ -1023,7 +1036,7 @@ static int netsnmp_session_set_security(struct snmp_session *session, char *sec_
/* Setting the security level. */
if (netsnmp_session_set_sec_level(session, sec_level)) {
- php_error_docref(NULL, E_WARNING, "Invalid security level '%s'", sec_level);
+ /* ValueError already generated, just bail out */
return (-1);
}
@@ -1031,7 +1044,7 @@ static int netsnmp_session_set_security(struct snmp_session *session, char *sec_
/* Setting the authentication protocol. */
if (netsnmp_session_set_auth_protocol(session, auth_protocol)) {
- /* Warning message sent already, just bail out */
+ /* ValueError already generated, just bail out */
return (-1);
}
@@ -1044,7 +1057,7 @@ static int netsnmp_session_set_security(struct snmp_session *session, char *sec_
if (session->securityLevel == SNMP_SEC_LEVEL_AUTHPRIV) {
/* Setting the security protocol. */
if (netsnmp_session_set_sec_protocol(session, priv_protocol)) {
- /* Warning message sent already, just bail out */
+ /* ValueError already generated, just bail out */
return (-1);
}
@@ -1220,9 +1233,9 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
snmp_object = Z_SNMP_P(object);
session = snmp_object->session;
if (!session) {
- php_error_docref(NULL, E_WARNING, "Invalid or uninitialized SNMP object");
+ zend_throw_error(NULL, "Invalid or uninitialized SNMP object");
efree(objid_query.vars);
- RETURN_FALSE;
+ RETURN_THROWS();
}
if (snmp_object->max_oids > 0) {
@@ -1351,11 +1364,9 @@ PHP_FUNCTION(snmp_set_oid_output_format)
case NETSNMP_OID_OUTPUT_NONE:
netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, a1);
RETURN_TRUE;
- break;
default:
- php_error_docref(NULL, E_WARNING, "Unknown SNMP output print format '%d'", (int) a1);
- RETURN_FALSE;
- break;
+ zend_argument_value_error(1, "must be an SNMP_OID_OUTPUT_* constant");
+ RETURN_THROWS();
}
}
/* }}} */
@@ -1443,8 +1454,8 @@ PHP_FUNCTION(snmp_set_valueretrieval)
SNMP_G(valueretrieval) = method;
RETURN_TRUE;
} else {
- php_error_docref(NULL, E_WARNING, "Unknown SNMP value retrieval method '" ZEND_LONG_FMT "'", method);
- RETURN_FALSE;
+ zend_argument_value_error(1, "must be a bitmask of SNMP_VALUE_LIBRARY, SNMP_VALUE_PLAIN, and SNMP_VALUE_OBJECT");
+ RETURN_THROWS();
}
}
/* }}} */
@@ -1827,7 +1838,7 @@ PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(exceptions_enabled)
/* {{{ */
static int php_snmp_write_info(php_snmp_object *snmp_object, zval *newval)
{
- php_error_docref(NULL, E_WARNING, "info property is read-only");
+ zend_throw_error(NULL, "SNMP::$info property is read-only");
return FAILURE;
}
/* }}} */
@@ -1835,40 +1846,38 @@ static int php_snmp_write_info(php_snmp_object *snmp_object, zval *newval)
/* {{{ */
static int php_snmp_write_max_oids(php_snmp_object *snmp_object, zval *newval)
{
- int ret = SUCCESS;
zend_long lval;
if (Z_TYPE_P(newval) == IS_NULL) {
snmp_object->max_oids = 0;
- return ret;
+ return SUCCESS;
}
lval = zval_get_long(newval);
- if (lval > 0) {
- snmp_object->max_oids = lval;
- } else {
- php_error_docref(NULL, E_WARNING, "max_oids should be positive integer or NULL, got " ZEND_LONG_FMT, lval);
+ if (lval <= 0) {
+ zend_value_error("max_oids must be greater than 0 or null");
+ return FAILURE;
}
+ snmp_object->max_oids = lval;
- return ret;
+ return SUCCESS;
}
/* }}} */
/* {{{ */
static int php_snmp_write_valueretrieval(php_snmp_object *snmp_object, zval *newval)
{
- int ret = SUCCESS;
zend_long lval = zval_get_long(newval);
if (lval >= 0 && lval <= (SNMP_VALUE_LIBRARY|SNMP_VALUE_PLAIN|SNMP_VALUE_OBJECT)) {
snmp_object->valueretrieval = lval;
} else {
- php_error_docref(NULL, E_WARNING, "Unknown SNMP value retrieval method '" ZEND_LONG_FMT "'", lval);
- ret = FAILURE;
+ zend_value_error("SNMP retrieval method must be a bitmask of SNMP_VALUE_LIBRARY, SNMP_VALUE_PLAIN, and SNMP_VALUE_OBJECT");
+ return FAILURE;
}
- return ret;
+ return SUCCESS;
}
/* }}} */
@@ -1892,7 +1901,6 @@ PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(oid_increasing_check)
/* {{{ */
static int php_snmp_write_oid_output_format(php_snmp_object *snmp_object, zval *newval)
{
- int ret = SUCCESS;
zend_long lval = zval_get_long(newval);
switch(lval) {
@@ -1903,14 +1911,11 @@ static int php_snmp_write_oid_output_format(php_snmp_object *snmp_object, zval *
case NETSNMP_OID_OUTPUT_UCD:
case NETSNMP_OID_OUTPUT_NONE:
snmp_object->oid_output_format = lval;
- break;
+ return SUCCESS;
default:
- php_error_docref(NULL, E_WARNING, "Unknown SNMP output print format '" ZEND_LONG_FMT "'", lval);
- ret = FAILURE;
- break;
+ zend_value_error("SNMP output print format must be an SNMP_OID_OUTPUT_* constant");
+ return FAILURE;
}
-
- return ret;
}
/* }}} */
diff --git a/ext/snmp/tests/snmp-object-error.phpt b/ext/snmp/tests/snmp-object-error.phpt
index a1268e4b4c..b170f9a083 100644
--- a/ext/snmp/tests/snmp-object-error.phpt
+++ b/ext/snmp/tests/snmp-object-error.phpt
@@ -54,18 +54,35 @@ var_dump($session->close());
echo "Open normal session\n";
$session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries);
-$session->valueretrieval = 67;
-var_dump($session->valueretrieval);
+try {
+ $session->valueretrieval = 67;
+ var_dump($session->valueretrieval);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
echo "Closing session\n";
var_dump($session->close());
-var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
-var_dump($session->close());
+
+try {
+ var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
+ var_dump($session->close());
+} catch (\Error $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
var_dump($session->max_oids);
-$session->max_oids = "ttt";
-$session->max_oids = 0;
+try {
+ $session->max_oids = "ttt";
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ $session->max_oids = 0;
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
var_dump($session->max_oids);
?>
--EXPECTF--
@@ -81,18 +98,11 @@ int(32)
string(46) "Invalid object identifier: .1.3.6.1.2.1.1.1..0"
bool(true)
Open normal session
-
-Warning: main(): Unknown SNMP value retrieval method '67' in %s on line %d
-int(%d)
+SNMP retrieval method must be a bitmask of SNMP_VALUE_LIBRARY, SNMP_VALUE_PLAIN, and SNMP_VALUE_OBJECT
Closing session
bool(true)
-
-Warning: SNMP::get(): Invalid or uninitialized SNMP object in %s on line %d
-bool(false)
-bool(true)
+Invalid or uninitialized SNMP object
NULL
-
-Warning: main(): max_oids should be positive integer or NULL, got 0 in %s on line %d
-
-Warning: main(): max_oids should be positive integer or NULL, got 0 in %s on line %d
+max_oids must be greater than 0 or null
+max_oids must be greater than 0 or null
NULL
diff --git a/ext/snmp/tests/snmp-object-properties.phpt b/ext/snmp/tests/snmp-object-properties.phpt
index aa1bbdec2f..47c6dc6638 100644
--- a/ext/snmp/tests/snmp-object-properties.phpt
+++ b/ext/snmp/tests/snmp-object-properties.phpt
@@ -54,13 +54,24 @@ $param = 'there is no such parameter';
var_dump($session->$param);
var_dump(property_exists($session, $param));
-$session->valueretrieval = 67;
-var_dump($session->valueretrieval);
-$session->oid_output_format = 78;
-var_dump($session->oid_output_format);
-
-$session->info = array("blah" => 2);
-var_dump($session->info);
+try {
+ $session->valueretrieval = 67;
+ var_dump($session->valueretrieval);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ $session->oid_output_format = 78;
+ var_dump($session->oid_output_format);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ $session->info = array("blah" => 2);
+ var_dump($session->info);
+} catch (\Error $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
$session->max_oids = NULL;
var_dump($session->max_oids);
@@ -179,20 +190,7 @@ Error handling
Warning: Undefined property: SNMP::$there is no such parameter in %s on line %d
NULL
bool(false)
-
-Warning: main(): Unknown SNMP value retrieval method '67' in %s on line %d
-int(1)
-
-Warning: main(): Unknown SNMP output print format '78' in %s on line %d
-int(3)
-
-Warning: main(): info property is read-only in %s on line %d
-array(3) {
- ["hostname"]=>
- string(%d) "%s"
- ["timeout"]=>
- int(%i)
- ["retries"]=>
- int(%d)
-}
+SNMP retrieval method must be a bitmask of SNMP_VALUE_LIBRARY, SNMP_VALUE_PLAIN, and SNMP_VALUE_OBJECT
+SNMP output print format must be an SNMP_OID_OUTPUT_* constant
+SNMP::$info property is read-only
NULL
diff --git a/ext/snmp/tests/snmp-object-setSecurity_error.phpt b/ext/snmp/tests/snmp-object-setSecurity_error.phpt
index 819642d957..b0bf03bd3d 100644
--- a/ext/snmp/tests/snmp-object-setSecurity_error.phpt
+++ b/ext/snmp/tests/snmp-object-setSecurity_error.phpt
@@ -18,12 +18,37 @@ $session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries
$session->setSecurity('noAuthNoPriv');
#echo "Checking error handling\n";
+
+try {
var_dump($session->setSecurity(''));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
var_dump($session->setSecurity('bugusPriv'));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
var_dump($session->setSecurity('authNoPriv', 'TTT'));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
var_dump($session->setSecurity('authNoPriv', 'MD5', ''));
var_dump($session->setSecurity('authNoPriv', 'MD5', 'te'));
-var_dump($session->setSecurity('authPriv', 'MD5', $auth_pass, 'BBB'));
+
+try {
+ var_dump(snmp3_get($hostname, $community, 'authPriv', 'MD5', $auth_pass, 'BBB', '', '.1.3.6.1.2.1.1.1.0'));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump($session->setSecurity('authPriv', 'MD5', $auth_pass, 'BBB'));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
var_dump($session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', ''));
var_dump($session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', 'ty'));
var_dump($session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', 'test12345', 'context', 'dsa'));
@@ -32,23 +57,17 @@ var_dump($session->close());
?>
--EXPECTF--
-Warning: SNMP::setSecurity(): Invalid security level '' in %s on line %d
-bool(false)
-
-Warning: SNMP::setSecurity(): Invalid security level 'bugusPriv' in %s on line %d
-bool(false)
-
-Warning: SNMP::setSecurity(): Unknown authentication protocol 'TTT' in %s on line %d
-bool(false)
+Security level must be one of "noAuthNoPriv", "authNoPriv", or "authPriv"
+Security level must be one of "noAuthNoPriv", "authNoPriv", or "authPriv"
+Authentication protocol must be either MD5 or SHA
Warning: SNMP::setSecurity(): Error generating a key for authentication pass phrase '': Generic error (The supplied password length is too short.) in %s on line %d
bool(false)
Warning: SNMP::setSecurity(): Error generating a key for authentication pass phrase 'te': Generic error (The supplied password length is too short.) in %s on line %d
bool(false)
-
-Warning: SNMP::setSecurity(): Unknown security protocol 'BBB' in %s on line %d
-bool(false)
+Security protocol must be one of DES, AES128, or AES
+Security protocol must be one of DES, AES128, or AES
Warning: SNMP::setSecurity(): Error generating a key for privacy pass phrase '': Generic error (The supplied password length is too short.) in %s on line %d
bool(false)
diff --git a/ext/snmp/tests/snmp2_get.phpt b/ext/snmp/tests/snmp2_get.phpt
index 05892d1e6b..92d52d8f0f 100644
--- a/ext/snmp/tests/snmp2_get.phpt
+++ b/ext/snmp/tests/snmp2_get.phpt
@@ -16,7 +16,11 @@ snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
echo "Checking error handling\n";
echo "Empty OID array\n";
-var_dump(snmp2_get($hostname, $community, array(), $timeout, $retries));
+try {
+ var_dump(snmp2_get($hostname, $community, array(), $timeout, $retries));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
echo "Checking working\n";
echo "Single OID\n";
@@ -47,9 +51,7 @@ var_dump(snmp2_get($hostname, $community, array('.1.3.6.1.2.1.1.1.0', '.1.3.6.1.
--EXPECTF--
Checking error handling
Empty OID array
-
-Warning: snmp2_get(): Got empty OID array in %s on line %d
-bool(false)
+Array of object IDs cannot be empty
Checking working
Single OID
string(%d) "%s"
diff --git a/ext/snmp/tests/snmp2_set.phpt b/ext/snmp/tests/snmp2_set.phpt
index 01c66d96f5..ea0581184e 100644
--- a/ext/snmp/tests/snmp2_set.phpt
+++ b/ext/snmp/tests/snmp2_set.phpt
@@ -16,8 +16,12 @@ snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
echo "Check error handing\n";
echo "No type & no value (timeout & retries instead)\n";
-$z = snmp2_set($hostname, $communityWrite, 'SNMPv2-MIB::sysLocation.0', $timeout, $retries);
-var_dump($z);
+try {
+ $z = snmp2_set($hostname, $communityWrite, 'SNMPv2-MIB::sysLocation.0', $timeout, $retries);
+ var_dump($z);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
echo "No value (timeout instead), retries instead of timeout\n";
$z = snmp2_set($hostname, $communityWrite, 'SNMPv2-MIB::sysLocation.0', 'q', $timeout, $retries);
@@ -39,6 +43,7 @@ echo "Single OID\n";
$z = snmp2_set($hostname, $communityWrite, $oid1, 's', $newvalue1, $timeout, $retries);
var_dump($z);
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $newvalue1));
+
$z = snmp2_set($hostname, $communityWrite, $oid1, 's', $oldvalue1, $timeout, $retries);
var_dump($z);
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
@@ -48,6 +53,10 @@ $z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('s','s'),
var_dump($z);
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $newvalue1));
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $newvalue2));
+
+$z = snmp2_set($hostname, $communityWrite, '.1.3.6.777.888.999.444.0', 's', 'bbb', $timeout, $retries);
+var_dump($z);
+
$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('s','s'), array($oldvalue1, $oldvalue2), $timeout, $retries);
var_dump($z);
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
@@ -58,44 +67,61 @@ $z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), 's', $newvalue1,
var_dump($z);
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $newvalue1));
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $newvalue1));
+
$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('s','s'), array($oldvalue1, $oldvalue2), $timeout, $retries);
var_dump($z);
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
-var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
+var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2 ));
echo "Multiple OID, single type, multiple value\n";
$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), 's', array($newvalue1, $newvalue2), $timeout, $retries);
var_dump($z);
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $newvalue1));
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $newvalue2));
+
$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('s','s'), array($oldvalue1, $oldvalue2), $timeout, $retries);
var_dump($z);
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
-
echo "More error handing\n";
echo "Single OID, single type in array, single value\n";
-$z = snmp2_set($hostname, $communityWrite, $oid1, array('s'), $newvalue1, $timeout, $retries);
-var_dump($z);
+try {
+ $z = snmp2_set($hostname, $communityWrite, $oid1, array('s'), $newvalue1, $timeout, $retries);
+ var_dump($z);
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
echo "Single OID, single type, single value in array\n";
-$z = snmp2_set($hostname, $communityWrite, $oid1, 's', array($newvalue1), $timeout, $retries);
-var_dump($z);
+try {
+ $z = snmp2_set($hostname, $communityWrite, $oid1, 's', array($newvalue1), $timeout, $retries);
+ var_dump($z);
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
echo "Multiple OID, 1st wrong type\n";
-$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('sw','s'), array($newvalue1, $newvalue2), $timeout, $retries);
-var_dump($z);
+try {
+ $z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('sw','s'), array($newvalue1, $newvalue2), $timeout, $retries);
+ var_dump($z);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
echo "Multiple OID, 2nd wrong type\n";
-$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('s','sb'), array($newvalue1, $newvalue2), $timeout, $retries);
-var_dump($z);
+try {
+ $z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('s','sb'), array($newvalue1, $newvalue2), $timeout, $retries);
+ var_dump($z);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
@@ -139,9 +165,7 @@ var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $ol
--EXPECTF--
Check error handing
No type & no value (timeout & retries instead)
-
-Warning: snmp2_set(): Bogus type '-1', should be single char, got 2 in %s on line %d
-bool(false)
+Type must be a single character
No value (timeout instead), retries instead of timeout
Warning: snmp2_set(): Could not add variable: OID='%s' type='q' value='%i': Bad variable type ("q") in %s on line %d
@@ -160,6 +184,9 @@ Multiple OID
bool(true)
bool(true)
bool(true)
+
+Warning: snmp2_set(): Error in packet at '%s': notWritable (That object does not support modification) in %s on line %d
+bool(false)
bool(true)
bool(true)
bool(true)
@@ -179,27 +206,19 @@ bool(true)
bool(true)
More error handing
Single OID, single type in array, single value
-
-Warning: snmp2_set(): Single objid and multiple type or values are not supported in %s on line %d
-bool(false)
+Type must be of type string when object ID is a string
bool(true)
bool(true)
Single OID, single type, single value in array
-
-Warning: snmp2_set(): Single objid and multiple type or values are not supported in %s on line %d
-bool(false)
+Value must be of type string when object ID is a string
bool(true)
bool(true)
Multiple OID, 1st wrong type
-
-Warning: snmp2_set(): '%s': bogus type 'sw', should be single char, got 2 in %s on line %d
-bool(false)
+Type must be a single character
bool(true)
bool(true)
Multiple OID, 2nd wrong type
-
-Warning: snmp2_set(): '%s': bogus type 'sb', should be single char, got 2 in %s on line %d
-bool(false)
+Type must be a single character
bool(true)
bool(true)
Multiple OID, single type in array, multiple value
diff --git a/ext/snmp/tests/snmp3-error.phpt b/ext/snmp/tests/snmp3-error.phpt
index cbebf69f62..7c07d13fa9 100644
--- a/ext/snmp/tests/snmp3-error.phpt
+++ b/ext/snmp/tests/snmp3-error.phpt
@@ -16,40 +16,56 @@ echo "Checking error handling\n";
// string auth_passphrase, string priv_protocol, string priv_passphrase,
// string object_id [, int timeout [, int retries]]);
-var_dump(snmp3_get($hostname, $community, '', '', '', '', '', '.1.3.6.1.2.1.1.1.0'));
-var_dump(snmp3_get($hostname, $community, 'bugusPriv', '', '', '', '', '.1.3.6.1.2.1.1.1.0'));
-var_dump(snmp3_get($hostname, $community, 'authNoPriv', 'TTT', '', '', '', '.1.3.6.1.2.1.1.1.0'));
+try {
+ var_dump(snmp3_get($hostname, $community, '', '', '', '', '', '.1.3.6.1.2.1.1.1.0'));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump(snmp3_get($hostname, $community, 'bugusPriv', '', '', '', '', '.1.3.6.1.2.1.1.1.0'));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump(snmp3_get($hostname, $community, 'authNoPriv', 'TTT', '', '', '', '.1.3.6.1.2.1.1.1.0'));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
var_dump(snmp3_get($hostname, $community, 'authNoPriv', 'MD5', '', '', '', '.1.3.6.1.2.1.1.1.0'));
var_dump(snmp3_get($hostname, $community, 'authNoPriv', 'MD5', 'te', '', '', '.1.3.6.1.2.1.1.1.0'));
-var_dump(snmp3_get($hostname, $community, 'authPriv', 'MD5', $auth_pass, 'BBB', '', '.1.3.6.1.2.1.1.1.0'));
+
+try {
+ var_dump(snmp3_get($hostname, $community, 'authPriv', 'MD5', $auth_pass, 'BBB', '', '.1.3.6.1.2.1.1.1.0'));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
var_dump(snmp3_get($hostname, $community, 'authPriv', 'MD5', $auth_pass, 'AES', '', '.1.3.6.1.2.1.1.1.0'));
var_dump(snmp3_get($hostname, $community, 'authPriv', 'MD5', $auth_pass, 'AES', 'ty', '.1.3.6.1.2.1.1.1.0'));
var_dump(snmp3_get($hostname, 'somebogususer', 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, '.1.3.6.1.2.1.1.1.0', $timeout, $retries));
var_dump(snmp3_set($hostname, $rwuser, 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, '.1.3.6.777...7.5.3', 's', 'ttt', $timeout, $retries));
-var_dump(snmp3_set($hostname, $rwuser, 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, '.1.3.6.777.7.5.3', array('s'), 'yyy', $timeout, $retries));
+
+try {
+ var_dump(snmp3_set($hostname, $rwuser, 'authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, '.1.3.6.777.7.5.3', array('s'), 'yyy', $timeout, $retries));
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
?>
--EXPECTF--
Checking error handling
-
-Warning: snmp3_get(): Invalid security level '' in %s on line %d
-bool(false)
-
-Warning: snmp3_get(): Invalid security level 'bugusPriv' in %s on line %d
-bool(false)
-
-Warning: snmp3_get(): Unknown authentication protocol 'TTT' in %s on line %d
-bool(false)
+Security level must be one of "noAuthNoPriv", "authNoPriv", or "authPriv"
+Security level must be one of "noAuthNoPriv", "authNoPriv", or "authPriv"
+Authentication protocol must be either MD5 or SHA
Warning: snmp3_get(): Error generating a key for authentication pass phrase '': Generic error (The supplied password length is too short.) in %s on line %d
bool(false)
Warning: snmp3_get(): Error generating a key for authentication pass phrase 'te': Generic error (The supplied password length is too short.) in %s on line %d
bool(false)
-
-Warning: snmp3_get(): Unknown security protocol 'BBB' in %s on line %d
-bool(false)
+Security protocol must be one of DES, AES128, or AES
Warning: snmp3_get(): Error generating a key for privacy pass phrase '': Generic error (The supplied password length is too short.) in %s on line %d
bool(false)
@@ -62,6 +78,4 @@ bool(false)
Warning: snmp3_set(): Invalid object identifier: .1.3.6.777...7.5.3 in %s on line %d
bool(false)
-
-Warning: snmp3_set(): Single objid and multiple type or values are not supported in %s on line %d
-bool(false)
+Type must be of type string when object ID is a string
diff --git a/ext/snmp/tests/snmp_get_valueretrieval.phpt b/ext/snmp/tests/snmp_get_valueretrieval.phpt
index 5d2242c1cd..11358135b0 100644
--- a/ext/snmp/tests/snmp_get_valueretrieval.phpt
+++ b/ext/snmp/tests/snmp_get_valueretrieval.phpt
@@ -11,7 +11,11 @@ require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/snmp_include.inc');
echo "Checking error handling\n";
-var_dump(snmp_set_valueretrieval(67));
+try {
+ var_dump(snmp_set_valueretrieval(67));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
echo "Checking working\n";
var_dump(snmp_get_valueretrieval());
@@ -29,9 +33,7 @@ var_dump(snmp_get_valueretrieval() === (SNMP_VALUE_LIBRARY|SNMP_VALUE_OBJECT));
?>
--EXPECTF--
Checking error handling
-
-Warning: snmp_set_valueretrieval(): Unknown SNMP value retrieval method '67' in %s on line %d
-bool(false)
+snmp_set_valueretrieval(): Argument #1 ($method) must be a bitmask of SNMP_VALUE_LIBRARY, SNMP_VALUE_PLAIN, and SNMP_VALUE_OBJECT
Checking working
int(%d)
bool(true)
diff --git a/ext/snmp/tests/snmp_set_oid_output_format.phpt b/ext/snmp/tests/snmp_set_oid_output_format.phpt
index 3ad5f16458..9cc28b3c6d 100644
--- a/ext/snmp/tests/snmp_set_oid_output_format.phpt
+++ b/ext/snmp/tests/snmp_set_oid_output_format.phpt
@@ -12,17 +12,19 @@ if (!function_exists('snmp_set_oid_output_format')) die('skip This function is o
require_once(__DIR__.'/snmp_include.inc');
echo "Checking error handling\n";
-var_dump(snmp_set_oid_output_format(123));
+try {
+ var_dump(snmp_set_oid_output_format(123));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
echo "Checking working\n";
var_dump(snmp_set_oid_output_format(SNMP_OID_OUTPUT_FULL));
var_dump(snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC));
?>
---EXPECTF--
+--EXPECT--
Checking error handling
-
-Warning: snmp_set_oid_output_format(): Unknown SNMP output print format '123' in %s on line %d
-bool(false)
+snmp_set_oid_output_format(): Argument #1 ($oid_format) must be an SNMP_OID_OUTPUT_* constant
Checking working
bool(true)
bool(true)
diff --git a/ext/snmp/tests/snmpset.phpt b/ext/snmp/tests/snmpset.phpt
index a870ab1ca6..f6320d3c29 100644
--- a/ext/snmp/tests/snmpset.phpt
+++ b/ext/snmp/tests/snmpset.phpt
@@ -16,8 +16,12 @@ snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
echo "Check error handing\n";
echo "No type & no value (timeout & retries instead)\n";
-$z = snmpset($hostname, $communityWrite, 'SNMPv2-MIB::sysLocation.0', $timeout, $retries);
-var_dump($z);
+try {
+ $z = snmpset($hostname, $communityWrite, 'SNMPv2-MIB::sysLocation.0', $timeout, $retries);
+ var_dump($z);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
echo "No value (timeout instead), retries instead of timeout\n";
$z = snmpset($hostname, $communityWrite, 'SNMPv2-MIB::sysLocation.0', 'q', $timeout, $retries);
@@ -76,26 +80,42 @@ var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $ol
echo "More error handing\n";
echo "Single OID, single type in array, single value\n";
-$z = snmpset($hostname, $communityWrite, $oid1, array('s'), $newvalue1, $timeout, $retries);
-var_dump($z);
+try {
+ $z = snmpset($hostname, $communityWrite, $oid1, array('s'), $newvalue1, $timeout, $retries);
+ var_dump($z);
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
echo "Single OID, single type, single value in array\n";
-$z = snmpset($hostname, $communityWrite, $oid1, 's', array($newvalue1), $timeout, $retries);
-var_dump($z);
+try {
+ $z = snmpset($hostname, $communityWrite, $oid1, 's', array($newvalue1), $timeout, $retries);
+ var_dump($z);
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
echo "Multiple OID, 1st wrong type\n";
-$z = snmpset($hostname, $communityWrite, array($oid1, $oid2), array('sw','s'), array($newvalue1, $newvalue2), $timeout, $retries);
-var_dump($z);
+try {
+ $z = snmpset($hostname, $communityWrite, array($oid1, $oid2), array('sw','s'), array($newvalue1, $newvalue2), $timeout, $retries);
+ var_dump($z);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
echo "Multiple OID, 2nd wrong type\n";
-$z = snmpset($hostname, $communityWrite, array($oid1, $oid2), array('s','sb'), array($newvalue1, $newvalue2), $timeout, $retries);
-var_dump($z);
+try {
+ $z = snmpset($hostname, $communityWrite, array($oid1, $oid2), array('s','sb'), array($newvalue1, $newvalue2), $timeout, $retries);
+ var_dump($z);
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
@@ -139,9 +159,7 @@ var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $ol
--EXPECTF--
Check error handing
No type & no value (timeout & retries instead)
-
-Warning: snmpset(): Bogus type '-1', should be single char, got 2 in %s on line %d
-bool(false)
+Type must be a single character
No value (timeout instead), retries instead of timeout
Warning: snmpset(): Could not add variable: OID='%s' type='q' value='%i': Bad variable type ("q") in %s on line %d
@@ -179,27 +197,19 @@ bool(true)
bool(true)
More error handing
Single OID, single type in array, single value
-
-Warning: snmpset(): Single objid and multiple type or values are not supported in %s on line %d
-bool(false)
+Type must be of type string when object ID is a string
bool(true)
bool(true)
Single OID, single type, single value in array
-
-Warning: snmpset(): Single objid and multiple type or values are not supported in %s on line %d
-bool(false)
+Value must be of type string when object ID is a string
bool(true)
bool(true)
Multiple OID, 1st wrong type
-
-Warning: snmpset(): '%s': bogus type 'sw', should be single char, got 2 in %s on line %d
-bool(false)
+Type must be a single character
bool(true)
bool(true)
Multiple OID, 2nd wrong type
-
-Warning: snmpset(): '%s': bogus type 'sb', should be single char, got 2 in %s on line %d
-bool(false)
+Type must be a single character
bool(true)
bool(true)
Multiple OID, single type in array, multiple value