1 |
/* This file is part of GNU RADIUS. |
/* This file is part of GNU Radius. |
2 |
Copyright (C) 2000,2001 Sergey Poznyakoff |
Copyright (C) 2002,2003 Sergey Poznyakoff |
3 |
|
|
4 |
This program is free software; you can redistribute it and/or modify |
GNU Radius is free software; you can redistribute it and/or modify |
5 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
6 |
the Free Software Foundation; either version 2 of the License, or |
the Free Software Foundation; either version 2 of the License, or |
7 |
(at your option) any later version. |
(at your option) any later version. |
8 |
|
|
9 |
This program is distributed in the hope that it will be useful, |
GNU Radius is distributed in the hope that it will be useful, |
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
GNU General Public License for more details. |
GNU General Public License for more details. |
13 |
|
|
14 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
15 |
along with this program; if not, write to the Free Software Foundation, |
along with GNU Radius; if not, write to the Free Software Foundation, |
16 |
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
17 |
|
|
18 |
/* Support for ascend binary filters. */ |
/* Support for ascend binary filters. */ |
139 |
#define _moreinput(pb) ((pb)->tokn < (pb)->tokc) |
#define _moreinput(pb) ((pb)->tokn < (pb)->tokc) |
140 |
|
|
141 |
static char * |
static char * |
142 |
_get_token(pb, require) |
_get_token(struct ascend_parse_buf *pb, int require) |
|
struct ascend_parse_buf *pb; |
|
|
int require; |
|
143 |
{ |
{ |
144 |
|
|
145 |
if (!_moreinput(pb)) { |
if (!_moreinput(pb)) { |
153 |
} |
} |
154 |
|
|
155 |
static char * |
static char * |
156 |
_lookahead(pb) |
_lookahead(struct ascend_parse_buf *pb) |
|
struct ascend_parse_buf *pb; |
|
157 |
{ |
{ |
158 |
if (_moreinput(pb)) |
if (_moreinput(pb)) |
159 |
return pb->tokv[pb->tokn]; |
return pb->tokv[pb->tokn]; |
161 |
} |
} |
162 |
|
|
163 |
static int |
static int |
164 |
_get_type(pb) |
_get_type(struct ascend_parse_buf *pb) |
|
struct ascend_parse_buf *pb; |
|
165 |
{ |
{ |
166 |
char *tok = _get_token(pb, 1); |
char *tok = _get_token(pb, 1); |
167 |
if (!tok) |
if (!tok) |
181 |
} |
} |
182 |
|
|
183 |
static int |
static int |
184 |
_get_dir(pb) |
_get_dir(struct ascend_parse_buf *pb) |
|
struct ascend_parse_buf *pb; |
|
185 |
{ |
{ |
186 |
char *tok; |
char *tok; |
187 |
if ((tok = _get_token(pb, 1)) == NULL) |
if ((tok = _get_token(pb, 1)) == NULL) |
198 |
} |
} |
199 |
|
|
200 |
static int |
static int |
201 |
_get_action(pb) |
_get_action(struct ascend_parse_buf *pb) |
|
struct ascend_parse_buf *pb; |
|
202 |
{ |
{ |
203 |
char *tok; |
char *tok; |
204 |
if ((tok = _get_token(pb, 1)) == NULL) |
if ((tok = _get_token(pb, 1)) == NULL) |
219 |
/* GENERIC filter parsing */ |
/* GENERIC filter parsing */ |
220 |
|
|
221 |
int |
int |
222 |
_get_hex_string(pb, buf) |
_get_hex_string(struct ascend_parse_buf *pb, u_char *buf) |
|
struct ascend_parse_buf *pb; |
|
|
u_char *buf; |
|
223 |
{ |
{ |
224 |
u_char tmp[2*ASCEND_MAX_CMP_LENGTH], *p; |
u_char tmp[2*ASCEND_MAX_CMP_LENGTH], *p; |
225 |
char *tok = _get_token(pb, 1); |
char *tok = _get_token(pb, 1); |
269 |
mask and value are hex strings */ |
mask and value are hex strings */ |
270 |
|
|
271 |
int |
int |
272 |
_ascend_parse_generic(pb) |
_ascend_parse_generic(struct ascend_parse_buf *pb) |
|
struct ascend_parse_buf *pb; |
|
273 |
{ |
{ |
274 |
char *p; |
char *p; |
275 |
int num; |
int num; |
328 |
/* ************************************************************************* */ |
/* ************************************************************************* */ |
329 |
/* IP filter parsing */ |
/* IP filter parsing */ |
330 |
int |
int |
331 |
_get_protocol(pb) |
_get_protocol(struct ascend_parse_buf *pb) |
|
struct ascend_parse_buf *pb; |
|
332 |
{ |
{ |
333 |
char *tok = _get_token(pb, 1); |
char *tok = _get_token(pb, 1); |
334 |
char *p; |
char *p; |
356 |
#define ASCEND_DIR_DST 1 |
#define ASCEND_DIR_DST 1 |
357 |
|
|
358 |
int |
int |
359 |
_get_direction_type(pb, suffix, lookahead) |
_get_direction_type(struct ascend_parse_buf *pb, char *suffix, int lookahead) |
|
struct ascend_parse_buf *pb; |
|
|
char *suffix; |
|
|
int lookahead; |
|
360 |
{ |
{ |
361 |
char *tok = lookahead ? _lookahead(pb) : _get_token(pb, 1); |
char *tok = lookahead ? _lookahead(pb) : _get_token(pb, 1); |
362 |
|
|
375 |
} |
} |
376 |
|
|
377 |
int |
int |
378 |
_get_ip(pb) |
_get_ip(struct ascend_parse_buf *pb) |
|
struct ascend_parse_buf *pb; |
|
379 |
{ |
{ |
380 |
int dir = _get_direction_type(pb, "ip", 0); |
int dir = _get_direction_type(pb, "ip", 0); |
381 |
char *tok; |
char *tok; |
423 |
/* FIXME: if second {src|dst}ip is misspelled, the function returns |
/* FIXME: if second {src|dst}ip is misspelled, the function returns |
424 |
success, supposing it was a portspec */ |
success, supposing it was a portspec */ |
425 |
int |
int |
426 |
_ascend_parse_ip_clause(pb) |
_ascend_parse_ip_clause(struct ascend_parse_buf *pb) |
|
struct ascend_parse_buf *pb; |
|
427 |
{ |
{ |
428 |
int n; |
int n; |
429 |
|
|
444 |
} |
} |
445 |
|
|
446 |
int |
int |
447 |
_get_op(pb) |
_get_op(struct ascend_parse_buf *pb) |
|
struct ascend_parse_buf *pb; |
|
448 |
{ |
{ |
449 |
char *s = _get_token(pb, 1); |
char *s = _get_token(pb, 1); |
450 |
if (!s) |
if (!s) |
465 |
} |
} |
466 |
|
|
467 |
int |
int |
468 |
_get_port(pb) |
_get_port(struct ascend_parse_buf *pb) |
|
struct ascend_parse_buf *pb; |
|
469 |
{ |
{ |
470 |
int dir = _get_direction_type(pb, "port", 0); |
int dir = _get_direction_type(pb, "port", 0); |
471 |
char *tok; |
char *tok; |
522 |
} |
} |
523 |
|
|
524 |
int |
int |
525 |
_ascend_parse_port_clause(pb) |
_ascend_parse_port_clause(struct ascend_parse_buf *pb) |
|
struct ascend_parse_buf *pb; |
|
526 |
{ |
{ |
527 |
int n = _get_port(pb); |
int n = _get_port(pb); |
528 |
|
|
556 |
PORT is either the port number or its name from /etc/services */ |
PORT is either the port number or its name from /etc/services */ |
557 |
|
|
558 |
int |
int |
559 |
_ascend_parse_ip(pb) |
_ascend_parse_ip(struct ascend_parse_buf *pb) |
|
struct ascend_parse_buf *pb; |
|
560 |
{ |
{ |
561 |
if (!_moreinput(pb)) |
if (!_moreinput(pb)) |
562 |
return 0; |
return 0; |
597 |
[ "dstipxnet" NETADDR "dstipxnode" NODE |
[ "dstipxnet" NETADDR "dstipxnode" NODE |
598 |
[ "dstipxsoc" cmp HEXNUM ]] */ |
[ "dstipxsoc" cmp HEXNUM ]] */ |
599 |
int |
int |
600 |
_ascend_parse_ipx(pb) |
_ascend_parse_ipx(struct ascend_parse_buf *pb) |
|
struct ascend_parse_buf *pb; |
|
601 |
{ |
{ |
602 |
asprintf(pb->errmsg, "IPX filters are not yet supported"); |
asprintf(pb->errmsg, "IPX filters are not yet supported"); |
603 |
return 1; |
return 1; |
604 |
} |
} |
605 |
|
|
606 |
int |
int |
607 |
_ascend_parse(pb) |
_ascend_parse(struct ascend_parse_buf *pb) |
|
struct ascend_parse_buf *pb; |
|
608 |
{ |
{ |
609 |
memset(pb->flt, 0, sizeof(pb->flt[0])); |
memset(pb->flt, 0, sizeof(pb->flt[0])); |
610 |
|
|
628 |
Return !0 and return diagnostics in errp otherwise. |
Return !0 and return diagnostics in errp otherwise. |
629 |
NOTE: errp is malloced and should be freed using usual free() */ |
NOTE: errp is malloced and should be freed using usual free() */ |
630 |
int |
int |
631 |
_ascend_parse_filter(input, flt, errp) |
_ascend_parse_filter(const char *input, ASCEND_FILTER *flt, char **errp) |
|
const char *input; |
|
|
ASCEND_FILTER *flt; |
|
|
char **errp; |
|
632 |
{ |
{ |
633 |
struct ascend_parse_buf pb; |
struct ascend_parse_buf pb; |
634 |
int rc; |
int rc; |
649 |
} |
} |
650 |
|
|
651 |
int |
int |
652 |
ascend_parse_filter(pair, errp) |
ascend_parse_filter(VALUE_PAIR *pair, char **errp) |
|
VALUE_PAIR *pair; |
|
|
char **errp; |
|
653 |
{ |
{ |
654 |
ASCEND_FILTER flt; |
ASCEND_FILTER flt; |
655 |
|
|