Ejemplo n.º 1
0
int
se_add_pair_to_list(struct snmp_enum_list **list, char *label, int value)
{
    struct snmp_enum_list *lastnode = NULL, *tmp;

    if (!list)
        return SE_DNE;

    tmp = *list;
    while (tmp) {
        if (tmp->value == value) {
            free(label);
            return (SE_ALREADY_THERE);
        }
        lastnode = tmp;
        tmp = tmp->next;
    }

    if (lastnode) {
        lastnode->next = SNMP_MALLOC_STRUCT(snmp_enum_list);
        lastnode = lastnode->next;
    } else {
        (*list) = SNMP_MALLOC_STRUCT(snmp_enum_list);
        lastnode = (*list);
    }
    if (!lastnode) {
        free(label);
        return (SE_NOMEM);
    }
    lastnode->label = label;
    lastnode->value = value;
    lastnode->next = NULL;
    return (SE_OK);
}
Ejemplo n.º 2
0
struct expExpressionTable_data *
create_expExpressionTable_data(void)
{
    struct expExpressionTable_data *StorageNew;
    StorageNew = SNMP_MALLOC_STRUCT(expExpressionTable_data);
    /*
     * fill in default row values here into StorageNew 
     */
    /*
     * fill in values for all tables (even if not
     * appropriate), since its easier to do here than anywhere
     * else 
     */

    StorageNew->expExpression = strdup("");
    StorageNew->expExpressionValueType = EXPEXPRESSION_COUNTER32;
    StorageNew->expExpressionComment = strdup("");
    StorageNew->expExpressionDeltaInterval = 0;
    StorageNew->expExpressionPrefix = calloc(1, sizeof(oid) * 2);       /* 0.0 */
    StorageNew->expExpressionPrefixLen = 2;
    StorageNew->hc_ObjectTableStorage = NULL;
    StorageNew->hc_ValueTableStorage = NULL;
    StorageNew->storageType = ST_NONVOLATILE;
    return StorageNew;
}
/** Initialize the LOCALSM security module */
void
init_localsm(void)
{
    struct snmp_secmod_def *def;
    int ret;

    def = SNMP_MALLOC_STRUCT(snmp_secmod_def);

    if (!def) {
        snmp_log(LOG_ERR,
                 "Unable to malloc snmp_secmod struct, not registering LOCALSM\n");
        return;
    }

    def->encode_reverse = localsm_rgenerate_out_msg;
    def->decode = localsm_process_in_msg;
    def->session_open = localsm_session_init;
    def->pdu_free_state_ref = localsm_free_state_ref;
    def->pdu_free = localsm_free_pdu;
    def->pdu_clone = localsm_clone_pdu;

    DEBUGMSGTL(("localsm","registering ourselves\n"));
    ret = register_sec_mod(NETSNMP_LOCALSM_SECURITY_MODEL, "localsm", def);
    DEBUGMSGTL(("localsm"," returned %d\n", ret));
}
Ejemplo n.º 4
0
/** Initialize the TSM security module */
void
init_tsm(void)
{
    struct snmp_secmod_def *def;
    int ret;

    def = SNMP_MALLOC_STRUCT(snmp_secmod_def);

    if (!def) {
        snmp_log(LOG_ERR,
                 "Unable to malloc snmp_secmod struct, not registering TSM\n");
        return;
    }

    def->encode_reverse = tsm_rgenerate_out_msg;
    def->decode = tsm_process_in_msg;
    def->session_open = tsm_session_init;
    def->pdu_free_state_ref = tsm_free_state_ref;
    def->pdu_clone = tsm_clone_pdu;
    def->pdu_free = tsm_free_pdu;
    def->probe_engineid = snmpv3_probe_contextEngineID_rfc5343;

    DEBUGMSGTL(("tsm","registering ourselves\n"));
    ret = register_sec_mod(NETSNMP_TSM_SECURITY_MODEL, "tsm", def);
    DEBUGMSGTL(("tsm"," returned %d\n", ret));

    netsnmp_ds_register_config(ASN_BOOLEAN, "snmp", "tsmUseTransportPrefix",
			       NETSNMP_DS_LIBRARY_ID,
                               NETSNMP_DS_LIB_TSM_USE_PREFIX);
}
Ejemplo n.º 5
0
/*
 * parse_snmpNotifyTable():
 *   parses .conf file entries needed to configure the mib.
 */
void
parse_snmpNotifyTable(const char *token, char *line)
{
    size_t          tmpint;
    struct snmpNotifyTable_data *StorageTmp =
        SNMP_MALLOC_STRUCT(snmpNotifyTable_data);


    DEBUGMSGTL(("snmpNotifyTable", "parsing config...  "));


    if (StorageTmp == NULL) {
        config_perror("malloc failure");
        return;
    }

    line =
        read_config_read_data(ASN_OCTET_STR, line,
                              &StorageTmp->snmpNotifyName,
                              &StorageTmp->snmpNotifyNameLen);
    if (StorageTmp->snmpNotifyName == NULL) {
        config_perror("invalid specification for snmpNotifyName");
        return;
    }

    line =
        read_config_read_data(ASN_OCTET_STR, line,
                              &StorageTmp->snmpNotifyTag,
                              &StorageTmp->snmpNotifyTagLen);
    if (StorageTmp->snmpNotifyTag == NULL) {
        config_perror("invalid specification for snmpNotifyTag");
        return;
    }

    line =
        read_config_read_data(ASN_INTEGER, line,
                              &StorageTmp->snmpNotifyType, &tmpint);

    line =
        read_config_read_data(ASN_INTEGER, line,
                              &StorageTmp->snmpNotifyStorageType, &tmpint);
    if (!StorageTmp->snmpNotifyStorageType)
        StorageTmp->snmpNotifyStorageType = ST_READONLY;

    line =
        read_config_read_data(ASN_INTEGER, line,
                              &StorageTmp->snmpNotifyRowStatus, &tmpint);
    if (!StorageTmp->snmpNotifyRowStatus)
        StorageTmp->snmpNotifyRowStatus = RS_ACTIVE;


    if (snmpNotifyTable_add(StorageTmp) != SNMPERR_SUCCESS){
        SNMP_FREE(StorageTmp->snmpNotifyName);
        SNMP_FREE(StorageTmp->snmpNotifyTag);
        SNMP_FREE(StorageTmp);
    }


    DEBUGMSGTL(("snmpNotifyTable", "done.\n"));
}
Ejemplo n.º 6
0
static int
ksm_insert_cache(long msgid, krb5_auth_context auth_context,
                 u_char * secName, size_t secNameLen)
{
    struct ksm_cache_entry *entry;
    int             bucket;
    int             retval;

    entry = SNMP_MALLOC_STRUCT(ksm_cache_entry);

    if (!entry)
        return SNMPERR_MALLOC;

    entry->msgid = msgid;
    entry->auth_context = auth_context;
    entry->refcount = 1;

    retval = memdup(&entry->secName, secName, secNameLen);

    if (retval != SNMPERR_SUCCESS) {
        free(entry);
        return retval;
    }

    entry->secNameLen = secNameLen;

    bucket = msgid % HASHSIZE;

    entry->next = ksm_hash_table[bucket];
    ksm_hash_table[bucket] = entry;

    return SNMPERR_SUCCESS;
}
Ejemplo n.º 7
0
unsigned int
snmp_alarm_register(unsigned int when, unsigned int flags,
                    SNMPAlarmCallback *thecallback, void *clientarg) {
  struct snmp_alarm **sa_pptr;
  if (thealarms != NULL) {
    for(sa_pptr = &thealarms; (*sa_pptr) != NULL;
        sa_pptr = &((*sa_pptr)->next));
  } else {
    sa_pptr = &thealarms;
  }

  *sa_pptr = SNMP_MALLOC_STRUCT(snmp_alarm);
  if (*sa_pptr == NULL)
    return 0;

  (*sa_pptr)->seconds = when;
  (*sa_pptr)->flags = flags;
  (*sa_pptr)->clientarg = clientarg;
  (*sa_pptr)->thecallback = thecallback;
  (*sa_pptr)->clientreg = regnum++;
  sa_update_entry(*sa_pptr);

  DEBUGMSGTL(("snmp_alarm_register","registered alarm %d, secends=%d, flags=%d\n",
              (*sa_pptr)->clientreg, (*sa_pptr)->seconds, (*sa_pptr)->flags));

  if (start_alarms)
    set_an_alarm();
  return (*sa_pptr)->clientreg;
} 
Ejemplo n.º 8
0
/*
 * parse_snmpNotifyFilterTable():
 *   parses .conf file entries needed to configure the mib.
 */
