]> git.sesse.net Git - itkacl/commitdiff
Make the core library support a configuration file (/etc/itkacl.conf),
authorSteinar H. Gunderson <sesse@samfundet.no>
Thu, 20 Jun 2013 22:19:09 +0000 (00:19 +0200)
committerSteinar H. Gunderson <sesse@samfundet.no>
Thu, 20 Jun 2013 22:19:09 +0000 (00:19 +0200)
reading the DNS zone name from there instead of hard-coded it in.

Begin ITKACL 2.1 changelog/Debian package.

17 files changed:
itkacl-2.0/debian/changelog [deleted file]
itkacl-2.1/Makefile [moved from itkacl-2.0/Makefile with 100% similarity]
itkacl-2.1/config.pm [moved from itkacl-2.0/config.pm with 100% similarity]
itkacl-2.1/debian/changelog [new file with mode: 0644]
itkacl-2.1/debian/compat [moved from itkacl-2.0/debian/compat with 100% similarity]
itkacl-2.1/debian/control [moved from itkacl-2.0/debian/control with 100% similarity]
itkacl-2.1/debian/copyright [moved from itkacl-2.0/debian/copyright with 100% similarity]
itkacl-2.1/debian/itkacl-sync.dirs [moved from itkacl-2.0/debian/itkacl-sync.dirs with 100% similarity]
itkacl-2.1/debian/itkacl-sync.install [moved from itkacl-2.0/debian/itkacl-sync.install with 100% similarity]
itkacl-2.1/debian/libitkacl-dev.install [moved from itkacl-2.0/debian/libitkacl-dev.install with 100% similarity]
itkacl-2.1/debian/libitkacl2.install [moved from itkacl-2.0/debian/libitkacl2.install with 58% similarity]
itkacl-2.1/debian/rules [moved from itkacl-2.0/debian/rules with 91% similarity]
itkacl-2.1/itkacl-test.c [moved from itkacl-2.0/itkacl-test.c with 100% similarity]
itkacl-2.1/itkacl.c [moved from itkacl-2.0/itkacl.c with 61% similarity]
itkacl-2.1/itkacl.h [moved from itkacl-2.0/itkacl.h with 100% similarity]
itkacl-2.1/itkacl.sql [moved from itkacl-2.0/itkacl.sql with 100% similarity]
itkacl-2.1/sync-itkacl.pl [moved from itkacl-2.0/sync-itkacl.pl with 100% similarity]

diff --git a/itkacl-2.0/debian/changelog b/itkacl-2.0/debian/changelog
deleted file mode 100644 (file)
index c66e4bf..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-itkacl (2.0) unstable; urgency=low
-
-  * Initial release.
-
- -- Steinar H. Gunderson <sesse@samfundet.no>  Tue, 14 May 2013 00:57:31 +0200
similarity index 100%
rename from itkacl-2.0/Makefile
rename to itkacl-2.1/Makefile
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 (file)
index 0000000..e553dcc
--- /dev/null
@@ -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 <sesse@samfundet.no>  Fri, 21 Jun 2013 00:17:34 +0200
+
+itkacl (2.0) unstable; urgency=low
+
+  * Initial release.
+
+ -- Steinar H. Gunderson <sesse@samfundet.no>  Tue, 14 May 2013 00:57:31 +0200
similarity index 58%
rename from itkacl-2.0/debian/libitkacl2.install
rename to itkacl-2.1/debian/libitkacl2.install
index d561644f40b1f9729d72eacf95fec605c5335005..89edcfc56f8d8bc2ff361192147870423d0f9d7c 100644 (file)
@@ -1 +1,2 @@
+etc/itkacl.conf
 usr/lib/libitkacl.so.*
similarity index 91%
rename from itkacl-2.0/debian/rules
rename to itkacl-2.1/debian/rules
index b1d86eb042b4fecbcf741f5d180503cdd0a72ff4..143f89c581ad98438f246fb354b7f1f615500307 100755 (executable)
@@ -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
similarity index 61%
rename from itkacl-2.0/itkacl.c
rename to itkacl-2.1/itkacl.c
index e373eb38090370bfc60db65ebe003e115254655e..1ebd3a096fec2c24299b3b2f97a24d114ac4b287 100644 (file)
 #include <stdlib.h>
 #include <stdarg.h>
 #include <unistd.h>
+#include <errno.h>
+#include <ctype.h>
 #include <netdb.h>
 
-#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 */
similarity index 100%
rename from itkacl-2.0/itkacl.h
rename to itkacl-2.1/itkacl.h
similarity index 100%
rename from itkacl-2.0/itkacl.sql
rename to itkacl-2.1/itkacl.sql