zabbix-agent2/src/libs/zbxsysinfo/sysinfo.c
/******************************************************************************
 *                                                                            *
 * Function: parse_key_access_rule                                            *
 *                                                                            *
 * Purpose: parses key access rule expression from AllowKey and DenyKey       *
 *                                                                            *
 * Parameters: pattern - [IN] key access rule wildcard                        *
 *             rule    - [IN] key access rule element to fill                 *
 *                                                                            *
 * Return value: SUCCEED - successful execution                               *
 *               FAIL    - pattern parsing failed                             *
 *                                                                            *
 ******************************************************************************/
parse_key_access_rule

Purpose: parses key access rule expression from AllowKey and DenyKey

Parameters: pattern - [IN] key access rule wildcard
rule    - [IN] key access rule element to fill

Return value: SUCCEED - successful execution
FAIL    - pattern parsing failed
parse_key_access_rule Purpose : parses key access rule expression from AllowKey and DenyKey Parameters : pattern - [ IN ] key access rule wildcard rule - [ IN ] key access rule element to fill Return value : SUCCEED - successful execution FAIL - pattern parsing failed
static int	parse_key_access_rule(char *pattern, zbx_key_access_rule_t *rule)
{
	char		*pl, *pr = NULL, *param;
	size_t		alloc = 0, offset = 0;
	int		i, size;
	for (pl = pattern; SUCCEED == is_key_char(*pl) || '*' == *pl; pl++);
	if (pl == pattern)
		return FAIL; 
	zbx_strncpy_alloc(&pr, &alloc, &offset, pattern, pl - pattern);
	zbx_wildcard_minimize(pr);
	zbx_vector_str_append(&rule->elements, pr);
	rule->empty_arguments = 0;
	if ('\0' == *pl)	
		return SUCCEED;
	if ('[' != *pl)		
		return FAIL;
	for (pr = ++pl; '\0' != *pr; pr++);
	if (']' != *--pr)
		return FAIL;
	if (1 > pr - pl)	
	{
		rule->empty_arguments = 1;
		return SUCCEED;
	}
	*pr = '\0';
	size = num_param(pl);
	zbx_vector_str_reserve(&rule->elements, size);
	for (i = 0; i < size; i++)
	{
		if (NULL == (param = get_param_dyn(pl, i + 1, NULL)))
			return FAIL;
		zbx_wildcard_minimize(param);
		zbx_vector_str_append(&rule->elements, param);
	}
	*pr = ']';
	if (1 < size && 0 == strcmp(rule->elements.values[i--], "*"))
	{
		for (; 0 < i; i--)
		{
			if (0 != strcmp(rule->elements.values[i], "*"))
				break;
			zbx_free(rule->elements.values[i + 1]);
			zbx_vector_str_remove(&rule->elements, i + 1);
		}
	}
	return SUCCEED;
}
static int parse_key_access_rule ( char * pattern , zbx_key_access_rule_t * rule ) { char * pl , * pr = NULL , * param ; size_t alloc = 0 , offset = 0 ; int i , size ; for ( pl = pattern ; SUCCEED == is_key_char ( * pl ) || ' ' == * pl ; pl ++ ) ; if ( pl == pattern ) return FAIL ; zbx_strncpy_alloc ( & pr , & alloc , & offset , pattern , pl - pattern ) ; zbx_wildcard_minimize ( pr ) ; zbx_vector_str_append ( & rule -> elements , pr ) ; rule -> empty_arguments = 0 ; if ( ' \0 ' == * pl ) return SUCCEED ; if ( ' ' != * pl ) return FAIL ; for ( pr = ++ pl ; ' \0 ' != * pr ; pr ++ ) ; if ( ' ' != * -- pr ) return FAIL ; if ( 1 > pr - pl ) { rule -> empty_arguments = 1 ; return SUCCEED ; } * pr = ' \0 ' ; size = num_param ( pl ) ; zbx_vector_str_reserve ( & rule -> elements , size ) ; for ( i = 0 ; i < size ; i ++ ) { if ( NULL == ( param = get_param_dyn ( pl , i + 1 , NULL ) ) ) return FAIL ; zbx_wildcard_minimize ( param ) ; zbx_vector_str_append ( & rule -> elements , param ) ; } * pr = ' ' ; if ( 1 < size && 0 == strcmp ( rule -> elements . values [ i -- ] , " " ) ) { for ( ; 0 < i ; i -- ) { if ( 0 != strcmp ( rule -> elements . values [ i ] , " " ) ) break ; zbx_free ( rule -> elements . values [ i + 1 ] ) ; zbx_vector_str_remove ( & rule -> elements , i + 1 ) ; } } return SUCCEED ; }
Function: parse_key_access_rule                                            
                                                                            
 Purpose: parses key access rule expression from AllowKey and DenyKey       
                                                                            
 Parameters: pattern - [IN] key access rule wildcard                        
             rule    - [IN] key access rule element to fill                 
                                                                            
 Return value: SUCCEED - successful execution                               
               FAIL    - pattern parsing failed
Function : parse_key_access_rule Purpose : parses key access rule expression from AllowKey and DenyKey Parameters : pattern - [ IN ] key access rule wildcard rule - [ IN ] key access rule element to fill Return value : SUCCEED - successful execution FAIL - pattern parsing failed
/* empty key */ /* extract rule elements [0] = key pattern and all parameters follow */ /* no parameters specified */ /* unsupported character */ /* no parameters specified */ /* remove repeated trailing "*" parameters */