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.1 2002/10/05 04:35:24 fcusack Exp $";
21 #include "radiusclient.h"
25 char pppd_version[] = VERSION;
27 char radrealms_config[MAXPATHLEN] = "/etc/radiusclient/realms";
29 static option_t Options[] = {
30 { "realms-config-file", o_string, &radrealms_config },
34 extern void (*radius_pre_auth_hook)(char const *user,
39 lookup_realm(char const *user,
45 SERVER *accts, *auths, *s;
49 auths = (SERVER *) malloc(sizeof(SERVER));
51 accts = (SERVER *) malloc(sizeof(SERVER));
54 realm = strrchr(user, '@');
57 info("Looking up servers for realm '%s'", realm);
59 info("Looking up servers for DEFAULT realm");
62 if (*(++realm) == '\0') {
67 if ((fd = fopen(radrealms_config, "r")) == NULL) {
68 option_error("cannot open %s", radrealms_config);
71 info("Reading %s", radrealms_config);
73 while ((fgets(buffer, sizeof(buffer), fd) != NULL)) {
76 if ((*buffer == '\n') || (*buffer == '#') || (*buffer == '\0'))
79 buffer[strlen(buffer)-1] = '\0';
81 p = strtok(buffer, "\t ");
83 if (p == NULL || (strcmp(p, "authserver") !=0
84 && strcmp(p, "acctserver"))) {
86 option_error("%s: invalid line %d: %s", radrealms_config,
90 info("Parsing '%s' entry:", p);
95 if (s->max >= SERVER_MAX)
98 if ((p = strtok(NULL, "\t ")) == NULL) {
100 option_error("%s: realm name missing on line %d: %s",
101 radrealms_config, line, buffer);
105 if ((realm != NULL && strcmp(p, realm) == 0) ||
106 (realm == NULL && strcmp(p, "DEFAULT") == 0) ) {
107 info(" - Matched realm %s", p);
108 if ((p = strtok(NULL, ":")) == NULL) {
110 option_error("%s: server address missing on line %d: %s",
111 radrealms_config, line, buffer);
114 s->name[s->max] = strdup(p);
115 info(" - Address is '%s'",p);
116 if ((p = strtok(NULL, "\t ")) == NULL) {
118 option_error("%s: server port missing on line %d: %s",
119 radrealms_config, line, buffer);
122 s->port[s->max] = atoi(p);
123 info(" - Port is '%d'", s->port[s->max]);
126 info(" - Skipping realm '%s'", p);
142 radius_pre_auth_hook = lookup_realm;
144 add_options(Options);
145 info("RADIUS Realms plugin initialized.");