/*
 * var_expExpressionTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_expExpressionTable above.
 */
unsigned char  *
var_expExpressionTable(struct variable *vp,
                       oid * name,
                       size_t *length,
                       int exact,
                       size_t *var_len, WriteMethod ** write_method)
{
    struct expExpressionTable_data *StorageTmp = NULL;

    DEBUGMSGTL(("expExpressionTable",
                "var_expExpressionTable: Entering...  \n"));

    /*
     * this assumes you have registered all your data properly
     */
    if ((StorageTmp =
         header_complex(expExpressionTableStorage, vp, name, length, exact,
                        var_len, write_method)) == NULL) {
        if (vp->magic == EXPEXPRESSIONENTRYSTATUS)
            *write_method = write_expExpressionEntryStatus;
        return NULL;
    }


    switch (vp->magic) {


    case EXPEXPRESSION:
        *write_method = write_expExpression;
        *var_len = StorageTmp->expExpressionLen;
        return (u_char *) StorageTmp->expExpression;

    case EXPEXPRESSIONVALUETYPE:
        *write_method = write_expExpressionValueType;
        *var_len = sizeof(StorageTmp->expExpressionValueType);
        return (u_char *) & StorageTmp->expExpressionValueType;

    case EXPEXPRESSIONCOMMENT:
        *write_method = write_expExpressionComment;
        *var_len = StorageTmp->expExpressionCommentLen;
        return (u_char *) StorageTmp->expExpressionComment;

    case EXPEXPRESSIONDELTALNTERVAL:
        *write_method = write_expExpressionDeltaInterval;
        *var_len = sizeof(StorageTmp->expExpressionDeltaInterval);
        return (u_char *) & StorageTmp->expExpressionDeltaInterval;

    case EXPEXPRESSIONPREFIX:
        *var_len = StorageTmp->expExpressionPrefixLen * sizeof(oid);
        return (u_char *) StorageTmp->expExpressionPrefix;

    case EXPEXPRESSIONERRORS:
        *var_len = sizeof(StorageTmp->expExpressionErrors);
        return (u_char *) & StorageTmp->expExpressionErrors;

    case EXPEXPRESSIONENTRYSTATUS:
        *write_method = write_expExpressionEntryStatus;
        *var_len = sizeof(StorageTmp->expExpressionEntryStatus);
        return (u_char *) & StorageTmp->expExpressionEntryStatus;

    default:
        ERROR_MSG("");

    }
    return NULL;
}
int
write_expExpressionComment(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)
{
    static char    *tmpvar;
    struct expExpressionTable_data *StorageTmp = NULL;
    static size_t   tmplen;
    size_t          newlen =
        name_len -
        (sizeof(expExpressionTable_variables_oid) / sizeof(oid) + 3 - 1);


    DEBUGMSGTL(("expExpressionTable",
                "write_expExpression entering action=%d...  \n", action));
    if ((StorageTmp =
         header_complex(expExpressionTableStorage, NULL,
                        &name[sizeof(expExpressionTable_variables_oid) /
                              sizeof(oid) + 3 - 1], &newlen, 1, NULL,
                        NULL)) == NULL)
        return SNMP_ERR_NOSUCHNAME;     /* remove if you support creation here */


    switch (action) {
    case RESERVE1:
        if (var_val_type != ASN_OCTET_STR) {
            snmp_log(LOG_ERR,
                     "write to expExpressionComment not ASN_OCTET_STR\n");
            return SNMP_ERR_WRONGTYPE;
        }
        if (StorageTmp->storageType != ST_NONVOLATILE)
            return SNMP_ERR_NOTWRITABLE;

        break;


    case RESERVE2:
        /*
         * memory reseveration, final preparation... 
         */
        break;


    case FREE:
        /*
         * Release any resources that have been allocated 
         */
        break;


    case ACTION:
        /*
         * The variable has been stored in string for
         * you to use, and you have just been asked to do something with
         * it.  Note that anything done here must be reversable in the UNDO case 
         */
        tmpvar = StorageTmp->expExpressionComment;
        tmplen = StorageTmp->expExpressionCommentLen;
        StorageTmp->expExpressionComment = netsnmp_memdup(var_val, var_val_len);
        StorageTmp->expExpressionCommentLen = var_val_len;
        break;


    case UNDO:
        /*
         * Back out any changes made in the ACTION case 
         */
        SNMP_FREE(StorageTmp->expExpressionComment);
        StorageTmp->expExpressionComment = tmpvar;
        StorageTmp->expExpressionCommentLen = tmplen;
        break;


    case COMMIT:
        /*
         * Things are working well, so it's now safe to make the change
         * permanently.  Make sure that anything done here can't fail! 
         */
        SNMP_FREE(tmpvar);
        snmp_store_needed(NULL);
        break;
    }
    return SNMP_ERR_NOERROR;

}
/*
 * var_snmpNotifyFilterProfileTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_snmpNotifyFilterProfileTable above.
 */
unsigned char  *
var_snmpNotifyFilterProfileTable(struct variable *vp,
                                 oid * name,
                                 size_t * length,
                                 int exact,
                                 size_t * var_len,
                                 WriteMethod ** write_method)
{


    struct snmpNotifyFilterProfileTable_data *StorageTmp = NULL;
    int found = 1;


    DEBUGMSGTL(("snmpNotifyFilterProfileTable",
                "var_snmpNotifyFilterProfileTable: Entering...  \n"));
    /*
     * this assumes you have registered all your data properly
     */
    if ((StorageTmp = (struct snmpNotifyFilterProfileTable_data *)
         header_complex((struct header_complex_index *)
                        snmpNotifyFilterProfileTableStorage, vp, name,
                        length, exact, var_len, write_method)) == NULL) {
        found = 0;
    }

    switch (vp->magic) {
    case SNMPNOTIFYFILTERPROFILENAME:
        *write_method = write_snmpNotifyFilterProfileName;
        break;

    case SNMPNOTIFYFILTERPROFILESTORTYPE:
        *write_method = write_snmpNotifyFilterProfileStorType;
        break;

    case SNMPNOTIFYFILTERPROFILEROWSTATUS:
        *write_method = write_snmpNotifyFilterProfileRowStatus;
        break;

    default:
        *write_method = NULL;
    }

    if (!found) {
        return NULL;
    }

    /*
     * this is where we do the value assignments for the mib results.
     */
    switch (vp->magic) {

    case SNMPNOTIFYFILTERPROFILENAME:
        *var_len = StorageTmp->snmpNotifyFilterProfileNameLen;
        return (u_char *) StorageTmp->snmpNotifyFilterProfileName;

    case SNMPNOTIFYFILTERPROFILESTORTYPE:
        *var_len = sizeof(StorageTmp->snmpNotifyFilterProfileStorType);
        return (u_char *) & StorageTmp->snmpNotifyFilterProfileStorType;

    case SNMPNOTIFYFILTERPROFILEROWSTATUS:
        *var_len = sizeof(StorageTmp->snmpNotifyFilterProfileRowStatus);
        return (u_char *) & StorageTmp->snmpNotifyFilterProfileRowStatus;


    default:
        ERROR_MSG("");
    }
    return NULL;
}
int
write_snmpNotifyTag(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)
{
    static char    *tmpvar;
    struct snmpNotifyTable_data *StorageTmp = NULL;
    static size_t   tmplen;
    size_t          newlen =
        name_len - (sizeof(snmpNotifyTable_variables_oid) / sizeof(oid) +
                    3 - 1);


    DEBUGMSGTL(("snmpNotifyTable",
                "write_snmpNotifyTag entering action=%d...  \n", action));
    if (action != RESERVE1 &&
        (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)) == NULL) {
        if ((StorageTmp = StorageNew) == NULL)
            return SNMP_ERR_NOSUCHNAME; /* remove if you support creation here */
    }


    switch (action) {
    case RESERVE1:
        if (var_val_type != ASN_OCTET_STR) {
            return SNMP_ERR_WRONGTYPE;
        }
        if (var_val_len > 255) {
            return SNMP_ERR_WRONGLENGTH;
        }
        if (!snmpTagValid((char *) var_val, var_val_len)) {
            return SNMP_ERR_WRONGVALUE;
        }
        break;


    case RESERVE2:
        /*
         * memory reseveration, final preparation... 
         */
        tmpvar = StorageTmp->snmpNotifyTag;
        tmplen = StorageTmp->snmpNotifyTagLen;
        StorageTmp->snmpNotifyTag = (char*)calloc(1, var_val_len + 1);
        if (NULL == StorageTmp->snmpNotifyTag)
            return SNMP_ERR_RESOURCEUNAVAILABLE;
        break;


    case FREE:
        /*
         * Release any resources that have been allocated 
         */
        break;


    case ACTION:
        memcpy(StorageTmp->snmpNotifyTag, var_val, var_val_len);
        StorageTmp->snmpNotifyTagLen = var_val_len;
        break;


    case UNDO:
        /*
         * Back out any changes made in the ACTION case 
         */
        SNMP_FREE(StorageTmp->snmpNotifyTag);
        StorageTmp->snmpNotifyTag = tmpvar;
        StorageTmp->snmpNotifyTagLen = tmplen;
        tmpvar = NULL;
        break;


    case COMMIT:
        /*
         * Things are working well, so it's now safe to make the change
         * permanently.  Make sure that anything done here can't fail! 
         */
        SNMP_FREE(tmpvar);
        snmp_store_needed(NULL);
        break;
    }

    return SNMP_ERR_NOERROR;
}
Exemple #5
0
/*
 * var_expValueTable():
 */
