Skip to content

Commit 14eaa5a

Browse files
author
Boris Lytochkin
committed
follow CS:
- method set_security should be named as setSecurity - SNMP_VERSION_2C constant
1 parent 547a960 commit 14eaa5a

13 files changed

+87
-86
lines changed

ext/snmp/php_snmp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ PHP_FUNCTION(snmp_get_valueretrieval);
7373
PHP_FUNCTION(snmp_read_mib);
7474

7575
PHP_METHOD(SNMP, open);
76-
PHP_METHOD(SNMP, set_security);
76+
PHP_METHOD(SNMP, setSecurity);
7777
PHP_METHOD(SNMP, close);
7878
PHP_METHOD(SNMP, get);
7979
PHP_METHOD(SNMP, getnext);

ext/snmp/snmp.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ ZEND_END_ARG_INFO()
374374
ZEND_BEGIN_ARG_INFO(arginfo_snmp_void, 0)
375375
ZEND_END_ARG_INFO()
376376

377-
ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp_set_security, 0, 0, 8)
377+
ZEND_BEGIN_ARG_INFO_EX(arginfo_snmp_setSecurity, 0, 0, 8)
378378
ZEND_ARG_INFO(0, session)
379379
ZEND_ARG_INFO(0, sec_level)
380380
ZEND_ARG_INFO(0, auth_protocol)
@@ -1847,9 +1847,9 @@ PHP_METHOD(snmp, set)
18471847
php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_SET, (-1));
18481848
}
18491849

