00001
00002
00003
00004
00005 #include <net-snmp/net-snmp-config.h>
00006
00007 #include <sys/types.h>
00008 #if HAVE_STDLIB_H
00009 #include <stdlib.h>
00010 #endif
00011 #if HAVE_STRING_H
00012 #include <string.h>
00013 #else
00014 #include <strings.h>
00015 #endif
00016 #include <stdio.h>
00017 #include <ctype.h>
00018 #include <errno.h>
00019
00020 #if TIME_WITH_SYS_TIME
00021 # ifdef WIN32
00022 # include <sys/timeb.h>
00023 # else
00024 # include <sys/time.h>
00025 # endif
00026 # include <time.h>
00027 #else
00028 # if HAVE_SYS_TIME_H
00029 # include <sys/time.h>
00030 # else
00031 # include <time.h>
00032 # endif
00033 #endif
00034 #if HAVE_NETINET_IN_H
00035 #include <netinet/in.h>
00036 #endif
00037 #if HAVE_NETINET_IN_SYSTM_H
00038 #include <netinet/in_systm.h>
00039 #endif
00040 #if HAVE_NETINET_IP_H
00041 #include <netinet/ip.h>
00042 #endif
00043 #ifdef INET6
00044 #if HAVE_NETINET_IP6_H
00045 #include <netinet/ip6.h>
00046 #endif
00047 #endif
00048 #if HAVE_SYS_QUEUE_H
00049 #include <sys/queue.h>
00050 #endif
00051 #if HAVE_SYS_SOCKET_H
00052 #include <sys/socket.h>
00053 #if HAVE_SYS_SOCKETVAR_H
00054 #ifndef dynix
00055 #include <sys/socketvar.h>
00056 #else
00057 #include <sys/param.h>
00058 #endif
00059 #endif
00060 #elif HAVE_WINSOCK_H
00061 #include <winsock.h>
00062 #endif
00063 #if HAVE_SYS_STREAM_H
00064 # ifdef sysv5UnixWare7
00065 # define _KMEMUSER 1
00066 # endif
00067 #include <sys/stream.h>
00068 #endif
00069 #if HAVE_NET_ROUTE_H
00070 #include <net/route.h>
00071 #endif
00072 #if HAVE_NETINET_IP_VAR_H
00073 #include <netinet/ip_var.h>
00074 #endif
00075 #ifdef INET6
00076 #if HAVE_NETINET6_IP6_VAR_H
00077 #include <netinet6/ip6_var.h>
00078 #endif
00079 #endif
00080 #if HAVE_NETINET_IN_PCB_H
00081 #include <netinet/in_pcb.h>
00082 #endif
00083 #if HAVE_INET_MIB2_H
00084 #include <inet/mib2.h>
00085 #endif
00086
00087 #if HAVE_UNISTD_H
00088 #include <unistd.h>
00089 #endif
00090 #ifdef HAVE_PWD_H
00091 #include <pwd.h>
00092 #endif
00093 #ifdef HAVE_GRP_H
00094 #include <grp.h>
00095 #endif
00096
00097 #include <net-snmp/net-snmp-includes.h>
00098 #include <net-snmp/agent/net-snmp-agent-includes.h>
00099
00100 #include "mibgroup/struct.h"
00101 #include <net-snmp/agent/agent_trap.h>
00102 #include "snmpd.h"
00103 #include <net-snmp/agent/agent_callbacks.h>
00104 #include <net-snmp/agent/table.h>
00105 #include <net-snmp/agent/table_iterator.h>
00106 #include <net-snmp/agent/table_data.h>
00107 #include <net-snmp/agent/table_dataset.h>
00108 #include "agent_module_includes.h"
00109 #include "mib_module_includes.h"
00110
00111 char dontReadConfigFiles;
00112 char *optconfigfile;
00113
00114 #ifdef HAVE_UNISTD_H
00115 void
00116 snmpd_set_agent_user(const char *token, char *cptr)
00117 {
00118 #if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H)
00119 struct passwd *info;
00120 #endif
00121
00122 if (cptr[0] == '#') {
00123 char *ecp;
00124 int uid;
00125 uid = strtoul(cptr + 1, &ecp, 10);
00126 if (*ecp != 0) {
00127 config_perror("Bad number");
00128 } else {
00129 netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
00130 NETSNMP_DS_AGENT_USERID, uid);
00131 }
00132 }
00133 #if defined(HAVE_GETPWNAM) && defined(HAVE_PWD_H)
00134 else if ((info = getpwnam(cptr)) != NULL) {
00135 netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
00136 NETSNMP_DS_AGENT_USERID, info->pw_uid);
00137 } else {
00138 config_perror("User not found in passwd database");
00139 }
00140 endpwent();
00141 #endif
00142 }
00143
00144 void
00145 snmpd_set_agent_group(const char *token, char *cptr)
00146 {
00147 #if defined(HAVE_GETGRNAM) && defined(HAVE_GRP_H)
00148 struct group *info;
00149 #endif
00150
00151 if (cptr[0] == '#') {
00152 char *ecp;
00153 int gid = strtoul(cptr + 1, &ecp, 10);
00154 if (*ecp != 0) {
00155 config_perror("Bad number");
00156 } else {
00157 netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
00158 NETSNMP_DS_AGENT_GROUPID, gid);
00159 }
00160 }
00161 #if defined(HAVE_GETGRNAM) && defined(HAVE_GRP_H)
00162 else if ((info = getgrnam(cptr)) != NULL) {
00163 netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
00164 NETSNMP_DS_AGENT_GROUPID, info->gr_gid);
00165 } else {
00166 config_perror("Group not found in group database");
00167 }
00168 endpwent();
00169 #endif
00170 }
00171 #endif
00172
00173 void
00174 snmpd_set_agent_address(const char *token, char *cptr)
00175 {
00176 char buf[SPRINT_MAX_LEN];
00177 char *ptr;
00178
00179
00180
00181
00182 ptr = netsnmp_ds_get_string(NETSNMP_DS_APPLICATION_ID,
00183 NETSNMP_DS_AGENT_PORTS);
00184
00185 if (ptr) {
00186
00187
00188
00189 sprintf(buf, "%s,%s", ptr, cptr);
00190 } else {
00191 strcpy(buf, cptr);
00192 }
00193
00194 DEBUGMSGTL(("snmpd_ports", "port spec: %s\n", buf));
00195 netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
00196 NETSNMP_DS_AGENT_PORTS, buf);
00197 }
00198
00199 void
00200 init_agent_read_config(const char *app)
00201 {
00202 if (app != NULL) {
00203 netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID,
00204 NETSNMP_DS_LIB_APPTYPE, app);
00205 } else {
00206 app = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID,
00207 NETSNMP_DS_LIB_APPTYPE);
00208 }
00209
00210 register_app_config_handler("authtrapenable",
00211 snmpd_parse_config_authtrap, NULL,
00212 "1 | 2\t\t(1 = enable, 2 = disable)");
00213 register_app_config_handler("pauthtrapenable",
00214 snmpd_parse_config_authtrap, NULL, NULL);
00215
00216
00217 if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
00218 NETSNMP_DS_AGENT_ROLE) == MASTER_AGENT) {
00219 #ifndef DISABLE_SNMPV1
00220 register_app_config_handler("trapsink",
00221 snmpd_parse_config_trapsink,
00222 snmpd_free_trapsinks,
00223 "host [community] [port]");
00224 #endif
00225 #ifndef DISABLE_SNMPV2C
00226 register_app_config_handler("trap2sink",
00227 snmpd_parse_config_trap2sink, NULL,
00228 "host [community] [port]");
00229 register_app_config_handler("informsink",
00230 snmpd_parse_config_informsink, NULL,
00231 "host [community] [port]");
00232 #endif
00233 register_app_config_handler("trapsess",
00234 snmpd_parse_config_trapsess, NULL,
00235 "[snmpcmdargs] host");
00236 }
00237 #if !defined(DISABLE_SNMPV1) || !defined(DISABLE_SNMPV2C)
00238 register_app_config_handler("trapcommunity",
00239 snmpd_parse_config_trapcommunity,
00240 snmpd_free_trapcommunity,
00241 "community-string");
00242 #endif
00243 netsnmp_ds_register_config(ASN_OCTET_STR, app, "v1trapaddress",
00244 NETSNMP_DS_APPLICATION_ID,
00245 NETSNMP_DS_AGENT_TRAP_ADDR);
00246 #ifdef HAVE_UNISTD_H
00247 register_app_config_handler("agentuser",
00248 snmpd_set_agent_user, NULL, "userid");
00249 register_app_config_handler("agentgroup",
00250 snmpd_set_agent_group, NULL, "groupid");
00251 #endif
00252 register_app_config_handler("agentaddress",
00253 snmpd_set_agent_address, NULL,
00254 "SNMP bind address");
00255 netsnmp_ds_register_config(ASN_BOOLEAN, app, "quit",
00256 NETSNMP_DS_APPLICATION_ID,
00257 NETSNMP_DS_AGENT_QUIT_IMMEDIATELY);
00258 netsnmp_ds_register_config(ASN_BOOLEAN, app, "leave_pidfile",
00259 NETSNMP_DS_APPLICATION_ID,
00260 NETSNMP_DS_AGENT_LEAVE_PIDFILE);
00261 netsnmp_ds_register_config(ASN_BOOLEAN, app, "dontLogTCPWrappersConnects",
00262 NETSNMP_DS_APPLICATION_ID,
00263 NETSNMP_DS_AGENT_DONT_LOG_TCPWRAPPERS_CONNECTS);
00264 netsnmp_ds_register_config(ASN_INTEGER, app, "maxGetbulkRepeats",
00265 NETSNMP_DS_APPLICATION_ID,
00266 NETSNMP_DS_AGENT_MAX_GETBULKREPEATS);
00267 netsnmp_ds_register_config(ASN_INTEGER, app, "maxGetbulkResponses",
00268 NETSNMP_DS_APPLICATION_ID,
00269 NETSNMP_DS_AGENT_MAX_GETBULKRESPONSES);
00270 netsnmp_init_handler_conf();
00271
00272 #include "agent_module_dot_conf.h"
00273 #include "mib_module_dot_conf.h"
00274 #ifdef TESTING
00275 print_config_handlers();
00276 #endif
00277 }
00278
00279 void
00280 update_config(void)
00281 {
00282 snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
00283 SNMPD_CALLBACK_PRE_UPDATE_CONFIG, NULL);
00284 free_config();
00285 vacm_standard_views(0,0,NULL,NULL);
00286 read_configs();
00287 }
00288
00289
00290 void
00291 snmpd_register_config_handler(const char *token,
00292 void (*parser) (const char *, char *),
00293 void (*releaser) (void), const char *help)
00294 {
00295 DEBUGMSGTL(("snmpd_register_app_config_handler",
00296 "registering .conf token for \"%s\"\n", token));
00297 register_app_config_handler(token, parser, releaser, help);
00298 }
00299
00300 void
00301 snmpd_unregister_config_handler(const char *token)
00302 {
00303 unregister_app_config_handler(token);
00304 }
00305
00306
00307
00308
00309
00310 void
00311 snmpd_store_config(const char *line)
00312 {
00313 read_app_config_store(line);
00314 }