>From 3ad99d3e67b6fc2e1c5615b8ca0435cf8b05bae8 Mon Sep 17 00:00:00 2001 From: Mats Erik Andersson Date: Mon, 20 Aug 2012 15:18:44 +0200 Subject: [PATCH] libshishi: Activate server-realm setting. Activate the configuration stanza `server-realm' and implement shishi_realm_for_server_file(). --- lib/cfg.c | 19 +++++++++++++------ lib/init.c | 5 ++++- lib/realm.c | 29 +++++++++++++++++++++++++++++ shishi.conf.in | 7 +++++-- 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/lib/cfg.c b/lib/cfg.c index a0e39b3..edd67d5 100644 --- a/lib/cfg.c +++ b/lib/cfg.c @@ -118,7 +118,7 @@ shishi_cfg (Shishi * handle, const char *option) char *p = opt; char *value; char *realm = NULL; - int res; + int res, server_realm = 0; size_t i; while (p != NULL && *p != '\0') @@ -214,11 +214,10 @@ shishi_cfg (Shishi * handle, const char *option) case SERVER_REALM_OPTION: { struct Shishi_realminfo *ri; - ri = _shishi_realminfo_new (handle, value); - ri->serverwildcards = xrealloc (ri->serverwildcards, - ++ri->nserverwildcards * - sizeof (*ri->serverwildcards)); - ri->serverwildcards[ri->nserverwildcards - 1] = xstrdup (value); + + server_realm = 1; + realm = xstrdup (value); + ri = _shishi_realminfo_new (handle, realm); } break; @@ -282,6 +281,14 @@ shishi_cfg (Shishi * handle, const char *option) char *protstr; int transport = UDP; + if (server_realm) /* Collect server pattern. */ + { + ri->serverwildcards = xrealloc (ri->serverwildcards, + ++ri->nserverwildcards * + sizeof (*ri->serverwildcards)); + ri->serverwildcards[ri->nserverwildcards - 1] = xstrdup (value); + break; + } if ((protstr = strchr (value, '/'))) { *protstr = '\0'; diff --git a/lib/init.c b/lib/init.c index 7fb349c..8c61001 100644 --- a/lib/init.c +++ b/lib/init.c @@ -175,7 +175,7 @@ shishi_done (Shishi * handle) if (handle->realminfos) { - size_t i; + size_t i, j; for (i = 0; i < handle->nrealminfos; i++) { @@ -183,6 +183,9 @@ shishi_done (Shishi * handle) free (handle->realminfos[i].kdcaddresses); free (handle->realminfos[i].name); + + for (j = 0; j < handle->realminfos[i].nserverwildcards; j++) + free (handle->realminfos[i].serverwildcards[j]); } } diff --git a/lib/realm.c b/lib/realm.c index b17010d..1b7c005 100644 --- a/lib/realm.c +++ b/lib/realm.c @@ -111,6 +111,35 @@ shishi_realm_default_set (Shishi * handle, const char *realm) char * shishi_realm_for_server_file (Shishi * handle, char *server) { + struct Shishi_realminfo *ri; + size_t i, j; + char *p; + + for (i = 0; i < handle->nrealminfos; i++) + { + ri = &handle->realminfos[i]; + + if (!ri->nserverwildcards) + continue; + + for (j = 0; j < ri->nserverwildcards; j++) + { + /* Exact server name match. */ + if (strcmp (server, ri->serverwildcards[j]) == 0) + return ri->name; + + /* Is this a tail pattern? */ + if (*(ri->serverwildcards[j]) != '.') + continue; + + /* Domain part matching. */ + p = server; + while (p = strchr (p, '.')) + if (strcmp (p++, ri->serverwildcards[j]) == 0) + return ri->name; + } + } + return NULL; } diff --git a/shishi.conf.in b/shishi.conf.in index 98db22b..2d2c285 100644 --- a/shishi.conf.in +++ b/shishi.conf.in @@ -70,8 +70,11 @@ # Specify realm for servers. # Value is REALM,SERVERREGEXP[,SERVERREGEXP...] -# SERVERREGEXP is a regular expression matching servers in the realm. -# The first match is used. +# SERVERREGEXP is a pattern used to establish membership in the +# given realm. The pattern is either the exact name of a server, +# or a trailing domain part expected in a qualified server name, +# whenever the pattern commences with a period. The first match +# found will be used in library calls. #server-realm=JOSEFSSON.ORG,.josefsson.org # How long shishi waits for a response from a KDC before continuing -- 1.7.2.5