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,
32 "Configuration file for RADIUS realms", OPT_STATIC, NULL, MAXPATHLEN },
36 extern void (*radius_pre_auth_hook)(char const *user,
41 lookup_realm(char const *user,
47 SERVER *accts, *auths, *s;
51 auths = (SERVER *) malloc(sizeof(SERVER));
53 accts = (SERVER *) malloc(sizeof(SERVER));
56 realm = strrchr(user, '@');
59 info("Looking up servers for realm '%s'", realm);
61 info("Looking up servers for DEFAULT realm");
64 if (*(++realm) == '\0') {
69 if ((fd = fopen(radrealms_config, "r")) == NULL) {
70 option_error("cannot open %s", radrealms_config);
73 info("Reading %s", radrealms_config);
75 while ((fgets(buffer, sizeof(buffer), fd) != NULL)) {
78 if ((*buffer == '\n') || (*buffer == '#') || (*buffer == '\0'))
81 buffer[strlen(buffer)-1] = '\0';
83 p = strtok(buffer, "\t ");
85 if (p == NULL || (strcmp(p, "authserver") !=0
86 && strcmp(p, "acctserver"))) {
88 option_error("%s: invalid line %d: %s", radrealms_config,
92 info("Parsing '%s' entry:", p);
97 if (s->max >= SERVER_MAX)
100 if ((p = strtok(NULL, "\t ")) == NULL) {
102 option_error("%s: realm name missing on line %d: %s",
103 radrealms_config, line, buffer);
107 if ((realm != NULL && strcmp(p, realm) == 0) ||
108 (realm == NULL && strcmp(p, "DEFAULT") == 0) ) {
109 info(" - Matched realm %s", p);
110 if ((p = strtok(NULL, ":")) == NULL) {
112 option_error("%s: server address missing on line %d: %s",
113 radrealms_config, line, buffer);
116 s->name[s->max] = strdup(p);
117 info(" - Address is '%s'",p);
118 if ((p = strtok(NULL, "\t ")) == NULL) {
120 option_error("%s: server port missing on line %d: %s",
121 radrealms_config, line, buffer);
124 s->port[s->max] = atoi(p);
125 info(" - Port is '%d'", s->port[s->max]);
128 info(" - Skipping realm '%s'", p);
144 radius_pre_auth_hook = lookup_realm;
146 add_options(Options);
147 info("RADIUS Realms plugin initialized.");