Blame agent/snmp_vars.c

Packit Service b38f0b
/*
Packit Service b38f0b
 * snmp_vars.c - return a pointer to the named variable.
Packit Service b38f0b
 */
Packit Service b38f0b
/**
Packit Service b38f0b
 * @addtogroup library
Packit Service b38f0b
 *
Packit Service b38f0b
 * @{
Packit Service b38f0b
 */
Packit Service b38f0b
/* Portions of this file are subject to the following copyright(s).  See
Packit Service b38f0b
 * the Net-SNMP's COPYING file for more details and other copyrights
Packit Service b38f0b
 * that may apply:
Packit Service b38f0b
 */
Packit Service b38f0b
/* Portions of this file are subject to the following copyright(s).  See
Packit Service b38f0b
 * the Net-SNMP's COPYING file for more details and other copyrights
Packit Service b38f0b
 * that may apply:
Packit Service b38f0b
 */
Packit Service b38f0b
/***********************************************************
Packit Service b38f0b
	Copyright 1988, 1989, 1990 by Carnegie Mellon University
Packit Service b38f0b
	Copyright 1989	TGV, Incorporated
Packit Service b38f0b
Packit Service b38f0b
		      All Rights Reserved
Packit Service b38f0b
Packit Service b38f0b
Permission to use, copy, modify, and distribute this software and its
Packit Service b38f0b
documentation for any purpose and without fee is hereby granted,
Packit Service b38f0b
provided that the above copyright notice appear in all copies and that
Packit Service b38f0b
both that copyright notice and this permission notice appear in
Packit Service b38f0b
supporting documentation, and that the name of CMU and TGV not be used
Packit Service b38f0b
in advertising or publicity pertaining to distribution of the software
Packit Service b38f0b
without specific, written prior permission.
Packit Service b38f0b
Packit Service b38f0b
CMU AND TGV DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
Packit Service b38f0b
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
Packit Service b38f0b
EVENT SHALL CMU OR TGV BE LIABLE FOR ANY SPECIAL, INDIRECT OR
Packit Service b38f0b
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
Packit Service b38f0b
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
Packit Service b38f0b
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
Packit Service b38f0b
PERFORMANCE OF THIS SOFTWARE.
Packit Service b38f0b
******************************************************************/
Packit Service b38f0b
/*
Packit Service b38f0b
 * Portions of this file are copyrighted by:
Packit Service b38f0b
 * Copyright © 2003 Sun Microsystems, Inc. All rights reserved.
Packit Service b38f0b
 * Use is subject to license terms specified in the COPYING file
Packit Service b38f0b
 * distributed with the Net-SNMP package.
Packit Service b38f0b
 *
Packit Service b38f0b
 * Portions of this file are copyrighted by:
Packit Service b38f0b
 * Copyright (c) 2016 VMware, Inc. All rights reserved.
Packit Service b38f0b
 * Use is subject to license terms specified in the COPYING file
Packit Service b38f0b
 * distributed with the Net-SNMP package.
Packit Service b38f0b
 */
Packit Service b38f0b
Packit Service b38f0b
/*
Packit Service b38f0b
 * additions, fixes and enhancements for Linux by Erik Schoenfelder
Packit Service b38f0b
 * (schoenfr@ibr.cs.tu-bs.de) 1994/1995.
Packit Service b38f0b
 * Linux additions taken from CMU to UCD stack by Jennifer Bray of Origin
Packit Service b38f0b
 * (jbray@origin-at.co.uk) 1997
Packit Service b38f0b
 */
Packit Service b38f0b
Packit Service b38f0b
/*
Packit Service b38f0b
 * XXXWWW merge todo: incl/excl range changes in differences between
Packit Service b38f0b
 * 1.194 and 1.199 
Packit Service b38f0b
 */
