harrie          Mon Nov 11 16:09:19 2002 EDT

  Modified files:              
    /php4/ext/snmp      CREDITS php_snmp.h snmp.c 
  Log:
  Adding SNMPv3 support.
  This splits the old php_snmp function into an argument parsing part and
  a data retrieval part. The data retrieval part is reused for SNMPv3.
  SNMPv3 has only a different argument parsing.
  
  THe code is not extremely beautiful, but having NET-SNMP and 
  UCD-SNMP support creates this. :-(
  Documentation must still be done.
  
  
Index: php4/ext/snmp/CREDITS
diff -u php4/ext/snmp/CREDITS:1.1 php4/ext/snmp/CREDITS:1.2
--- php4/ext/snmp/CREDITS:1.1   Mon Nov 20 05:31:36 2000
+++ php4/ext/snmp/CREDITS       Mon Nov 11 16:09:19 2002
@@ -1,2 +1,3 @@
 SNMP
 Rasmus Lerdorf
+Harrie Hazewinkel
Index: php4/ext/snmp/php_snmp.h
diff -u php4/ext/snmp/php_snmp.h:1.12 php4/ext/snmp/php_snmp.h:1.13
--- php4/ext/snmp/php_snmp.h:1.12       Thu Feb 28 03:26:42 2002
+++ php4/ext/snmp/php_snmp.h    Mon Nov 11 16:09:19 2002
@@ -15,10 +15,11 @@
 | Authors: Rasmus Lerdorf <[EMAIL PROTECTED]>                             |
 |          Mike Jackson <[EMAIL PROTECTED]>                            |
 |          Steven Lawrance <[EMAIL PROTECTED]>                |
+|          Harrie Hazewinkel <[EMAIL PROTECTED]>                      |
 +----------------------------------------------------------------------+
 */
 
-/* $Id: php_snmp.h,v 1.12 2002/02/28 08:26:42 sebastian Exp $ */
+/* $Id: php_snmp.h,v 1.13 2002/11/11 21:09:19 harrie Exp $ */
 #ifndef PHP_SNMP_H
 #define PHP_SNMP_H
 
@@ -37,6 +38,12 @@
 PHP_FUNCTION(snmp_get_quick_print);
 PHP_FUNCTION(snmp_set_quick_print);
 PHP_FUNCTION(snmpset);
+PHP_FUNCTION(snmpv3get);
+PHP_FUNCTION(snmpv3getnext);
+PHP_FUNCTION(snmpv3walk);
+PHP_FUNCTION(snmpv3realwalk);
+PHP_FUNCTION(snmpv3set);
+PHP_FUNCTION(snmpv3getbulk);
 PHP_MINFO_FUNCTION(snmp);
 #else
 
Index: php4/ext/snmp/snmp.c
diff -u php4/ext/snmp/snmp.c:1.68 php4/ext/snmp/snmp.c:1.69
--- php4/ext/snmp/snmp.c:1.68   Mon Nov 11 13:45:50 2002
+++ php4/ext/snmp/snmp.c        Mon Nov 11 16:09:19 2002
@@ -15,9 +15,10 @@
 | Authors: Rasmus Lerdorf <[EMAIL PROTECTED]>                             |
 |          Mike Jackson <[EMAIL PROTECTED]>                            |
 |          Steven Lawrance <[EMAIL PROTECTED]>                |
+|          Harrie Hazewinkel <[EMAIL PROTECTED]>                      |
 +----------------------------------------------------------------------+
 */
-/* $Id: snmp.c,v 1.68 2002/11/11 18:45:50 harrie Exp $ */
+/* $Id: snmp.c,v 1.69 2002/11/11 21:09:19 harrie Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -84,10 +85,17 @@
 #include "snmp_client.h"
 #include "snmp_impl.h"
 #include "snmp.h"
+#include "snmpv3.h"
+#include "keytools.h"
 #include "parse.h"
 #include "mib.h"
 #include "version.h"
+#include "transform_oids.h"
 #endif
+/* 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))
 
 /* For really old ucd-snmp versions.. */
 #ifndef HAVE_SNMP_PARSE_OID
@@ -113,6 +121,11 @@
        PHP_FE(snmp_get_quick_print, NULL)
        PHP_FE(snmp_set_quick_print, NULL)
        PHP_FE(snmpset, NULL)
+       PHP_FE(snmpv3get, NULL)
+       PHP_FE(snmpv3walk, NULL)
+       PHP_FE(snmpv3realwalk, NULL)
+       PHP_FALIAS(snmpv3walkoid, snmpv3realwalk, NULL)
+       PHP_FE(snmpv3set, NULL)
        {NULL,NULL,NULL}
 };
 /* }}} */
