int main(int argc, char **argv) { netsnmp_session *session = NULL; netsnmp_transport *transport = NULL; char *listening_address = "udp:5200"; int local = 1; char *default_domain = "udp"; program_name = basename(argv[0]); printf("%s: main\n", program_name); init_usm(); netsnmp_udp_ctor(); init_snmpv3(NULL); setup_engineID(NULL, NULL); usm_parse_create_usmUser("createUser", "-e 0x8000000001020304 traptest SHA mypassword AES"); transport = netsnmp_tdomain_transport(listening_address, local, default_domain); if (transport == NULL) { printf("%s: failed to open server: %s\n", argv[0], strerror(errno)); exit(EXIT_FAILURE); } session = snmptrapd_add_session(transport); select_loop(); snmp_close(session); exit(EXIT_SUCCESS); }
/*******************************************************************-o-****** * init_snmpv3 * * Parameters: * *type Label for the config file "type" used by calling entity. * * Set time and engineID. * Set parsing functions for config file tokens. * Initialize SNMP Crypto API (SCAPI). */ void init_snmpv3(const char *type) { gettimeofday(&snmpv3starttime, NULL); if (type == NULL) type = "snmpapp"; if (type && !strcmp(type,"snmpapp")) { setup_engineID(NULL,"__snmpapp__"); } else { setup_engineID(NULL, NULL); } /* initialize submodules */ init_usm(); /* we need to be called back later */ snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_POST_READ_CONFIG, init_snmpv3_post_config, NULL); /* we need to be called back later */ snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA, snmpv3_store, (void *) type); #if !defined(USE_INTERNAL_MD5) /* doesn't belong here at all */ sc_init(); #endif /* !USE_INTERNAL_MD5 */ /* register all our configuration handlers (ack, there's a lot) */ /* handle engineID setup before everything else which may depend on it */ register_premib_handler(type,"engineID", engineID_conf, NULL, "string"); register_premib_handler(type,"oldEngineID", oldengineID_conf, NULL, NULL); register_config_handler(type,"engineBoots", engineBoots_conf, NULL, NULL); /* default store config entries */ ds_register_config(ASN_OCTET_STR, "snmp", "defSecurityName", DS_LIBRARY_ID, DS_LIB_SECNAME); ds_register_config(ASN_OCTET_STR, "snmp", "defContext", DS_LIBRARY_ID, DS_LIB_CONTEXT); ds_register_config(ASN_OCTET_STR, "snmp", "defPassphrase", DS_LIBRARY_ID, DS_LIB_PASSPHRASE); ds_register_config(ASN_OCTET_STR, "snmp", "defAuthPassphrase", DS_LIBRARY_ID, DS_LIB_AUTHPASSPHRASE); ds_register_config(ASN_OCTET_STR, "snmp", "defPrivPassphrase", DS_LIBRARY_ID, DS_LIB_PRIVPASSPHRASE); register_config_handler("snmp","defVersion", version_conf, NULL, "1|2c|3"); register_config_handler("snmp","defAuthType", snmpv3_authtype_conf, NULL, "MD5|SHA"); register_config_handler("snmp","defPrivType", snmpv3_privtype_conf, NULL, "DES (currently the only possible value)"); register_config_handler("snmp","defSecurityLevel", snmpv3_secLevel_conf, NULL, "noAuthNoPriv|authNoPriv|authPriv"); register_config_handler(type,"userSetAuthPass", usm_set_password, NULL, "secname engineIDLen engineID pass"); register_config_handler(type,"userSetPrivPass", usm_set_password, NULL, "secname engineIDLen engineID pass"); register_config_handler(type,"userSetAuthKey", usm_set_password, NULL, "secname engineIDLen engineID KuLen Ku"); register_config_handler(type,"userSetPrivKey", usm_set_password, NULL, "secname engineIDLen engineID KuLen Ku"); register_config_handler(type,"userSetAuthLocalKey", usm_set_password, NULL, "secname engineIDLen engineID KulLen Kul"); register_config_handler(type,"userSetPrivLocalKey", usm_set_password, NULL, "secname engineIDLen engineID KulLen Kul"); }