Packit Service b38f0b
Packit Service b38f0b
#include <net-snmp/net-snmp-config.h>
Packit Service b38f0b
#if HAVE_SYS_PARAM_H
Packit Service b38f0b
#include <sys/param.h>
Packit Service b38f0b
#endif
Packit Service b38f0b
#if HAVE_STRING_H
Packit Service b38f0b
#include <string.h>
Packit Service b38f0b
#endif
Packit Service b38f0b
#if HAVE_STDLIB_H
Packit Service b38f0b
#include <stdlib.h>
Packit Service b38f0b
#endif
Packit Service b38f0b
#include <sys/types.h>
Packit Service b38f0b
#include <stdio.h>
Packit Service b38f0b
#include <fcntl.h>
Packit Service b38f0b
#include <errno.h>
Packit Service b38f0b
Packit Service b38f0b
#if TIME_WITH_SYS_TIME
Packit Service b38f0b
# include <sys/time.h>
Packit Service b38f0b
# include <time.h>
Packit Service b38f0b
#else
Packit Service b38f0b
# if HAVE_SYS_TIME_H
Packit Service b38f0b
#  include <sys/time.h>
Packit Service b38f0b
# else
Packit Service b38f0b
#  include <time.h>
Packit Service b38f0b
# endif
Packit Service b38f0b
#endif
Packit Service b38f0b
#if HAVE_SYS_SOCKET_H
Packit Service b38f0b
# include <sys/socket.h>
Packit Service b38f0b
#endif
Packit Service b38f0b
#if HAVE_SYS_STREAM_H
Packit Service b38f0b
#   ifdef sysv5UnixWare7
Packit Service b38f0b
#      define _KMEMUSER 1 /* <sys/stream.h> needs this for queue_t */
Packit Service b38f0b
#   endif
Packit Service b38f0b
#include <sys/stream.h>
Packit Service b38f0b
#endif
Packit Service b38f0b
#if HAVE_SYS_SOCKETVAR_H
Packit Service b38f0b
# include <sys/socketvar.h>
Packit Service b38f0b
#endif
Packit Service b38f0b
#if HAVE_NETINET_IN_H
Packit Service b38f0b
#include <netinet/in.h>
Packit Service b38f0b
#endif
Packit Service b38f0b
#if HAVE_NETINET_IN_SYSTM_H
Packit Service b38f0b
#include <netinet/in_systm.h>
Packit Service b38f0b
#endif
Packit Service b38f0b
#if HAVE_NETINET_IP_H
Packit Service b38f0b
#include <netinet/ip.h>
Packit Service b38f0b
#endif
Packit Service b38f0b
#ifdef NETSNMP_ENABLE_IPV6
Packit Service b38f0b
#if HAVE_NETINET_IP6_H
Packit Service b38f0b
#include <netinet/ip6.h>
Packit Service b38f0b
#endif
Packit Service b38f0b
#endif
Packit Service b38f0b
#if HAVE_SYS_QUEUE_H
Packit Service b38f0b
#include <sys/queue.h>
Packit Service b38f0b
#endif
Packit Service b38f0b
#if HAVE_NET_ROUTE_H
Packit Service b38f0b
#include <net/route.h>
Packit Service b38f0b
#endif
Packit Service b38f0b
#if HAVE_NETINET_IP_VAR_H
Packit Service b38f0b
#include <netinet/ip_var.h>
Packit Service b38f0b
#endif
Packit Service b38f0b
#ifdef NETSNMP_ENABLE_IPV6
Packit Service b38f0b
#if HAVE_NETNETSNMP_ENABLE_IPV6_IP6_VAR_H
Packit Service b38f0b
#include <netinet6/ip6_var.h>
Packit Service b38f0b
#endif
Packit Service b38f0b
#endif
Packit Service b38f0b
#if HAVE_NETINET_IN_PCB_H
Packit Service b38f0b
#include <netinet/in_pcb.h>
Packit Service b38f0b
#endif
Packit Service b38f0b
#if HAVE_INET_MIB2_H
Packit Service b38f0b
#include <inet/mib2.h>
Packit Service b38f0b
#endif
Packit Service b38f0b
Packit Service b38f0b
#include <net-snmp/net-snmp-includes.h>
Packit Service b38f0b
#include <net-snmp/agent/net-snmp-agent-includes.h>
Packit Service b38f0b
#include <net-snmp/agent/mib_modules.h>
Packit Service b38f0b
#include <net-snmp/agent/agent_sysORTable.h>
Packit Service b38f0b
#include "agent_global_vars.h"
Packit Service b38f0b
#include "kernel.h"
Packit Service b38f0b
Packit Service b38f0b
#include "mibgroup/struct.h"
Packit Service b38f0b
#include "snmpd.h"
Packit Service b38f0b
#include "agentx/agentx_config.h"
Packit Service b38f0b
#include "agentx/subagent.h"
Packit Service b38f0b
#include "net-snmp/agent/all_helpers.h"
Packit Service b38f0b
#include "agent_module_includes.h"
Packit Service b38f0b
#include "net-snmp/library/container.h"
Packit Service b38f0b
Packit Service b38f0b
#if defined(NETSNMP_USE_OPENSSL) && defined(HAVE_LIBSSL)
Packit Service b38f0b
#include <openssl/ssl.h>
Packit Service b38f0b
#include <openssl/x509v3.h>
Packit Service b38f0b
#include <net-snmp/library/cert_util.h>
Packit Service b38f0b
#endif
Packit Service b38f0b
Packit Service b38f0b
#include "snmp_perl.h"
Packit Service b38f0b
Packit Service b38f0b
#ifndef  MIN
Packit Service b38f0b
#define  MIN(a,b)                     (((a) < (b)) ? (a) : (b))
Packit Service b38f0b
#endif
Packit Service b38f0b
Packit Service b38f0b
static char     done_init_agent = 0;
Packit Service b38f0b
Packit Service b38f0b
struct module_init_list *initlist = NULL;
Packit Service b38f0b
struct module_init_list *noinitlist = NULL;
Packit Service b38f0b
Packit Service b38f0b
/*
Packit Service b38f0b
 * mib clients are passed a pointer to a oid buffer.  Some mib clients
Packit Service b38f0b
 * * (namely, those first noticed in mibII/vacm.c) modify this oid buffer
Packit Service b38f0b
 * * before they determine if they really need to send results back out
Packit Service b38f0b
 * * using it.  If the master agent determined that the client was not the
Packit Service b38f0b
 * * right one to talk with, it will use the same oid buffer to pass to the
Packit Service b38f0b
 * * rest of the clients, which may not longer be valid.  This should be
Packit Service b38f0b
 * * fixed in all clients rather than the master.  However, its not a
Packit Service b38f0b
 * * particularily easy bug to track down so this saves debugging time at
Packit Service b38f0b
 * * the expense of a few memcpy's.
Packit Service b38f0b
 */
