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 $";
21 #include "radiusclient.h"
26 char pppd_version[] = VERSION;
28 char radrealms_config[MAXPATHLEN] = "/etc/radiusclient/realms";
30 static option_t Options[] = {
31 { "realms-config-file", o_string, &radrealms_config },
35 extern void (*radius_pre_auth_hook)(char const *user,
40 lookup_realm(char const *user,
46 SERVER *accts, *auths, *s;
50 auths = (SERVER *) malloc(sizeof(SERVER));
52 accts = (SERVER *) malloc(sizeof(SERVER));
55 realm = strrchr(user, '@');
58 info("Looking up servers for realm '%s'", realm);
60 info("Looking up servers for DEFAULT realm");
63 if (*(++realm) == '\0') {
68 if ((fd = fopen(radrealms_config, "r")) == NULL) {
69 option_error("cannot open %s", radrealms_config);
72 info("Reading %s", radrealms_config);
74 while ((fgets(buffer, sizeof(buffer), fd) != NULL)) {
77 if ((*buffer == '\n') || (*buffer == '#') || (*buffer == '\0'))
80 buffer[strlen(buffer)-1] = '\0';
82 p = strtok(buffer, "\t ");
84 if (p == NULL || (strcmp(p, "authserver") !=0
85 && strcmp(p, "acctserver"))) {
87 option_error("%s: invalid line %d: %s", radrealms_config,
91 info("Parsing '%s' entry:", p);
96 if (s->max >= SERVER_MAX)
99 if ((p = strtok(NULL, "\t ")) == NULL) {
101 option_error("%s: realm name missing on line %d: %s",
102 radrealms_config, line, buffer);
106 if ((realm != NULL && strcmp(p, realm) == 0) ||
107 (realm == NULL && strcmp(p, "DEFAULT") == 0) ) {
108 info(" - Matched realm %s", p);
109 if ((p = strtok(NULL, ":")) == NULL) {
111 option_error("%s: server address missing on line %d: %s",
112 radrealms_config, line, buffer);
115 s->name[s->max] = strdup(p);
116 info(" - Address is '%s'",p);
117 if ((p = strtok(NULL, "\t ")) == NULL) {
119 option_error("%s: server port missing on line %d: %s",
120 radrealms_config, line, buffer);
123 s->port[s->max] = atoi(p);
124 info(" - Port is '%d'", s->port[s->max]);
127 info(" - Skipping realm '%s'", p);
143 radius_pre_auth_hook = lookup_realm;
145 add_options(Options);
146 info("RADIUS Realms plugin initialized.");