php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
snmp.c
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Authors: Rasmus Lerdorf <rasmus@php.net> |
14 | Mike Jackson <mhjack@tscnet.com> |
15 | Steven Lawrance <slawrance@technologist.com> |
16 | Harrie Hazewinkel <harrie@lisanza.net> |
17 | Johann Hanne <jonny@nurfuerspam.de> |
18 | Boris Lytockin <lytboris@gmail.com> |
19 +----------------------------------------------------------------------+
20 */
21
22#ifdef HAVE_CONFIG_H
23#include <config.h>
24#endif
25
26#include "php.h"
27#include "main/php_network.h"
28#include "ext/standard/info.h"
29
30#ifdef PHP_WIN32
31// avoid conflicting declarations of (v)asprintf()
32# define HAVE_ASPRINTF
33#endif
34#include "php_snmp.h"
35
36#include "zend_exceptions.h"
37#include "zend_smart_string.h"
39
40#ifdef HAVE_SNMP
41
42#include <sys/types.h>
43#include <errno.h>
44#ifdef PHP_WIN32
45#include <winsock2.h>
46#include <process.h>
47#include "win32/time.h"
48#else
49#include <sys/socket.h>
50#include <netinet/in.h>
51#include <arpa/inet.h>
52#include <netdb.h>
53#endif
54#ifdef HAVE_UNISTD_H
55#include <unistd.h>
56#endif
57#include <locale.h>
58
59#ifndef __P
60#ifdef __GNUC__
61#define __P(args) args
62#else
63#define __P(args) ()
64#endif
65#endif
66
67#include <net-snmp/net-snmp-config.h>
68#include <net-snmp/net-snmp-includes.h>
69
70#include "snmp_arginfo.h"
71
72/* For net-snmp prior to 5.4 */
73#ifndef HAVE_SHUTDOWN_SNMP_LOGGING
74extern netsnmp_log_handler *logh_head;
75#define shutdown_snmp_logging() \
76 { \
77 snmp_disable_log(); \
78 while(NULL != logh_head) \
79 netsnmp_remove_loghandler( logh_head ); \
80 }
81#endif
82
83typedef struct snmp_session php_snmp_session;
84
85#define PHP_SNMP_ADD_PROPERTIES(a, b) \
86{ \
87 int i = 0; \
88 while (b[i].name != NULL) { \
89 php_snmp_add_property((a), (b)[i].name, (b)[i].name_length, \
90 (php_snmp_read_t)(b)[i].read_func, (php_snmp_write_t)(b)[i].write_func); \
91 i++; \
92 } \
93}
94
96static PHP_GINIT_FUNCTION(snmp);
97
98/* constant - can be shared among threads */
99static const oid objid_mib[] = {1, 3, 6, 1, 2, 1};
100
101/* Handlers */
102static zend_object_handlers php_snmp_object_handlers;
103
104/* Class entries */
105zend_class_entry *php_snmp_ce;
106zend_class_entry *php_snmp_exception_ce;
107
108/* Class object properties */
109static HashTable php_snmp_properties;
110
111struct objid_query {
112 int count;
113 int offset;
114 int step;
115 zend_long non_repeaters;
116 zend_long max_repetitions;
117 int valueretrieval;
118 bool array_output;
119 bool oid_increasing_check;
120 snmpobjarg *vars;
121};
122
123/* query an agent with GET method */
124#define SNMP_CMD_GET (1<<0)
125/* query an agent with GETNEXT method */
126#define SNMP_CMD_GETNEXT (1<<1)
127/* query an agent with SET method */
128#define SNMP_CMD_SET (1<<2)
129/* walk the mib */
130#define SNMP_CMD_WALK (1<<3)
131/* force values-only output */
132#define SNMP_NUMERIC_KEYS (1<<7)
133/* use user-supplied OID names for keys in array output mode in GET method */
134#define SNMP_ORIGINAL_NAMES_AS_KEYS (1<<8)
135/* use OID suffix (`index') for keys in array output mode in WALK method */
136#define SNMP_USE_SUFFIX_AS_KEYS (1<<9)
137
138#ifdef COMPILE_DL_SNMP
139ZEND_GET_MODULE(snmp)
140#endif
141
142/* {{{ PHP_GINIT_FUNCTION */
143static PHP_GINIT_FUNCTION(snmp)
144{
145 snmp_globals->valueretrieval = SNMP_VALUE_LIBRARY;
146}
147/* }}} */
148
149#define PHP_SNMP_SESSION_FREE(a) { \
150 if ((*session)->a) { \
151 efree((*session)->a); \
152 (*session)->a = NULL; \
153 } \
154}
155
156static void netsnmp_session_free(php_snmp_session **session) /* {{{ */
157{
158 if (*session) {
159 PHP_SNMP_SESSION_FREE(peername);
160 PHP_SNMP_SESSION_FREE(community);
161 PHP_SNMP_SESSION_FREE(securityName);
162 PHP_SNMP_SESSION_FREE(contextEngineID);
163 efree(*session);
164 *session = NULL;
165 }
166}
167/* }}} */
168
169static void php_snmp_object_free_storage(zend_object *object) /* {{{ */
170{
171 php_snmp_object *intern = php_snmp_fetch_object(object);
172
173 if (!intern) {
174 return;
175 }
176
177 netsnmp_session_free(&(intern->session));
178
179 zend_object_std_dtor(&intern->zo);
180}
181/* }}} */
182
183static zend_object *php_snmp_object_new(zend_class_entry *class_type) /* {{{ */
184{
185 php_snmp_object *intern;
186
187 /* Allocate memory for it */
188 intern = zend_object_alloc(sizeof(php_snmp_object), class_type);
189
190 zend_object_std_init(&intern->zo, class_type);
191 object_properties_init(&intern->zo, class_type);
192
193 return &intern->zo;
194
195}
196/* }}} */
197
198/* {{{ php_snmp_error
199 *
200 * Record last SNMP-related error in object
201 *
202 */
203static void php_snmp_error(zval *object, int type, const char *format, ...)
204{
205 va_list args;
206 php_snmp_object *snmp_object = NULL;
207
208 if (object) {
209 snmp_object = Z_SNMP_P(object);
210 if (type == PHP_SNMP_ERRNO_NOERROR) {
211 memset(snmp_object->snmp_errstr, 0, sizeof(snmp_object->snmp_errstr));
212 } else {
213 va_start(args, format);
214 vsnprintf(snmp_object->snmp_errstr, sizeof(snmp_object->snmp_errstr) - 1, format, args);
215 va_end(args);
216 }
217 snmp_object->snmp_errno = type;
218 }
219
220 if (type == PHP_SNMP_ERRNO_NOERROR) {
221 return;
222 }
223
224 if (object && (snmp_object->exceptions_enabled & type)) {
225 zend_throw_exception_ex(php_snmp_exception_ce, type, "%s", snmp_object->snmp_errstr);
226 } else {
227 va_start(args, format);
228 php_verror(NULL, "", E_WARNING, format, args);
229 va_end(args);
230 }
231}
232
233/* }}} */
234
235/* {{{ php_snmp_getvalue
236*
237* SNMP value to zval converter
238*
239*/
240static void php_snmp_getvalue(struct variable_list *vars, zval *snmpval, int valueretrieval)
241{
242 zval val;
243 char sbuf[512];
244 char *buf = &(sbuf[0]);
245 char *dbuf = (char *)NULL;
246 int buflen = sizeof(sbuf) - 1;
247 int val_len = vars->val_len;
248
249 /* use emalloc() for large values, use static array otherwise */
250
251 /* There is no way to know the size of buffer snprint_value() needs in order to print a value there.
252 * So we are forced to probe it
253 */
254 while ((valueretrieval & SNMP_VALUE_PLAIN) == 0) {
255 *buf = '\0';
256 if (snprint_value(buf, buflen, vars->name, vars->name_length, vars) == -1) {
257 if (val_len > 512*1024) {
258 php_error_docref(NULL, E_WARNING, "snprint_value() asks for a buffer more than 512k, Net-SNMP bug?");
259 break;
260 }
261 /* buffer is not long enough to hold full output, double it */
262 val_len *= 2;
263 } else {
264 break;
265 }
266
267 if (buf == dbuf) {
268 dbuf = (char *)erealloc(dbuf, val_len + 1);
269 } else {
270 dbuf = (char *)emalloc(val_len + 1);
271 }
272
273 buf = dbuf;
274 buflen = val_len;
275 }
276
277 if((valueretrieval & SNMP_VALUE_PLAIN) && val_len > buflen){
278 dbuf = (char *)emalloc(val_len + 1);
279 buf = dbuf;
280 buflen = val_len;
281 }
282
283 if (valueretrieval & SNMP_VALUE_PLAIN) {
284 *buf = 0;
285 switch (vars->type) {
286 case ASN_BIT_STR: /* 0x03, asn1.h */
287 ZVAL_STRINGL(&val, (char *)vars->val.bitstring, vars->val_len);
288 break;
289
290 case ASN_OCTET_STR: /* 0x04, asn1.h */
291 case ASN_OPAQUE: /* 0x44, snmp_impl.h */
292 ZVAL_STRINGL(&val, (char *)vars->val.string, vars->val_len);
293 break;
294
295 case ASN_NULL: /* 0x05, asn1.h */
296 ZVAL_NULL(&val);
297 break;
298
299 case ASN_OBJECT_ID: /* 0x06, asn1.h */
300 snprint_objid(buf, buflen, vars->val.objid, vars->val_len / sizeof(oid));
302 break;
303
304 case ASN_IPADDRESS: /* 0x40, snmp_impl.h */
305 snprintf(buf, buflen, "%d.%d.%d.%d",
306 (vars->val.string)[0], (vars->val.string)[1],
307 (vars->val.string)[2], (vars->val.string)[3]);
308 buf[buflen]=0;
310 break;
311
312 case ASN_COUNTER: /* 0x41, snmp_impl.h */
313 case ASN_GAUGE: /* 0x42, snmp_impl.h */
314 /* ASN_UNSIGNED is the same as ASN_GAUGE */
315 case ASN_TIMETICKS: /* 0x43, snmp_impl.h */
316 case ASN_UINTEGER: /* 0x47, snmp_impl.h */
317 snprintf(buf, buflen, "%lu", *vars->val.integer);
318 buf[buflen]=0;
320 break;
321
322 case ASN_INTEGER: /* 0x02, asn1.h */
323 snprintf(buf, buflen, "%ld", *vars->val.integer);
324 buf[buflen]=0;
326 break;
327
328#if defined(NETSNMP_WITH_OPAQUE_SPECIAL_TYPES) || defined(OPAQUE_SPECIAL_TYPES)
329 case ASN_OPAQUE_FLOAT: /* 0x78, asn1.h */
330 snprintf(buf, buflen, "%f", *vars->val.floatVal);
332 break;
333
334 case ASN_OPAQUE_DOUBLE: /* 0x79, asn1.h */
335 snprintf(buf, buflen, "%f", *vars->val.doubleVal);
337 break;
338
339 case ASN_OPAQUE_I64: /* 0x80, asn1.h */
340 printI64(buf, vars->val.counter64);
342 break;
343
344 case ASN_OPAQUE_U64: /* 0x81, asn1.h */
345#endif
346 case ASN_COUNTER64: /* 0x46, snmp_impl.h */
347 printU64(buf, vars->val.counter64);
349 break;
350
351 default:
352 ZVAL_STRING(&val, "Unknown value type");
353 php_error_docref(NULL, E_WARNING, "Unknown value type: %u", vars->type);
354 break;
355 }
356 } else /* use Net-SNMP value translation */ {
357 /* we have desired string in buffer, just use it */
359 }
360
361 if (valueretrieval & SNMP_VALUE_OBJECT) {
362 object_init(snmpval);
363 add_property_long(snmpval, "type", vars->type);
364 add_property_zval(snmpval, "value", &val);
365 } else {
366 ZVAL_COPY(snmpval, &val);
367 }
369
370 if (dbuf){ /* malloc was used to store value */
371 efree(dbuf);
372 }
373}
374/* }}} */
375
376/* {{{ php_snmp_internal
377*
378* SNMP object fetcher/setter for all SNMP versions
379*
380*/
381static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS, int st,
382 struct snmp_session *session,
383 struct objid_query *objid_query)
384{
385 struct snmp_session *ss;
386 struct snmp_pdu *pdu=NULL, *response;
387 struct variable_list *vars;
388 oid root[MAX_NAME_LEN];
389 size_t rootlen = 0;
390 int status, count, found;
391 char buf[2048];
392 char buf2[2048];
393 bool keepwalking = true;
394 char *err;
395 zval snmpval;
396 int snmp_errno;
397
398 /* we start with retval=FALSE. If any actual data is acquired, retval will be set to appropriate type */
400
401 /* reset errno and errstr */
402 php_snmp_error(getThis(), PHP_SNMP_ERRNO_NOERROR, "");
403
404 if (st & SNMP_CMD_WALK) { /* remember root OID */
405 memcpy((char *)root, (char *)(objid_query->vars[0].name), (objid_query->vars[0].name_length) * sizeof(oid));
406 rootlen = objid_query->vars[0].name_length;
407 objid_query->offset = objid_query->count;
408 }
409
410 if ((ss = snmp_open(session)) == NULL) {
411 snmp_error(session, NULL, NULL, &err);
412 php_error_docref(NULL, E_WARNING, "Could not open snmp connection: %s", err);
413 free(err);
415 }
416
417 if ((st & SNMP_CMD_SET) && objid_query->count > objid_query->step) {
418 php_snmp_error(getThis(), PHP_SNMP_ERRNO_MULTIPLE_SET_QUERIES, "Cannot fit all OIDs for SET query into one packet, using multiple queries");
419 }
420
421 while (keepwalking) {
422 keepwalking = false;
423 if (st & SNMP_CMD_WALK) {
424 if (session->version == SNMP_VERSION_1) {
425 pdu = snmp_pdu_create(SNMP_MSG_GETNEXT);
426 } else {
427 pdu = snmp_pdu_create(SNMP_MSG_GETBULK);
428 pdu->non_repeaters = objid_query->non_repeaters;
429 pdu->max_repetitions = objid_query->max_repetitions;
430 }
431 snmp_add_null_var(pdu, objid_query->vars[0].name, objid_query->vars[0].name_length);
432 } else {
433 if (st & SNMP_CMD_GET) {
434 pdu = snmp_pdu_create(SNMP_MSG_GET);
435 } else if (st & SNMP_CMD_GETNEXT) {
436 pdu = snmp_pdu_create(SNMP_MSG_GETNEXT);
437 } else if (st & SNMP_CMD_SET) {
438 pdu = snmp_pdu_create(SNMP_MSG_SET);
439 } else {
440 snmp_close(ss);
441 php_error_docref(NULL, E_ERROR, "Unknown SNMP command (internals)");
443 }
444 for (count = 0; objid_query->offset < objid_query->count && count < objid_query->step; objid_query->offset++, count++){
445 if (st & SNMP_CMD_SET) {
446 if ((snmp_errno = snmp_add_var(pdu, objid_query->vars[objid_query->offset].name, objid_query->vars[objid_query->offset].name_length, objid_query->vars[objid_query->offset].type, objid_query->vars[objid_query->offset].value))) {
447 snprint_objid(buf, sizeof(buf), objid_query->vars[objid_query->offset].name, objid_query->vars[objid_query->offset].name_length);
448 php_snmp_error(getThis(), PHP_SNMP_ERRNO_OID_PARSING_ERROR, "Could not add variable: OID='%s' type='%c' value='%s': %s", buf, objid_query->vars[objid_query->offset].type, objid_query->vars[objid_query->offset].value, snmp_api_errstring(snmp_errno));
449 snmp_free_pdu(pdu);
450 snmp_close(ss);
452 }
453 } else {
454 snmp_add_null_var(pdu, objid_query->vars[objid_query->offset].name, objid_query->vars[objid_query->offset].name_length);
455 }
456 }
457 if(pdu->variables == NULL){
458 snmp_free_pdu(pdu);
459 snmp_close(ss);
461 }
462 }
463
464retry:
465 status = snmp_synch_response(ss, pdu, &response);
466 if (status == STAT_SUCCESS) {
467 if (response->errstat == SNMP_ERR_NOERROR) {
468 if (st & SNMP_CMD_SET) {
469 if (objid_query->offset < objid_query->count) { /* we have unprocessed OIDs */
470 keepwalking = true;
471 snmp_free_pdu(response);
472 continue;
473 }
474 snmp_free_pdu(response);
475 snmp_close(ss);
477 }
478 for (vars = response->variables; vars; vars = vars->next_variable) {
479 /* do not output errors as values */
480 if ( vars->type == SNMP_ENDOFMIBVIEW ||
481 vars->type == SNMP_NOSUCHOBJECT ||
482 vars->type == SNMP_NOSUCHINSTANCE ) {
483 if ((st & SNMP_CMD_WALK) && Z_TYPE_P(return_value) == IS_ARRAY) {
484 break;
485 }
486 snprint_objid(buf, sizeof(buf), vars->name, vars->name_length);
487 snprint_value(buf2, sizeof(buf2), vars->name, vars->name_length, vars);
488 php_snmp_error(getThis(), PHP_SNMP_ERRNO_ERROR_IN_REPLY, "Error in packet at '%s': %s", buf, buf2);
489 continue;
490 }
491
492 if ((st & SNMP_CMD_WALK) &&
493 (vars->name_length < rootlen || memcmp(root, vars->name, rootlen * sizeof(oid)))) { /* not part of this subtree */
494 if (Z_TYPE_P(return_value) == IS_ARRAY) { /* some records are fetched already, shut down further lookup */
495 keepwalking = false;
496 } else {
497 /* first fetched OID is out of subtree, fallback to GET query */
498 st |= SNMP_CMD_GET;
499 st ^= SNMP_CMD_WALK;
500 objid_query->offset = 0;
501 keepwalking = true;
502 }
503 break;
504 }
505
506 ZVAL_NULL(&snmpval);
507 php_snmp_getvalue(vars, &snmpval, objid_query->valueretrieval);
508
509 if (objid_query->array_output) {
512 }
513 if (st & SNMP_NUMERIC_KEYS) {
514 add_next_index_zval(return_value, &snmpval);
515 } else if (st & SNMP_ORIGINAL_NAMES_AS_KEYS && st & SNMP_CMD_GET) {
516 found = 0;
517 for (count = 0; count < objid_query->count; count++) {
518 if (objid_query->vars[count].name_length == vars->name_length && snmp_oid_compare(objid_query->vars[count].name, objid_query->vars[count].name_length, vars->name, vars->name_length) == 0) {
519 found = 1;
520 objid_query->vars[count].name_length = 0; /* mark this name as used */
521 break;
522 }
523 }
524 if (found) {
525 add_assoc_zval(return_value, objid_query->vars[count].oid, &snmpval);
526 } else {
527 snprint_objid(buf2, sizeof(buf2), vars->name, vars->name_length);
528 php_error_docref(NULL, E_WARNING, "Could not find original OID name for '%s'", buf2);
529 }
530 } else if (st & SNMP_USE_SUFFIX_AS_KEYS && st & SNMP_CMD_WALK) {
531 snprint_objid(buf2, sizeof(buf2), vars->name, vars->name_length);
532 if (rootlen <= vars->name_length && snmp_oid_compare(root, rootlen, vars->name, rootlen) == 0) {
533 buf2[0] = '\0';
534 count = rootlen;
535 while(count < vars->name_length){
536 snprintf(buf, sizeof(buf), "%lu.", vars->name[count]);
537 strcat(buf2, buf);
538 count++;
539 }
540 buf2[strlen(buf2) - 1] = '\0'; /* remove trailing '.' */
541 }
542 add_assoc_zval(return_value, buf2, &snmpval);
543 } else {
544 snprint_objid(buf2, sizeof(buf2), vars->name, vars->name_length);
545 add_assoc_zval(return_value, buf2, &snmpval);
546 }
547 } else {
548 ZVAL_COPY_VALUE(return_value, &snmpval);
549 break;
550 }
551
552 /* OID increase check */
553 if (st & SNMP_CMD_WALK) {
554 if (objid_query->oid_increasing_check && snmp_oid_compare(objid_query->vars[0].name, objid_query->vars[0].name_length, vars->name, vars->name_length) >= 0) {
555 snprint_objid(buf2, sizeof(buf2), vars->name, vars->name_length);
556 php_snmp_error(getThis(), PHP_SNMP_ERRNO_OID_NOT_INCREASING, "Error: OID not increasing: %s", buf2);
557 keepwalking = false;
558 } else {
559 memcpy((char *)(objid_query->vars[0].name), (char *)vars->name, vars->name_length * sizeof(oid));
560 objid_query->vars[0].name_length = vars->name_length;
561 keepwalking = true;
562 }
563 }
564 }
565 if (objid_query->offset < objid_query->count) { /* we have unprocessed OIDs */
566 keepwalking = true;
567 }
568 } else {
569 if (st & SNMP_CMD_WALK && response->errstat == SNMP_ERR_TOOBIG && objid_query->max_repetitions > 1) { /* Answer will not fit into single packet */
570 objid_query->max_repetitions /= 2;
571 snmp_free_pdu(response);
572 keepwalking = true;
573 continue;
574 }
575 if (!(st & SNMP_CMD_WALK) || response->errstat != SNMP_ERR_NOSUCHNAME || Z_TYPE_P(return_value) == IS_TRUE || Z_TYPE_P(return_value) == IS_FALSE) {
576 for (count=1, vars = response->variables;
577 vars && count != response->errindex;
578 vars = vars->next_variable, count++);
579
580 if (st & (SNMP_CMD_GET | SNMP_CMD_GETNEXT) && response->errstat == SNMP_ERR_TOOBIG && objid_query->step > 1) { /* Answer will not fit into single packet */
581 objid_query->offset = ((objid_query->offset > objid_query->step) ? (objid_query->offset - objid_query->step) : 0 );
582 objid_query->step /= 2;
583 snmp_free_pdu(response);
584 keepwalking = true;
585 continue;
586 }
587 if (vars) {
588 snprint_objid(buf, sizeof(buf), vars->name, vars->name_length);
589 php_snmp_error(getThis(), PHP_SNMP_ERRNO_ERROR_IN_REPLY, "Error in packet at '%s': %s", buf, snmp_errstring(response->errstat));
590 } else {
591 php_snmp_error(getThis(), PHP_SNMP_ERRNO_ERROR_IN_REPLY, "Error in packet at %u object_id: %s", response->errindex, snmp_errstring(response->errstat));
592 }
593 if (st & (SNMP_CMD_GET | SNMP_CMD_GETNEXT)) { /* cut out bogus OID and retry */
594 if ((pdu = snmp_fix_pdu(response, ((st & SNMP_CMD_GET) ? SNMP_MSG_GET : SNMP_MSG_GETNEXT) )) != NULL) {
595 snmp_free_pdu(response);
596 goto retry;
597 }
598 }
599 snmp_free_pdu(response);
600 snmp_close(ss);
601 if (objid_query->array_output) {
603 }
605 }
606 }
607 } else if (status == STAT_TIMEOUT) {
608 php_snmp_error(getThis(), PHP_SNMP_ERRNO_TIMEOUT, "No response from %s", session->peername);
609 if (objid_query->array_output) {
611 }
612 snmp_close(ss);
614 } else { /* status == STAT_ERROR */
615 snmp_error(ss, NULL, NULL, &err);
616 php_snmp_error(getThis(), PHP_SNMP_ERRNO_GENERIC, "Fatal error: %s", err);
617 free(err);
618 if (objid_query->array_output) {
620 }
621 snmp_close(ss);
623 }
624 if (response) {
625 snmp_free_pdu(response);
626 }
627 } /* keepwalking */
628 snmp_close(ss);
629}
630/* }}} */
631
632static void php_snmp_zend_string_release_from_char_pointer(char *ptr) {
633 if (ptr) {
635 zend_string_release(pptr);
636 }
637}
638
639static void php_free_objid_query(struct objid_query *objid_query, HashTable* oid_ht, const HashTable *value_ht, int st) {
640 if (oid_ht) {
641 uint32_t count = zend_hash_num_elements(oid_ht);
642
643 for (uint32_t i = 0; i < count; i ++) {
644 snmpobjarg *arg = &objid_query->vars[i];
645 if (!arg->oid) {
646 break;
647 }
648 if (value_ht) {
649 php_snmp_zend_string_release_from_char_pointer(arg->value);
650 }
651 php_snmp_zend_string_release_from_char_pointer(arg->oid);
652 }
653 }
654 efree(objid_query->vars);
655}
656
657/* {{{ php_snmp_parse_oid
658*
659* OID parser (and type, value for SNMP_SET command)
660*/
661static bool php_snmp_parse_oid(
662 zval *object, int st, struct objid_query *objid_query, zend_string *oid_str, HashTable *oid_ht,
663 zend_string *type_str, HashTable *type_ht, zend_string *value_str, HashTable *value_ht
664) {
665 char *pptr;
666 uint32_t idx_type = 0, idx_value = 0;
667 zval *tmp_oid, *tmp_type, *tmp_value;
668
669 objid_query->count = 0;
670 objid_query->array_output = (st & SNMP_CMD_WALK) != 0;
671 if (oid_str) {
672 objid_query->vars = (snmpobjarg *)emalloc(sizeof(snmpobjarg));
673 objid_query->vars[objid_query->count].oid = ZSTR_VAL(oid_str);
674 if (st & SNMP_CMD_SET) {
675 if (type_ht) {
676 zend_type_error("Type must be of type string when object ID is a string");
677 efree(objid_query->vars);
678 return false;
679 }
680 if (value_ht) {
681 zend_type_error("Value must be of type string when object ID is a string");
682 efree(objid_query->vars);
683 return false;
684 }
685
686 /* Both type and value must be valid strings */
687 ZEND_ASSERT(type_str && value_str);
688
689 if (ZSTR_LEN(type_str) != 1) {
690 zend_value_error("Type must be a single character");
691 efree(objid_query->vars);
692 return false;
693 }
694 pptr = ZSTR_VAL(type_str);
695 objid_query->vars[objid_query->count].type = *pptr;
696 objid_query->vars[objid_query->count].value = ZSTR_VAL(value_str);
697 }
698 objid_query->count++;
699 } else if (oid_ht) { /* we got objid array */
700 if (zend_hash_num_elements(oid_ht) == 0) {
701 zend_value_error("Array of object IDs must not be empty");
702 return false;
703 }
704 objid_query->vars = (snmpobjarg *)safe_emalloc(sizeof(snmpobjarg), zend_hash_num_elements(oid_ht), 0);
705 memset(objid_query->vars, 0, sizeof(snmpobjarg) * zend_hash_num_elements(oid_ht));
706 objid_query->array_output = (st & SNMP_CMD_SET) == 0;
707 ZEND_HASH_FOREACH_VAL(oid_ht, tmp_oid) {
708 zend_string *tmp = zval_try_get_string(tmp_oid);
709 if (!tmp) {
710 php_free_objid_query(objid_query, oid_ht, value_ht, st);
711 return false;
712 }
713 objid_query->vars[objid_query->count].oid = ZSTR_VAL(tmp);
714 if (st & SNMP_CMD_SET) {
715 if (type_str) {
716 pptr = ZSTR_VAL(type_str);
717 objid_query->vars[objid_query->count].type = *pptr;
718 } else if (type_ht) {
719 if (HT_IS_PACKED(type_ht)) {
720 while (idx_type < type_ht->nNumUsed) {
721 tmp_type = &type_ht->arPacked[idx_type];
722 if (Z_TYPE_P(tmp_type) != IS_UNDEF) {
723 break;
724 }
725 idx_type++;
726 }
727 } else {
728 while (idx_type < type_ht->nNumUsed) {
729 tmp_type = &type_ht->arData[idx_type].val;
730 if (Z_TYPE_P(tmp_type) != IS_UNDEF) {
731 break;
732 }
733 idx_type++;
734 }
735 }
736 if (idx_type < type_ht->nNumUsed) {
737 zend_string *type = zval_try_get_string(tmp_type);
738 if (!type) {
739 php_free_objid_query(objid_query, oid_ht, value_ht, st);
740 return false;
741 }
742 size_t len = ZSTR_LEN(type);
743 char ptype = *ZSTR_VAL(type);
744 zend_string_release(type);
745 if (len != 1) {
746 zend_value_error("Type must be a single character");
747 php_free_objid_query(objid_query, oid_ht, value_ht, st);
748 return false;
749 }
750 objid_query->vars[objid_query->count].type = ptype;
751 idx_type++;
752 } else {
753 php_error_docref(NULL, E_WARNING, "'%s': no type set", ZSTR_VAL(tmp));
754 php_free_objid_query(objid_query, oid_ht, value_ht, st);
755 return false;
756 }
757 }
758
759 if (value_str) {
760 objid_query->vars[objid_query->count].value = ZSTR_VAL(value_str);
761 } else if (value_ht) {
762 if (HT_IS_PACKED(value_ht)) {
763 while (idx_value < value_ht->nNumUsed) {
764 tmp_value = &value_ht->arPacked[idx_value];
765 if (Z_TYPE_P(tmp_value) != IS_UNDEF) {
766 break;
767 }
768 idx_value++;
769 }
770 } else {
771 while (idx_value < value_ht->nNumUsed) {
772 tmp_value = &value_ht->arData[idx_value].val;
773 if (Z_TYPE_P(tmp_value) != IS_UNDEF) {
774 break;
775 }
776 idx_value++;
777 }
778 }
779 if (idx_value < value_ht->nNumUsed) {
780 zend_string *tmp = zval_try_get_string(tmp_value);
781 if (!tmp) {
782 php_free_objid_query(objid_query, oid_ht, value_ht, st);
783 return false;
784 }
785 objid_query->vars[objid_query->count].value = ZSTR_VAL(tmp);
786 idx_value++;
787 } else {
788 php_error_docref(NULL, E_WARNING, "'%s': no value set", ZSTR_VAL(tmp));
789 php_free_objid_query(objid_query, oid_ht, value_ht, st);
790 return false;
791 }
792 }
793 }
794 objid_query->count++;
796 }
797
798 /* now parse all OIDs */
799 if (st & SNMP_CMD_WALK) {
800 if (objid_query->count > 1) {
801 php_snmp_error(object, PHP_SNMP_ERRNO_OID_PARSING_ERROR, "Multi OID walks are not supported!");
802 php_free_objid_query(objid_query, oid_ht, value_ht, st);
803 return false;
804 }
805 objid_query->vars[0].name_length = MAX_NAME_LEN;
806 if (strlen(objid_query->vars[0].oid)) { /* on a walk, an empty string means top of tree - no error */
807 if (!snmp_parse_oid(objid_query->vars[0].oid, objid_query->vars[0].name, &(objid_query->vars[0].name_length))) {
808 php_snmp_error(object, PHP_SNMP_ERRNO_OID_PARSING_ERROR, "Invalid object identifier: %s", objid_query->vars[0].oid);
809 php_free_objid_query(objid_query, oid_ht, value_ht, st);
810 return false;
811 }
812 } else {
813 memmove((char *)objid_query->vars[0].name, (const char *)objid_mib, sizeof(objid_mib));
814 objid_query->vars[0].name_length = sizeof(objid_mib) / sizeof(oid);
815 }
816 } else {
817 for (objid_query->offset = 0; objid_query->offset < objid_query->count; objid_query->offset++) {
818 objid_query->vars[objid_query->offset].name_length = MAX_OID_LEN;
819 if (!snmp_parse_oid(objid_query->vars[objid_query->offset].oid, objid_query->vars[objid_query->offset].name, &(objid_query->vars[objid_query->offset].name_length))) {
820 php_snmp_error(object, PHP_SNMP_ERRNO_OID_PARSING_ERROR, "Invalid object identifier: %s", objid_query->vars[objid_query->offset].oid);
821 php_free_objid_query(objid_query, oid_ht, value_ht, st);
822 return false;
823 }
824 }
825 }
826 objid_query->offset = 0;
827 objid_query->step = objid_query->count;
828 return (objid_query->count > 0);
829}
830/* }}} */
831
832/* {{{ netsnmp_session_init
833 allocates memory for session and session->peername, caller should free it manually using netsnmp_session_free() and efree()
834*/
835static bool netsnmp_session_init(php_snmp_session **session_p, int version, zend_string *hostname, zend_string *community, int timeout, int retries)
836{
837 php_snmp_session *session;
838 char *pptr, *host_ptr;
839 bool force_ipv6 = false;
840 int n;
841 struct sockaddr **psal;
842 struct sockaddr **res;
843 // TODO: Do not strip and re-add the port in peername?
844 unsigned remote_port = SNMP_PORT;
845
846 *session_p = (php_snmp_session *)emalloc(sizeof(php_snmp_session));
847 session = *session_p;
848 memset(session, 0, sizeof(php_snmp_session));
849
850 snmp_sess_init(session);
851
852 session->version = version;
853
854 session->peername = emalloc(MAX_NAME_LEN);
855 /* we copy original hostname for further processing */
856 strlcpy(session->peername, ZSTR_VAL(hostname), MAX_NAME_LEN);
857 host_ptr = session->peername;
858
859 /* Reading the hostname and its optional non-default port number */
860 if (*host_ptr == '[') { /* IPv6 address */
861 force_ipv6 = true;
862 host_ptr++;
863 if ((pptr = strchr(host_ptr, ']'))) {
864 if (pptr[1] == ':') {
865 remote_port = atoi(pptr + 2);
866 }
867 *pptr = '\0';
868 } else {
869 php_error_docref(NULL, E_WARNING, "Malformed IPv6 address, closing square bracket missing");
870 return false;
871 }
872 } else { /* IPv4 address */
873 if ((pptr = strchr(host_ptr, ':'))) {
874 remote_port = atoi(pptr + 1);
875 *pptr = '\0';
876 }
877 }
878
879 /* since Net-SNMP library requires 'udp6:' prefix for all IPv6 addresses (in FQDN form too) we need to
880 perform possible name resolution before running any SNMP queries */
881 if ((n = php_network_getaddresses(host_ptr, SOCK_DGRAM, &psal, NULL)) == 0) { /* some resolver error */
882 /* warnings sent, bailing out */
883 return false;
884 }
885
886 /* we have everything we need in psal, flush peername and fill it properly */
887 *(session->peername) = '\0';
888 res = psal;
889 while (n-- > 0) {
890 pptr = session->peername;
891#if defined(HAVE_GETADDRINFO) && defined(HAVE_IPV6)
892 if (force_ipv6 && (*res)->sa_family != AF_INET6) {
893 res++;
894 continue;
895 }
896 if ((*res)->sa_family == AF_INET6) {
897 strcpy(session->peername, "udp6:[");
898 pptr = session->peername + strlen(session->peername);
899 inet_ntop((*res)->sa_family, &(((struct sockaddr_in6*)(*res))->sin6_addr), pptr, MAX_NAME_LEN);
900 strcat(pptr, "]");
901 } else if ((*res)->sa_family == AF_INET) {
902 inet_ntop((*res)->sa_family, &(((struct sockaddr_in*)(*res))->sin_addr), pptr, MAX_NAME_LEN);
903 } else {
904 res++;
905 continue;
906 }
907#endif
908 break;
909 }
910
911 if (strlen(session->peername) == 0) {
912 php_error_docref(NULL, E_WARNING, "Unknown failure while resolving '%s'", ZSTR_VAL(hostname));
913 return false;
914 }
915 /* XXX FIXME
916 There should be check for non-empty session->peername!
917 */
918
919 /* put back non-standard SNMP port */
920 if (remote_port != SNMP_PORT) {
921 size_t peername_length = strlen(session->peername);
922 pptr = session->peername + peername_length;
923 snprintf(pptr, MAX_NAME_LEN - peername_length, ":%d", remote_port);
924 }
925
927
928 if (version == SNMP_VERSION_3) {
929 /* Setting the security name. */
930 session->securityName = estrdup(ZSTR_VAL(community));
931 session->securityNameLen = ZSTR_LEN(community);
932 } else {
933 session->authenticator = NULL;
934 session->community = (uint8_t *)estrdup(ZSTR_VAL(community));
935 session->community_len = ZSTR_LEN(community);
936 }
937
938 session->retries = retries;
939 session->timeout = timeout;
940 return true;
941}
942/* }}} */
943
944/* {{{ Set the security level in the snmpv3 session */
945static bool netsnmp_session_set_sec_level(struct snmp_session *s, zend_string *level)
946{
947 if (zend_string_equals_literal_ci(level, "noAuthNoPriv") || zend_string_equals_literal_ci(level, "nanp")) {
948 s->securityLevel = SNMP_SEC_LEVEL_NOAUTH;
949 } else if (zend_string_equals_literal_ci(level, "authNoPriv") || zend_string_equals_literal_ci(level, "anp")) {
950 s->securityLevel = SNMP_SEC_LEVEL_AUTHNOPRIV;
951 } else if (zend_string_equals_literal_ci(level, "authPriv") || zend_string_equals_literal_ci(level, "ap")) {
952 s->securityLevel = SNMP_SEC_LEVEL_AUTHPRIV;
953 } else {
954 zend_value_error("Security level must be one of \"noAuthNoPriv\", \"authNoPriv\", or \"authPriv\"");
955 return false;
956 }
957 return true;
958}
959/* }}} */
960
961/* {{{ Set the authentication protocol in the snmpv3 session */
962static bool netsnmp_session_set_auth_protocol(struct snmp_session *s, zend_string *prot)
963{
964#ifndef DISABLE_MD5
965 if (zend_string_equals_literal_ci(prot, "MD5")) {
966 s->securityAuthProto = usmHMACMD5AuthProtocol;
967 s->securityAuthProtoLen = USM_AUTH_PROTO_MD5_LEN;
968 return true;
969 }
970#endif
971
972 if (zend_string_equals_literal_ci(prot, "SHA")) {
973 s->securityAuthProto = usmHMACSHA1AuthProtocol;
974 s->securityAuthProtoLen = USM_AUTH_PROTO_SHA_LEN;
975 return true;
976 }
977
978#ifdef HAVE_SNMP_SHA256
979 if (zend_string_equals_literal_ci(prot, "SHA256")) {
980 s->securityAuthProto = usmHMAC192SHA256AuthProtocol;
981 s->securityAuthProtoLen = sizeof(usmHMAC192SHA256AuthProtocol) / sizeof(oid);
982 return true;
983 }
984#endif
985
986#ifdef HAVE_SNMP_SHA512
987 if (zend_string_equals_literal_ci(prot, "SHA512")) {
988 s->securityAuthProto = usmHMAC384SHA512AuthProtocol;
989 s->securityAuthProtoLen = sizeof(usmHMAC384SHA512AuthProtocol) / sizeof(oid);
990 return true;
991 }
992#endif
993
994 smart_string err = {0};
995
996 smart_string_appends(&err, "Authentication protocol must be \"SHA\"");
997#ifdef HAVE_SNMP_SHA256
998 smart_string_appends(&err, " or \"SHA256\"");
999#endif
1000#ifdef HAVE_SNMP_SHA512
1001 smart_string_appends(&err, " or \"SHA512\"");
1002#endif
1003#ifndef DISABLE_MD5
1004 smart_string_appends(&err, " or \"MD5\"");
1005#endif
1006 smart_string_0(&err);
1007 zend_value_error("%s", err.c);
1009 return false;
1010}
1011/* }}} */
1012
1013/* {{{ Set the security protocol in the snmpv3 session */
1014static bool netsnmp_session_set_sec_protocol(struct snmp_session *s, zend_string *prot)
1015{
1016#ifndef NETSNMP_DISABLE_DES
1017 if (zend_string_equals_literal_ci(prot, "DES")) {
1018 s->securityPrivProto = usmDESPrivProtocol;
1019 s->securityPrivProtoLen = USM_PRIV_PROTO_DES_LEN;
1020 return true;
1021 }
1022#endif
1023
1024#ifdef HAVE_AES
1025 if (zend_string_equals_literal_ci(prot, "AES128")
1026 || zend_string_equals_literal_ci(prot, "AES")) {
1027 s->securityPrivProto = usmAESPrivProtocol;
1028 s->securityPrivProtoLen = USM_PRIV_PROTO_AES_LEN;
1029 return true;
1030 }
1031#endif
1032
1033#ifdef HAVE_AES
1034# ifndef NETSNMP_DISABLE_DES
1035 zend_value_error("Security protocol must be one of \"DES\", \"AES128\", or \"AES\"");
1036# else
1037 zend_value_error("Security protocol must be one of \"AES128\", or \"AES\"");
1038# endif
1039#else
1040# ifndef NETSNMP_DISABLE_DES
1041 zend_value_error("Security protocol must be \"DES\"");
1042# else
1043 zend_value_error("No security protocol supported");
1044# endif
1045#endif
1046 return false;
1047}
1048/* }}} */
1049
1050/* {{{ Make key from pass phrase in the snmpv3 session */
1051static bool netsnmp_session_gen_auth_key(struct snmp_session *s, zend_string *pass)
1052{
1053 int snmp_errno;
1054 s->securityAuthKeyLen = USM_AUTH_KU_LEN;
1055 if ((snmp_errno = generate_Ku(s->securityAuthProto, s->securityAuthProtoLen,
1056 (uint8_t *) ZSTR_VAL(pass), ZSTR_LEN(pass),
1057 s->securityAuthKey, &(s->securityAuthKeyLen)))) {
1058 php_error_docref(NULL, E_WARNING, "Error generating a key for authentication pass phrase '%s': %s", ZSTR_VAL(pass), snmp_api_errstring(snmp_errno));
1059 return false;
1060 }
1061 return true;
1062}
1063/* }}} */
1064
1065/* {{{ Make key from pass phrase in the snmpv3 session */
1066static bool netsnmp_session_gen_sec_key(struct snmp_session *s, zend_string *pass)
1067{
1068 int snmp_errno;
1069
1070 s->securityPrivKeyLen = USM_PRIV_KU_LEN;
1071 if ((snmp_errno = generate_Ku(s->securityAuthProto, s->securityAuthProtoLen,
1072 (uint8_t *)ZSTR_VAL(pass), ZSTR_LEN(pass),
1073 s->securityPrivKey, &(s->securityPrivKeyLen)))) {
1074 php_error_docref(NULL, E_WARNING, "Error generating a key for privacy pass phrase '%s': %s", ZSTR_VAL(pass), snmp_api_errstring(snmp_errno));
1075 return false;
1076 }
1077 return true;
1078}
1079/* }}} */
1080
1081/* {{{ Set context Engine Id in the snmpv3 session */
1082static bool netsnmp_session_set_contextEngineID(struct snmp_session *s, zend_string * contextEngineID)
1083{
1084 size_t ebuf_len = 32, eout_len = 0;
1085 uint8_t *ebuf = (uint8_t *) emalloc(ebuf_len);
1086
1087 if (!snmp_hex_to_binary(&ebuf, &ebuf_len, &eout_len, 1, ZSTR_VAL(contextEngineID))) {
1088 // TODO Promote to Error?
1089 php_error_docref(NULL, E_WARNING, "Bad engine ID value '%s'", ZSTR_VAL(contextEngineID));
1090 efree(ebuf);
1091 return false;
1092 }
1093
1094 if (s->contextEngineID) {
1095 efree(s->contextEngineID);
1096 }
1097
1098 s->contextEngineID = ebuf;
1099 s->contextEngineIDLen = eout_len;
1100 return true;
1101}
1102/* }}} */
1103
1104/* {{{ Set all snmpv3-related security options */
1105static bool netsnmp_session_set_security(struct snmp_session *session, zend_string *sec_level,
1106 zend_string *auth_protocol, zend_string *auth_passphrase, zend_string *priv_protocol,
1107 zend_string *priv_passphrase, zend_string *contextName, zend_string *contextEngineID)
1108{
1109
1110 /* Setting the security level. */
1111 if (!netsnmp_session_set_sec_level(session, sec_level)) {
1112 /* ValueError already generated, just bail out */
1113 return false;
1114 }
1115
1116 if (session->securityLevel == SNMP_SEC_LEVEL_AUTHNOPRIV || session->securityLevel == SNMP_SEC_LEVEL_AUTHPRIV) {
1117
1118 /* Setting the authentication protocol. */
1119 if (!netsnmp_session_set_auth_protocol(session, auth_protocol)) {
1120 /* ValueError already generated, just bail out */
1121 return false;
1122 }
1123
1124 /* Setting the authentication passphrase. */
1125 if (!netsnmp_session_gen_auth_key(session, auth_passphrase)) {
1126 /* Warning message sent already, just bail out */
1127 return false;
1128 }
1129
1130 if (session->securityLevel == SNMP_SEC_LEVEL_AUTHPRIV) {
1131 /* Setting the security protocol. */
1132 if (!netsnmp_session_set_sec_protocol(session, priv_protocol)) {
1133 /* ValueError already generated, just bail out */
1134 return false;
1135 }
1136
1137 /* Setting the security protocol passphrase. */
1138 if (!netsnmp_session_gen_sec_key(session, priv_passphrase)) {
1139 /* Warning message sent already, just bail out */
1140 return false;
1141 }
1142 }
1143 }
1144
1145 /* Setting contextName if specified */
1146 if (contextName) {
1147 session->contextName = ZSTR_VAL(contextName);
1148 session->contextNameLen = ZSTR_LEN(contextName);
1149 }
1150
1151 /* Setting contextEngineIS if specified */
1152 if (contextEngineID && ZSTR_LEN(contextEngineID) && !netsnmp_session_set_contextEngineID(session, contextEngineID)) {
1153 /* Warning message sent already, just bail out */
1154 return false;
1155 }
1156
1157 return true;
1158}
1159/* }}} */
1160
1161/* {{{ php_snmp
1162*
1163* Generic SNMP handler for all versions.
1164* This function makes use of the internal SNMP object fetcher.
1165* Used both in old (non-OO) and OO API
1166*
1167*/
1168static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
1169{
1170 zend_string *oid_str, *type_str = NULL, *value_str = NULL;
1171 HashTable *oid_ht, *type_ht = NULL, *value_ht = NULL;
1172 zend_string *a1 = NULL, *a2 = NULL, *a3 = NULL, *a4 = NULL, *a5 = NULL, *a6 = NULL, *a7 = NULL;
1173 bool use_orignames = 0, suffix_keys = 0;
1174 zend_long timeout = SNMP_DEFAULT_TIMEOUT;
1175 zend_long retries = SNMP_DEFAULT_RETRIES;
1176 struct objid_query objid_query;
1177 php_snmp_session *session;
1178 int session_less_mode = (getThis() == NULL);
1179 php_snmp_object *snmp_object;
1180 php_snmp_object glob_snmp_object;
1181
1182 objid_query.max_repetitions = -1;
1183 objid_query.non_repeaters = 0;
1184 objid_query.valueretrieval = SNMP_G(valueretrieval);
1185 objid_query.oid_increasing_check = true;
1186
1187 if (session_less_mode) {
1188 if (version == SNMP_VERSION_3) {
1189 if (st & SNMP_CMD_SET) {
1191 Z_PARAM_STR(a1)
1192 Z_PARAM_STR(a2)
1193 Z_PARAM_STR(a3)
1194 Z_PARAM_STR(a4)
1195 Z_PARAM_STR(a5)
1196 Z_PARAM_STR(a6)
1197 Z_PARAM_STR(a7)
1198 Z_PARAM_ARRAY_HT_OR_STR(oid_ht, oid_str)
1199 Z_PARAM_ARRAY_HT_OR_STR(type_ht, type_str)
1200 Z_PARAM_ARRAY_HT_OR_STR(value_ht, value_str)
1202 Z_PARAM_LONG(timeout)
1203 Z_PARAM_LONG(retries)
1205 } else {
1206 /* SNMP_CMD_GET
1207 * SNMP_CMD_GETNEXT
1208 * SNMP_CMD_WALK
1209 */
1211 Z_PARAM_STR(a1)
1212 Z_PARAM_STR(a2)
1213 Z_PARAM_STR(a3)
1214 Z_PARAM_STR(a4)
1215 Z_PARAM_STR(a5)
1216 Z_PARAM_STR(a6)
1217 Z_PARAM_STR(a7)
1218 Z_PARAM_ARRAY_HT_OR_STR(oid_ht, oid_str)
1220 Z_PARAM_LONG(timeout)
1221 Z_PARAM_LONG(retries)
1223 }
1224 } else {
1225 if (st & SNMP_CMD_SET) {
1227 Z_PARAM_STR(a1)
1228 Z_PARAM_STR(a2)
1229 Z_PARAM_ARRAY_HT_OR_STR(oid_ht, oid_str)
1230 Z_PARAM_ARRAY_HT_OR_STR(type_ht, type_str)
1231 Z_PARAM_ARRAY_HT_OR_STR(value_ht, value_str)
1233 Z_PARAM_LONG(timeout)
1234 Z_PARAM_LONG(retries)
1236 } else {
1237 /* SNMP_CMD_GET
1238 * SNMP_CMD_GETNEXT
1239 * SNMP_CMD_WALK
1240 */
1242 Z_PARAM_STR(a1)
1243 Z_PARAM_STR(a2)
1244 Z_PARAM_ARRAY_HT_OR_STR(oid_ht, oid_str)
1246 Z_PARAM_LONG(timeout)
1247 Z_PARAM_LONG(retries)
1249 }
1250 }
1251 } else {
1252 if (st & SNMP_CMD_SET) {
1254 Z_PARAM_ARRAY_HT_OR_STR(oid_ht, oid_str)
1255 Z_PARAM_ARRAY_HT_OR_STR(type_ht, type_str)
1256 Z_PARAM_ARRAY_HT_OR_STR(value_ht, value_str)
1258 } else if (st & SNMP_CMD_WALK) {
1260 Z_PARAM_ARRAY_HT_OR_STR(oid_ht, oid_str)
1262 Z_PARAM_BOOL(suffix_keys)
1263 Z_PARAM_LONG(objid_query.max_repetitions)
1264 Z_PARAM_LONG(objid_query.non_repeaters)
1266 if (suffix_keys) {
1267 st |= SNMP_USE_SUFFIX_AS_KEYS;
1268 }
1269 } else if (st & SNMP_CMD_GET) {
1271 Z_PARAM_ARRAY_HT_OR_STR(oid_ht, oid_str)
1273 Z_PARAM_BOOL(use_orignames)
1275 if (use_orignames) {
1276 st |= SNMP_ORIGINAL_NAMES_AS_KEYS;
1277 }
1278 } else {
1279 /* SNMP_CMD_GETNEXT
1280 */
1282 Z_PARAM_ARRAY_HT_OR_STR(oid_ht, oid_str)
1284 }
1285 }
1286
1287 if (!php_snmp_parse_oid(getThis(), st, &objid_query, oid_str, oid_ht, type_str, type_ht, value_str, value_ht)) {
1289 }
1290
1291 if (session_less_mode) {
1292 if (!netsnmp_session_init(&session, version, a1, a2, timeout, retries)) {
1293 php_free_objid_query(&objid_query, oid_ht, value_ht, st);
1294 netsnmp_session_free(&session);
1296 }
1297 if (version == SNMP_VERSION_3 && !netsnmp_session_set_security(session, a3, a4, a5, a6, a7, NULL, NULL)) {
1298 php_free_objid_query(&objid_query, oid_ht, value_ht, st);
1299 netsnmp_session_free(&session);
1300 /* Warning message sent already, just bail out */
1302 }
1303 } else {
1304 zval *object = getThis();
1305 snmp_object = Z_SNMP_P(object);
1306 session = snmp_object->session;
1307 if (!session) {
1308 zend_throw_error(NULL, "Invalid or uninitialized SNMP object");
1309 php_free_objid_query(&objid_query, oid_ht, value_ht, st);
1310 RETURN_THROWS();
1311 }
1312
1313 if (snmp_object->max_oids > 0) {
1314 objid_query.step = snmp_object->max_oids;
1315 if (objid_query.max_repetitions < 0) { /* unspecified in function call, use session-wise */
1316 objid_query.max_repetitions = snmp_object->max_oids;
1317 }
1318 }
1319 objid_query.oid_increasing_check = snmp_object->oid_increasing_check;
1320 objid_query.valueretrieval = snmp_object->valueretrieval;
1321 glob_snmp_object.enum_print = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM);
1322 netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM, snmp_object->enum_print);
1323 glob_snmp_object.quick_print = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT);
1324 netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT, snmp_object->quick_print);
1325 glob_snmp_object.oid_output_format = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT);
1326 netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, snmp_object->oid_output_format);
1327 }
1328
1329 if (objid_query.max_repetitions < 0) {
1330 objid_query.max_repetitions = 20; /* provide correct default value */
1331 }
1332
1333 php_snmp_internal(INTERNAL_FUNCTION_PARAM_PASSTHRU, st, session, &objid_query);
1334
1335 php_free_objid_query(&objid_query, oid_ht, value_ht, st);
1336
1337 if (session_less_mode) {
1338 netsnmp_session_free(&session);
1339 } else {
1340 netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM, glob_snmp_object.enum_print);
1341 netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT, glob_snmp_object.quick_print);
1342 netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, glob_snmp_object.oid_output_format);
1343 }
1344}
1345/* }}} */
1346
1347/* {{{ Fetch a SNMP object */
1349{
1350 php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_GET, SNMP_VERSION_1);
1351}
1352/* }}} */
1353
1354/* {{{ Fetch a SNMP object */
1356{
1357 php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_GETNEXT, SNMP_VERSION_1);
1358}
1359/* }}} */
1360
1361/* {{{ Return all objects under the specified object id */
1363{
1364 php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, (SNMP_CMD_WALK | SNMP_NUMERIC_KEYS), SNMP_VERSION_1);
1365}
1366/* }}} */
1367
1368/* {{{ Return all objects including their respective object id within the specified one */
1370{
1371 php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_WALK, SNMP_VERSION_1);
1372}
1373/* }}} */
1374
1375/* {{{ Set the value of a SNMP object */
1377{
1378 php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_SET, SNMP_VERSION_1);
1379}
1380/* }}} */
1381
1382/* {{{ Return the current status of quick_print */
1384{
1386 RETURN_THROWS();
1387 }
1388
1389 RETURN_BOOL(netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT));
1390}
1391/* }}} */
1392
1393/* {{{ Return all objects including their respective object id within the specified one */
1395{
1396 bool a1;
1397
1398 if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &a1) == FAILURE) {
1399 RETURN_THROWS();
1400 }
1401
1402 netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT, (int)a1);
1404}
1405/* }}} */
1406
1407/* {{{ Return all values that are enums with their enum value instead of the raw integer */
1409{
1410 bool a1;
1411
1412 if (zend_parse_parameters(ZEND_NUM_ARGS(), "b", &a1) == FAILURE) {
1413 RETURN_THROWS();
1414 }
1415
1416 netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM, (int) a1);
1418}
1419/* }}} */
1420
1421/* {{{ Set the OID output format. */
1423{
1424 zend_long a1;
1425
1426 if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &a1) == FAILURE) {
1427 RETURN_THROWS();
1428 }
1429
1430 switch (a1) {
1431 case NETSNMP_OID_OUTPUT_SUFFIX:
1432 case NETSNMP_OID_OUTPUT_MODULE:
1433 case NETSNMP_OID_OUTPUT_FULL:
1434 case NETSNMP_OID_OUTPUT_NUMERIC:
1435 case NETSNMP_OID_OUTPUT_UCD:
1436 case NETSNMP_OID_OUTPUT_NONE:
1437 netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, a1);
1439 default:
1440 zend_argument_value_error(1, "must be an SNMP_OID_OUTPUT_* constant");
1441 RETURN_THROWS();
1442 }
1443}
1444/* }}} */
1445
1446/* {{{ Fetch a SNMP object */
1448{
1449 php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_GET, SNMP_VERSION_2c);
1450}
1451/* }}} */
1452
1453/* {{{ Fetch a SNMP object */
1455{
1456 php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_GETNEXT, SNMP_VERSION_2c);
1457}
1458/* }}} */
1459
1460/* {{{ Return all objects under the specified object id */
1462{
1463 php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, (SNMP_CMD_WALK | SNMP_NUMERIC_KEYS), SNMP_VERSION_2c);
1464}
1465/* }}} */
1466
1467/* {{{ Return all objects including their respective object id within the specified one */
1469{
1470 php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_WALK, SNMP_VERSION_2c);
1471}
1472/* }}} */
1473
1474/* {{{ Set the value of a SNMP object */
1476{
1477 php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_SET, SNMP_VERSION_2c);
1478}
1479/* }}} */
1480
1481/* {{{ Fetch the value of a SNMP object */
1483{
1484 php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_GET, SNMP_VERSION_3);
1485}
1486/* }}} */
1487
1488/* {{{ Fetch the value of a SNMP object */
1490{
1491 php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_GETNEXT, SNMP_VERSION_3);
1492}
1493/* }}} */
1494
1495/* {{{ Fetch the value of a SNMP object */
1497{
1498 php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, (SNMP_CMD_WALK | SNMP_NUMERIC_KEYS), SNMP_VERSION_3);
1499}
1500/* }}} */
1501
1502/* {{{ Fetch the value of a SNMP object */
1504{
1505 php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_WALK, SNMP_VERSION_3);
1506}
1507/* }}} */
1508
1509/* {{{ Fetch the value of a SNMP object */
1511{
1512 php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_SET, SNMP_VERSION_3);
1513}
1514/* }}} */
1515
1516/* {{{ Specify the method how the SNMP values will be returned */
1518{
1519 zend_long method;
1520
1521 if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &method) == FAILURE) {
1522 RETURN_THROWS();
1523 }
1524
1525 if (method >= 0 && method <= (SNMP_VALUE_LIBRARY|SNMP_VALUE_PLAIN|SNMP_VALUE_OBJECT)) {
1526 SNMP_G(valueretrieval) = method;
1528 } else {
1529 zend_argument_value_error(1, "must be a bitmask of SNMP_VALUE_LIBRARY, SNMP_VALUE_PLAIN, and SNMP_VALUE_OBJECT");
1530 RETURN_THROWS();
1531 }
1532}
1533/* }}} */
1534
1535/* {{{ Return the method how the SNMP values will be returned */
1537{
1539 RETURN_THROWS();
1540 }
1541
1542 RETURN_LONG(SNMP_G(valueretrieval));
1543}
1544/* }}} */
1545
1546/* {{{ Reads and parses a MIB file into the active MIB tree. */
1548{
1549 char *filename;
1550 size_t filename_len;
1551
1552 if (zend_parse_parameters(ZEND_NUM_ARGS(), "p", &filename, &filename_len) == FAILURE) {
1553 RETURN_THROWS();
1554 }
1555
1556 if (!read_mib(filename)) {
1557 char *error = strerror(errno);
1558 php_error_docref(NULL, E_WARNING, "Error while reading MIB file '%s': %s", filename, error);
1560 }
1562}
1563/* }}} */
1564
1565/* {{{ Creates a new SNMP session to specified host. */
1566PHP_METHOD(SNMP, __construct)
1567{
1568 php_snmp_object *snmp_object;
1569 zval *object = ZEND_THIS;
1570 zend_string *a1, *a2;
1571 zend_long timeout = SNMP_DEFAULT_TIMEOUT;
1572 zend_long retries = SNMP_DEFAULT_RETRIES;
1573 zend_long version = SNMP_DEFAULT_VERSION;
1574
1575 snmp_object = Z_SNMP_P(object);
1576
1577 if (zend_parse_parameters(ZEND_NUM_ARGS(), "lSS|ll", &version, &a1, &a2, &timeout, &retries) == FAILURE) {
1578 RETURN_THROWS();
1579 }
1580
1581 switch (version) {
1582 case SNMP_VERSION_1:
1583 case SNMP_VERSION_2c:
1584 case SNMP_VERSION_3:
1585 break;
1586 default:
1587 zend_argument_value_error(1, "must be a valid SNMP protocol version");
1588 RETURN_THROWS();
1589 }
1590
1591 /* handle re-open of snmp session */
1592 if (snmp_object->session) {
1593 netsnmp_session_free(&(snmp_object->session));
1594 }
1595
1596 if (!netsnmp_session_init(&(snmp_object->session), version, a1, a2, timeout, retries)) {
1597 return;
1598 }
1599 snmp_object->max_oids = 0;
1600 snmp_object->valueretrieval = SNMP_G(valueretrieval);
1601 snmp_object->enum_print = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM);
1602 snmp_object->oid_output_format = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT);
1603 snmp_object->quick_print = netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT);
1604 snmp_object->oid_increasing_check = true;
1605 snmp_object->exceptions_enabled = 0;
1606}
1607/* }}} */
1608
1609/* {{{ Close SNMP session */
1611{
1612 php_snmp_object *snmp_object;
1613 zval *object = ZEND_THIS;
1614
1615 snmp_object = Z_SNMP_P(object);
1616
1618 RETURN_THROWS();
1619 }
1620
1621 netsnmp_session_free(&(snmp_object->session));
1622
1624}
1625/* }}} */
1626
1627/* {{{ Fetch a SNMP object returning scalar for single OID and array of oid->value pairs for multi OID request */
1628PHP_METHOD(SNMP, get)
1629{
1630 php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_GET, (-1));
1631}
1632/* }}} */
1633
1634/* {{{ Fetch a SNMP object returning scalar for single OID and array of oid->value pairs for multi OID request */
1635PHP_METHOD(SNMP, getnext)
1636{
1637 php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_GETNEXT, (-1));
1638}
1639/* }}} */
1640
1641/* {{{ Return all objects including their respective object id within the specified one as array of oid->value pairs */
1642PHP_METHOD(SNMP, walk)
1643{
1644 php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_WALK, (-1));
1645}
1646/* }}} */
1647
1648/* {{{ Set the value of a SNMP object */
1649PHP_METHOD(SNMP, set)
1650{
1651 php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU, SNMP_CMD_SET, (-1));
1652}
1653/* }}} */
1654
1655/* {{{ Set SNMPv3 security-related session parameters */
1656PHP_METHOD(SNMP, setSecurity)
1657{
1658 php_snmp_object *snmp_object;
1659 zval *object = ZEND_THIS;
1660 zend_string *a1 = NULL, *a2 = NULL, *a3 = NULL, *a4 = NULL, *a5 = NULL, *a6 = NULL, *a7 = NULL;
1661
1662 snmp_object = Z_SNMP_P(object);
1663 if (!snmp_object->session) {
1664 zend_throw_error(NULL, "Invalid or uninitialized SNMP object");
1665 RETURN_THROWS();
1666 }
1667
1668 if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|SSSSSS", &a1, &a2, &a3, &a4,&a5, &a6, &a7) == FAILURE) {
1669 RETURN_THROWS();
1670 }
1671
1672 if (!netsnmp_session_set_security(snmp_object->session, a1, a2, a3, a4, a5, a6, a7)) {
1673 /* Warning message sent already, just bail out */
1675 }
1677}
1678/* }}} */
1679
1680/* {{{ Get last error code number */
1681PHP_METHOD(SNMP, getErrno)
1682{
1683 php_snmp_object *snmp_object;
1684 zval *object = ZEND_THIS;
1685
1686 snmp_object = Z_SNMP_P(object);
1687
1689 RETURN_THROWS();
1690 }
1691
1692 RETURN_LONG(snmp_object->snmp_errno);
1693}
1694/* }}} */
1695
1696/* {{{ Get last error message */
1697PHP_METHOD(SNMP, getError)
1698{
1699 php_snmp_object *snmp_object;
1700 zval *object = ZEND_THIS;
1701
1702 snmp_object = Z_SNMP_P(object);
1703
1705 RETURN_THROWS();
1706 }
1707
1708 RETURN_STRING(snmp_object->snmp_errstr);
1709}
1710/* }}} */
1711
1712/* {{{ */
1713void php_snmp_add_property(HashTable *h, const char *name, size_t name_length, php_snmp_read_t read_func, php_snmp_write_t write_func)
1714{
1715 php_snmp_prop_handler p;
1716 zend_string *str;
1717
1718 p.name = (char*) name;
1719 p.name_length = name_length;
1720 p.read_func = (read_func) ? read_func : NULL;
1721 p.write_func = (write_func) ? write_func : NULL;
1722 str = zend_string_init_interned(name, name_length, 1);
1723 zend_hash_add_mem(h, str, &p, sizeof(php_snmp_prop_handler));
1724 zend_string_release_ex(str, 1);
1725}
1726/* }}} */
1727
1728/* {{{ php_snmp_read_property(zval *object, zval *member, int type[, const zend_literal *key])
1729 Generic object property reader */
1730zval *php_snmp_read_property(zend_object *object, zend_string *name, int type, void **cache_slot, zval *rv)
1731{
1732 zval *retval;
1733 php_snmp_object *obj;
1734 php_snmp_prop_handler *hnd;
1735 int ret;
1736
1737 obj = php_snmp_fetch_object(object);
1738 hnd = zend_hash_find_ptr(&php_snmp_properties, name);
1739
1740 if (hnd && hnd->read_func) {
1741 ret = hnd->read_func(obj, rv);
1742 if (ret == SUCCESS) {
1743 retval = rv;
1744 } else {
1745 retval = &EG(uninitialized_zval);
1746 }
1747 } else {
1748 retval = zend_std_read_property(object, name, type, cache_slot, rv);
1749 }
1750
1751 return retval;
1752}
1753/* }}} */
1754
1755/* {{{ Generic object property writer */
1756zval *php_snmp_write_property(zend_object *object, zend_string *name, zval *value, void **cache_slot)
1757{
1758 php_snmp_object *obj = php_snmp_fetch_object(object);
1759 php_snmp_prop_handler *hnd = zend_hash_find_ptr(&php_snmp_properties, name);
1760
1761 if (hnd) {
1762 if (!hnd->write_func) {
1763 zend_throw_error(NULL, "Cannot write read-only property %s::$%s", ZSTR_VAL(object->ce->name), ZSTR_VAL(name));
1764 return &EG(error_zval);
1765 }
1766
1767 zend_property_info *prop = zend_get_property_info(object->ce, name, /* silent */ true);
1768 if (prop && ZEND_TYPE_IS_SET(prop->type)) {
1769 zval tmp;
1770 ZVAL_COPY(&tmp, value);
1771 if (!zend_verify_property_type(prop, &tmp,
1772 ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data)))) {
1773 zval_ptr_dtor(&tmp);
1774 return &EG(error_zval);
1775 }
1776 hnd->write_func(obj, &tmp);
1777 zval_ptr_dtor(&tmp);
1778 } else {
1779 hnd->write_func(obj, value);
1780 }
1781 return value;
1782 }
1783
1784 return zend_std_write_property(object, name, value, cache_slot);
1785}
1786/* }}} */
1787
1788/* {{{ php_snmp_has_property(zval *object, zval *member, int has_set_exists[, const zend_literal *key])
1789 Generic object property checker */
1790static int php_snmp_has_property(zend_object *object, zend_string *name, int has_set_exists, void **cache_slot)
1791{
1792 zval rv;
1793 php_snmp_prop_handler *hnd;
1794 int ret = 0;
1795
1796 if ((hnd = zend_hash_find_ptr(&php_snmp_properties, name)) != NULL) {
1797 switch (has_set_exists) {
1799 ret = 1;
1800 break;
1801 case ZEND_PROPERTY_ISSET: {
1802 zval *value = php_snmp_read_property(object, name, BP_VAR_IS, cache_slot, &rv);
1803 if (value != &EG(uninitialized_zval)) {
1804 ret = Z_TYPE_P(value) != IS_NULL? 1 : 0;
1806 }
1807 break;
1808 }
1809 default: {
1810 zval *value = php_snmp_read_property(object, name, BP_VAR_IS, cache_slot, &rv);
1811 if (value != &EG(uninitialized_zval)) {
1813 ret = Z_TYPE_P(value) == IS_TRUE? 1:0;
1814 }
1815 break;
1816 }
1817 }
1818 } else {
1819 ret = zend_std_has_property(object, name, has_set_exists, cache_slot);
1820 }
1821 return ret;
1822}
1823/* }}} */
1824
1825static HashTable *php_snmp_get_gc(zend_object *object, zval **gc_data, int *gc_data_count) /* {{{ */
1826{
1827 *gc_data = NULL;
1828 *gc_data_count = 0;
1829 return zend_std_get_properties(object);
1830}
1831/* }}} */
1832
1833/* {{{ php_snmp_get_properties(zval *object)
1834 Returns all object properties. Injects SNMP properties into object on first call */
1835static HashTable *php_snmp_get_properties(zend_object *object)
1836{
1837 php_snmp_object *obj;
1838 php_snmp_prop_handler *hnd;
1839 HashTable *props;
1840 zval rv;
1842
1843 obj = php_snmp_fetch_object(object);
1844 props = zend_std_get_properties(object);
1845
1846 ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(&php_snmp_properties, key, hnd) {
1847 if (!hnd->read_func || hnd->read_func(obj, &rv) != SUCCESS) {
1848 ZVAL_NULL(&rv);
1849 }
1850 zend_hash_update(props, key, &rv);
1852
1853 return obj->zo.properties;
1854}
1855/* }}} */
1856
1857static zval *php_snmp_get_property_ptr_ptr(zend_object *object, zend_string *name, int type, void **cache_slot)
1858{
1859 php_snmp_prop_handler *hnd = zend_hash_find_ptr(&php_snmp_properties, name);
1860 if (hnd == NULL) {
1861 return zend_std_get_property_ptr_ptr(object, name, type, cache_slot);
1862 }
1863
1864 if (cache_slot) {
1865 cache_slot[0] = cache_slot[1] = cache_slot[2] = NULL;
1866 }
1867 return NULL;
1868}
1869
1870/* {{{ */
1871static int php_snmp_read_info(php_snmp_object *snmp_object, zval *retval)
1872{
1873 zval val;
1874
1876
1877 if (snmp_object->session == NULL) {
1878 return SUCCESS;
1879 }
1880
1881 ZVAL_STRINGL(&val, snmp_object->session->peername, strlen(snmp_object->session->peername));
1882 add_assoc_zval(retval, "hostname", &val);
1883
1884 ZVAL_LONG(&val, snmp_object->session->timeout);
1885 add_assoc_zval(retval, "timeout", &val);
1886
1887 ZVAL_LONG(&val, snmp_object->session->retries);
1888 add_assoc_zval(retval, "retries", &val);
1889
1890 return SUCCESS;
1891}
1892/* }}} */
1893
1894/* {{{ */
1895static int php_snmp_read_max_oids(php_snmp_object *snmp_object, zval *retval)
1896{
1897 if (snmp_object->max_oids > 0) {
1898 ZVAL_LONG(retval, snmp_object->max_oids);
1899 } else {
1901 }
1902 return SUCCESS;
1903}
1904/* }}} */
1905
1906#define PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(name) \
1907 static int php_snmp_read_##name(php_snmp_object *snmp_object, zval *retval) \
1908 { \
1909 ZVAL_BOOL(retval, snmp_object->name); \
1910 return SUCCESS; \
1911 }
1912
1913PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(oid_increasing_check)
1914PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(quick_print)
1915PHP_SNMP_BOOL_PROPERTY_READER_FUNCTION(enum_print)
1916
1917#define PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(name) \
1918 static int php_snmp_read_##name(php_snmp_object *snmp_object, zval *retval) \
1919 { \
1920 ZVAL_LONG(retval, snmp_object->name); \
1921 return SUCCESS; \
1922 }
1923
1924PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(valueretrieval)
1925PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(oid_output_format)
1926PHP_SNMP_LONG_PROPERTY_READER_FUNCTION(exceptions_enabled)
1927
1928/* {{{ */
1929static int php_snmp_write_max_oids(php_snmp_object *snmp_object, zval *newval)
1930{
1931 zend_long lval;
1932
1933 if (Z_TYPE_P(newval) == IS_NULL) {
1934 snmp_object->max_oids = 0;
1935 return SUCCESS;
1936 }
1937
1938 lval = zval_get_long(newval);
1939
1940 if (lval <= 0) {
1941 zend_value_error("SNMP::$max_oids must be greater than 0 or null");
1942 return FAILURE;
1943 }
1944 snmp_object->max_oids = lval;
1945
1946 return SUCCESS;
1947}
1948/* }}} */
1949
1950/* {{{ */
1951static int php_snmp_write_valueretrieval(php_snmp_object *snmp_object, zval *newval)
1952{
1953 zend_long lval = zval_get_long(newval);
1954
1955 if (lval >= 0 && lval <= (SNMP_VALUE_LIBRARY|SNMP_VALUE_PLAIN|SNMP_VALUE_OBJECT)) {
1956 snmp_object->valueretrieval = lval;
1957 } else {
1958 zend_value_error("SNMP retrieval method must be a bitmask of SNMP_VALUE_LIBRARY, SNMP_VALUE_PLAIN, and SNMP_VALUE_OBJECT");
1959 return FAILURE;
1960 }
1961
1962 return SUCCESS;
1963}
1964/* }}} */
1965
1966#define PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(name) \
1967static int php_snmp_write_##name(php_snmp_object *snmp_object, zval *newval) \
1968{ \
1969 zval ztmp; \
1970 ZVAL_COPY(&ztmp, newval); \
1971 convert_to_boolean(&ztmp); \
1972 newval = &ztmp; \
1973\
1974 snmp_object->name = Z_TYPE_P(newval) == IS_TRUE? 1 : 0; \
1975\
1976 return SUCCESS; \
1977}
1978
1979PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(quick_print)
1980PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(enum_print)
1981PHP_SNMP_BOOL_PROPERTY_WRITER_FUNCTION(oid_increasing_check)
1982
1983/* {{{ */
1984static int php_snmp_write_oid_output_format(php_snmp_object *snmp_object, zval *newval)
1985{
1986 zend_long lval = zval_get_long(newval);
1987
1988 switch(lval) {
1989 case NETSNMP_OID_OUTPUT_SUFFIX:
1990 case NETSNMP_OID_OUTPUT_MODULE:
1991 case NETSNMP_OID_OUTPUT_FULL:
1992 case NETSNMP_OID_OUTPUT_NUMERIC:
1993 case NETSNMP_OID_OUTPUT_UCD:
1994 case NETSNMP_OID_OUTPUT_NONE:
1995 snmp_object->oid_output_format = lval;
1996 return SUCCESS;
1997 default:
1998 zend_value_error("SNMP output print format must be an SNMP_OID_OUTPUT_* constant");
1999 return FAILURE;
2000 }
2001}
2002/* }}} */
2003
2004/* {{{ */
2005static int php_snmp_write_exceptions_enabled(php_snmp_object *snmp_object, zval *newval)
2006{
2007 int ret = SUCCESS;
2008
2009 snmp_object->exceptions_enabled = zval_get_long(newval);
2010
2011 return ret;
2012}
2013/* }}} */
2014
2015static void free_php_snmp_properties(zval *el) /* {{{ */
2016{
2017 pefree(Z_PTR_P(el), 1);
2018}
2019/* }}} */
2020
2021#define PHP_SNMP_PROPERTY_ENTRY_RECORD(name) \
2022 { "" #name "", sizeof("" #name "") - 1, php_snmp_read_##name, php_snmp_write_##name }
2023
2024#define PHP_SNMP_READONLY_PROPERTY_ENTRY_RECORD(name) \
2025 { "" #name "", sizeof("" #name "") - 1, php_snmp_read_##name, NULL }
2026
2027const php_snmp_prop_handler php_snmp_property_entries[] = {
2028 PHP_SNMP_READONLY_PROPERTY_ENTRY_RECORD(info),
2029 PHP_SNMP_PROPERTY_ENTRY_RECORD(max_oids),
2030 PHP_SNMP_PROPERTY_ENTRY_RECORD(valueretrieval),
2031 PHP_SNMP_PROPERTY_ENTRY_RECORD(quick_print),
2032 PHP_SNMP_PROPERTY_ENTRY_RECORD(enum_print),
2033 PHP_SNMP_PROPERTY_ENTRY_RECORD(oid_output_format),
2034 PHP_SNMP_PROPERTY_ENTRY_RECORD(oid_increasing_check),
2035 PHP_SNMP_PROPERTY_ENTRY_RECORD(exceptions_enabled),
2036 { NULL, 0, NULL, NULL}
2037};
2038/* }}} */
2039
2040/* {{{ PHP_MINIT_FUNCTION */
2042{
2043 netsnmp_log_handler *logh;
2044
2045 init_snmp("snmpapp");
2046 /* net-snmp corrupts the CTYPE locale during initialization. */
2048
2049#ifdef NETSNMP_DS_LIB_DONT_PERSIST_STATE
2050 /* Prevent update of the snmpapp.conf file */
2051 netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PERSIST_STATE, 1);
2052#endif
2053
2054 /* Disable logging, use exit status'es and related variabled to detect errors */
2055 shutdown_snmp_logging();
2056 logh = netsnmp_register_loghandler(NETSNMP_LOGHANDLER_NONE, LOG_ERR);
2057 if (logh) {
2058 logh->pri_max = LOG_ERR;
2059 }
2060
2061 memcpy(&php_snmp_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
2062 php_snmp_object_handlers.read_property = php_snmp_read_property;
2063 php_snmp_object_handlers.write_property = php_snmp_write_property;
2064 php_snmp_object_handlers.get_property_ptr_ptr = php_snmp_get_property_ptr_ptr;
2065 php_snmp_object_handlers.has_property = php_snmp_has_property;
2066 php_snmp_object_handlers.get_properties = php_snmp_get_properties;
2067 php_snmp_object_handlers.get_gc = php_snmp_get_gc;
2068
2069 /* Register SNMP Class */
2070 php_snmp_ce = register_class_SNMP();
2071 php_snmp_ce->create_object = php_snmp_object_new;
2072 php_snmp_ce->default_object_handlers = &php_snmp_object_handlers;
2073 php_snmp_object_handlers.offset = XtOffsetOf(php_snmp_object, zo);
2074 php_snmp_object_handlers.clone_obj = NULL;
2075 php_snmp_object_handlers.free_obj = php_snmp_object_free_storage;
2076
2077 /* Register SNMP Class properties */
2078 zend_hash_init(&php_snmp_properties, 0, NULL, free_php_snmp_properties, 1);
2079 PHP_SNMP_ADD_PROPERTIES(&php_snmp_properties, php_snmp_property_entries);
2080
2081 /* Register SNMPException class */
2082 php_snmp_exception_ce = register_class_SNMPException(spl_ce_RuntimeException);
2083
2084 register_snmp_symbols(module_number);
2085
2086 return SUCCESS;
2087}
2088/* }}} */
2089
2090/* {{{ PHP_MSHUTDOWN_FUNCTION */
2092{
2093 snmp_shutdown("snmpapp");
2094
2095 zend_hash_destroy(&php_snmp_properties);
2096
2097 return SUCCESS;
2098}
2099/* }}} */
2100
2101/* {{{ PHP_MINFO_FUNCTION */
2103{
2105 php_info_print_table_row(2, "NET-SNMP Support", "enabled");
2106 php_info_print_table_row(2, "NET-SNMP Version", netsnmp_get_version());
2108}
2109/* }}} */
2110
2111/* {{{ snmp_module_deps[] */
2112static const zend_module_dep snmp_module_deps[] = {
2113 ZEND_MOD_REQUIRED("spl")
2115};
2116/* }}} */
2117
2118/* {{{ snmp_module_entry */
2119zend_module_entry snmp_module_entry = {
2121 NULL,
2122 snmp_module_deps,
2123 "snmp",
2124 ext_functions,
2125 PHP_MINIT(snmp),
2126 PHP_MSHUTDOWN(snmp),
2127 NULL,
2128 NULL,
2129 PHP_MINFO(snmp),
2131 PHP_MODULE_GLOBALS(snmp),
2132 PHP_GINIT(snmp),
2133 NULL,
2134 NULL,
2136};
2137/* }}} */
2138
2139#endif
strcat($n)
Definition bench.php:337
size_t len
Definition apprentice.c:174
count(Countable|array $value, int $mode=COUNT_NORMAL)
strchr(string $haystack, string $needle, bool $before_needle=false)
char s[4]
Definition cdf.c:77
DNS_STATUS status
Definition dns_win32.c:49
error($message)
Definition ext_skel.php:22
zend_ffi_type * type
Definition ffi.c:3812
zend_long n
Definition ffi.c:4979
zend_string * res
Definition ffi.c:4692
void * ptr
Definition ffi.c:3814
memcpy(ptr1, ptr2, size)
char * err
Definition ffi.c:3029
zval * arg
Definition ffi.c:3975
memset(ptr, 0, type->size)
zval * val
Definition ffi.c:4262
zend_ffi_ctype_name_buf buf
Definition ffi.c:4685
zend_long offset
size_t filename_len
#define NULL
Definition gdcache.h:45
#define SUCCESS
Definition hash_sha3.c:261
#define pass(a, b, c, mul)
Definition hash_tiger.c:50
foreach($dp as $el) foreach( $dp as $el) if( $pass2< 2) echo ""
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
Definition main.c:1173
PHPAPI ZEND_COLD void php_verror(const char *docref, const char *params, int type, const char *format, va_list args)
Definition main.c:992
inet_ntop(AF_INET, addr, addr_str, sizeof(addr_str))
PHPAPI void php_network_freeaddresses(struct sockaddr **sal)
Definition network.c:133
PHPAPI int php_network_getaddresses(const char *host, int socktype, struct sockaddr ***sal, zend_string **error_string)
Definition network.c:148
#define memmove(a, b, c)
php_info_print_table_start()
Definition info.c:1064
php_info_print_table_row(2, "PDO Driver for Firebird", "enabled")
php_info_print_table_end()
Definition info.c:1074
#define PHP_GINIT
Definition php.h:397
#define PHP_FUNCTION
Definition php.h:364
#define PHP_MSHUTDOWN_FUNCTION
Definition php.h:401
#define PHP_MINFO
Definition php.h:396
#define PHP_MINIT_FUNCTION
Definition php.h:400
#define strlcpy
Definition php.h:159
#define PHP_MSHUTDOWN
Definition php.h:393
#define PHP_MINFO_FUNCTION
Definition php.h:404
#define PHP_GINIT_FUNCTION
Definition php.h:405
#define PHP_MINIT
Definition php.h:392
#define PHP_METHOD
Definition php.h:365
#define PHP_MODULE_GLOBALS
Definition php.h:408
unsigned char key[REFLECTION_KEY_LEN]
#define PHP_SNMP_VERSION
Definition php_snmp.h:25
zval rv
Definition session.c:1024
p
Definition session.c:1105
snmp_set_quick_print(bool $enable)
snmp_set_oid_output_format(int $format)
const SNMP_VALUE_LIBRARY
Definition snmp.stub.php:40
snmpgetnext(string $hostname, string $community, array|string $object_id, int $timeout=-1, int $retries=-1)
snmp2_set(string $hostname, string $community, array|string $object_id, array|string $type, array|string $value, int $timeout=-1, int $retries=-1)
snmp_get_quick_print()
snmp_set_valueretrieval(int $method)
snmp2_getnext(string $hostname, string $community, array|string $object_id, int $timeout=-1, int $retries=-1)
snmp3_walk(string $hostname, string $security_name, string $security_level, string $auth_protocol, string $auth_passphrase, string $privacy_protocol, string $privacy_passphrase, array|string $object_id, int $timeout=-1, int $retries=-1)
snmpwalk(string $hostname, string $community, array|string $object_id, int $timeout=-1, int $retries=-1)
snmp3_getnext(string $hostname, string $security_name, string $security_level, string $auth_protocol, string $auth_passphrase, string $privacy_protocol, string $privacy_passphrase, array|string $object_id, int $timeout=-1, int $retries=-1)
snmp_read_mib(string $filename)
snmp3_real_walk(string $hostname, string $security_name, string $security_level, string $auth_protocol, string $auth_passphrase, string $privacy_protocol, string $privacy_passphrase, array|string $object_id, int $timeout=-1, int $retries=-1)
snmp2_real_walk(string $hostname, string $community, array|string $object_id, int $timeout=-1, int $retries=-1)
const SNMP_VALUE_PLAIN
Definition snmp.stub.php:45
snmp2_get(string $hostname, string $community, array|string $object_id, int $timeout=-1, int $retries=-1)
snmp_set_enum_print(bool $enable)
snmp3_set(string $hostname, string $security_name, string $security_level, string $auth_protocol, string $auth_passphrase, string $privacy_protocol, string $privacy_passphrase, array|string $object_id, array|string $type, array|string $value, int $timeout=-1, int $retries=-1)
snmp_get_valueretrieval()
snmpget(string $hostname, string $community, array|string $object_id, int $timeout=-1, int $retries=-1)
snmp3_get(string $hostname, string $security_name, string $security_level, string $auth_protocol, string $auth_passphrase, string $privacy_protocol, string $privacy_passphrase, array|string $object_id, int $timeout=-1, int $retries=-1)
const SNMP_VALUE_OBJECT
Definition snmp.stub.php:50
snmp2_walk(string $hostname, string $community, array|string $object_id, int $timeout=-1, int $retries=-1)
snmpset(string $hostname, string $community, array|string $object_id, array|string $type, array|string $value, int $timeout=-1, int $retries=-1)
snmprealwalk(string $hostname, string $community, array|string $object_id, int $timeout=-1, int $retries=-1)
#define vsnprintf
Definition snprintf.h:104
const AF_INET
const AF_INET6
const SOCK_DGRAM
PHPAPI zend_class_entry * spl_ce_RuntimeException
zval val
Definition zend_types.h:381
Bucket * arData
Definition zend_types.h:403
zval * arPacked
Definition zend_types.h:404
zend_object *(* create_object)(zend_class_entry *class_type)
Definition zend.h:195
const zend_object_handlers * default_object_handlers
Definition zend.h:186
zend_object_write_property_t write_property
zend_object_get_property_ptr_ptr_t get_property_ptr_ptr
zend_object_free_obj_t free_obj
zend_object_get_gc_t get_gc
zend_object_read_property_t read_property
zend_object_has_property_t has_property
zend_object_clone_obj_t clone_obj
zend_object_get_properties_t get_properties
#define LOG_ERR
Definition syslog.h:25
#define close(a)
#define errno
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format,...)
Definition zend.c:1772
ZEND_API ZEND_COLD void zend_type_error(const char *format,...)
Definition zend.c:1824
ZEND_API ZEND_COLD void zend_value_error(const char *format,...)
Definition zend.c:1849
#define INTERNAL_FUNCTION_PARAMETERS
Definition zend.h:49
#define INTERNAL_FUNCTION_PARAM_PASSTHRU
Definition zend.h:50
ZEND_API zend_result zend_parse_parameters(uint32_t num_args, const char *type_spec,...)
Definition zend_API.c:1300
ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type)
Definition zend_API.c:1688
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
Definition zend_API.c:433
ZEND_API void object_init(zval *arg)
Definition zend_API.c:1922
#define ZEND_NUM_ARGS()
Definition zend_API.h:530
#define RETURN_STRING(s)
Definition zend_API.h:1043
#define ZEND_PARSE_PARAMETERS_END()
Definition zend_API.h:1641
#define RETURN_FALSE
Definition zend_API.h:1058
#define ZVAL_STRING(z, s)
Definition zend_API.h:956
#define ZEND_DECLARE_MODULE_GLOBALS(module_name)
Definition zend_API.h:268
#define Z_PARAM_OPTIONAL
Definition zend_API.h:1667
#define ZEND_GET_MODULE(name)
Definition zend_API.h:241
#define zend_parse_parameters_none()
Definition zend_API.h:353
#define Z_PARAM_STR(dest)
Definition zend_API.h:2086
#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args)
Definition zend_API.h:1620
#define Z_PARAM_ARRAY_HT_OR_STR(dest_ht, dest_str)
Definition zend_API.h:2151
#define Z_PARAM_LONG(dest)
Definition zend_API.h:1896
#define RETURN_LONG(l)
Definition zend_API.h:1037
#define RETURN_BOOL(b)
Definition zend_API.h:1035
#define RETURN_THROWS()
Definition zend_API.h:1060
#define ZEND_THIS
Definition zend_API.h:523
#define Z_PARAM_BOOL(dest)
Definition zend_API.h:1726
#define getThis()
Definition zend_API.h:526
#define ZVAL_STRINGL(z, s, l)
Definition zend_API.h:952
#define RETVAL_FALSE
Definition zend_API.h:1032
#define RETURN_TRUE
Definition zend_API.h:1059
#define array_init(arg)
Definition zend_API.h:537
#define efree(ptr)
Definition zend_alloc.h:155
#define estrdup(s)
Definition zend_alloc.h:164
#define pefree(ptr, persistent)
Definition zend_alloc.h:191
#define erealloc(ptr, size)
Definition zend_alloc.h:159
#define safe_emalloc(nmemb, size, offset)
Definition zend_alloc.h:154
#define emalloc(size)
Definition zend_alloc.h:151
struct _zval_struct zval
strlen(string $string)
zend_string_release_ex(func->internal_function.function_name, 0)
zval * args
struct _zend_property_info zend_property_info
#define ZEND_CALL_USES_STRICT_TYPES(call)
#define BP_VAR_IS
#define snprintf
#define E_ERROR
Definition zend_errors.h:23
#define E_WARNING
Definition zend_errors.h:24
ZEND_API ZEND_COLD zend_object * zend_throw_exception_ex(zend_class_entry *exception_ce, zend_long code, const char *format,...)
ZEND_API bool zend_never_inline zend_verify_property_type(const zend_property_info *info, zval *property, bool strict)
#define EG(v)
ZEND_API void ZEND_FASTCALL zend_hash_destroy(HashTable *ht)
Definition zend_hash.c:1727
ZEND_API zval *ZEND_FASTCALL zend_hash_update(HashTable *ht, zend_string *key, zval *pData)
Definition zend_hash.c:997
#define zend_hash_init(ht, nSize, pHashFunction, pDestructor, persistent)
Definition zend_hash.h:108
#define HT_IS_PACKED(ht)
Definition zend_hash.h:59
#define ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(ht, _key, _ptr)
Definition zend_hash.h:1433
#define ZEND_HASH_FOREACH_END()
Definition zend_hash.h:1086
#define ZEND_HASH_FOREACH_VAL(ht, _val)
Definition zend_hash.h:1102
zend_string * tmp_value
Definition zend_ini.c:900
else
Definition zend_ini.c:906
int32_t zend_long
Definition zend_long.h:42
struct _zend_string zend_string
#define ZEND_MOD_END
struct _zend_module_dep zend_module_dep
struct _zend_module_entry zend_module_entry
#define ZEND_MOD_REQUIRED(name)
#define STANDARD_MODULE_PROPERTIES_EX
#define STANDARD_MODULE_HEADER_EX
ZEND_API zval * zend_std_get_property_ptr_ptr(zend_object *zobj, zend_string *name, int type, void **cache_slot)
ZEND_API HashTable * zend_std_get_properties(zend_object *zobj)
ZEND_API int zend_std_has_property(zend_object *zobj, zend_string *name, int has_set_exists, void **cache_slot)
ZEND_API const zend_object_handlers std_object_handlers
ZEND_API zval * zend_std_write_property(zend_object *zobj, zend_string *name, zval *value, void **cache_slot)
ZEND_API zend_property_info * zend_get_property_info(const zend_class_entry *ce, zend_string *member, int silent)
ZEND_API zval * zend_std_read_property(zend_object *zobj, zend_string *name, int type, void **cache_slot, zval *rv)
#define ZEND_PROPERTY_ISSET
#define ZEND_PROPERTY_EXISTS
ZEND_API void ZEND_FASTCALL zend_object_std_init(zend_object *object, zend_class_entry *ce)
ZEND_API void zend_object_std_dtor(zend_object *object)
ZEND_API void ZEND_FASTCALL convert_to_boolean(zval *op)
ZEND_API void zend_reset_lc_ctype_locale(void)
#define XtOffsetOf(s_type, field)
#define ZEND_ASSERT(c)
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object
#define smart_string_free(s)
#define smart_string_appends(str, src)
ZEND_API zend_string_init_interned_func_t zend_string_init_interned
Definition zend_string.c:31
#define ZSTR_VAL(zstr)
Definition zend_string.h:68
#define ZSTR_LEN(zstr)
Definition zend_string.h:69
#define zend_string_equals_literal_ci(str, c)
#define Z_TYPE_P(zval_p)
Definition zend_types.h:660
#define IS_TRUE
Definition zend_types.h:603
#define IS_FALSE
Definition zend_types.h:602
#define IS_UNDEF
Definition zend_types.h:600
#define ZVAL_NULL(z)
#define ZVAL_LONG(z, l)
struct _zend_array HashTable
Definition zend_types.h:386
#define IS_ARRAY
Definition zend_types.h:607
#define Z_PTR_P(zval_p)
#define IS_NULL
Definition zend_types.h:601
@ FAILURE
Definition zend_types.h:61
#define ZEND_TYPE_IS_SET(t)
Definition zend_types.h:166
#define ZVAL_COPY(z, v)
struct _zend_object_handlers zend_object_handlers
Definition zend_types.h:88
#define ZVAL_COPY_VALUE(z, v)
ZEND_API void zval_ptr_dtor(zval *zval_ptr)
zval retval
zval * return_value
zend_string * name
object
zval * ret
value