Packit Service b38f0b
#define MIB_CLIENTS_ARE_EVIL 1
Packit Service b38f0b
Packit Service b38f0b
/*
Packit Service b38f0b
 *      Each variable name is placed in the variable table, without the
Packit Service b38f0b
 * terminating substring that determines the instance of the variable.  When
Packit Service b38f0b
 * a string is found that is lexicographicly preceded by the input string,
Packit Service b38f0b
 * the function for that entry is called to find the method of access of the
Packit Service b38f0b
 * instance of the named variable.  If that variable is not found, NULL is
Packit Service b38f0b
 * returned, and the search through the table continues (it will probably
Packit Service b38f0b
 * stop at the next entry).  If it is found, the function returns a character
Packit Service b38f0b
 * pointer and a length or a function pointer.  The former is the address
Packit Service b38f0b
 * of the operand, the latter is a write routine for the variable.
Packit Service b38f0b
 *
Packit Service b38f0b
 * u_char *
Packit Service b38f0b
 * findVar(name, length, exact, var_len, write_method)
Packit Service b38f0b
 * oid      *name;          IN/OUT - input name requested, output name found
Packit Service b38f0b
 * int      length;         IN/OUT - number of sub-ids in the in and out oid's
Packit Service b38f0b
 * int      exact;          IN - TRUE if an exact match was requested.
Packit Service b38f0b
 * int      len;            OUT - length of variable or 0 if function returned.
Packit Service b38f0b
 * int      write_method;   OUT - pointer to function to set variable,
Packit Service b38f0b
 *                                otherwise 0
Packit Service b38f0b
 *
Packit Service b38f0b
 *     The writeVar function is returned to handle row addition or complex
Packit Service b38f0b
 * writes that require boundary checking or executing an action.
Packit Service b38f0b
 * This routine will be called three times for each varbind in the packet.
Packit Service b38f0b
 * The first time for each varbind, action is set to RESERVE1.  The type
Packit Service b38f0b
 * and value should be checked during this pass.  If any other variables
Packit Service b38f0b
 * in the MIB depend on this variable, this variable will be stored away
Packit Service b38f0b
 * (but *not* committed!) in a place where it can be found by a call to
Packit Service b38f0b
 * writeVar for a dependent variable, even in the same PDU.  During
Packit Service b38f0b
 * the second pass, action is set to RESERVE2.  If this variable is dependent
Packit Service b38f0b
 * on any other variables, it will check them now.  It must check to see
Packit Service b38f0b
 * if any non-committed values have been stored for variables in the same
Packit Service b38f0b
 * PDU that it depends on.  Sometimes resources will need to be reserved
Packit Service b38f0b
 * in the first two passes to guarantee that the operation can proceed
Packit Service b38f0b
 * during the third pass.  During the third pass, if there were no errors
Packit Service b38f0b
 * in the first two passes, writeVar is called for every varbind with action
Packit Service b38f0b
 * set to COMMIT.  It is now that the values should be written.  If there
Packit Service b38f0b
 * were errors during the first two passes, writeVar is called in the third
Packit Service b38f0b
 * pass once for each varbind, with the action set to FREE.  An opportunity
Packit Service b38f0b
 * is thus provided to free those resources reserved in the first two passes.
Packit Service b38f0b
 * 
Packit Service b38f0b
 * writeVar(action, var_val, var_val_type, var_val_len, statP, name, name_len)
Packit Service b38f0b
 * int      action;         IN - RESERVE1, RESERVE2, COMMIT, or FREE
Packit Service b38f0b
 * u_char   *var_val;       IN - input or output buffer space
Packit Service b38f0b
 * u_char   var_val_type;   IN - type of input buffer
Packit Service b38f0b
 * int      var_val_len;    IN - input and output buffer len
Packit Service b38f0b
 * u_char   *statP;         IN - pointer to local statistic
Packit Service b38f0b
 * oid      *name           IN - pointer to name requested
Packit Service b38f0b
 * int      name_len        IN - number of sub-ids in the name
Packit Service b38f0b
 */