unsigned char  *
var_expValueTable(struct variable *vp,
                  oid * name,
                  size_t *length,
                  int exact, size_t *var_len, WriteMethod ** write_method)
{

    static netsnmp_variable_list *vars;
    size_t          newlen =
        *length - (sizeof(expValueTable_variables_oid) / sizeof(oid) +
                   3 - 1);
    struct expValueTable_data *StorageTmp = NULL;
    unsigned int    counter32;




    DEBUGMSGTL(("expValueTable", "var_expValueTable: Entering...  \n"));

    /*
     *  before we build valuetable we must free any other valutable if exist
     */
    header_complex_free_all(expValueTableStorage, expValueTable_clean);
    expValueTableStorage = NULL;


    build_valuetable();


    /*
     * this assumes you have registered all your data properly
     */
    if ((StorageTmp =
         header_complex(expValueTableStorage, vp, name, length, exact,
                        var_len, write_method)) == NULL)
        return NULL;


    /*
     * this is where we do the value assignments for the mib results.
     */
    switch (vp->magic) {
        /*
         *   we only support counter32val
         */

    case EXPVALUECOUNTER32VAL:
        StorageTmp->expValueCounter32Val = Evaluate_Expression(StorageTmp);
        *var_len = sizeof(StorageTmp->expValueCounter32Val);
        return (u_char *) & StorageTmp->expValueCounter32Val;

    case EXPVALUEUNSIGNED32VAL:
        /* var_len = sizeof(StorageTmp->expValueUnsigned32Val); */
        /* return (u_char *) & StorageTmp->expValueUnsigned32Val;         */
        return NULL;

    case EXPVALUETIMETICKSVAL:
        /* var_len = sizeof(StorageTmp->expValueTimeTicksVal); */
        /* return (u_char *) & StorageTmp->expValueTimeTicksVal; */
        return NULL;

    case EXPVALUEINTEGER32VAL:
        /* var_len = sizeof(StorageTmp->expValueInteger32Val); */
        /* return (u_char *) & StorageTmp->expValueInteger32Val; */
        return NULL;

    case EXPVALUEIPADDRESSVAL:
        /* var_len = sizeof(StorageTmp->expValueIpAddressVal); */
        /* return (u_char *) & StorageTmp->expValueIpAddressVal; */
        return NULL;

    case EXPVALUEOCTETSTRINGVAL:
        /* var_len = sizeof(StorageTmp->expValueOctetStringVal); */
        /* return (u_char *) & StorageTmp->expValueOctetStringVal;        */
        return NULL;

    case EXPVALUEOIDVAL:
        /* var_len = StorageTmp->expValueOidValLen; */
        /* return (u_char *) & StorageTmp->expValueOidVal; */
        return NULL;

    case EXPVALUECOUNTER64VAL:
        /* var_len = sizeof(StorageTmp->expValueCounter64Val); */
        /* return (u_char *) & StorageTmp->expValueCounter64Val; */
        return NULL;
    default:
        ERROR_MSG("");
    }
}
/*
 * var_mteTriggerThresholdTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_mteTriggerThresholdTable above.
 */
