|
|
6bbd11 |
autofs-5.0.7 - setup program map env from macro table
|
|
|
6bbd11 |
|
|
|
6bbd11 |
From: Ian Kent <raven@themaw.net>
|
|
|
6bbd11 |
|
|
|
6bbd11 |
The ability to pass parameters to program maps, in some way, is needed.
|
|
|
6bbd11 |
Standard autofs specifies that program maps have one argument so passing
|
|
|
6bbd11 |
parameters as arguments shouldn't be done.
|
|
|
6bbd11 |
|
|
|
6bbd11 |
This patch sets the existing macro table definitions (for both global and
|
|
|
6bbd11 |
local table) as environment variables before calling the map. The values
|
|
|
6bbd11 |
are not checked after return so, at this stage, program maps can't change
|
|
|
6bbd11 |
macro definitions.
|
|
|
6bbd11 |
---
|
|
|
6bbd11 |
CHANGELOG | 1 +
|
|
|
6bbd11 |
include/macros.h | 1 +
|
|
|
6bbd11 |
lib/macros.c | 28 ++++++++++++++++++++++++++++
|
|
|
6bbd11 |
modules/lookup_program.c | 20 ++++++++++++++++++++
|
|
|
6bbd11 |
4 files changed, 50 insertions(+)
|
|
|
6bbd11 |
|
|
|
6bbd11 |
--- autofs-5.0.7.orig/CHANGELOG
|
|
|
6bbd11 |
+++ autofs-5.0.7/CHANGELOG
|
|
|
6bbd11 |
@@ -76,6 +76,7 @@
|
|
|
6bbd11 |
- fix options compare.
|
|
|
6bbd11 |
- fix fix options compare.
|
|
|
6bbd11 |
- fix max() declaration.
|
|
|
6bbd11 |
+- setup program map env from macro table.
|
|
|
6bbd11 |
|
|
|
6bbd11 |
25/07/2012 autofs-5.0.7
|
|
|
6bbd11 |
=======================
|
|
|
6bbd11 |
--- autofs-5.0.7.orig/include/macros.h
|
|
|
6bbd11 |
+++ autofs-5.0.7/include/macros.h
|
|
|
6bbd11 |
@@ -40,5 +40,6 @@ void macro_free_global_table(void);
|
|
|
6bbd11 |
void macro_free_table(struct substvar *table);
|
|
|
6bbd11 |
const struct substvar *
|
|
|
6bbd11 |
macro_findvar(const struct substvar *table, const char *str, int len);
|
|
|
6bbd11 |
+void macro_setenv(struct substvar *table);
|
|
|
6bbd11 |
|
|
|
6bbd11 |
#endif
|
|
|
6bbd11 |
--- autofs-5.0.7.orig/lib/macros.c
|
|
|
6bbd11 |
+++ autofs-5.0.7/lib/macros.c
|
|
|
6bbd11 |
@@ -421,3 +421,31 @@ macro_findvar(const struct substvar *tab
|
|
|
6bbd11 |
return NULL;
|
|
|
6bbd11 |
}
|
|
|
6bbd11 |
|
|
|
6bbd11 |
+/* Set environment from macro variable table */
|
|
|
6bbd11 |
+void macro_setenv(struct substvar *table)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ const struct substvar *sv = system_table;
|
|
|
6bbd11 |
+ const struct substvar *lv = table;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ /*
|
|
|
6bbd11 |
+ * First set environment from global table, matching local
|
|
|
6bbd11 |
+ * variables will overwrite these.
|
|
|
6bbd11 |
+ */
|
|
|
6bbd11 |
+ while (sv) {
|
|
|
6bbd11 |
+ if (sv->def)
|
|
|
6bbd11 |
+ setenv(sv->def, sv->val, 1);
|
|
|
6bbd11 |
+ sv = sv->next;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ error(LOGOPT_ANY, "table %p", table);
|
|
|
6bbd11 |
+ dump_table(table);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ /* Next set environment from the local table */
|
|
|
6bbd11 |
+ while (lv) {
|
|
|
6bbd11 |
+ if (lv->def)
|
|
|
6bbd11 |
+ setenv(lv->def, lv->val, 1);
|
|
|
6bbd11 |
+ lv = lv->next;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ return;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
--- autofs-5.0.7.orig/modules/lookup_program.c
|
|
|
6bbd11 |
+++ autofs-5.0.7/modules/lookup_program.c
|
|
|
6bbd11 |
@@ -36,9 +36,17 @@
|
|
|
6bbd11 |
|
|
|
6bbd11 |
struct lookup_context {
|
|
|
6bbd11 |
const char *mapname;
|
|
|
6bbd11 |
+ char *mapfmt;
|
|
|
6bbd11 |
struct parse_mod *parse;
|
|
|
6bbd11 |
};
|
|
|
6bbd11 |
|
|
|
6bbd11 |
+struct parse_context {
|
|
|
6bbd11 |
+ char *optstr; /* Mount options */
|
|
|
6bbd11 |
+ char *macros; /* Map wide macro defines */
|
|
|
6bbd11 |
+ struct substvar *subst; /* $-substitutions */
|
|
|
6bbd11 |
+ int slashify_colons; /* Change colons to slashes? */
|
|
|
6bbd11 |
+};
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
int lookup_version = AUTOFS_LOOKUP_VERSION; /* Required by protocol */
|
|
|
6bbd11 |
|
|
|
6bbd11 |
int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **context)
|
|
|
6bbd11 |
@@ -79,6 +87,8 @@ int lookup_init(const char *mapfmt, int
|
|
|
6bbd11 |
if (!mapfmt)
|
|
|
6bbd11 |
mapfmt = MAPFMT_DEFAULT;
|
|
|
6bbd11 |
|
|
|
6bbd11 |
+ ctxt->mapfmt = strdup(mapfmt);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
ctxt->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
|
|
|
6bbd11 |
if (!ctxt->parse) {
|
|
|
6bbd11 |
logmsg(MODPREFIX "failed to open parse context");
|
|
|
6bbd11 |
@@ -255,6 +265,14 @@ int lookup_mount(struct autofs_point *ap
|
|
|
6bbd11 |
warn(ap->logopt,
|
|
|
6bbd11 |
MODPREFIX "failed to set PWD to %s for map %s",
|
|
|
6bbd11 |
ap->path, ctxt->mapname);
|
|
|
6bbd11 |
+ /*
|
|
|
6bbd11 |
+ * MAPFMT_DEFAULT must be "sun" for ->parse_init() to have setup
|
|
|
6bbd11 |
+ * the macro table.
|
|
|
6bbd11 |
+ */
|
|
|
6bbd11 |
+ if (ctxt->mapfmt && strcmp(ctxt->mapfmt, "MAPFMT_DEFAULT")) {
|
|
|
6bbd11 |
+ struct parse_context *pctxt = (struct parse_context *) ctxt->parse->context;
|
|
|
6bbd11 |
+ macro_setenv(pctxt->subst);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
execl(ctxt->mapname, ctxt->mapname, name, NULL);
|
|
|
6bbd11 |
_exit(255); /* execl() failed */
|
|
|
6bbd11 |
}
|
|
|
6bbd11 |
@@ -448,6 +466,8 @@ int lookup_done(void *context)
|
|
|
6bbd11 |
{
|
|
|
6bbd11 |
struct lookup_context *ctxt = (struct lookup_context *) context;
|
|
|
6bbd11 |
int rv = close_parse(ctxt->parse);
|
|
|
6bbd11 |
+ if (ctxt->mapfmt)
|
|
|
6bbd11 |
+ free(ctxt->mapfmt);
|
|
|
6bbd11 |
free(ctxt);
|
|
|
6bbd11 |
return rv;
|
|
|
6bbd11 |
}
|