Packit Service b38f0b
Packit Service b38f0b
long            long_return;
Packit Service b38f0b
#ifndef ibm032
Packit Service b38f0b
u_char          return_buf[258];
Packit Service b38f0b
#else
Packit Service b38f0b
u_char          return_buf[256];        /* nee 64 */
Packit Service b38f0b
#endif
Packit Service b38f0b
Packit Service b38f0b
static int
Packit Service b38f0b
_warn_if_all_disabled(int maj, int min, void *serverarg, void *clientarg);
Packit Service b38f0b
Packit Service b38f0b
int             callback_master_num = -1;
Packit Service b38f0b
Packit Service b38f0b
#ifdef NETSNMP_TRANSPORT_CALLBACK_DOMAIN
Packit Service b38f0b
netsnmp_session *callback_master_sess = NULL;
Packit Service b38f0b
Packit Service b38f0b
static void
Packit Service b38f0b
_init_agent_callback_transport(void)
Packit Service b38f0b
{
Packit Service b38f0b
    /*
Packit Service b38f0b
     * always register a callback transport for internal use 
Packit Service b38f0b
     */
Packit Service b38f0b
    callback_master_sess = netsnmp_callback_open(0, handle_snmp_packet,
Packit Service b38f0b
                                                 netsnmp_agent_check_packet,
Packit Service b38f0b
                                                 netsnmp_agent_check_parse);
Packit Service b38f0b
    if (callback_master_sess)
Packit Service b38f0b
        callback_master_num = callback_master_sess->local_port;
Packit Service b38f0b
}
Packit Service b38f0b
#else
Packit Service b38f0b
#define _init_agent_callback_transport()
Packit Service b38f0b
#endif
Packit Service b38f0b
Packit Service b38f0b
/**
Packit Service b38f0b
 * Initialize the agent.  Calls into init_agent_read_config to set tha app's
Packit Service b38f0b
 * configuration file in the appropriate default storage space,
Packit Service b38f0b
 *  NETSNMP_DS_LIB_APPTYPE.  Need to call init_agent before calling init_snmp.
Packit Service b38f0b
 *
Packit Service b38f0b
 * @param app the configuration file to be read in, gets stored in default
Packit Service b38f0b
 *        storage
Packit Service b38f0b
 *
Packit Service b38f0b
 * @return Returns non-zero on failure and zero on success.
Packit Service b38f0b
 *
Packit Service b38f0b
 * @see init_snmp
Packit Service b38f0b
 */
