1999-04-22 10:48:28 +08:00
|
|
|
/*
|
2003-01-24 17:40:53 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| PHP Version 4 |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Copyright (c) 1997-2003 The PHP Group |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| This source file is subject to version 2.02 of the PHP license, |
|
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
|
|
|
| http://www.php.net/license/2_02.txt. |
|
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Rasmus Lerdorf <rasmus@php.net> |
|
|
|
|
| Mike Jackson <mhjack@tscnet.com> |
|
|
|
|
| Steven Lawrance <slawrance@technologist.com> |
|
|
|
|
| Harrie Hazewinkel <harrie@lisanza.net> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
/* $Id$ */
|
|
|
|
|
2001-05-24 18:07:29 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
#include "php.h"
|
2000-04-07 05:07:44 +08:00
|
|
|
#include "ext/standard/info.h"
|
1999-12-05 03:19:57 +08:00
|
|
|
#include "php_snmp.h"
|
2002-10-15 08:43:34 +08:00
|
|
|
|
|
|
|
#if HAVE_SNMP
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
#include <sys/types.h>
|
2000-02-11 23:59:30 +08:00
|
|
|
#ifdef PHP_WIN32
|
1999-04-22 10:48:28 +08:00
|
|
|
#include <winsock.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <process.h>
|
|
|
|
#include "win32/time.h"
|
2002-09-05 19:50:43 +08:00
|
|
|
#elif defined(NETWARE)
|
|
|
|
#ifdef USE_WINSOCK
|
|
|
|
/*#include <ws2nlm.h>*/
|
|
|
|
#include <novsock2.h>
|
|
|
|
#else
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#endif
|
|
|
|
#include <errno.h>
|
|
|
|
/*#include <process.h>*/
|
|
|
|
#ifdef NEW_LIBC
|
|
|
|
#include <sys/timeval.h>
|
|
|
|
#else
|
|
|
|
#include "netware/time_nw.h"
|
|
|
|
#endif
|
1999-04-22 10:48:28 +08:00
|
|
|
#else
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
1999-08-05 04:56:33 +08:00
|
|
|
#ifndef _OSD_POSIX
|
1999-04-22 10:48:28 +08:00
|
|
|
#include <sys/errno.h>
|
1999-08-05 04:56:33 +08:00
|
|
|
#else
|
|
|
|
#include <errno.h> /* BS2000/OSD uses <errno.h>, not <sys/errno.h> */
|
|
|
|
#endif
|
1999-04-22 10:48:28 +08:00
|
|
|
#include <netdb.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __P
|
|
|
|
#ifdef __GNUC__
|
|
|
|
#define __P(args) args
|
|
|
|
#else
|
|
|
|
#define __P(args) ()
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2002-10-15 08:43:34 +08:00
|
|
|
#ifdef HAVE_NET_SNMP
|
|
|
|
#include <net-snmp/net-snmp-config.h>
|
|
|
|
#include <net-snmp/net-snmp-includes.h>
|
|
|
|
#else
|
2000-03-19 20:38:53 +08:00
|
|
|
#ifdef HAVE_DEFAULT_STORE_H
|
|
|
|
#include "default_store.h"
|
|
|
|
#endif
|
1999-04-22 10:48:28 +08:00
|
|
|
#include "asn1.h"
|
|
|
|
#include "snmp_api.h"
|
|
|
|
#include "snmp_client.h"
|
|
|
|
#include "snmp_impl.h"
|
|
|
|
#include "snmp.h"
|
2002-11-12 05:09:19 +08:00
|
|
|
#include "snmpv3.h"
|
|
|
|
#include "keytools.h"
|
1999-04-22 10:48:28 +08:00
|
|
|
#include "parse.h"
|
|
|
|
#include "mib.h"
|
2000-08-30 23:52:07 +08:00
|
|
|
#include "version.h"
|
2002-11-12 05:09:19 +08:00
|
|
|
#include "transform_oids.h"
|
2002-10-15 08:43:34 +08:00
|
|
|
#endif
|
2002-11-12 05:09:19 +08:00
|
|
|
/* Ugly macro, since the length of OIDs in UCD-SNMP and NET-SNMP
|
|
|
|
* is different and this way the code is not full of 'ifdef's.
|
|
|
|
*/
|
|
|
|
#define OIDSIZE(p) (sizeof(p)/sizeof(oid))
|
1999-04-22 10:48:28 +08:00
|
|
|
|
2002-10-17 14:39:55 +08:00
|
|
|
/* For really old ucd-snmp versions.. */
|
|
|
|
#ifndef HAVE_SNMP_PARSE_OID
|
|
|
|
#define snmp_parse_oid read_objid
|
|
|
|
#endif
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
/* ucd-snmp 3.3.1 changed the name of a few #defines... They've been changed back to the original ones in 3.5.3! */
|
|
|
|
#ifndef SNMP_MSG_GET
|
|
|
|
#define SNMP_MSG_GET GET_REQ_MSG
|
|
|
|
#define SNMP_MSG_GETNEXT GETNEXT_REQ_MSG
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* constant - can be shared among threads */
|
|
|
|
static oid objid_mib[] = {1, 3, 6, 1, 2, 1};
|
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
/* {{{ snmp_functions[]
|
|
|
|
*/
|
1999-04-22 10:48:28 +08:00
|
|
|
function_entry snmp_functions[] = {
|
2002-10-17 10:51:22 +08:00
|
|
|
PHP_FE(snmpget, NULL)
|
|
|
|
PHP_FE(snmpwalk, NULL)
|
|
|
|
PHP_FE(snmprealwalk, NULL)
|
|
|
|
PHP_FALIAS(snmpwalkoid, snmprealwalk, NULL)
|
|
|
|
PHP_FE(snmp_get_quick_print, NULL)
|
|
|
|
PHP_FE(snmp_set_quick_print, NULL)
|
2002-11-12 05:37:19 +08:00
|
|
|
#ifdef HAVE_NET_SNMP
|
|
|
|
PHP_FE(snmp_set_enum_print, NULL)
|
|
|
|
PHP_FE(snmp_set_oid_numeric_print, NULL)
|
|
|
|
#endif
|
2002-10-17 10:51:22 +08:00
|
|
|
PHP_FE(snmpset, NULL)
|
2002-12-06 03:33:03 +08:00
|
|
|
|
|
|
|
PHP_FE(snmp3_get, NULL)
|
|
|
|
PHP_FE(snmp3_walk, NULL)
|
|
|
|
PHP_FE(snmp3_real_walk, NULL)
|
|
|
|
PHP_FE(snmp3_set, NULL)
|
2002-10-17 10:51:22 +08:00
|
|
|
{NULL,NULL,NULL}
|
1999-04-22 10:48:28 +08:00
|
|
|
};
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
/* {{{ snmp_module_entry
|
|
|
|
*/
|
1999-12-18 04:55:31 +08:00
|
|
|
zend_module_entry snmp_module_entry = {
|
2001-10-12 07:33:59 +08:00
|
|
|
STANDARD_MODULE_HEADER,
|
2000-07-02 05:34:45 +08:00
|
|
|
"snmp",
|
|
|
|
snmp_functions,
|
|
|
|
PHP_MINIT(snmp),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
PHP_MINFO(snmp),
|
2002-10-17 10:51:22 +08:00
|
|
|
NO_VERSION_YET,
|
2000-07-02 05:34:45 +08:00
|
|
|
STANDARD_MODULE_PROPERTIES
|
1999-04-22 10:48:28 +08:00
|
|
|
};
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
2000-05-23 17:33:51 +08:00
|
|
|
#ifdef COMPILE_DL_SNMP
|
2000-05-02 08:30:36 +08:00
|
|
|
ZEND_GET_MODULE(snmp)
|
1999-04-22 10:48:28 +08:00
|
|
|
#endif
|
|
|
|
|
1999-12-18 12:08:03 +08:00
|
|
|
/* THREAD_LS snmp_module php_snmp_module; - may need one of these at some point */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
/* {{{ PHP_MINIT_FUNCTION
|
|
|
|
*/
|
1999-12-18 12:08:03 +08:00
|
|
|
PHP_MINIT_FUNCTION(snmp)
|
|
|
|
{
|
2002-11-12 05:09:19 +08:00
|
|
|
init_snmp("snmpapp");
|
1999-04-22 10:48:28 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
2001-06-05 21:12:10 +08:00
|
|
|
/* {{{ PHP_MINFO_FUNCTION
|
|
|
|
*/
|
1999-12-18 12:08:03 +08:00
|
|
|
PHP_MINFO_FUNCTION(snmp)
|
|
|
|
{
|
2000-04-07 05:07:44 +08:00
|
|
|
php_info_print_table_start();
|
2002-11-12 02:45:50 +08:00
|
|
|
#ifdef HAVE_NET_SNMP
|
|
|
|
php_info_print_table_row(2, "NET-SNMP Support", "enabled");
|
|
|
|
php_info_print_table_row(2, "NET-SNMP Version", netsnmp_get_version());
|
|
|
|
#else
|
2000-04-07 05:07:44 +08:00
|
|
|
php_info_print_table_row(2, "UCD-SNMP Support", "enabled");
|
2000-08-30 23:52:07 +08:00
|
|
|
php_info_print_table_row(2, "UCD-SNMP Version", VersionInfo);
|
2002-11-12 02:45:50 +08:00
|
|
|
#endif
|
2000-04-07 05:07:44 +08:00
|
|
|
php_info_print_table_end();
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
2002-11-12 05:09:19 +08:00
|
|
|
/* {{{ php_snmp_internal
|
2001-06-05 21:12:10 +08:00
|
|
|
*
|
2002-11-12 05:09:19 +08:00
|
|
|
* Generic SNMP object fetcher (for both v3 and v1)
|
1999-08-05 04:56:33 +08:00
|
|
|
*
|
2002-10-17 10:51:22 +08:00
|
|
|
* st=1 snmpget() - query an agent and return a single value.
|
1999-08-05 04:56:33 +08:00
|
|
|
* st=2 snmpwalk() - walk the mib and return a single dimensional array
|
2002-10-17 10:51:22 +08:00
|
|
|
* containing the values.
|
|
|
|
* st=3 snmprealwalk() and snmpwalkoid() - walk the mib and return an
|
|
|
|
* array of oid,value pairs.
|
1999-08-05 04:56:33 +08:00
|
|
|
* st=5-8 ** Reserved **
|
2002-10-17 10:51:22 +08:00
|
|
|
* st=11 snmpset() - query an agent and set a single value
|
1999-08-05 04:56:33 +08:00
|
|
|
*
|
|
|
|
*/
|
2003-01-24 17:52:46 +08:00
|
|
|
static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS, int st,
|
|
|
|
struct snmp_session *session,
|
|
|
|
char *objid,
|
|
|
|
char type,
|
|
|
|
char* value)
|
2002-05-12 01:00:49 +08:00
|
|
|
{
|
2002-11-12 05:09:19 +08:00
|
|
|
struct snmp_session *ss;
|
1999-04-22 10:48:28 +08:00
|
|
|
struct snmp_pdu *pdu=NULL, *response;
|
|
|
|
struct variable_list *vars;
|
2002-10-17 10:51:22 +08:00
|
|
|
oid name[MAX_NAME_LEN];
|
|
|
|
int name_length;
|
1999-04-22 10:48:28 +08:00
|
|
|
oid root[MAX_NAME_LEN];
|
2002-11-12 05:09:19 +08:00
|
|
|
int rootlen = 0;
|
|
|
|
int gotroot = 0;
|
|
|
|
int status, count;
|
1999-04-22 10:48:28 +08:00
|
|
|
char buf[2048];
|
|
|
|
char buf2[2048];
|
|
|
|
int keepwalking=1;
|
2002-11-12 05:09:19 +08:00
|
|
|
char *err;
|
2000-03-26 03:58:19 +08:00
|
|
|
|
|
|
|
if (st >= 2) { /* walk */
|
1999-04-22 10:48:28 +08:00
|
|
|
rootlen = MAX_NAME_LEN;
|
2002-05-12 01:00:49 +08:00
|
|
|
if (strlen(objid)) { /* on a walk, an empty string means top of tree - no error */
|
|
|
|
if (read_objid(objid, root, &rootlen)) {
|
1999-04-22 10:48:28 +08:00
|
|
|
gotroot = 1;
|
|
|
|
} else {
|
2002-12-06 03:33:03 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid object identifier: %s", objid);
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
}
|
2002-05-12 01:00:49 +08:00
|
|
|
|
|
|
|
if (!gotroot) {
|
|
|
|
memmove((char *) root, (char *) objid_mib, sizeof(objid_mib));
|
1999-08-05 04:56:33 +08:00
|
|
|
rootlen = sizeof(objid_mib) / sizeof(oid);
|
|
|
|
gotroot = 1;
|
|
|
|
}
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
2001-07-13 13:09:40 +08:00
|
|
|
|
2002-11-12 05:09:19 +08:00
|
|
|
if ((ss = snmp_open(session)) == NULL) {
|
|
|
|
snmp_error(session, NULL, NULL, &err);
|
2002-10-16 10:33:47 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not open snmp connection: %s", err);
|
|
|
|
free(err);
|
1999-04-22 10:48:28 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2000-03-26 03:58:19 +08:00
|
|
|
|
|
|
|
if (st >= 2) {
|
1999-04-22 10:48:28 +08:00
|
|
|
memmove((char *)name, (char *)root, rootlen * sizeof(oid));
|
|
|
|
name_length = rootlen;
|
2001-07-13 13:21:37 +08:00
|
|
|
switch(st) {
|
|
|
|
case 2:
|
|
|
|
case 3:
|
2002-10-16 10:33:47 +08:00
|
|
|
array_init(return_value);
|
2001-07-13 13:21:37 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
RETVAL_TRUE;
|
|
|
|
break;
|
2000-07-02 05:34:45 +08:00
|
|
|
}
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
2000-03-26 03:58:19 +08:00
|
|
|
|
2002-05-12 01:00:49 +08:00
|
|
|
while (keepwalking) {
|
|
|
|
keepwalking = 0;
|
2000-03-26 03:58:19 +08:00
|
|
|
if (st == 1) {
|
|
|
|
pdu = snmp_pdu_create(SNMP_MSG_GET);
|
2002-10-16 10:33:47 +08:00
|
|
|
name_length = MAX_OID_LEN;
|
|
|
|
if (!snmp_parse_oid(objid, name, &name_length)) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid object identifier: %s", objid);
|
2001-10-16 02:36:43 +08:00
|
|
|
snmp_close(ss);
|
1999-04-22 10:48:28 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-08-05 04:56:33 +08:00
|
|
|
snmp_add_null_var(pdu, name, name_length);
|
2000-03-26 03:58:19 +08:00
|
|
|
} else if (st == 11) {
|
|
|
|
pdu = snmp_pdu_create(SNMP_MSG_SET);
|
1999-08-05 04:56:33 +08:00
|
|
|
if (snmp_add_var(pdu, name, name_length, type, value)) {
|
2003-01-24 17:52:46 +08:00
|
|
|
#ifdef HAVE_NET_SNMP
|
|
|
|
snprint_objid(buf, sizeof(buf), name, name_length);
|
|
|
|
#else
|
|
|
|
sprint_objid(buf, name, name_length);
|
|
|
|
#endif
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not add variable: %s %c %s", buf, type, value);
|
2001-10-16 02:36:43 +08:00
|
|
|
snmp_close(ss);
|
1999-08-05 04:56:33 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2000-03-26 03:58:19 +08:00
|
|
|
} else if (st >= 2) {
|
|
|
|
pdu = snmp_pdu_create(SNMP_MSG_GETNEXT);
|
|
|
|
snmp_add_null_var(pdu, name, name_length);
|
1999-08-05 04:56:33 +08:00
|
|
|
}
|
2002-11-12 05:09:19 +08:00
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
retry:
|
|
|
|
status = snmp_synch_response(ss, pdu, &response);
|
|
|
|
if (status == STAT_SUCCESS) {
|
|
|
|
if (response->errstat == SNMP_ERR_NOERROR) {
|
2000-03-26 03:58:19 +08:00
|
|
|
for (vars = response->variables; vars; vars = vars->next_variable) {
|
|
|
|
if (st >= 2 && st != 11 &&
|
|
|
|
(vars->name_length < rootlen || memcmp(root, vars->name, rootlen * sizeof(oid)))) {
|
1999-04-22 10:48:28 +08:00
|
|
|
continue; /* not part of this subtree */
|
2000-03-26 03:58:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (st != 11) {
|
2002-10-15 08:43:34 +08:00
|
|
|
#ifdef HAVE_NET_SNMP
|
2002-10-16 08:29:56 +08:00
|
|
|
snprint_value(buf, sizeof(buf), vars->name, vars->name_length, vars);
|
2002-10-15 08:43:34 +08:00
|
|
|
#else
|
2002-11-12 05:09:19 +08:00
|
|
|
sprint_value(buf,vars->name, vars->name_length, vars);
|
2002-10-15 08:43:34 +08:00
|
|
|
#endif
|
2000-03-26 03:58:19 +08:00
|
|
|
}
|
2002-05-12 01:00:49 +08:00
|
|
|
|
2000-03-26 03:58:19 +08:00
|
|
|
if (st == 1) {
|
1999-04-22 10:48:28 +08:00
|
|
|
RETVAL_STRING(buf,1);
|
2000-03-26 03:58:19 +08:00
|
|
|
} else if (st == 2) {
|
|
|
|
add_next_index_string(return_value,buf,1); /* Add to returned array */
|
|
|
|
} else if (st == 3) {
|
2002-10-15 08:43:34 +08:00
|
|
|
#ifdef HAVE_NET_SNMP
|
2002-10-16 08:29:56 +08:00
|
|
|
snprint_objid(buf2, sizeof(buf2), vars->name, vars->name_length);
|
2002-10-15 08:43:34 +08:00
|
|
|
#else
|
2002-11-12 05:09:19 +08:00
|
|
|
sprint_objid(buf2, vars->name, vars->name_length);
|
2002-10-15 08:43:34 +08:00
|
|
|
#endif
|
1999-04-22 10:48:28 +08:00
|
|
|
add_assoc_string(return_value,buf2,buf,1);
|
|
|
|
}
|
2000-03-26 03:58:19 +08:00
|
|
|
if (st >= 2 && st != 11) {
|
2002-10-14 10:46:52 +08:00
|
|
|
if (vars->type != SNMP_ENDOFMIBVIEW &&
|
|
|
|
vars->type != SNMP_NOSUCHOBJECT && vars->type != SNMP_NOSUCHINSTANCE) {
|
1999-04-22 10:48:28 +08:00
|
|
|
memmove((char *)name, (char *)vars->name,vars->name_length * sizeof(oid));
|
|
|
|
name_length = vars->name_length;
|
|
|
|
keepwalking = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2000-03-26 03:58:19 +08:00
|
|
|
if (st != 2 || response->errstat != SNMP_ERR_NOSUCHNAME) {
|
2002-10-16 10:33:47 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error in packet: %s", snmp_errstring(response->errstat));
|
1999-04-22 10:48:28 +08:00
|
|
|
if (response->errstat == SNMP_ERR_NOSUCHNAME) {
|
2000-03-26 03:58:19 +08:00
|
|
|
for (count=1, vars = response->variables; vars && count != response->errindex;
|
1999-08-05 04:56:33 +08:00
|
|
|
vars = vars->next_variable, count++);
|
2000-03-26 03:58:19 +08:00
|
|
|
if (vars) {
|
2002-10-15 08:43:34 +08:00
|
|
|
#ifdef HAVE_NET_SNMP
|
2002-10-16 08:29:56 +08:00
|
|
|
snprint_objid(buf, sizeof(buf), vars->name, vars->name_length);
|
2002-10-15 08:43:34 +08:00
|
|
|
#else
|
2002-11-12 05:09:19 +08:00
|
|
|
sprint_objid(buf,vars->name, vars->name_length);
|
2002-10-15 08:43:34 +08:00
|
|
|
#endif
|
2000-03-26 03:58:19 +08:00
|
|
|
}
|
2002-10-16 10:33:47 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "This name does not exist: %s",buf);
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
2000-03-26 03:58:19 +08:00
|
|
|
if (st == 1) {
|
|
|
|
if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GET)) != NULL) {
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
} else if (st == 11) {
|
|
|
|
if ((pdu = snmp_fix_pdu(response, SNMP_MSG_SET)) != NULL) {
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
} else if (st >= 2) {
|
|
|
|
if ((pdu = snmp_fix_pdu(response, SNMP_MSG_GETNEXT)) != NULL) {
|
|
|
|
goto retry;
|
|
|
|
}
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
2001-10-16 02:36:43 +08:00
|
|
|
snmp_close(ss);
|
1999-04-22 10:48:28 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (status == STAT_TIMEOUT) {
|
2002-12-06 03:33:03 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "No response from %s", session->peername);
|
2002-10-16 10:33:47 +08:00
|
|
|
if (st == 2 || st == 3) {
|
|
|
|
zval_dtor(return_value);
|
|
|
|
}
|
2001-10-16 02:36:43 +08:00
|
|
|
snmp_close(ss);
|
1999-04-22 10:48:28 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
} else { /* status == STAT_ERROR */
|
2002-12-06 03:33:03 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "An error occurred, quitting");
|
2002-10-16 10:33:47 +08:00
|
|
|
if (st == 2 || st == 3) {
|
|
|
|
zval_dtor(return_value);
|
|
|
|
}
|
2001-10-16 02:36:43 +08:00
|
|
|
snmp_close(ss);
|
1999-04-22 10:48:28 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2000-03-26 03:58:19 +08:00
|
|
|
if (response) {
|
|
|
|
snmp_free_pdu(response);
|
|
|
|
}
|
1999-04-22 10:48:28 +08:00
|
|
|
} /* keepwalking */
|
|
|
|
snmp_close(ss);
|
|
|
|
}
|
2001-06-05 21:12:10 +08:00
|
|
|
/* }}} */
|
1999-04-22 10:48:28 +08:00
|
|
|
|
2002-11-12 05:09:19 +08:00
|
|
|
/* {{{ php_snmp
|
|
|
|
*
|
|
|
|
* Generic SNMPv1 handler
|
|
|
|
* This function makes use of the internal SNMP object fetcher.
|
|
|
|
* The object fetcher is shared with SNMPv3.
|
|
|
|
*
|
|
|
|
* st=1 snmpget() - query an agent and return a single value.
|
|
|
|
* st=2 snmpwalk() - walk the mib and return a single dimensional array
|
|
|
|
* containing the values.
|
|
|
|
* st=3 snmprealwalk() and snmpwalkoid() - walk the mib and return an
|
|
|
|
* array of oid,value pairs.
|
|
|
|
* st=5-8 ** Reserved **
|
|
|
|
* st=11 snmpset() - query an agent and set a single value
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st)
|
|
|
|
{
|
|
|
|
zval **a1, **a2, **a3, **a4, **a5, **a6, **a7;
|
|
|
|
struct snmp_session session;
|
|
|
|
long timeout=SNMP_DEFAULT_TIMEOUT;
|
|
|
|
long retries=SNMP_DEFAULT_RETRIES;
|
|
|
|
int myargc = ZEND_NUM_ARGS();
|
2002-12-06 03:33:03 +08:00
|
|
|
char type = (char) 0;
|
|
|
|
char *value = (char *) 0;
|
2002-11-12 05:09:19 +08:00
|
|
|
char hostname[MAX_NAME_LEN];
|
|
|
|
int remote_port = 161;
|
|
|
|
char *pptr;
|
|
|
|
|
|
|
|
if (myargc < 3 || myargc > 7 ||
|
|
|
|
zend_get_parameters_ex(myargc, &a1, &a2, &a3, &a4, &a5, &a6, &a7) == FAILURE) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
convert_to_string_ex(a1);
|
|
|
|
convert_to_string_ex(a2);
|
|
|
|
convert_to_string_ex(a3);
|
|
|
|
|
|
|
|
if (st == 11) {
|
|
|
|
if (myargc < 5) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
convert_to_string_ex(a4);
|
|
|
|
convert_to_string_ex(a5);
|
2002-12-06 03:33:03 +08:00
|
|
|
|
2002-11-12 05:09:19 +08:00
|
|
|
if(myargc > 5) {
|
|
|
|
convert_to_long_ex(a6);
|
|
|
|
timeout = Z_LVAL_PP(a6);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(myargc > 6) {
|
|
|
|
convert_to_long_ex(a7);
|
|
|
|
retries = Z_LVAL_PP(a7);
|
|
|
|
}
|
|
|
|
|
|
|
|
type = Z_STRVAL_PP(a4)[0];
|
|
|
|
value = Z_STRVAL_PP(a5);
|
|
|
|
} else {
|
|
|
|
if(myargc > 3) {
|
|
|
|
convert_to_long_ex(a4);
|
|
|
|
timeout = Z_LVAL_PP(a4);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(myargc > 4) {
|
|
|
|
convert_to_long_ex(a5);
|
|
|
|
retries = Z_LVAL_PP(a5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
snmp_sess_init(&session);
|
|
|
|
strcpy (hostname, Z_STRVAL_PP(a1));
|
|
|
|
if ((pptr = strchr (hostname, ':'))) {
|
|
|
|
remote_port = strtol (pptr + 1, NULL, 0);
|
|
|
|
*pptr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
session.peername = hostname;
|
|
|
|
session.remote_port = remote_port;
|
|
|
|
session.version = SNMP_VERSION_1;
|
|
|
|
/*
|
|
|
|
* FIXME: potential memory leak
|
|
|
|
* This is a workaround for an "artifact" (Mike Slifcak)
|
|
|
|
* in (at least) ucd-snmp 3.6.1 which frees
|
|
|
|
* memory it did not allocate
|
|
|
|
*/
|
|
|
|
#ifdef UCD_SNMP_HACK
|
|
|
|
session.community = (u_char *)strdup(Z_STRVAL_PP(a2)); /* memory freed by SNMP library, strdup NOT estrdup */
|
|
|
|
#else
|
|
|
|
session.community = (u_char *)Z_STRVAL_PP(a2);
|
|
|
|
#endif
|
|
|
|
session.community_len = Z_STRLEN_PP(a2);
|
|
|
|
session.retries = retries;
|
|
|
|
session.timeout = timeout;
|
|
|
|
|
|
|
|
session.authenticator = NULL;
|
|
|
|
|
2003-01-24 17:52:46 +08:00
|
|
|
php_snmp_internal(INTERNAL_FUNCTION_PARAM_PASSTHRU, st, &session, Z_STRVAL_PP(a3), type, value);
|
2002-11-12 05:09:19 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
/* {{{ proto string snmpget(string host, string community, string object_id [, int timeout [, int retries]])
|
2000-03-26 06:27:30 +08:00
|
|
|
Fetch a SNMP object */
|
2001-08-05 09:43:02 +08:00
|
|
|
PHP_FUNCTION(snmpget)
|
|
|
|
{
|
1999-12-18 12:08:03 +08:00
|
|
|
php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,1);
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2000-03-25 12:05:13 +08:00
|
|
|
/* {{{ proto array snmpwalk(string host, string community, string object_id [, int timeout [, int retries]])
|
2000-02-24 15:38:19 +08:00
|
|
|
Return all objects under the specified object id */
|
2001-08-05 09:43:02 +08:00
|
|
|
PHP_FUNCTION(snmpwalk)
|
|
|
|
{
|
2000-09-15 04:22:02 +08:00
|
|
|
php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,2);
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2000-03-25 12:05:13 +08:00
|
|
|
/* {{{ proto array snmprealwalk(string host, string community, string object_id [, int timeout [, int retries]])
|
2000-02-24 15:38:19 +08:00
|
|
|
Return all objects including their respective object id withing the specified one */
|
2001-08-05 09:43:02 +08:00
|
|
|
PHP_FUNCTION(snmprealwalk)
|
|
|
|
{
|
2000-09-15 04:22:02 +08:00
|
|
|
php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,3);
|
1999-04-22 10:48:28 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2000-03-26 03:58:19 +08:00
|
|
|
/* {{{ proto bool snmp_get_quick_print(void)
|
2000-02-24 15:38:19 +08:00
|
|
|
Return the current status of quick_print */
|
2001-08-05 09:43:02 +08:00
|
|
|
PHP_FUNCTION(snmp_get_quick_print)
|
|
|
|
{
|
2001-08-13 15:55:39 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 0) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2001-08-13 14:43:47 +08:00
|
|
|
|
2002-10-16 08:58:15 +08:00
|
|
|
#ifdef HAVE_NET_SNMP
|
|
|
|
RETURN_BOOL(netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT));
|
|
|
|
#else
|
|
|
|
RETURN_BOOL(snmp_get_quick_print());
|
|
|
|
#endif
|
1999-08-05 04:56:33 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto void snmp_set_quick_print(int quick_print)
|
2000-02-24 15:38:19 +08:00
|
|
|
Return all objects including their respective object id withing the specified one */
|
2001-08-05 09:43:02 +08:00
|
|
|
PHP_FUNCTION(snmp_set_quick_print)
|
|
|
|
{
|
2001-08-13 14:43:47 +08:00
|
|
|
int argc = ZEND_NUM_ARGS();
|
|
|
|
long a1;
|
|
|
|
|
2001-08-14 03:31:18 +08:00
|
|
|
if (zend_parse_parameters(argc TSRMLS_CC, "l", &a1) == FAILURE) {
|
2001-08-13 14:43:47 +08:00
|
|
|
return;
|
2001-08-14 03:31:18 +08:00
|
|
|
}
|
2001-08-13 15:55:39 +08:00
|
|
|
|
2002-10-16 08:58:15 +08:00
|
|
|
#ifdef HAVE_NET_SNMP
|
|
|
|
netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT, (int) a1);
|
|
|
|
#else
|
2001-08-13 14:43:47 +08:00
|
|
|
snmp_set_quick_print((int)a1);
|
2002-10-16 08:58:15 +08:00
|
|
|
#endif
|
1999-08-05 04:56:33 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-11-12 05:37:19 +08:00
|
|
|
#ifdef HAVE_NET_SNMP
|
|
|
|
/* {{{ proto void snmp_set_enum_print(int enum_print)
|
|
|
|
Return all values that are enums with their enum value instead of the raw integer */
|
|
|
|
PHP_FUNCTION(snmp_set_enum_print)
|
|
|
|
{
|
|
|
|
int argc = ZEND_NUM_ARGS();
|
|
|
|
long a1;
|
|
|
|
|
|
|
|
if (zend_parse_parameters(argc TSRMLS_CC, "l", &a1) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM, (int) a1);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto void snmp_set_oid_numeric_print(int oid_numeric_print)
|
|
|
|
Return all objects including their respective object id withing the specified one */
|
|
|
|
PHP_FUNCTION(snmp_set_oid_numeric_print)
|
|
|
|
{
|
|
|
|
int argc = ZEND_NUM_ARGS();
|
|
|
|
long a1;
|
|
|
|
|
|
|
|
if (zend_parse_parameters(argc TSRMLS_CC, "l", &a1) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((int) a1 != 0) {
|
2002-12-06 03:33:03 +08:00
|
|
|
netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID,
|
|
|
|
NETSNMP_DS_LIB_OID_OUTPUT_FORMAT,
|
|
|
|
NETSNMP_OID_OUTPUT_NUMERIC);
|
|
|
|
}
|
2002-11-12 05:37:19 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
#endif
|
|
|
|
|
1999-08-05 04:56:33 +08:00
|
|
|
/* {{{ proto int snmpset(string host, string community, string object_id, string type, mixed value [, int timeout [, int retries]])
|
2000-02-24 15:38:19 +08:00
|
|
|
Set the value of a SNMP object */
|
2001-08-05 09:43:02 +08:00
|
|
|
PHP_FUNCTION(snmpset)
|
|
|
|
{
|
1999-12-18 12:08:03 +08:00
|
|
|
php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,11);
|
1999-08-05 04:56:33 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-11-12 05:09:19 +08:00
|
|
|
/* {{{ proto int netsnmp_session_set_sec_name(struct snmp_session *s, char *name)
|
2002-12-06 03:33:03 +08:00
|
|
|
Set the security name in the snmpv3 session */
|
|
|
|
static int netsnmp_session_set_sec_name(struct snmp_session *s, char *name)
|
2002-11-12 05:09:19 +08:00
|
|
|
{
|
2002-12-06 03:33:03 +08:00
|
|
|
if ((s) && (name)) {
|
|
|
|
s->securityName = strdup(name);
|
|
|
|
s->securityNameLen = strlen(s->securityName);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (-1);
|
2002-11-12 05:09:19 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto int netsnmp_session_set_sec_level(struct snmp_session *s, char *level)
|
2002-12-06 03:33:03 +08:00
|
|
|
Set the security level in the snmpv3 session */
|
2002-12-11 01:07:40 +08:00
|
|
|
static int netsnmp_session_set_sec_level(struct snmp_session *s, char *level TSRMLS_DC)
|
2002-11-12 05:09:19 +08:00
|
|
|
{
|
2002-12-06 03:33:03 +08:00
|
|
|
if ((s) && (level)) {
|
|
|
|
if (!strcasecmp(level, "noAuthNoPriv") || !strcasecmp(level, "nanp")) {
|
|
|
|
s->securityLevel = SNMP_SEC_LEVEL_NOAUTH;
|
|
|
|
return (0);
|
|
|
|
} else if (!strcasecmp(level, "authNoPriv") || !strcasecmp(level, "anp")) {
|
|
|
|
s->securityLevel = SNMP_SEC_LEVEL_AUTHNOPRIV;
|
|
|
|
return (0);
|
|
|
|
} else if (!strcasecmp(level, "authPriv") || !strcasecmp(level, "ap")) {
|
|
|
|
s->securityLevel = SNMP_SEC_LEVEL_AUTHPRIV;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid security level: %s", level);
|
|
|
|
}
|
|
|
|
return (-1);
|
2002-11-12 05:09:19 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto int netsnmp_session_set_auth_protocol(struct snmp_session *s, char *prot)
|
2002-12-06 03:33:03 +08:00
|
|
|
Set the authentication protocol in the snmpv3 session */
|
2002-12-11 01:07:40 +08:00
|
|
|
static int netsnmp_session_set_auth_protocol(struct snmp_session *s, char *prot TSRMLS_DC)
|
2002-11-12 05:09:19 +08:00
|
|
|
{
|
2002-12-06 03:33:03 +08:00
|
|
|
if ((s) && (prot)) {
|
|
|
|
if (!strcasecmp(prot, "MD5")) {
|
|
|
|
s->securityAuthProto = usmHMACMD5AuthProtocol;
|
|
|
|
s->securityAuthProtoLen = OIDSIZE(usmHMACMD5AuthProtocol);
|
|
|
|
return (0);
|
|
|
|
} else if (!strcasecmp(prot, "SHA")) {
|
|
|
|
s->securityAuthProto = usmHMACSHA1AuthProtocol;
|
|
|
|
s->securityAuthProtoLen = OIDSIZE(usmHMACSHA1AuthProtocol);
|
|
|
|
return (0);
|
|
|
|
} else if (strlen(prot)) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid authentication protocol: %s", prot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (-1);
|
2002-11-12 05:09:19 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto int netsnmp_session_set_sec_protocol(struct snmp_session *s, char *prot)
|
2002-12-06 03:33:03 +08:00
|
|
|
Set the security protocol in the snmpv3 session */
|
2002-12-11 01:07:40 +08:00
|
|
|
static int netsnmp_session_set_sec_protocol(struct snmp_session *s, char *prot TSRMLS_DC)
|
2002-11-12 05:09:19 +08:00
|
|
|
{
|
2002-12-06 03:33:03 +08:00
|
|
|
if ((s) && (prot)) {
|
|
|
|
if (!strcasecmp(prot, "DES")) {
|
|
|
|
s->securityPrivProto = usmDESPrivProtocol;
|
|
|
|
s->securityPrivProtoLen = OIDSIZE(usmDESPrivProtocol);
|
|
|
|
return (0);
|
2002-11-12 05:09:19 +08:00
|
|
|
#ifdef HAVE_AES
|
2002-12-06 03:33:03 +08:00
|
|
|
} else if (!strcasecmp(prot, "AES128")) {
|
|
|
|
s->securityPrivProto = usmAES128PrivProtocol;
|
|
|
|
s->securityPrivProtoLen = OIDSIZE(usmAES128PrivProtocol);
|
|
|
|
return (0);
|
|
|
|
} else if (!strcasecmp(prot, "AES192")) {
|
|
|
|
s->securityPrivProto = usmAES192PrivProtocol;
|
|
|
|
s->securityPrivProtoLen = OIDSIZE(usmAES192PrivProtocol);
|
|
|
|
return (0);
|
|
|
|
} else if (!strcasecmp(prot, "AES256")) {
|
|
|
|
s->securityPrivProto = usmAES256PrivProtocol;
|
|
|
|
s->securityPrivProtoLen = OIDSIZE(usmAES256PrivProtocol);
|
|
|
|
return (0);
|
2002-11-12 05:09:19 +08:00
|
|
|
#endif
|
2002-12-06 03:33:03 +08:00
|
|
|
} else if (strlen(prot)) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid privacy protocol: %s", prot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (-1);
|
2002-11-12 05:09:19 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto int netsnmp_session_gen_auth_key(struct snmp_session *s, char *pass)
|
2002-12-06 03:33:03 +08:00
|
|
|
Make key from pass phrase in the snmpv3 session */
|
2002-12-11 01:07:40 +08:00
|
|
|
static int netsnmp_session_gen_auth_key(struct snmp_session *s, char *pass TSRMLS_DC)
|
2002-11-12 05:09:19 +08:00
|
|
|
{
|
2002-12-06 03:33:03 +08:00
|
|
|
/*
|
|
|
|
* make master key from pass phrases
|
|
|
|
*/
|
|
|
|
if ((s) && (pass) && strlen(pass)) {
|
|
|
|
s->securityAuthKeyLen = USM_AUTH_KU_LEN;
|
|
|
|
if (s->securityAuthProto == NULL) {
|
|
|
|
/* get .conf set default */
|
|
|
|
oid *def = get_default_authtype(&(s->securityAuthProtoLen));
|
|
|
|
s->securityAuthProto = snmp_duplicate_objid(def, s->securityAuthProtoLen);
|
|
|
|
}
|
|
|
|
if (s->securityAuthProto == NULL) {
|
|
|
|
/* assume MD5 */
|
|
|
|
s->securityAuthProto =
|
|
|
|
snmp_duplicate_objid(usmHMACMD5AuthProtocol, OIDSIZE(usmHMACMD5AuthProtocol));
|
|
|
|
s->securityAuthProtoLen = OIDSIZE(usmHMACMD5AuthProtocol);
|
|
|
|
}
|
|
|
|
if (generate_Ku(s->securityAuthProto, s->securityAuthProtoLen,
|
|
|
|
(u_char *) pass, strlen(pass),
|
|
|
|
s->securityAuthKey, &(s->securityAuthKeyLen)) != SNMPERR_SUCCESS) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error generating a key for authentication pass phrase");
|
|
|
|
return (-2);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (-1);
|
2002-11-12 05:09:19 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto int netsnmp_session_gen_sec_key(struct snmp_session *s, u_char *pass)
|
2002-12-06 03:33:03 +08:00
|
|
|
Make key from pass phrase in the snmpv3 session */
|
2002-12-11 01:07:40 +08:00
|
|
|
static int netsnmp_session_gen_sec_key(struct snmp_session *s, u_char *pass TSRMLS_DC)
|
2002-11-12 05:09:19 +08:00
|
|
|
{
|
2002-12-06 03:33:03 +08:00
|
|
|
if ((s) && (pass) && strlen(pass)) {
|
|
|
|
s->securityPrivKeyLen = USM_PRIV_KU_LEN;
|
|
|
|
if (s->securityPrivProto == NULL) {
|
|
|
|
/* get .conf set default */
|
|
|
|
oid *def = get_default_privtype(&(s->securityPrivProtoLen));
|
|
|
|
s->securityPrivProto = snmp_duplicate_objid(def, s->securityPrivProtoLen);
|
|
|
|
}
|
|
|
|
if (s->securityPrivProto == NULL) {
|
|
|
|
/* assume DES */
|
|
|
|
s->securityPrivProto = snmp_duplicate_objid(usmDESPrivProtocol,
|
|
|
|
OIDSIZE(usmDESPrivProtocol));
|
|
|
|
s->securityPrivProtoLen = OIDSIZE(usmDESPrivProtocol);
|
|
|
|
}
|
|
|
|
if (generate_Ku(s->securityAuthProto, s->securityAuthProtoLen,
|
|
|
|
pass, strlen(pass),
|
|
|
|
s->securityPrivKey, &(s->securityPrivKeyLen)) != SNMPERR_SUCCESS) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error generating a key for privacy pass phrase");
|
|
|
|
return (-2);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (-1);
|
2002-11-12 05:09:19 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto void php_snmpv3(INTERNAL_FUNCTION_PARAMETERS, int st)
|
|
|
|
*
|
|
|
|
* Generic SNMPv3 object fetcher
|
|
|
|
* From here is passed on the the common internal object fetcher.
|
|
|
|
*
|
2002-12-06 03:33:03 +08:00
|
|
|
* st=1 snmp3_get() - query an agent and return a single value.
|
|
|
|
* st=2 snmp3_walk() - walk the mib and return a single dimensional array
|
|
|
|
* containing the values.
|
|
|
|
* st=3 snmp3_real_walk() - walk the mib and return an
|
|
|
|
* array of oid,value pairs.
|
|
|
|
* st=11 snmp3_set() - query an agent and set a single value
|
2002-11-12 05:09:19 +08:00
|
|
|
*
|
|
|
|
*/
|
2003-01-24 17:40:53 +08:00
|
|
|
static void php_snmpv3(INTERNAL_FUNCTION_PARAMETERS, int st)
|
|
|
|
{
|
2002-11-12 05:09:19 +08:00
|
|
|
zval **a1, **a2, **a3, **a4, **a5, **a6, **a7, **a8, **a9, **a10, **a11, **a12;
|
|
|
|
struct snmp_session session;
|
|
|
|
long timeout=SNMP_DEFAULT_TIMEOUT;
|
|
|
|
long retries=SNMP_DEFAULT_RETRIES;
|
|
|
|
int myargc = ZEND_NUM_ARGS();
|
|
|
|
char type = (char) 0;
|
|
|
|
char *value = (char *) 0;
|
|
|
|
char hostname[MAX_NAME_LEN];
|
|
|
|
int remote_port = 161;
|
|
|
|
char *pptr;
|
|
|
|
|
|
|
|
if (myargc < 8 || myargc > 12 ||
|
|
|
|
zend_get_parameters_ex(myargc, &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10, &a11, &a12) == FAILURE) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
snmp_sess_init(&session);
|
2002-12-06 03:33:03 +08:00
|
|
|
/* This is all SNMPv3 */
|
2002-11-12 05:09:19 +08:00
|
|
|
session.version = SNMP_VERSION_3;
|
|
|
|
|
2002-12-06 03:33:03 +08:00
|
|
|
/* Reading the hostname and its optional non-default port number */
|
2002-11-12 05:09:19 +08:00
|
|
|
convert_to_string_ex(a1);
|
|
|
|
strcpy(hostname, Z_STRVAL_PP(a1));
|
|
|
|
if ((pptr = strchr (hostname, ':'))) {
|
|
|
|
remote_port = strtol (pptr + 1, NULL, 0);
|
|
|
|
*pptr = 0;
|
|
|
|
}
|
|
|
|
session.peername = hostname;
|
|
|
|
session.remote_port = remote_port;
|
|
|
|
|
2002-12-06 03:33:03 +08:00
|
|
|
/* Setting the security name. */
|
2002-11-12 05:09:19 +08:00
|
|
|
convert_to_string_ex(a2);
|
2002-12-06 03:33:03 +08:00
|
|
|
if (netsnmp_session_set_sec_name(&session, Z_STRVAL_PP(a2))) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could net set security name: %s", Z_STRVAL_PP(a2));
|
2002-11-12 05:09:19 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-12-06 03:33:03 +08:00
|
|
|
/* Setting the security level. */
|
|
|
|
convert_to_string_ex(a3);
|
2002-12-11 01:07:40 +08:00
|
|
|
if (netsnmp_session_set_sec_level(&session, Z_STRVAL_PP(a3) TSRMLS_CC)) {
|
2002-12-06 03:33:03 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid security level: %s", a3);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2002-11-12 05:09:19 +08:00
|
|
|
|
2002-12-06 03:33:03 +08:00
|
|
|
/* Setting the authentication protocol. */
|
|
|
|
convert_to_string_ex(a4);
|
2002-12-11 01:07:40 +08:00
|
|
|
if (netsnmp_session_set_auth_protocol(&session, Z_STRVAL_PP(a4) TSRMLS_CC)) {
|
2002-12-06 03:33:03 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid authentication protocol: %s", Z_STRVAL_PP(a4));
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2003-01-24 17:40:53 +08:00
|
|
|
|
2002-12-06 03:33:03 +08:00
|
|
|
/* Setting the authentication passphrase. */
|
|
|
|
convert_to_string_ex(a5);
|
2002-12-11 01:07:40 +08:00
|
|
|
if (netsnmp_session_gen_auth_key(&session, Z_STRVAL_PP(a5) TSRMLS_CC)) {
|
2002-12-06 03:33:03 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not generate key for authentication pass phrase: %s", Z_STRVAL_PP(a4));
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setting the security protocol. */
|
|
|
|
convert_to_string_ex(a6);
|
2002-12-11 01:07:40 +08:00
|
|
|
if (netsnmp_session_set_sec_protocol(&session, Z_STRVAL_PP(a6) TSRMLS_CC) &&
|
2002-12-06 03:33:03 +08:00
|
|
|
(0 != strlen(Z_STRVAL_PP(a6)))) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid security protocol: %s", Z_STRVAL_PP(a6));
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2003-01-24 17:40:53 +08:00
|
|
|
|
2002-12-06 03:33:03 +08:00
|
|
|
/* Setting the security protocol passphrase. */
|
|
|
|
convert_to_string_ex(a7);
|
2002-12-11 01:07:40 +08:00
|
|
|
if (netsnmp_session_gen_sec_key(&session, Z_STRVAL_PP(a7) TSRMLS_CC) &&
|
2002-11-12 05:09:19 +08:00
|
|
|
(0 != strlen(Z_STRVAL_PP(a7)))) {
|
2002-12-06 03:33:03 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not generate key for security pass phrase: %s", Z_STRVAL_PP(a7));
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2002-11-12 05:09:19 +08:00
|
|
|
|
|
|
|
if (st == 11) {
|
|
|
|
if (myargc < 10) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
if (myargc > 10) {
|
|
|
|
convert_to_long_ex(a11);
|
|
|
|
timeout = Z_LVAL_PP(a11);
|
|
|
|
}
|
|
|
|
if (myargc > 11) {
|
|
|
|
convert_to_long_ex(a12);
|
|
|
|
retries = Z_LVAL_PP(a12);
|
|
|
|
}
|
|
|
|
convert_to_string_ex(a9);
|
|
|
|
convert_to_string_ex(a10);
|
2002-12-06 03:33:03 +08:00
|
|
|
type = Z_STRVAL_PP(a9)[0];
|
|
|
|
value = Z_STRVAL_PP(a10);
|
2002-11-12 05:09:19 +08:00
|
|
|
} else {
|
|
|
|
if (myargc > 8) {
|
|
|
|
convert_to_long_ex(a9);
|
|
|
|
timeout = Z_LVAL_PP(a9);
|
|
|
|
}
|
|
|
|
if (myargc > 9) {
|
|
|
|
convert_to_long_ex(a10);
|
|
|
|
retries = Z_LVAL_PP(a10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
session.retries = retries;
|
|
|
|
session.timeout = timeout;
|
|
|
|
|
2003-01-24 17:52:46 +08:00
|
|
|
php_snmp_internal(INTERNAL_FUNCTION_PARAM_PASSTHRU, st, &session, Z_STRVAL_PP(a8), type, value);
|
2002-11-12 05:09:19 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-12-06 03:33:03 +08:00
|
|
|
/* {{{ proto int snmp3_get(string host, string sec_name, string sec_level, string auth_protocol, string auth_passphrase, string priv_protocol, string priv_passphrase, string object_id [, int timeout [, int retries]])
|
2002-11-12 05:09:19 +08:00
|
|
|
Fetch the value of a SNMP object */
|
2002-12-06 03:33:03 +08:00
|
|
|
PHP_FUNCTION(snmp3_get)
|
2002-11-12 05:09:19 +08:00
|
|
|
{
|
2002-12-06 03:33:03 +08:00
|
|
|
php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
|
2002-11-12 05:09:19 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
2002-12-06 03:33:03 +08:00
|
|
|
/* {{{ proto int snmp3_walk(string host, string sec_name, string sec_level, string auth_protocol, string auth_passphrase, string priv_protocol, string priv_passphrase, string object_id [, int timeout [, int retries]])
|
2002-11-12 05:09:19 +08:00
|
|
|
Fetch the value of a SNMP object */
|
2002-12-06 03:33:03 +08:00
|
|
|
PHP_FUNCTION(snmp3_walk)
|
2002-11-12 05:09:19 +08:00
|
|
|
{
|
2002-12-06 03:33:03 +08:00
|
|
|
php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2);
|
2002-11-12 05:09:19 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-12-06 03:33:03 +08:00
|
|
|
/* {{{ proto int snmp3_real_walk(string host, string sec_name, string sec_level, string auth_protocol, string auth_passphrase, string priv_protocol, string priv_passphrase, string object_id [, int timeout [, int retries]])
|
2002-11-12 05:09:19 +08:00
|
|
|
Fetch the value of a SNMP object */
|
2002-12-06 03:33:03 +08:00
|
|
|
PHP_FUNCTION(snmp3_real_walk)
|
2002-11-12 05:09:19 +08:00
|
|
|
{
|
2002-12-06 03:33:03 +08:00
|
|
|
php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, 3);
|
2002-11-12 05:09:19 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-12-06 03:33:03 +08:00
|
|
|
/* {{{ proto int snmp3_set(string host, string sec_name, string sec_level, string auth_protocol, string auth_passphrase, string priv_protocol, string priv_passphrase, string object_id, string type, mixed value [, int timeout [, int retries]])
|
2002-11-12 05:09:19 +08:00
|
|
|
Fetch the value of a SNMP object */
|
2002-12-06 03:33:03 +08:00
|
|
|
PHP_FUNCTION(snmp3_set)
|
2002-11-12 05:09:19 +08:00
|
|
|
{
|
2002-12-06 03:33:03 +08:00
|
|
|
php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU, 11);
|
2002-11-12 05:09:19 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
1999-04-22 10:48:28 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2001-06-05 21:12:10 +08:00
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
2001-09-09 21:29:31 +08:00
|
|
|
* vim600: sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: sw=4 ts=4
|
2001-06-05 21:12:10 +08:00
|
|
|
*/
|