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 <sys/param.h>
27 #include <sys/types.h>
29 #include <pppd/pppd.h>
31 #include "radiusclient.h"
33 char pppd_version[] = PPPD_VERSION;
35 char radrealms_config[MAXPATHLEN] = "/etc/radiusclient/realms";
37 static option_t Options[] = {
38 { "realms-config-file", o_string, &radrealms_config,
39 "Configuration file for RADIUS realms", OPT_STATIC, NULL, MAXPATHLEN },
43 extern void (*radius_pre_auth_hook)(char const *user,
48 lookup_realm(char const *user,
54 SERVER *accts, *auths, *s;
58 auths = (SERVER *) malloc(sizeof(SERVER));
60 accts = (SERVER *) malloc(sizeof(SERVER));
63 realm = strrchr(user, '@');
66 info("Looking up servers for realm '%s'", realm);
68 info("Looking up servers for DEFAULT realm");
71 if (*(++realm) == '\0') {
76 if ((fd = fopen(radrealms_config, "r")) == NULL) {
77 ppp_option_error("cannot open %s", radrealms_config);
82 info("Reading %s", radrealms_config);
84 while ((fgets(buffer, sizeof(buffer), fd) != NULL)) {
87 if ((*buffer == '\n') || (*buffer == '#') || (*buffer == '\0'))
90 buffer[strlen(buffer)-1] = '\0';
92 p = strtok(buffer, "\t ");
94 if (p == NULL || (strcmp(p, "authserver") !=0
95 && strcmp(p, "acctserver"))) {
97 ppp_option_error("%s: invalid line %d: %s", radrealms_config,
103 info("Parsing '%s' entry:", p);
108 if (s->max >= SERVER_MAX)
111 if ((p = strtok(NULL, "\t ")) == NULL) {
113 ppp_option_error("%s: realm name missing on line %d: %s",
114 radrealms_config, line, buffer);
120 if ((realm != NULL && strcmp(p, realm) == 0) ||
121 (realm == NULL && strcmp(p, "DEFAULT") == 0) ) {
122 info(" - Matched realm %s", p);
123 if ((p = strtok(NULL, ":")) == NULL) {
125 ppp_option_error("%s: server address missing on line %d: %s",
126 radrealms_config, line, buffer);
131 s->name[s->max] = strdup(p);
132 info(" - Address is '%s'",p);
133 if ((p = strtok(NULL, "\t ")) == NULL) {
135 ppp_option_error("%s: server port missing on line %d: %s",
136 radrealms_config, line, buffer);
141 s->port[s->max] = atoi(p);
142 info(" - Port is '%d'", s->port[s->max]);
145 info(" - Skipping realm '%s'", p);
161 radius_pre_auth_hook = lookup_realm;
163 ppp_add_options(Options);
164 info("RADIUS Realms plugin initialized.");