unsigned char  *
var_mteTriggerThresholdTable(struct variable *vp,
                             oid * name,
                             size_t * length,
                             int exact,
                             size_t * var_len, WriteMethod ** write_method)
{


    struct mteTriggerTable_data *StorageTmp = NULL;


    DEBUGMSGTL(("mteTriggerThresholdTable",
                "var_mteTriggerThresholdTable: Entering...  \n"));
    /*
     * this assumes you have registered all your data properly
     */
    if ((StorageTmp =
         header_complex(mteTriggerTableStorage, vp, name, length, exact,
                        var_len, write_method)) == NULL)
        return NULL;


    if (!(StorageTmp->mteTriggerTest[0] & MTETRIGGERTEST_THRESHOLD))
        return NULL;

    /*
     * this is where we do the value assignments for the mib results.
     */
    switch (vp->magic) {


    case MTETRIGGERTHRESHOLDSTARTUP:
        *write_method = write_mteTriggerThresholdStartup;
        *var_len = sizeof(StorageTmp->mteTriggerThresholdStartup);
        return (u_char *) & StorageTmp->mteTriggerThresholdStartup;

    case MTETRIGGERTHRESHOLDRISING:
        *write_method = write_mteTriggerThresholdRising;
        *var_len = sizeof(StorageTmp->mteTriggerThresholdRising);
        return (u_char *) & StorageTmp->mteTriggerThresholdRising;

    case MTETRIGGERTHRESHOLDFALLING:
        *write_method = write_mteTriggerThresholdFalling;
        *var_len = sizeof(StorageTmp->mteTriggerThresholdFalling);
        return (u_char *) & StorageTmp->mteTriggerThresholdFalling;

    case MTETRIGGERTHRESHOLDDELTARISING:
        *write_method = write_mteTriggerThresholdDeltaRising;
        *var_len = sizeof(StorageTmp->mteTriggerThresholdDeltaRising);
        return (u_char *) & StorageTmp->mteTriggerThresholdDeltaRising;

    case MTETRIGGERTHRESHOLDDELTAFALLING:
        *write_method = write_mteTriggerThresholdDeltaFalling;
        *var_len = sizeof(StorageTmp->mteTriggerThresholdDeltaFalling);
        return (u_char *) & StorageTmp->mteTriggerThresholdDeltaFalling;

    case MTETRIGGERTHRESHOLDOBJECTSOWNER:
        *write_method = write_mteTriggerThresholdObjectsOwner;
        *var_len = StorageTmp->mteTriggerThresholdObjectsOwnerLen;
        return (u_char *) StorageTmp->mteTriggerThresholdObjectsOwner;

    case MTETRIGGERTHRESHOLDOBJECTS:
        *write_method = write_mteTriggerThresholdObjects;
        *var_len = StorageTmp->mteTriggerThresholdObjectsLen;
        return (u_char *) StorageTmp->mteTriggerThresholdObjects;

    case MTETRIGGERTHRESHOLDRISINGEVENTOWNER:
        *write_method = write_mteTriggerThresholdRisingEventOwner;
        *var_len = StorageTmp->mteTriggerThresholdRisingEventOwnerLen;
        return (u_char *) StorageTmp->mteTriggerThresholdRisingEventOwner;

    case MTETRIGGERTHRESHOLDRISINGEVENT:
        *write_method = write_mteTriggerThresholdRisingEvent;
        *var_len = StorageTmp->mteTriggerThresholdRisingEventLen;
        return (u_char *) StorageTmp->mteTriggerThresholdRisingEvent;

    case MTETRIGGERTHRESHOLDFALLINGEVENTOWNER:
        *write_method = write_mteTriggerThresholdFallingEventOwner;
        *var_len = StorageTmp->mteTriggerThresholdFallingEventOwnerLen;
        return (u_char *) StorageTmp->mteTriggerThresholdFallingEventOwner;

    case MTETRIGGERTHRESHOLDFALLINGEVENT:
        *write_method = write_mteTriggerThresholdFallingEvent;
        *var_len = StorageTmp->mteTriggerThresholdFallingEventLen;
        return (u_char *) StorageTmp->mteTriggerThresholdFallingEvent;

    case MTETRIGGERTHRESHOLDDELTARISINGEVENTOWNER:
        *write_method = write_mteTriggerThresholdDeltaRisingEventOwner;
        *var_len = StorageTmp->mteTriggerThresholdDeltaRisingEventOwnerLen;
        return (u_char *) StorageTmp->
            mteTriggerThresholdDeltaRisingEventOwner;

    case MTETRIGGERTHRESHOLDDELTARISINGEVENT:
        *write_method = write_mteTriggerThresholdDeltaRisingEvent;
        *var_len = StorageTmp->mteTriggerThresholdDeltaRisingEventLen;
        return (u_char *) StorageTmp->mteTriggerThresholdDeltaRisingEvent;

    case MTETRIGGERTHRESHOLDDELTAFALLINGEVENTOWNER:
        *write_method = write_mteTriggerThresholdDeltaFallingEventOwner;
        *var_len =
            StorageTmp->mteTriggerThresholdDeltaFallingEventOwnerLen;
        return (u_char *) StorageTmp->
            mteTriggerThresholdDeltaFallingEventOwner;

    case MTETRIGGERTHRESHOLDDELTAFALLINGEVENT:
        *write_method = write_mteTriggerThresholdDeltaFallingEvent;
        *var_len = StorageTmp->mteTriggerThresholdDeltaFallingEventLen;
        return (u_char *) StorageTmp->mteTriggerThresholdDeltaFallingEvent;


    default:
        ERROR_MSG("");
    }
    return NULL;
}
Exemple #7
0
int
write_mteObjectsEntryStatus(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 mteObjectsTable_data *StorageTmp = NULL;
    static struct mteObjectsTable_data *StorageNew, *StorageDel;
    size_t          newlen =
        name_len - (sizeof(mteObjectsTable_variables_oid) / sizeof(oid) +
                    3 - 1);
    static int      old_value;
    int             set_value;
    static netsnmp_variable_list *vars, *vp;
    struct header_complex_index *hciptr;


    StorageTmp =
        header_complex(mteObjectsTableStorage, NULL,
                       &name[sizeof(mteObjectsTable_variables_oid) /
                             sizeof(oid) + 3 - 1], &newlen, 1, NULL, NULL);

    if (var_val_type != ASN_INTEGER || var_val == NULL) {
        snmp_log(LOG_ERR,
                 "write to mteObjectsEntryStatus not ASN_INTEGER\n");
        return SNMP_ERR_WRONGTYPE;
    }

    if (StorageTmp && StorageTmp->storagetype == ST_READONLY) {
        return SNMP_ERR_NOTWRITABLE;
    }

    set_value = *((long *) var_val);


    /*
     * check legal range, and notReady is reserved for us, not a user 
     */
    if (set_value < 1 || set_value > 6 || set_value == RS_NOTREADY)
        return SNMP_ERR_INCONSISTENTVALUE;


    switch (action) {
    case RESERVE1:
        /*
         * stage one: test validity 
         */
        if (StorageTmp == NULL) {
            /*
             * create the row now? 
             */


            /*
             * ditch illegal values now 
             */
            if (set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE)
                return SNMP_ERR_INCONSISTENTVALUE;


            /*
             * destroying a non-existent row is actually legal 
             */
            if (set_value == RS_DESTROY) {
                return SNMP_ERR_NOERROR;
            }


            /*
             * illegal creation values 
             */
            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 
             */
        }
        break;




    case RESERVE2:
        /*
         * memory reseveration, final preparation... 
         */
        if (StorageTmp == NULL) {
            /*
             * creation 
             */
            vars = NULL;


            snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, NULL, 0);  /* mteOwner */
            snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, NULL, 0);  /* mteObjectsName */
            snmp_varlist_add_variable(&vars, NULL, 0, ASN_UNSIGNED, NULL, 0);   /* mteObjectsIndex */

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


            StorageNew = SNMP_MALLOC_STRUCT(mteObjectsTable_data);
            if (StorageNew == NULL)
                return SNMP_ERR_GENERR;
            StorageNew->mteOwner = netsnmp_strdup_and_null(vp->val.string,
                                                           vp->val_len);
            StorageNew->mteOwnerLen = vp->val_len;
            vp = vp->next_variable;
            StorageNew->mteObjectsName  =
                netsnmp_strdup_and_null(vp->val.string,
                                        vp->val_len);
            StorageNew->mteObjectsNameLen = vp->val_len;
            vp = vp->next_variable;
            StorageNew->mteObjectsIndex = *(vp->val.integer);

            /*
             * XXX: fill in default row values here into StorageNew 
             */
            StorageNew->mteObjectsID = calloc(1, sizeof(oid) * sizeof(2));      /* 0.0 */
            StorageNew->mteObjectsIDLen = 2;
            StorageNew->mteObjectsIDWildcard = MTEOBJECTSIDWILDCARD_FALSE;

            StorageNew->mteObjectsEntryStatus = set_value;
            /*
             * XXX: free, zero vars, no longer needed? 
             */
        }


        break;




    case FREE:
        /*
         * XXX: free, zero vars 
         */
        /*
         * Release any resources that have been allocated 
         */
        break;




    case ACTION:
        /*
         * The variable has been stored in set_value for you to
         * use, and you have just been asked to do something with
         * it.  Note that anything done here must be reversable in
         * the UNDO case 
         */


        if (StorageTmp == NULL) {
            /*
             * row creation, so add it 
             */
            if (StorageNew != NULL)
                mteObjectsTable_add(StorageNew);
            /*
             * XXX: ack, and if it is NULL? 
             */
        } else if (set_value != RS_DESTROY) {
            /*
             * set the flag? 
             */
            old_value = StorageTmp->mteObjectsEntryStatus;
            StorageTmp->mteObjectsEntryStatus = *((long *) var_val);
        } else {
            /*
             * destroy...  extract it for now 
             */
            hciptr =
                header_complex_find_entry(mteObjectsTableStorage,
                                          StorageTmp);
            StorageDel =
                header_complex_extract_entry(&mteObjectsTableStorage,
                                             hciptr);
        }
        break;




    case UNDO:
        /*
         * Back out any changes made in the ACTION case 
         */
        if (StorageTmp == NULL) {
            /*
             * row creation, so remove it again 
             */
            hciptr =
                header_complex_find_entry(mteObjectsTableStorage,
                                          StorageTmp);
            StorageDel =
                header_complex_extract_entry(&mteObjectsTableStorage,
                                             hciptr);
            /*
             * XXX: free it 
             */
        } else if (StorageDel != NULL) {
            /*
             * row deletion, so add it again 
             */
            mteObjectsTable_add(StorageDel);
        } else {
            StorageTmp->mteObjectsEntryStatus = old_value;
        }
        break;




    case COMMIT:
        /*
         * Things are working well, so it's now safe to make the change
         * permanently.  Make sure that anything done here can't fail! 
         */
        if (StorageDel != NULL) {
            StorageDel = 0;
            /*
             * XXX: free it, its dead 
             */
        } else {
            if (StorageTmp
                && StorageTmp->mteObjectsEntryStatus == RS_CREATEANDGO) {
                StorageTmp->mteObjectsEntryStatus = RS_ACTIVE;
            } else if (StorageTmp &&
                       StorageTmp->mteObjectsEntryStatus ==
                       RS_CREATEANDWAIT) {
                StorageTmp->mteObjectsEntryStatus = RS_NOTINSERVICE;
            }
        }
        snmp_store_needed(NULL);

        break;
    }
    return SNMP_ERR_NOERROR;
}
int
write_snmpNotifyFilterMask(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)
{
    static char    *tmpvar;
    struct snmpNotifyFilterTable_data *StorageTmp = NULL;
    static size_t   tmplen;
    size_t          newlen =
        name_len -
        (sizeof(snmpNotifyFilterTable_variables_oid) / sizeof(oid) + 3 -
         1);

    DEBUGMSGTL(("snmpNotifyFilterTable",
                "write_snmpNotifyFilterMask entering action=%d...  \n",
                action));
    if ((StorageTmp = (struct snmpNotifyFilterTable_data *)
         header_complex((struct header_complex_index *)
                        snmpNotifyFilterTableStorage, NULL,
                        &name[sizeof(snmpNotifyFilterTable_variables_oid) /
                              sizeof(oid) + 3 - 1], &newlen, 1, NULL,
                        NULL)) == NULL)
        return SNMP_ERR_NOSUCHNAME;     /* remove if you support creation here */


    switch (action) {
    case RESERVE1:
        if (var_val_type != ASN_OCTET_STR) {
            fprintf(stderr,
                    "write to snmpNotifyFilterMask not ASN_OCTET_STR\n");
            return SNMP_ERR_WRONGTYPE;
        }
        break;


    case RESERVE2:
        /*
         * memory reseveration, final preparation... 
         */
        break;


    case FREE:
        /*
         * Release any resources that have been allocated 
         */
        break;


    case ACTION:
        /*
         * The variable has been stored in string for
         * you to use, and you have just been asked to do something with
         * it.  Note that anything done here must be reversable in the UNDO case 
         */
        tmpvar = StorageTmp->snmpNotifyFilterMask;
        tmplen = StorageTmp->snmpNotifyFilterMaskLen;
        memdup((u_char **) & StorageTmp->snmpNotifyFilterMask, var_val,
               var_val_len);
        StorageTmp->snmpNotifyFilterMaskLen = var_val_len;
        break;


    case UNDO:
        /*
         * Back out any changes made in the ACTION case 
         */
        SNMP_FREE(StorageTmp->snmpNotifyFilterMask);
        StorageTmp->snmpNotifyFilterMask = tmpvar;
        StorageTmp->snmpNotifyFilterMaskLen = tmplen;
        break;


    case COMMIT:
        /*
         * Things are working well, so it's now safe to make the change
         * permanently.  Make sure that anything done here can't fail! 
         */
        SNMP_FREE(tmpvar);
        break;
    }
    return SNMP_ERR_NOERROR;
}
Exemple #9
0
/*
 * var_mteObjectsTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_mteObjectsTable above.
 */