void
parse_snmpNotifyFilterTable(const char *token, char *line)
{
    size_t          tmpint;
    struct snmpNotifyFilterTable_data *StorageTmp =
        SNMP_MALLOC_STRUCT(snmpNotifyFilterTable_data);


    DEBUGMSGTL(("snmpNotifyFilterTable", "parsing config...  "));


    if (StorageTmp == NULL) {
        config_perror("malloc failure");
        return;
    }


    line =
        read_config_read_data(ASN_OCTET_STR, line,
                              &StorageTmp->snmpNotifyFilterProfileName,
                              &StorageTmp->snmpNotifyFilterProfileNameLen);
    if (StorageTmp->snmpNotifyFilterProfileName == NULL) {
        config_perror
            ("invalid specification for snmpNotifyFilterProfileName");
        return;
    }

    line =
        read_config_read_data(ASN_OBJECT_ID, line,
                              &StorageTmp->snmpNotifyFilterSubtree,
                              &StorageTmp->snmpNotifyFilterSubtreeLen);
    if (StorageTmp->snmpNotifyFilterSubtree == NULL) {
        config_perror("invalid specification for snmpNotifyFilterSubtree");
        return;
    }

    line =
        read_config_read_data(ASN_OCTET_STR, line,
                              &StorageTmp->snmpNotifyFilterMask,
                              &StorageTmp->snmpNotifyFilterMaskLen);

    line =
        read_config_read_data(ASN_INTEGER, line,
                              &StorageTmp->snmpNotifyFilterType, &tmpint);

    line =
        read_config_read_data(ASN_INTEGER, line,
                              &StorageTmp->snmpNotifyFilterStorageType,
                              &tmpint);

    line =
        read_config_read_data(ASN_INTEGER, line,
                              &StorageTmp->snmpNotifyFilterRowStatus,
                              &tmpint);

    snmpNotifyFilterTable_add(StorageTmp);

    DEBUGMSGTL(("snmpNotifyFilterTable", "done.\n"));
}
void
parse_lookupResultsTable(const char *token, char *line)
{
    size_t          tmpint;
    struct lookupResultsTable_data *StorageTmp =
        SNMP_MALLOC_STRUCT(lookupResultsTable_data);

    DEBUGMSGTL(("lookupResultsTable", "parsing config...  "));


    if (StorageTmp == NULL) {
        config_perror("malloc failure");
        return;
    }

    line =
        read_config_read_data(ASN_OCTET_STR, line,
                              &StorageTmp->lookupCtlOwnerIndex,
                              &StorageTmp->lookupCtlOwnerIndexLen);
    if (StorageTmp->lookupCtlOwnerIndex == NULL) {
        config_perror("invalid specification for lookupCtlOwnerIndex");
        return;
    }

    line =
        read_config_read_data(ASN_OCTET_STR, line,
                              &StorageTmp->lookupCtlOperationName,
                              &StorageTmp->lookupCtlOperationNameLen);
    if (StorageTmp->lookupCtlOperationName == NULL) {
        config_perror("invalid specification for lookupCtlOperationName");
        return;
    }

    line =
        read_config_read_data(ASN_UNSIGNED, line,
                              &StorageTmp->lookupResultsIndex, &tmpint);
    line =
        read_config_read_data(ASN_INTEGER, line,
                              &StorageTmp->lookupResultsAddressType,
                              &tmpint);
    line =
        read_config_read_data(ASN_OCTET_STR, line,
                              &StorageTmp->lookupResultsAddress,
                              &StorageTmp->lookupResultsAddressLen);
    if (StorageTmp->lookupResultsAddress == NULL) {
        config_perror("invalid specification for lookupResultsAddress");
        return;
    }


    lookupResultsTable_inadd(StorageTmp);

    /* lookupResultsTable_cleaner(lookupResultsTableStorage); */

    DEBUGMSGTL(("lookupResultsTable", "done.\n"));
}
Ejemplo n.º 10
0
int
ds_register_premib(u_char type, const char *ftype, const char *token,
                   int storeid, int which) {
  struct ds_read_config *drsp;

  if (storeid >= DS_MAX_IDS || which >= DS_MAX_SUBIDS ||
      storeid < 0 || which < 0 || token == NULL)
    return SNMPERR_GENERR;

  if (ds_configs == NULL) {
    ds_configs = SNMP_MALLOC_STRUCT(ds_read_config);
    drsp = ds_configs;
  } else {
    for(drsp = ds_configs; drsp->next != NULL; drsp = drsp->next);
    drsp->next = SNMP_MALLOC_STRUCT(ds_read_config);
    drsp = drsp->next;
  }

  drsp->type = type;
  drsp->token = strdup(token);
  drsp->storeid = storeid;
  drsp->which = which;

  switch (type) {
    case ASN_BOOLEAN:
      register_premib_handler(ftype, token, ds_handle_config, NULL,"(1|yes|true|0|no|false)");
      break;

    case ASN_INTEGER:
      register_premib_handler(ftype, token, ds_handle_config, NULL,"integerValue");
      break;

    case ASN_OCTET_STR:
      register_premib_handler(ftype, token, ds_handle_config, NULL,"string");
      break;
    
  }
  return SNMPERR_SUCCESS;
}
/*
 * parse_snmpNotifyFilterProfileTable():
 *   parses .conf file entries needed to configure the mib.
 */
void
parse_snmpNotifyFilterProfileTable(const char *token, char *line)
{
    size_t          tmpint;
    struct snmpNotifyFilterProfileTable_data *StorageTmp =
        SNMP_MALLOC_STRUCT(snmpNotifyFilterProfileTable_data);

    DEBUGMSGTL(("snmpNotifyFilterProfileTable", "parsing config...  "));

    if (StorageTmp == NULL) {
        config_perror("malloc failure");
        return;
    }

    line =
        read_config_read_data(ASN_OCTET_STR, line,
                              &StorageTmp->snmpTargetParamsName,
                              &StorageTmp->snmpTargetParamsNameLen);
    if (StorageTmp->snmpTargetParamsName == NULL) {
        config_perror("invalid specification for snmpTargetParamsName");
        return;
    }

    line =
        read_config_read_data(ASN_OCTET_STR, line,
                              &StorageTmp->snmpNotifyFilterProfileName,
                              &StorageTmp->snmpNotifyFilterProfileNameLen);
    if (StorageTmp->snmpNotifyFilterProfileName == NULL) {
        config_perror("invalid specification for snmpNotifyFilterProfileName");
        return;
    }

    line =
        read_config_read_data(ASN_INTEGER, line,
                              &StorageTmp->snmpNotifyFilterProfileStorType,
                              &tmpint);

    line =
        read_config_read_data(ASN_INTEGER, line,
                              &StorageTmp->
                              snmpNotifyFilterProfileRowStatus, &tmpint);

    if (snmpNotifyFilterProfileTable_add(StorageTmp) != SNMPERR_SUCCESS){
        SNMP_FREE(StorageTmp->snmpTargetParamsName);
        SNMP_FREE(StorageTmp->snmpNotifyFilterProfileName);
        SNMP_FREE(StorageTmp);
    }

    DEBUGMSGTL(("snmpNotifyFilterProfileTable", "done.\n"));
}
Ejemplo n.º 12
0
struct header_complex_index *
_header_complex_add_between(struct header_complex_index **thedata,
                            struct header_complex_index *hciptrp,
                            struct header_complex_index *hciptrn,
                            oid * newoid, size_t newoid_len, void *data)
{
    struct header_complex_index *ourself;

    /*
     * nptr should now point to the spot that we need to add ourselves
     * in front of, and pptr should be our new 'prev'. 
     */

    /*
     * create ourselves 
     */
    ourself = (struct header_complex_index *)
        SNMP_MALLOC_STRUCT(header_complex_index);
    if (ourself == NULL)
        return NULL;

    /*
     * change our pointers 
     */
    ourself->prev = hciptrp;
    ourself->next = hciptrn;

    if (ourself->next)
        ourself->next->prev = ourself;

    if (ourself->prev)
        ourself->prev->next = ourself;

    ourself->data = data;
    ourself->name = snmp_duplicate_objid(newoid, newoid_len);
    ourself->namelen = newoid_len;

    /*
     * rewind to the head of the list and return it (since the new head
     * could be us, we need to notify the above routine who the head now is. 
     */
    for (hciptrp = ourself; hciptrp->prev != NULL;
         hciptrp = hciptrp->prev);

    *thedata = hciptrp;
    DEBUGMSGTL(("header_complex_add_data", "adding something...\n"));

    return hciptrp;
}
Ejemplo n.º 13
0
int
register_sec_mod(int secmod, const char *modname,
                 struct snmp_secmod_def *newdef)
{
    int             result = 0;
    struct snmp_secmod_list *sptr;
    char           *othername, *modname2 = NULL;

    for (sptr = registered_services; sptr; sptr = sptr->next) {
        if (sptr->securityModel == secmod) {
            return SNMPERR_GENERR;
        }
    }
    sptr = SNMP_MALLOC_STRUCT(snmp_secmod_list);
    if (sptr == NULL)
        return SNMPERR_MALLOC;
    sptr->secDef = newdef;
    sptr->securityModel = secmod;
    sptr->next = registered_services;
    registered_services = sptr;
    modname2 = strdup(modname);
    if (!modname2)
        result = SE_NOMEM;
    else
        result = se_add_pair_to_slist("snmp_secmods", modname2, secmod);
    if (result != SE_OK) {
        switch (result) {
        case SE_NOMEM:
            snmp_log(LOG_CRIT, "snmp_secmod: no memory\n");
            break;

        case SE_ALREADY_THERE:
            othername = se_find_label_in_slist("snmp_secmods", secmod);
            if (strcmp(othername, modname) != 0) {
                snmp_log(LOG_ERR,
                         "snmp_secmod: two security modules %s and %s registered with the same security number\n",
                         modname, othername);
            }
            break;

        default:
            snmp_log(LOG_ERR,
                     "snmp_secmod: unknown error trying to register a new security module\n");
            break;
        }
        return SNMPERR_GENERR;
    }
    return SNMPERR_SUCCESS;
}
Ejemplo n.º 14
0
int
snmp_register_callback(int major, int minor, SNMPCallback *new_callback,
                       void *arg) {

  struct snmp_gen_callback *scp;
  
  if (major >= MAX_CALLBACK_IDS || minor >= MAX_CALLBACK_SUBIDS) {
    return SNMPERR_GENERR;
  }
  
  if (thecallbacks[major][minor] != NULL) {
    /* get to the end of the list */
    for(scp = thecallbacks[major][minor]; scp->next != NULL; scp = scp->next);

    /* mallocate a new entry */
    scp->next = SNMP_MALLOC_STRUCT(snmp_gen_callback);
    scp = scp->next;
  } else {
    /* mallocate a new entry */
    scp = SNMP_MALLOC_STRUCT(snmp_gen_callback);

    /* make the new node the head */
    thecallbacks[major][minor] = scp;
  }

  if (scp == NULL)
    return SNMPERR_GENERR;

  scp->sc_client_arg = arg;
  scp->sc_callback = new_callback;

  DEBUGMSGTL(("callback","registered callback for maj=%d min=%d\n",
              major, minor));

  return SNMPERR_SUCCESS;
}
Ejemplo n.º 15
0
static void
netsnmp_register_user_target(const char* token, char* cptr)
{
    struct netsnmp_lookup_target *run = targets, *prev = NULL;
    size_t len = strlen(cptr) + 1;
    char* application = (char*)malloc(len);
    char* domain = (char*)malloc(len);
    char* target = (char*)malloc(len);
    int i = 0;

    {
	char* cp = copy_nword(cptr, application, len);
	cp = copy_nword(cp, domain, len);
	cp = copy_nword(cp, target, len);
	if (cp)
	    config_pwarn("Trailing junk found");
    }

    while (run && ((i = strcmp(run->application, application)) < 0 ||
		   (i == 0 && strcmp(run->domain, domain) < 0))) {
	prev = run;
	run = run->next;
    }
    if (run && i == 0 && strcmp(run->domain, domain) == 0) {
	if (run->userTarget != NULL) {
	    config_perror("Default target already registered for this "
			  "application-domain combination");
	    goto done;
	}
    } else {
	run = SNMP_MALLOC_STRUCT(netsnmp_lookup_target);
	run->application = strdup(application);
	run->domain = strdup(domain);
	run->target = NULL;
	if (prev) {
	    run->next = prev->next;
	    prev->next = run;
	} else {
	    run->next = targets;
	    targets = run;
	}
    }
    run->userTarget = strdup(target);
 done:
    free(target);
    free(domain);
    free(application);
}
Ejemplo n.º 16
0
/**
 * @fn struct ss7OmMIB_data *ss7OmMIB_duplicate(struct ss7OmMIB_data *thedata)
 * @param thedata the mib structure to duplicate
 * @brief duplicate a mib structure for the mib
 *
 * Duplicates the specified mib structure @param thedata and returns a pointer to the newly
 * allocated mib structure on success, or NULL on failure.
 */
