2 * $Id: clientid.c,v 1.2 2002/02/27 15:51:20 dfs Exp $
4 * Copyright (C) 1995,1996,1997 Lars Fenneberg
6 * See the file COPYRIGHT for the respective terms and conditions.
7 * If the file is missing contact me at lf@elemental.net
8 * and I'll send you a copy.
14 #include <radiusclient.h>
20 struct map2id_s
*next
;
23 static struct map2id_s
*map2id_list
= NULL
;
26 * Function: rc_read_mapfile
28 * Purpose: Read in the ttyname to port id map file
30 * Arguments: the file name of the map file
32 * Returns: zero on success, negative integer on failure
35 int rc_read_mapfile(char *filename
)
39 char *c
, *name
, *id
, *q
;
43 if ((mapfd
= fopen(filename
,"r")) == NULL
)
45 rc_log(LOG_ERR
,"rc_read_mapfile: can't read %s: %s", filename
, strerror(errno
));
49 #define SKIP(p) while(*p && isspace(*p)) p++;
51 while (fgets(buffer
, sizeof(buffer
), mapfd
) != NULL
)
59 if ((*q
== '\n') || (*q
== '#') || (*q
== '\0'))
62 if (( c
= strchr(q
, ' ')) || (c
= strchr(q
,'\t'))) {
70 if ((p
= (struct map2id_s
*)malloc(sizeof(*p
))) == NULL
) {
71 rc_log(LOG_CRIT
,"rc_read_mapfile: out of memory");
75 p
->name
= strdup(name
);
77 p
->next
= map2id_list
;
82 rc_log(LOG_ERR
, "rc_read_mapfile: malformed line in %s, line %d", filename
, lnr
);
98 * Purpose: Map ttyname to port id
100 * Arguments: full pathname of the tty
102 * Returns: port id, zero if no entry found
105 UINT4
rc_map2id(char *name
)
108 char ttyname
[PATH_MAX
];
112 strcpy(ttyname
, "/dev/");
114 strncat(ttyname
, name
, sizeof(ttyname
));
116 for(p
= map2id_list
; p
; p
= p
->next
)
117 if (!strcmp(ttyname
, p
->name
)) return p
->id
;
119 rc_log(LOG_WARNING
,"rc_map2id: can't find tty %s in map database", ttyname
);