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 $";
23 #include <pppd/pppd.h>
25 #include "radiusclient.h"
27 char pppd_version[] = PPPD_VERSION;
29 char radrealms_config[MAXPATHLEN] = "/etc/radiusclient/realms";
31 static option_t Options[] = {
32 { "realms-config-file", o_string, &radrealms_config,
33 "Configuration file for RADIUS realms", OPT_STATIC, NULL, MAXPATHLEN },
37 extern void (*radius_pre_auth_hook)(char const *user,
42 lookup_realm(char const *user,
48 SERVER *accts, *auths, *s;
52 auths = (SERVER *) malloc(sizeof(SERVER));
54 accts = (SERVER *) malloc(sizeof(SERVER));
57 realm = strrchr(user, '@');
60 info("Looking up servers for realm '%s'", realm);
62 info("Looking up servers for DEFAULT realm");
65 if (*(++realm) == '\0') {
70 if ((fd = fopen(radrealms_config, "r")) == NULL) {
71 option_error("cannot open %s", radrealms_config);
76 info("Reading %s", radrealms_config);
78 while ((fgets(buffer, sizeof(buffer), fd) != NULL)) {
81 if ((*buffer == '\n') || (*buffer == '#') || (*buffer == '\0'))
84 buffer[strlen(buffer)-1] = '\0';
86 p = strtok(buffer, "\t ");
88 if (p == NULL || (strcmp(p, "authserver") !=0
89 && strcmp(p, "acctserver"))) {
91 option_error("%s: invalid line %d: %s", radrealms_config,
97 info("Parsing '%s' entry:", p);
102 if (s->max >= SERVER_MAX)
105 if ((p = strtok(NULL, "\t ")) == NULL) {
107 option_error("%s: realm name missing on line %d: %s",
108 radrealms_config, line, buffer);
114 if ((realm != NULL && strcmp(p, realm) == 0) ||
115 (realm == NULL && strcmp(p, "DEFAULT") == 0) ) {
116 info(" - Matched realm %s", p);
117 if ((p = strtok(NULL, ":")) == NULL) {
119 option_error("%s: server address missing on line %d: %s",
120 radrealms_config, line, buffer);
125 s->name[s->max] = strdup(p);
126 info(" - Address is '%s'",p);
127 if ((p = strtok(NULL, "\t ")) == NULL) {
129 option_error("%s: server port missing on line %d: %s",
130 radrealms_config, line, buffer);
135 s->port[s->max] = atoi(p);
136 info(" - Port is '%d'", s->port[s->max]);
139 info(" - Skipping realm '%s'", p);
155 radius_pre_auth_hook = lookup_realm;
157 add_options(Options);
158 info("RADIUS Realms plugin initialized.");