unsigned char  *
var_mteObjectsTable(struct variable *vp,
                    oid * name,
                    size_t * length,
                    int exact,
                    size_t * var_len, WriteMethod ** write_method)
{


    struct mteObjectsTable_data *StorageTmp = NULL;


    DEBUGMSGTL(("mteObjectsTable",
                "var_mteObjectsTable: Entering...  \n"));

	/* set default value */
	*write_method = NULL;

    /*
     * this assumes you have registered all your data properly
     */
    if ((StorageTmp =
         header_complex(mteObjectsTableStorage, vp, name, length, exact,
                        var_len, write_method)) == NULL) {
        if (vp->magic == MTEOBJECTSENTRYSTATUS)
            *write_method = write_mteObjectsEntryStatus;
        return NULL;
    }

    /*
     * this is where we do the value assignments for the mib results.
     */
    switch (vp->magic) {


    case MTEOBJECTSID:
#ifndef NETSNMP_NO_WRITE_SUPPORT
        *write_method = write_mteObjectsID;
#endif /* !NETSNMP_NO_WRITE_SUPPORT */
        *var_len = (StorageTmp->mteObjectsIDLen) * sizeof(oid);
        return (u_char *) StorageTmp->mteObjectsID;

    case MTEOBJECTSIDWILDCARD:
#ifndef NETSNMP_NO_WRITE_SUPPORT
        *write_method = write_mteObjectsIDWildcard;
#endif /* !NETSNMP_NO_WRITE_SUPPORT */
        *var_len = sizeof(StorageTmp->mteObjectsIDWildcard);
        return (u_char *) & StorageTmp->mteObjectsIDWildcard;

    case MTEOBJECTSENTRYSTATUS:
#ifndef NETSNMP_NO_WRITE_SUPPORT
        *write_method = write_mteObjectsEntryStatus;
#endif /* !NETSNMP_NO_WRITE_SUPPORT */
        *var_len = sizeof(StorageTmp->mteObjectsEntryStatus);
        return (u_char *) & StorageTmp->mteObjectsEntryStatus;


    default:
        ERROR_MSG("");
    }
    return NULL;
}
Exemple #10
0
int
write_mteObjectsID(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)
{
    static oid     *tmpvar;
    struct mteObjectsTable_data *StorageTmp = NULL;
    static size_t   tmplen;
    size_t          newlen =
        name_len - (sizeof(mteObjectsTable_variables_oid) / sizeof(oid) +
                    3 - 1);


    DEBUGMSGTL(("mteObjectsTable",
                "write_mteObjectsID entering action=%d...  \n", action));
    if ((StorageTmp =
         header_complex(mteObjectsTableStorage, NULL,
                        &name[sizeof(mteObjectsTable_variables_oid) /
                              sizeof(oid) + 3 - 1], &newlen, 1, NULL,
                        NULL)) == NULL)
        return SNMP_ERR_NOSUCHNAME;     /* remove if you support creation here */

    if (StorageTmp && StorageTmp->storagetype == ST_READONLY) {
        return SNMP_ERR_NOTWRITABLE;
    }

    switch (action) {
    case RESERVE1:
        if (var_val_type != ASN_OBJECT_ID) {
            snmp_log(LOG_ERR, "write to mteObjectsID not ASN_OBJECT_ID\n");
            return SNMP_ERR_WRONGTYPE;
        }
        break;


    case RESERVE2:
        /*
         * memory reseveration, final preparation... 
         */
        break;


    case FREE:
        /*
         * Release any resources that have been allocated 
         */
        break;


    case ACTION:
        /*
         * The variable has been stored in objid for
         * you to use, and you have just been asked to do something with
         * it.  Note that anything done here must be reversable in the UNDO case 
         */
        tmpvar = StorageTmp->mteObjectsID;
        tmplen = StorageTmp->mteObjectsIDLen;
        memdup((u_char **) & StorageTmp->mteObjectsID, var_val,
               var_val_len);
        StorageTmp->mteObjectsIDLen = var_val_len / sizeof(oid);
        break;


    case UNDO:
        /*
         * Back out any changes made in the ACTION case 
         */
        SNMP_FREE(StorageTmp->mteObjectsID);
        StorageTmp->mteObjectsID = tmpvar;
        StorageTmp->mteObjectsIDLen = tmplen;
        break;


    case COMMIT:
        /*
         * Things are working well, so it's now safe to make the change
         * permanently.  Make sure that anything done here can't fail! 
         */
        SNMP_FREE(tmpvar);

        snmp_store_needed(NULL);

        break;
    }
    return SNMP_ERR_NOERROR;
}
/*
 * var_mteTriggerDeltaTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_mteTriggerDeltaTable above.
 */
