00001 /* 00002 * agent_read_config.c 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 NETSNMP_ENABLE_IPV6 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 /* <sys/stream.h> needs this for queue_t */ 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 NETSNMP_ENABLE_IPV6 00076 #if HAVE_NETNETSNMP_ENABLE_IPV6_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 * has something been specified before? 00181 */ 00182 ptr = netsnmp_ds_get_string(NETSNMP_DS_APPLICATION_ID, 00183 NETSNMP_DS_AGENT_PORTS); 00184 00185 if (ptr) { 00186 /* 00187 * append to the older specification string 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 NETSNMP_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 NETSNMP_DISABLE_SNMPV2C 00226 register_app_config_handler("trap2sink", 00227 snmpd_parse_config_trap2sink, 00228 snmpd_free_trapsinks, 00229 "host [community] [port]"); 00230 register_app_config_handler("informsink", 00231 snmpd_parse_config_informsink, 00232 snmpd_free_trapsinks, 00233 "host [community] [port]"); 00234 #endif 00235 register_app_config_handler("trapsess", 00236 snmpd_parse_config_trapsess, 00237 snmpd_free_trapsinks, 00238 "[snmpcmdargs] host"); 00239 } 00240 #if !defined(NETSNMP_DISABLE_SNMPV1) || !defined(NETSNMP_DISABLE_SNMPV2C) 00241 register_app_config_handler("trapcommunity", 00242 snmpd_parse_config_trapcommunity, 00243 snmpd_free_trapcommunity, 00244 "community-string"); 00245 #endif /* support for community based SNMP */ 00246 netsnmp_ds_register_config(ASN_OCTET_STR, app, "v1trapaddress", 00247 NETSNMP_DS_APPLICATION_ID, 00248 NETSNMP_DS_AGENT_TRAP_ADDR); 00249 #ifdef HAVE_UNISTD_H 00250 register_app_config_handler("agentuser", 00251 snmpd_set_agent_user, NULL, "userid"); 00252 register_app_config_handler("agentgroup", 00253 snmpd_set_agent_group, NULL, "groupid"); 00254 #endif 00255 register_app_config_handler("agentaddress", 00256 snmpd_set_agent_address, NULL, 00257 "SNMP bind address"); 00258 netsnmp_ds_register_config(ASN_BOOLEAN, app, "quit", 00259 NETSNMP_DS_APPLICATION_ID, 00260 NETSNMP_DS_AGENT_QUIT_IMMEDIATELY); 00261 netsnmp_ds_register_config(ASN_BOOLEAN, app, "leave_pidfile", 00262 NETSNMP_DS_APPLICATION_ID, 00263 NETSNMP_DS_AGENT_LEAVE_PIDFILE); 00264 netsnmp_ds_register_config(ASN_BOOLEAN, app, "dontLogTCPWrappersConnects", 00265 NETSNMP_DS_APPLICATION_ID, 00266 NETSNMP_DS_AGENT_DONT_LOG_TCPWRAPPERS_CONNECTS); 00267 netsnmp_ds_register_config(ASN_INTEGER, app, "maxGetbulkRepeats", 00268 NETSNMP_DS_APPLICATION_ID, 00269 NETSNMP_DS_AGENT_MAX_GETBULKREPEATS); 00270 netsnmp_ds_register_config(ASN_INTEGER, app, "maxGetbulkResponses", 00271 NETSNMP_DS_APPLICATION_ID, 00272 NETSNMP_DS_AGENT_MAX_GETBULKRESPONSES); 00273 netsnmp_init_handler_conf(); 00274 00275 #include "agent_module_dot_conf.h" 00276 #include "mib_module_dot_conf.h" 00277 #ifdef TESTING 00278 print_config_handlers(); 00279 #endif 00280 } 00281 00282 void 00283 update_config(void) 00284 { 00285 snmp_call_callbacks(SNMP_CALLBACK_APPLICATION, 00286 SNMPD_CALLBACK_PRE_UPDATE_CONFIG, NULL); 00287 free_config(); 00288 read_configs(); 00289 } 00290 00291 00292 void 00293 snmpd_register_config_handler(const char *token, 00294 void (*parser) (const char *, char *), 00295 void (*releaser) (void), const char *help) 00296 { 00297 DEBUGMSGTL(("snmpd_register_app_config_handler", 00298 "registering .conf token for \"%s\"\n", token)); 00299 register_app_config_handler(token, parser, releaser, help); 00300 } 00301 00302 void 00303 snmpd_unregister_config_handler(const char *token) 00304 { 00305 unregister_app_config_handler(token); 00306 } 00307 00308 /* 00309 * this function is intended for use by mib-modules to store permenant 00310 * configuration information generated by sets or persistent counters 00311 */ 00312 void 00313 snmpd_store_config(const char *line) 00314 { 00315 read_app_config_store(line); 00316 }
Last modified: Wednesday, 01-Aug-2018 04:41:28 UTC
For questions regarding web content and site functionality, please write to the net-snmp-users mail list.