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

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