summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNalin Dahyabhai <nalin.dahyabhai@pobox.com>2009-04-01 20:11:02 -0400
committerNalin Dahyabhai <nalin.dahyabhai@pobox.com>2009-04-01 20:11:02 -0400
commite8977e621bd3a5717ae416aa77860143ae197097 (patch)
tree8a6b82aef708827d759baf795a56f494843892eb
parent4ef0f586a5d8d4bc4296ecb5aca57a60aa30cc50 (diff)
downloadcredmonger-e8977e621bd3a5717ae416aa77860143ae197097.tar.gz
credmonger-e8977e621bd3a5717ae416aa77860143ae197097.tar.xz
credmonger-e8977e621bd3a5717ae416aa77860143ae197097.zip
- take a configdir
- skip over backups and rpmsave/orig/new
-rw-r--r--src/credmonger.c50
-rw-r--r--src/root2
2 files changed, 45 insertions, 7 deletions
diff --git a/src/credmonger.c b/src/credmonger.c
index 02ee37d..df9d2ac 100644
--- a/src/credmonger.c
+++ b/src/credmonger.c
@@ -3,6 +3,7 @@
#endif
#include <sys/types.h>
+#include <dirent.h>
#include <errno.h>
#include <pwd.h>
#include <signal.h>
@@ -14,7 +15,7 @@
#include <krb5.h>
-#define CONFIG_FILE "./credmongertab"
+#define CONFIG_DIR "/etc/credmonger.d"
#define FCC_PREFIX "FILE:"
#define DEFAULT_RETRY_TIME 300
@@ -32,6 +33,9 @@ static struct monger_entry {
/* Time to exit. */
static int quit = 0;
+/* Configuration directory. */
+static const char *configdir = CONFIG_DIR;
+
/* Read the configuration and return a list of ccache names. */
static struct monger_entry **
entries_read(void)
@@ -44,11 +48,35 @@ entries_read(void)
gid_t gid;
FILE *fp;
int n_entries;
+ DIR *dir;
+ struct dirent *ent;
list = NULL;
n_entries = 0;
-
- fp = fopen(CONFIG_FILE, "r");
+ for (dir = opendir(configdir);
+ (dir != NULL) && ((ent = readdir(dir)) != NULL);
+ closedir(dir)) {
+ if (strchr(".#~", ent->d_name[0]) != NULL) {
+ continue;
+ }
+ snprintf(buf, sizeof(buf), "%s/%.*s",
+ configdir, NAME_MAX, ent->d_name);
+ if (strlen(buf) > 0) {
+ p = buf + strlen(buf) - 1;
+ if (strchr("#~", *p) != NULL) {
+ continue;
+ }
+ if (strcmp(buf + strlen(buf) - 8, ".rpmsave") == 0) {
+ continue;
+ }
+ if (strcmp(buf + strlen(buf) - 8, ".rpmorig") == 0) {
+ continue;
+ }
+ if (strcmp(buf + strlen(buf) - 7, ".rpmnew") == 0) {
+ continue;
+ }
+ }
+ fp = fopen(buf, "r");
if (fp != NULL) {
while (fgets(buf, sizeof(buf), fp) != NULL) {
/* Trim end-of-line characters. */
@@ -183,7 +211,7 @@ entries_read(void)
}
fclose(fp);
}
-
+ }
return list;
}
@@ -223,7 +251,8 @@ entries_poll(void)
}
/* Walk the list of entries. */
for (i = 0; (entries != NULL) && (entries[i] != NULL); i++) {
- fprintf(stderr, "%ld:%s,%s,%s\n",
+ fprintf(stderr,
+ "uid=%ld,keytab=%s,client=%s,ccache=%s\n",
(unsigned long) entries[i]->uid,
entries[i]->keytab,
entries[i]->principal_name,
@@ -267,7 +296,8 @@ entries_poll(void)
}
ret = krb5_parse_name(ctx, principal_name, &client);
if (ret != 0) {
- fprintf(stderr, "Error parsing client: %s.\n",
+ fprintf(stderr, "Error parsing client \"%s\": "
+ "%s.\n", principal_name,
error_message(ret));
free(principal_name);
krb5_kt_close(ctx, keytab);
@@ -498,8 +528,11 @@ main(int argc, char **argv)
nofork = 0;
pidfile = NULL;
- while ((c = getopt(argc, argv, "np:")) != -1) {
+ while ((c = getopt(argc, argv, "c:np:")) != -1) {
switch (c) {
+ case 'c':
+ configdir = optarg;
+ break;
case 'n':
nofork++;
break;
@@ -512,6 +545,9 @@ main(int argc, char **argv)
}
entries = entries_read();
+ if (entries == NULL) {
+ fprintf(stderr, "Nothing configured.\n");
+ }
if (!nofork) {
daemon(0, 0);
diff --git a/src/root b/src/root
new file mode 100644
index 0000000..c205d51
--- /dev/null
+++ b/src/root
@@ -0,0 +1,2 @@
+root::host/:/tmp/krb5cc_0
+root::nfs/:/tmp/krb5cc_0