Packit Service b38f0b
int
Packit Service b38f0b
init_agent(const char *app)
Packit Service b38f0b
{
Packit Service b38f0b
    int             r = 0;
Packit Service b38f0b
Packit Service b38f0b
    if(++done_init_agent > 1) {
Packit Service b38f0b
        snmp_log(LOG_WARNING, "ignoring extra call to init_agent (%d)\n", 
Packit Service b38f0b
                 done_init_agent);
Packit Service b38f0b
        return r;
Packit Service b38f0b
    }
Packit Service b38f0b
Packit Service b38f0b
    /*
Packit Service b38f0b
     * get current time (ie, the time the agent started) 
Packit Service b38f0b
     */
Packit Service b38f0b
    netsnmp_set_agent_starttime(NULL);
Packit Service b38f0b
Packit Service b38f0b
    /*
Packit Service b38f0b
     * we handle alarm signals ourselves in the select loop 
Packit Service b38f0b
     */
Packit Service b38f0b
    netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, 
Packit Service b38f0b
			   NETSNMP_DS_LIB_ALARM_DONT_USE_SIG, 1);
Packit Service b38f0b
Packit Service b38f0b
#ifdef HAVE_KMEM
Packit Service b38f0b
    r = init_kmem("/dev/kmem") ? 0 : -EACCES;
Packit Service b38f0b
#endif
Packit Service b38f0b
Packit Service b38f0b
    setup_tree();
Packit Service b38f0b
Packit Service b38f0b
    init_agent_read_config(app);
Packit Service b38f0b
Packit Service b38f0b
#ifdef TESTING
Packit Service b38f0b
    auto_nlist_print_tree(-2, 0);
Packit Service b38f0b
#endif
Packit Service b38f0b
Packit Service b38f0b
    _init_agent_callback_transport();
Packit Service b38f0b
Packit Service b38f0b
#ifndef NETSNMP_FEATURE_REMOVE_RUNTIME_DISABLE_VERSION
Packit Service b38f0b
    snmp_register_callback(SNMP_CALLBACK_LIBRARY,
Packit Service b38f0b
                           SNMP_CALLBACK_POST_READ_CONFIG,
Packit Service b38f0b
                           _warn_if_all_disabled, NULL);
