Esempio n. 1
0
  /*
   * ... Unfortunately, the internal engine ID is not set up
   * until later, so this default session is incomplete.
   * The resulting engineID probe runs into problems,
   * causing the very first internal query to time out.
   *   Updating the default session with the internal engineID
   * once it has been set, fixes this problem.
   */
int
_tweak_default_iquery_session( int majorID, int minorID,
                              void *serverargs, void *clientarg)
{
    u_char eID[SNMP_MAXBUF_SMALL];
    size_t elen;
    netsnmp_session *s = netsnmp_query_get_default_session();

    if ( s && s->securityEngineIDLen == 0 ) {
        elen = snmpv3_get_engineID(eID, sizeof(eID));
        memdup( &(s->securityEngineID), eID, elen );
        s->securityEngineIDLen = elen;
    }
    return SNMPERR_SUCCESS;
}
Esempio n. 2
0
void
parse_sched_periodic( const char *token, char *line )
{
    netsnmp_tdata_row       *row;
    struct schedTable_entry *entry;
    char   buf[24], tmpbuf[SPRINT_MAX_LEN];
    long   frequency;
    long   value;
    size_t tmpint;
    oid    variable[ MAX_OID_LEN], *var_ptr = variable;
    size_t var_len = MAX_OID_LEN;
    
    schedEntries++;
    sprintf(buf, "_conf%03d", schedEntries);

    DEBUGMSGTL(( "disman:schedule:conf", "periodic: %s %s\n", token, line));
    /*
     *  Parse the configure directive line
     */
    line = copy_nword(line, tmpbuf, sizeof(tmpbuf));
    frequency = netsnmp_string_time_to_secs(tmpbuf);
    if (frequency == -1) {
        config_perror("Illegal frequency specified");
        return;
    }

    line = read_config_read_data(ASN_OBJECT_ID, line, &var_ptr,   &var_len);
    if (var_len == 0) {
        config_perror("invalid specification for schedVariable");
        return;
    }
    /*
     * Skip over optional assignment in "var = value"
     */
    while (line && isspace((unsigned char)(*line)))
        line++;
    if (line && *line == '=' ) {
        line++;
        while (line && isspace((unsigned char)(*line))) {
            line++;
        }
    }
    line = read_config_read_data(ASN_INTEGER,   line, &value, &tmpint);
    
    /*
     * Create an entry in the schedTable
     */
    row   = schedTable_createEntry( "snmpd.conf", buf );
    if (!row || !row->data) {
        config_perror("create schedule entry failure");
        return;
    }
    entry = (struct schedTable_entry *)row->data;

    entry->schedInterval     = frequency;
    entry->schedValue        = value;
    entry->schedVariable_len = var_len;
    memcpy(entry->schedVariable, variable, var_len*sizeof(oid));

    entry->schedType         = SCHED_TYPE_PERIODIC;
    entry->schedStorageType  = ST_READONLY;  /* or PERMANENT */
    entry->flags             = SCHEDULE_FLAG_ENABLED |
                               SCHEDULE_FLAG_ACTIVE  |
                               SCHEDULE_FLAG_VALID;
    entry->session           = netsnmp_query_get_default_session();
    sched_nextTime( entry );
}
Esempio n. 3
0
void
parse_sched_timed( const char *token, char *line )
{
    netsnmp_tdata_row       *row;
    struct schedTable_entry *entry;
    char   buf[24], *cp;

    char  minConf[512];  size_t  min_len = sizeof(minConf);  char  minVal[8];
    char hourConf[512];  size_t hour_len = sizeof(hourConf); char hourVal[3];
    char dateConf[512];  size_t date_len = sizeof(dateConf); char dateVal[8];
    char  monConf[512];  size_t  mon_len = sizeof(monConf);  char  monVal[2];
    char  dayConf[512];  size_t  day_len = sizeof(dayConf);  char  dayVal;

    long   value;
    size_t tmpint;
    oid    variable[ MAX_OID_LEN], *var_ptr = variable;
    size_t var_len = MAX_OID_LEN;
    
    schedEntries++;
    sprintf(buf, "_conf%03d", schedEntries);

    DEBUGMSGTL(( "sched", "config: %s %s\n", token, line));
    /*
     *  Parse the configure directive line
     */
    cp       = minConf;
    line = read_config_read_data(ASN_OCTET_STR, line, &cp,   &min_len);
    cp       = hourConf;
    line = read_config_read_data(ASN_OCTET_STR, line, &cp,  &hour_len);
    cp       = dateConf;
    line = read_config_read_data(ASN_OCTET_STR, line, &cp,  &date_len);
    cp       = monConf;
    line = read_config_read_data(ASN_OCTET_STR, line, &cp,   &mon_len);
    cp       = dayConf;
    line = read_config_read_data(ASN_OCTET_STR, line, &cp,   &day_len);
    if (!line) {
        config_perror("invalid schedule time specification");
        return;
    }

    line = read_config_read_data(ASN_OBJECT_ID, line, &var_ptr,   &var_len);
    if (var_len == 0) {
        config_perror("invalid specification for schedVariable");
        return;
    }
    /*
     * Skip over optional assignment in "var = value"
     */
    while (line && isspace((unsigned char)(*line)))
        line++;
    if ( *line == '=' ) {
        line++;
        while (line && isspace((unsigned char)(*line))) {
            line++;
        }
    }
    line = read_config_read_data(ASN_INTEGER,   line, &value, &tmpint);

    /*
     * Convert from cron-style specifications into bits
     */
    _sched_convert_bits( minConf,  minVal,  8, 60, 0 );
    _sched_convert_bits( hourConf, hourVal, 3, 24, 0 );
    memset(dateVal+4, 0, 4); /* Clear the reverse day bits */
    _sched_convert_bits( dateConf, dateVal, 4, 31, 1 );
    _sched_convert_bits( monConf,  monVal,  2, 12, 1 );
    _sched_convert_bits( dayConf, &dayVal,  1,  8, 0 );
    if ( dayVal & 0x01 ) {  /* sunday(7) = sunday(0) */
         dayVal |= 0x80;
         dayVal &= 0xfe;
    }
    
    /*
     * Create an entry in the schedTable
     */
    row   = schedTable_createEntry("snmpd.conf", buf);
    if (!row || !row->data) {
        config_perror("create schedule entry failure");
        return;
    }
    entry = (struct schedTable_entry *)row->data;

    entry->schedWeekDay = dayVal;
    memcpy(entry->schedMonth,  monVal,  2);
    memcpy(entry->schedDay,    dateVal, 4+4);
    memcpy(entry->schedHour,   hourVal, 3);
    memcpy(entry->schedMinute, minVal,  8);
    
    memcpy(entry->schedVariable, variable, var_len*sizeof(oid));
    entry->schedVariable_len = var_len;
    entry->schedValue        = value;

    if ( !strcmp( token, "at" ))
        entry->schedType     = SCHED_TYPE_ONESHOT;
    else
        entry->schedType     = SCHED_TYPE_CALENDAR;
    entry->schedStorageType  = ST_READONLY;  /* or PERMANENT */
    entry->flags             = SCHEDULE_FLAG_ENABLED |
                               SCHEDULE_FLAG_ACTIVE  |
                               SCHEDULE_FLAG_VALID;
    entry->session           = netsnmp_query_get_default_session();
    sched_nextTime( entry );
}
void
parse_expression(const char *token, char *line)
{
    char   buf[ SPRINT_MAX_LEN];
    char   ename[EXP_STR1_LEN+1];
    oid    name_buf[MAX_OID_LEN];
    size_t name_len;
    char *cp, *cp2;
    struct expExpression *entry;
    struct expObject     *object;
    netsnmp_session *sess = NULL;
    int    type=EXPVALTYPE_COUNTER;
    int    i=1;

    DEBUGMSGTL(("disman:expr:conf", "Parsing expression config...  "));

    memset(buf,   0, sizeof(buf));
    memset(ename, 0, sizeof(ename));

    for (cp = copy_nword(line, buf, SPRINT_MAX_LEN);
         ;
         cp = copy_nword(cp,   buf, SPRINT_MAX_LEN)) {

        if (buf[0] == '-' ) {
            switch (buf[1]) {
            case 't':   /*  type */
                switch (buf[2]) {
                case 'c':   type = EXPVALTYPE_COUNTER;   break;
                case 'u':   type = EXPVALTYPE_UNSIGNED;  break;
                case 't':   type = EXPVALTYPE_TIMETICKS; break;
                case 'i':   type = EXPVALTYPE_INTEGER;   break;
                case 'a':   type = EXPVALTYPE_IPADDRESS; break;
                case 's':   type = EXPVALTYPE_STRING;    break;
                case 'o':   type = EXPVALTYPE_OID;       break;
                case 'C':   type = EXPVALTYPE_COUNTER64; break;
                }
                break;
            case 'u':   /*  user */
                cp     = copy_nword(cp, buf, SPRINT_MAX_LEN);
                sess   = netsnmp_iquery_user_session(buf);
                break;
            }
        } else {
            break;
        }
    }

    memcpy(ename, buf, sizeof(ename));
 /* cp    = copy_nword(line, ename, sizeof(ename)); */
    entry = expExpression_createEntry( "snmpd.conf", ename, 1 );
    if (!entry)
        return;

    cp2 = entry->expExpression;
    while (cp && *cp) {
        /*
         * Copy everything that can't possibly be a MIB
         * object name into the expression field...
         */
        /*   XXX - TODO - Handle string literals */
        if (!isalpha(*cp)) {
           *cp2++ = *cp++;
           continue;
        }
        /*
         * ... and copy the defined functions across as well
         *   XXX - TODO
         */

        /*
         * Anything else is presumably a MIB object (or instance).
         * Create an entry in the expObjectTable, and insert a
         *   corresponding parameter in the expression itself.
         */
        name_len = MAX_OID_LEN;
        cp = copy_nword(cp, buf, SPRINT_MAX_LEN);
        snmp_parse_oid( buf, name_buf, &name_len );
        object = expObject_createEntry( "snmpd.conf", ename, i, 1 );
        memcpy( object->expObjectID, name_buf, name_len*sizeof(oid));
        object->expObjectID_len = name_len;
        object->flags |= EXP_OBJ_FLAG_VALID
                      |  EXP_OBJ_FLAG_ACTIVE
                      |  EXP_OBJ_FLAG_OWILD;
        /*
         * The first such object can also be used as the
         * expExpressionPrefix
         */
        if ( i == 1 ) {
            memcpy( entry->expPrefix, name_buf, name_len*sizeof(oid));
            entry->expPrefix_len = name_len;
            object->flags |= EXP_OBJ_FLAG_PREFIX;
        }
        sprintf(cp2, "$%d", i++);
        while (*cp2)
            cp2++;  /* Skip over this parameter */
    }

    if (sess)
        entry->session      = sess;
    else
        entry->session      = netsnmp_query_get_default_session();
    entry->expDeltaInterval = 10;
    entry->expValueType     = type;
    entry->flags |= EXP_FLAG_VALID
                 |  EXP_FLAG_ACTIVE;
    expExpression_enable( entry );
    DEBUGMSG(("disman:expr:conf", "(%s, %s)\n", ename,
                                                entry->expExpression));
}
Esempio n. 5
0
static int iquery(struct variable_list **vars, char *secName, int snmp_version,
                  const oid *name, int name_len)
{
    struct snmp_session *ss;
    struct snmp_pdu *pdu;
    struct snmp_pdu *response;
    struct variable_list *v;
    int status, rc = SNMP_ERR_GENERR;

    ss = netsnmp_query_get_default_session();
    if (!ss) {
        snmp_log(LOG_ERR, "%s: default SNMP session not available\n", __func__);
        goto out;
    }

    ss->retries = 0;

    pdu = snmp_pdu_create(SNMP_MSG_GET);
    if (!pdu) {
        snmp_log(LOG_ERR, "%s: failed to create an SNMP PDU\n", __func__);
        goto out;
    }

    if (snmp_add_null_var(pdu, name, name_len) == NULL) {
        snmp_log(LOG_ERR, "%s: appending a variable to a PDU failed\n",
                 __func__);
        goto free_pdu;
    }

    DEBUGMSGTL(("expValueTable", "%s: querying OID ", __func__));
    DEBUGMSGOID(("expValueTable", name, name_len));
    DEBUGMSG(("expValueTable", "\n"));

    status = snmp_synch_response(ss, pdu, &response);

    DEBUGMSGTL(("expValueTable", "%s: SNMP response status %d; rc %ld\n",
                __func__, status, response ? response->errstat : -1));

    if (status != STAT_SUCCESS)
        goto free_pdu;

    rc = response->errstat;
    *vars = snmp_clone_varbind(response->variables);
    if (*vars == NULL)
        goto free_response;

    for (v = *vars; v; v = v->next_variable) {
        DEBUGMSGTL(("expValueTable", "%s: response variable type %d; oid ",
                    __func__, v->type));
        DEBUGMSGOID(("expValueTable", v->name, v->name_length));
        if (v->type == ASN_INTEGER)
            DEBUGMSG(("expValueTable", "; value %ld\n", *v->val.integer));
        DEBUGMSG(("expValueTable", "\n"));
    }

    rc = SNMPERR_SUCCESS;

free_response:
    if (response)
        snmp_free_pdu(response);

free_pdu:
    /* if (pdu) snmp_free_pdu(pdu); -- triggers a use-after-free */

out:
    return rc;
}