2 * Copyright (C) 1995,1996,1997 Lars Fenneberg
4 * See the file COPYRIGHT for the respective terms and conditions.
5 * If the file is missing contact me at lf@elemental.net
6 * and I'll send you a copy.
11 #include <radiusclient.h>
17 struct map2id_s *next;
20 static struct map2id_s *map2id_list = NULL;
23 * Function: rc_read_mapfile
25 * Purpose: Read in the ttyname to port id map file
27 * Arguments: the file name of the map file
29 * Returns: zero on success, negative integer on failure
32 int rc_read_mapfile(char *filename)
36 char *c, *name, *id, *q;
40 if ((mapfd = fopen(filename,"r")) == NULL)
42 error("rc_read_mapfile: can't read %s: %s", filename, strerror(errno));
46 #define SKIP(p) while(*p && isspace(*p)) p++;
48 while (fgets(buffer, sizeof(buffer), mapfd) != NULL)
56 if ((*q == '\n') || (*q == '#') || (*q == '\0'))
59 if (( c = strchr(q, ' ')) || (c = strchr(q,'\t'))) {
67 if ((p = (struct map2id_s *)malloc(sizeof(*p))) == NULL) {
68 novm("rc_read_mapfile");
73 if ((p->name = strdup(name)) == NULL) {
74 novm("rc_read_mapfile");
79 p->next = map2id_list;
84 error("rc_read_mapfile: malformed line in %s, line %d", filename, lnr);
101 * Purpose: Map ttyname to port id
103 * Arguments: full pathname of the tty
105 * Returns: port id, zero if no entry found
108 UINT4 rc_map2id(const char *name)
111 char ttyname[PATH_MAX];
115 strcpy(ttyname, "/dev/");
117 strncat(ttyname, name, sizeof(ttyname) - strlen(ttyname) -1);
119 for(p = map2id_list; p; p = p->next)
120 if (!strcmp(ttyname, p->name)) return p->id;
122 warn("rc_map2id: can't find tty %s in map database", ttyname);