[26671] in Source-Commits
/svn/athena r25687 - in trunk/athena/etc/athinfod: . debian
daemon@ATHENA.MIT.EDU (Jonathan D Reed)
Thu Aug 2 16:29:48 2012
Date: Thu, 2 Aug 2012 16:29:47 -0400
From: Jonathan D Reed <jdreed@MIT.EDU>
Message-Id: <201208022029.q72KTlWj027231@drugstore.mit.edu>
To: source-commits@MIT.EDU
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Author: jdreed
Date: 2012-08-02 16:29:47 -0400 (Thu, 02 Aug 2012)
New Revision: 25687
Modified:
trunk/athena/etc/athinfod/athinfo.access.5
trunk/athena/etc/athinfod/athinfo.defs.5
trunk/athena/etc/athinfod/athinfod.c
trunk/athena/etc/athinfod/debian/changelog
Log:
In athinfod:
* Support athinfo.defs.d (Trac: #808)
* Correct typos in athinfo.access(5)
Modified: trunk/athena/etc/athinfod/athinfo.access.5
===================================================================
--- trunk/athena/etc/athinfod/athinfo.access.5 2012-08-02 17:42:01 UTC (rev 25686)
+++ trunk/athena/etc/athinfod/athinfo.access.5 2012-08-02 20:29:47 UTC (rev 25687)
@@ -25,7 +25,7 @@
.BR athinfod (8))
will answer requests for a given query. Blank lines and lines
beginning with '#' are ignored. Each line begins with the word
-"enabled" or "disabled" and continues with either a query name or "*"
+"enable" or "disable" and continues with either a query name or "*"
to match all queries. A specific match ("enable foo" or "disable foo"
when the query is "foo") takes priority over a glob match ("enable *"
or "disable *"). If no lines match the query, then it is disabled (so
Modified: trunk/athena/etc/athinfod/athinfo.defs.5
===================================================================
--- trunk/athena/etc/athinfod/athinfo.defs.5 2012-08-02 17:42:01 UTC (rev 25686)
+++ trunk/athena/etc/athinfod/athinfo.defs.5 2012-08-02 20:29:47 UTC (rev 25687)
@@ -13,11 +13,14 @@
.\" M.I.T. makes no representations about the suitability of
.\" this software for any purpose. It is provided "as is"
.\" without express or implied warranty.
-.TH ATHINFO.DEFS 5 "13 April 1999"
+.TH ATHINFO.DEFS 5 "2 August 2012"
.SH NAME
athinfo.defs \- Define athinfo queries
.SH SYNOPSIS
.B /etc/athena/athinfo.defs
+
+.B /etc/athena/athinfo.defs.d
+(optional)
.SH DESCRIPTION
The file
.B /etc/athena/athinfo.defs
@@ -28,6 +31,35 @@
by /bin/sh in response to the query. The command executed will not
receive input from the athinfo client. For security reasons, the
command should not depend on a network filesystem.
+
+The optional directory
+.B /etc/athena/athinfo.defs.d
+may contain query snippet files, whose filenames must end in
+.I .defs\fP. The format is identical to the
+.I athinfo.defs
+file. Queries listed in
+.I athinfo.defs
+will always override queries in these files. In the event of two files
+providing the same query name, the file which sorts first (using
+alphasort() from scandir(3)) will be used. The directory need not be
+present, but if it is present, it (and all files in it) must be readable
+by the user as which athinfod runs, or athinfod will generate an error.
+.SH BUGS
+Actually, when parsing files in
+.B athinfo.defs.d
+athinfod will only generate an error if attempts to read an unreadable
+file. If it finds the query in question in a readable file before
+encountering an unreadable one, no error will be generated. Users with
+an overly paranoid umask who routinely edit the query definition files
+as root should consider checking the file permissions after making
+changes.
+
+If you create a
+.I .defs
+file in
+.B /etc/athena/athinfo.defs.d
+whose full pathname (including the directory) exceeds PATH_MAX, it will
+not be parsed and will be silently skipped. Don't do that.
.SH EXAMPLE
The following example defines two queries, one to display the routing
table and another to display the rc.conf file.
Modified: trunk/athena/etc/athinfod/athinfod.c
===================================================================
--- trunk/athena/etc/athinfod/athinfod.c 2012-08-02 17:42:01 UTC (rev 25686)
+++ trunk/athena/etc/athinfod/athinfod.c 2012-08-02 20:29:47 UTC (rev 25687)
@@ -24,9 +24,14 @@
#include <ctype.h>
#include <unistd.h>
#include <fcntl.h>
+#include <dirent.h>
+#include <fnmatch.h>
+#include <errno.h>
#define PATH_ATHINFO_DEFS "/etc/athena/athinfo.defs"
#define PATH_ATHINFO_ACCESS "/etc/athena/athinfo.access"
+#define PATH_ATHINFO_DEFS_D "/etc/athena/athinfo.defs.d"
+#define ATHINFO_DEFS_D_WILDCARD "*.defs" /* Files to be read in defs.d */
static const char *read_query(void);
static void shutdown_input(void);
@@ -100,18 +105,19 @@
}
}
-/* Read the definition of query from the athinfo.defs file. */
-static const char *get_definition(const char *query)
+/* Read the definition of query from the specified file. */
+static const char *get_definition_from_file(const char *query,
+ const char *filepath)
{
char *line = NULL;
int linesize;
FILE *fp;
- fp = fopen(PATH_ATHINFO_DEFS, "r");
+ fp = fopen(filepath, "r");
if (!fp)
{
fprintf(stderr,
- "athinfod: cannot open athinfo definitions file, aborting.\n");
+ "athinfod: cannot open %s (%s), aborting.\n", filepath, strerror(errno));
exit(1);
}
@@ -129,6 +135,49 @@
}
fclose(fp);
+ return NULL;
+}
+
+static int defs_file_filter(const struct dirent *entry)
+{
+ return fnmatch(ATHINFO_DEFS_D_WILDCARD, entry->d_name, 0) == 0;
+}
+
+static const char *get_definition(const char *query)
+{
+ const char *definition;
+ definition = get_definition_from_file(query, PATH_ATHINFO_DEFS);
+ if (definition != NULL)
+ return definition;
+
+ struct dirent **namelist;
+ int numfiles, i;
+ numfiles = scandir(PATH_ATHINFO_DEFS_D, &namelist,
+ defs_file_filter, alphasort);
+ if (numfiles < 0) {
+ if (errno != ENOENT) {
+ fprintf(stderr, "athinfod: %s while scanning %s.\n",
+ strerror(errno), PATH_ATHINFO_DEFS_D);
+ exit(1);
+ }
+ } else {
+ for (i = 0; i < numfiles; i++) {
+ int len;
+ char path[PATH_MAX];
+ len = snprintf(path, sizeof(path), "%s/%s", PATH_ATHINFO_DEFS_D,
+ namelist[i]->d_name);
+ if (len < 0 || len >= (int)sizeof(path))
+ /* Should we print an error here? I don't think so. */
+ continue;
+ definition = get_definition_from_file(query, path);
+ free(namelist[i]);
+ if (definition != NULL)
+ break;
+ }
+ }
+ free(namelist);
+ if (definition != NULL)
+ return definition;
fprintf(stderr, "athinfod: unrecognized query.\n");
exit(0);
}
Modified: trunk/athena/etc/athinfod/debian/changelog
===================================================================
--- trunk/athena/etc/athinfod/debian/changelog 2012-08-02 17:42:01 UTC (rev 25686)
+++ trunk/athena/etc/athinfod/debian/changelog 2012-08-02 20:29:47 UTC (rev 25687)
@@ -1,8 +1,10 @@
-debathena-athinfod (10.0.0-0debathena18) UNRELEASED; urgency=low
+debathena-athinfod (10.1-0debathena1) unstable; urgency=low
* Bump debian/compat to 6
+ * Support athinfo.defs.d (Trac: #808)
+ * Correct typos in athinfo.access(5)
- -- Jonathan Reed <jdreed@mit.edu> Sun, 01 Jul 2012 12:21:30 -0400
+ -- Jonathan Reed <jdreed@mit.edu> Thu, 02 Aug 2012 16:12:48 -0400
debathena-athinfod (10.0.0-0debathena17) unstable; urgency=low