Пример #1
0
int
write_dlmodStatus(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)
{
    /*
     * variables we may use later 
     */
    struct dlmod   *dlm;

    if (var_val_type != ASN_INTEGER) {
        snmp_log(LOG_ERR, "write to dlmodStatus not ASN_INTEGER\n");
        return SNMP_ERR_WRONGTYPE;
    }
    if (var_val_len > sizeof(long)) {
        snmp_log(LOG_ERR, "write to dlmodStatus: bad length\n");
        return SNMP_ERR_WRONGLENGTH;
    }
    if (action == COMMIT) {
        /*
         * object identifier in form .1.3.6.1.4.1.2021.13.14.2.1.4.x 
         * where X is index with offset 12 
         */

        dlm = dlmod_get_by_index(name[12]);
        switch (*((long *) var_val)) {
        case DLMOD_CREATE:
            if (dlm || (name[12] != dlmod_next_index))
                return SNMP_ERR_RESOURCEUNAVAILABLE;
            dlm = dlmod_create_module();
            if (!dlm)
                return SNMP_ERR_RESOURCEUNAVAILABLE;
            break;
        case DLMOD_LOAD:
            if (!dlm || dlm->status == DLMOD_LOADED)
                return SNMP_ERR_RESOURCEUNAVAILABLE;
            dlmod_load_module(dlm);
            break;
        case DLMOD_UNLOAD:
            if (!dlm || dlm->status != DLMOD_LOADED)
                return SNMP_ERR_RESOURCEUNAVAILABLE;
            dlmod_unload_module(dlm);
            break;
        case DLMOD_DELETE:
            if (!dlm || dlm->status == DLMOD_LOADED)
                return SNMP_ERR_RESOURCEUNAVAILABLE;
            dlmod_delete_module(dlm);
            break;
        default:
            return SNMP_ERR_WRONGVALUE;
        }
    }
    return SNMP_ERR_NOERROR;
}
Пример #2
0
static void
dlmod_parse_config(char *token, char *cptr)
{
    char           *dlm_name, *dlm_path;
    struct dlmod   *dlm;

    if (cptr == NULL) {
        config_perror("Bad dlmod line");
        return;
    }
    /*
     * remove comments 
     */
    *(cptr + strcspn(cptr, "#;\r\n")) = '\0';

    dlm = dlmod_create_module();
    if (!dlm)
        return;

    /*
     * dynamic module name 
     */
    dlm_name = strtok(cptr, "\t ");
    if (dlm_name == NULL) {
        config_perror("Bad dlmod line");
        dlmod_delete_module(dlm);
        return;
    }
    strncpy(dlm->name, dlm_name, sizeof(dlm->name));

    /*
     * dynamic module path 
     */
    dlm_path = strtok(NULL, "\t ");
    if (dlm_path)
        strncpy(dlm->path, dlm_path, sizeof(dlm->path));
    else
        strncpy(dlm->path, dlm_name, sizeof(dlm->path));

    dlmod_load_module(dlm);

    if (dlm->status == DLMOD_ERROR)
        snmp_log(LOG_ERR, "%s\n", dlm->error);

}