5 * A pppd plugin which is stacked on top of radius.so. This plugin
6 * allows selection of alternate set of servers based on the user's realm.
8 * Author: Ben McKeegan ben@netservers.co.uk
10 * Copyright (C) 2002 Netservers
12 * This plugin may be distributed according to the terms of the GNU
13 * General Public License, version 2 or (at your option) any later version.
17 static char const RCSID[] =
18 "$Id: radrealms.c,v 1.2 2004/11/14 07:26:26 paulus Exp $";
25 #include "radiusclient.h"
30 char pppd_version[] = VERSION;
32 char radrealms_config[MAXPATHLEN] = "/etc/radiusclient/realms";
34 static option_t Options[] = {
35 { "realms-config-file", o_string, &radrealms_config,
36 "Configuration file for RADIUS realms", OPT_STATIC, NULL, MAXPATHLEN },
40 extern void (*radius_pre_auth_hook)(char const *user,
45 lookup_realm(char const *user,
51 SERVER *accts, *auths, *s;
55 auths = (SERVER *) malloc(sizeof(SERVER));
57 accts = (SERVER *) malloc(sizeof(SERVER));
60 realm = strrchr(user, '@');
63 info("Looking up servers for realm '%s'", realm);
65 info("Looking up servers for DEFAULT realm");
68 if (*(++realm) == '\0') {
73 if ((fd = fopen(radrealms_config, "r")) == NULL) {
74 option_error("cannot open %s", radrealms_config);
79 info("Reading %s", radrealms_config);
81 while ((fgets(buffer, sizeof(buffer), fd) != NULL)) {
84 if ((*buffer == '\n') || (*buffer == '#') || (*buffer == '\0'))
87 buffer[strlen(buffer)-1] = '\0';
89 p = strtok(buffer, "\t ");
91 if (p == NULL || (strcmp(p, "authserver") !=0
92 && strcmp(p, "acctserver"))) {
94 option_error("%s: invalid line %d: %s", radrealms_config,
100 info("Parsing '%s' entry:", p);
105 if (s->max >= SERVER_MAX)
108 if ((p = strtok(NULL, "\t ")) == NULL) {
110 option_error("%s: realm name missing on line %d: %s",
111 radrealms_config, line, buffer);
117 if ((realm != NULL && strcmp(p, realm) == 0) ||
118 (realm == NULL && strcmp(p, "DEFAULT") == 0) ) {
119 info(" - Matched realm %s", p);
120 if ((p = strtok(NULL, ":")) == NULL) {
122 option_error("%s: server address missing on line %d: %s",
123 radrealms_config, line, buffer);
128 s->name[s->max] = strdup(p);
129 info(" - Address is '%s'",p);
130 if ((p = strtok(NULL, "\t ")) == NULL) {
132 option_error("%s: server port missing on line %d: %s",
133 radrealms_config, line, buffer);
138 s->port[s->max] = atoi(p);
139 info(" - Port is '%d'", s->port[s->max]);
142 info(" - Skipping realm '%s'", p);
158 radius_pre_auth_hook = lookup_realm;
160 add_options(Options);
161 info("RADIUS Realms plugin initialized.");