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

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