summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvenaas <venaas>2007-05-15 14:19:44 +0000
committervenaas <venaas@e88ac4ed-0b26-0410-9574-a7f39faa03bf>2007-05-15 14:19:44 +0000
commitdfcb1477dc31cf7ae1e3b66fc25fb3d8acd5f163 (patch)
tree0f8d63e0c676d5b478880ed33de27e068bac7ab5
parent36f1a92cea2b74a44ba521701d6cb31df8ce3cd1 (diff)
fixed bug in id2server
git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@87 e88ac4ed-0b26-0410-9574-a7f39faa03bf
-rw-r--r--radsecproxy.c29
-rw-r--r--radsecproxy.h1
2 files changed, 14 insertions, 16 deletions
diff --git a/radsecproxy.c b/radsecproxy.c
index 779a1fa..6e1e3b5 100644
--- a/radsecproxy.c
+++ b/radsecproxy.c
@@ -41,6 +41,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
+#include <regex.h>
#include <libgen.h>
#include <pthread.h>
#include <openssl/ssl.h>
@@ -992,6 +993,7 @@ int msmppdecrypt(uint8_t *text, uint8_t len, uint8_t *shared, uint8_t sharedlen,
}
struct server *id2server(char *id, uint8_t len) {
+#ifndef REGEXP
int i;
char *idrealm;
struct server *deflt = NULL;
@@ -1004,29 +1006,22 @@ struct server *id2server(char *id, uint8_t len) {
idrealm = "-";
len = 1;
}
-#if 0
- char **realm;
- for (i = 0; i < server_count; i++) {
- for (realm = servers[i].realms; *realm; realm++) {
- if ((strlen(*realm) == 1 && **realm == '*') ||
- (strlen(*realm) == len && !memcmp(idrealm, *realm, len))) {
- debug(DBG_DBG, "found matching realm: %s, host %s", *realm, servers[i].peer.host);
- return servers + i;
- }
- }
- }
- return NULL;
-#else
+
for (i = 0; i < realm_count; i++) {
if (!deflt && realms[i].name[0] == '*' && realms[i].name[1] == '\0')
deflt = realms[i].server;
else if (!strncasecmp(idrealm, realms[i].name, len)) {
- debug(DBG_DBG, "found matching realm: %s, host %s", realms[i].name, servers[i].peer.host);
- return servers + i;
+ debug(DBG_DBG, "found matching realm: %s, host %s", realms[i].name, realms[i].server->peer.host);
+ return realms[i].server;
}
}
return deflt;
-#endif
+#else
+ for (i = 0; i < realm_count; i++)
+ if (!regexec(&realms[i].regex, id, 0, NULL, 0))
+ return realms[i].server;
+ return NULL;
+#endif
}
int rqinqueue(struct server *to, struct client *from, uint8_t id) {
@@ -1665,6 +1660,8 @@ void addrealm(char *value, char *server) {
memset(realm, 0, sizeof(struct realm));
realm->name = stringcopy(value, 0);
realm->server = servers + i;
+ if (regcomp(&realm->regex, value, REG_ICASE | REG_NOSUB))
+ debugx(1, DBG_ERR, "addrealm: failed to compile regular expression %s", value);
debug(DBG_DBG, "addrealm: added realm %s for server %s", value, server);
}
diff --git a/radsecproxy.h b/radsecproxy.h
index 797fa53..45b646f 100644
--- a/radsecproxy.h
+++ b/radsecproxy.h
@@ -115,6 +115,7 @@ struct server {
struct realm {
char *name;
+ regex_t regex;
struct server *server;
};