1 |
/* This file is part of GNU RADIUS. |
/* This file is part of GNU Radius |
2 |
Copyright (C) 2000, Sergey Poznyakoff |
Copyright (C) 2000, 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 |
#define RADIUS_MODULE_RADUTIL_C |
#define RADIUS_MODULE_RADUTIL_C |
19 |
|
|
|
#ifndef lint |
|
|
static char rcsid[] = |
|
|
"@(#) $Id$"; |
|
|
#endif |
|
|
|
|
20 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
21 |
# include <config.h> |
# include <config.h> |
22 |
#endif |
#endif |
27 |
#include <radiusd.h> |
#include <radiusd.h> |
28 |
#include <obstack1.h> |
#include <obstack1.h> |
29 |
|
|
|
static void attr_to_str(struct obstack *obp, |
|
|
RADIUS_REQ *req, |
|
|
VALUE_PAIR *pairlist, |
|
|
DICT_ATTR *attr, char *defval); |
|
|
static void curtime_to_str(struct obstack *obp, VALUE_PAIR *request, int gmt); |
|
|
static void attrno_to_str(struct obstack *obp, |
|
|
RADIUS_REQ *req, |
|
|
VALUE_PAIR *pairlist, |
|
|
int attr_no, char *defval); |
|
|
static DICT_ATTR *parse_dict_attr(char *p, char **endp, char **defval); |
|
|
|
|
|
static void obstack_grow_quoted(struct obstack *obp, char *str, int len); |
|
|
|
|
30 |
/* obstack_grow with quoting of potentially dangerous characters */ |
/* obstack_grow with quoting of potentially dangerous characters */ |
31 |
void |
static void |
32 |
obstack_grow_quoted(obp, str, len) |
obstack_grow_quoted(struct obstack *obp, char *str, int len) |
|
struct obstack *obp; |
|
|
char *str; |
|
|
int len; |
|
33 |
{ |
{ |
34 |
for (; len > 0; len--, str++) { |
for (; len > 0; len--, str++) { |
35 |
switch (*str) { |
switch (*str) { |
71 |
* the latter is NULL, store "unknown" for string type and "0" for |
* the latter is NULL, store "unknown" for string type and "0" for |
72 |
* others. |
* others. |
73 |
*/ |
*/ |
74 |
void |
static void |
75 |
attr_to_str(obp, req, pairlist, attr, defval) |
attr_to_str(struct obstack *obp, RADIUS_REQ *req, VALUE_PAIR *pairlist, |
76 |
struct obstack *obp; |
DICT_ATTR *attr, char *defval) |
|
RADIUS_REQ *req; |
|
|
VALUE_PAIR *pairlist; |
|
|
DICT_ATTR *attr; |
|
|
char *defval; |
|
77 |
{ |
{ |
78 |
VALUE_PAIR *pair; |
VALUE_PAIR *pair; |
79 |
int len; |
int len; |
177 |
} |
} |
178 |
} |
} |
179 |
|
|
180 |
void |
static void |
181 |
curtime_to_str(obp, request, gmt) |
curtime_to_str(struct obstack *obp, VALUE_PAIR *request, int gmt) |
|
struct obstack *obp; |
|
|
VALUE_PAIR *request; |
|
|
int gmt; |
|
182 |
{ |
{ |
183 |
time_t curtime; |
time_t curtime; |
184 |
struct tm *tm, tms; |
struct tm *tm, tms; |
203 |
* If no attribute found, use provided default value (see comment to |
* If no attribute found, use provided default value (see comment to |
204 |
* attr_to_str) |
* attr_to_str) |
205 |
*/ |
*/ |
206 |
void |
static void |
207 |
attrno_to_str(obp, req, pairlist, attr_no, defval) |
attrno_to_str(struct obstack *obp, RADIUS_REQ *req, VALUE_PAIR *pairlist, |
208 |
struct obstack *obp; |
int attr_no, char *defval) |
|
RADIUS_REQ *req; |
|
|
VALUE_PAIR *pairlist; |
|
|
int attr_no; |
|
|
char *defval; |
|
209 |
{ |
{ |
210 |
attr_to_str(obp, req, pairlist, |
attr_to_str(obp, req, pairlist, |
211 |
attr_number_to_dict(attr_no), defval); |
attr_number_to_dict(attr_no), defval); |
212 |
} |
} |
213 |
|
|
214 |
static DICT_ATTR * |
static DICT_ATTR * |
215 |
parse_dict_attr(p, endp, defval) |
parse_dict_attr(char *p, char **endp, char **defval) |
|
char *p; |
|
|
char **endp; |
|
|
char **defval; |
|
216 |
{ |
{ |
217 |
char namebuf[MAX_DICTNAME]; |
char namebuf[MAX_DICTNAME]; |
218 |
|
|
259 |
} |
} |
260 |
|
|
261 |
void |
void |
262 |
radius_xlate0(obp, str, req, reply) |
radius_xlate0(struct obstack *obp, char *str, RADIUS_REQ *req, |
263 |
struct obstack *obp; |
VALUE_PAIR *reply) |
|
char *str; |
|
|
RADIUS_REQ *req; |
|
|
VALUE_PAIR *reply; |
|
264 |
{ |
{ |
265 |
int c; |
int c; |
266 |
char *p; |
char *p; |
386 |
} |
} |
387 |
|
|
388 |
char * |
char * |
389 |
radius_xlate(obp, str, req, reply) |
radius_xlate(struct obstack *obp, char *str, RADIUS_REQ *req, VALUE_PAIR *reply) |
|
struct obstack *obp; |
|
|
char *str; |
|
|
RADIUS_REQ *req; |
|
|
VALUE_PAIR *reply; |
|
390 |
{ |
{ |
391 |
radius_xlate0(obp, str, req, reply); |
radius_xlate0(obp, str, req, reply); |
392 |
obstack_1grow(obp, 0); |
obstack_1grow(obp, 0); |