Example #1
0
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;
}
Example #2
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 ) );
            }

        }

    }
}
Example #3
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;

}