unsigned char  *
var_mteTriggerDeltaTable(struct variable *vp,
                         oid * name,
                         size_t * length,
                         int exact,
                         size_t * var_len, WriteMethod ** write_method)
{


    struct mteTriggerTable_data *StorageTmp = NULL;


    DEBUGMSGTL(("mteTriggerDeltaTable",
                "var_mteTriggerDeltaTable: Entering...  \n"));

    /* set default value */
	*write_method = NULL;

    /*
     * this assumes you have registered all your data properly
     */
    if ((StorageTmp =
         header_complex(mteTriggerTableStorage, vp, name, length, exact,
                        var_len, write_method)) == NULL)
        return NULL;

    /*
     * this is where we do the value assignments for the mib results.
     */
    switch (vp->magic) {


    case MTETRIGGERDELTADISCONTINUITYID:
#ifndef NETSNMP_NO_WRITE_SUPPORT
        *write_method = write_mteTriggerDeltaDiscontinuityID;
#endif /* !NETSNMP_NO_WRITE_SUPPORT */
        *var_len =
            StorageTmp->mteTriggerDeltaDiscontinuityIDLen * sizeof(oid);
        return (u_char *) StorageTmp->mteTriggerDeltaDiscontinuityID;

    case MTETRIGGERDELTADISCONTINUITYIDWILDCARD:
#ifndef NETSNMP_NO_WRITE_SUPPORT
        *write_method = write_mteTriggerDeltaDiscontinuityIDWildcard;
#endif /* !NETSNMP_NO_WRITE_SUPPORT */
        *var_len =
            sizeof(StorageTmp->mteTriggerDeltaDiscontinuityIDWildcard);
        return (u_char *) & StorageTmp->
            mteTriggerDeltaDiscontinuityIDWildcard;

    case MTETRIGGERDELTADISCONTINUITYIDTYPE:
#ifndef NETSNMP_NO_WRITE_SUPPORT
        *write_method = write_mteTriggerDeltaDiscontinuityIDType;
#endif /* !NETSNMP_NO_WRITE_SUPPORT */
        *var_len = sizeof(StorageTmp->mteTriggerDeltaDiscontinuityIDType);
        return (u_char *) & StorageTmp->mteTriggerDeltaDiscontinuityIDType;

    default:
        ERROR_MSG("");
    }
    return NULL;
}
int
write_snmpNotifyFilterProfileRowStatus(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 snmpNotifyFilterProfileTable_data *StorageTmp = NULL;
    static struct snmpNotifyFilterProfileTable_data *StorageDel;
    size_t          newlen =
        name_len -
        (sizeof(snmpNotifyFilterProfileTable_variables_oid) / sizeof(oid) +
         3 - 1);
    static int      old_value;
    int             set_value = *((long *) var_val);
    netsnmp_variable_list *vars;
    struct header_complex_index *hciptr;


    DEBUGMSGTL(("snmpNotifyFilterProfileTable",
                "write_snmpNotifyFilterProfileRowStatus entering action=%d...  \n",
                action));
    StorageTmp = (struct snmpNotifyFilterProfileTable_data *)
        header_complex((struct header_complex_index *)
                       snmpNotifyFilterProfileTableStorage, NULL,
                       &name[sizeof
                             (snmpNotifyFilterProfileTable_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;
        }
        /*
         * stage one: test validity 
         */
        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;
            }
            if ((set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE) &&
                StorageTmp->snmpNotifyFilterProfileNameLen == 0) {
                /*
                 * can't activate row without a profile name
                 */
                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);

            if (header_complex_parse_oid
                (&
                 (name
                  [sizeof(snmpNotifyFilterProfileTable_variables_oid) /
                   sizeof(oid) + 2]), newlen, vars) != SNMPERR_SUCCESS) {
                snmp_free_var(vars);
                return SNMP_ERR_INCONSISTENTNAME;
            }

            StorageNew =
                SNMP_MALLOC_STRUCT(snmpNotifyFilterProfileTable_data);
            if (StorageNew == NULL)
                return SNMP_ERR_GENERR;
            memdup((u_char **) & (StorageNew->snmpTargetParamsName),
                   vars->val.string, vars->val_len);
            StorageNew->snmpTargetParamsNameLen = vars->val_len;
            StorageNew->snmpNotifyFilterProfileStorType = ST_NONVOLATILE;

            StorageNew->snmpNotifyFilterProfileRowStatus = RS_NOTREADY;
            snmp_free_var(vars);
        }


        break;

    case RESERVE2:
        break;

    case FREE:
        /*
         * XXX: free, zero vars 
         */
        /*
         * Release any resources that have been allocated 
         */
        if (StorageNew != NULL) {
            SNMP_FREE(StorageNew->snmpTargetParamsName);
            SNMP_FREE(StorageNew->snmpNotifyFilterProfileName);
            free(StorageNew);
            StorageNew = NULL;
        }
        break;




    case ACTION:
        /*
         * The variable has been stored in set_value for you to
         * use, and you have just been asked to do something with
         * it.  Note that anything done here must be reversable in
         * the UNDO case 
         */

        if (StorageTmp == NULL &&
            (set_value == RS_CREATEANDGO ||
             set_value == RS_CREATEANDWAIT)) {
            /*
             * row creation, so add it 
             */
            if (StorageNew != NULL)
                snmpNotifyFilterProfileTable_add(StorageNew);
            /*
             * XXX: ack, and if it is NULL? 
             */
        } else if (set_value != RS_DESTROY) {
            /*
             * set the flag? 
             */
            if (StorageTmp == NULL)
                return SNMP_ERR_GENERR; /* should never ever get here */
            
            old_value = StorageTmp->snmpNotifyFilterProfileRowStatus;
            StorageTmp->snmpNotifyFilterProfileRowStatus =
                *((long *) var_val);
        } else {
            /*
             * destroy...  extract it for now 
             */
            if (StorageTmp) {
                hciptr =
                    header_complex_find_entry
                    (snmpNotifyFilterProfileTableStorage, StorageTmp);
                StorageDel = (struct snmpNotifyFilterProfileTable_data *)
                    header_complex_extract_entry((struct
                                                  header_complex_index **)
                                                 &snmpNotifyFilterProfileTableStorage,
                                                 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
                (snmpNotifyFilterProfileTableStorage, StorageNew);
            StorageDel = (struct snmpNotifyFilterProfileTable_data *)
                header_complex_extract_entry((struct header_complex_index
                                              **)
                                             &snmpNotifyFilterProfileTableStorage,
                                             hciptr);
            /*
             * XXX: free it 
             */
        } else if (StorageDel != NULL) {
            /*
             * row deletion, so add it again 
             */
            snmpNotifyFilterProfileTable_add(StorageDel);
            StorageDel = NULL;
        } else if (set_value != RS_DESTROY) {
            if (StorageTmp)
                StorageTmp->snmpNotifyFilterProfileRowStatus = old_value;
        }
        break;




    case COMMIT:
        /*
         * Things are working well, so it's now safe to make the change
         * permanently.  Make sure that anything done here can't fail! 
         */
        if (StorageDel != NULL) {
            SNMP_FREE(StorageDel->snmpTargetParamsName);
            SNMP_FREE(StorageDel->snmpNotifyFilterProfileName);
            free(StorageDel);
            StorageDel = NULL;
        }
        if (StorageTmp && set_value == RS_CREATEANDGO) {
            if (StorageTmp->snmpNotifyFilterProfileNameLen)
                StorageTmp->snmpNotifyFilterProfileRowStatus = RS_ACTIVE;
            StorageNew = NULL;
        } else if (StorageTmp && set_value == RS_CREATEANDWAIT) {
            if (StorageTmp->snmpNotifyFilterProfileNameLen)
                StorageTmp->snmpNotifyFilterProfileRowStatus = RS_NOTINSERVICE;
            StorageNew = NULL;
        }
        break;
    }
    return SNMP_ERR_NOERROR;
}
int
write_snmpNotifyFilterProfileStorType(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)
{
    static int      tmpvar;
    long            value = *((long *) var_val);
    struct snmpNotifyFilterProfileTable_data *StorageTmp = NULL;
    size_t          newlen =
        name_len -
        (sizeof(snmpNotifyFilterProfileTable_variables_oid) / sizeof(oid) +
         3 - 1);


    DEBUGMSGTL(("snmpNotifyFilterProfileTable",
                "write_snmpNotifyFilterProfileStorType entering action=%d...  \n",
                action));
    if (action != RESERVE1 &&
        (StorageTmp = (struct snmpNotifyFilterProfileTable_data *)
         header_complex((struct header_complex_index *)
                        snmpNotifyFilterProfileTableStorage, NULL,
                        &name[sizeof
                              (snmpNotifyFilterProfileTable_variables_oid)
                              / sizeof(oid) + 3 - 1], &newlen, 1, NULL,
                        NULL)) == NULL) {
        if ((StorageTmp = StorageNew) == NULL)
            return SNMP_ERR_NOSUCHNAME;     /* remove if you support creation here */
    }

    switch (action) {
    case RESERVE1:
        if (var_val_type != ASN_INTEGER) {
            return SNMP_ERR_WRONGTYPE;
        }
        if (var_val_len != sizeof(long)) {
            return SNMP_ERR_WRONGLENGTH;
        }
        if (value != SNMP_STORAGE_OTHER && value != SNMP_STORAGE_VOLATILE
            && value != SNMP_STORAGE_NONVOLATILE) {
            return SNMP_ERR_WRONGVALUE;
        }
        break;


    case RESERVE2:
        /*
         * memory reseveration, final preparation... 
         */
        break;


    case FREE:
        /*
         * Release any resources that have been allocated 
         */
        break;


    case ACTION:
        /*
         * The variable has been stored in long_ret for
         * you to use, and you have just been asked to do something with
         * it.  Note that anything done here must be reversable in the UNDO case 
         */
        tmpvar = StorageTmp->snmpNotifyFilterProfileStorType;
        StorageTmp->snmpNotifyFilterProfileStorType = *((long *) var_val);
        break;


    case UNDO:
        /*
         * Back out any changes made in the ACTION case 
         */
        StorageTmp->snmpNotifyFilterProfileStorType = tmpvar;
        break;


    case COMMIT:
        /*
         * Things are working well, so it's now safe to make the change
         * permanently.  Make sure that anything done here can't fail! 
         */

        break;
    }
    return SNMP_ERR_NOERROR;
}
int
write_expExpressionEntryStatus(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 expExpressionTable_data *StorageTmp = NULL;
    static struct expExpressionTable_data *StorageNew, *StorageDel;
    size_t          newlen =
        name_len -
        (sizeof(expExpressionTable_variables_oid) / sizeof(oid) + 3 - 1);
    static int      old_value;
    int             set_value;
    static netsnmp_variable_list *vars, *vp;
    struct header_complex_index *hciptr;

    StorageTmp =
        header_complex(expExpressionTableStorage, NULL,
                       &name[sizeof(expExpressionTable_variables_oid) /
                             sizeof(oid) + 3 - 1], &newlen, 1, NULL, NULL);




    if (var_val_type != ASN_INTEGER || var_val == NULL) {
        snmp_log(LOG_ERR,
                 "write to expExpressionEntryStatus not ASN_INTEGER\n");
        return SNMP_ERR_WRONGTYPE;
    }
    set_value = *((long *) var_val);


    /*
     * check legal range, and notReady is reserved for us, not a user 
     */
    if (set_value < 1 || set_value > 6 || set_value == RS_NOTREADY)
        return SNMP_ERR_INCONSISTENTVALUE;


    switch (action) {
    case RESERVE1:
        /*
         * stage one: test validity 
         */
        if (StorageTmp == NULL) {
            /*
             * create the row now? 
             */


            /*
             * ditch illegal values now 
             */
            if (set_value == RS_ACTIVE || set_value == RS_NOTINSERVICE)
                return SNMP_ERR_INCONSISTENTVALUE;


            /*
             * destroying a non-existent row is actually legal 
             */
            if (set_value == RS_DESTROY) {
                return SNMP_ERR_NOERROR;
            }


            /*
             * illegal creation values 
             */
            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;
            }

            if (StorageTmp->expExpressionEntryStatus == RS_ACTIVE &&
                set_value != RS_DESTROY) {
                /*
                 * "Once made active an entry may not be modified except to 
                 * delete it."  XXX: doesn't this in fact apply to ALL
                 * columns of the table and not just this one?  
                 */
                return SNMP_ERR_INCONSISTENTVALUE;
            }
            if (StorageTmp->storageType != ST_NONVOLATILE)
                return SNMP_ERR_NOTWRITABLE;
        }
        break;




    case RESERVE2:
        /*
         * memory reseveration, final preparation... 
         */
        if (StorageTmp == NULL) {
            /*
             * creation 
             */
            vars = NULL;


            snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, NULL, 0);  /* expExpressionOwner */
            snmp_varlist_add_variable(&vars, NULL, 0, ASN_OCTET_STR, NULL, 0);  /* expExpressionName */



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


            StorageNew = create_expExpressionTable_data();

            StorageNew->expExpressionOwner = malloc(vp->val_len + 1);
            memcpy(StorageNew->expExpressionOwner, vp->val.string,
                   vp->val_len);
            StorageNew->expExpressionOwner[vp->val_len] = '\0';
            StorageNew->expExpressionOwnerLen = vp->val_len;

            vp = vp->next_variable;
            StorageNew->expExpressionName = malloc(vp->val_len + 1);
            memcpy(StorageNew->expExpressionName, vp->val.string,
                   vp->val_len);
            StorageNew->expExpressionName[vp->val_len] = '\0';
            StorageNew->expExpressionNameLen = vp->val_len;

            vp = vp->next_variable;

            StorageNew->expExpressionEntryStatus = set_value;

        }


        break;




    case FREE:
        /*
         * XXX: free, zero vars 
         */
        /*
         * Release any resources that have been allocated 
         */
        break;




    case ACTION:
        /*
         * The variable has been stored in set_value for you to
         * use, and you have just been asked to do something with
         * it.  Note that anything done here must be reversable in
         * the UNDO case 
         */


        if (StorageTmp == NULL) {
            /*
             * row creation, so add it 
             */
            if (StorageNew != NULL)
                expExpressionTable_add(StorageNew);
            /*
             * XXX: ack, and if it is NULL? 
             */
        } else if (set_value != RS_DESTROY) {
            /*
             * set the flag? 
             */
            old_value = StorageTmp->expExpressionEntryStatus;
            StorageTmp->expExpressionEntryStatus = *((long *) var_val);
        } else {
            /*
             * destroy...  extract it for now 
             */
            hciptr =
                header_complex_find_entry(expExpressionTableStorage,
                                          StorageTmp);
            StorageDel =
                header_complex_extract_entry(&expExpressionTableStorage,
                                             hciptr);
        }
        break;




    case UNDO:
        /*
         * Back out any changes made in the ACTION case 
         */
        if (StorageTmp == NULL) {
            /*
             * row creation, so remove it again 
             */
            hciptr =
                header_complex_find_entry(expExpressionTableStorage,
                                          StorageTmp);
            StorageDel =
                header_complex_extract_entry(&expExpressionTableStorage,
                                             hciptr);
            /*
             * XXX: free it 
             */
        } else if (StorageDel != NULL) {
            /*
             * row deletion, so add it again 
             */
            expExpressionTable_add(StorageDel);
        } else {
            StorageTmp->expExpressionEntryStatus = old_value;
        }
        break;




    case COMMIT:
        /*
         * Things are working well, so it's now safe to make the change
         * permanently.  Make sure that anything done here can't fail! 
         */
        if (StorageDel != NULL) {
            StorageDel = 0;
            /*
             * XXX: free it, its dead 
             */
        } else {
            if (StorageTmp
                && StorageTmp->expExpressionEntryStatus ==
                RS_CREATEANDGO) {
                StorageTmp->expExpressionEntryStatus = RS_ACTIVE;
            } else if (StorageTmp &&
                       StorageTmp->expExpressionEntryStatus ==
                       RS_CREATEANDWAIT) {
                StorageTmp->expExpressionEntryStatus = RS_NOTINSERVICE;
            }
        }
        if (StorageTmp &&
            StorageTmp->expExpressionEntryStatus == RS_ACTIVE &&
            !StorageTmp->have_copied_auth_info) {

            netsnmp_agent_session *asp =
                netsnmp_get_current_agent_session();
            netsnmp_pdu    *pdu = NULL;

            if (!asp) {
                snmp_log(LOG_ERR,
                         "snmpTriggerTable: can't get master session for authentication params\n");
            } else {
                pdu = asp->orig_pdu;
                if (!pdu) {
                    snmp_log(LOG_ERR,
                             "snmpTriggerTable: can't get master pdu for authentication params\n");
                }
            }

            if (pdu) {
                DEBUGMSGTL(("expExpressionTest",
                            "copying PDU auth info\n"));
                StorageTmp->pdu_version = pdu->version;
                StorageTmp->pdu_securityModel = pdu->securityModel;
                StorageTmp->pdu_securityLevel = pdu->securityLevel;
                StorageTmp->pdu_tDomain = pdu->tDomain;
                StorageTmp->pdu_tDomainLen = pdu->tDomainLen;
                if (pdu->transport_data != NULL) {
                    StorageTmp->pdu_transport =
                        malloc(pdu->transport_data_length);
                    memcpy(StorageTmp->pdu_transport, pdu->transport_data,
                           pdu->transport_data_length);
                }
                StorageTmp->pdu_transportLen = pdu->transport_data_length;
                if (pdu->community) {
                    StorageTmp->pdu_community =
                        calloc(1, pdu->community_len + 1);
                    memcpy(StorageTmp->pdu_community, pdu->community,
                           pdu->community_len);
                    StorageTmp->pdu_community_len = pdu->community_len;
                } else {
                    StorageTmp->pdu_community = NULL;
                    StorageTmp->pdu_community_len = 0;
                }
                if (pdu->securityName) {
                    StorageTmp->pdu_securityName =
                        calloc(1, pdu->securityNameLen + 1);
                    memcpy(StorageTmp->pdu_securityName, pdu->securityName,
                           pdu->securityNameLen);
                    StorageTmp->pdu_securityNameLen = pdu->securityNameLen;
                } else {
                    StorageTmp->pdu_securityName = NULL;
                    StorageTmp->pdu_securityNameLen = 0;
                }
                StorageTmp->have_copied_auth_info = 1;
            }
        }
        snmp_store_needed(NULL);
        break;
    }
    return SNMP_ERR_NOERROR;
}
/*
 * var_traceRouteHopsTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_traceRouteHopsTable above.
 */