1850-
/* {{{ proto bool SNMP::set_security(resource session, string sec_level, [ string auth_protocol, string auth_passphrase [, string priv_protocol, string priv_passphrase [, string contextName [, string contextEngineID]]]])
1850+
/* {{{ proto bool SNMP::setSecurity(resource session, string sec_level, [ string auth_protocol, string auth_passphrase [, string priv_protocol, string priv_passphrase [, string contextName [, string contextEngineID]]]])
18511851
Set SNMPv3 security-related session parameters */
1852-
PHP_METHOD(snmp, set_security)
1852+
PHP_METHOD(snmp, setSecurity)
18531853
{
18541854
php_snmp_object *snmp_object;
18551855
zval *object = getThis();
@@ -2338,7 +2338,7 @@ static int php_snmp_write_oid_output_format(php_snmp_object *snmp_object, zval *
23382338
static zend_function_entry php_snmp_class_methods[] = {
23392339
PHP_ME(snmp, open, arginfo_snmp_open, ZEND_ACC_PUBLIC)
23402340
PHP_ME(snmp, close, arginfo_snmp_void, ZEND_ACC_PUBLIC)
2341-
PHP_ME(snmp, set_security, arginfo_snmp_set_security, ZEND_ACC_PUBLIC)
2341+
PHP_ME(snmp, setSecurity, arginfo_snmp_setSecurity, ZEND_ACC_PUBLIC)
23422342

23432343
PHP_ME(snmp, get, arginfo_snmp_get, ZEND_ACC_PUBLIC)
23442344
PHP_ME(snmp, getnext, arginfo_snmp_get, ZEND_ACC_PUBLIC)
@@ -2434,6 +2434,7 @@ PHP_MINIT_FUNCTION(snmp)
24342434

24352435
REGISTER_LONG_CONSTANT("SNMP_VERSION_1", SNMP_VERSION_1, CONST_CS | CONST_PERSISTENT);
24362436
REGISTER_LONG_CONSTANT("SNMP_VERSION_2c", SNMP_VERSION_2c, CONST_CS | CONST_PERSISTENT);
2437+
REGISTER_LONG_CONSTANT("SNMP_VERSION_2C", SNMP_VERSION_2c, CONST_CS | CONST_PERSISTENT);
24372438
REGISTER_LONG_CONSTANT("SNMP_VERSION_3", SNMP_VERSION_3, CONST_CS | CONST_PERSISTENT);
24382439

24392440
REGISTER_SNMP_CLASS_CONST_LONG("ERRNO_NOERROR", (long)PHP_SNMP_ERRNO_NOERROR);

ext/snmp/tests/generic_timeout_error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ var_dump(snmpget($hostname, 'timeout_community_432', '.1.3.6.1.2.1.1.1.0', $time
1919
?>
2020
--EXPECTF--
2121
Warning: snmpget(): No response from %s in %s on line %d
22-
bool(false)
22+
bool(false)

ext/snmp/tests/snmp-object-errno-errstr.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var_dump($session->get_error());
3838
$session->close();
3939
echo "SNMP::ERRNO_GENERIC\n";
4040
$session = new SNMP(SNMP_VERSION_3, $hostname, 'somebogususer', $timeout, $retries);
41-
$session->set_security('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
41+
$session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
4242
var_dump(@$session->get('.1.3.6.1.2.1.1.1.0'));
4343
var_dump($session->get_errno() == SNMP::ERRNO_GENERIC);
4444
var_dump($session->get_error());
@@ -60,4 +60,4 @@ bool(true)
6060
SNMP::ERRNO_GENERIC
6161
bool(false)
6262
bool(true)
63-
%string|unicode%(%d) "Fatal error: Unknown user name"
63+
%string|unicode%(%d) "Fatal error: Unknown user name"

ext/snmp/tests/snmp-object-error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,4 @@ NULL
9191
Warning: main(): max_oids should be positive integer or NULL, got 0 in %s on line %d
9292

9393
Warning: main(): max_oids should be positive integer or NULL, got 0 in %s on line %d
94-
NULL
94+
NULL

ext/snmp/tests/snmp-object-properties.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,4 @@ array(4) {
187187
["retries"]=>
188188
int(%d)
189189
}
190-
NULL
190+
NULL
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
--TEST--
2+
OO API: SNMP::setSecurity (errors)
3+
--CREDITS--
4+
Boris Lytochkin
5+
--SKIPIF--
6+
<?php
7+
require_once(dirname(__FILE__).'/skipif.inc');
8+
?>
9+
--FILE--
10+
<?php
11+
require_once(dirname(__FILE__).'/snmp_include.inc');
12+
13+
//EXPECTF format is quickprint OFF
14+
snmp_set_quick_print(false);
15+
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
16+
17+
$session = new SNMP(SNMP_VERSION_3, $hostname, $user_noauth, $timeout, $retries);
18+
$session->setSecurity('noAuthNoPriv');
19+
20+
#echo "Checking error handling\n";
21+
var_dump($session->setSecurity());
22+
var_dump($session->setSecurity(''));
23+
var_dump($session->setSecurity('bugusPriv'));
24+
var_dump($session->setSecurity('authNoPriv', 'TTT'));
25+
var_dump($session->setSecurity('authNoPriv', 'MD5', ''));
26+
var_dump($session->setSecurity('authNoPriv', 'MD5', 'te'));
27+
var_dump($session->setSecurity('authPriv', 'MD5', $auth_pass, 'BBB'));
28+
var_dump($session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', ''));
29+
var_dump($session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', 'ty'));
30+
var_dump($session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', 'test12345', 'context', 'dsa'));
31+
32+
var_dump($session->close());
33+
34+
?>
35+
--EXPECTF--
36+
37+
Warning: SNMP::setSecurity() expects at least 1 parameter, 0 given in %s on line %d
38+
bool(false)
39+
40+
Warning: SNMP::setSecurity(): Invalid security level '' in %s on line %d
41+
bool(false)
42+
43+
Warning: SNMP::setSecurity(): Invalid security level 'bugusPriv' in %s on line %d
44+
bool(false)
45+
46+
Warning: SNMP::setSecurity(): Unknown authentication protocol 'TTT' in %s on line %d
47+
bool(false)
48+
49+
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
50+
bool(false)
51+
52+
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
53+
bool(false)
54+
55+
Warning: SNMP::setSecurity(): Unknown security protocol 'BBB' in %s on line %d
56+
bool(false)
57+
58+
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
59+
bool(false)
60+
61+
Warning: SNMP::setSecurity(): Error generating a key for privacy pass phrase 'ty': Generic error (The supplied password length is too short.) in %s on line %d
62+
bool(false)
63+
64+
Warning: SNMP::setSecurity(): Bad engine ID value 'dsa' in %s on line %d
65+
bool(false)
66+
bool(true)

ext/snmp/tests/snmp-object-set_security_error.phpt

Lines changed: 0 additions & 66 deletions
This file was deleted.

ext/snmp/tests/snmp-object.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,29 @@ var_dump($session->close());
6969

7070
echo "SNMPv3 (default security settings)\n";
7171
$session = new SNMP(SNMP_VERSION_3, $hostname, $user_noauth, $timeout, $retries);
72-
#$session->set_security($user_noauth, 'noAuthNoPriv', '', '', '', '', '', '');
72+
#$session->setSecurity($user_noauth, 'noAuthNoPriv', '', '', '', '', '', '');
7373
var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
7474
var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
7575
var_dump($session->close());
7676

7777
echo "SNMPv3 (noAuthNoPriv)\n";
7878
$session = new SNMP(SNMP_VERSION_3, $hostname, $user_noauth, $timeout, $retries);
79-
$session->set_security('noAuthNoPriv');
79+
$session->setSecurity('noAuthNoPriv');
8080
var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
8181
var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
8282
var_dump($session->close());
8383

8484
echo "SNMPv3 (authPriv)\n";
8585
$session = new SNMP(SNMP_VERSION_3, $hostname, $rwuser, $timeout, $retries);
86-
$session->set_security('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
86+
$session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
8787
var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
8888
var_dump($session->getnext('.1.3.6.1.2.1.1.1.0'));
8989
var_dump($session->walk('.1.3.6.1.2.1.1.1.0'));
9090
var_dump($session->close());
9191

9292
echo "SET single OID\n";
9393
$session = new SNMP(SNMP_VERSION_3, $hostname, $rwuser, $timeout, $retries);
94-
$session->set_security('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
94+
$session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass);
9595
$oid1 = 'SNMPv2-MIB::sysContact.0';
9696
$oldvalue1 = $session->get($oid1);
9797
$newvalue1 = $oldvalue1 . '0';
@@ -106,7 +106,7 @@ var_dump($session->close());
106106

107107
echo "SNMPv3, setting contextEngineID (authPriv)\n";
108108
$session = new SNMP(SNMP_VERSION_3, $hostname, $rwuser, $timeout, $retries);
109-
$session->set_security('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, '', 'aeeeff');
109+
$session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, '', 'aeeeff');
110110
var_dump($session->get('.1.3.6.1.2.1.1.1.0'));
111111
var_dump($session->close());
112112

@@ -174,4 +174,4 @@ bool(true)
174174
bool(true)
175175
SNMPv3, setting contextEngineID (authPriv)
176176
string(%d) "%S"
177-
bool(true)
177+
bool(true)

ext/snmp/tests/snmp2_set-nomib.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ Single OID
5656
bool(true)
5757
bool(true)
5858
bool(true)
59-
bool(true)
59+
bool(true)

ext/snmp/tests/snmp3-error.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@ Warning: snmp3_set(): Invalid object identifier: .1.3.6.777...7.5.3 in %s on lin
7373
bool(false)
7474

7575
Warning: snmp3_set(): Single objid and multiple type or values are not supported in %s on line %d
76-
bool(false)
76+
bool(false)

ext/snmp/tests/snmpset-nomib.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ Single OID
5757
bool(true)
5858
bool(true)
5959
bool(true)
60-
bool(true)
60+
bool(true)

ext/snmp/tests/wrong_hostname.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ var_dump(snmpget('192.168..6.1', 'community', '.1.3.6.1.2.1.1.1.0', $timeout, $r
1919
?>
2020
--EXPECTF--
2121
Warning: snmpget(): Could not open snmp connection: Unknown host (192.168..6.1) (%s) in %s on line %d
22-
bool(false)
22+
bool(false)

0 commit comments

Comments
 (0)