summaryrefslogtreecommitdiffstats
path: root/share/examples/autofs
diff options
context:
space:
mode:
authoralfred <alfred@FreeBSD.org>2004-09-09 01:26:11 +0000
committeralfred <alfred@FreeBSD.org>2004-09-09 01:26:11 +0000
commita581fa78d90bf52f6dfb7f384a9c15548387e170 (patch)
treec91b49d0c6c07e2b441e67f2985838ef1075d969 /share/examples/autofs
parent1d00793bf6f72d2209c94f630a51c7704d7b0745 (diff)
downloadFreeBSD-src-a581fa78d90bf52f6dfb7f384a9c15548387e170.zip
FreeBSD-src-a581fa78d90bf52f6dfb7f384a9c15548387e170.tar.gz
Plug an fd leak by using autoh_freeall(3).
Refuse to run unless root. Check in /etc, /usr/local/etc and ./ for the "autotab" configuration file. Add more debug statements.
Diffstat (limited to 'share/examples/autofs')
-rw-r--r--share/examples/autofs/driver/autodriver.c44
1 files changed, 36 insertions, 8 deletions
diff --git a/share/examples/autofs/driver/autodriver.c b/share/examples/autofs/driver/autodriver.c
index 10ccbb0..69af0c5 100644
--- a/share/examples/autofs/driver/autodriver.c
+++ b/share/examples/autofs/driver/autodriver.c
@@ -114,15 +114,26 @@ parsetab(void)
char *cp, *p, *line, *opt;
size_t len;
struct autoentry *ent;
- int lineno, x, gotopt;
+ int i, lineno, x, gotopt;
const char *expecting = "expecting 'direct', 'indirect' or 'browse'";
+ const char *tabfiles[] = {
+ "/etc/autotab", "/usr/local/etc/autotab", "./autotab", NULL
+ };
- tab = "autotab";
lineno = 0;
+ for (i = 0; (tab = tabfiles[i]) != NULL; i++) {
+ tab = tabfiles[i];
+ fp = fopen(tab, "r");
+ if (fp == NULL)
+ warn("fopen %s", tab);
+ if (fp != NULL)
+ break;
+ }
+ if (fp == NULL) {
+ err(1, "no config file available.");
+ }
- fp = fopen(tab, "r");
- if (fp == NULL)
- err(1, "fopen %s", tab);
+ fprintf(stderr, "using config file: %s\n", tab);
while ((cp = fgetln(fp, &len)) != NULL) {
lineno++;
@@ -280,6 +291,7 @@ doreq(autoh_t ah, autoreq_t req)
struct autoentry *ent;
int error;
int mcmp;
+ int xid;
const char *mnt;
mnt = autoh_mp(ah);
@@ -293,6 +305,8 @@ doreq(autoh_t ah, autoreq_t req)
(int)strlen(ent->ae_mnt),
(int)strlen(autoreq_getpath(req)),
(int)strlen(ent->ae_path));
+ autoreq_getxid(req, &xid);
+ fprintf(stderr, "req xid %d\n", xid);
if ((mcmp = strcmp(mnt, ent->ae_mnt)) != 0) {
fprintf(stderr, "mcmp = %d\n", mcmp);
continue;
@@ -322,8 +336,11 @@ mount_indirect(req, ent)
char *path, *cmd;
int error, x;
- if (ent->ae_indirect != 1)
+ if (ent->ae_indirect != 1) {
+ fprintf(stderr, "not indirect.\n");
return (0);
+ }
+ fprintf(stderr, "indirect mount...\n");
/*
* handle lookups, fake all stat(2) requests... this is bad,
* but we're a driver so we don't care...
@@ -333,14 +350,19 @@ mount_indirect(req, ent)
case AUTOREQ_OP_LOOKUP:
break;
case AUTOREQ_OP_STAT:
+ fprintf(stderr, "stat\n");
return (1);
default:
+ fprintf(stderr, "unknown\n");
return (0);
}
if (stat(ent->ae_fullpath, &sb))
return (0);
- if (sb.st_ino != autoreq_getdirino(req))
+ if (sb.st_ino != autoreq_getdirino(req)) {
+ fprintf(stderr, "st_ino %d != dirino %d\n",
+ (int)sb.st_ino, (int)autoreq_getdirino(req));
return (0);
+ }
x = asprintf(&path, "%s/%s", ent->ae_fullpath, autoreq_getpath(req));
if (x > PATH_MAX) {
autoreq_seterrno(req, ENAMETOOLONG);
@@ -377,8 +399,11 @@ mount_direct(req, ent)
char *cmd;
int error;
- if (ent->ae_direct != 1)
+ if (ent->ae_direct != 1) {
+ fprintf(stderr, "not direct.\n");
return (0);
+ }
+ fprintf(stderr, "direct mount...\n");
/*
* handle lookups, fake all stat(2) requests... this is bad,
* but we're a driver so we don't care...
@@ -496,6 +521,7 @@ eventloop(void)
for (i = 0; i < cnt; i++) {
dotheneedful(array[i]);
}
+ autoh_freeall(array);
}
}
@@ -503,6 +529,8 @@ int
main(int argc __unused, char **argv __unused)
{
+ if (getuid() != 0)
+ errx(1, "autodriver needs to be run as root to work.");
parsetab();
populate_tab();
eventloop();
OpenPOWER on IntegriCloud