unsigned char  *
var_traceRouteHopsTable(struct variable *vp,
                        oid * name,
                        size_t *length,
                        int exact,
                        size_t *var_len, WriteMethod ** write_method)
{


    struct traceRouteHopsTable_data *StorageTmp = NULL;

    *write_method = NULL;
    /*
     * this assumes you have registered all your data properly
     */
    if ((StorageTmp =
         header_complex(traceRouteHopsTableStorage, vp, name, length,
                        exact, var_len, write_method)) == NULL) {
        return NULL;
    }

    /*
     * this is where we do the value assignments for the mib results.
     */

    switch (vp->magic) {

    case COLUMN_TRACEROUTEHOPSIPTGTADDRESSTYPE:
        *var_len = sizeof(StorageTmp->traceRouteHopsIpTgtAddressType);
        return (u_char *) & StorageTmp->traceRouteHopsIpTgtAddressType;

    case COLUMN_TRACEROUTEHOPSIPTGTADDRESS:
        *var_len = (StorageTmp->traceRouteHopsIpTgtAddressLen);
        return (u_char *) StorageTmp->traceRouteHopsIpTgtAddress;

    case COLUMN_TRACEROUTEHOPSMINRTT:
        *var_len = sizeof(StorageTmp->traceRouteHopsMinRtt);
        return (u_char *) & StorageTmp->traceRouteHopsMinRtt;

    case COLUMN_TRACEROUTEHOPSMAXRTT:
        *var_len = sizeof(StorageTmp->traceRouteHopsMaxRtt);
        return (u_char *) & StorageTmp->traceRouteHopsMaxRtt;

    case COLUMN_TRACEROUTEHOPSAVERAGERTT:
        *var_len = sizeof(StorageTmp->traceRouteHopsAverageRtt);
        return (u_char *) & StorageTmp->traceRouteHopsAverageRtt;

    case COLUMN_TRACEROUTEHOPSRTTSUMOFSQUARES:
        *var_len = sizeof(StorageTmp->traceRouteHopsRttSumOfSquares);
        return (u_char *) & StorageTmp->traceRouteHopsRttSumOfSquares;

    case COLUMN_TRACEROUTEHOPSSENTPROBES:
        *var_len = sizeof(StorageTmp->traceRouteHopsSentProbes);
        return (u_char *) & StorageTmp->traceRouteHopsSentProbes;

    case COLUMN_TRACEROUTEHOPSPROBERESPONSES:
        *var_len = sizeof(StorageTmp->traceRouteHopsProbeResponses);
        return (u_char *) & StorageTmp->traceRouteHopsProbeResponses;

    case COLUMN_TRACEROUTEHOPSLASTGOODPROBE:
        *var_len = (StorageTmp->traceRouteHopsLastGoodProbeLen);
        return (u_char *) StorageTmp->traceRouteHopsLastGoodProbe;

    default:
        ERROR_MSG("");
    }

    return NULL;
}
/*
 * var_traceRouteResultsTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_traceRouteResultsTable above.
 */
unsigned char  *
var_traceRouteResultsTable(struct variable *vp,
                           oid * name,
                           size_t *length,
                           int exact,
                           size_t *var_len, WriteMethod ** write_method)
{


    struct traceRouteResultsTable_data *StorageTmp = NULL;

    *write_method = NULL;

    /*
     * this assumes you have registered all your data properly
     */
    if ((StorageTmp =
         header_complex(traceRouteResultsTableStorage, vp, name, length,
                        exact, var_len, write_method)) == NULL) {
        return NULL;
    }

    /*
     * this is where we do the value assignments for the mib results.
     */

    switch (vp->magic) {

    case COLUMN_TRACEROUTERESULTSOPERSTATUS:
        *var_len = sizeof(StorageTmp->traceRouteResultsOperStatus);
        return (u_char *) & StorageTmp->traceRouteResultsOperStatus;

    case COLUMN_TRACEROUTERESULTSCURHOPCOUNT:
        *var_len = sizeof(StorageTmp->traceRouteResultsCurHopCount);
        return (u_char *) & StorageTmp->traceRouteResultsCurHopCount;

    case COLUMN_TRACEROUTERESULTSCURPROBECOUNT:
        *var_len = sizeof(StorageTmp->traceRouteResultsCurProbeCount);
        return (u_char *) & StorageTmp->traceRouteResultsCurProbeCount;

    case COLUMN_TRACEROUTERESULTSIPTGTADDRTYPE:
        *var_len = sizeof(StorageTmp->traceRouteResultsIpTgtAddrType);
        return (u_char *) & StorageTmp->traceRouteResultsIpTgtAddrType;

    case COLUMN_TRACEROUTERESULTSIPTGTADDR:
        *var_len = (StorageTmp->traceRouteResultsIpTgtAddrLen);
        return (u_char *) StorageTmp->traceRouteResultsIpTgtAddr;

    case COLUMN_TRACEROUTERESULTSTESTATTEMPTS:
        *var_len = sizeof(StorageTmp->traceRouteResultsTestAttempts);
        return (u_char *) & StorageTmp->traceRouteResultsTestAttempts;

    case COLUMN_TRACEROUTERESULTSTESTSUCCESSES:
        *var_len = sizeof(StorageTmp->traceRouteResultsTestSuccesses);
        return (u_char *) & StorageTmp->traceRouteResultsTestSuccesses;

    case COLUMN_TRACEROUTERESULTSLASTGOODPATH:
        *var_len = (StorageTmp->traceRouteResultsLastGoodPathLen);
        return (u_char *) StorageTmp->traceRouteResultsLastGoodPath;

    default:
        ERROR_MSG("");
    }

    return NULL;
}
Exemple #17
0
/*
 * var_mteTriggerBooleanTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_mteTriggerBooleanTable above.
 */
