2 * $Id: clientid.c,v 1.1 2004/11/14 07:26:26 paulus 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.
13 #include <radiusclient.h>
19 struct map2id_s *next;
22 static struct map2id_s *map2id_list = NULL;
25 * Function: rc_read_mapfile
27 * Purpose: Read in the ttyname to port id map file
29 * Arguments: the file name of the map file
31 * Returns: zero on success, negative integer on failure
34 int rc_read_mapfile(char *filename)
38 char *c, *name, *id, *q;
42 if ((mapfd = fopen(filename,"r")) == NULL)
44 error("rc_read_mapfile: can't read %s: %s", filename, strerror(errno));
48 #define SKIP(p) while(*p && isspace(*p)) p++;
50 while (fgets(buffer, sizeof(buffer), mapfd) != NULL)
58 if ((*q == '\n') || (*q == '#') || (*q == '\0'))
61 if (( c = strchr(q, ' ')) || (c = strchr(q,'\t'))) {
69 if ((p = (struct map2id_s *)malloc(sizeof(*p))) == NULL) {
70 novm("rc_read_mapfile");
74 p->name = strdup(name);
76 p->next = map2id_list;
81 error("rc_read_mapfile: malformed line in %s, line %d", filename, lnr);
97 * Purpose: Map ttyname to port id
99 * Arguments: full pathname of the tty
101 * Returns: port id, zero if no entry found
104 UINT4 rc_map2id(char *name)
107 char ttyname[PATH_MAX];
111 strcpy(ttyname, "/dev/");
113 strncat(ttyname, name, sizeof(ttyname));
115 for(p = map2id_list; p; p = p->next)
116 if (!strcmp(ttyname, p->name)) return p->id;
118 warn("rc_map2id: can't find tty %s in map database", ttyname);