Packit Service b38f0b
#endif /* NETSNMP_FEATURE_REMOVE_RUNTIME_DISABLE_VERSION */
Packit Service b38f0b
Packit Service b38f0b
    netsnmp_init_helpers();
Packit Service b38f0b
    init_traps();
Packit Service b38f0b
    netsnmp_container_init_list();
Packit Service b38f0b
    init_agent_sysORTable();
Packit Service b38f0b
Packit Service b38f0b
#if defined(USING_AGENTX_SUBAGENT_MODULE) || defined(USING_AGENTX_MASTER_MODULE)
Packit Service b38f0b
    /*
Packit Service b38f0b
     * initialize agentx configs
Packit Service b38f0b
     */
Packit Service b38f0b
    agentx_config_init();
Packit Service b38f0b
#if defined(USING_AGENTX_SUBAGENT_MODULE)
Packit Service b38f0b
    if(netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
Packit Service b38f0b
                              NETSNMP_DS_AGENT_ROLE) == SUB_AGENT)
Packit Service b38f0b
        subagent_init();
Packit Service b38f0b
#endif
Packit Service b38f0b
#endif
Packit Service b38f0b
Packit Service b38f0b
    /*
Packit Service b38f0b
     * Register configuration tokens from transport modules.  
Packit Service b38f0b
     */
Packit Service b38f0b
#ifdef NETSNMP_TRANSPORT_UDP_DOMAIN
Packit Service b38f0b
    netsnmp_udp_agent_config_tokens_register();
Packit Service b38f0b
#endif
Packit Service b38f0b
#ifdef NETSNMP_TRANSPORT_UDPIPV6_DOMAIN
Packit Service b38f0b
    netsnmp_udp6_agent_config_tokens_register();
Packit Service b38f0b
#endif
Packit Service b38f0b
#ifdef NETSNMP_TRANSPORT_UNIX_DOMAIN
Packit Service b38f0b
    netsnmp_unix_agent_config_tokens_register();
Packit Service b38f0b
#endif
Packit Service b38f0b
Packit Service b38f0b
#ifdef NETSNMP_EMBEDDED_PERL
Packit Service b38f0b
    init_perl();
Packit Service b38f0b
#endif
Packit Service b38f0b
Packit Service b38f0b
#if defined(NETSNMP_USE_OPENSSL) && defined(HAVE_LIBSSL) && NETSNMP_TRANSPORT_TLSBASE_DOMAIN
Packit Service b38f0b
    /** init secname mapping */
Packit Service b38f0b
    netsnmp_certs_agent_init();
Packit Service b38f0b
#endif
Packit Service b38f0b
Packit Service b38f0b
#ifdef USING_AGENTX_SUBAGENT_MODULE
Packit Service b38f0b
    /*
Packit Service b38f0b
     * don't init agent modules for a sub-agent
Packit Service b38f0b
     */
Packit Service b38f0b
    if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, 
Packit Service b38f0b
			       NETSNMP_DS_AGENT_ROLE) == SUB_AGENT)
Packit Service b38f0b
        return r;
Packit Service b38f0b
#endif
Packit Service b38f0b
Packit Service b38f0b
#  include "agent_module_inits.h"
Packit Service b38f0b
Packit Service b38f0b
    return r;