unsigned char *var_mteTriggerBooleanTable (struct variable *vp,
                                           oid * name,
                                           size_t * length, int exact, size_t * var_len, WriteMethod ** write_method)
{


    struct mteTriggerTable_data *StorageTmp = NULL;


    DEBUGMSGTL (("mteTriggerBooleanTable", "var_mteTriggerBooleanTable: Entering...  \n"));

    /* set default value */
    *write_method = NULL;

    /*
     * this assumes you have registered all your data properly
     */
    if ((StorageTmp = header_complex (mteTriggerTableStorage, vp, name, length, exact, var_len, write_method)) == NULL)
        return NULL;

    if (!(StorageTmp->mteTriggerTest[0] & MTETRIGGERTEST_BOOLEAN))
        return NULL;

    /*
     * this is where we do the value assignments for the mib results.
     */
    switch (vp->magic)
    {


        case MTETRIGGERBOOLEANCOMPARISON:
#ifndef NETSNMP_NO_WRITE_SUPPORT
            *write_method = write_mteTriggerBooleanComparison;
#endif                            /* !NETSNMP_NO_WRITE_SUPPORT */
            *var_len = sizeof (StorageTmp->mteTriggerBooleanComparison);
            return (u_char *) & StorageTmp->mteTriggerBooleanComparison;

        case MTETRIGGERBOOLEANVALUE:
#ifndef NETSNMP_NO_WRITE_SUPPORT
            *write_method = write_mteTriggerBooleanValue;
#endif                            /* !NETSNMP_NO_WRITE_SUPPORT */
            *var_len = sizeof (StorageTmp->mteTriggerBooleanValue);
            return (u_char *) & StorageTmp->mteTriggerBooleanValue;

        case MTETRIGGERBOOLEANSTARTUP:
#ifndef NETSNMP_NO_WRITE_SUPPORT
            *write_method = write_mteTriggerBooleanStartup;
#endif                            /* !NETSNMP_NO_WRITE_SUPPORT */
            *var_len = sizeof (StorageTmp->mteTriggerBooleanStartup);
            return (u_char *) & StorageTmp->mteTriggerBooleanStartup;

        case MTETRIGGERBOOLEANOBJECTSOWNER:
#ifndef NETSNMP_NO_WRITE_SUPPORT
            *write_method = write_mteTriggerBooleanObjectsOwner;
#endif                            /* !NETSNMP_NO_WRITE_SUPPORT */
            *var_len = StorageTmp->mteTriggerBooleanObjectsOwnerLen;
            return (u_char *) StorageTmp->mteTriggerBooleanObjectsOwner;

        case MTETRIGGERBOOLEANOBJECTS:
#ifndef NETSNMP_NO_WRITE_SUPPORT
            *write_method = write_mteTriggerBooleanObjects;
#endif                            /* !NETSNMP_NO_WRITE_SUPPORT */
            *var_len = StorageTmp->mteTriggerBooleanObjectsLen;
            return (u_char *) StorageTmp->mteTriggerBooleanObjects;

        case MTETRIGGERBOOLEANEVENTOWNER:
#ifndef NETSNMP_NO_WRITE_SUPPORT
            *write_method = write_mteTriggerBooleanEventOwner;
#endif                            /* !NETSNMP_NO_WRITE_SUPPORT */
            *var_len = StorageTmp->mteTriggerBooleanEventOwnerLen;
            return (u_char *) StorageTmp->mteTriggerBooleanEventOwner;

        case MTETRIGGERBOOLEANEVENT:
#ifndef NETSNMP_NO_WRITE_SUPPORT
            *write_method = write_mteTriggerBooleanEvent;
#endif                            /* !NETSNMP_NO_WRITE_SUPPORT */
            *var_len = StorageTmp->mteTriggerBooleanEventLen;
            return (u_char *) StorageTmp->mteTriggerBooleanEvent;


        default:
            ERROR_MSG ("");
    }
    return NULL;
}
int
write_snmpNotifyFilterRowStatus(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 snmpNotifyFilterTable_data *StorageTmp = NULL;
    static struct snmpNotifyFilterTable_data *StorageNew, *StorageDel;
    size_t          newlen =
        name_len -
        (sizeof(snmpNotifyFilterTable_variables_oid) / sizeof(oid) + 3 -
         1);
    static int      old_value;
    int             set_value;
    static netsnmp_variable_list *vars, *vp;
    struct header_complex_index *hciptr;


    StorageTmp = (struct snmpNotifyFilterTable_data *)
        header_complex((struct header_complex_index *)
                       snmpNotifyFilterTableStorage, NULL,
                       &name[sizeof(snmpNotifyFilterTable_variables_oid) /
                             sizeof(oid) + 3 - 1], &newlen, 1, NULL, NULL);




    if (var_val_type != ASN_INTEGER || var_val == NULL) {
        fprintf(stderr,
                "write to snmpNotifyFilterRowStatus not ASN_INTEGER\n");
        return SNMP_ERR_WRONGTYPE;
    }
    set_value = *((long *) var_val);


    /*
     * check legal range, and notReady is reserved for us, not a user 
     */
    if (set_value < 1 || set_value > 6 || set_value == RS_NOTREADY)
        return SNMP_ERR_INCONSISTENTVALUE;


    switch (action) {
    case RESERVE1:
        /*
         * stage one: test validity 
         */
        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 
             */
        }
        break;




    case RESERVE2:
        /*
         * 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_OCTET_STR, NULL, 0);  /* snmpNotifyFilterSubtree */
            snmp_varlist_add_variable(&vars, NULL, 0, ASN_PRIV_IMPLIED_OBJECT_ID, NULL, 0);     /* snmpNotifyFilterSubtree */

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

            StorageNew = SNMP_MALLOC_STRUCT(snmpNotifyFilterTable_data);
            memdup((u_char **) & (StorageNew->snmpNotifyFilterProfileName),
                   (u_char *) vp->val.string, vp->val_len);
            StorageNew->snmpNotifyFilterProfileNameLen = vp->val_len;
            vp = vp->next_variable;
            memdup((u_char **) & (StorageNew->snmpNotifyFilterSubtree),
                   (u_char *) vp->val.objid, vp->val_len);
            StorageNew->snmpNotifyFilterSubtreeLen =
                vp->val_len / sizeof(oid);

            StorageNew->snmpNotifyFilterMask = (char *) calloc(1, 1);
            StorageNew->snmpNotifyFilterMaskLen = 0;
            StorageNew->snmpNotifyFilterType =
                SNMPNOTIFYFILTERTYPE_INCLUDED;
            StorageNew->snmpNotifyFilterStorageType = ST_NONVOLATILE;
            StorageNew->snmpNotifyFilterRowStatus = set_value;
            /*
             * XXX: free, zero vars, no longer needed? 
             */
        }


        break;




    case FREE:
        /*
         * XXX: free, zero vars 
         */
        /*
         * Release any resources that have been allocated 
         */
        break;




    case ACTION:
        /*
         * The variable has been stored in set_value for you to
         * use, and you have just been asked to do something with
         * it.  Note that anything done here must be reversable in
         * the UNDO case 
         */


        if (StorageTmp == NULL &&
            (set_value == RS_CREATEANDGO ||
             set_value == RS_CREATEANDWAIT)) {
            /*
             * row creation, so add it 
             */
            if (StorageNew != NULL)
                snmpNotifyFilterTable_add(StorageNew);
            /*
             * XXX: ack, and if it is NULL? 
             */
        } else if (set_value != RS_DESTROY) {
            /*
             * set the flag? 
             */
            old_value = StorageTmp->snmpNotifyFilterRowStatus;
            StorageTmp->snmpNotifyFilterRowStatus = *((long *) var_val);
        } else {
            /*
             * destroy...  extract it for now 
             */
            if (StorageTmp) {
                hciptr =
                    header_complex_find_entry(snmpNotifyFilterTableStorage,
                                              StorageTmp);
                StorageDel = (struct snmpNotifyFilterTable_data *)
                    header_complex_extract_entry((struct
                                                  header_complex_index **)
                                                 &snmpNotifyFilterTableStorage,
                                                 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(snmpNotifyFilterTableStorage,
                                          StorageNew);
            StorageDel = (struct snmpNotifyFilterTable_data *)
                header_complex_extract_entry((struct header_complex_index
                                              **)
                                             &snmpNotifyFilterTableStorage,
                                             hciptr);
            /*
             * XXX: free it 
             */
        } else if (StorageDel != NULL) {
            /*
             * row deletion, so add it again 
             */
            snmpNotifyFilterTable_add(StorageDel);
            StorageDel = NULL;
        } else if (set_value != RS_DESTROY) {
            StorageTmp->snmpNotifyFilterRowStatus = old_value;
        }
        break;




    case COMMIT:
        /*
         * Things are working well, so it's now safe to make the change
         * permanently.  Make sure that anything done here can't fail! 
         */
        if (StorageDel != NULL) {
            StorageDel = NULL;
            /*
             * XXX: free it, its dead 
             */
        } else {
            if (StorageTmp
                && StorageTmp->snmpNotifyFilterRowStatus ==
                RS_CREATEANDGO) {
                StorageTmp->snmpNotifyFilterRowStatus = RS_ACTIVE;
            } else if (StorageTmp &&
                       StorageTmp->snmpNotifyFilterRowStatus ==
                       RS_CREATEANDWAIT) {
                StorageTmp->snmpNotifyFilterRowStatus = RS_NOTINSERVICE;
            }
        }
        break;
    }
    return SNMP_ERR_NOERROR;
}
Exemple #19
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;
            }
            StorageNew->snmpNotifyName = (char*)calloc( 1, vp->val_len + 1 );
            if (StorageNew->snmpNotifyName == NULL) {
                return SNMP_ERR_RESOURCEUNAVAILABLE;
            }
            memcpy(StorageNew->snmpNotifyName, vp->val.string, vp->val_len);
            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? 
             */
            if (StorageTmp == NULL)
                return SNMP_ERR_GENERR; /* should never ever get here */
            
            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) {
            if (StorageTmp)
                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;
        }
        snmp_store_needed(NULL);
        break;
    }
    return SNMP_ERR_NOERROR;
}
/*
 * var_pingResultsTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_pingResultsTable above.
 */
