mirror of
https://github.com/php/php-src.git
synced 2025-08-16 14:08:47 +02:00
Promote warnings to Error in SNMP extension
This commit is contained in:
parent
1a8936cde3
commit
62c20c662a
10 changed files with 265 additions and 184 deletions
|
@ -659,7 +659,6 @@ retry:
|
||||||
*
|
*
|
||||||
* OID parser (and type, value for SNMP_SET command)
|
* OID parser (and type, value for SNMP_SET command)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int php_snmp_parse_oid(
|
static int php_snmp_parse_oid(
|
||||||
zval *object, int st, struct objid_query *objid_query, zend_string *oid_str, HashTable *oid_ht,
|
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
|
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 = (snmpobjarg *)emalloc(sizeof(snmpobjarg));
|
||||||
objid_query->vars[objid_query->count].oid = ZSTR_VAL(oid_str);
|
objid_query->vars[objid_query->count].oid = ZSTR_VAL(oid_str);
|
||||||
if (st & SNMP_CMD_SET) {
|
if (st & SNMP_CMD_SET) {
|
||||||
if (type_str && value_str) {
|
if (type_ht) {
|
||||||
if (ZSTR_LEN(type_str) != 1) {
|
zend_type_error("Type must be of type string when object ID is a string");
|
||||||
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");
|
|
||||||
efree(objid_query->vars);
|
efree(objid_query->vars);
|
||||||
return FALSE;
|
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++;
|
objid_query->count++;
|
||||||
} else if (oid_ht) { /* we got objid array */
|
} else if (oid_ht) { /* we got objid array */
|
||||||
if (zend_hash_num_elements(oid_ht) == 0) {
|
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;
|
return FALSE;
|
||||||
}
|
}
|
||||||
objid_query->vars = (snmpobjarg *)safe_emalloc(sizeof(snmpobjarg), zend_hash_num_elements(oid_ht), 0);
|
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) {
|
if (idx_type < type_ht->nNumUsed) {
|
||||||
convert_to_string_ex(tmp_type);
|
convert_to_string_ex(tmp_type);
|
||||||
if (Z_STRLEN_P(tmp_type) != 1) {
|
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);
|
efree(objid_query->vars);
|
||||||
return FALSE;
|
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")) {
|
} else if (!strcasecmp(level, "authPriv") || !strcasecmp(level, "ap")) {
|
||||||
s->securityLevel = SNMP_SEC_LEVEL_AUTHPRIV;
|
s->securityLevel = SNMP_SEC_LEVEL_AUTHPRIV;
|
||||||
} else {
|
} else {
|
||||||
|
zend_value_error("Security level must be one of \"noAuthNoPriv\", \"authNoPriv\", or \"authPriv\"");
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -933,7 +941,7 @@ static int netsnmp_session_set_auth_protocol(struct snmp_session *s, char *prot)
|
||||||
s->securityAuthProto = usmHMACSHA1AuthProtocol;
|
s->securityAuthProto = usmHMACSHA1AuthProtocol;
|
||||||
s->securityAuthProtoLen = USM_AUTH_PROTO_SHA_LEN;
|
s->securityAuthProtoLen = USM_AUTH_PROTO_SHA_LEN;
|
||||||
} else {
|
} 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 (-1);
|
||||||
}
|
}
|
||||||
return (0);
|
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;
|
s->securityPrivProtoLen = USM_PRIV_PROTO_AES_LEN;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} 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 (-1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -987,7 +999,7 @@ static int netsnmp_session_gen_sec_key(struct snmp_session *s, char *pass)
|
||||||
(u_char *)pass, strlen(pass),
|
(u_char *)pass, strlen(pass),
|
||||||
s->securityPrivKey, &(s->securityPrivKeyLen)))) {
|
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));
|
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);
|
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);
|
u_char *ebuf = (u_char *) emalloc(ebuf_len);
|
||||||
|
|
||||||
if (!snmp_hex_to_binary(&ebuf, &ebuf_len, &eout_len, 1, contextEngineID)) {
|
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);
|
php_error_docref(NULL, E_WARNING, "Bad engine ID value '%s'", contextEngineID);
|
||||||
efree(ebuf);
|
efree(ebuf);
|
||||||
return (-1);
|
return (-1);
|
||||||
|
@ -1023,7 +1036,7 @@ static int netsnmp_session_set_security(struct snmp_session *session, char *sec_
|
||||||
|
|
||||||
/* Setting the security level. */
|
/* Setting the security level. */
|
||||||
if (netsnmp_session_set_sec_level(session, sec_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);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1031,7 +1044,7 @@ static int netsnmp_session_set_security(struct snmp_session *session, char *sec_
|
||||||
|
|
||||||
/* Setting the authentication protocol. */
|
/* Setting the authentication protocol. */
|
||||||
if (netsnmp_session_set_auth_protocol(session, auth_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);
|
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) {
|
if (session->securityLevel == SNMP_SEC_LEVEL_AUTHPRIV) {
|
||||||
/* Setting the security protocol. */
|
/* Setting the security protocol. */
|
||||||
if (netsnmp_session_set_sec_protocol(session, priv_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);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1220,9 +1233,9 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
|
||||||
snmp_object = Z_SNMP_P(object);
|
snmp_object = Z_SNMP_P(object);
|
||||||
session = snmp_object->session;
|
session = snmp_object->session;
|
||||||
if (!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);
|
efree(objid_query.vars);
|
||||||
RETURN_FALSE;
|
RETURN_THROWS();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (snmp_object->max_oids > 0) {
|
if (snmp_object->max_oids > 0) {
|
||||||
|
@ -1351,11 +1364,9 @@ PHP_FUNCTION(snmp_set_oid_output_format)
|
||||||
case NETSNMP_OID_OUTPUT_NONE:
|
case NETSNMP_OID_OUTPUT_NONE:
|
||||||
netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, a1);
|
netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, a1);
|
||||||
RETURN_TRUE;
|
RETURN_TRUE;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
php_error_docref(NULL, E_WARNING, "Unknown SNMP output print format '%d'", (int) a1);
|
zend_argument_value_error(1, "must be an SNMP_OID_OUTPUT_* constant");
|
||||||
RETURN_FALSE;
|
RETURN_THROWS();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
@ -1443,8 +1454,8 @@ PHP_FUNCTION(snmp_set_valueretrieval)
|
||||||
SNMP_G(valueretrieval) = method;
|
SNMP_G(valueretrieval) = method;
|
||||||
RETURN_TRUE;
|
RETURN_TRUE;
|
||||||
} else {
|
} else {
|
||||||
php_error_docref(NULL, E_WARNING, "Unknown SNMP value retrieval method '" ZEND_LONG_FMT "'", method);
|
zend_argument_value_error(1, "must be a bitmask of SNMP_VALUE_LIBRARY, SNMP_VALUE_PLAIN, and SNMP_VALUE_OBJECT");
|
||||||
RETURN_FALSE;
|
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)
|
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;
|
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)
|
static int php_snmp_write_max_oids(php_snmp_object *snmp_object, zval *newval)
|
||||||
{
|
{
|
||||||
int ret = SUCCESS;
|
|
||||||
zend_long lval;
|
zend_long lval;
|
||||||
|
|
||||||
if (Z_TYPE_P(newval) == IS_NULL) {
|
if (Z_TYPE_P(newval) == IS_NULL) {
|
||||||
snmp_object->max_oids = 0;
|
snmp_object->max_oids = 0;
|
||||||
return ret;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
lval = zval_get_long(newval);
|
lval = zval_get_long(newval);
|
||||||
|
|
||||||
if (lval > 0) {
|
if (lval <= 0) {
|
||||||
snmp_object->max_oids = lval;
|
zend_value_error("max_oids must be greater than 0 or null");
|
||||||
} else {
|
return FAILURE;
|
||||||
php_error_docref(NULL, E_WARNING, "max_oids should be positive integer or NULL, got " ZEND_LONG_FMT, lval);
|
|
||||||
}
|
}
|
||||||
|
snmp_object->max_oids = lval;
|
||||||
|
|
||||||
return ret;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
/* {{{ */
|
/* {{{ */
|
||||||
static int php_snmp_write_valueretrieval(php_snmp_object *snmp_object, zval *newval)
|
static int php_snmp_write_valueretrieval(php_snmp_object *snmp_object, zval *newval)
|
||||||
{
|
{
|
||||||
int ret = SUCCESS;
|
|
||||||
zend_long lval = zval_get_long(newval);
|
zend_long lval = zval_get_long(newval);
|
||||||
|
|
||||||
if (lval >= 0 && lval <= (SNMP_VALUE_LIBRARY|SNMP_VALUE_PLAIN|SNMP_VALUE_OBJECT)) {
|
if (lval >= 0 && lval <= (SNMP_VALUE_LIBRARY|SNMP_VALUE_PLAIN|SNMP_VALUE_OBJECT)) {
|
||||||
snmp_object->valueretrieval = lval;
|
snmp_object->valueretrieval = lval;
|
||||||
} else {
|
} else {
|
||||||
php_error_docref(NULL, E_WARNING, "Unknown SNMP value retrieval method '" ZEND_LONG_FMT "'", lval);
|
zend_value_error("SNMP retrieval method must be a bitmask of SNMP_VALUE_LIBRARY, SNMP_VALUE_PLAIN, and SNMP_VALUE_OBJECT");
|
||||||
ret = FAILURE;
|
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)
|
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);
|
zend_long lval = zval_get_long(newval);
|
||||||
|
|
||||||
switch(lval) {
|
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_UCD:
|
||||||
case NETSNMP_OID_OUTPUT_NONE:
|
case NETSNMP_OID_OUTPUT_NONE:
|
||||||
snmp_object->oid_output_format = lval;
|
snmp_object->oid_output_format = lval;
|
||||||
break;
|
return SUCCESS;
|
||||||
default:
|
default:
|
||||||
php_error_docref(NULL, E_WARNING, "Unknown SNMP output print format '" ZEND_LONG_FMT "'", lval);
|
zend_value_error("SNMP output print format must be an SNMP_OID_OUTPUT_* constant");
|
||||||
ret = FAILURE;
|
return FAILURE;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
|
@ -54,18 +54,35 @@ var_dump($session->close());
|
||||||
|
|
||||||
echo "Open normal session\n";
|
echo "Open normal session\n";
|
||||||
$session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries);
|
$session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries);
|
||||||
$session->valueretrieval = 67;
|
try {
|
||||||
var_dump($session->valueretrieval);
|
$session->valueretrieval = 67;
|
||||||
|
var_dump($session->valueretrieval);
|
||||||
|
} catch (\ValueError $e) {
|
||||||
|
echo $e->getMessage() . \PHP_EOL;
|
||||||
|
}
|
||||||
echo "Closing session\n";
|
echo "Closing session\n";
|
||||||
var_dump($session->close());
|
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);
|
$session = new SNMP(SNMP::VERSION_2c, $hostname, $community, $timeout, $retries);
|
||||||
|
|
||||||
var_dump($session->max_oids);
|
var_dump($session->max_oids);
|
||||||
$session->max_oids = "ttt";
|
try {
|
||||||
$session->max_oids = 0;
|
$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);
|
var_dump($session->max_oids);
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
|
@ -81,18 +98,11 @@ int(32)
|
||||||
string(46) "Invalid object identifier: .1.3.6.1.2.1.1.1..0"
|
string(46) "Invalid object identifier: .1.3.6.1.2.1.1.1..0"
|
||||||
bool(true)
|
bool(true)
|
||||||
Open normal session
|
Open normal session
|
||||||
|
SNMP retrieval method must be a bitmask of SNMP_VALUE_LIBRARY, SNMP_VALUE_PLAIN, and SNMP_VALUE_OBJECT
|
||||||
Warning: main(): Unknown SNMP value retrieval method '67' in %s on line %d
|
|
||||||
int(%d)
|
|
||||||
Closing session
|
Closing session
|
||||||
bool(true)
|
bool(true)
|
||||||
|
Invalid or uninitialized SNMP object
|
||||||
Warning: SNMP::get(): Invalid or uninitialized SNMP object in %s on line %d
|
|
||||||
bool(false)
|
|
||||||
bool(true)
|
|
||||||
NULL
|
NULL
|
||||||
|
max_oids must be greater than 0 or null
|
||||||
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
|
||||||
|
|
||||||
Warning: main(): max_oids should be positive integer or NULL, got 0 in %s on line %d
|
|
||||||
NULL
|
NULL
|
||||||
|
|
|
@ -54,13 +54,24 @@ $param = 'there is no such parameter';
|
||||||
var_dump($session->$param);
|
var_dump($session->$param);
|
||||||
var_dump(property_exists($session, $param));
|
var_dump(property_exists($session, $param));
|
||||||
|
|
||||||
$session->valueretrieval = 67;
|
try {
|
||||||
var_dump($session->valueretrieval);
|
$session->valueretrieval = 67;
|
||||||
$session->oid_output_format = 78;
|
var_dump($session->valueretrieval);
|
||||||
var_dump($session->oid_output_format);
|
} catch (\ValueError $e) {
|
||||||
|
echo $e->getMessage() . \PHP_EOL;
|
||||||
$session->info = array("blah" => 2);
|
}
|
||||||
var_dump($session->info);
|
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;
|
$session->max_oids = NULL;
|
||||||
var_dump($session->max_oids);
|
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
|
Warning: Undefined property: SNMP::$there is no such parameter in %s on line %d
|
||||||
NULL
|
NULL
|
||||||
bool(false)
|
bool(false)
|
||||||
|
SNMP retrieval method must be a bitmask of SNMP_VALUE_LIBRARY, SNMP_VALUE_PLAIN, and SNMP_VALUE_OBJECT
|
||||||
Warning: main(): Unknown SNMP value retrieval method '67' in %s on line %d
|
SNMP output print format must be an SNMP_OID_OUTPUT_* constant
|
||||||
int(1)
|
SNMP::$info property is read-only
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
NULL
|
NULL
|
||||||
|
|
|
@ -18,12 +18,37 @@ $session = new SNMP(SNMP::VERSION_3, $hostname, $user_noauth, $timeout, $retries
|
||||||
$session->setSecurity('noAuthNoPriv');
|
$session->setSecurity('noAuthNoPriv');
|
||||||
|
|
||||||
#echo "Checking error handling\n";
|
#echo "Checking error handling\n";
|
||||||
|
|
||||||
|
try {
|
||||||
var_dump($session->setSecurity(''));
|
var_dump($session->setSecurity(''));
|
||||||
|
} catch (\ValueError $e) {
|
||||||
|
echo $e->getMessage() . \PHP_EOL;
|
||||||
|
}
|
||||||
|
try {
|
||||||
var_dump($session->setSecurity('bugusPriv'));
|
var_dump($session->setSecurity('bugusPriv'));
|
||||||
|
} catch (\ValueError $e) {
|
||||||
|
echo $e->getMessage() . \PHP_EOL;
|
||||||
|
}
|
||||||
|
try {
|
||||||
var_dump($session->setSecurity('authNoPriv', 'TTT'));
|
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', ''));
|
||||||
var_dump($session->setSecurity('authNoPriv', 'MD5', 'te'));
|
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', ''));
|
||||||
var_dump($session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', 'ty'));
|
var_dump($session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', 'ty'));
|
||||||
var_dump($session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', 'test12345', 'context', 'dsa'));
|
var_dump($session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', 'test12345', 'context', 'dsa'));
|
||||||
|
@ -32,23 +57,17 @@ var_dump($session->close());
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Warning: SNMP::setSecurity(): Invalid security level '' in %s on line %d
|
Security level must be one of "noAuthNoPriv", "authNoPriv", or "authPriv"
|
||||||
bool(false)
|
Security level must be one of "noAuthNoPriv", "authNoPriv", or "authPriv"
|
||||||
|
Authentication protocol must be either MD5 or SHA
|
||||||
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)
|
|
||||||
|
|
||||||
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
|
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)
|
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
|
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)
|
bool(false)
|
||||||
|
Security protocol must be one of DES, AES128, or AES
|
||||||
Warning: SNMP::setSecurity(): Unknown security protocol 'BBB' in %s on line %d
|
Security protocol must be one of DES, AES128, or AES
|
||||||
bool(false)
|
|
||||||
|
|
||||||
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
|
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)
|
bool(false)
|
||||||
|
|
|
@ -16,7 +16,11 @@ snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
|
||||||
|
|
||||||
echo "Checking error handling\n";
|
echo "Checking error handling\n";
|
||||||
echo "Empty OID array\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 "Checking working\n";
|
||||||
echo "Single OID\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--
|
--EXPECTF--
|
||||||
Checking error handling
|
Checking error handling
|
||||||
Empty OID array
|
Empty OID array
|
||||||
|
Array of object IDs cannot be empty
|
||||||
Warning: snmp2_get(): Got empty OID array in %s on line %d
|
|
||||||
bool(false)
|
|
||||||
Checking working
|
Checking working
|
||||||
Single OID
|
Single OID
|
||||||
string(%d) "%s"
|
string(%d) "%s"
|
||||||
|
|
|
@ -16,8 +16,12 @@ snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
|
||||||
|
|
||||||
echo "Check error handing\n";
|
echo "Check error handing\n";
|
||||||
echo "No type & no value (timeout & retries instead)\n";
|
echo "No type & no value (timeout & retries instead)\n";
|
||||||
$z = snmp2_set($hostname, $communityWrite, 'SNMPv2-MIB::sysLocation.0', $timeout, $retries);
|
try {
|
||||||
var_dump($z);
|
$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";
|
echo "No value (timeout instead), retries instead of timeout\n";
|
||||||
$z = snmp2_set($hostname, $communityWrite, 'SNMPv2-MIB::sysLocation.0', 'q', $timeout, $retries);
|
$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);
|
$z = snmp2_set($hostname, $communityWrite, $oid1, 's', $newvalue1, $timeout, $retries);
|
||||||
var_dump($z);
|
var_dump($z);
|
||||||
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $newvalue1));
|
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $newvalue1));
|
||||||
|
|
||||||
$z = snmp2_set($hostname, $communityWrite, $oid1, 's', $oldvalue1, $timeout, $retries);
|
$z = snmp2_set($hostname, $communityWrite, $oid1, 's', $oldvalue1, $timeout, $retries);
|
||||||
var_dump($z);
|
var_dump($z);
|
||||||
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
|
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($z);
|
||||||
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $newvalue1));
|
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $newvalue1));
|
||||||
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $newvalue2));
|
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);
|
$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('s','s'), array($oldvalue1, $oldvalue2), $timeout, $retries);
|
||||||
var_dump($z);
|
var_dump($z);
|
||||||
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
|
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($z);
|
||||||
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $newvalue1));
|
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $newvalue1));
|
||||||
var_dump((snmpget($hostname, $communityWrite, $oid2, $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);
|
$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('s','s'), array($oldvalue1, $oldvalue2), $timeout, $retries);
|
||||||
var_dump($z);
|
var_dump($z);
|
||||||
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
|
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";
|
echo "Multiple OID, single type, multiple value\n";
|
||||||
$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), 's', array($newvalue1, $newvalue2), $timeout, $retries);
|
$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), 's', array($newvalue1, $newvalue2), $timeout, $retries);
|
||||||
var_dump($z);
|
var_dump($z);
|
||||||
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $newvalue1));
|
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $newvalue1));
|
||||||
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $newvalue2));
|
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);
|
$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('s','s'), array($oldvalue1, $oldvalue2), $timeout, $retries);
|
||||||
var_dump($z);
|
var_dump($z);
|
||||||
var_dump((snmpget($hostname, $communityWrite, $oid1, $timeout, $retries) === $oldvalue1));
|
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 "More error handing\n";
|
echo "More error handing\n";
|
||||||
echo "Single OID, single type in array, single value\n";
|
echo "Single OID, single type in array, single value\n";
|
||||||
$z = snmp2_set($hostname, $communityWrite, $oid1, array('s'), $newvalue1, $timeout, $retries);
|
try {
|
||||||
var_dump($z);
|
$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, $oid1, $timeout, $retries) === $oldvalue1));
|
||||||
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
|
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
|
||||||
|
|
||||||
echo "Single OID, single type, single value in array\n";
|
echo "Single OID, single type, single value in array\n";
|
||||||
$z = snmp2_set($hostname, $communityWrite, $oid1, 's', array($newvalue1), $timeout, $retries);
|
try {
|
||||||
var_dump($z);
|
$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, $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, 1st wrong type\n";
|
echo "Multiple OID, 1st wrong type\n";
|
||||||
$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('sw','s'), array($newvalue1, $newvalue2), $timeout, $retries);
|
try {
|
||||||
var_dump($z);
|
$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, $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, 2nd wrong type\n";
|
echo "Multiple OID, 2nd wrong type\n";
|
||||||
$z = snmp2_set($hostname, $communityWrite, array($oid1, $oid2), array('s','sb'), array($newvalue1, $newvalue2), $timeout, $retries);
|
try {
|
||||||
var_dump($z);
|
$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, $oid1, $timeout, $retries) === $oldvalue1));
|
||||||
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
|
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
|
||||||
|
|
||||||
|
@ -139,9 +165,7 @@ var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $ol
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Check error handing
|
Check error handing
|
||||||
No type & no value (timeout & retries instead)
|
No type & no value (timeout & retries instead)
|
||||||
|
Type must be a single character
|
||||||
Warning: snmp2_set(): Bogus type '-1', should be single char, got 2 in %s on line %d
|
|
||||||
bool(false)
|
|
||||||
No value (timeout instead), retries instead of timeout
|
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
|
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)
|
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)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
|
@ -179,27 +206,19 @@ bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
More error handing
|
More error handing
|
||||||
Single OID, single type in array, single value
|
Single OID, single type in array, single value
|
||||||
|
Type must be of type string when object ID is a string
|
||||||
Warning: snmp2_set(): Single objid and multiple type or values are not supported in %s on line %d
|
|
||||||
bool(false)
|
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
Single OID, single type, single value in array
|
Single OID, single type, single value in array
|
||||||
|
Value must be of type string when object ID is a string
|
||||||
Warning: snmp2_set(): Single objid and multiple type or values are not supported in %s on line %d
|
|
||||||
bool(false)
|
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
Multiple OID, 1st wrong type
|
Multiple OID, 1st wrong type
|
||||||
|
Type must be a single character
|
||||||
Warning: snmp2_set(): '%s': bogus type 'sw', should be single char, got 2 in %s on line %d
|
|
||||||
bool(false)
|
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
Multiple OID, 2nd wrong type
|
Multiple OID, 2nd wrong type
|
||||||
|
Type must be a single character
|
||||||
Warning: snmp2_set(): '%s': bogus type 'sb', should be single char, got 2 in %s on line %d
|
|
||||||
bool(false)
|
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
Multiple OID, single type in array, multiple value
|
Multiple OID, single type in array, multiple value
|
||||||
|
|
|
@ -16,40 +16,56 @@ echo "Checking error handling\n";
|
||||||
// string auth_passphrase, string priv_protocol, string priv_passphrase,
|
// string auth_passphrase, string priv_protocol, string priv_passphrase,
|
||||||
// string object_id [, int timeout [, int retries]]);
|
// string object_id [, int timeout [, int retries]]);
|
||||||
|
|
||||||
var_dump(snmp3_get($hostname, $community, '', '', '', '', '', '.1.3.6.1.2.1.1.1.0'));
|
try {
|
||||||
var_dump(snmp3_get($hostname, $community, 'bugusPriv', '', '', '', '', '.1.3.6.1.2.1.1.1.0'));
|
var_dump(snmp3_get($hostname, $community, '', '', '', '', '', '.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'));
|
} 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', '', '', '', '.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, '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', '', '.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, $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_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', '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--
|
--EXPECTF--
|
||||||
Checking error handling
|
Checking error handling
|
||||||
|
Security level must be one of "noAuthNoPriv", "authNoPriv", or "authPriv"
|
||||||
Warning: snmp3_get(): Invalid security level '' in %s on line %d
|
Security level must be one of "noAuthNoPriv", "authNoPriv", or "authPriv"
|
||||||
bool(false)
|
Authentication protocol must be either MD5 or SHA
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
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
|
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)
|
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
|
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)
|
bool(false)
|
||||||
|
Security protocol must be one of DES, AES128, or AES
|
||||||
Warning: snmp3_get(): Unknown security protocol 'BBB' in %s on line %d
|
|
||||||
bool(false)
|
|
||||||
|
|
||||||
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
|
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)
|
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
|
Warning: snmp3_set(): Invalid object identifier: .1.3.6.777...7.5.3 in %s on line %d
|
||||||
bool(false)
|
bool(false)
|
||||||
|
Type must be of type string when object ID is a string
|
||||||
Warning: snmp3_set(): Single objid and multiple type or values are not supported in %s on line %d
|
|
||||||
bool(false)
|
|
||||||
|
|
|
@ -11,7 +11,11 @@ require_once(__DIR__.'/skipif.inc');
|
||||||
require_once(__DIR__.'/snmp_include.inc');
|
require_once(__DIR__.'/snmp_include.inc');
|
||||||
|
|
||||||
echo "Checking error handling\n";
|
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";
|
echo "Checking working\n";
|
||||||
var_dump(snmp_get_valueretrieval());
|
var_dump(snmp_get_valueretrieval());
|
||||||
|
@ -29,9 +33,7 @@ var_dump(snmp_get_valueretrieval() === (SNMP_VALUE_LIBRARY|SNMP_VALUE_OBJECT));
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Checking error handling
|
Checking error handling
|
||||||
|
snmp_set_valueretrieval(): Argument #1 ($method) must be a bitmask of SNMP_VALUE_LIBRARY, SNMP_VALUE_PLAIN, and SNMP_VALUE_OBJECT
|
||||||
Warning: snmp_set_valueretrieval(): Unknown SNMP value retrieval method '67' in %s on line %d
|
|
||||||
bool(false)
|
|
||||||
Checking working
|
Checking working
|
||||||
int(%d)
|
int(%d)
|
||||||
bool(true)
|
bool(true)
|
||||||
|
|
|
@ -12,17 +12,19 @@ if (!function_exists('snmp_set_oid_output_format')) die('skip This function is o
|
||||||
require_once(__DIR__.'/snmp_include.inc');
|
require_once(__DIR__.'/snmp_include.inc');
|
||||||
|
|
||||||
echo "Checking error handling\n";
|
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";
|
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_FULL));
|
||||||
var_dump(snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC));
|
var_dump(snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC));
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECT--
|
||||||
Checking error handling
|
Checking error handling
|
||||||
|
snmp_set_oid_output_format(): Argument #1 ($oid_format) must be an SNMP_OID_OUTPUT_* constant
|
||||||
Warning: snmp_set_oid_output_format(): Unknown SNMP output print format '123' in %s on line %d
|
|
||||||
bool(false)
|
|
||||||
Checking working
|
Checking working
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
|
|
|
@ -16,8 +16,12 @@ snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
|
||||||
|
|
||||||
echo "Check error handing\n";
|
echo "Check error handing\n";
|
||||||
echo "No type & no value (timeout & retries instead)\n";
|
echo "No type & no value (timeout & retries instead)\n";
|
||||||
$z = snmpset($hostname, $communityWrite, 'SNMPv2-MIB::sysLocation.0', $timeout, $retries);
|
try {
|
||||||
var_dump($z);
|
$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";
|
echo "No value (timeout instead), retries instead of timeout\n";
|
||||||
$z = snmpset($hostname, $communityWrite, 'SNMPv2-MIB::sysLocation.0', 'q', $timeout, $retries);
|
$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 "More error handing\n";
|
||||||
echo "Single OID, single type in array, single value\n";
|
echo "Single OID, single type in array, single value\n";
|
||||||
$z = snmpset($hostname, $communityWrite, $oid1, array('s'), $newvalue1, $timeout, $retries);
|
try {
|
||||||
var_dump($z);
|
$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, $oid1, $timeout, $retries) === $oldvalue1));
|
||||||
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
|
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
|
||||||
|
|
||||||
echo "Single OID, single type, single value in array\n";
|
echo "Single OID, single type, single value in array\n";
|
||||||
$z = snmpset($hostname, $communityWrite, $oid1, 's', array($newvalue1), $timeout, $retries);
|
try {
|
||||||
var_dump($z);
|
$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, $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, 1st wrong type\n";
|
echo "Multiple OID, 1st wrong type\n";
|
||||||
$z = snmpset($hostname, $communityWrite, array($oid1, $oid2), array('sw','s'), array($newvalue1, $newvalue2), $timeout, $retries);
|
try {
|
||||||
var_dump($z);
|
$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, $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, 2nd wrong type\n";
|
echo "Multiple OID, 2nd wrong type\n";
|
||||||
$z = snmpset($hostname, $communityWrite, array($oid1, $oid2), array('s','sb'), array($newvalue1, $newvalue2), $timeout, $retries);
|
try {
|
||||||
var_dump($z);
|
$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, $oid1, $timeout, $retries) === $oldvalue1));
|
||||||
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
|
var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $oldvalue2));
|
||||||
|
|
||||||
|
@ -139,9 +159,7 @@ var_dump((snmpget($hostname, $communityWrite, $oid2, $timeout, $retries) === $ol
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Check error handing
|
Check error handing
|
||||||
No type & no value (timeout & retries instead)
|
No type & no value (timeout & retries instead)
|
||||||
|
Type must be a single character
|
||||||
Warning: snmpset(): Bogus type '-1', should be single char, got 2 in %s on line %d
|
|
||||||
bool(false)
|
|
||||||
No value (timeout instead), retries instead of timeout
|
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
|
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)
|
bool(true)
|
||||||
More error handing
|
More error handing
|
||||||
Single OID, single type in array, single value
|
Single OID, single type in array, single value
|
||||||
|
Type must be of type string when object ID is a string
|
||||||
Warning: snmpset(): Single objid and multiple type or values are not supported in %s on line %d
|
|
||||||
bool(false)
|
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
Single OID, single type, single value in array
|
Single OID, single type, single value in array
|
||||||
|
Value must be of type string when object ID is a string
|
||||||
Warning: snmpset(): Single objid and multiple type or values are not supported in %s on line %d
|
|
||||||
bool(false)
|
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
Multiple OID, 1st wrong type
|
Multiple OID, 1st wrong type
|
||||||
|
Type must be a single character
|
||||||
Warning: snmpset(): '%s': bogus type 'sw', should be single char, got 2 in %s on line %d
|
|
||||||
bool(false)
|
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
Multiple OID, 2nd wrong type
|
Multiple OID, 2nd wrong type
|
||||||
|
Type must be a single character
|
||||||
Warning: snmpset(): '%s': bogus type 'sb', should be single char, got 2 in %s on line %d
|
|
||||||
bool(false)
|
|
||||||
bool(true)
|
bool(true)
|
||||||
bool(true)
|
bool(true)
|
||||||
Multiple OID, single type in array, multiple value
|
Multiple OID, single type in array, multiple value
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue