|
|
516ab0 |
autofs-5.1.0 - add a prefix to program map stdvars
|
|
|
516ab0 |
|
|
|
516ab0 |
From: Ian Kent <ikent@redhat.com>
|
|
|
516ab0 |
|
|
|
516ab0 |
When a program map uses an interpreted languages like python it's
|
|
|
516ab0 |
possible to load and execute arbitray code from a user home directory.
|
|
|
516ab0 |
This is because the standard environment variables are used to locate
|
|
|
516ab0 |
and load modules when using these languages.
|
|
|
516ab0 |
|
|
|
516ab0 |
To avoid that we need to add a prefix to these environment names so
|
|
|
516ab0 |
they aren't used for this purpose. The prefix used is "AUTOFS_" and
|
|
|
516ab0 |
is not configurable.
|
|
|
516ab0 |
---
|
|
|
516ab0 |
CHANGELOG | 1
|
|
|
516ab0 |
include/mounts.h | 4 +-
|
|
|
516ab0 |
lib/mounts.c | 84 +++++++++++++++++++++++++++++++++++++++--------
|
|
|
516ab0 |
modules/lookup_program.c | 2 -
|
|
|
516ab0 |
modules/parse_sun.c | 8 ++--
|
|
|
516ab0 |
5 files changed, 78 insertions(+), 21 deletions(-)
|
|
|
516ab0 |
|
|
|
516ab0 |
--- autofs-5.0.7.orig/CHANGELOG
|
|
|
516ab0 |
+++ autofs-5.0.7/CHANGELOG
|
|
|
516ab0 |
@@ -162,6 +162,7 @@
|
|
|
516ab0 |
- make negative cache update consistent for all lookup modules.
|
|
|
516ab0 |
- ensure negative cache isn't updated on remount.
|
|
|
516ab0 |
- dont add wildcard to negative cache.
|
|
|
516ab0 |
+- add a prefix to program map stdvars.
|
|
|
516ab0 |
|
|
|
516ab0 |
25/07/2012 autofs-5.0.7
|
|
|
516ab0 |
=======================
|
|
|
516ab0 |
--- autofs-5.0.7.orig/include/mounts.h
|
|
|
516ab0 |
+++ autofs-5.0.7/include/mounts.h
|
|
|
516ab0 |
@@ -87,8 +87,8 @@ extern unsigned int nfs_mount_uses_strin
|
|
|
516ab0 |
|
|
|
516ab0 |
struct amd_entry;
|
|
|
516ab0 |
|
|
|
516ab0 |
-struct substvar *addstdenv(struct substvar *sv);
|
|
|
516ab0 |
-struct substvar *removestdenv(struct substvar *sv);
|
|
|
516ab0 |
+struct substvar *addstdenv(struct substvar *sv, const char *prefix);
|
|
|
516ab0 |
+struct substvar *removestdenv(struct substvar *sv, const char *prefix);
|
|
|
516ab0 |
void add_std_amd_vars(struct substvar *sv);
|
|
|
516ab0 |
void remove_std_amd_vars(void);
|
|
|
516ab0 |
struct amd_entry *new_amd_entry(const struct substvar *sv);
|
|
|
516ab0 |
--- autofs-5.0.7.orig/lib/mounts.c
|
|
|
516ab0 |
+++ autofs-5.0.7/lib/mounts.c
|
|
|
516ab0 |
@@ -32,6 +32,7 @@
|
|
|
516ab0 |
|
|
|
516ab0 |
#define MAX_OPTIONS_LEN 80
|
|
|
516ab0 |
#define MAX_MNT_NAME_LEN 30
|
|
|
516ab0 |
+#define MAX_ENV_NAME 15
|
|
|
516ab0 |
|
|
|
516ab0 |
#define EBUFSIZ 1024
|
|
|
516ab0 |
|
|
|
516ab0 |
@@ -328,7 +329,61 @@ int check_nfs_mount_version(struct nfs_m
|
|
|
516ab0 |
}
|
|
|
516ab0 |
#endif
|
|
|
516ab0 |
|
|
|
516ab0 |
-struct substvar *addstdenv(struct substvar *sv)
|
|
|
516ab0 |
+static char *set_env_name(const char *prefix, const char *name, char *buf)
|
|
|
516ab0 |
+{
|
|
|
516ab0 |
+ size_t len;
|
|
|
516ab0 |
+
|
|
|
516ab0 |
+ len = strlen(name);
|
|
|
516ab0 |
+ if (prefix)
|
|
|
516ab0 |
+ len += strlen(prefix);
|
|
|
516ab0 |
+ len++;
|
|
|
516ab0 |
+
|
|
|
516ab0 |
+ if (len > MAX_ENV_NAME)
|
|
|
516ab0 |
+ return NULL;
|
|
|
516ab0 |
+
|
|
|
516ab0 |
+ if (!prefix)
|
|
|
516ab0 |
+ strcpy(buf, name);
|
|
|
516ab0 |
+ else {
|
|
|
516ab0 |
+ strcpy(buf, prefix);
|
|
|
516ab0 |
+ strcat(buf, name);
|
|
|
516ab0 |
+ }
|
|
|
516ab0 |
+ return buf;
|
|
|
516ab0 |
+}
|
|
|
516ab0 |
+
|
|
|
516ab0 |
+static struct substvar *do_macro_addvar(struct substvar *list,
|
|
|
516ab0 |
+ const char *prefix,
|
|
|
516ab0 |
+ const char *name,
|
|
|
516ab0 |
+ const char *val)
|
|
|
516ab0 |
+{
|
|
|
516ab0 |
+ char buf[MAX_ENV_NAME + 1];
|
|
|
516ab0 |
+ char *new;
|
|
|
516ab0 |
+ size_t len;
|
|
|
516ab0 |
+
|
|
|
516ab0 |
+ new = set_env_name(prefix, name, buf);
|
|
|
516ab0 |
+ if (new) {
|
|
|
516ab0 |
+ len = strlen(new);
|
|
|
516ab0 |
+ list = macro_addvar(list, new, len, val);
|
|
|
516ab0 |
+ }
|
|
|
516ab0 |
+ return list;
|
|
|
516ab0 |
+}
|
|
|
516ab0 |
+
|
|
|
516ab0 |
+static struct substvar *do_macro_removevar(struct substvar *list,
|
|
|
516ab0 |
+ const char *prefix,
|
|
|
516ab0 |
+ const char *name)
|
|
|
516ab0 |
+{
|
|
|
516ab0 |
+ char buf[MAX_ENV_NAME + 1];
|
|
|
516ab0 |
+ char *new;
|
|
|
516ab0 |
+ size_t len;
|
|
|
516ab0 |
+
|
|
|
516ab0 |
+ new = set_env_name(prefix, name, buf);
|
|
|
516ab0 |
+ if (new) {
|
|
|
516ab0 |
+ len = strlen(new);
|
|
|
516ab0 |
+ list = macro_removevar(list, new, len);
|
|
|
516ab0 |
+ }
|
|
|
516ab0 |
+ return list;
|
|
|
516ab0 |
+}
|
|
|
516ab0 |
+
|
|
|
516ab0 |
+struct substvar *addstdenv(struct substvar *sv, const char *prefix)
|
|
|
516ab0 |
{
|
|
|
516ab0 |
struct substvar *list = sv;
|
|
|
516ab0 |
struct thread_stdenv_vars *tsv;
|
|
|
516ab0 |
@@ -343,14 +398,14 @@ struct substvar *addstdenv(struct substv
|
|
|
516ab0 |
num = (long) tsv->uid;
|
|
|
516ab0 |
ret = sprintf(numbuf, "%ld", num);
|
|
|
516ab0 |
if (ret > 0)
|
|
|
516ab0 |
- list = macro_addvar(list, "UID", 3, numbuf);
|
|
|
516ab0 |
+ list = do_macro_addvar(list, prefix, "UID", numbuf);
|
|
|
516ab0 |
num = (long) tsv->gid;
|
|
|
516ab0 |
ret = sprintf(numbuf, "%ld", num);
|
|
|
516ab0 |
if (ret > 0)
|
|
|
516ab0 |
- list = macro_addvar(list, "GID", 3, numbuf);
|
|
|
516ab0 |
- list = macro_addvar(list, "USER", 4, tsv->user);
|
|
|
516ab0 |
- list = macro_addvar(list, "GROUP", 5, tsv->group);
|
|
|
516ab0 |
- list = macro_addvar(list, "HOME", 4, tsv->home);
|
|
|
516ab0 |
+ list = do_macro_addvar(list, prefix, "GID", numbuf);
|
|
|
516ab0 |
+ list = do_macro_addvar(list, prefix, "USER", tsv->user);
|
|
|
516ab0 |
+ list = do_macro_addvar(list, prefix, "GROUP", tsv->group);
|
|
|
516ab0 |
+ list = do_macro_addvar(list, prefix, "HOME", tsv->home);
|
|
|
516ab0 |
mv = macro_findvar(list, "HOST", 4);
|
|
|
516ab0 |
if (mv) {
|
|
|
516ab0 |
char *shost = strdup(mv->val);
|
|
|
516ab0 |
@@ -358,7 +413,8 @@ struct substvar *addstdenv(struct substv
|
|
|
516ab0 |
char *dot = strchr(shost, '.');
|
|
|
516ab0 |
if (dot)
|
|
|
516ab0 |
*dot = '\0';
|
|
|
516ab0 |
- list = macro_addvar(list, "SHOST", 5, shost);
|
|
|
516ab0 |
+ list = do_macro_addvar(list,
|
|
|
516ab0 |
+ prefix, "SHOST", shost);
|
|
|
516ab0 |
free(shost);
|
|
|
516ab0 |
}
|
|
|
516ab0 |
}
|
|
|
516ab0 |
@@ -366,16 +422,16 @@ struct substvar *addstdenv(struct substv
|
|
|
516ab0 |
return list;
|
|
|
516ab0 |
}
|
|
|
516ab0 |
|
|
|
516ab0 |
-struct substvar *removestdenv(struct substvar *sv)
|
|
|
516ab0 |
+struct substvar *removestdenv(struct substvar *sv, const char *prefix)
|
|
|
516ab0 |
{
|
|
|
516ab0 |
struct substvar *list = sv;
|
|
|
516ab0 |
|
|
|
516ab0 |
- list = macro_removevar(list, "UID", 3);
|
|
|
516ab0 |
- list = macro_removevar(list, "USER", 4);
|
|
|
516ab0 |
- list = macro_removevar(list, "HOME", 4);
|
|
|
516ab0 |
- list = macro_removevar(list, "GID", 3);
|
|
|
516ab0 |
- list = macro_removevar(list, "GROUP", 5);
|
|
|
516ab0 |
- list = macro_removevar(list, "SHOST", 5);
|
|
|
516ab0 |
+ list = do_macro_removevar(list, prefix, "UID");
|
|
|
516ab0 |
+ list = do_macro_removevar(list, prefix, "USER");
|
|
|
516ab0 |
+ list = do_macro_removevar(list, prefix, "HOME");
|
|
|
516ab0 |
+ list = do_macro_removevar(list, prefix, "GID");
|
|
|
516ab0 |
+ list = do_macro_removevar(list, prefix, "GROUP");
|
|
|
516ab0 |
+ list = do_macro_removevar(list, prefix, "SHOST");
|
|
|
516ab0 |
return list;
|
|
|
516ab0 |
}
|
|
|
516ab0 |
|
|
|
516ab0 |
--- autofs-5.0.7.orig/modules/lookup_program.c
|
|
|
516ab0 |
+++ autofs-5.0.7/modules/lookup_program.c
|
|
|
516ab0 |
@@ -181,7 +181,7 @@ static char *lookup_one(struct autofs_po
|
|
|
516ab0 |
if (ctxt->mapfmt && strcmp(ctxt->mapfmt, "MAPFMT_DEFAULT")) {
|
|
|
516ab0 |
struct parse_context *pctxt = (struct parse_context *) ctxt->parse->context;
|
|
|
516ab0 |
/* Add standard environment as seen by sun map parser */
|
|
|
516ab0 |
- pctxt->subst = addstdenv(pctxt->subst);
|
|
|
516ab0 |
+ pctxt->subst = addstdenv(pctxt->subst, "AUTOFS_");
|
|
|
516ab0 |
macro_setenv(pctxt->subst);
|
|
|
516ab0 |
}
|
|
|
516ab0 |
execl(ctxt->mapname, ctxt->mapname, name, NULL);
|
|
|
516ab0 |
--- autofs-5.0.7.orig/modules/parse_sun.c
|
|
|
516ab0 |
+++ autofs-5.0.7/modules/parse_sun.c
|
|
|
516ab0 |
@@ -1214,12 +1214,12 @@ int parse_mount(struct autofs_point *ap,
|
|
|
516ab0 |
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
|
|
|
516ab0 |
macro_lock();
|
|
|
516ab0 |
|
|
|
516ab0 |
- ctxt->subst = addstdenv(ctxt->subst);
|
|
|
516ab0 |
+ ctxt->subst = addstdenv(ctxt->subst, NULL);
|
|
|
516ab0 |
|
|
|
516ab0 |
mapent_len = expandsunent(mapent, NULL, name, ctxt->subst, slashify);
|
|
|
516ab0 |
if (mapent_len == 0) {
|
|
|
516ab0 |
error(ap->logopt, MODPREFIX "failed to expand map entry");
|
|
|
516ab0 |
- ctxt->subst = removestdenv(ctxt->subst);
|
|
|
516ab0 |
+ ctxt->subst = removestdenv(ctxt->subst, NULL);
|
|
|
516ab0 |
macro_unlock();
|
|
|
516ab0 |
pthread_setcancelstate(cur_state, NULL);
|
|
|
516ab0 |
return 1;
|
|
|
516ab0 |
@@ -1229,7 +1229,7 @@ int parse_mount(struct autofs_point *ap,
|
|
|
516ab0 |
if (!pmapent) {
|
|
|
516ab0 |
char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
|
|
|
516ab0 |
logerr(MODPREFIX "alloca: %s", estr);
|
|
|
516ab0 |
- ctxt->subst = removestdenv(ctxt->subst);
|
|
|
516ab0 |
+ ctxt->subst = removestdenv(ctxt->subst, NULL);
|
|
|
516ab0 |
macro_unlock();
|
|
|
516ab0 |
pthread_setcancelstate(cur_state, NULL);
|
|
|
516ab0 |
return 1;
|
|
|
516ab0 |
@@ -1237,7 +1237,7 @@ int parse_mount(struct autofs_point *ap,
|
|
|
516ab0 |
pmapent[mapent_len] = '\0';
|
|
|
516ab0 |
|
|
|
516ab0 |
expandsunent(mapent, pmapent, name, ctxt->subst, slashify);
|
|
|
516ab0 |
- ctxt->subst = removestdenv(ctxt->subst);
|
|
|
516ab0 |
+ ctxt->subst = removestdenv(ctxt->subst, NULL);
|
|
|
516ab0 |
|
|
|
516ab0 |
macro_unlock();
|
|
|
516ab0 |
pthread_setcancelstate(cur_state, NULL);
|