unsigned char  *
var_pingResultsTable(struct variable *vp,
                     oid * name,
                     size_t *length,
                     int exact,
                     size_t *var_len, WriteMethod ** write_method)
{


    struct pingResultsTable_data *StorageTmp = NULL;

    *write_method = NULL;
    /*
     * this assumes you have registered all your data properly
     */
    if ((StorageTmp =
         header_complex(pingResultsTableStorage, vp, name, length, exact,
                        var_len, write_method)) == NULL) {

        return NULL;
    }

    /*
     * this is where we do the value assignments for the mib results.
     */

    switch (vp->magic) {

    case COLUMN_PINGRESULTSOPERSTATUS:
        *var_len = sizeof(StorageTmp->pingResultsOperStatus);
        return (u_char *) & StorageTmp->pingResultsOperStatus;

    case COLUMN_PINGRESULTSIPTARGETADDRESSTYPE:
        *var_len = sizeof(StorageTmp->pingResultsIpTargetAddressType);
        return (u_char *) & StorageTmp->pingResultsIpTargetAddressType;

    case COLUMN_PINGRESULTSIPTARGETADDRESS:
        *var_len = (StorageTmp->pingResultsIpTargetAddressLen);
        return (u_char *) StorageTmp->pingResultsIpTargetAddress;

    case COLUMN_PINGRESULTSMINRTT:
        *var_len = sizeof(StorageTmp->pingResultsMinRtt);
        return (u_char *) & StorageTmp->pingResultsMinRtt;

    case COLUMN_PINGRESULTSMAXRTT:
        *var_len = sizeof(StorageTmp->pingResultsMaxRtt);
        return (u_char *) & StorageTmp->pingResultsMaxRtt;

    case COLUMN_PINGRESULTSAVERAGERTT:
        *var_len = sizeof(StorageTmp->pingResultsAverageRtt);
        return (u_char *) & StorageTmp->pingResultsAverageRtt;

    case COLUMN_PINGRESULTSPROBERESPONSES:
        *var_len = sizeof(StorageTmp->pingResultsProbeResponses);
        return (u_char *) & StorageTmp->pingResultsProbeResponses;

    case COLUMN_PINGRESULTSSENTPROBES:
        *var_len = sizeof(StorageTmp->pingResultsSendProbes);
        return (u_char *) & StorageTmp->pingResultsSendProbes;

    case COLUMN_PINGRESULTSRTTSUMOFSQUARES:
        *var_len = sizeof(StorageTmp->pingResultsRttSumOfSquares);
        return (u_char *) & StorageTmp->pingResultsRttSumOfSquares;

    case COLUMN_PINGRESULTSLASTGOODPROBE:
        *var_len = (StorageTmp->pingResultsLastGoodProbeLen);
        return (u_char *) StorageTmp->pingResultsLastGoodProbe;

    default:
        ERROR_MSG("");
    }

    return NULL;
}
Exemple #21
0
/*
 * var_snmpNotifyTable():
 *   Handle this table separately from the scalar value case.
 *   The workings of this are basically the same as for var_snmpNotifyTable above.
 */
unsigned char  *
var_snmpNotifyTable(struct variable *vp,
                    oid * name,
                    size_t * length,
                    int exact,
                    size_t * var_len, WriteMethod ** write_method)
{
    struct snmpNotifyTable_data *StorageTmp = NULL;
    int             found = 1;

    DEBUGMSGTL(("snmpNotifyTable",
                "var_snmpNotifyTable: Entering...  \n"));
    /*
     * this assumes you have registered all your data properly
     */
    if ((StorageTmp = (struct snmpNotifyTable_data *)
         header_complex((struct header_complex_index *)
                        snmpNotifyTableStorage, vp, name, length, exact,
                        var_len, write_method)) == NULL) {
        found = 0;
    }

    switch (vp->magic) {
#ifndef NETSNMP_NO_WRITE_SUPPORT
    case SNMPNOTIFYTAG:
        *write_method = write_snmpNotifyTag;
        break;
    case SNMPNOTIFYTYPE:
        *write_method = write_snmpNotifyType;
        break;
    case SNMPNOTIFYSTORAGETYPE:
        *write_method = write_snmpNotifyStorageType;
        break;
    case SNMPNOTIFYROWSTATUS:
        *write_method = write_snmpNotifyRowStatus;
        break;
#endif /* !NETSNMP_NO_WRITE_SUPPORT */
    default:
        *write_method = NULL;
    }

    if (!found) {
        return NULL;
    }

#ifndef NETSNMP_NO_READ_SUPPORT
    switch (vp->magic) {
    case SNMPNOTIFYTAG:
        *var_len = StorageTmp->snmpNotifyTagLen;
        return (u_char *) StorageTmp->snmpNotifyTag;

    case SNMPNOTIFYTYPE:
        *var_len = sizeof(StorageTmp->snmpNotifyType);
        return (u_char *) & StorageTmp->snmpNotifyType;

    case SNMPNOTIFYSTORAGETYPE:
        *var_len = sizeof(StorageTmp->snmpNotifyStorageType);
        return (u_char *) & StorageTmp->snmpNotifyStorageType;

    case SNMPNOTIFYROWSTATUS:
        *var_len = sizeof(StorageTmp->snmpNotifyRowStatus);
        return (u_char *) & StorageTmp->snmpNotifyRowStatus;

    default:
        ERROR_MSG("");
    }
#endif /* !NETSNMP_NO_READ_SUPPORT */ 
    return NULL;
}
int
write_mteTriggerThresholdStartup(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)
{
    static int      tmpvar;
    struct mteTriggerTable_data *StorageTmp = NULL;
    size_t          newlen =
        name_len -
        (sizeof(mteTriggerThresholdTable_variables_oid) / sizeof(oid) + 3 -
         1);


    DEBUGMSGTL(("mteTriggerThresholdTable",
                "write_mteTriggerThresholdStartup entering action=%d...  \n",
                action));
    if ((StorageTmp =
         header_complex(mteTriggerTableStorage, NULL,
                        &name[sizeof
                              (mteTriggerThresholdTable_variables_oid) /
                              sizeof(oid) + 3 - 1], &newlen, 1, NULL,
                        NULL)) == NULL)
        return SNMP_ERR_NOSUCHNAME;     /* remove if you support creation here */


    switch (action) {
    case RESERVE1:
        if (var_val_type != ASN_INTEGER) {
            fprintf(stderr,
                    "write to mteTriggerThresholdStartup not ASN_INTEGER\n");
            return SNMP_ERR_WRONGTYPE;
        }
        if (StorageTmp->storageType != ST_NONVOLATILE)
            return SNMP_ERR_NOTWRITABLE;
        break;


    case RESERVE2:
        /*
         * memory reseveration, final preparation... 
         */
        break;


    case FREE:
        /*
         * Release any resources that have been allocated 
         */
        break;


    case ACTION:
        /*
         * The variable has been stored in long_ret for
         * you to use, and you have just been asked to do something with
         * it.  Note that anything done here must be reversable in the UNDO case 
         */
        tmpvar = StorageTmp->mteTriggerThresholdStartup;
        StorageTmp->mteTriggerThresholdStartup = *((long *) var_val);
        break;


    case UNDO:
        /*
         * Back out any changes made in the ACTION case 
         */
        StorageTmp->mteTriggerThresholdStartup = tmpvar;
        break;


    case COMMIT:
        /*
         * Things are working well, so it's now safe to make the change
         * permanently.  Make sure that anything done here can't fail! 
         */

        break;
    }
    return SNMP_ERR_NOERROR;
}
Exemple #23
0
static unsigned char *var_expValueTable(struct variable *vp, oid * name,
                                        size_t *length, int exact,
                                        size_t *var_len,
                                        WriteMethod ** write_method)
{
    struct expValueTable_data *StorageTmp = NULL;

    DEBUGMSGTL(("expValueTable", "var_expValueTable: Entering...  \n"));

    struct header_complex_index *hciptr, *hciptrn;

    for (hciptr = expValueTableStorage; hciptr; hciptr = hciptr->next) {
        StorageTmp = hciptr->data;
        StorageTmp->set = 0;
    }

    build_valuetable();

    for (hciptr = expValueTableStorage; hciptr; hciptr = hciptrn) {
        hciptrn = hciptr->next;
        StorageTmp = hciptr->data;
        if (!StorageTmp->set)
            header_complex_free_entry(hciptr, expValueTable_clean);
    }

    /*
     * this assumes you have registered all your data properly
     */
    if ((StorageTmp =
         header_complex(expValueTableStorage, vp, name, length, exact,
                        var_len, write_method)) == NULL) {
        DEBUGMSGTL(("expValueTable", "%s: entry not found.\n", __func__));
        return NULL;
    }

    DEBUGMSGTL(("expValueTable", "%s: vp->magic = %d.\n", __func__, vp->magic));


    /*
     * this is where we do the value assignments for the mib results.
     */
    switch (vp->magic) {
        /*
         *   we only support counter32val
         */

    case EXPVALUECOUNTER32VAL:
        StorageTmp->expValueCounter32Val = Evaluate_Expression(StorageTmp);
        *var_len = sizeof(StorageTmp->expValueCounter32Val);
        return (u_char *) & StorageTmp->expValueCounter32Val;

    case EXPVALUEUNSIGNED32VAL:
        /* var_len = sizeof(StorageTmp->expValueUnsigned32Val); */
        /* return (u_char *) & StorageTmp->expValueUnsigned32Val;         */
        return NULL;

    case EXPVALUETIMETICKSVAL:
        /* var_len = sizeof(StorageTmp->expValueTimeTicksVal); */
        /* return (u_char *) & StorageTmp->expValueTimeTicksVal; */
        return NULL;

    case EXPVALUEINTEGER32VAL:
        /* var_len = sizeof(StorageTmp->expValueInteger32Val); */
        /* return (u_char *) & StorageTmp->expValueInteger32Val; */
        return NULL;

    case EXPVALUEIPADDRESSVAL:
        /* var_len = sizeof(StorageTmp->expValueIpAddressVal); */
        /* return (u_char *) & StorageTmp->expValueIpAddressVal; */
        return NULL;

    case EXPVALUEOCTETSTRINGVAL:
        /* var_len = sizeof(StorageTmp->expValueOctetStringVal); */
        /* return (u_char *) & StorageTmp->expValueOctetStringVal;        */
        return NULL;

    case EXPVALUEOIDVAL:
        /* var_len = StorageTmp->expValueOidValLen; */
        /* return (u_char *) & StorageTmp->expValueOidVal; */
        return NULL;

    case EXPVALUECOUNTER64VAL:
        /* var_len = sizeof(StorageTmp->expValueCounter64Val); */
        /* return (u_char *) & StorageTmp->expValueCounter64Val; */
        return NULL;
    default:
        ERROR_MSG("");
	return NULL;
    }
}