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

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