Packit Service b38f0b
}                               /* end init_agent() */
Packit Service b38f0b
Packit Service b38f0b
oid             nullOid[] = { 0, 0 };
Packit Service b38f0b
int             nullOidLen = sizeof(nullOid);
Packit Service b38f0b
Packit Service b38f0b
void
Packit Service b38f0b
shutdown_agent(void) {
Packit Service b38f0b
Packit Service b38f0b
    /* probably some of this can be called as shutdown callback */
Packit Service b38f0b
    shutdown_tree();
Packit Service b38f0b
    clear_context();
Packit Service b38f0b
    netsnmp_clear_callback_list();
Packit Service b38f0b
    netsnmp_clear_tdomain_list();
Packit Service b38f0b
    netsnmp_clear_handler_list();
Packit Service b38f0b
    shutdown_agent_sysORTable();
Packit Service b38f0b
    netsnmp_container_free_list();
Packit Service b38f0b
    clear_sec_mod();
Packit Service b38f0b
    clear_snmp_enum();
Packit Service b38f0b
    clear_callback();
Packit Service b38f0b
    shutdown_secmod();
Packit Service b38f0b
    netsnmp_addrcache_destroy();
Packit Service b38f0b
#ifdef HAVE_KMEM
Packit Service b38f0b
    free_kmem();
Packit Service b38f0b
#endif
Packit Service b38f0b
Packit Service b38f0b
    done_init_agent = 0;
Packit Service b38f0b
}
Packit Service b38f0b
Packit Service b38f0b
Packit Service b38f0b
void
Packit Service b38f0b
add_to_init_list(char *module_list)
Packit Service b38f0b
{
Packit Service b38f0b
    struct module_init_list *newitem, **list;
Packit Service b38f0b
    char           *cp;
Packit Service b38f0b
    char           *st;
Packit Service b38f0b
Packit Service b38f0b
    if (module_list == NULL) {
Packit Service b38f0b
        return;
Packit Service b38f0b
    } else {
Packit Service b38f0b
        cp = (char *) module_list;
Packit Service b38f0b
    }
Packit Service b38f0b
Packit Service b38f0b
    if (*cp == '-' || *cp == '!') {
Packit Service b38f0b
        cp++;
Packit Service b38f0b
        list = &noinitlist;
Packit Service b38f0b
    } else {
Packit Service b38f0b
        list = &initlist;
Packit Service b38f0b
    }
Packit Service b38f0b
Packit Service b38f0b
    cp = strtok_r(cp, ", :", &st);
Packit Service b38f0b
    while (cp) {
Packit Service b38f0b
        newitem = (struct module_init_list *) calloc(1, sizeof(*initlist));
Packit Service b38f0b
        newitem->module_name = strdup(cp);
Packit Service b38f0b
        newitem->next = *list;
Packit Service b38f0b
        *list = newitem;
Packit Service b38f0b
        cp = strtok_r(NULL, ", :", &st);
Packit Service b38f0b
    }
Packit Service b38f0b
}
Packit Service b38f0b
Packit Service b38f0b
int
Packit Service b38f0b
should_init(const char *module_name)
Packit Service b38f0b
{
Packit Service b38f0b
    struct module_init_list *listp;
Packit Service b38f0b
Packit Service b38f0b
    /*
Packit Service b38f0b
     * a definitive list takes priority 
Packit Service b38f0b
     */
Packit Service b38f0b
    if (initlist) {
Packit Service b38f0b
        listp = initlist;
Packit Service b38f0b
        while (listp) {
Packit Service b38f0b
            if (strcmp(listp->module_name, module_name) == 0) {
Packit Service b38f0b
                DEBUGMSGTL(("mib_init", "initializing: %s\n",
Packit Service b38f0b
                            module_name));
Packit Service b38f0b
                return DO_INITIALIZE;
Packit Service b38f0b
            }
Packit Service b38f0b
            listp = listp->next;
Packit Service b38f0b
        }
Packit Service b38f0b
        DEBUGMSGTL(("mib_init", "skipping:     %s\n", module_name));
Packit Service b38f0b
        return DONT_INITIALIZE;
Packit Service b38f0b
    }
Packit Service b38f0b
Packit Service b38f0b
    /*
Packit Service b38f0b
     * initialize it only if not on the bad list (bad module, no bone) 
Packit Service b38f0b
     */
Packit Service b38f0b
    if (noinitlist) {
Packit Service b38f0b
        listp = noinitlist;
Packit Service b38f0b
        while (listp) {
Packit Service b38f0b
            if (strcmp(listp->module_name, module_name) == 0) {
Packit Service b38f0b
                DEBUGMSGTL(("mib_init", "skipping:     %s\n",
Packit Service b38f0b
                            module_name));
Packit Service b38f0b
                return DONT_INITIALIZE;
Packit Service b38f0b
            }
Packit Service b38f0b
            listp = listp->next;
Packit Service b38f0b
        }
Packit Service b38f0b
    }
Packit Service b38f0b
    DEBUGMSGTL(("mib_init", "initializing: %s\n", module_name));
Packit Service b38f0b
Packit Service b38f0b
    /*
Packit Service b38f0b
     * initialize it 
Packit Service b38f0b
     */
Packit Service b38f0b
    return DO_INITIALIZE;
Packit Service b38f0b
}
Packit Service b38f0b
Packit Service b38f0b
static int
Packit Service b38f0b
_warn_if_all_disabled(int maj, int min, void *serverarg, void *clientarg)
Packit Service b38f0b
{
Packit Service b38f0b
    const char * name = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID,
Packit Service b38f0b
                                              NETSNMP_DS_LIB_APPTYPE);