struct ss7OmMIB_data *
ss7OmMIB_duplicate(struct ss7OmMIB_data *thedata)
{
	struct ss7OmMIB_data *StorageNew = SNMP_MALLOC_STRUCT(ss7OmMIB_data);

	DEBUGMSGTL(("ss7OmMIB", "ss7OmMIB_duplicate: duplicating mib... "));
	if (StorageNew != NULL) {
	}
      done:
	DEBUGMSGTL(("ss7OmMIB", "done.\n"));
	return (StorageNew);
	goto destroy;
      destroy:
	ss7OmMIB_destroy(&StorageNew);
	goto done;
}
Ejemplo n.º 17
0
void
init_ksm(void)
{
    krb5_error_code retval;
    struct snmp_secmod_def *def;
    int             i;

    netsnmp_ds_register_config(ASN_OCTET_STR, "snmp", "defKSMKeytab",
                               NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_KSM_KEYTAB);
    netsnmp_ds_register_config(ASN_OCTET_STR, "snmp", "defKSMServiceName",
                               NETSNMP_DS_LIBRARY_ID,
			       NETSNMP_DS_LIB_KSM_SERVICE_NAME);
    snmp_register_callback(SNMP_CALLBACK_LIBRARY,
			   SNMP_CALLBACK_POST_READ_CONFIG,
			   init_snmpksm_post_config, NULL);


    if (kcontext == NULL) {
        retval = krb5_init_context(&kcontext);

        if (retval) {
            DEBUGMSGTL(("ksm", "krb5_init_context failed (%s), not "
                        "registering KSM\n", error_message(retval)));
            return;
        }
    }

    for (i = 0; i < HASHSIZE; i++)
        ksm_hash_table[i] = NULL;

    def = SNMP_MALLOC_STRUCT(snmp_secmod_def);

    if (!def) {
        DEBUGMSGTL(("ksm", "Unable to malloc snmp_secmod struct, not "
                    "registering KSM\n"));
        return;
    }

    def->encode_reverse = ksm_rgenerate_out_msg;
    def->decode = ksm_process_in_msg;
    def->session_open = ksm_session_init;
    def->pdu_free_state_ref = ksm_free_state_ref;
    def->pdu_free = ksm_free_pdu;
    def->pdu_clone = ksm_clone_pdu;

    register_sec_mod(2066432, "ksm", def);
}
Ejemplo n.º 18
0
/**
 * @fn struct ss7OmMIB_data *ss7OmMIB_create(void)
 * @brief create a fresh data structure representing scalars in ss7OmMIB.
 *
 * Creates a new ss7OmMIB_data structure by allocating dynamic memory for the structure and
 * initializing the default values of scalars in ss7OmMIB.
 */
