Beispiel #1
0
static int polrun_read_triggers(config_file_t config, const char *policy_name,
                                policy_run_config_t *conf, char *msg_out)
{
    int rc;
    unsigned int blk_index;
    char block_name[1024];

    /* get TRIGGER blocks */
    snprintf(block_name, sizeof(block_name), "%s" TRIGGER_SUFFIX, policy_name);

    for (blk_index = 0; blk_index < rh_config_GetNbBlocks(config);
            blk_index++) {
        char *curr_bname;

        config_item_t curr_item = rh_config_GetBlockByIndex(config, blk_index);
        critical_err_check(curr_item, "root");

        if (rh_config_ItemType(curr_item) != CONFIG_ITEM_BLOCK)
            continue;

        curr_bname = rh_config_GetBlockName(curr_item);
        critical_err_check(curr_bname, "root");

        if (!strcasecmp(curr_bname, block_name)) {
            conf->trigger_count++;
            /* realloc behaves as malloc when trigger_list is NULL */
            conf->trigger_list = (trigger_item_t *) realloc(conf->trigger_list,
                                 conf->
                                 trigger_count *
                                 sizeof
                                 (trigger_item_t));
            if (conf->trigger_list == NULL)
                return ENOMEM;

            /* analyze trigger block */
            rc = parse_trigger_block(curr_item, curr_bname,
                                     &conf->trigger_list[conf->trigger_count -
                                             1], msg_out);
            if (rc)
                return rc;
        }
    }

    return 0;
}
Beispiel #2
0
int Read_ResourceMon_Config( config_file_t config,
                             void *module_config, char *msg_out, int for_reload )
{
    int            rc;
    int            intval;
    resource_monitor_config_t *conf = ( resource_monitor_config_t * ) module_config;

    unsigned int   blc_index;

    static const char *purge_allowed[] = {
        "nb_threads_purge", "post_purge_df_latency",
        "purge_queue_size", "db_result_size_max",
#ifdef ATTR_INDEX_status
        "check_purge_status_on_startup",
#endif
        "recheck_ignored_classes",
#ifdef _TMP_FS_MGR
        "purge_command",
#endif
        NULL
    };

    /* get PURGE_PARAM block */

    config_item_t  param_block = rh_config_FindItemByName( config, PURGE_PARAM_BLOCK );
    if ( param_block != NULL )
    {
        /* no error, because no parameter is mandatory */

        /* check this is a block... */
        if ( rh_config_ItemType( param_block ) != CONFIG_ITEM_BLOCK )
        {
            strcpy( msg_out, "A block is expected for '" PURGE_PARAM_BLOCK "' item" );
            return EINVAL;
        }

        /* parse parameters */
        rc = GetIntParam( param_block, PURGE_PARAM_BLOCK, "nb_threads_purge",
                          INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL, ( int * ) &conf->nb_threads_purge,
                          NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;

        rc = GetDurationParam( param_block, PURGE_PARAM_BLOCK, "post_purge_df_latency", INT_PARAM_POSITIVE, /* 0 is authorized: no delay */
                               &intval, NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;
        else if ( rc != ENOENT )
            conf->post_purge_df_latency = intval;

        rc = GetIntParam( param_block, PURGE_PARAM_BLOCK, "purge_queue_size",
                          INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL, ( int * ) &conf->purge_queue_size,
                          NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;

        rc = GetIntParam( param_block, PURGE_PARAM_BLOCK, "db_result_size_max",
                          INT_PARAM_POSITIVE, ( int * ) &conf->db_request_limit, NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;

#ifdef ATTR_INDEX_status
        rc = GetBoolParam( param_block, PURGE_PARAM_BLOCK, "check_purge_status_on_startup",
                           0, &intval, NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;
        else if ( rc != ENOENT )
            conf->check_purge_status_on_startup = intval;
#endif
        rc = GetBoolParam( param_block, PURGE_PARAM_BLOCK, "recheck_ignored_classes",
                           0, &intval, NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;
        else if ( rc != ENOENT )
            conf->recheck_ignored_classes = intval;

        rc = GetBoolParam( param_block, PURGE_PARAM_BLOCK, "simulation_mode",
                           0, &intval, NULL, NULL, msg_out );
        if ( rc == 0 )
        {
            DisplayLog( LVL_CRIT, RESMONCFG_TAG,
                "WARNING: 'simulation_mode' parameter is deprecated. Use '--dry-run' option instead.");
        }

#ifdef _TMP_FS_MGR
        rc = GetStringParam(param_block, PURGE_PARAM_BLOCK, "purge_command",
                         STR_PARAM_ABSOLUTE_PATH, /* can contain wildcards: {path}, {fid}, {fsname} */
                         conf->purge_command, RBH_PATH_MAX, NULL, NULL, msg_out);
        if ((rc != 0) && (rc != ENOENT))
            return rc;
#endif

        CheckUnknownParameters( param_block, PURGE_PARAM_BLOCK, purge_allowed );

    } /* end of purge parameters */

    /* get PURGE_TRIGGER blocks */

    for ( blc_index = 0; blc_index < rh_config_GetNbBlocks( config ); blc_index++ )
    {
        char          *block_name;
        config_item_t  curr_item = rh_config_GetBlockByIndex( config, blc_index );
        critical_err_check( curr_item, "root" );

        if ( rh_config_ItemType( curr_item ) != CONFIG_ITEM_BLOCK )
            continue;

        block_name = rh_config_GetBlockName( curr_item );
        critical_err_check( block_name, "root" );

        if ( !strcasecmp( block_name, TRIGGER_BLOCK ) )
        {
            if ( conf->trigger_count == 0 )
                conf->trigger_list = ( trigger_item_t * ) malloc( sizeof( trigger_item_t ) );
            else
                conf->trigger_list =
                    ( trigger_item_t * ) realloc( conf->trigger_list,
                                                  ( conf->trigger_count +
                                                    1 ) * sizeof( trigger_item_t ) );

            conf->trigger_count++;

            /* analyze trigger block */
            rc = parse_trigger_block( curr_item, block_name,
                                      &conf->trigger_list[conf->trigger_count - 1], msg_out );

            if ( rc )
                return rc;
        }
    }

    return 0;
}
Beispiel #3
0
/**
 * Check that no unknown parameter or block is found.
 * @param param_array NULL terminated array of allowed parameters.
 */
void CheckUnknownParameters(config_item_t block, const char *block_name,
                            const char * const *param_array )
{
    int            i, j;

    for ( i = 0; i < rh_config_GetNbItems( block ); i++ )
    {
        config_item_t  curr_item = rh_config_GetItemByIndex( block, i );

        if ( rh_config_ItemType( curr_item ) == CONFIG_ITEM_VAR )
        {
            char          *name;
            char          *value;
            int            args_flg;
            bool           found = false;

            if ( rh_config_GetKeyValue( curr_item, &name, &value, &args_flg ) == 0 )
            {
                for ( j = 0; param_array[j] != NULL; j++ )
                {
                    if ( !strcasecmp( param_array[j], name ) )
                    {
                        found = true;
                        break;
                    }
                }

                if ( !found )
                    DisplayLog( LVL_CRIT, "Config Check",
                                "WARNING: unknown parameter '%s' in block '%s' line %d", name,
                                block_name, rh_config_GetItemLine( curr_item ) );
            }
        }
        else if ( rh_config_ItemType( curr_item ) == CONFIG_ITEM_BLOCK )
        {
            char          *name;
            bool           found = false;

            name = rh_config_GetBlockName( curr_item );

            if ( name != NULL )
            {
                for ( j = 0; param_array[j] != NULL; j++ )
                {
                    if ( !strcasecmp( param_array[j], name ) )
                    {
                        found = true;
                        break;
                    }
                }

                if ( !found )
                    DisplayLog( LVL_CRIT, "Config Check",
                                "WARNING: unknown block '%s' as sub-block of '%s' line %d", name,
                                block_name, rh_config_GetItemLine( curr_item ) );
            }

        }

    }
}
int Read_EntryProc_Config( config_file_t config, void *module_config,
                           char *msg_out, int for_reload )
{
    int            rc, blc_index, i;
    int            tmpval;
    entry_proc_config_t *conf = ( entry_proc_config_t * ) module_config;

    char           pipeline_names[PIPELINE_STAGE_COUNT][256];
    char          *entry_proc_allowed[PIPELINE_STAGE_COUNT + 5];

    entry_proc_allowed[0] = "nb_threads";
    entry_proc_allowed[1] = "max_pending_operations";
    entry_proc_allowed[2] = "match_classes";
    entry_proc_allowed[3] = ALERT_BLOCK;

    entry_proc_allowed[PIPELINE_STAGE_COUNT + 4] = NULL;        /* PIPELINE_STAGE_COUNT+4 = last slot */

    /* get EntryProcessor block */

    config_item_t  entryproc_block = rh_config_FindItemByName( config, ENTRYPROC_CONFIG_BLOCK );

    if ( entryproc_block == NULL )
    {
        strcpy( msg_out, "Missing configuration block '" ENTRYPROC_CONFIG_BLOCK "'" );
        /* No error because no parameter is mandatory  */
        return 0;
    }

    if ( rh_config_ItemType( entryproc_block ) != CONFIG_ITEM_BLOCK )
    {
        strcpy( msg_out, "A block is expected for '" ENTRYPROC_CONFIG_BLOCK "' item" );
        return EINVAL;
    }

    /* retrieve parameters */

    rc = GetIntParam( entryproc_block, ENTRYPROC_CONFIG_BLOCK, "nb_threads",
                      INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                      ( int * ) &conf->nb_thread, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetIntParam( entryproc_block, ENTRYPROC_CONFIG_BLOCK, "max_pending_operations",
                      INT_PARAM_POSITIVE,
                      ( int * ) &conf->max_pending_operations, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetBoolParam( entryproc_block, ENTRYPROC_CONFIG_BLOCK, "match_classes",
                       0, &conf->match_classes, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;


    /* look for '<stage>_thread_max' parameters */
    for ( i = 0; i < PIPELINE_STAGE_COUNT; i++ )
    {
        char           varname[256];

        snprintf( varname, 256, "%s_threads_max", entry_proc_pipeline[i].stage_name );

        strncpy( pipeline_names[i], varname, 256 );
        entry_proc_allowed[i + 4] = pipeline_names[i];

        rc = GetIntParam( entryproc_block, ENTRYPROC_CONFIG_BLOCK, varname,
                          INT_PARAM_POSITIVE, &tmpval, NULL, NULL, msg_out );

        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;
        else if ( ( rc != ENOENT ) && ( tmpval > 0 ) )  /* 0: keep default */
        {
            if ( entry_proc_pipeline[i].stage_flags & STAGE_FLAG_MAX_THREADS )
                entry_proc_pipeline[i].max_thread_count =
                    MIN2( entry_proc_pipeline[i].max_thread_count, tmpval );
            else if ( entry_proc_pipeline[i].stage_flags & STAGE_FLAG_PARALLEL )
            {
                /* the stqge is no more parallel, it has a limited number of threads */
                entry_proc_pipeline[i].stage_flags &= ~STAGE_FLAG_PARALLEL;
                entry_proc_pipeline[i].stage_flags |= STAGE_FLAG_MAX_THREADS;
                entry_proc_pipeline[i].max_thread_count = tmpval;
            }
            else if ( ( entry_proc_pipeline[i].stage_flags & STAGE_FLAG_SEQUENTIAL )
                      && ( tmpval != 1 ) )
            {
                sprintf( msg_out, "%s is sequential. Cannot use %u threads at this stage.",
                         entry_proc_pipeline[i].stage_name, tmpval );
                return EINVAL;
            }
        }

    }

    /* Find and parse "Alert" blocks */
    for ( blc_index = 0; blc_index < rh_config_GetNbItems( entryproc_block ); blc_index++ )
    {
        char          *block_name;
        config_item_t  curr_item = rh_config_GetItemByIndex( entryproc_block, blc_index );
        critical_err_check( curr_item, ENTRYPROC_CONFIG_BLOCK );

        if ( rh_config_ItemType( curr_item ) != CONFIG_ITEM_BLOCK )
            continue;

        block_name = rh_config_GetBlockName( curr_item );
        critical_err_check( curr_item, ENTRYPROC_CONFIG_BLOCK );

        if ( !strcasecmp( block_name, ALERT_BLOCK ) )
        {
            char * alert_title = NULL;

            if ( conf->alert_count == 0 )
                conf->alert_list = ( alert_item_t * ) malloc( sizeof( alert_item_t ) );
            else
                conf->alert_list =
                    ( alert_item_t * ) realloc( conf->alert_list,
                                                ( conf->alert_count + 1 )
                                                * sizeof( alert_item_t ) );

            conf->alert_count++;

            alert_title = rh_config_GetBlockId( curr_item );
            if ( alert_title != NULL )
                strncpy( conf->alert_list[conf->alert_count - 1].title,
                         alert_title, ALERT_TITLE_MAX );
            else
                conf->alert_list[conf->alert_count - 1].title[0] = '\0';

            /* analyze boolean expression */
            rc = GetBoolExpr( curr_item, block_name,
                              &conf->alert_list[conf->alert_count - 1].boolexpr,
                              &conf->alert_list[conf->alert_count - 1].attr_mask, msg_out );

            if ( rc )
                return rc;

            conf->alert_attr_mask |= conf->alert_list[conf->alert_count - 1].attr_mask;
        }
    }                           /* Loop on subblocks */

    CheckUnknownParameters( entryproc_block, ENTRYPROC_CONFIG_BLOCK,
                            ( const char ** ) entry_proc_allowed );

    return 0;
}
Beispiel #5
0
int FSScan_ReadConfig( config_file_t config, void *module_config, char *msg_out, int for_reload )
{
    int            rc, blc_index;
    fs_scan_config_t *conf = ( fs_scan_config_t * ) module_config;
    int scan_intl_set = FALSE;
    int scan_intl = 0;

    static const char * fsscan_allowed[] =
    {
        "scan_interval", "min_scan_interval", "max_scan_interval",
        "scan_retry_delay", "nb_threads_scan", "scan_op_timeout",
        "exit_on_timeout", "spooler_check_interval", "nb_prealloc_tasks",
		"completion_command",
        IGNORE_BLOCK, NULL
    };

    /* get FS Scan block */

    config_item_t  fsscan_block = rh_config_FindItemByName( config, FSSCAN_CONFIG_BLOCK );

    if ( fsscan_block == NULL )
    {
        strcpy( msg_out, "Missing configuration block '" FSSCAN_CONFIG_BLOCK "'" );
        /* No error because no parameter is mandatory  */
        return 0;
    }

    if ( rh_config_ItemType( fsscan_block ) != CONFIG_ITEM_BLOCK )
    {
        strcpy( msg_out, "A block is expected for '" FSSCAN_CONFIG_BLOCK "' item" );
        return EINVAL;
    }

    /* retrieve parameters */
    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                           "min_scan_interval",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           ( int * ) &conf->min_scan_interval, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == 0 )
        scan_intl_set = TRUE;

    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                           "max_scan_interval",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           ( int * ) &conf->max_scan_interval, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == 0 )
        scan_intl_set = TRUE;

    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                           "scan_interval",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           &scan_intl, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == 0 )
    {
        if (scan_intl_set)
        {
            strcpy( msg_out, "scan_interval parameter cannot be used with min/max_scan_interval" );
            return EINVAL;
        }
        conf->min_scan_interval = scan_intl;
        conf->max_scan_interval = scan_intl;
    }

    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                           "scan_retry_delay",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           ( int * ) &conf->scan_retry_delay, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetIntParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                      "nb_threads_scan",
                      INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                      ( int * ) &conf->nb_threads_scan, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK, "scan_op_timeout",
                            INT_PARAM_POSITIVE,    /* 0 is authorized => no timeout */
                           ( int * ) &conf->scan_op_timeout, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetBoolParam( fsscan_block, FSSCAN_CONFIG_BLOCK, "exit_on_timeout", 0,
                       (int*)&conf->exit_on_timeout, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                           "spooler_check_interval",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           ( int * ) &conf->spooler_check_interval, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                           "nb_prealloc_tasks",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           ( int * ) &conf->nb_prealloc_tasks, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetStringParam( fsscan_block, FSSCAN_CONFIG_BLOCK, "completion_command",
                         STR_PARAM_ABSOLUTE_PATH, /* can contain wildcards: {cfg} or {fspath} */
                         conf->completion_command, RBH_PATH_MAX, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;


    /* Find and parse "ignore" blocks */
    for ( blc_index = 0; blc_index < rh_config_GetNbItems( fsscan_block ); blc_index++ )
    {
        char          *block_name;
        config_item_t  curr_item = rh_config_GetItemByIndex( fsscan_block, blc_index );
        critical_err_check( curr_item, FSSCAN_CONFIG_BLOCK );

        if ( rh_config_ItemType( curr_item ) != CONFIG_ITEM_BLOCK )
            continue;

        block_name = rh_config_GetBlockName( curr_item );
        critical_err_check( curr_item, FSSCAN_CONFIG_BLOCK );

        if ( !strcasecmp( block_name, IGNORE_BLOCK ) )
        {
            if ( conf->ignore_count == 0 )
                conf->ignore_list = ( whitelist_item_t * ) malloc( sizeof( whitelist_item_t ) );
            else
                conf->ignore_list =
                    ( whitelist_item_t * ) realloc( conf->ignore_list,
                                                 ( conf->ignore_count + 1 )
                                                 * sizeof( whitelist_item_t ) );

            conf->ignore_count++;

            /* analyze boolean expression */
            rc = GetBoolExpr( curr_item, block_name,
                              &conf->ignore_list[conf->ignore_count - 1].bool_expr,
                              &conf->ignore_list[conf->ignore_count - 1].attr_mask, msg_out );

            if ( rc )
                return rc;

        }
    }                           /* Loop on subblocks */

    CheckUnknownParameters( fsscan_block, FSSCAN_CONFIG_BLOCK, fsscan_allowed );

    return 0;

}