Packit Service b38f0b
    const int agent_mode =  netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
Packit Service b38f0b
                                                   NETSNMP_DS_AGENT_ROLE);
Packit Service b38f0b
    int enabled = 0;
Packit Service b38f0b
    if (NULL==name)
Packit Service b38f0b
        name = "snmpd";
Packit Service b38f0b
Packit Service b38f0b
    if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID,
Packit Service b38f0b
                                NETSNMP_DS_LIB_DISABLE_V3))
Packit Service b38f0b
        ++enabled;
Packit Service b38f0b
#ifndef NETSNMP_DISABLE_SNMPV2C
Packit Service b38f0b
    if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID,
Packit Service b38f0b
                                NETSNMP_DS_LIB_DISABLE_V2c))
Packit Service b38f0b
        ++enabled;
Packit Service b38f0b
#endif /* NETSNMP_DISABLE_SNMPV2C */
Packit Service b38f0b
#ifndef NETSNMP_DISABLE_SNMPV1
Packit Service b38f0b
    if (!netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID,
Packit Service b38f0b
                                NETSNMP_DS_LIB_DISABLE_V1))
Packit Service b38f0b
        ++enabled;
Packit Service b38f0b
#endif /* NETSNMP_DISABLE_SNMPV1 */
Packit Service b38f0b
Packit Service b38f0b
    if (0 == enabled) {
Packit Service b38f0b
        if ((MASTER_AGENT == agent_mode) && (strcmp(name, "snmptrapd") != 0)) {
Packit Service b38f0b
            snmp_log(LOG_WARNING,
Packit Service b38f0b
                     "Warning: all protocol versions are runtime disabled.\n"
Packit Service b38f0b
                 "  It's unlikely this agent can serve any useful purpose in this state.\n"
Packit Service b38f0b
                     "  Check %s.conf file(s) for this agent.\n", name);
Packit Service b38f0b
        } else if (!strcmp(name, "snmptrapd") &&
Packit Service b38f0b
            !netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
Packit Service b38f0b
                                    NETSNMP_DS_APP_NO_AUTHORIZATION)) {
Packit Service b38f0b
            snmp_log(LOG_WARNING,
Packit Service b38f0b
                     "Warning: all protocol versions are runtime disabled.\n"
Packit Service b38f0b
                     "This receiver will *NOT* accept any incoming notifications.\n");
Packit Service b38f0b
        }
Packit Service b38f0b
    }
Packit Service b38f0b
    return SNMP_ERR_NOERROR;
Packit Service b38f0b
}
Packit Service b38f0b
Packit Service b38f0b
/**  @} */
Packit Service b38f0b