コード例 #1
0
/*
 * filterBinary:
 *
 * This routine will call routines to parse entries from an ASCII format
 * to a binary format recognized by the Ascend boxes.
 *
 *	pair:			Pointer to value_pair to place return.
 *
 *	valstr:			The string to parse
 *
 *	return:			-1 for error or 0.
 */
int ascend_parse_filter(VALUE_PAIR *vp, char const *value, size_t len)
{
	int		token, type;
	int		rcode;
	int		argc;
	char		*argv[32];
	ascend_filter_t filter;
	char		*p;

	rcode = -1;

	/*
	 *	Rather than printing specific error messages, we create
	 *	a general one here, which won't be used if the function
	 *	returns OK.
	 */
	fr_strerror_printf("Text is not in proper format");

	/*
	 *	Tokenize the input string in the VP.
	 *
	 *	Once the filter is *completelty* parsed, then we will
	 *	over-write it with the final binary filter.
	 */
	p = talloc_memdup(vp, value, len);
	p[len] = '\0';
	argc = str2argv(p, argv, 32);
	if (argc < 3) {
		talloc_free(p);
		return -1;
	}

	/*
	 *	Decide which filter type it is: ip, ipx, or generic
	 */
	type = fr_str2int(filterType, argv[0], -1);
	memset(&filter, 0, sizeof(filter));

	/*
	 *	Validate the filter type.
	 */
	switch (type) {
	case RAD_FILTER_GENERIC:
	case RAD_FILTER_IP:
	case RAD_FILTER_IPX:
		filter.type = type;
		break;

	default:
		fr_strerror_printf("Unknown Ascend filter type \"%s\"", argv[0]);
		talloc_free(p);
		return -1;
		break;
	}

	/*
	 *	Parse direction
	 */
	token = fr_str2int(filterKeywords, argv[1], -1);
	switch (token) {
	case FILTER_IN:
		filter.direction = 1;
		break;

	case FILTER_OUT:
		filter.direction = 0;
		break;

	default:
		fr_strerror_printf("Unknown Ascend filter direction \"%s\"", argv[1]);
		talloc_free(p);
		return -1;
	}

	/*
	 *	Parse action
	 */
	token = fr_str2int(filterKeywords, argv[2], -1);
	switch (token) {
	case FILTER_FORWARD:
		filter.forward = 1;
		break;

	case FILTER_DROP:
		filter.forward = 0;
		break;

	default:
		fr_strerror_printf("Unknown Ascend filter action \"%s\"", argv[2]);
		talloc_free(p);
		return -1;
		break;
	}


	switch (type) {
	case RAD_FILTER_GENERIC:
		rcode = ascend_parse_generic(argc - 3, &argv[3], &filter.u.generic);
		break;

	case RAD_FILTER_IP:
		rcode = ascend_parse_ip(argc - 3, &argv[3], &filter.u.ip);
		break;

	case RAD_FILTER_IPX:
		rcode = ascend_parse_ipx(argc - 3, &argv[3], &filter.u.ipx);
		break;
	}

	/*
	 *	Touch the VP only if everything was OK.
	 */
	if (rcode == 0) {
		vp->length = sizeof(filter);
		memcpy(vp->vp_filter, &filter, sizeof(filter));
	}

	talloc_free(p);
	return rcode;

#if 0
    /*
     * if 'more' is set then this new entry must exist, be a
     * FILTER_GENERIC_TYPE, direction and disposition must match for
     * the previous 'more' to be valid. If any should fail then TURN OFF
     * previous 'more'
     */
    if( prevRadvp ) {
	filt = ( RadFilter * )prevRadvp->vp_strvalue;
	if(( tok != FILTER_GENERIC_TYPE ) || (rc == -1 ) ||
	   ( prevRadvp->attribute != vp->attribute ) ||
	   ( filt->indirection != radFil.indirection ) ||
	   ( filt->forward != radFil.forward ) ) {
	    gen = &filt->u.generic;
	    gen->more = false;
	    fr_strerror_printf("filterBinary:  'more' for previous entry doesn't match: %s.\n",
		     valstr);
	}
    }
    prevRadvp = NULL;
    if( rc != -1 && tok == FILTER_GENERIC_TYPE ) {
	if( radFil.u.generic.more ) {
	    prevRadvp = vp;
	}
    }

    if( rc != -1 ) {
	    vpmemcpy(vp, &radFil, vp->length );
    }
    return(rc);

#endif
}
コード例 #2
0
/** Filter binary
 *
 * This routine will call routines to parse entries from an ASCII format
 * to a binary format recognized by the Ascend boxes.
 *
 * @param out Where to write parsed filter.
 * @param value ascend filter text.
 * @param len of value.
 * @return -1 for error or 0.
 */
int ascend_parse_filter(value_data_t *out, char const *value, size_t len)
{
    int		token, type;
    int		rcode;
    int		argc;
    char		*argv[32];
    ascend_filter_t filter;
    char		*p;

    rcode = -1;

    /*
     *	Tokenize the input string in the VP.
     *
     *	Once the filter is *completely* parsed, then we will
     *	over-write it with the final binary filter.
     */
    p = talloc_memdup(NULL, value, len+1);
    p[len] = '\0';

    /*
     *	Rather than printing specific error messages, we create
     *	a general one here, which won't be used if the function
     *	returns OK.
     */
    fr_strerror_printf("Failed parsing \"%s\" as ascend filer", p);

    argc = str2argv(p, argv, 32);
    if (argc < 3) {
        talloc_free(p);
        return -1;
    }

    /*
     *	Decide which filter type it is: ip, ipx, or generic
     */
    type = fr_str2int(filterType, argv[0], -1);
    memset(&filter, 0, sizeof(filter));

    /*
     *	Validate the filter type.
     */
    switch (type) {
    case RAD_FILTER_GENERIC:
    case RAD_FILTER_IP:
    case RAD_FILTER_IPX:
        filter.type = type;
        break;

    default:
        fr_strerror_printf("Unknown Ascend filter type \"%s\"", argv[0]);
        talloc_free(p);
        return -1;
    }

    /*
     *	Parse direction
     */
    token = fr_str2int(filterKeywords, argv[1], -1);
    switch (token) {
    case FILTER_IN:
        filter.direction = 1;
        break;

    case FILTER_OUT:
        filter.direction = 0;
        break;

    default:
        fr_strerror_printf("Unknown Ascend filter direction \"%s\"", argv[1]);
        talloc_free(p);
        return -1;
    }

    /*
     *	Parse action
     */
    token = fr_str2int(filterKeywords, argv[2], -1);
    switch (token) {
    case FILTER_FORWARD:
        filter.forward = 1;
        break;

    case FILTER_DROP:
        filter.forward = 0;
        break;

    default:
        fr_strerror_printf("Unknown Ascend filter action \"%s\"", argv[2]);
        talloc_free(p);
        return -1;
    }


    switch (type) {
    case RAD_FILTER_GENERIC:
        rcode = ascend_parse_generic(argc - 3, &argv[3], &filter.u.generic);
        break;

    case RAD_FILTER_IP:
        rcode = ascend_parse_ip(argc - 3, &argv[3], &filter.u.ip);
        break;

    case RAD_FILTER_IPX:
        rcode = ascend_parse_ipx(argc - 3, &argv[3], &filter.u.ipx);
        break;
    }

    /*
     *	Touch the VP only if everything was OK.
     */
    if (rcode == 0) memcpy(out->filter, &filter, sizeof(filter));
    talloc_free(p);
    printf("%i", rcode);

    return rcode;
}