@@ -143,7 +156,7 @@
  */
 PHP_MINIT_FUNCTION(snmp)
 {
-       init_mib();
+       init_snmp("snmpapp");
        return SUCCESS;
 }
 /* }}} */
@@ -164,9 +177,9 @@
 }
 /* }}} */
 
-/* {{{ php_snmp
+/* {{{ php_snmp_internal
 *
-* Generic SNMP object fetcher
+* Generic SNMP object fetcher (for both v3 and v1)
 *
 * st=1   snmpget()  - query an agent and return a single value.
 * st=2   snmpwalk() - walk the mib and return a single dimensional array 
@@ -177,72 +190,27 @@
 * st=11  snmpset()  - query an agent and set a single value
 *
 */
-static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st) 
+static void php_snmp_internal(INTERNAL_FUNCTION_PARAMETERS,
+               int st,
+               struct snmp_session *session,
+               char *objid) 
 {
-       zval **a1, **a2, **a3, **a4, **a5, **a6, **a7;
-       struct snmp_session session, *ss;
+       struct snmp_session *ss;
        struct snmp_pdu *pdu=NULL, *response;
        struct variable_list *vars;
-       char *objid;
        oid name[MAX_NAME_LEN];
        int name_length;
-       int status, count,rootlen=0,gotroot=0;
        oid root[MAX_NAME_LEN];
+       int rootlen = 0;
+       int gotroot = 0;
+       int status, count;
        char buf[2048];
        char buf2[2048];
        int keepwalking=1;
-       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, *err;
-
-       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);
-       
-               if(myargc > 5) {
-                       convert_to_long_ex(a6);
-                       timeout = Z_LVAL_PP(a6);
-               }
+       char *err;
 
-               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);
-               }
-       }
-
-       objid = Z_STRVAL_PP(a3);
-       
        if (st >= 2) { /* walk */
                rootlen = MAX_NAME_LEN;
                if (strlen(objid)) { /* on a walk, an empty string means top of tree - 
no error */
@@ -259,40 +227,9 @@
                        gotroot = 1;
                }
        }
-       
-       memset(&session, 0, sizeof(struct snmp_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;
-
-#ifndef HAVE_NET_SNMP
-       snmp_synch_setup(&session);
-#endif
-
-       if ((ss = snmp_open(&session)) == NULL) {
-               snmp_error(&session, NULL, NULL, &err);
+       if ((ss = snmp_open(session)) == NULL) {
+               snmp_error(session, NULL, NULL, &err);
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not open snmp 
connection: %s", err);
                free(err);
                RETURN_FALSE;
@@ -334,7 +271,7 @@
                        pdu = snmp_pdu_create(SNMP_MSG_GETNEXT);
                        snmp_add_null_var(pdu, name, name_length);
                }
-               
+
 retry:
                status = snmp_synch_response(ss, pdu, &response);
                if (status == STAT_SUCCESS) {
@@ -349,7 +286,7 @@
 #ifdef HAVE_NET_SNMP
                                                snprint_value(buf, sizeof(buf), 
vars->name, vars->name_length, vars);
 #else
-                                               sprint_value((struct sbuf *) 
buf,vars->name, vars->name_length, vars);
+                                               sprint_value(buf,vars->name, 
+vars->name_length, vars);
 #endif
                                        }
 
@@ -361,7 +298,7 @@
 #ifdef HAVE_NET_SNMP
                                                snprint_objid(buf2, sizeof(buf2), 
vars->name, vars->name_length);
 #else
-                                               sprint_objid((struct sbuf *)buf2, 
vars->name, vars->name_length);
+                                               sprint_objid(buf2, vars->name, 
+vars->name_length);
 #endif
                                                
add_assoc_string(return_value,buf2,buf,1);
                                        }
@@ -384,7 +321,7 @@
 #ifdef HAVE_NET_SNMP
                                                        snprint_objid(buf, 
sizeof(buf), vars->name, vars->name_length);
 #else
-                                                       sprint_objid((struct sbuf 
*)buf,vars->name, vars->name_length);
+                                                       sprint_objid(buf,vars->name, 
+vars->name_length);
 #endif
                                                }
                                                php_error_docref(NULL TSRMLS_CC, 
E_WARNING, "This name does not exist: %s",buf);
@@ -407,7 +344,7 @@
                                }
                        }
                } else if (status == STAT_TIMEOUT) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "No Response from 
