Blame SOURCES/autofs-5.0.7-add-std-vars-to-program-map-invocation.patch

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