From: Steinar H. Gunderson Date: Thu, 20 Jun 2013 22:19:09 +0000 (+0200) Subject: Make the core library support a configuration file (/etc/itkacl.conf), X-Git-Url: https://git.sesse.net/?p=itkacl;a=commitdiff_plain;h=66f114e2e5b127115cc127ea23865371f1bea90d Make the core library support a configuration file (/etc/itkacl.conf), reading the DNS zone name from there instead of hard-coded it in. Begin ITKACL 2.1 changelog/Debian package. --- diff --git a/itkacl-2.0/debian/changelog b/itkacl-2.0/debian/changelog deleted file mode 100644 index c66e4bf..0000000 --- a/itkacl-2.0/debian/changelog +++ /dev/null @@ -1,5 +0,0 @@ -itkacl (2.0) unstable; urgency=low - - * Initial release. - - -- Steinar H. Gunderson Tue, 14 May 2013 00:57:31 +0200 diff --git a/itkacl-2.0/Makefile b/itkacl-2.1/Makefile similarity index 100% rename from itkacl-2.0/Makefile rename to itkacl-2.1/Makefile diff --git a/itkacl-2.0/config.pm b/itkacl-2.1/config.pm similarity index 100% rename from itkacl-2.0/config.pm rename to itkacl-2.1/config.pm diff --git a/itkacl-2.1/debian/changelog b/itkacl-2.1/debian/changelog new file mode 100644 index 0000000..e553dcc --- /dev/null +++ b/itkacl-2.1/debian/changelog @@ -0,0 +1,12 @@ +itkacl (2.1) UNRELEASED; urgency=low + + * Make the core library support a configuration file (/etc/itkacl.conf), + reading the DNS zone name from there instead of hard-coded it in. + + -- Steinar H. Gunderson Fri, 21 Jun 2013 00:17:34 +0200 + +itkacl (2.0) unstable; urgency=low + + * Initial release. + + -- Steinar H. Gunderson Tue, 14 May 2013 00:57:31 +0200 diff --git a/itkacl-2.0/debian/compat b/itkacl-2.1/debian/compat similarity index 100% rename from itkacl-2.0/debian/compat rename to itkacl-2.1/debian/compat diff --git a/itkacl-2.0/debian/control b/itkacl-2.1/debian/control similarity index 100% rename from itkacl-2.0/debian/control rename to itkacl-2.1/debian/control diff --git a/itkacl-2.0/debian/copyright b/itkacl-2.1/debian/copyright similarity index 100% rename from itkacl-2.0/debian/copyright rename to itkacl-2.1/debian/copyright diff --git a/itkacl-2.0/debian/itkacl-sync.dirs b/itkacl-2.1/debian/itkacl-sync.dirs similarity index 100% rename from itkacl-2.0/debian/itkacl-sync.dirs rename to itkacl-2.1/debian/itkacl-sync.dirs diff --git a/itkacl-2.0/debian/itkacl-sync.install b/itkacl-2.1/debian/itkacl-sync.install similarity index 100% rename from itkacl-2.0/debian/itkacl-sync.install rename to itkacl-2.1/debian/itkacl-sync.install diff --git a/itkacl-2.0/debian/libitkacl-dev.install b/itkacl-2.1/debian/libitkacl-dev.install similarity index 100% rename from itkacl-2.0/debian/libitkacl-dev.install rename to itkacl-2.1/debian/libitkacl-dev.install diff --git a/itkacl-2.0/debian/libitkacl2.install b/itkacl-2.1/debian/libitkacl2.install similarity index 58% rename from itkacl-2.0/debian/libitkacl2.install rename to itkacl-2.1/debian/libitkacl2.install index d561644..89edcfc 100644 --- a/itkacl-2.0/debian/libitkacl2.install +++ b/itkacl-2.1/debian/libitkacl2.install @@ -1 +1,2 @@ +etc/itkacl.conf usr/lib/libitkacl.so.* diff --git a/itkacl-2.0/debian/rules b/itkacl-2.1/debian/rules similarity index 91% rename from itkacl-2.0/debian/rules rename to itkacl-2.1/debian/rules index b1d86eb..143f89c 100755 --- a/itkacl-2.0/debian/rules +++ b/itkacl-2.1/debian/rules @@ -20,6 +20,7 @@ binary-arch: mkdir -p debian/tmp/usr/share dh_installdirs $(MAKE) install DESTDIR=debian/tmp PREFIX=/usr + install -m 0644 itkacl.conf debian/tmp/etc/ dh_install dh_installchangelogs dh_compress diff --git a/itkacl-2.0/itkacl-test.c b/itkacl-2.1/itkacl-test.c similarity index 100% rename from itkacl-2.0/itkacl-test.c rename to itkacl-2.1/itkacl-test.c diff --git a/itkacl-2.0/itkacl.c b/itkacl-2.1/itkacl.c similarity index 61% rename from itkacl-2.0/itkacl.c rename to itkacl-2.1/itkacl.c index e373eb3..1ebd3a0 100644 --- a/itkacl-2.0/itkacl.c +++ b/itkacl-2.1/itkacl.c @@ -9,19 +9,101 @@ #include #include #include +#include +#include #include -#define BASE_ZONE "itkacl.samfundet.no" +struct itkacl_config { + char nszone[256]; +}; + +#define CONFIG_FILENAME "/etc/itkacl.conf" + +static int itkacl_read_config(const char * const filename, + struct itkacl_config *config, + char *errmsg, size_t errmsg_size) +{ + FILE *fp; + int lineno = 0; + + strcpy(config->nszone, ""); + + fp = fopen(CONFIG_FILENAME, "r"); + if (fp == NULL) { + if (errmsg) + snprintf(errmsg, errmsg_size, "%s: %s", + CONFIG_FILENAME, strerror(errno)); + return -1; + } + + while (!feof(fp)) { + char line[256], arg[256], *ptr; + + if (fgets(line, sizeof(line), fp) == NULL) { + break; + } + ++lineno; + + /* Remove trailing newlines and then comments. */ + ptr = strchr(line, '\n'); + if (ptr != NULL) + *ptr = 0; + + ptr = strchr(line, '\r'); + if (ptr != NULL) + *ptr = 0; + + ptr = strchr(line, '#'); + if (ptr != NULL) + *ptr = 0; + + /* Remove trailing whitespace, if any. */ + ptr = line + strlen(line) - 1; + while (ptr >= line && isspace(*ptr)) + *ptr-- = 0; + + /* Skip lines that now ended up blank. */ + if (line[0] == 0) + continue; + + if (sscanf(line, "zone %255s", arg) == 1) { + strcpy(config->nszone, arg); + continue; + } + + if (errmsg) + snprintf(errmsg, errmsg_size, "%s: Could not parse line %d", + CONFIG_FILENAME, lineno); + fclose(fp); + return -1; + } + + if (strlen(config->nszone) == 0) { + if (errmsg) + snprintf(errmsg, errmsg_size, "%s: Missing 'zone' directive", + CONFIG_FILENAME); + fclose(fp); + return -1; + } + + fclose(fp); + return 0; +} int itkacl_check(const char * const realm, const char * const user, char *errmsg, size_t errmsg_size) { + struct itkacl_config config; struct hostent he, *he_ptr; int ret, host_errno; const char *ptr; - char nszone[256] = BASE_ZONE; + char nszone[256]; char temp[256], ns_temp[1024]; + if (itkacl_read_config(CONFIG_FILENAME, &config, errmsg, errmsg_size) != 0) { + return -1; + } + if (realm[0] != '/') { if (errmsg) snprintf(errmsg, errmsg_size, "Invalid realm '%s' (missing leading /)", @@ -59,6 +141,7 @@ int itkacl_check(const char * const realm, const char * const user, /* traverse the realm entry by entry from the root, * creating a DNS zone name as we go */ + strcpy(nszone, config.nszone); ptr = realm; while (*ptr) { /* copy all characters to next / or end of string */ diff --git a/itkacl-2.0/itkacl.h b/itkacl-2.1/itkacl.h similarity index 100% rename from itkacl-2.0/itkacl.h rename to itkacl-2.1/itkacl.h diff --git a/itkacl-2.0/itkacl.sql b/itkacl-2.1/itkacl.sql similarity index 100% rename from itkacl-2.0/itkacl.sql rename to itkacl-2.1/itkacl.sql diff --git a/itkacl-2.0/sync-itkacl.pl b/itkacl-2.1/sync-itkacl.pl similarity index 100% rename from itkacl-2.0/sync-itkacl.pl rename to itkacl-2.1/sync-itkacl.pl