Blob Blame History Raw
autofs-5.0.7 - add std vars to program map invocation

From: Ian Kent <ikent@redhat.com>

Program maps currently don't have the standard macro variables set
in the environemt when they run.

Also, program maps aren't necessarily executed within a shell so
setting the standard variables in the environment needs to be done
the same way it's done by the Sun map parser.
---
 CHANGELOG                |    1 
 include/mounts.h         |    3 ++
 lib/mounts.c             |   51 +++++++++++++++++++++++++++++++++++++++++++++++
 modules/lookup_program.c |    2 +
 modules/parse_sun.c      |   51 -----------------------------------------------
 5 files changed, 57 insertions(+), 51 deletions(-)

--- autofs-5.0.7.orig/CHANGELOG
+++ autofs-5.0.7/CHANGELOG
@@ -79,6 +79,7 @@
 - setup program map env from macro table.
 - add short host name standard marco variable.
 - fix symlink fail message in mount_bind.c.
+- add std vars to program map invocation.
 
 25/07/2012 autofs-5.0.7
 =======================
--- autofs-5.0.7.orig/include/mounts.h
+++ autofs-5.0.7/include/mounts.h
@@ -85,6 +85,9 @@ unsigned int linux_version_code(void);
 int check_nfs_mount_version(struct nfs_mount_vers *, struct nfs_mount_vers *);
 extern unsigned int nfs_mount_uses_string_options;
 
+struct substvar *addstdenv(struct substvar *sv);
+struct substvar *removestdenv(struct substvar *sv);
+
 unsigned int query_kproto_ver(void);
 unsigned int get_kver_major(void);
 unsigned int get_kver_minor(void);
--- autofs-5.0.7.orig/lib/mounts.c
+++ autofs-5.0.7/lib/mounts.c
@@ -303,6 +303,57 @@ int check_nfs_mount_version(struct nfs_m
 }
 #endif
 
+struct substvar *addstdenv(struct substvar *sv)
+{
+	struct substvar *list = sv;
+	struct thread_stdenv_vars *tsv;
+	char numbuf[16];
+
+	tsv = pthread_getspecific(key_thread_stdenv_vars);
+	if (tsv) {
+		const struct substvar *mv;
+		int ret;
+		long num;
+
+		num = (long) tsv->uid;
+		ret = sprintf(numbuf, "%ld", num);
+		if (ret > 0)
+			list = macro_addvar(list, "UID", 3, numbuf);
+		num = (long) tsv->gid;
+		ret = sprintf(numbuf, "%ld", num);
+		if (ret > 0)
+			list = macro_addvar(list, "GID", 3, numbuf);
+		list = macro_addvar(list, "USER", 4, tsv->user);
+		list = macro_addvar(list, "GROUP", 5, tsv->group);
+		list = macro_addvar(list, "HOME", 4, tsv->home);
+		mv = macro_findvar(list, "HOST", 4);
+		if (mv) {
+			char *shost = strdup(mv->val);
+			if (shost) {
+				char *dot = strchr(shost, '.');
+				if (dot)
+					*dot = '\0';
+				list = macro_addvar(list, "SHOST", 5, shost);
+				free(shost);
+			}
+		}
+	}
+	return list;
+}
+
+struct substvar *removestdenv(struct substvar *sv)
+{
+	struct substvar *list = sv;
+
+	list = macro_removevar(list, "UID", 3);
+	list = macro_removevar(list, "USER", 4);
+	list = macro_removevar(list, "HOME", 4);
+	list = macro_removevar(list, "GID", 3);
+	list = macro_removevar(list, "GROUP", 5);
+	list = macro_removevar(list, "SHOST", 5);
+	return list;
+}
+
 /*
  * Make common autofs mount options string
  */
--- autofs-5.0.7.orig/modules/lookup_program.c
+++ autofs-5.0.7/modules/lookup_program.c
@@ -271,6 +271,8 @@ int lookup_mount(struct autofs_point *ap
 		 */
 		if (ctxt->mapfmt && strcmp(ctxt->mapfmt, "MAPFMT_DEFAULT")) {
 			struct parse_context *pctxt = (struct parse_context *) ctxt->parse->context;
+			/* Add standard environment as seen by sun map parser */
+			pctxt->subst = addstdenv(pctxt->subst);
 			macro_setenv(pctxt->subst);
 		}
 		execl(ctxt->mapname, ctxt->mapname, name, NULL);
--- autofs-5.0.7.orig/modules/parse_sun.c
+++ autofs-5.0.7/modules/parse_sun.c
@@ -99,57 +99,6 @@ static void kill_context(struct parse_co
 	free(ctxt);
 }
 
-static struct substvar *addstdenv(struct substvar *sv)
-{
-	struct substvar *list = sv;
-	struct thread_stdenv_vars *tsv;
-	char numbuf[16];
-
-	tsv = pthread_getspecific(key_thread_stdenv_vars);
-	if (tsv) {
-		struct substvar *mv;
-		int ret;
-		long num;
-
-		num = (long) tsv->uid;
-		ret = sprintf(numbuf, "%ld", num);
-		if (ret > 0)
-			list = macro_addvar(list, "UID", 3, numbuf);
-		num = (long) tsv->gid;
-		ret = sprintf(numbuf, "%ld", num);
-		if (ret > 0)
-			list = macro_addvar(list, "GID", 3, numbuf);
-		list = macro_addvar(list, "USER", 4, tsv->user);
-		list = macro_addvar(list, "GROUP", 5, tsv->group);
-		list = macro_addvar(list, "HOME", 4, tsv->home);
-		mv = macro_findvar(list, "HOST", 4);
-		if (mv) {
-			char *shost = strdup(mv->val);
-			if (shost) {
-				char *dot = strchr(shost, '.');
-				if (dot)
-					*dot = '\0';
-				list = macro_addvar(list, "SHOST", 5, shost);
-				free(shost);
-			}
-		}
-	}
-	return list;
-}
-
-static struct substvar *removestdenv(struct substvar *sv)
-{
-	struct substvar *list = sv;
-
-	list = macro_removevar(list, "UID", 3);
-	list = macro_removevar(list, "USER", 4);
-	list = macro_removevar(list, "HOME", 4);
-	list = macro_removevar(list, "GID", 3);
-	list = macro_removevar(list, "GROUP", 5);
-	list = macro_removevar(list, "SHOST", 5);
-	return list;
-}
-
 /* 
  * $- and &-expand a Sun-style map entry and return the length of the entry.
  * If "dst" is NULL, just count the length.