|
|
6bbd11 |
autofs-5.0.7 - allow use of hosts map in maps
|
|
|
6bbd11 |
|
|
|
6bbd11 |
From: Ian Kent <raven@themaw.net>
|
|
|
6bbd11 |
|
|
|
6bbd11 |
At the moment the internal hosts map can only be use as an entry in the
|
|
|
6bbd11 |
master map but there's no reason (I can think of so far) that it shouldn't
|
|
|
6bbd11 |
be possible to use it in map entries.
|
|
|
6bbd11 |
---
|
|
|
6bbd11 |
lib/parse_subs.c | 17 ++++++-----
|
|
|
6bbd11 |
modules/mount_autofs.c | 29 ++++++++++++++++----
|
|
|
6bbd11 |
modules/parse_sun.c | 71 +++++++++++++++++++++++++++++++------------------
|
|
|
6bbd11 |
3 files changed, 80 insertions(+), 37 deletions(-)
|
|
|
6bbd11 |
|
|
|
6bbd11 |
--- autofs-5.0.7.orig/lib/parse_subs.c
|
|
|
6bbd11 |
+++ autofs-5.0.7/lib/parse_subs.c
|
|
|
6bbd11 |
@@ -35,6 +35,7 @@ static struct types map_type[] = {
|
|
|
6bbd11 |
{ "ldaps", 5 },
|
|
|
6bbd11 |
{ "hesiod", 6 },
|
|
|
6bbd11 |
{ "userdir", 7 },
|
|
|
6bbd11 |
+ { "hosts", 5 },
|
|
|
6bbd11 |
};
|
|
|
6bbd11 |
static unsigned int map_type_count = sizeof(map_type)/sizeof(struct types);
|
|
|
6bbd11 |
|
|
|
6bbd11 |
@@ -384,7 +385,7 @@ struct map_type_info *parse_map_type_inf
|
|
|
6bbd11 |
return NULL;
|
|
|
6bbd11 |
} else {
|
|
|
6bbd11 |
*pos++ = '\0';
|
|
|
6bbd11 |
- while (*pos == ' ')
|
|
|
6bbd11 |
+ while (*pos && *pos == ' ')
|
|
|
6bbd11 |
*pos++ = '\0';
|
|
|
6bbd11 |
map = pos;
|
|
|
6bbd11 |
break;
|
|
|
6bbd11 |
@@ -412,7 +413,7 @@ struct map_type_info *parse_map_type_inf
|
|
|
6bbd11 |
return NULL;
|
|
|
6bbd11 |
} else {
|
|
|
6bbd11 |
*pos++ = '\0';
|
|
|
6bbd11 |
- while (*pos == ' ')
|
|
|
6bbd11 |
+ while (*pos && *pos == ' ')
|
|
|
6bbd11 |
*pos++ = '\0';
|
|
|
6bbd11 |
map = pos;
|
|
|
6bbd11 |
break;
|
|
|
6bbd11 |
@@ -458,11 +459,13 @@ struct map_type_info *parse_map_type_inf
|
|
|
6bbd11 |
}
|
|
|
6bbd11 |
}
|
|
|
6bbd11 |
|
|
|
6bbd11 |
- info->map = strdup(map);
|
|
|
6bbd11 |
- if (!info->map) {
|
|
|
6bbd11 |
- free(buf);
|
|
|
6bbd11 |
- free_map_type_info(info);
|
|
|
6bbd11 |
- return NULL;
|
|
|
6bbd11 |
+ if (map) {
|
|
|
6bbd11 |
+ info->map = strdup(map);
|
|
|
6bbd11 |
+ if (!info->map) {
|
|
|
6bbd11 |
+ free(buf);
|
|
|
6bbd11 |
+ free_map_type_info(info);
|
|
|
6bbd11 |
+ return NULL;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
}
|
|
|
6bbd11 |
|
|
|
6bbd11 |
free(buf);
|
|
|
6bbd11 |
--- autofs-5.0.7.orig/modules/mount_autofs.c
|
|
|
6bbd11 |
+++ autofs-5.0.7/modules/mount_autofs.c
|
|
|
6bbd11 |
@@ -62,6 +62,7 @@ int mount_mount(struct autofs_point *ap,
|
|
|
6bbd11 |
char buf[MAX_ERR_BUF];
|
|
|
6bbd11 |
char *options, *p;
|
|
|
6bbd11 |
int len, ret;
|
|
|
6bbd11 |
+ int hosts = 0;
|
|
|
6bbd11 |
|
|
|
6bbd11 |
/* Root offset of multi-mount */
|
|
|
6bbd11 |
len = strlen(root);
|
|
|
6bbd11 |
@@ -123,6 +124,8 @@ int mount_mount(struct autofs_point *ap,
|
|
|
6bbd11 |
ghost = 1;
|
|
|
6bbd11 |
else if (strncmp(cp, "symlink", 7) == 0)
|
|
|
6bbd11 |
symlnk = 1;
|
|
|
6bbd11 |
+ else if (strncmp(cp, "hosts", 5) == 0)
|
|
|
6bbd11 |
+ hosts = 1;
|
|
|
6bbd11 |
else if (strncmp(cp, "timeout=", 8) == 0) {
|
|
|
6bbd11 |
char *val = strchr(cp, '=');
|
|
|
6bbd11 |
unsigned tout;
|
|
|
6bbd11 |
@@ -164,7 +167,10 @@ int mount_mount(struct autofs_point *ap,
|
|
|
6bbd11 |
if (symlnk)
|
|
|
6bbd11 |
nap->flags |= MOUNT_FLAG_SYMLINK;
|
|
|
6bbd11 |
|
|
|
6bbd11 |
- argc = 1;
|
|
|
6bbd11 |
+ if (hosts)
|
|
|
6bbd11 |
+ argc = 0;
|
|
|
6bbd11 |
+ else
|
|
|
6bbd11 |
+ argc = 1;
|
|
|
6bbd11 |
|
|
|
6bbd11 |
if (options) {
|
|
|
6bbd11 |
char *t = options;
|
|
|
6bbd11 |
@@ -176,14 +182,27 @@ int mount_mount(struct autofs_point *ap,
|
|
|
6bbd11 |
}
|
|
|
6bbd11 |
argv = (const char **) alloca((argc + 1) * sizeof(char *));
|
|
|
6bbd11 |
|
|
|
6bbd11 |
- argc = 1;
|
|
|
6bbd11 |
-
|
|
|
6bbd11 |
- if (!(info = parse_map_type_info(what))) {
|
|
|
6bbd11 |
+ if (hosts)
|
|
|
6bbd11 |
+ argc = 0;
|
|
|
6bbd11 |
+ else
|
|
|
6bbd11 |
+ argc = 1;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ /*
|
|
|
6bbd11 |
+ * If a mount of a hosts map is being requested it will come
|
|
|
6bbd11 |
+ * ro us via the options. Catch that below when processing the
|
|
|
6bbd11 |
+ * option and create type info struct then.
|
|
|
6bbd11 |
+ */
|
|
|
6bbd11 |
+ if (hosts)
|
|
|
6bbd11 |
+ info = parse_map_type_info("hosts:");
|
|
|
6bbd11 |
+ else
|
|
|
6bbd11 |
+ info = parse_map_type_info(what);
|
|
|
6bbd11 |
+ if (!info) {
|
|
|
6bbd11 |
error(ap->logopt, MODPREFIX "failed to parse map info");
|
|
|
6bbd11 |
master_free_mapent(entry);
|
|
|
6bbd11 |
return 1;
|
|
|
6bbd11 |
}
|
|
|
6bbd11 |
- argv[0] = info->map;
|
|
|
6bbd11 |
+ if (info->map)
|
|
|
6bbd11 |
+ argv[0] = info->map;
|
|
|
6bbd11 |
|
|
|
6bbd11 |
if (options) {
|
|
|
6bbd11 |
p = options;
|
|
|
6bbd11 |
--- autofs-5.0.7.orig/modules/parse_sun.c
|
|
|
6bbd11 |
+++ autofs-5.0.7/modules/parse_sun.c
|
|
|
6bbd11 |
@@ -695,14 +695,18 @@ static int sun_mount(struct autofs_point
|
|
|
6bbd11 |
rv = mount_nfs->mount_mount(ap, root, mountpoint, strlen(mountpoint),
|
|
|
6bbd11 |
what, fstype, options, mount_nfs->context);
|
|
|
6bbd11 |
} else {
|
|
|
6bbd11 |
- what = alloca(loclen + 1);
|
|
|
6bbd11 |
- if (*loc == ':') {
|
|
|
6bbd11 |
- loclen--;
|
|
|
6bbd11 |
- memcpy(what, loc + 1, loclen);
|
|
|
6bbd11 |
- what[loclen] = '\0';
|
|
|
6bbd11 |
- } else {
|
|
|
6bbd11 |
- memcpy(what, loc, loclen);
|
|
|
6bbd11 |
- what[loclen] = '\0';
|
|
|
6bbd11 |
+ if (!loclen)
|
|
|
6bbd11 |
+ what = NULL;
|
|
|
6bbd11 |
+ else {
|
|
|
6bbd11 |
+ what = alloca(loclen + 1);
|
|
|
6bbd11 |
+ if (*loc == ':') {
|
|
|
6bbd11 |
+ loclen--;
|
|
|
6bbd11 |
+ memcpy(what, loc + 1, loclen);
|
|
|
6bbd11 |
+ what[loclen] = '\0';
|
|
|
6bbd11 |
+ } else {
|
|
|
6bbd11 |
+ memcpy(what, loc, loclen);
|
|
|
6bbd11 |
+ what[loclen] = '\0';
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
}
|
|
|
6bbd11 |
|
|
|
6bbd11 |
debug(ap->logopt, MODPREFIX
|
|
|
6bbd11 |
@@ -799,7 +803,8 @@ update_offset_entry(struct autofs_point
|
|
|
6bbd11 |
|
|
|
6bbd11 |
mc = source->mc;
|
|
|
6bbd11 |
|
|
|
6bbd11 |
- if (!*path || !*loc) {
|
|
|
6bbd11 |
+ /* Internal hosts map may have loc == NULL */
|
|
|
6bbd11 |
+ if (!*path) {
|
|
|
6bbd11 |
error(ap->logopt,
|
|
|
6bbd11 |
MODPREFIX "syntax error in offset %s -> %s", path, loc);
|
|
|
6bbd11 |
return CHE_FAIL;
|
|
|
6bbd11 |
@@ -833,8 +838,10 @@ update_offset_entry(struct autofs_point
|
|
|
6bbd11 |
if (*myoptions) {
|
|
|
6bbd11 |
strcpy(m_mapent, "-");
|
|
|
6bbd11 |
strcat(m_mapent, myoptions);
|
|
|
6bbd11 |
- strcat(m_mapent, " ");
|
|
|
6bbd11 |
- strcat(m_mapent, loc);
|
|
|
6bbd11 |
+ if (loc) {
|
|
|
6bbd11 |
+ strcat(m_mapent, " ");
|
|
|
6bbd11 |
+ strcat(m_mapent, loc);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
} else
|
|
|
6bbd11 |
strcpy(m_mapent, loc);
|
|
|
6bbd11 |
|
|
|
6bbd11 |
@@ -1435,13 +1442,17 @@ int parse_mount(struct autofs_point *ap,
|
|
|
6bbd11 |
|
|
|
6bbd11 |
l = parse_mapent(p, options, &myoptions, &loc, ap->logopt);
|
|
|
6bbd11 |
if (!l) {
|
|
|
6bbd11 |
- cache_delete_offset_list(mc, name);
|
|
|
6bbd11 |
- cache_multi_unlock(me);
|
|
|
6bbd11 |
- cache_unlock(mc);
|
|
|
6bbd11 |
- free(path);
|
|
|
6bbd11 |
- free(options);
|
|
|
6bbd11 |
- pthread_setcancelstate(cur_state, NULL);
|
|
|
6bbd11 |
- return 1;
|
|
|
6bbd11 |
+ if (!(strstr(myoptions, "fstype=autofs") &&
|
|
|
6bbd11 |
+ strstr(myoptions, "hosts"))) {
|
|
|
6bbd11 |
+ error(LOGOPT_ANY, "I think I'm a hosts map? l %d", l);
|
|
|
6bbd11 |
+ cache_delete_offset_list(mc, name);
|
|
|
6bbd11 |
+ cache_multi_unlock(me);
|
|
|
6bbd11 |
+ cache_unlock(mc);
|
|
|
6bbd11 |
+ free(path);
|
|
|
6bbd11 |
+ free(options);
|
|
|
6bbd11 |
+ pthread_setcancelstate(cur_state, NULL);
|
|
|
6bbd11 |
+ return 1;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
}
|
|
|
6bbd11 |
|
|
|
6bbd11 |
p += l;
|
|
|
6bbd11 |
@@ -1592,13 +1603,23 @@ int parse_mount(struct autofs_point *ap,
|
|
|
6bbd11 |
p = skipspace(p);
|
|
|
6bbd11 |
}
|
|
|
6bbd11 |
|
|
|
6bbd11 |
- loclen = strlen(loc);
|
|
|
6bbd11 |
- if (loclen == 0) {
|
|
|
6bbd11 |
- free(loc);
|
|
|
6bbd11 |
- free(options);
|
|
|
6bbd11 |
- error(ap->logopt,
|
|
|
6bbd11 |
- MODPREFIX "entry %s is empty!", name);
|
|
|
6bbd11 |
- return 1;
|
|
|
6bbd11 |
+ /*
|
|
|
6bbd11 |
+ * If options are asking for a hosts map loc should be
|
|
|
6bbd11 |
+ * NULL but we see it can contain junk, so ....
|
|
|
6bbd11 |
+ */
|
|
|
6bbd11 |
+ if ((strstr(options, "fstype=autofs") &&
|
|
|
6bbd11 |
+ strstr(options, "hosts"))) {
|
|
|
6bbd11 |
+ loc = NULL;
|
|
|
6bbd11 |
+ loclen = 0;
|
|
|
6bbd11 |
+ } else {
|
|
|
6bbd11 |
+ loclen = strlen(loc);
|
|
|
6bbd11 |
+ if (loclen == 0) {
|
|
|
6bbd11 |
+ free(loc);
|
|
|
6bbd11 |
+ free(options);
|
|
|
6bbd11 |
+ error(ap->logopt,
|
|
|
6bbd11 |
+ MODPREFIX "entry %s is empty!", name);
|
|
|
6bbd11 |
+ return 1;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
}
|
|
|
6bbd11 |
|
|
|
6bbd11 |
debug(ap->logopt,
|