%s", Z_STRVAL_PP(a1));
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "No Response from 
+%s", session->peername);
                        if (st == 2 || st == 3) {
                                zval_dtor(return_value);
                        }
@@ -429,6 +366,106 @@
 }
 /* }}} */
 
+/* {{{ 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();
+    char type = (char) 0;
+    char *value = (char *) 0;
+       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);
+       
+               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;
+
+       php_snmp_internal(INTERNAL_FUNCTION_PARAM_PASSTHRU, st, &session, 
+Z_STRVAL_PP(a3));
+}
+/* }}} */
+
 /* {{{ proto string snmpget(string host, string community, string object_id [, int 
timeout [, int retries]]) 
    Fetch a SNMP object */
 PHP_FUNCTION(snmpget)
@@ -493,6 +530,337 @@
 PHP_FUNCTION(snmpset)
 {
        php_snmp(INTERNAL_FUNCTION_PARAM_PASSTHRU,11);
+}
+/* }}} */
+
+/* {{{ proto int netsnmp_session_set_sec_name(struct snmp_session *s, char *name)
+    Set the security name in the snmpv3 session */
+static int
+netsnmp_session_set_sec_name(struct snmp_session *s, char *name)
+{
+    if ((s) && (name)) {     
+        s->securityName = strdup(name);
+        s->securityNameLen = strlen(s->securityName);
+        return (0);
+    }        
+    return (-1);
+}
+/* }}} */
+
+/* {{{ proto int netsnmp_session_set_sec_level(struct snmp_session *s, char *level)
+    Set the security level in the snmpv3 session */
+static int
+netsnmp_session_set_sec_level(struct snmp_session *s, char *level)
+{
+    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);
+        }
+        fprintf(stderr, "Invalid security level: %s\n",
+                level);
+    }
+    return (-1);
+}
+/* }}} */
+
+/* {{{ proto int netsnmp_session_set_auth_protocol(struct snmp_session *s, char *prot)
+    Set the authentication protocol in the snmpv3 session */
+static int
+netsnmp_session_set_auth_protocol(struct snmp_session *s, char *prot)
+{
+    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)) {
+            fprintf(stderr,
+                    "Invalid authentication protocol: %s\n",
+                    prot);
+        }
+    }
+    return (-1);
+}
+/* }}} */
+
+/* {{{ proto int netsnmp_session_set_sec_protocol(struct snmp_session *s, char *prot)
+    Set the security protocol in the snmpv3 session */
+static int
+netsnmp_session_set_sec_protocol(struct snmp_session *s, char *prot)
+{
+    if ((s) && (prot)) {
+        if (!strcasecmp(prot, "DES")) {
+            s->securityPrivProto = usmDESPrivProtocol;
+            s->securityPrivProtoLen = OIDSIZE(usmDESPrivProtocol);
+            return (0);
+#ifdef HAVE_AES
+        } 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);
+#endif
+        } else if (strlen(prot)) {
+            fprintf(stderr,
+                    "Invalid privacy protocol: %s\n",
+                    prot);
+        }
+    }
+    return (-1);
+}
+/* }}} */
+
+/* {{{ proto int netsnmp_session_gen_auth_key(struct snmp_session *s, char *pass)
+    make key from pass phrase in the snmpv3 session */
+static int
+netsnmp_session_gen_auth_key(struct snmp_session *s, char *pass)
+{
+    /*
+     * 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 */
+            const 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) {
+            fprintf(stderr,
+                    "Error generating a key for authentication pass phrase.\n");
+            return (-2);
+        }
+        return (0);
+    }
+    return (-1);
+}
+/* }}} */
+
+/* {{{ proto int netsnmp_session_gen_sec_key(struct snmp_session *s, u_char *pass)
+   make key from pass phrase in the snmpv3 session */
+static int
+netsnmp_session_gen_sec_key(struct snmp_session *s, u_char *pass)
+{
+    if ((s) && (pass) && strlen(pass)) {
+        s->securityPrivKeyLen = USM_PRIV_KU_LEN;
+        if (s->securityPrivProto == NULL) {
+            /* get .conf set default */
+            const 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) {
+            fprintf(stderr,
+                    "Error generating a key for privacy pass phrase.\n");
+            return (-2);
+        }
+        return (0);
+    }
+    return (-1);
+}
+/* }}} */
+
+
+/* {{{ proto void php_snmpv3(INTERNAL_FUNCTION_PARAMETERS, int st)
+*
+* Generic SNMPv3 object fetcher
+* From here is passed on the the common internal object fetcher.
+*
+* st=1   snmpv3get() - query an agent and return a single value.
+* st=2   snmpv3walk() - walk the mib and return a single dimensional array 
+*          containing the values.
+* st=3   snmpv3realwalk() and snmpv3walkoid() - walk the mib and return an 
+*          array of oid,value pairs.
+* st=11  snmpv3set() - query an agent and set a single value
+*
+*/
+void php_snmpv3(INTERNAL_FUNCTION_PARAMETERS, int st) {
+       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);
+        /* This is all SNMPv3 */
+       session.version = SNMP_VERSION_3;
+
+        /* Reading the hostname and its optional non-default port number */
+       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;
+
+        /* Setting the security name. */
+       convert_to_string_ex(a2);
+        if (netsnmp_session_set_sec_name(&session, Z_STRVAL_PP(a2))) {
+               php_error(E_WARNING,"Could net set security name: %s\n", 
+Z_STRVAL_PP(a2));
+               RETURN_FALSE;
+       }
+
+        /* Setting the security level. */
+        convert_to_string_ex(a3);
+       if (netsnmp_session_set_sec_level(&session, Z_STRVAL_PP(a3))) {
+            php_error(E_WARNING,"Invalid security level: %s\n", a3);
+            RETURN_FALSE;
+        }
+
+        /* Setting the authentication protocol. */
+        convert_to_string_ex(a4);
+       if (netsnmp_session_set_auth_protocol(&session, Z_STRVAL_PP(a4))) {
+            php_error(E_WARNING,"Invalid authentication protocol: %s\n", 
+Z_STRVAL_PP(a4));
+            RETURN_FALSE;
+        }
+        /* Setting the authentication passphrase. */
+        convert_to_string_ex(a5);
+        if (netsnmp_session_gen_auth_key(&session, Z_STRVAL_PP(a5))) {
+            php_error(E_WARNING,"Could not generate key for authentication pass 
+phrase: %s\n", Z_STRVAL_PP(a4));
+            RETURN_FALSE;
+        }
+
+        /* Setting the security protocol. */
+        convert_to_string_ex(a6);
+       if (netsnmp_session_set_sec_protocol(&session, Z_STRVAL_PP(a6)) &&
+                                                       (0 != 
+strlen(Z_STRVAL_PP(a6)))) {
+            php_error(E_WARNING,"Invalid security protocol: %s\n", Z_STRVAL_PP(a6));
+            RETURN_FALSE;
+        }
+        /* Setting the security protocol passphrase. */
+        convert_to_string_ex(a7);
+       if (netsnmp_session_gen_sec_key(&session, Z_STRVAL_PP(a7)) &&
+                                                       (0 != 
+strlen(Z_STRVAL_PP(a7)))) {
+            php_error(E_WARNING,"Could not generate key for security pass phrase: 
+%s\n", Z_STRVAL_PP(a7));
+            RETURN_FALSE;
+        }
+
+       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);
+                type = Z_STRVAL_PP(a9)[0];
+                value = Z_STRVAL_PP(a10);
+       } 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;
+
+       php_snmp_internal(INTERNAL_FUNCTION_PARAM_PASSTHRU, st, &session, 
+Z_STRVAL_PP(a8));
+}
+/* }}} */
+
+/* {{{ proto int snmpv3get(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]])
+   Fetch the value of a SNMP object */
+PHP_FUNCTION(snmpv3get)
+{
+        php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU,1);
+}
+/* }}} */
+
+
+/* {{{ proto int snmpv3walk(string host,
+                                 string sec_name, string sec_level,
+                                 string auth_protocol, string auth_passphrase,
+                                 string priv_protocol, string priv_passphrase,
+                                 tring object_id [, int timeout [, int retries]])
+   Fetch the value of a SNMP object */
+PHP_FUNCTION(snmpv3walk)
+{
+        php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU,2);
+}
+/* }}} */
+
+/* {{{ proto int snmpv3realwalk(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]])
+   Fetch the value of a SNMP object */
+PHP_FUNCTION(snmpv3realwalk)
+{
+        php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU,3);
+}
+/* }}} */
+
+/* {{{ proto int snmpv3set(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]])
+   Fetch the value of a SNMP object */
+PHP_FUNCTION(snmpv3set)
+{
+        php_snmpv3(INTERNAL_FUNCTION_PARAM_PASSTHRU,11);
 }
 /* }}} */
 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to