struct ss7OmMIB_data *
ss7OmMIB_create(void)
{
	struct ss7OmMIB_data *StorageNew = SNMP_MALLOC_STRUCT(ss7OmMIB_data);

	DEBUGMSGTL(("ss7OmMIB", "ss7OmMIB_create: creating scalars...  "));
	if (StorageNew != NULL) {
		/* XXX: fill in default scalar values here into StorageNew */

	}
      done:
	DEBUGMSGTL(("ss7OmMIB", "done.\n"));
	return (StorageNew);
	goto nomem;
      nomem:
	ss7OmMIB_destroy(&StorageNew);
	goto done;
}
Ejemplo n.º 19
0
struct expObjectTable_data *
create_expObjectTable_data(void)
{
    struct expObjectTable_data *StorageNew;

    StorageNew = SNMP_MALLOC_STRUCT(expObjectTable_data);

    /*
     * fill in default row values here into StorageNew
     */
    /*
     * fill in values for all tables (even if not
     * appropriate), since its easier to do here than anywhere
     * else
     */

    StorageNew->expObjectIDWildcard = EXPOBJCETIDWILDCARD_FALSE;
    StorageNew->expObjectSampleType = EXPOBJCETSAMPLETYPE_ABSOLUTEVALUE;
    StorageNew->expObjectDeltaDiscontinuityID =
        netsnmp_memdup(TimeInstance, sizeof(TimeInstance));
    StorageNew->expObjectDeltaDiscontinuityIDLen =
        sizeof(TimeInstance) / sizeof(oid);




    StorageNew->expObjectDiscontinuityIDWildcard =
        EXPOBJCETDISCONTINUITYIDWILDCARD_FALSE;
    StorageNew->expObjectDiscontinuityIDType =
        EXPOBJECTDISCONTINUITYIDTYPE_TIMETICKS;

    StorageNew->expObjectConditional = calloc(1, sizeof(oid) * 2);      /* 0.0 */
    StorageNew->expObjectConditionalLen = 2;

    StorageNew->expObjectID = calloc(1, sizeof(oid) * 2);       /* 0.0 */
    StorageNew->expObjectIDLen = 2;

    StorageNew->expObjectConditionalWildcard =
        EXPOBJECTCONDITIONALWILDCARD_FALSE;
    StorageNew->storageType = ST_NONVOLATILE;

    return StorageNew;
}
Ejemplo n.º 20
0
int
netsnmp_register_default_target(const char* application, const char* domain,
				const char* target)
{
    struct netsnmp_lookup_target *run = targets, *prev = NULL;
    int i = 0, res = 0;
    while (run && ((i = strcmp(run->application, application)) < 0 ||
		   (i == 0 && strcmp(run->domain, domain) < 0))) {
	prev = run;
	run = run->next;
    }
    if (run && i == 0 && strcmp(run->domain, domain) == 0) {
      if (run->target != NULL) {
	    free(run->target);
	    run->target = NULL;
	    res = 1;
      }
    } else {
	run = SNMP_MALLOC_STRUCT(netsnmp_lookup_target);
	run->application = strdup(application);
	run->domain = strdup(domain);
	run->userTarget = NULL;
	if (prev) {
	    run->next = prev->next;
	    prev->next = run;
	} else {
	    run->next = targets;
	    targets = run;
	}
    }
    if (target) {
	run->target = strdup(target);
    } else if (run->userTarget == NULL) {
	if (prev)
	    prev->next = run->next;
	else
	    targets = run->next;
	free(run->domain);
	free(run->application);
	free(run);
    }
    return res;
}
Ejemplo n.º 21
0
int
netsnmp_register_callback(int major, int minor, SNMPCallback * new_callback,
                          void *arg, int priority)
{
    struct snmp_gen_callback *newscp = NULL, *scp = NULL;
    struct snmp_gen_callback **prevNext = &(thecallbacks[major][minor]);

    if (major >= MAX_CALLBACK_IDS || minor >= MAX_CALLBACK_SUBIDS) {
        return SNMPERR_GENERR;
    }

    if (_callback_need_init)
        init_callbacks();

    _callback_lock(major,minor, "netsnmp_register_callback", 1);
    
    if ((newscp = SNMP_MALLOC_STRUCT(snmp_gen_callback)) == NULL) {
        _callback_unlock(major,minor);
        return SNMPERR_GENERR;
    } else {
        newscp->priority = priority;
        newscp->sc_client_arg = arg;
        newscp->sc_callback = new_callback;
        newscp->next = NULL;

        for (scp = thecallbacks[major][minor]; scp != NULL;
             scp = scp->next) {
            if (newscp->priority < scp->priority) {
                newscp->next = scp;
                break;
            }
            prevNext = &(scp->next);
        }

        *prevNext = newscp;

        DEBUGMSGTL(("callback", "registered (%d,%d) at %p with priority %d\n",
                    major, minor, newscp, priority));
        _callback_unlock(major,minor);
        return SNMPERR_SUCCESS;
    }
}
Ejemplo n.º 22
0
int
se_add_pair_to_slist(const char *listname, char *label, int value)
{
    struct snmp_enum_list *list = se_find_slist(listname);
    int             created = (list) ? 1 : 0;
    int             ret = se_add_pair_to_list(&list, label, value);

    if (!created) {
        struct snmp_enum_list_str *sptr =
            SNMP_MALLOC_STRUCT(snmp_enum_list_str);
        if (!sptr) {
            free_enum_list(list);
            return SE_NOMEM;
        }
        sptr->next = sliststorage;
        sptr->name = strdup(listname);
        sptr->list = list;
        sliststorage = sptr;
    }
    return ret;
}
Ejemplo n.º 23
0
struct expValueTable_data *
create_expValueTable_data(void)
{
    struct expValueTable_data *StorageNew;

    StorageNew = SNMP_MALLOC_STRUCT(expValueTable_data);

    /*
     * fill in default row values here into StorageNew 
     */
    /*
     * fill in values for all tables (even if not
     * appropriate), since its easier to do here than anywhere
     * else 
     */
    StorageNew->expExpressionOwner = strdup("");
    StorageNew->expExpressionName = strdup("");
    StorageNew->expValueInstance = calloc(1, sizeof(oid) * sizeof(2));  /* 0.0.0 */
    StorageNew->expValueInstanceLen = 3;
    return StorageNew;
}
Ejemplo n.º 24
0
int
netsnmp_register_default_domain(const char* application, const char* domain)
{
    struct netsnmp_lookup_domain *run = domains, *prev = NULL;
    int res = 0;

    while (run != NULL && strcmp(run->application, application) < 0) {
	prev = run;
	run = run->next;
    }
    if (run && strcmp(run->application, application) == 0) {
      if (run->domain != NULL) {
          destroy_word_array(run->domain);
	  run->domain = NULL;
	  res = 1;
      }
    } else {
	run = SNMP_MALLOC_STRUCT(netsnmp_lookup_domain);
	run->application = strdup(application);
	run->userDomain = NULL;
	if (prev) {
	    run->next = prev->next;
	    prev->next = run;
	} else {
	    run->next = domains;
	    domains = run;
	}
    }
    if (domain) {
        run->domain = create_word_array(domain);
    } else if (run->userDomain == NULL) {
	if (prev)
	    prev->next = run->next;
	else
	    domains = run->next;
	free(run->application);
	free(run);
    }
    return res;
}
Ejemplo n.º 25
0
static void
netsnmp_register_user_domain(const char* token, char* cptr)
{
    struct netsnmp_lookup_domain *run = domains, *prev = NULL;
    size_t len = strlen(cptr) + 1;
    char* application = (char*)malloc(len);
    char** domain;

    {
        char* cp = copy_nword(cptr, application, len);
        domain = create_word_array(cp);
    }

    while (run != NULL && strcmp(run->application, application) < 0) {
	prev = run;
	run = run->next;
    }
    if (run && strcmp(run->application, application) == 0) {
	if (run->userDomain != NULL) {
	    config_perror("Default transport already registered for this "
			  "application");
            destroy_word_array(domain);
            free(application);
	    return;
	}
    } else {
	run = SNMP_MALLOC_STRUCT(netsnmp_lookup_domain);
	run->application = strdup(application);
	run->domain = NULL;
	if (prev) {
	    run->next = prev->next;
	    prev->next = run;
	} else {
	    run->next = domains;
	    domains = run;
	}
    }
    run->userDomain = domain;
    free(application);
}
Ejemplo n.º 26
0
int
write_snmpNotifyRowStatus(int action,
                          u_char * var_val,
                          u_char var_val_type,
                          size_t var_val_len,
                          u_char * statP, oid * name, size_t name_len)
{
    struct snmpNotifyTable_data *StorageTmp = NULL;
    static struct snmpNotifyTable_data *StorageDel;
    size_t          newlen =
        name_len - (sizeof(snmpNotifyTable_variables_oid) / sizeof(oid) +
                    3 - 1);
    static int      old_value;
    int             set_value = *((long *) var_val);
    static netsnmp_variable_list *vars, *vp;
    struct header_complex_index *hciptr;


    DEBUGMSGTL(("snmpNotifyTable",
                "write_snmpNotifyRowStatus entering action=%d...  \n",
                action));
    StorageTmp = (struct snmpNotifyTable_data *)
        header_complex((struct header_complex_index *)
                       snmpNotifyTableStorage, NULL,
                       &name[sizeof(snmpNotifyTable_variables_oid) /
                             sizeof(oid) + 3 - 1], &newlen, 1, NULL, NULL);

    switch (action) {
    case RESERVE1:
        if (var_val_type != ASN_INTEGER || var_val == NULL) {
            return SNMP_ERR_WRONGTYPE;
        }
        if (var_val_len != sizeof(long)) {
            return SNMP_ERR_WRONGLENGTH;
        }
        if (set_value < 1 || set_value > 6 || set_value == RS_NOTREADY) {
            return SNMP_ERR_WRONGVALUE;
        }
        if (StorageTmp == NULL) {
            /*
             * create the row now? 
             */
            /*
             * ditch illegal values now 
             */
            if (set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE) {
                return SNMP_ERR_INCONSISTENTVALUE;
            }
        } else {
            /*
             * row exists.  Check for a valid state change 
             */
            if (set_value == RS_CREATEANDGO
                || set_value == RS_CREATEANDWAIT) {
                /*
                 * can't create a row that exists 
                 */
                return SNMP_ERR_INCONSISTENTVALUE;
            }
            /*
             * XXX: interaction with row storage type needed 
             */
        }

        /*
         * memory reseveration, final preparation... 
         */
        if (StorageTmp == NULL &&
            (set_value == RS_CREATEANDGO
             || set_value == RS_CREATEANDWAIT)) {
            /*
             * creation 
             */
            vars = NULL;

            snmp_varlist_add_variable(&vars, NULL, 0, ASN_PRIV_IMPLIED_OCTET_STR, NULL, 0);     /* snmpNotifyName */

            if (header_complex_parse_oid
                (&
                 (name
                  [sizeof(snmpNotifyTable_variables_oid) / sizeof(oid) +
                   2]), newlen, vars) != SNMPERR_SUCCESS) {
                /*
                 * XXX: free, zero vars 
                 */
                snmp_free_var(vars);
                return SNMP_ERR_INCONSISTENTNAME;
            }
            vp = vars;


            StorageNew = SNMP_MALLOC_STRUCT(snmpNotifyTable_data);
            if (StorageNew == NULL) {
                return SNMP_ERR_RESOURCEUNAVAILABLE;
            }
            memdup((u_char **) & (StorageNew->snmpNotifyName),
                   vp->val.string, vp->val_len);
            if (StorageNew->snmpNotifyName == NULL) {
                return SNMP_ERR_RESOURCEUNAVAILABLE;
            }
            StorageNew->snmpNotifyNameLen = vp->val_len;
            vp = vp->next_variable;

            /*
             * default values 
             */
            StorageNew->snmpNotifyStorageType = ST_NONVOLATILE;
            StorageNew->snmpNotifyType = SNMPNOTIFYTYPE_TRAP;
            StorageNew->snmpNotifyTagLen = 0;
            StorageNew->snmpNotifyTag = (char *) calloc(sizeof(char), 1);
            if (StorageNew->snmpNotifyTag == NULL) {
                return SNMP_ERR_RESOURCEUNAVAILABLE;
            }

            StorageNew->snmpNotifyRowStatus = set_value;
            snmp_free_var(vars);
        }
        break;

    case RESERVE2:
        break;

    case FREE:
        if (StorageNew != NULL) {
            SNMP_FREE(StorageNew->snmpNotifyTag);
            SNMP_FREE(StorageNew->snmpNotifyName);
            free(StorageNew);
            StorageNew = NULL;
        }
        break;

    case ACTION:
        if (StorageTmp == NULL && (set_value == RS_CREATEANDGO ||
                                   set_value == RS_CREATEANDWAIT)) {
            /*
             * row creation, so add it 
             */
            if (StorageNew != NULL) {
                snmpNotifyTable_add(StorageNew);
            }
        } else if (set_value != RS_DESTROY) {
            /*
             * set the flag? 
             */
            old_value = StorageTmp->snmpNotifyRowStatus;
            StorageTmp->snmpNotifyRowStatus = *((long *) var_val);
        } else {
            /*
             * destroy...  extract it for now 
             */
            if (StorageTmp) {
                hciptr = header_complex_find_entry(snmpNotifyTableStorage,
                                                   StorageTmp);
                StorageDel = (struct snmpNotifyTable_data *)
                    header_complex_extract_entry((struct
                                                  header_complex_index **)
                                                 &snmpNotifyTableStorage,
                                                 hciptr);
            }
        }
        break;

    case UNDO:
        /*
         * Back out any changes made in the ACTION case 
         */
        if (StorageTmp == NULL && (set_value == RS_CREATEANDGO ||
                                   set_value == RS_CREATEANDWAIT)) {
            /*
             * row creation, so remove it again 
             */
            hciptr = header_complex_find_entry(snmpNotifyTableStorage,
                                               StorageNew);
            StorageDel = (struct snmpNotifyTable_data *)
                header_complex_extract_entry((struct header_complex_index
                                              **) &snmpNotifyTableStorage,
                                             hciptr);
            /*
             * XXX: free it 
             */
        } else if (StorageDel != NULL) {
            /*
             * row deletion, so add it again 
             */
            snmpNotifyTable_add(StorageDel);
        } else if (set_value != RS_DESTROY) {
            StorageTmp->snmpNotifyRowStatus = old_value;
        }
        break;

    case COMMIT:
        if (StorageDel != NULL) {
            SNMP_FREE(StorageDel->snmpNotifyTag);
            SNMP_FREE(StorageDel->snmpNotifyName);
            free(StorageDel);
            StorageDel = NULL;
        }
        if (StorageTmp
            && StorageTmp->snmpNotifyRowStatus == RS_CREATEANDGO) {
            StorageTmp->snmpNotifyRowStatus = RS_ACTIVE;
            StorageNew = NULL;
        } else if (StorageTmp &&
                   StorageTmp->snmpNotifyRowStatus == RS_CREATEANDWAIT) {
            StorageTmp->snmpNotifyRowStatus = RS_NOTINSERVICE;
            StorageNew = NULL;
        }
        break;
    }
    return SNMP_ERR_NOERROR;
}
Ejemplo n.º 27
0
int
notifyTable_register_notifications(int major, int minor,
                                   void *serverarg, void *clientarg)
{
    struct targetAddrTable_struct *ptr;
    struct targetParamTable_struct *pptr;
    struct snmpNotifyTable_data *nptr;
    int             confirm, i;
    char            buf[SNMP_MAXBUF_SMALL];
    netsnmp_transport *t = NULL;
    struct agent_add_trap_args *args =
        (struct agent_add_trap_args *) serverarg;
    netsnmp_session *ss;

    if (!args || !(args->ss)) {
        return (0);
    }
    confirm = args->confirm;
    ss = args->ss;

    /*
     * XXX: START move target creation to target code 
     */
    for (i = 0; i < MAX_ENTRIES; i++) {
        sprintf(buf, "internal%d", i);
        if (get_addrForName(buf) == NULL && get_paramEntry(buf) == NULL)
            break;
    }
    if (i == MAX_ENTRIES) {
        snmp_log(LOG_ERR,
                 "Can't register new trap destination: max limit reached: %d",
                 MAX_ENTRIES);
        snmp_sess_close(ss);
        return (0);
    }

    /*
     * address 
     */
    ptr = snmpTargetAddrTable_create();
    ptr->name = strdup(buf);
    t = snmp_sess_transport(snmp_sess_pointer(ss));
    memcpy(ptr->tDomain, t->domain, t->domain_length * sizeof(oid));
    ptr->tDomainLen = t->domain_length;
    ptr->tAddressLen = t->remote_length;
    ptr->tAddress = t->remote;

    ptr->timeout = ss->timeout / 1000;
    ptr->retryCount = ss->retries;
    SNMP_FREE(ptr->tagList);
    ptr->tagList = strdup(ptr->name);
    ptr->params = strdup(ptr->name);
    ptr->storageType = ST_READONLY;
    ptr->rowStatus = RS_ACTIVE;
    ptr->sess = ss;
    DEBUGMSGTL(("trapsess", "adding to trap table\n"));
    snmpTargetAddrTable_add(ptr);

    /*
     * param 
     */
    pptr = snmpTargetParamTable_create();
    pptr->paramName = strdup(buf);
    pptr->mpModel = ss->version;
    if (ss->version == SNMP_VERSION_3) {
        pptr->secModel = ss->securityModel;
        pptr->secLevel = ss->securityLevel;
        pptr->secName = (char *) malloc(ss->securityNameLen + 1);
        memcpy((void *) pptr->secName, (void *) ss->securityName,
               ss->securityNameLen);
        pptr->secName[ss->securityNameLen] = 0;
    } else {
        pptr->secModel = ss->version == SNMP_VERSION_1 ?
            SNMP_SEC_MODEL_SNMPv1 : SNMP_SEC_MODEL_SNMPv2c;
        pptr->secLevel = SNMP_SEC_LEVEL_NOAUTH;
        pptr->secName = NULL;
        if (ss->community && (ss->community_len > 0)) {
            pptr->secName = (char *) malloc(ss->community_len + 1);
            memcpy((void *) pptr->secName, (void *) ss->community,
                   ss->community_len);
            pptr->secName[ss->community_len] = 0;
        }
    }
    pptr->storageType = ST_READONLY;
    pptr->rowStatus = RS_ACTIVE;
    snmpTargetParamTable_add(pptr);
    /*
     * XXX: END move target creation to target code 
     */

    /*
     * notify table 
     */
    nptr = SNMP_MALLOC_STRUCT(snmpNotifyTable_data);
    nptr->snmpNotifyName = strdup(buf);
    nptr->snmpNotifyNameLen = strlen(buf);
    nptr->snmpNotifyTag = strdup(buf);
    nptr->snmpNotifyTagLen = strlen(buf);
    nptr->snmpNotifyType = confirm ?
        SNMPNOTIFYTYPE_INFORM : SNMPNOTIFYTYPE_TRAP;
    nptr->snmpNotifyStorageType = ST_READONLY;
    nptr->snmpNotifyRowStatus = RS_ACTIVE;

    snmpNotifyTable_add(nptr);
    return 0;
}
Ejemplo n.º 28
0
/** handles requests for the ipCidrRouteTable table, if anything else
   needs to be done */
int
ipCidrRouteTable_handler(netsnmp_mib_handler *handler,
                         netsnmp_handler_registration *reginfo,
                         netsnmp_agent_request_info *reqinfo,
                         netsnmp_request_info *requests)
{

    netsnmp_request_info *request;
    netsnmp_table_request_info *table_info;
    netsnmp_variable_list *var;

    void           *data_context;

    oid            *suffix;
    size_t          suffix_len;

    /** column and row index encoded portion */
    suffix = requests->requestvb->name + reginfo->rootoid_len + 1;
    suffix_len = requests->requestvb->name_length -
        (reginfo->rootoid_len + 1);

    for (request = requests; request; request = request->next) {
        var = request->requestvb;
        if (request->processed != 0)
            continue;

        data_context = netsnmp_extract_iterator_context(request);
        if (data_context == NULL) {
            if (reqinfo->mode == MODE_GET) {
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_NOSUCHINSTANCE);
                continue;
            }
            /** XXX: no row existed, if you support creation and this is a
               set, start dealing with it here, else continue */
        }

        /** extracts the information about the table from the request */
        table_info = netsnmp_extract_table_info(request);
        /** table_info->colnum contains the column number requested */
        /** table_info->indexes contains a linked list of snmp variable
           bindings for the indexes of the table.  Values in the list
           have been set corresponding to the indexes of the
           request */
        if (table_info == NULL) {
            continue;
        }

        switch (reqinfo->mode) {
        case MODE_GET:
            switch (table_info->colnum) {
            case COLUMN_IPCIDRROUTEDEST:
                {
                    u_long         *retval;
                    size_t          retval_len = 0;
                    retval =
                        get_ipCidrRouteDest(data_context, &retval_len);
                    snmp_set_var_typed_value(var, ASN_IPADDRESS,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            case COLUMN_IPCIDRROUTEMASK:
                {
                    u_long         *retval;
                    size_t          retval_len = 0;
                    retval =
                        get_ipCidrRouteMask(data_context, &retval_len);
                    snmp_set_var_typed_value(var, ASN_IPADDRESS,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            case COLUMN_IPCIDRROUTETOS:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    retval = get_ipCidrRouteTos(data_context, &retval_len);
                    snmp_set_var_typed_value(var, ASN_INTEGER,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            case COLUMN_IPCIDRROUTENEXTHOP:
                {
                    u_long         *retval;
                    size_t          retval_len = 0;
                    retval =
                        get_ipCidrRouteNextHop(data_context, &retval_len);
                    snmp_set_var_typed_value(var, ASN_IPADDRESS,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            case COLUMN_IPCIDRROUTEIFINDEX:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    retval =
                        get_ipCidrRouteIfIndex(data_context, &retval_len);
                    snmp_set_var_typed_value(var, ASN_INTEGER,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            case COLUMN_IPCIDRROUTETYPE:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    retval =
                        get_ipCidrRouteType(data_context, &retval_len);
                    snmp_set_var_typed_value(var, ASN_INTEGER,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            case COLUMN_IPCIDRROUTEPROTO:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    retval =
                        get_ipCidrRouteProto(data_context, &retval_len);
                    snmp_set_var_typed_value(var, ASN_INTEGER,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            case COLUMN_IPCIDRROUTEAGE:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    retval = get_ipCidrRouteAge(data_context, &retval_len);
                    snmp_set_var_typed_value(var, ASN_INTEGER,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            case COLUMN_IPCIDRROUTEINFO:
                {
                    oid            *retval;
                    size_t          retval_len = 0;
                    retval =
                        get_ipCidrRouteInfo(data_context, &retval_len);
                    snmp_set_var_typed_value(var, ASN_OBJECT_ID,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            case COLUMN_IPCIDRROUTENEXTHOPAS:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    retval =
                        get_ipCidrRouteNextHopAS(data_context,
                                                 &retval_len);
                    snmp_set_var_typed_value(var, ASN_INTEGER,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            case COLUMN_IPCIDRROUTEMETRIC1:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    retval =
                        get_ipCidrRouteMetric1(data_context, &retval_len);
                    snmp_set_var_typed_value(var, ASN_INTEGER,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            case COLUMN_IPCIDRROUTEMETRIC2:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    retval =
                        get_ipCidrRouteMetric2(data_context, &retval_len);
                    snmp_set_var_typed_value(var, ASN_INTEGER,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            case COLUMN_IPCIDRROUTEMETRIC3:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    retval =
                        get_ipCidrRouteMetric3(data_context, &retval_len);
                    snmp_set_var_typed_value(var, ASN_INTEGER,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            case COLUMN_IPCIDRROUTEMETRIC4:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    retval =
                        get_ipCidrRouteMetric4(data_context, &retval_len);
                    snmp_set_var_typed_value(var, ASN_INTEGER,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            case COLUMN_IPCIDRROUTEMETRIC5:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    retval =
                        get_ipCidrRouteMetric5(data_context, &retval_len);
                    snmp_set_var_typed_value(var, ASN_INTEGER,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            case COLUMN_IPCIDRROUTESTATUS:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    retval =
                        get_ipCidrRouteStatus(data_context, &retval_len);
                    snmp_set_var_typed_value(var, ASN_INTEGER,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            default:
                        /** We shouldn't get here */
                snmp_log(LOG_ERR,
                         "problem encountered in ipCidrRouteTable_handler: unknown column\n");
            }
            break;

        case MODE_SET_RESERVE1:
                /** mib2cXXX: clear out old undo info if we have any.  Remove if
                   table_iterator becomes un-serialized */
            netsnmp_oid_stash_free(&undoStorage, free_undoInfo);

            switch (table_info->colnum) {
            case COLUMN_IPCIDRROUTEIFINDEX:
                {
                    int             ret =
                        check_ipCidrRouteIfIndex(request->requestvb->type,
                                                 (long *) request->
                                                 requestvb->val.string,
                                                 request->requestvb->
                                                 val_len);
                    if (ret != 0) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTETYPE:
                {
                    int             ret =
                        check_ipCidrRouteType(request->requestvb->type,
                                              (long *) request->requestvb->
                                              val.string,
                                              request->requestvb->val_len);
                    if (ret != 0) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEINFO:
                {
                    int             ret =
                        check_ipCidrRouteInfo(request->requestvb->type,
                                              (oid *) request->requestvb->
                                              val.string,
                                              request->requestvb->val_len);
                    if (ret != 0) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTENEXTHOPAS:
                {
                    int             ret =
                        check_ipCidrRouteNextHopAS(request->requestvb->
                                                   type,
                                                   (long *) request->
                                                   requestvb->val.string,
                                                   request->requestvb->
                                                   val_len);
                    if (ret != 0) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC1:
                {
                    int             ret =
                        check_ipCidrRouteMetric1(request->requestvb->type,
                                                 (long *) request->
                                                 requestvb->val.string,
                                                 request->requestvb->
                                                 val_len);
                    if (ret != 0) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC2:
                {
                    int             ret =
                        check_ipCidrRouteMetric2(request->requestvb->type,
                                                 (long *) request->
                                                 requestvb->val.string,
                                                 request->requestvb->
                                                 val_len);
                    if (ret != 0) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC3:
                {
                    int             ret =
                        check_ipCidrRouteMetric3(request->requestvb->type,
                                                 (long *) request->
                                                 requestvb->val.string,
                                                 request->requestvb->
                                                 val_len);
                    if (ret != 0) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC4:
                {
                    int             ret =
                        check_ipCidrRouteMetric4(request->requestvb->type,
                                                 (long *) request->
                                                 requestvb->val.string,
                                                 request->requestvb->
                                                 val_len);
                    if (ret != 0) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC5:
                {
                    int             ret =
                        check_ipCidrRouteMetric5(request->requestvb->type,
                                                 (long *) request->
                                                 requestvb->val.string,
                                                 request->requestvb->
                                                 val_len);
                    if (ret != 0) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTESTATUS:
                {
                    int             ret =
                        check_ipCidrRouteStatus(request->requestvb->type,
                                                (long *) request->
                                                requestvb->val.string,
                                                request->requestvb->
                                                val_len);
                    if (ret != 0) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            default:
                netsnmp_set_request_error(reqinfo, requests,
                                          SNMP_ERR_NOTWRITABLE);
                break;
            }
            break;

        case MODE_SET_RESERVE2:
                /** save a variable copy */
            switch (table_info->colnum) {
            case COLUMN_IPCIDRROUTEIFINDEX:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    struct undoInfo *ui;
                    retval =
                        get_ipCidrRouteIfIndex(data_context, &retval_len);
                    if (retval) {
                        ui = SNMP_MALLOC_STRUCT(undoInfo);
                        ui->len = retval_len;
                        memdup((u_char **) & ui->ptr,
                               (u_char *) retval, ui->len);
                        netsnmp_oid_stash_add_data(&undoStorage,
                                                   suffix, suffix_len, ui);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTETYPE:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    struct undoInfo *ui;
                    retval =
                        get_ipCidrRouteType(data_context, &retval_len);
                    if (retval) {
                        ui = SNMP_MALLOC_STRUCT(undoInfo);
                        ui->len = retval_len;
                        memdup((u_char **) & ui->ptr,
                               (u_char *) retval, ui->len);
                        netsnmp_oid_stash_add_data(&undoStorage,
                                                   suffix, suffix_len, ui);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEINFO:
                {
                    oid            *retval;
                    size_t          retval_len = 0;
                    struct undoInfo *ui;
                    retval =
                        get_ipCidrRouteInfo(data_context, &retval_len);
                    if (retval) {
                        ui = SNMP_MALLOC_STRUCT(undoInfo);
                        ui->len = retval_len;
                        memdup((u_char **) & ui->ptr,
                               (u_char *) retval, ui->len);
                        netsnmp_oid_stash_add_data(&undoStorage,
                                                   suffix, suffix_len, ui);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTENEXTHOPAS:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    struct undoInfo *ui;
                    retval =
                        get_ipCidrRouteNextHopAS(data_context,
                                                 &retval_len);
                    if (retval) {
                        ui = SNMP_MALLOC_STRUCT(undoInfo);
                        ui->len = retval_len;
                        memdup((u_char **) & ui->ptr,
                               (u_char *) retval, ui->len);
                        netsnmp_oid_stash_add_data(&undoStorage,
                                                   suffix, suffix_len, ui);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC1:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    struct undoInfo *ui;
                    retval =
                        get_ipCidrRouteMetric1(data_context, &retval_len);
                    if (retval) {
                        ui = SNMP_MALLOC_STRUCT(undoInfo);
                        ui->len = retval_len;
                        memdup((u_char **) & ui->ptr,
                               (u_char *) retval, ui->len);
                        netsnmp_oid_stash_add_data(&undoStorage,
                                                   suffix, suffix_len, ui);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC2:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    struct undoInfo *ui;
                    retval =
                        get_ipCidrRouteMetric2(data_context, &retval_len);
                    if (retval) {
                        ui = SNMP_MALLOC_STRUCT(undoInfo);
                        ui->len = retval_len;
                        memdup((u_char **) & ui->ptr,
                               (u_char *) retval, ui->len);
                        netsnmp_oid_stash_add_data(&undoStorage,
                                                   suffix, suffix_len, ui);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC3:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    struct undoInfo *ui;
                    retval =
                        get_ipCidrRouteMetric3(data_context, &retval_len);
                    if (retval) {
                        ui = SNMP_MALLOC_STRUCT(undoInfo);
                        ui->len = retval_len;
                        memdup((u_char **) & ui->ptr,
                               (u_char *) retval, ui->len);
                        netsnmp_oid_stash_add_data(&undoStorage,
                                                   suffix, suffix_len, ui);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC4:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    struct undoInfo *ui;
                    retval =
                        get_ipCidrRouteMetric4(data_context, &retval_len);
                    if (retval) {
                        ui = SNMP_MALLOC_STRUCT(undoInfo);
                        ui->len = retval_len;
                        memdup((u_char **) & ui->ptr,
                               (u_char *) retval, ui->len);
                        netsnmp_oid_stash_add_data(&undoStorage,
                                                   suffix, suffix_len, ui);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC5:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    struct undoInfo *ui;
                    retval =
                        get_ipCidrRouteMetric5(data_context, &retval_len);
                    if (retval) {
                        ui = SNMP_MALLOC_STRUCT(undoInfo);
                        ui->len = retval_len;
                        memdup((u_char **) & ui->ptr,
                               (u_char *) retval, ui->len);
                        netsnmp_oid_stash_add_data(&undoStorage,
                                                   suffix, suffix_len, ui);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTESTATUS:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    struct undoInfo *ui;
                    retval =
                        get_ipCidrRouteStatus(data_context, &retval_len);
                    if (retval) {
                        ui = SNMP_MALLOC_STRUCT(undoInfo);
                        ui->len = retval_len;
                        memdup((u_char **) & ui->ptr,
                               (u_char *) retval, ui->len);
                        netsnmp_oid_stash_add_data(&undoStorage,
                                                   suffix, suffix_len, ui);
                    }
                }
                break;
            }
            break;

        case MODE_SET_FREE:
                /** Forget undo data, if exists */
            netsnmp_oid_stash_free(&undoStorage, free_undoInfo);
            break;

        case MODE_SET_ACTION:
                /** save a variable copy */
            switch (table_info->colnum) {
            case COLUMN_IPCIDRROUTEIFINDEX:
                {
                    int             ret =
                        set_ipCidrRouteIfIndex(data_context,
                                               (long *) request->
                                               requestvb->val.string,
                                               request->requestvb->
                                               val_len);
                    if (ret) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTETYPE:
                {
                    int             ret = set_ipCidrRouteType(data_context,
                                                              (long *)
                                                              request->
                                                              requestvb->
                                                              val.string,
                                                              request->
                                                              requestvb->
                                                              val_len);
                    if (ret) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEINFO:
                {
                    int             ret = set_ipCidrRouteInfo(data_context,
                                                              (oid *)
                                                              request->
                                                              requestvb->
                                                              val.string,
                                                              request->
                                                              requestvb->
                                                              val_len);
                    if (ret) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTENEXTHOPAS:
                {
                    int             ret =
                        set_ipCidrRouteNextHopAS(data_context,
                                                 (long *) request->
                                                 requestvb->val.string,
                                                 request->requestvb->
                                                 val_len);
                    if (ret) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC1:
                {
                    int             ret =
                        set_ipCidrRouteMetric1(data_context,
                                               (long *) request->
                                               requestvb->val.string,
                                               request->requestvb->
                                               val_len);
                    if (ret) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC2:
                {
                    int             ret =
                        set_ipCidrRouteMetric2(data_context,
                                               (long *) request->
                                               requestvb->val.string,
                                               request->requestvb->
                                               val_len);
                    if (ret) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC3:
                {
                    int             ret =
                        set_ipCidrRouteMetric3(data_context,
                                               (long *) request->
                                               requestvb->val.string,
                                               request->requestvb->
                                               val_len);
                    if (ret) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC4:
                {
                    int             ret =
                        set_ipCidrRouteMetric4(data_context,
                                               (long *) request->
                                               requestvb->val.string,
                                               request->requestvb->
                                               val_len);
                    if (ret) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC5:
                {
                    int             ret =
                        set_ipCidrRouteMetric5(data_context,
                                               (long *) request->
                                               requestvb->val.string,
                                               request->requestvb->
                                               val_len);
                    if (ret) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTESTATUS:
                {
                    int             ret =
                        set_ipCidrRouteStatus(data_context,
                                              (long *) request->requestvb->
                                              val.string,
                                              request->requestvb->val_len);
                    if (ret) {
                        netsnmp_set_request_error(reqinfo, requests, ret);
                    }
                }
                break;
            }
            break;

        case MODE_SET_COMMIT:
                /** answers were all good.  Forget undo data */
            netsnmp_oid_stash_free(&undoStorage, free_undoInfo);
                /** mib2cXXX: call commit hook */
            break;

        case MODE_SET_UNDO:
                /** save a variable copy */
            switch (table_info->colnum) {
            case COLUMN_IPCIDRROUTEIFINDEX:
                {
                    int             retval;
                    struct undoInfo *ui;
                    ui = netsnmp_oid_stash_get_data(undoStorage,
                                                    suffix, suffix_len);
                    retval =
                        set_ipCidrRouteIfIndex(data_context, ui->ptr,
                                               ui->len);
                    if (retval) {
                        netsnmp_set_request_error(reqinfo, requests,
                                                  SNMP_ERR_UNDOFAILED);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTETYPE:
                {
                    int             retval;
                    struct undoInfo *ui;
                    ui = netsnmp_oid_stash_get_data(undoStorage,
                                                    suffix, suffix_len);
                    retval =
                        set_ipCidrRouteType(data_context, ui->ptr,
                                            ui->len);
                    if (retval) {
                        netsnmp_set_request_error(reqinfo, requests,
                                                  SNMP_ERR_UNDOFAILED);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEINFO:
                {
                    int             retval;
                    struct undoInfo *ui;
                    ui = netsnmp_oid_stash_get_data(undoStorage,
                                                    suffix, suffix_len);
                    retval =
                        set_ipCidrRouteInfo(data_context, ui->ptr,
                                            ui->len);
                    if (retval) {
                        netsnmp_set_request_error(reqinfo, requests,
                                                  SNMP_ERR_UNDOFAILED);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTENEXTHOPAS:
                {
                    int             retval;
                    struct undoInfo *ui;
                    ui = netsnmp_oid_stash_get_data(undoStorage,
                                                    suffix, suffix_len);
                    retval =
                        set_ipCidrRouteNextHopAS(data_context, ui->ptr,
                                                 ui->len);
                    if (retval) {
                        netsnmp_set_request_error(reqinfo, requests,
                                                  SNMP_ERR_UNDOFAILED);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC1:
                {
                    int             retval;
                    struct undoInfo *ui;
                    ui = netsnmp_oid_stash_get_data(undoStorage,
                                                    suffix, suffix_len);
                    retval =
                        set_ipCidrRouteMetric1(data_context, ui->ptr,
                                               ui->len);
                    if (retval) {
                        netsnmp_set_request_error(reqinfo, requests,
                                                  SNMP_ERR_UNDOFAILED);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC2:
                {
                    int             retval;
                    struct undoInfo *ui;
                    ui = netsnmp_oid_stash_get_data(undoStorage,
                                                    suffix, suffix_len);
                    retval =
                        set_ipCidrRouteMetric2(data_context, ui->ptr,
                                               ui->len);
                    if (retval) {
                        netsnmp_set_request_error(reqinfo, requests,
                                                  SNMP_ERR_UNDOFAILED);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC3:
                {
                    int             retval;
                    struct undoInfo *ui;
                    ui = netsnmp_oid_stash_get_data(undoStorage,
                                                    suffix, suffix_len);
                    retval =
                        set_ipCidrRouteMetric3(data_context, ui->ptr,
                                               ui->len);
                    if (retval) {
                        netsnmp_set_request_error(reqinfo, requests,
                                                  SNMP_ERR_UNDOFAILED);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC4:
                {
                    int             retval;
                    struct undoInfo *ui;
                    ui = netsnmp_oid_stash_get_data(undoStorage,
                                                    suffix, suffix_len);
                    retval =
                        set_ipCidrRouteMetric4(data_context, ui->ptr,
                                               ui->len);
                    if (retval) {
                        netsnmp_set_request_error(reqinfo, requests,
                                                  SNMP_ERR_UNDOFAILED);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTEMETRIC5:
                {
                    int             retval;
                    struct undoInfo *ui;
                    ui = netsnmp_oid_stash_get_data(undoStorage,
                                                    suffix, suffix_len);
                    retval =
                        set_ipCidrRouteMetric5(data_context, ui->ptr,
                                               ui->len);
                    if (retval) {
                        netsnmp_set_request_error(reqinfo, requests,
                                                  SNMP_ERR_UNDOFAILED);
                    }
                }
                break;
            case COLUMN_IPCIDRROUTESTATUS:
                {
                    int             retval;
                    struct undoInfo *ui;
                    ui = netsnmp_oid_stash_get_data(undoStorage,
                                                    suffix, suffix_len);
                    retval =
                        set_ipCidrRouteStatus(data_context, ui->ptr,
                                              ui->len);
                    if (retval) {
                        netsnmp_set_request_error(reqinfo, requests,
                                                  SNMP_ERR_UNDOFAILED);
                    }
                }
                break;
            }
                /** mib2cXXX: remove cache!  hard to do when serialized, however */
            break;

        default:
            snmp_log(LOG_ERR,
                     "problem encountered in ipCidrRouteTable_handler: unsupported mode\n");
        }
    }
    return SNMP_ERR_NOERROR;
}
Ejemplo n.º 29
0
/** handles requests for the netSnmpHostsTable table, if anything else needs to be done */
int
netSnmpHostsTable_handler(netsnmp_mib_handler *handler,
                          netsnmp_handler_registration *reginfo,
                          netsnmp_agent_request_info *reqinfo,
                          netsnmp_request_info *requests)
{

    netsnmp_request_info *request;
    netsnmp_table_request_info *table_info;
    struct commitInfo *ci = NULL;

    void           *data_context = NULL;

    for (request = requests; request; request = request->next) {
        /* column and row index encoded portion */
        netsnmp_variable_list *var = request->requestvb;
        const oid * const suffix = var->name + reginfo->rootoid_len + 1;
        const size_t suffix_len = var->name_length - (reginfo->rootoid_len + 1);

        if (request->processed != 0)
            continue;

        switch (reqinfo->mode) {
        case MODE_GET:
        case MODE_SET_RESERVE1:
            data_context = netsnmp_extract_iterator_context(request);
            if (data_context == NULL) {
                if (reqinfo->mode == MODE_GET) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
            }
            break;

        default:               /* == the other SET modes */
            ci = netsnmp_oid_stash_get_data(commitStorage,
                                            suffix + 1, suffix_len - 1);
            break;

        }

        /** extracts the information about the table from the request */
        table_info = netsnmp_extract_table_info(request);
        /** table_info->colnum contains the column number requested */
        /** table_info->indexes contains a linked list of snmp variable
           bindings for the indexes of the table.  Values in the list
           have been set corresponding to the indexes of the
           request */
        if (table_info == NULL) {
            continue;
        }

        switch (reqinfo->mode) {
        case MODE_GET:
            switch (table_info->colnum) {
            case COLUMN_NETSNMPHOSTADDRESSTYPE:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    retval =
                        get_netSnmpHostAddressType(data_context,
                                                   &retval_len);
                    snmp_set_var_typed_value(var, ASN_INTEGER,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            case COLUMN_NETSNMPHOSTADDRESS:
                {
                    char           *retval;
                    size_t          retval_len = 0;
                    retval =
                        get_netSnmpHostAddress(data_context, &retval_len);
                    snmp_set_var_typed_value(var, ASN_OCTET_STR,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            case COLUMN_NETSNMPHOSTSTORAGE:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    retval =
                        get_netSnmpHostStorage(data_context, &retval_len);
                    snmp_set_var_typed_value(var, ASN_INTEGER,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            case COLUMN_NETSNMPHOSTROWSTATUS:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    retval =
                        get_netSnmpHostRowStatus(data_context,
                                                 &retval_len);
                    snmp_set_var_typed_value(var, ASN_INTEGER,
                                             (const u_char *) retval,
                                             retval_len);
                }
                break;

            default:
                /** We shouldn't get here */
                snmp_log(LOG_ERR,
                         "problem encountered in netSnmpHostsTable_handler: unknown column\n");
            }
            break;

        case MODE_SET_RESERVE1:
            ci = netsnmp_oid_stash_get_data(commitStorage,
                                            suffix + 1, suffix_len - 1);

            if (!ci) {
                    /** create the commit storage info */
                ci = SNMP_MALLOC_STRUCT(commitInfo);
                if (!data_context) {
                    ci->data_context =
                        netSnmpHostsTable_create_data_context(table_info->
                                                              indexes);
                    ci->new_row = 1;
                } else {
                    ci->data_context = data_context;
                }
                netsnmp_oid_stash_add_data(&commitStorage,
                                           suffix + 1, suffix_len - 1, ci);
            }
            break;

        case MODE_SET_RESERVE2:
            switch (table_info->colnum) {
            case COLUMN_NETSNMPHOSTADDRESSTYPE:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    struct undoInfo *ui = NULL;
                    int             ret;

                    /** first, get the old value */
                    retval =
                        get_netSnmpHostAddressType(ci->data_context,
                                                   &retval_len);
                    if (retval) {
                        ui = SNMP_MALLOC_STRUCT(undoInfo);
                        ui->len = retval_len;
                        memdup((u_char **) & ui->ptr,
                               (u_char *) retval, ui->len);
                    }

                    /** check the new value, possibly against the
                        older value for a valid state transition */
                    ret =
                        check_netSnmpHostAddressType(request->requestvb->
                                                     type,
                                                     (long *) request->
                                                     requestvb->val.string,
                                                     request->requestvb->
                                                     val_len, retval,
                                                     retval_len);
                    if (ret != 0) {
                        netsnmp_set_request_error(reqinfo, request, ret);
                        netSnmpHostsTable_free_undoInfo(ui);
                    } else if (ui) {
                        /** remember information for undo purposes later */
                        netsnmp_oid_stash_add_data(&undoStorage,
                                                   suffix, suffix_len, ui);
                    }

                }
                break;
            case COLUMN_NETSNMPHOSTADDRESS:
                {
                    char           *retval;
                    size_t          retval_len = 0;
                    struct undoInfo *ui = NULL;
                    int             ret;

                    /** first, get the old value */
                    retval =
                        get_netSnmpHostAddress(ci->data_context,
                                               &retval_len);
                    if (retval) {
                        ui = SNMP_MALLOC_STRUCT(undoInfo);
                        ui->len = retval_len;
                        memdup((u_char **) & ui->ptr,
                               (u_char *) retval, ui->len);
                    }

                    /** check the new value, possibly against the
                        older value for a valid state transition */
                    ret =
                        check_netSnmpHostAddress(request->requestvb->type,
                                                 (char *) request->
                                                 requestvb->val.string,
                                                 request->requestvb->
                                                 val_len, retval,
                                                 retval_len);
                    if (ret != 0) {
                        netsnmp_set_request_error(reqinfo, request, ret);
                        netSnmpHostsTable_free_undoInfo(ui);
                    } else if (ui) {
                        /** remember information for undo purposes later */
                        netsnmp_oid_stash_add_data(&undoStorage,
                                                   suffix, suffix_len, ui);
                    }

                }
                break;
            case COLUMN_NETSNMPHOSTSTORAGE:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    struct undoInfo *ui = NULL;
                    int             ret;

                    /** first, get the old value */
                    retval =
                        get_netSnmpHostStorage(ci->data_context,
                                               &retval_len);
                    if (retval) {
                        ui = SNMP_MALLOC_STRUCT(undoInfo);
                        ui->len = retval_len;
                        memdup((u_char **) & ui->ptr,
                               (u_char *) retval, ui->len);
                    }

                    /** check the new value, possibly against the
                        older value for a valid state transition */
                    ret =
                        check_netSnmpHostStorage(request->requestvb->type,
                                                 (long *) request->
                                                 requestvb->val.string,
                                                 request->requestvb->
                                                 val_len, retval,
                                                 retval_len);
                    if (ret != 0) {
                        netsnmp_set_request_error(reqinfo, request, ret);
                        netSnmpHostsTable_free_undoInfo(ui);
                    } else if (ui) {
                        /** remember information for undo purposes later */
                        netsnmp_oid_stash_add_data(&undoStorage,
                                                   suffix, suffix_len, ui);
                    }

                }
                break;
            case COLUMN_NETSNMPHOSTROWSTATUS:
                {
                    long           *retval;
                    size_t          retval_len = 0;
                    struct undoInfo *ui = NULL;
                    int             ret;

                    /** first, get the old value */
                    retval =
                        get_netSnmpHostRowStatus(ci->data_context,
                                                 &retval_len);
                    if (retval) {
                        ui = SNMP_MALLOC_STRUCT(undoInfo);
                        ui->len = retval_len;
                        memdup((u_char **) & ui->ptr,
                               (u_char *) retval, ui->len);
                    }

                    /** check the new value, possibly against the
                        older value for a valid state transition */
                    ret =
                        check_netSnmpHostRowStatus(request->requestvb->
                                                   type,
                                                   (long *) request->
                                                   requestvb->val.string,
                                                   request->requestvb->
                                                   val_len, retval,
                                                   retval_len);
                    if (ret != 0) {
                        netsnmp_set_request_error(reqinfo, request, ret);
                        netSnmpHostsTable_free_undoInfo(ui);
                    } else if (ui) {
                        /** remember information for undo purposes later */
                        netsnmp_oid_stash_add_data(&undoStorage,
                                                   suffix, suffix_len, ui);
                    }

                }
                break;
            default:
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_ERR_NOTWRITABLE);
                break;
            }
            break;

        case MODE_SET_ACTION:
            /** save a variable copy */
            switch (table_info->colnum) {
            case COLUMN_NETSNMPHOSTADDRESSTYPE:
                {
                    int             ret;
                    ret = set_netSnmpHostAddressType(ci->data_context,
                                                     (long *) request->
                                                     requestvb->val.string,
                                                     request->requestvb->
                                                     val_len);
                    if (ret) {
                        netsnmp_set_request_error(reqinfo, request, ret);
                    }
                }
                break;
            case COLUMN_NETSNMPHOSTADDRESS:
                {
                    int             ret;
                    ret = set_netSnmpHostAddress(ci->data_context,
                                                 (char *) request->
                                                 requestvb->val.string,
                                                 request->requestvb->
                                                 val_len);
                    if (ret) {
                        netsnmp_set_request_error(reqinfo, request, ret);
                    }
                }
                break;
            case COLUMN_NETSNMPHOSTSTORAGE:
                {
                    int             ret;
                    ret = set_netSnmpHostStorage(ci->data_context,
                                                 (long *) request->
                                                 requestvb->val.string,
                                                 request->requestvb->
                                                 val_len);
                    if (ret) {
                        netsnmp_set_request_error(reqinfo, request, ret);
                    }
                }
                break;
            case COLUMN_NETSNMPHOSTROWSTATUS:
                {
                    int             ret;
                    ret = set_netSnmpHostRowStatus(ci->data_context,
                                                   (long *) request->
                                                   requestvb->val.string,
                                                   request->requestvb->
                                                   val_len);
                    if (ret) {
                        netsnmp_set_request_error(reqinfo, request, ret);
                    }
                    if (*request->requestvb->val.integer == RS_DESTROY) {
                        ci->new_row = -1;
                    }
                }
                break;
            }
            break;

        case MODE_SET_COMMIT:
            if (!ci->have_committed) {
                    /** do this once per row only */
                netSnmpHostsTable_commit_row(&ci->data_context,
                                             ci->new_row);
                ci->have_committed = 1;
            }
            break;

        case MODE_SET_UNDO:
             /** save a variable copy */
            switch (table_info->colnum) {
            case COLUMN_NETSNMPHOSTADDRESSTYPE:
                {
                    int             retval;
                    struct undoInfo *ui;
                    ui = netsnmp_oid_stash_get_data(undoStorage,
                                                    suffix, suffix_len);
                    retval =
                        set_netSnmpHostAddressType(ci->data_context,
                                                   ui->ptr, ui->len);
                    if (retval) {
                        netsnmp_set_request_error(reqinfo, request,
                                                  SNMP_ERR_UNDOFAILED);
                    }
                }
                break;
            case COLUMN_NETSNMPHOSTADDRESS:
                {
                    int             retval;
                    struct undoInfo *ui;
                    ui = netsnmp_oid_stash_get_data(undoStorage,
                                                    suffix, suffix_len);
                    retval =
                        set_netSnmpHostAddress(ci->data_context, ui->ptr,
                                               ui->len);
                    if (retval) {
                        netsnmp_set_request_error(reqinfo, request,
                                                  SNMP_ERR_UNDOFAILED);
                    }
                }
                break;
            case COLUMN_NETSNMPHOSTSTORAGE:
                {
                    int             retval;
                    struct undoInfo *ui;
                    ui = netsnmp_oid_stash_get_data(undoStorage,
                                                    suffix, suffix_len);
                    retval =
                        set_netSnmpHostStorage(ci->data_context, ui->ptr,
                                               ui->len);
                    if (retval) {
                        netsnmp_set_request_error(reqinfo, request,
                                                  SNMP_ERR_UNDOFAILED);
                    }
                }
                break;
            case COLUMN_NETSNMPHOSTROWSTATUS:
                {
                    int             retval;
                    struct undoInfo *ui;
                    ui = netsnmp_oid_stash_get_data(undoStorage,
                                                    suffix, suffix_len);
                    retval =
                        set_netSnmpHostRowStatus(ci->data_context, ui->ptr,
                                                 ui->len);
                    if (retval) {
                        netsnmp_set_request_error(reqinfo, request,
                                                  SNMP_ERR_UNDOFAILED);
                    }
                }
                break;
            }
            break;

        case MODE_SET_FREE:
            break;

        default:
            snmp_log(LOG_ERR,
                     "problem encountered in netSnmpHostsTable_handler: unsupported mode\n");
        }
    }

    /** clean up after all requset processing has ended */
    switch (reqinfo->mode) {
    case MODE_SET_UNDO:
    case MODE_SET_FREE:
    case MODE_SET_COMMIT:
        /** clear out the undo cache */
        netsnmp_oid_stash_free(&undoStorage,
                               netSnmpHostsTable_free_undoInfo);
        netsnmp_oid_stash_free(&commitStorage, netsnmp_oid_stash_no_free);
    }


    return SNMP_ERR_NOERROR;
}
Ejemplo n.º 30
0
struct header_complex_index *
header_complex_add_data_by_oid(struct header_complex_index **thedata,
                               oid * newoid, size_t newoid_len, void *data)
{
    struct header_complex_index *hciptrn, *hciptrp, *ourself;
    int rc;

    if (thedata == NULL || newoid == NULL || data == NULL)
        return NULL;

    for (hciptrn = *thedata, hciptrp = NULL;
         hciptrn != NULL; hciptrp = hciptrn, hciptrn = hciptrn->next) {
        /*
         * XXX: check for == and error (overlapping table entries) 
         * 8/2005 rks Ok, I added duplicate entry check, but only log
         *            warning and continue, because it seems that nobody
         *            that calls this fucntion does error checking!.
         */
        rc = snmp_oid_compare(hciptrn->name, hciptrn->namelen,
                              newoid, newoid_len);
        if (rc > 0)
            break;
        else if (0 == rc) {
            snmp_log(LOG_WARNING, "header_complex_add_data_by_oid with "
                     "duplicate index.\n");
            /** uncomment null return when callers do error checking */
            /** return NULL; */
        }
    }

    /*
     * nptr should now point to the spot that we need to add ourselves
     * in front of, and pptr should be our new 'prev'. 
     */

    /*
     * create ourselves 
     */
    ourself = (struct header_complex_index *)
        SNMP_MALLOC_STRUCT(header_complex_index);
    if (ourself == NULL)
        return NULL;

    /*
     * change our pointers 
     */
    ourself->prev = hciptrp;
    ourself->next = hciptrn;

    if (ourself->next)
        ourself->next->prev = ourself;

    if (ourself->prev)
        ourself->prev->next = ourself;

    ourself->data = data;
    ourself->name = snmp_duplicate_objid(newoid, newoid_len);
    ourself->namelen = newoid_len;

    /*
     * rewind to the head of the list and return it (since the new head
     * could be us, we need to notify the above routine who the head now is. 
     */
    for (hciptrp = ourself; hciptrp->prev != NULL;
         hciptrp = hciptrp->prev);

    *thedata = hciptrp;
    DEBUGMSGTL(("header_complex_add_data", "adding something...\n"));

    return hciptrp;
}