|
|
6bbd11 |
autofs-5.0.9 - amd lookup add parse_amd.c
|
|
|
6bbd11 |
|
|
|
6bbd11 |
From: Ian Kent <raven@themaw.net>
|
|
|
6bbd11 |
|
|
|
6bbd11 |
Add a yacc parser and an autofs parser module for amd format
|
|
|
6bbd11 |
maps.
|
|
|
6bbd11 |
---
|
|
|
6bbd11 |
include/automount.h | 1
|
|
|
6bbd11 |
include/mounts.h | 6
|
|
|
6bbd11 |
include/parse_amd.h | 54 ++
|
|
|
6bbd11 |
lib/mounts.c | 81 +++
|
|
|
6bbd11 |
modules/Makefile | 21 -
|
|
|
6bbd11 |
modules/amd_parse.y | 511 ++++++++++++++++++++++++
|
|
|
6bbd11 |
modules/amd_tok.l | 316 +++++++++++++++
|
|
|
6bbd11 |
modules/parse_amd.c | 1081 ++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
6bbd11 |
8 files changed, 2069 insertions(+), 2 deletions(-)
|
|
|
6bbd11 |
create mode 100644 include/parse_amd.h
|
|
|
6bbd11 |
create mode 100644 modules/amd_parse.y
|
|
|
6bbd11 |
create mode 100644 modules/amd_tok.l
|
|
|
6bbd11 |
create mode 100644 modules/parse_amd.c
|
|
|
6bbd11 |
|
|
|
6bbd11 |
--- autofs-5.0.7.orig/include/automount.h
|
|
|
6bbd11 |
+++ autofs-5.0.7/include/automount.h
|
|
|
6bbd11 |
@@ -34,6 +34,7 @@
|
|
|
6bbd11 |
#include "parse_subs.h"
|
|
|
6bbd11 |
#include "mounts.h"
|
|
|
6bbd11 |
#include "dev-ioctl-lib.h"
|
|
|
6bbd11 |
+#include "parse_amd.h"
|
|
|
6bbd11 |
|
|
|
6bbd11 |
#ifdef WITH_DMALLOC
|
|
|
6bbd11 |
#include <dmalloc.h>
|
|
|
6bbd11 |
--- autofs-5.0.7.orig/include/mounts.h
|
|
|
6bbd11 |
+++ autofs-5.0.7/include/mounts.h
|
|
|
6bbd11 |
@@ -85,10 +85,16 @@ 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 amd_entry;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
struct substvar *addstdenv(struct substvar *sv);
|
|
|
6bbd11 |
struct substvar *removestdenv(struct substvar *sv);
|
|
|
6bbd11 |
void add_std_amd_vars(struct substvar *sv);
|
|
|
6bbd11 |
void remove_std_amd_vars(void);
|
|
|
6bbd11 |
+struct amd_entry *new_amd_entry(const struct substvar *sv);
|
|
|
6bbd11 |
+void clear_amd_entry(struct amd_entry *entry);
|
|
|
6bbd11 |
+void free_amd_entry(struct amd_entry *entry);
|
|
|
6bbd11 |
+void free_amd_entry_list(struct list_head *entries);
|
|
|
6bbd11 |
|
|
|
6bbd11 |
unsigned int query_kproto_ver(void);
|
|
|
6bbd11 |
unsigned int get_kver_major(void);
|
|
|
6bbd11 |
--- /dev/null
|
|
|
6bbd11 |
+++ autofs-5.0.7/include/parse_amd.h
|
|
|
6bbd11 |
@@ -0,0 +1,54 @@
|
|
|
6bbd11 |
+/* ----------------------------------------------------------------------- *
|
|
|
6bbd11 |
+ *
|
|
|
6bbd11 |
+ * Copyright 2004-2006 Ian Kent <raven@themaw.net>
|
|
|
6bbd11 |
+ * Copyright 2013 Red Hat, Inc.
|
|
|
6bbd11 |
+ * All rights reserved.
|
|
|
6bbd11 |
+ *
|
|
|
6bbd11 |
+ * This program is free software; you can redistribute it and/or modify
|
|
|
6bbd11 |
+ * it under the terms of the GNU General Public License as published by
|
|
|
6bbd11 |
+ * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
|
|
|
6bbd11 |
+ * USA; either version 2 of the License, or (at your option) any later
|
|
|
6bbd11 |
+ * version; incorporated herein by reference.
|
|
|
6bbd11 |
+ *
|
|
|
6bbd11 |
+ * ----------------------------------------------------------------------- */
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#ifndef PARSE_AMD_H
|
|
|
6bbd11 |
+#define PARSE_AMD_H
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#define AMD_MOUNT_TYPE_NONE 0x00000000
|
|
|
6bbd11 |
+#define AMD_MOUNT_TYPE_AUTO 0x00000001
|
|
|
6bbd11 |
+#define AMD_MOUNT_TYPE_NFS 0x00000002
|
|
|
6bbd11 |
+#define AMD_MOUNT_TYPE_LINK 0x00000004
|
|
|
6bbd11 |
+#define AMD_MOUNT_TYPE_HOST 0x00000008
|
|
|
6bbd11 |
+#define AMD_MOUNT_TYPE_MASK 0x0000ffff
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#define AMD_ENTRY_CUT 0x00010000
|
|
|
6bbd11 |
+#define AMD_ENTRY_MASK 0x00ff0000
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#define AMD_DEFAULTS_MERGE 0x01000000
|
|
|
6bbd11 |
+#define AMD_DEFAULTS_RESET 0x02000000
|
|
|
6bbd11 |
+#define AMD_DEFAULTS_MASK 0xff000000
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+struct amd_entry {
|
|
|
6bbd11 |
+ char *path;
|
|
|
6bbd11 |
+ unsigned long flags;
|
|
|
6bbd11 |
+ char *type;
|
|
|
6bbd11 |
+ char *map_type;
|
|
|
6bbd11 |
+ char *pref;
|
|
|
6bbd11 |
+ char *fs;
|
|
|
6bbd11 |
+ char *rhost;
|
|
|
6bbd11 |
+ char *rfs;
|
|
|
6bbd11 |
+ char *opts;
|
|
|
6bbd11 |
+ char *addopts;
|
|
|
6bbd11 |
+ char *remopts;
|
|
|
6bbd11 |
+ char *sublink;
|
|
|
6bbd11 |
+ struct selector *selector;
|
|
|
6bbd11 |
+ struct list_head list;
|
|
|
6bbd11 |
+ struct list_head entries;
|
|
|
6bbd11 |
+ struct list_head ext_mount;
|
|
|
6bbd11 |
+};
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+int amd_parse_list(struct autofs_point *,
|
|
|
6bbd11 |
+ const char *, struct list_head *, struct substvar **);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#endif
|
|
|
6bbd11 |
--- autofs-5.0.7.orig/lib/mounts.c
|
|
|
6bbd11 |
+++ autofs-5.0.7/lib/mounts.c
|
|
|
6bbd11 |
@@ -442,6 +442,87 @@ void remove_std_amd_vars(void)
|
|
|
6bbd11 |
return;
|
|
|
6bbd11 |
}
|
|
|
6bbd11 |
|
|
|
6bbd11 |
+struct amd_entry *new_amd_entry(const struct substvar *sv)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ struct amd_entry *new;
|
|
|
6bbd11 |
+ const struct substvar *v;
|
|
|
6bbd11 |
+ char *path;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ v = macro_findvar(sv, "path", 4);
|
|
|
6bbd11 |
+ if (!v)
|
|
|
6bbd11 |
+ return NULL;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ path = strdup(v->val);
|
|
|
6bbd11 |
+ if (!path)
|
|
|
6bbd11 |
+ return NULL;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ new = malloc(sizeof(struct amd_entry));
|
|
|
6bbd11 |
+ if (!new) {
|
|
|
6bbd11 |
+ free(path);
|
|
|
6bbd11 |
+ return NULL;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ memset(new, 0, sizeof(*new));
|
|
|
6bbd11 |
+ new->path = path;
|
|
|
6bbd11 |
+ INIT_LIST_HEAD(&new->list);
|
|
|
6bbd11 |
+ INIT_LIST_HEAD(&new->entries);
|
|
|
6bbd11 |
+ INIT_LIST_HEAD(&new->ext_mount);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ return new;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+void clear_amd_entry(struct amd_entry *entry)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ if (!entry)
|
|
|
6bbd11 |
+ return;
|
|
|
6bbd11 |
+ if (entry->path)
|
|
|
6bbd11 |
+ free(entry->path);
|
|
|
6bbd11 |
+ if (entry->map_type)
|
|
|
6bbd11 |
+ free(entry->map_type);
|
|
|
6bbd11 |
+ if (entry->pref)
|
|
|
6bbd11 |
+ free(entry->pref);
|
|
|
6bbd11 |
+ if (entry->fs)
|
|
|
6bbd11 |
+ free(entry->fs);
|
|
|
6bbd11 |
+ if (entry->rhost)
|
|
|
6bbd11 |
+ free(entry->rhost);
|
|
|
6bbd11 |
+ if (entry->rfs)
|
|
|
6bbd11 |
+ free(entry->rfs);
|
|
|
6bbd11 |
+ if (entry->opts)
|
|
|
6bbd11 |
+ free(entry->opts);
|
|
|
6bbd11 |
+ if (entry->addopts)
|
|
|
6bbd11 |
+ free(entry->addopts);
|
|
|
6bbd11 |
+ if (entry->remopts)
|
|
|
6bbd11 |
+ free(entry->remopts);
|
|
|
6bbd11 |
+ if (entry->sublink)
|
|
|
6bbd11 |
+ free(entry->sublink);
|
|
|
6bbd11 |
+ if (entry->selector)
|
|
|
6bbd11 |
+ free_selector(entry->selector);
|
|
|
6bbd11 |
+ return;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+void free_amd_entry(struct amd_entry *entry)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ clear_amd_entry(entry);
|
|
|
6bbd11 |
+ free(entry);
|
|
|
6bbd11 |
+ return;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+void free_amd_entry_list(struct list_head *entries)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ if (!list_empty(entries)) {
|
|
|
6bbd11 |
+ struct list_head *head = entries;
|
|
|
6bbd11 |
+ struct amd_entry *this;
|
|
|
6bbd11 |
+ struct list_head *p;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ p = head->next;
|
|
|
6bbd11 |
+ while (p != head) {
|
|
|
6bbd11 |
+ this = list_entry(p, struct amd_entry, list);
|
|
|
6bbd11 |
+ p = p->next;
|
|
|
6bbd11 |
+ free_amd_entry(this);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
/*
|
|
|
6bbd11 |
* Make common autofs mount options string
|
|
|
6bbd11 |
*/
|
|
|
6bbd11 |
--- autofs-5.0.7.orig/modules/Makefile
|
|
|
6bbd11 |
+++ autofs-5.0.7/modules/Makefile
|
|
|
6bbd11 |
@@ -7,16 +7,18 @@ include ../Makefile.rules
|
|
|
6bbd11 |
|
|
|
6bbd11 |
SRCS := lookup_file.c lookup_program.c lookup_userhome.c \
|
|
|
6bbd11 |
lookup_multi.c lookup_hosts.c lookup_dir.c \
|
|
|
6bbd11 |
- parse_sun.c \
|
|
|
6bbd11 |
+ parse_sun.c parse_amd.c \
|
|
|
6bbd11 |
mount_generic.c mount_nfs.c mount_afs.c mount_autofs.c \
|
|
|
6bbd11 |
mount_changer.c mount_bind.c
|
|
|
6bbd11 |
|
|
|
6bbd11 |
MODS := lookup_file.so lookup_program.so lookup_userhome.so \
|
|
|
6bbd11 |
lookup_multi.so lookup_hosts.so lookup_dir.so \
|
|
|
6bbd11 |
- parse_sun.so \
|
|
|
6bbd11 |
+ parse_sun.so parse_amd.so \
|
|
|
6bbd11 |
mount_generic.so mount_nfs.so mount_afs.so mount_autofs.so \
|
|
|
6bbd11 |
mount_changer.so mount_bind.so
|
|
|
6bbd11 |
|
|
|
6bbd11 |
+YACCSRC = amd_tok.c amd_parse.tab.c amd_parse.tab.h \
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
ifeq ($(EXT2FS), 1)
|
|
|
6bbd11 |
SRCS += mount_ext2.c
|
|
|
6bbd11 |
MODS += mount_ext2.so
|
|
|
6bbd11 |
@@ -94,6 +96,21 @@ else ifeq ($(EXT4FS), 1)
|
|
|
6bbd11 |
mv $(INSTALLROOT)$(autofslibdir)/mount_ext2.so $(INSTALLROOT)$(autofslibdir)/mount_ext4.so
|
|
|
6bbd11 |
endif
|
|
|
6bbd11 |
|
|
|
6bbd11 |
+amd_tok.c: amd_tok.l
|
|
|
6bbd11 |
+ $(LEX) -o$@ -Pamd_ $?
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+amd_tok.o: amd_tok.c amd_parse.tab.h
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+amd_parse.tab.c amd_parse.tab.h: amd_parse.y
|
|
|
6bbd11 |
+ $(YACC) -v -d -p amd_ -b amd_parse $?
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+amd_parse.tab.o: amd_parse.tab.c amd_parse.tab.h
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+parse_amd.so: parse_amd.c amd_parse.tab.o amd_tok.o
|
|
|
6bbd11 |
+ $(CC) $(LDFLAGS) $(SOLDFLAGS) $(CFLAGS) -o parse_amd.so \
|
|
|
6bbd11 |
+ parse_amd.c amd_parse.tab.o amd_tok.o $(AUTOFS_LIB) $(LIBS)
|
|
|
6bbd11 |
+ $(STRIP) parse_amd.so
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
#
|
|
|
6bbd11 |
# Ad hoc compilation rules for modules which need auxilliary libraries
|
|
|
6bbd11 |
#
|
|
|
6bbd11 |
--- /dev/null
|
|
|
6bbd11 |
+++ autofs-5.0.7/modules/amd_parse.y
|
|
|
6bbd11 |
@@ -0,0 +1,511 @@
|
|
|
6bbd11 |
+%{
|
|
|
6bbd11 |
+/* ----------------------------------------------------------------------- *
|
|
|
6bbd11 |
+ *
|
|
|
6bbd11 |
+ * Copyright 2013 Ian Kent <raven@themaw.net>
|
|
|
6bbd11 |
+ * Copyright 2013 Red Hat, Inc.
|
|
|
6bbd11 |
+ * All rights reserved.
|
|
|
6bbd11 |
+ *
|
|
|
6bbd11 |
+ * This program is free software; you can redistribute it and/or modify
|
|
|
6bbd11 |
+ * it under the terms of the GNU General Public License as published by
|
|
|
6bbd11 |
+ * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
|
|
|
6bbd11 |
+ * USA; either version 2 of the License, or (at your option) any later
|
|
|
6bbd11 |
+ * version.
|
|
|
6bbd11 |
+ *
|
|
|
6bbd11 |
+ * This program is distributed in the hope that it will be useful,
|
|
|
6bbd11 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
6bbd11 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
6bbd11 |
+ * GNU General Public License for more details.
|
|
|
6bbd11 |
+ *
|
|
|
6bbd11 |
+ * ----------------------------------------------------------------------- */
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#include <stdio.h>
|
|
|
6bbd11 |
+#include <string.h>
|
|
|
6bbd11 |
+#include <stdlib.h>
|
|
|
6bbd11 |
+#include <stdarg.h>
|
|
|
6bbd11 |
+#include <ctype.h>
|
|
|
6bbd11 |
+#include <sys/ioctl.h>
|
|
|
6bbd11 |
+#include <syslog.h>
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#include "automount.h"
|
|
|
6bbd11 |
+#include "parse_amd.h"
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#define MAX_OPTS_LEN 1024
|
|
|
6bbd11 |
+#define MAX_ERR_LEN 512
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static pthread_mutex_t parse_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+extern FILE *amd_in;
|
|
|
6bbd11 |
+extern char *amd_text;
|
|
|
6bbd11 |
+extern int amd_lex(void);
|
|
|
6bbd11 |
+extern void amd_set_scan_buffer(const char *);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static char *amd_strdup(char *);
|
|
|
6bbd11 |
+static void local_init_vars(void);
|
|
|
6bbd11 |
+static void local_free_vars(void);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static int amd_error(const char *s);
|
|
|
6bbd11 |
+static int amd_notify(const char *s);
|
|
|
6bbd11 |
+static int amd_msg(const char *s);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static int add_location(void);
|
|
|
6bbd11 |
+static int make_selector(char *name,
|
|
|
6bbd11 |
+ char *value1, char *value2,
|
|
|
6bbd11 |
+ unsigned int compare);
|
|
|
6bbd11 |
+static void add_selector(struct selector *selector);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static struct amd_entry entry;
|
|
|
6bbd11 |
+static struct list_head *entries;
|
|
|
6bbd11 |
+static struct autofs_point *pap;
|
|
|
6bbd11 |
+struct substvar *psv;
|
|
|
6bbd11 |
+static char opts[MAX_OPTS_LEN];
|
|
|
6bbd11 |
+static void prepend_opt(char *, char *);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#define YYDEBUG 0
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#ifndef YYENABLE_NLS
|
|
|
6bbd11 |
+#define YYENABLE_NLS 0
|
|
|
6bbd11 |
+#endif
|
|
|
6bbd11 |
+#ifndef YYLTYPE_IS_TRIVIAL
|
|
|
6bbd11 |
+#define YYLTYPE_IS_TRIVIAL 0
|
|
|
6bbd11 |
+#endif
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#if YYDEBUG
|
|
|
6bbd11 |
+static int amd_fprintf(FILE *, char *, ...);
|
|
|
6bbd11 |
+#undef YYFPRINTF
|
|
|
6bbd11 |
+#define YYFPRINTF amd_fprintf
|
|
|
6bbd11 |
+#endif
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+%}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+%union {
|
|
|
6bbd11 |
+ char strtype[2048];
|
|
|
6bbd11 |
+ int inttype;
|
|
|
6bbd11 |
+ long longtype;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+%token COMMENT
|
|
|
6bbd11 |
+%token SEPERATOR
|
|
|
6bbd11 |
+%token SPACE
|
|
|
6bbd11 |
+%token HYPHEN
|
|
|
6bbd11 |
+%token IS_EQUAL
|
|
|
6bbd11 |
+%token CUT
|
|
|
6bbd11 |
+%token NOT_EQUAL
|
|
|
6bbd11 |
+%token COMMA
|
|
|
6bbd11 |
+%token OPTION_ASSIGN
|
|
|
6bbd11 |
+%token NILL
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+%token <strtype> MAP_OPTION
|
|
|
6bbd11 |
+%token <strtype> MAP_TYPE
|
|
|
6bbd11 |
+%token <strtype> FS_TYPE
|
|
|
6bbd11 |
+%token <strtype> FS_OPTION
|
|
|
6bbd11 |
+%token <strtype> FS_OPT_VALUE
|
|
|
6bbd11 |
+%token <strtype> MNT_OPTION
|
|
|
6bbd11 |
+%token <strtype> SELECTOR
|
|
|
6bbd11 |
+%token <strtype> SELECTOR_VALUE
|
|
|
6bbd11 |
+%token <strtype> OPTION
|
|
|
6bbd11 |
+%token <strtype> MACRO
|
|
|
6bbd11 |
+%token <strtype> OTHER
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+%type <strtype> options
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+%start file
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+%%
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+file: {
|
|
|
6bbd11 |
+#if YYDEBUG != 0
|
|
|
6bbd11 |
+ amd_debug = YYDEBUG;
|
|
|
6bbd11 |
+#endif
|
|
|
6bbd11 |
+ memset(opts, 0, sizeof(opts));
|
|
|
6bbd11 |
+ } line
|
|
|
6bbd11 |
+ ;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+line:
|
|
|
6bbd11 |
+ | location_selection_list
|
|
|
6bbd11 |
+ ;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+location_selection_list: location
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ if (!add_location()) {
|
|
|
6bbd11 |
+ amd_msg("failed to allocate new location");
|
|
|
6bbd11 |
+ YYABORT;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ | location_selection_list SPACE location
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ if (!add_location()) {
|
|
|
6bbd11 |
+ amd_msg("failed to allocate new location");
|
|
|
6bbd11 |
+ YYABORT;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ | location_selection_list SPACE CUT SPACE location
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ entry.flags |= AMD_ENTRY_CUT;
|
|
|
6bbd11 |
+ if (!add_location()) {
|
|
|
6bbd11 |
+ amd_msg("failed to allocate new location");
|
|
|
6bbd11 |
+ YYABORT;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ ;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+location: location_entry
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ | HYPHEN location_entry
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ entry.flags |= AMD_DEFAULTS_MERGE;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ | HYPHEN
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ entry.flags |= AMD_DEFAULTS_RESET;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ ;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+location_entry: selector_or_option
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ | location_entry SEPERATOR selector_or_option
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ | location_entry SEPERATOR
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ ;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+selector_or_option: selection
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ | option_assignment
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ | OTHER
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ amd_notify($1);
|
|
|
6bbd11 |
+ YYABORT;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ ;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+selection: SELECTOR IS_EQUAL SELECTOR_VALUE
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ if (!make_selector($1, $3, NULL, SEL_TYPE_EQUAL)) {
|
|
|
6bbd11 |
+ amd_notify($1);
|
|
|
6bbd11 |
+ YYABORT;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ | SELECTOR NOT_EQUAL SELECTOR_VALUE
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ if (!make_selector($1, $3, NULL, SEL_TYPE_NOTEQUAL)) {
|
|
|
6bbd11 |
+ amd_notify($1);
|
|
|
6bbd11 |
+ YYABORT;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ ;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+option_assignment: MAP_OPTION OPTION_ASSIGN FS_TYPE
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ if (!strcmp($3, "auto")) {
|
|
|
6bbd11 |
+ entry.flags |= AMD_MOUNT_TYPE_AUTO;
|
|
|
6bbd11 |
+ entry.type = amd_strdup($3);
|
|
|
6bbd11 |
+ } else if (!strcmp($3, "nfs") ||
|
|
|
6bbd11 |
+ !strcmp($3, "nfs4")) {
|
|
|
6bbd11 |
+ entry.flags |= AMD_MOUNT_TYPE_NFS;
|
|
|
6bbd11 |
+ entry.type = amd_strdup($3);
|
|
|
6bbd11 |
+ } else if (!strcmp($3, "link")) {
|
|
|
6bbd11 |
+ entry.flags |= AMD_MOUNT_TYPE_LINK;
|
|
|
6bbd11 |
+ entry.type = amd_strdup($3);
|
|
|
6bbd11 |
+ } else if (!strcmp($3, "host")) {
|
|
|
6bbd11 |
+ entry.flags |= AMD_MOUNT_TYPE_HOST;
|
|
|
6bbd11 |
+ entry.type = amd_strdup($3);
|
|
|
6bbd11 |
+ } else {
|
|
|
6bbd11 |
+ amd_notify($1);
|
|
|
6bbd11 |
+ YYABORT;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ | MAP_OPTION OPTION_ASSIGN MAP_TYPE
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ if (!strcmp($3, "file") ||
|
|
|
6bbd11 |
+ !strcmp($3, "nis") ||
|
|
|
6bbd11 |
+ !strcmp($3, "nisplus") ||
|
|
|
6bbd11 |
+ !strcmp($3, "ldap") ||
|
|
|
6bbd11 |
+ !strcmp($3, "hesiod"))
|
|
|
6bbd11 |
+ entry.map_type = amd_strdup($3);
|
|
|
6bbd11 |
+ else if (!strcmp($3, "exec"))
|
|
|
6bbd11 |
+ /* autofs uses "program" for "exec" map type */
|
|
|
6bbd11 |
+ entry.map_type = amd_strdup("program");
|
|
|
6bbd11 |
+ else {
|
|
|
6bbd11 |
+ amd_notify($1);
|
|
|
6bbd11 |
+ YYABORT;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ | MAP_OPTION OPTION_ASSIGN FS_OPT_VALUE
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ if (!strcmp($1, "fs"))
|
|
|
6bbd11 |
+ entry.fs = amd_strdup($3);
|
|
|
6bbd11 |
+ else if (!strcmp($1, "sublink"))
|
|
|
6bbd11 |
+ entry.sublink = amd_strdup($3);
|
|
|
6bbd11 |
+ else if (!strcmp($1, "pref")) {
|
|
|
6bbd11 |
+ if (!strcmp($3, "null"))
|
|
|
6bbd11 |
+ entry.pref = amd_strdup("");
|
|
|
6bbd11 |
+ else
|
|
|
6bbd11 |
+ entry.pref = amd_strdup($3);
|
|
|
6bbd11 |
+ } else {
|
|
|
6bbd11 |
+ amd_notify($1);
|
|
|
6bbd11 |
+ YYABORT;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ | FS_OPTION OPTION_ASSIGN FS_OPT_VALUE
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ if (!strcmp($1, "rhost"))
|
|
|
6bbd11 |
+ entry.rhost = amd_strdup($3);
|
|
|
6bbd11 |
+ else if (!strcmp($1, "rfs"))
|
|
|
6bbd11 |
+ entry.rfs = amd_strdup($3);
|
|
|
6bbd11 |
+ else {
|
|
|
6bbd11 |
+ amd_notify($1);
|
|
|
6bbd11 |
+ YYABORT;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ | MNT_OPTION OPTION_ASSIGN options
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ if (!strcmp($1, "opts")) {
|
|
|
6bbd11 |
+ entry.opts = amd_strdup(opts);
|
|
|
6bbd11 |
+ memset(opts, 0, sizeof(opts));
|
|
|
6bbd11 |
+ } else if (!strcmp($1, "addopts")) {
|
|
|
6bbd11 |
+ entry.addopts = amd_strdup(opts);
|
|
|
6bbd11 |
+ memset(opts, 0, sizeof(opts));
|
|
|
6bbd11 |
+ } else if (!strcmp($1, "remopts")) {
|
|
|
6bbd11 |
+ entry.remopts = amd_strdup(opts);
|
|
|
6bbd11 |
+ memset(opts, 0, sizeof(opts));
|
|
|
6bbd11 |
+ } else {
|
|
|
6bbd11 |
+ memset(opts, 0, sizeof(opts));
|
|
|
6bbd11 |
+ amd_notify($1);
|
|
|
6bbd11 |
+ YYABORT;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ ;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+options: OPTION
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ prepend_opt(opts, $1);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ | OPTION COMMA options
|
|
|
6bbd11 |
+ {
|
|
|
6bbd11 |
+ prepend_opt(opts, $1);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ ;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+%%
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static void prepend_opt(char *dest, char *opt)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ char new[MAX_OPTS_LEN];
|
|
|
6bbd11 |
+ strcpy(new, opt);
|
|
|
6bbd11 |
+ if (*dest != '\0') {
|
|
|
6bbd11 |
+ strcat(new, ",");
|
|
|
6bbd11 |
+ strcat(new, dest);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ memmove(dest, new, strlen(new));
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#if YYDEBUG
|
|
|
6bbd11 |
+static int amd_fprintf(FILE *f, char *msg, ...)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ va_list ap;
|
|
|
6bbd11 |
+ va_start(ap, msg);
|
|
|
6bbd11 |
+ vsyslog(LOG_DEBUG, msg, ap);
|
|
|
6bbd11 |
+ va_end(ap);
|
|
|
6bbd11 |
+ return 1;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+#endif
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static char *amd_strdup(char *str)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ char *tmp;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ tmp = strdup(str);
|
|
|
6bbd11 |
+ if (!tmp)
|
|
|
6bbd11 |
+ amd_error("memory allocation error");
|
|
|
6bbd11 |
+ return tmp;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static int amd_error(const char *s)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ if (strcmp(s, "syntax"))
|
|
|
6bbd11 |
+ logmsg("syntax error in location near [ %s ]\n", amd_text);
|
|
|
6bbd11 |
+ else
|
|
|
6bbd11 |
+ logmsg("%s while parsing location.\n", s);
|
|
|
6bbd11 |
+ return 0;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static int amd_notify(const char *s)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ logmsg("syntax error in location near [ %s ]\n", s);
|
|
|
6bbd11 |
+ return(0);
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static int amd_msg(const char *s)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ logmsg("%s\n", s);
|
|
|
6bbd11 |
+ return 0;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static void local_init_vars(void)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ memset(&entry, 0, sizeof(entry));
|
|
|
6bbd11 |
+ memset(opts, 0, sizeof(opts));
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static void local_free_vars(void)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ clear_amd_entry(&entry);
|
|
|
6bbd11 |
+ return;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static void add_selector(struct selector *selector)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ struct selector *s = entry.selector;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!s) {
|
|
|
6bbd11 |
+ entry.selector = selector;
|
|
|
6bbd11 |
+ return;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ while (s->next)
|
|
|
6bbd11 |
+ s = s->next;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ selector->next = s;
|
|
|
6bbd11 |
+ entry.selector = selector;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ return;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static int make_selector(char *name,
|
|
|
6bbd11 |
+ char *value1, char *value2,
|
|
|
6bbd11 |
+ unsigned int compare)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ struct selector *s;
|
|
|
6bbd11 |
+ char *tmp;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!sel_lookup(name))
|
|
|
6bbd11 |
+ return 0;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!value1)
|
|
|
6bbd11 |
+ return 0;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ s = get_selector(name);
|
|
|
6bbd11 |
+ if (!s)
|
|
|
6bbd11 |
+ return 0;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (s->sel->flags & SEL_FLAG_MACRO) {
|
|
|
6bbd11 |
+ tmp = amd_strdup(value1);
|
|
|
6bbd11 |
+ if (!tmp)
|
|
|
6bbd11 |
+ goto error;
|
|
|
6bbd11 |
+ s->comp.value = tmp;
|
|
|
6bbd11 |
+ } else if (s->sel->flags & SEL_FLAG_FUNC1) {
|
|
|
6bbd11 |
+ char *tmp = amd_strdup(value1);
|
|
|
6bbd11 |
+ if (!tmp)
|
|
|
6bbd11 |
+ goto error;
|
|
|
6bbd11 |
+ s->func.arg1 = tmp;
|
|
|
6bbd11 |
+ } else if (s->sel->flags & SEL_FLAG_FUNC2) {
|
|
|
6bbd11 |
+ char *tmp = amd_strdup(value1);
|
|
|
6bbd11 |
+ if (!tmp)
|
|
|
6bbd11 |
+ goto error;
|
|
|
6bbd11 |
+ s->func.arg1 = tmp;
|
|
|
6bbd11 |
+ if (value2) {
|
|
|
6bbd11 |
+ tmp = amd_strdup(value2);
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ s->func.arg2 = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ s->compare = compare;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ add_selector(s);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ return 1;
|
|
|
6bbd11 |
+error:
|
|
|
6bbd11 |
+ free_selector(s);
|
|
|
6bbd11 |
+ return 0;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+void amd_init_scan(void)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static void parse_mutex_lock(void)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ int status = pthread_mutex_lock(&parse_mutex);
|
|
|
6bbd11 |
+ if (status)
|
|
|
6bbd11 |
+ fatal(status);
|
|
|
6bbd11 |
+ return;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static void parse_mutex_unlock(void *arg)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ int status = pthread_mutex_unlock(&parse_mutex);
|
|
|
6bbd11 |
+ if (status)
|
|
|
6bbd11 |
+ fatal(status);
|
|
|
6bbd11 |
+ return;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static int add_location(void)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ struct amd_entry *new;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ new = new_amd_entry(psv);
|
|
|
6bbd11 |
+ if (!new)
|
|
|
6bbd11 |
+ return 0;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry.path) {
|
|
|
6bbd11 |
+ free(new->path);
|
|
|
6bbd11 |
+ new->path = entry.path;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ new->flags = entry.flags;
|
|
|
6bbd11 |
+ new->type = entry.type;
|
|
|
6bbd11 |
+ new->map_type = entry.map_type;
|
|
|
6bbd11 |
+ new->pref = entry.pref;
|
|
|
6bbd11 |
+ new->fs = entry.fs;
|
|
|
6bbd11 |
+ new->rhost = entry.rhost;
|
|
|
6bbd11 |
+ new->rfs = entry.rfs;
|
|
|
6bbd11 |
+ new->dev = entry.dev;
|
|
|
6bbd11 |
+ new->opts = entry.opts;
|
|
|
6bbd11 |
+ new->addopts = entry.addopts;
|
|
|
6bbd11 |
+ new->remopts = entry.remopts;
|
|
|
6bbd11 |
+ new->sublink = entry.sublink;
|
|
|
6bbd11 |
+ new->selector = entry.selector;
|
|
|
6bbd11 |
+ list_add_tail(&new->list, entries);
|
|
|
6bbd11 |
+ memset(&entry, 0, sizeof(struct amd_entry));
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ return 1;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+int amd_parse_list(struct autofs_point *ap,
|
|
|
6bbd11 |
+ const char *buffer, struct list_head *list,
|
|
|
6bbd11 |
+ struct substvar **sv)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ char *buf;
|
|
|
6bbd11 |
+ size_t len;
|
|
|
6bbd11 |
+ int ret;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ len = strlen(buffer) + 2;
|
|
|
6bbd11 |
+ buf = malloc(len);
|
|
|
6bbd11 |
+ if (!buf)
|
|
|
6bbd11 |
+ return 0;
|
|
|
6bbd11 |
+ strcpy(buf, buffer);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ parse_mutex_lock();
|
|
|
6bbd11 |
+ pthread_cleanup_push(parse_mutex_unlock, NULL);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ pap = ap;
|
|
|
6bbd11 |
+ psv = *sv;
|
|
|
6bbd11 |
+ entries = list;
|
|
|
6bbd11 |
+ amd_set_scan_buffer(buf);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ local_init_vars();
|
|
|
6bbd11 |
+ ret = amd_parse();
|
|
|
6bbd11 |
+ local_free_vars();
|
|
|
6bbd11 |
+ *sv = psv;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ pthread_cleanup_pop(1);
|
|
|
6bbd11 |
+ free(buf);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ return ret;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
--- /dev/null
|
|
|
6bbd11 |
+++ autofs-5.0.7/modules/amd_tok.l
|
|
|
6bbd11 |
@@ -0,0 +1,316 @@
|
|
|
6bbd11 |
+%{
|
|
|
6bbd11 |
+/* ----------------------------------------------------------------------- *
|
|
|
6bbd11 |
+ *
|
|
|
6bbd11 |
+ * Copyright 2013 Ian Kent <raven@themaw.net>
|
|
|
6bbd11 |
+ * Copyright 2013 Red Hat, Inc.
|
|
|
6bbd11 |
+ * All rights reserved.
|
|
|
6bbd11 |
+ *
|
|
|
6bbd11 |
+ * This program is free software; you can redistribute it and/or modify
|
|
|
6bbd11 |
+ * it under the terms of the GNU General Public License as published by
|
|
|
6bbd11 |
+ * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
|
|
|
6bbd11 |
+ * USA; either version 2 of the License, or (at your option) any later
|
|
|
6bbd11 |
+ * version.
|
|
|
6bbd11 |
+ *
|
|
|
6bbd11 |
+ * This program is distributed in the hope that it will be useful,
|
|
|
6bbd11 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
6bbd11 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
6bbd11 |
+ * GNU General Public License for more details.
|
|
|
6bbd11 |
+ *
|
|
|
6bbd11 |
+ * ----------------------------------------------------------------------- */
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#ifdef ECHO
|
|
|
6bbd11 |
+# undef ECHO
|
|
|
6bbd11 |
+#endif
|
|
|
6bbd11 |
+static void amd_echo(void); /* forward definition */
|
|
|
6bbd11 |
+#define ECHO amd_echo()
|
|
|
6bbd11 |
+int amd_wrap(void);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#include <stdio.h>
|
|
|
6bbd11 |
+#include <stdlib.h>
|
|
|
6bbd11 |
+#include <string.h>
|
|
|
6bbd11 |
+#include <ctype.h>
|
|
|
6bbd11 |
+#include "amd_parse.tab.h"
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+int amd_lex(void);
|
|
|
6bbd11 |
+int mad_wrap(void);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#define YY_SKIP_YYWRAP
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#ifndef YY_STACK_USED
|
|
|
6bbd11 |
+#define YY_STACK_USED 0
|
|
|
6bbd11 |
+#endif
|
|
|
6bbd11 |
+#ifndef YY_ALWAYS_INTERACTIVE
|
|
|
6bbd11 |
+#define YY_ALWAYS_INTERACTIVE 0
|
|
|
6bbd11 |
+#endif
|
|
|
6bbd11 |
+#ifndef YY_NEVER_INTERACTIVE
|
|
|
6bbd11 |
+#define YY_NEVER_INTERACTIVE 0
|
|
|
6bbd11 |
+#endif
|
|
|
6bbd11 |
+#ifndef YY_MAIN
|
|
|
6bbd11 |
+#define YY_MAIN 0
|
|
|
6bbd11 |
+#endif
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+void amd_set_scan_buffer(const char *);
|
|
|
6bbd11 |
+static const char *line = NULL;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#ifdef FLEX_SCANNER
|
|
|
6bbd11 |
+static const char *line_pos = NULL;
|
|
|
6bbd11 |
+static const char *line_lim = NULL;
|
|
|
6bbd11 |
+int amd_yyinput(char *, int);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#undef YY_INPUT
|
|
|
6bbd11 |
+#define YY_INPUT(b, r, ms) (r = amd_yyinput(b, ms))
|
|
|
6bbd11 |
+#else
|
|
|
6bbd11 |
+#undef input
|
|
|
6bbd11 |
+#undef unput
|
|
|
6bbd11 |
+#define input() (*(char *) line++)
|
|
|
6bbd11 |
+#define unput(c) (*(char *) --line = c)
|
|
|
6bbd11 |
+#endif
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+%}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+%option nounput
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+%x MAPOPTVAL FSOPTVAL MNTOPTVAL SELOPTVAL
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+NL \r?\n
|
|
|
6bbd11 |
+OPTWS [[:blank:]]*
|
|
|
6bbd11 |
+OTHR [^!;:=/|\- \t\r\n#]*
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+MACRO (\$\{([[:alpha:]_/]([[:alnum:]_\-])([[:alnum:]_\-/])*)\})
|
|
|
6bbd11 |
+QSTR (\"([^"\\]|\\.)*\")
|
|
|
6bbd11 |
+OSTR ([[:alpha:]]([[:alnum:]_\-])+)
|
|
|
6bbd11 |
+FSTR ([[:alnum:]_/\.]([[:alnum:]_\-/\.]|(\\.))*)
|
|
|
6bbd11 |
+VSTR (([[:alnum:]_\-\:/\.])+)
|
|
|
6bbd11 |
+SSTR ([[:alpha:]]([[:alnum:]\-\.])+)
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+FOPT (({QSTR}|{FSTR}|{MACRO})+)
|
|
|
6bbd11 |
+OPTS ({OSTR}(=({VSTR}|{QSTR}|{MACRO})+)?)
|
|
|
6bbd11 |
+SOPT (({SSTR}|{QSTR}|{MACRO})+)
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+MAPOPT (fs|type|maptype|pref|sublink|delay)
|
|
|
6bbd11 |
+MNTOPT (opts|addopts|remopts)
|
|
|
6bbd11 |
+FSOPTS (rhost|rfs|dev|cachedir)
|
|
|
6bbd11 |
+MAPTYPE (file|nis|nisplus|ldap|hesiod|exec|ndbm|passwd|union)
|
|
|
6bbd11 |
+FSTYPE (auto|nfs|link|host|nfsx|ufs|xfs|efs)
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+OSSEL (arch|karch|os|osver|full_os|vendor)
|
|
|
6bbd11 |
+HSTSEL (host|hostd|xhost|domain|byte|cluster)
|
|
|
6bbd11 |
+NETSEL (netnumber|network|wire|netgrp|netgrpd|in_network)
|
|
|
6bbd11 |
+USRSEL (uid|gid)
|
|
|
6bbd11 |
+MAPSEL (key|map|path)
|
|
|
6bbd11 |
+OTRSEL (exists|autodir|dollar)
|
|
|
6bbd11 |
+BOLSEL (true|false)
|
|
|
6bbd11 |
+SELOPT ({OSSEL}|{HSTSEL}|{NETSEL}|{BOLSEL}|{USRSEL}|{MAPSEL}|{OTRSEL})
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+CUTSEP (\|\||\/)
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+%%
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+<INITIAL>{
|
|
|
6bbd11 |
+ {NL} |
|
|
|
6bbd11 |
+ \x00 { }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ {MAPOPT} {
|
|
|
6bbd11 |
+ BEGIN(MAPOPTVAL);
|
|
|
6bbd11 |
+ strcpy(amd_lval.strtype, amd_text);
|
|
|
6bbd11 |
+ return MAP_OPTION;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ {FSOPTS} {
|
|
|
6bbd11 |
+ BEGIN(FSOPTVAL);
|
|
|
6bbd11 |
+ strcpy(amd_lval.strtype, amd_text);
|
|
|
6bbd11 |
+ return FS_OPTION;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ {MNTOPT} {
|
|
|
6bbd11 |
+ BEGIN(MNTOPTVAL);
|
|
|
6bbd11 |
+ strcpy(amd_lval.strtype, amd_text);
|
|
|
6bbd11 |
+ return MNT_OPTION;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ {SELOPT} {
|
|
|
6bbd11 |
+ BEGIN(SELOPTVAL);
|
|
|
6bbd11 |
+ strcpy(amd_lval.strtype, amd_text);
|
|
|
6bbd11 |
+ return SELECTOR;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ {CUTSEP} { return CUT; }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ "-" { return HYPHEN; }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ {OPTWS} { return SPACE; }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ #.* { return COMMENT; }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ {OTHR} {
|
|
|
6bbd11 |
+ strcpy(amd_lval.strtype, amd_text);
|
|
|
6bbd11 |
+ return OTHER;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+<MAPOPTVAL>{
|
|
|
6bbd11 |
+ {NL} |
|
|
|
6bbd11 |
+ \x00 {
|
|
|
6bbd11 |
+ BEGIN(INITIAL);
|
|
|
6bbd11 |
+ yyless(1);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ ";" {
|
|
|
6bbd11 |
+ BEGIN(INITIAL);
|
|
|
6bbd11 |
+ return SEPERATOR;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ {OPTWS} {
|
|
|
6bbd11 |
+ BEGIN(INITIAL);
|
|
|
6bbd11 |
+ return SPACE;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ ":=" { return OPTION_ASSIGN; }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ {FSTYPE} {
|
|
|
6bbd11 |
+ strcpy(amd_lval.strtype, amd_text);
|
|
|
6bbd11 |
+ return FS_TYPE;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ {MAPTYPE} {
|
|
|
6bbd11 |
+ strcpy(amd_lval.strtype, amd_text);
|
|
|
6bbd11 |
+ return MAP_TYPE;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ {FOPT} {
|
|
|
6bbd11 |
+ strcpy(amd_lval.strtype, amd_text);
|
|
|
6bbd11 |
+ return FS_OPT_VALUE;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+<FSOPTVAL>{
|
|
|
6bbd11 |
+ {NL} |
|
|
|
6bbd11 |
+ \x00 {
|
|
|
6bbd11 |
+ BEGIN(INITIAL);
|
|
|
6bbd11 |
+ yyless(1);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ ";" {
|
|
|
6bbd11 |
+ BEGIN(INITIAL);
|
|
|
6bbd11 |
+ return SEPERATOR;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ {OPTWS} {
|
|
|
6bbd11 |
+ BEGIN(INITIAL);
|
|
|
6bbd11 |
+ return SPACE;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ ":=" { return OPTION_ASSIGN; }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ {FOPT} {
|
|
|
6bbd11 |
+ strcpy(amd_lval.strtype, amd_text);
|
|
|
6bbd11 |
+ return FS_OPT_VALUE;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+<MNTOPTVAL>{
|
|
|
6bbd11 |
+ {NL} |
|
|
|
6bbd11 |
+ \x00 {
|
|
|
6bbd11 |
+ BEGIN(INITIAL);
|
|
|
6bbd11 |
+ yyless(1);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ ";" {
|
|
|
6bbd11 |
+ BEGIN(INITIAL);
|
|
|
6bbd11 |
+ return SEPERATOR;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ {OPTWS} {
|
|
|
6bbd11 |
+ BEGIN(INITIAL);
|
|
|
6bbd11 |
+ return SPACE;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ ":=" { return OPTION_ASSIGN; }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ "," { return COMMA; }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ {OPTS} {
|
|
|
6bbd11 |
+ strcpy(amd_lval.strtype, amd_text);
|
|
|
6bbd11 |
+ return OPTION;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+<SELOPTVAL>{
|
|
|
6bbd11 |
+ {NL} |
|
|
|
6bbd11 |
+ \x00 {
|
|
|
6bbd11 |
+ BEGIN(INITIAL);
|
|
|
6bbd11 |
+ yyless(1);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ ";" {
|
|
|
6bbd11 |
+ BEGIN(INITIAL);
|
|
|
6bbd11 |
+ return SEPERATOR;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ {OPTWS} {
|
|
|
6bbd11 |
+ BEGIN(INITIAL);
|
|
|
6bbd11 |
+ return SPACE;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ "==" { return IS_EQUAL; }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ "!=" { return NOT_EQUAL; }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ {SOPT} {
|
|
|
6bbd11 |
+ strcpy(amd_lval.strtype, amd_text);
|
|
|
6bbd11 |
+ return SELECTOR_VALUE;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+%%
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#include "automount.h"
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+int amd_wrap(void)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ return 1;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static void amd_echo(void)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ logmsg("%s\n", amd_text);
|
|
|
6bbd11 |
+ return;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#ifdef FLEX_SCANNER
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+void amd_set_scan_buffer(const char *buffer)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ line = buffer;
|
|
|
6bbd11 |
+ line_pos = &line[0];
|
|
|
6bbd11 |
+ /*
|
|
|
6bbd11 |
+ * Ensure buffer is 1 greater than string and is zeroed before
|
|
|
6bbd11 |
+ * the parse so we can fit the extra NULL which allows us to
|
|
|
6bbd11 |
+ * explicitly match an end of line within the buffer (ie. the
|
|
|
6bbd11 |
+ * need for 2 NULLS when parsing in memeory buffers).
|
|
|
6bbd11 |
+ */
|
|
|
6bbd11 |
+ line_lim = line + strlen(buffer) + 1;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#define amd_min(a,b) (((a) < (b)) ? (a) : (b))
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+int amd_yyinput(char *buffer, int max_size)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ int n = amd_min(max_size, line_lim - line_pos);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (n > 0) {
|
|
|
6bbd11 |
+ memcpy(buffer, line_pos, n);
|
|
|
6bbd11 |
+ line_pos += n;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ return n;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#else
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+void amd_set_scan_buffer(const char *buffer)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ line = buffer;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#endif
|
|
|
6bbd11 |
--- /dev/null
|
|
|
6bbd11 |
+++ autofs-5.0.7/modules/parse_amd.c
|
|
|
6bbd11 |
@@ -0,0 +1,1081 @@
|
|
|
6bbd11 |
+/* ----------------------------------------------------------------------- *
|
|
|
6bbd11 |
+ *
|
|
|
6bbd11 |
+ * Copyright 2013 Ian Kent <raven@themaw.net>
|
|
|
6bbd11 |
+ * Copyright 2013 Red Hat, Inc.
|
|
|
6bbd11 |
+ * All rights reserved.
|
|
|
6bbd11 |
+ *
|
|
|
6bbd11 |
+ * This program is free software; you can redistribute it and/or modify
|
|
|
6bbd11 |
+ * it under the terms of the GNU General Public License as published by
|
|
|
6bbd11 |
+ * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
|
|
|
6bbd11 |
+ * USA; either version 2 of the License, or (at your option) any later
|
|
|
6bbd11 |
+ * version; incorporated herein by reference.
|
|
|
6bbd11 |
+ *
|
|
|
6bbd11 |
+ * ----------------------------------------------------------------------- */
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#include <stdio.h>
|
|
|
6bbd11 |
+#include <malloc.h>
|
|
|
6bbd11 |
+#include <netdb.h>
|
|
|
6bbd11 |
+#include <stdlib.h>
|
|
|
6bbd11 |
+#include <string.h>
|
|
|
6bbd11 |
+#include <ctype.h>
|
|
|
6bbd11 |
+#include <limits.h>
|
|
|
6bbd11 |
+#include <sys/param.h>
|
|
|
6bbd11 |
+#include <sys/socket.h>
|
|
|
6bbd11 |
+#include <sys/types.h>
|
|
|
6bbd11 |
+#include <sys/stat.h>
|
|
|
6bbd11 |
+#include <sys/vfs.h>
|
|
|
6bbd11 |
+#include <sys/utsname.h>
|
|
|
6bbd11 |
+#include <netinet/in.h>
|
|
|
6bbd11 |
+#include <sys/mount.h>
|
|
|
6bbd11 |
+#include <linux/fs.h>
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#define MODULE_PARSE
|
|
|
6bbd11 |
+#include "automount.h"
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+#define MODPREFIX "parse(amd): "
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+int parse_version = AUTOFS_PARSE_VERSION; /* Required by protocol */
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static struct mount_mod *mount_nfs = NULL;
|
|
|
6bbd11 |
+static int init_ctr = 0;
|
|
|
6bbd11 |
+static pthread_mutex_t instance_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static void instance_mutex_lock(void)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ int status = pthread_mutex_lock(&instance_mutex);
|
|
|
6bbd11 |
+ if (status)
|
|
|
6bbd11 |
+ fatal(status);
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static void instance_mutex_unlock(void)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ int status = pthread_mutex_unlock(&instance_mutex);
|
|
|
6bbd11 |
+ if (status)
|
|
|
6bbd11 |
+ fatal(status);
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+extern const char *global_options;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+struct parse_context {
|
|
|
6bbd11 |
+ char *optstr; /* Mount options */
|
|
|
6bbd11 |
+ char *macros; /* Map wide macro defines */
|
|
|
6bbd11 |
+ struct substvar *subst; /* $-substitutions */
|
|
|
6bbd11 |
+};
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+struct multi_mnt {
|
|
|
6bbd11 |
+ char *path;
|
|
|
6bbd11 |
+ char *options;
|
|
|
6bbd11 |
+ char *location;
|
|
|
6bbd11 |
+ struct multi_mnt *next;
|
|
|
6bbd11 |
+};
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+/* Default context */
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static struct parse_context default_context = {
|
|
|
6bbd11 |
+ NULL, /* No mount options */
|
|
|
6bbd11 |
+ NULL, /* No map wide macros */
|
|
|
6bbd11 |
+ NULL /* The substvar local vars table */
|
|
|
6bbd11 |
+};
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+/* Free all storage associated with this context */
|
|
|
6bbd11 |
+static void kill_context(struct parse_context *ctxt)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ macro_lock();
|
|
|
6bbd11 |
+ macro_free_table(ctxt->subst);
|
|
|
6bbd11 |
+ macro_unlock();
|
|
|
6bbd11 |
+ if (ctxt->optstr)
|
|
|
6bbd11 |
+ free(ctxt->optstr);
|
|
|
6bbd11 |
+ if (ctxt->macros)
|
|
|
6bbd11 |
+ free(ctxt->macros);
|
|
|
6bbd11 |
+ free(ctxt);
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+int parse_init(int argc, const char *const *argv, void **context)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ struct parse_context *ctxt;
|
|
|
6bbd11 |
+ char buf[MAX_ERR_BUF];
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ sel_hash_init();
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ /* Set up context and escape chain */
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!(ctxt = (struct parse_context *) malloc(sizeof(struct parse_context)))) {
|
|
|
6bbd11 |
+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
|
|
|
6bbd11 |
+ logerr(MODPREFIX "malloc: %s", estr);
|
|
|
6bbd11 |
+ *context = NULL;
|
|
|
6bbd11 |
+ return 1;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ *context = (void *) ctxt;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ *ctxt = default_context;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ /* We only need this once. NFS mounts are so common that we cache
|
|
|
6bbd11 |
+ this module. */
|
|
|
6bbd11 |
+ instance_mutex_lock();
|
|
|
6bbd11 |
+ if (mount_nfs)
|
|
|
6bbd11 |
+ init_ctr++;
|
|
|
6bbd11 |
+ else {
|
|
|
6bbd11 |
+ if ((mount_nfs = open_mount("nfs", MODPREFIX))) {
|
|
|
6bbd11 |
+ init_ctr++;
|
|
|
6bbd11 |
+ } else {
|
|
|
6bbd11 |
+ kill_context(ctxt);
|
|
|
6bbd11 |
+ *context = NULL;
|
|
|
6bbd11 |
+ instance_mutex_unlock();
|
|
|
6bbd11 |
+ return 1;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ instance_mutex_unlock();
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ return 0;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static void update_with_defaults(struct amd_entry *defaults,
|
|
|
6bbd11 |
+ struct amd_entry *entry,
|
|
|
6bbd11 |
+ struct substvar *sv)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ const struct substvar *v;
|
|
|
6bbd11 |
+ unsigned long fstype = entry->flags & AMD_MOUNT_TYPE_MASK;
|
|
|
6bbd11 |
+ char *tmp;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (fstype == AMD_MOUNT_TYPE_NONE) {
|
|
|
6bbd11 |
+ unsigned long deftype = defaults->flags & AMD_MOUNT_TYPE_MASK;
|
|
|
6bbd11 |
+ if (deftype != AMD_MOUNT_TYPE_NONE)
|
|
|
6bbd11 |
+ entry->flags |= (defaults->flags & AMD_MOUNT_TYPE_MASK);
|
|
|
6bbd11 |
+ else {
|
|
|
6bbd11 |
+ entry->flags = AMD_MOUNT_TYPE_NFS;
|
|
|
6bbd11 |
+ tmp = strdup("nfs");
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ entry->type = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!entry->type && defaults->type) {
|
|
|
6bbd11 |
+ tmp = strdup(defaults->type);
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ entry->type = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!entry->map_type && defaults->map_type) {
|
|
|
6bbd11 |
+ tmp = strdup(defaults->map_type);
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ entry->map_type = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!entry->pref && defaults->pref) {
|
|
|
6bbd11 |
+ tmp = strdup(defaults->pref);
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ entry->pref = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!entry->fs && defaults->fs) {
|
|
|
6bbd11 |
+ tmp = strdup(defaults->fs);
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ entry->fs = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!entry->rfs && defaults->rfs) {
|
|
|
6bbd11 |
+ tmp = strdup(defaults->rfs);
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ entry->rfs = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!entry->rhost && defaults->rhost) {
|
|
|
6bbd11 |
+ tmp = strdup(defaults->rhost);
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ entry->rhost = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!entry->opts && defaults->opts) {
|
|
|
6bbd11 |
+ tmp = merge_options(defaults->opts, entry->opts);
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ entry->opts = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!entry->addopts && defaults->addopts) {
|
|
|
6bbd11 |
+ tmp = merge_options(defaults->addopts, entry->addopts);
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ entry->addopts = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!entry->remopts && defaults->remopts) {
|
|
|
6bbd11 |
+ tmp = merge_options(defaults->remopts, entry->remopts);
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ entry->remopts = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ return;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static char *normalize_hostname(unsigned int logopt, const char *host,
|
|
|
6bbd11 |
+ unsigned int flags, struct substvar *sv)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ struct addrinfo hints, *ni;
|
|
|
6bbd11 |
+ char *name;
|
|
|
6bbd11 |
+ int ret;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!(flags & CONF_NORMALIZE_HOSTNAMES))
|
|
|
6bbd11 |
+ name = strdup(host);
|
|
|
6bbd11 |
+ else {
|
|
|
6bbd11 |
+ memset(&hints, 0, sizeof(hints));
|
|
|
6bbd11 |
+ hints.ai_flags = AI_CANONNAME;
|
|
|
6bbd11 |
+ hints.ai_family = AF_UNSPEC;
|
|
|
6bbd11 |
+ hints.ai_socktype = SOCK_DGRAM;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ ret = getaddrinfo(host, NULL, &hints, &ni);
|
|
|
6bbd11 |
+ if (ret) {
|
|
|
6bbd11 |
+ error(logopt, "hostname lookup failed: %s", gai_strerror(ret));
|
|
|
6bbd11 |
+ return NULL;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ name = strdup(ni->ai_canonname);
|
|
|
6bbd11 |
+ freeaddrinfo(ni);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!name)
|
|
|
6bbd11 |
+ return NULL;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (flags & CONF_DOMAIN_STRIP) {
|
|
|
6bbd11 |
+ const struct substvar *v = macro_findvar(sv, "hostd", 5);
|
|
|
6bbd11 |
+ if (v) {
|
|
|
6bbd11 |
+ char *d1 = strchr(name, '.');
|
|
|
6bbd11 |
+ if (d1) {
|
|
|
6bbd11 |
+ char *d2 = strchr(v->val, '.');
|
|
|
6bbd11 |
+ if (d2 && !strcmp(d1, d2))
|
|
|
6bbd11 |
+ *d1 = '\0';
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ return name;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static struct substvar *expand_entry(struct autofs_point *ap,
|
|
|
6bbd11 |
+ struct amd_entry *entry,
|
|
|
6bbd11 |
+ unsigned int flags,
|
|
|
6bbd11 |
+ struct substvar *sv)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ unsigned int logopt = ap->logopt;
|
|
|
6bbd11 |
+ char *expand;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->rhost) {
|
|
|
6bbd11 |
+ char *host = strdup(entry->rhost);
|
|
|
6bbd11 |
+ char *nn;
|
|
|
6bbd11 |
+ if (!host) {
|
|
|
6bbd11 |
+ error(ap->logopt, MODPREFIX
|
|
|
6bbd11 |
+ "failed to allocate storage for rhost");
|
|
|
6bbd11 |
+ goto next;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ if (expand_selectors(ap, host, &expand, sv)) {
|
|
|
6bbd11 |
+ free(host);
|
|
|
6bbd11 |
+ host = expand;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ nn = normalize_hostname(ap->logopt, host, flags, sv);
|
|
|
6bbd11 |
+ if (!nn)
|
|
|
6bbd11 |
+ sv = macro_addvar(sv, "rhost", 5, host);
|
|
|
6bbd11 |
+ else {
|
|
|
6bbd11 |
+ sv = macro_addvar(sv, "rhost", 5, nn);
|
|
|
6bbd11 |
+ free(host);
|
|
|
6bbd11 |
+ host = nn;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ debug(logopt, MODPREFIX
|
|
|
6bbd11 |
+ "rhost expand(\"%s\") -> %s", entry->rhost, host);
|
|
|
6bbd11 |
+ free(entry->rhost);
|
|
|
6bbd11 |
+ entry->rhost = host;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+next:
|
|
|
6bbd11 |
+ if (entry->sublink) {
|
|
|
6bbd11 |
+ if (expand_selectors(ap, entry->sublink, &expand, sv)) {
|
|
|
6bbd11 |
+ debug(logopt, MODPREFIX
|
|
|
6bbd11 |
+ "sublink expand(\"%s\") -> %s",
|
|
|
6bbd11 |
+ entry->sublink, expand);
|
|
|
6bbd11 |
+ free(entry->sublink);
|
|
|
6bbd11 |
+ entry->sublink = expand;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ sv = macro_addvar(sv, "sublink", 7, entry->sublink);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->rfs) {
|
|
|
6bbd11 |
+ if (expand_selectors(ap, entry->rfs, &expand, sv)) {
|
|
|
6bbd11 |
+ debug(logopt, MODPREFIX
|
|
|
6bbd11 |
+ "rfs expand(\"%s\") -> %s", entry->rfs, expand);
|
|
|
6bbd11 |
+ free(entry->rfs);
|
|
|
6bbd11 |
+ entry->rfs = expand;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ sv = macro_addvar(sv, "rfs", 3, entry->rfs);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->fs) {
|
|
|
6bbd11 |
+ if (expand_selectors(ap, entry->fs, &expand, sv)) {
|
|
|
6bbd11 |
+ debug(logopt, MODPREFIX
|
|
|
6bbd11 |
+ "fs expand(\"%s\") -> %s", entry->fs, expand);
|
|
|
6bbd11 |
+ free(entry->fs);
|
|
|
6bbd11 |
+ entry->fs = expand;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ sv = macro_addvar(sv, "fs", 2, entry->fs);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->opts) {
|
|
|
6bbd11 |
+ if (expand_selectors(ap, entry->opts, &expand, sv)) {
|
|
|
6bbd11 |
+ debug(logopt, MODPREFIX
|
|
|
6bbd11 |
+ "ops expand(\"%s\") -> %s", entry->opts, expand);
|
|
|
6bbd11 |
+ free(entry->opts);
|
|
|
6bbd11 |
+ entry->opts = expand;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ sv = macro_addvar(sv, "opts", 4, entry->opts);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->addopts) {
|
|
|
6bbd11 |
+ if (expand_selectors(ap, entry->addopts, &expand, sv)) {
|
|
|
6bbd11 |
+ debug(logopt, MODPREFIX
|
|
|
6bbd11 |
+ "addopts expand(\"%s\") -> %s",
|
|
|
6bbd11 |
+ entry->addopts, expand);
|
|
|
6bbd11 |
+ free(entry->addopts);
|
|
|
6bbd11 |
+ entry->addopts = expand;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ sv = macro_addvar(sv, "addopts", 7, entry->addopts);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->remopts) {
|
|
|
6bbd11 |
+ if (expand_selectors(ap, entry->remopts, &expand, sv)) {
|
|
|
6bbd11 |
+ debug(logopt, MODPREFIX
|
|
|
6bbd11 |
+ "remopts expand(\"%s\") -> %s",
|
|
|
6bbd11 |
+ entry->remopts, expand);
|
|
|
6bbd11 |
+ free(entry->remopts);
|
|
|
6bbd11 |
+ entry->remopts = expand;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ sv = macro_addvar(sv, "remopts", 7, entry->remopts);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ return sv;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static void expand_merge_options(struct autofs_point *ap,
|
|
|
6bbd11 |
+ struct amd_entry *entry,
|
|
|
6bbd11 |
+ struct substvar *sv)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ char *tmp;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->opts) {
|
|
|
6bbd11 |
+ if (!expand_selectors(ap, entry->opts, &tmp, sv))
|
|
|
6bbd11 |
+ error(ap->logopt, MODPREFIX "failed to expand opts");
|
|
|
6bbd11 |
+ else {
|
|
|
6bbd11 |
+ free(entry->opts);
|
|
|
6bbd11 |
+ entry->opts = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->addopts) {
|
|
|
6bbd11 |
+ if (!expand_selectors(ap, entry->addopts, &tmp, sv))
|
|
|
6bbd11 |
+ error(ap->logopt, MODPREFIX "failed to expand addopts");
|
|
|
6bbd11 |
+ else {
|
|
|
6bbd11 |
+ free(entry->addopts);
|
|
|
6bbd11 |
+ entry->addopts = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->remopts) {
|
|
|
6bbd11 |
+ if (!expand_selectors(ap, entry->remopts, &tmp, sv))
|
|
|
6bbd11 |
+ error(ap->logopt, MODPREFIX "failed to expand remopts");
|
|
|
6bbd11 |
+ else {
|
|
|
6bbd11 |
+ free(entry->remopts);
|
|
|
6bbd11 |
+ entry->remopts = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ return;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static struct substvar *merge_entry_options(struct autofs_point *ap,
|
|
|
6bbd11 |
+ struct amd_entry *entry,
|
|
|
6bbd11 |
+ struct substvar *sv)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ char *tmp;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!entry->addopts)
|
|
|
6bbd11 |
+ return sv;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->opts && entry->remopts &&
|
|
|
6bbd11 |
+ !strcmp(entry->opts, entry->remopts)) {
|
|
|
6bbd11 |
+ expand_merge_options(ap, entry, sv);
|
|
|
6bbd11 |
+ tmp = merge_options(entry->opts, entry->addopts);
|
|
|
6bbd11 |
+ if (tmp) {
|
|
|
6bbd11 |
+ info(ap->logopt, MODPREFIX
|
|
|
6bbd11 |
+ "merge remopts \"%s\" addopts \"%s\" => \"%s\"",
|
|
|
6bbd11 |
+ entry->opts, entry->addopts, tmp);
|
|
|
6bbd11 |
+ free(entry->opts);
|
|
|
6bbd11 |
+ entry->opts = tmp;
|
|
|
6bbd11 |
+ sv = macro_addvar(sv, "opts", 4, entry->opts);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ tmp = strdup(entry->opts);
|
|
|
6bbd11 |
+ if (tmp) {
|
|
|
6bbd11 |
+ free(entry->remopts);
|
|
|
6bbd11 |
+ entry->remopts = tmp;
|
|
|
6bbd11 |
+ sv = macro_addvar(sv, "remopts", 7, entry->remopts);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ return sv;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ expand_merge_options(ap, entry, sv);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->opts && entry->addopts) {
|
|
|
6bbd11 |
+ tmp = merge_options(entry->opts, entry->addopts);
|
|
|
6bbd11 |
+ if (tmp) {
|
|
|
6bbd11 |
+ info(ap->logopt, MODPREFIX
|
|
|
6bbd11 |
+ "merge opts \"%s\" addopts \"%s\" => \"%s\"",
|
|
|
6bbd11 |
+ entry->opts, entry->addopts, tmp);
|
|
|
6bbd11 |
+ free(entry->opts);
|
|
|
6bbd11 |
+ entry->opts = tmp;
|
|
|
6bbd11 |
+ sv = macro_addvar(sv, "opts", 4, entry->opts);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ } else if (entry->addopts) {
|
|
|
6bbd11 |
+ tmp = strdup(entry->addopts);
|
|
|
6bbd11 |
+ if (tmp) {
|
|
|
6bbd11 |
+ info(ap->logopt, MODPREFIX
|
|
|
6bbd11 |
+ "opts add addopts \"%s\" => \"%s\"", entry->addopts, tmp);
|
|
|
6bbd11 |
+ entry->opts = tmp;
|
|
|
6bbd11 |
+ sv = macro_addvar(sv, "opts", 4, entry->opts);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ expand_merge_options(ap, entry, sv);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->remopts && entry->addopts) {
|
|
|
6bbd11 |
+ tmp = merge_options(entry->remopts, entry->addopts);
|
|
|
6bbd11 |
+ if (tmp) {
|
|
|
6bbd11 |
+ info(ap->logopt, MODPREFIX
|
|
|
6bbd11 |
+ "merge remopts \"%s\" addopts \"%s\" => \"%s\"",
|
|
|
6bbd11 |
+ entry->remopts, entry->addopts, tmp);
|
|
|
6bbd11 |
+ free(entry->remopts);
|
|
|
6bbd11 |
+ entry->remopts = tmp;
|
|
|
6bbd11 |
+ sv = macro_addvar(sv, "remopts", 7, entry->remopts);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ } else if (entry->addopts) {
|
|
|
6bbd11 |
+ tmp = strdup(entry->addopts);
|
|
|
6bbd11 |
+ if (tmp) {
|
|
|
6bbd11 |
+ info(ap->logopt, MODPREFIX
|
|
|
6bbd11 |
+ "remopts add addopts \"%s\" => \"%s\"",
|
|
|
6bbd11 |
+ entry->addopts, tmp);
|
|
|
6bbd11 |
+ entry->remopts = tmp;
|
|
|
6bbd11 |
+ sv = macro_addvar(sv, "remopts", 7, entry->remopts);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ return sv;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static int do_auto_mount(struct autofs_point *ap, const char *name,
|
|
|
6bbd11 |
+ struct amd_entry *entry, unsigned int flags)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ char target[PATH_MAX + 1];
|
|
|
6bbd11 |
+ int ret;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!entry->map_type)
|
|
|
6bbd11 |
+ strcpy(target, entry->fs);
|
|
|
6bbd11 |
+ else {
|
|
|
6bbd11 |
+ strcpy(target, entry->map_type);
|
|
|
6bbd11 |
+ strcat(target, ",amd:");
|
|
|
6bbd11 |
+ strcat(target, entry->fs);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ ret = do_mount(ap, ap->path,
|
|
|
6bbd11 |
+ name, strlen(name), target, "autofs", NULL);
|
|
|
6bbd11 |
+ if (!ret) {
|
|
|
6bbd11 |
+ struct autofs_point *sm;
|
|
|
6bbd11 |
+ sm = master_find_submount(ap, entry->path);
|
|
|
6bbd11 |
+ if (sm) {
|
|
|
6bbd11 |
+ sm->pref = entry->pref;
|
|
|
6bbd11 |
+ entry->pref = NULL;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ return ret;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static int do_link_mount(struct autofs_point *ap, const char *name,
|
|
|
6bbd11 |
+ struct amd_entry *entry, unsigned int flags)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ char target[PATH_MAX + 1];
|
|
|
6bbd11 |
+ int ret;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->sublink)
|
|
|
6bbd11 |
+ strcpy(target, entry->sublink);
|
|
|
6bbd11 |
+ else
|
|
|
6bbd11 |
+ strcpy(target, entry->fs);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!(flags & CONF_AUTOFS_USE_LOFS))
|
|
|
6bbd11 |
+ goto symlink;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ /* For a sublink this might cause an external mount */
|
|
|
6bbd11 |
+ ret = do_mount(ap, ap->path,
|
|
|
6bbd11 |
+ name, strlen(name), target, "bind", entry->opts);
|
|
|
6bbd11 |
+ if (!ret)
|
|
|
6bbd11 |
+ goto out;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ debug(ap->logopt, MODPREFIX "bind mount failed, symlinking");
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+symlink:
|
|
|
6bbd11 |
+ ret = do_mount(ap, ap->path,
|
|
|
6bbd11 |
+ name, strlen(name), target, "bind", "symlink");
|
|
|
6bbd11 |
+ if (!ret)
|
|
|
6bbd11 |
+ goto out;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ error(ap->logopt, MODPREFIX
|
|
|
6bbd11 |
+ "failed to symlink %s to %s", entry->path, target);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->sublink) {
|
|
|
6bbd11 |
+ /* failed to complete sublink mount */
|
|
|
6bbd11 |
+ if (ext_mount_remove(&entry->ext_mount, entry->fs))
|
|
|
6bbd11 |
+ umount_ent(ap, entry->fs);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+out:
|
|
|
6bbd11 |
+ return ret;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static int do_nfs_mount(struct autofs_point *ap, const char *name,
|
|
|
6bbd11 |
+ struct amd_entry *entry, unsigned int flags)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ char target[PATH_MAX + 1];
|
|
|
6bbd11 |
+ int ret = 0;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ strcpy(target, entry->rhost);
|
|
|
6bbd11 |
+ strcat(target, ":");
|
|
|
6bbd11 |
+ strcat(target, entry->rfs);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!entry->sublink) {
|
|
|
6bbd11 |
+ ret = mount_nfs->mount_mount(ap, ap->path, name, strlen(name),
|
|
|
6bbd11 |
+ target, entry->type, entry->opts,
|
|
|
6bbd11 |
+ mount_nfs->context);
|
|
|
6bbd11 |
+ } else {
|
|
|
6bbd11 |
+ if (!is_mounted(_PATH_MOUNTED, entry->fs, MNTS_REAL)) {
|
|
|
6bbd11 |
+ ret = mount_nfs->mount_mount(ap, entry->fs, "/", 1,
|
|
|
6bbd11 |
+ target, entry->type, entry->opts,
|
|
|
6bbd11 |
+ mount_nfs->context);
|
|
|
6bbd11 |
+ if (ret)
|
|
|
6bbd11 |
+ goto out;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ /* We might be using an external mount */
|
|
|
6bbd11 |
+ ext_mount_add(&entry->ext_mount, entry->fs);
|
|
|
6bbd11 |
+ ret = do_link_mount(ap, name, entry, flags);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+out:
|
|
|
6bbd11 |
+ return ret;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static int do_host_mount(struct autofs_point *ap, const char *name,
|
|
|
6bbd11 |
+ struct amd_entry *entry, struct map_source *source,
|
|
|
6bbd11 |
+ unsigned int flags)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ struct lookup_mod *lookup;
|
|
|
6bbd11 |
+ struct mapent *me;
|
|
|
6bbd11 |
+ const char *argv[2];
|
|
|
6bbd11 |
+ int ret = 1;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ argv[0] = entry->opts;
|
|
|
6bbd11 |
+ argv[1] = NULL;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ lookup = open_lookup("hosts", MODPREFIX, NULL, 1, argv);
|
|
|
6bbd11 |
+ if (!lookup) {
|
|
|
6bbd11 |
+ debug(ap->logopt, "open lookup module hosts failed");
|
|
|
6bbd11 |
+ goto out;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ me = cache_lookup_distinct(source->mc, name);
|
|
|
6bbd11 |
+ if (me)
|
|
|
6bbd11 |
+ cache_push_mapent(me, NULL);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ master_source_current_wait(ap->entry);
|
|
|
6bbd11 |
+ ap->entry->current = source;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ ret = lookup->lookup_mount(ap, name, strlen(name), lookup->context);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ close_lookup(lookup);
|
|
|
6bbd11 |
+out:
|
|
|
6bbd11 |
+ return ret;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static int amd_mount(struct autofs_point *ap, const char *name,
|
|
|
6bbd11 |
+ struct amd_entry *entry, struct map_source *source,
|
|
|
6bbd11 |
+ struct substvar *sv, unsigned int flags,
|
|
|
6bbd11 |
+ struct parse_context *ctxt)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ unsigned long fstype = entry->flags & AMD_MOUNT_TYPE_MASK;
|
|
|
6bbd11 |
+ int ret = 1;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ switch (fstype) {
|
|
|
6bbd11 |
+ case AMD_MOUNT_TYPE_AUTO:
|
|
|
6bbd11 |
+ ret = do_auto_mount(ap, name, entry, flags);
|
|
|
6bbd11 |
+ break;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ case AMD_MOUNT_TYPE_NFS:
|
|
|
6bbd11 |
+ ret = do_nfs_mount(ap, name, entry, flags);
|
|
|
6bbd11 |
+ break;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ case AMD_MOUNT_TYPE_LINK:
|
|
|
6bbd11 |
+ ret = do_link_mount(ap, name, entry, flags);
|
|
|
6bbd11 |
+ break;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ case AMD_MOUNT_TYPE_HOST:
|
|
|
6bbd11 |
+ ret = do_host_mount(ap, name, entry, source, flags);
|
|
|
6bbd11 |
+ break;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ default:
|
|
|
6bbd11 |
+ info(ap->logopt,
|
|
|
6bbd11 |
+ MODPREFIX "unkown file system type %x", fstype);
|
|
|
6bbd11 |
+ break;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ return ret;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+void dequote_entry(struct autofs_point *ap, struct amd_entry *entry)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ char *res;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->pref) {
|
|
|
6bbd11 |
+ res = dequote(entry->pref, strlen(entry->pref), ap->logopt);
|
|
|
6bbd11 |
+ if (res) {
|
|
|
6bbd11 |
+ debug(ap->logopt,
|
|
|
6bbd11 |
+ MODPREFIX "pref dequote(\"%.*s\") -> %s",
|
|
|
6bbd11 |
+ strlen(entry->pref), entry->pref, res);
|
|
|
6bbd11 |
+ free(entry->pref);
|
|
|
6bbd11 |
+ entry->pref = res;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->sublink) {
|
|
|
6bbd11 |
+ res = dequote(entry->sublink, strlen(entry->sublink), ap->logopt);
|
|
|
6bbd11 |
+ if (res) {
|
|
|
6bbd11 |
+ debug(ap->logopt,
|
|
|
6bbd11 |
+ MODPREFIX "sublink dequote(\"%.*s\") -> %s",
|
|
|
6bbd11 |
+ strlen(entry->sublink), entry->sublink, res);
|
|
|
6bbd11 |
+ free(entry->sublink);
|
|
|
6bbd11 |
+ entry->sublink = res;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->fs) {
|
|
|
6bbd11 |
+ res = dequote(entry->fs, strlen(entry->fs), ap->logopt);
|
|
|
6bbd11 |
+ if (res) {
|
|
|
6bbd11 |
+ debug(ap->logopt,
|
|
|
6bbd11 |
+ MODPREFIX "fs dequote(\"%.*s\") -> %s",
|
|
|
6bbd11 |
+ strlen(entry->fs), entry->fs, res);
|
|
|
6bbd11 |
+ free(entry->fs);
|
|
|
6bbd11 |
+ entry->fs = res;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->rfs) {
|
|
|
6bbd11 |
+ res = dequote(entry->rfs, strlen(entry->rfs), ap->logopt);
|
|
|
6bbd11 |
+ if (res) {
|
|
|
6bbd11 |
+ debug(ap->logopt,
|
|
|
6bbd11 |
+ MODPREFIX "rfs dequote(\"%.*s\") -> %s",
|
|
|
6bbd11 |
+ strlen(entry->rfs), entry->rfs, res);
|
|
|
6bbd11 |
+ free(entry->rfs);
|
|
|
6bbd11 |
+ entry->rfs = res;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->opts) {
|
|
|
6bbd11 |
+ res = dequote(entry->opts, strlen(entry->opts), ap->logopt);
|
|
|
6bbd11 |
+ if (res) {
|
|
|
6bbd11 |
+ debug(ap->logopt,
|
|
|
6bbd11 |
+ MODPREFIX "ops dequote(\"%.*s\") -> %s",
|
|
|
6bbd11 |
+ strlen(entry->opts), entry->opts, res);
|
|
|
6bbd11 |
+ free(entry->opts);
|
|
|
6bbd11 |
+ entry->opts = res;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->remopts) {
|
|
|
6bbd11 |
+ res = dequote(entry->remopts, strlen(entry->remopts), ap->logopt);
|
|
|
6bbd11 |
+ if (res) {
|
|
|
6bbd11 |
+ debug(ap->logopt,
|
|
|
6bbd11 |
+ MODPREFIX "remopts dequote(\"%.*s\") -> %s",
|
|
|
6bbd11 |
+ strlen(entry->remopts), entry->remopts, res);
|
|
|
6bbd11 |
+ free(entry->remopts);
|
|
|
6bbd11 |
+ entry->remopts = res;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->addopts) {
|
|
|
6bbd11 |
+ res = dequote(entry->addopts, strlen(entry->addopts), ap->logopt);
|
|
|
6bbd11 |
+ if (res) {
|
|
|
6bbd11 |
+ debug(ap->logopt,
|
|
|
6bbd11 |
+ MODPREFIX "addopts dequote(\"%.*s\") -> %s",
|
|
|
6bbd11 |
+ strlen(entry->addopts), entry->addopts, res);
|
|
|
6bbd11 |
+ free(entry->addopts);
|
|
|
6bbd11 |
+ entry->addopts = res;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ return;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static void normalize_sublink(unsigned int logopt,
|
|
|
6bbd11 |
+ struct amd_entry *entry, struct substvar *sv)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ char *new;
|
|
|
6bbd11 |
+ size_t len;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (entry->sublink && *entry->sublink != '/') {
|
|
|
6bbd11 |
+ len = strlen(entry->fs) + strlen(entry->sublink) + 2;
|
|
|
6bbd11 |
+ new = malloc(len);
|
|
|
6bbd11 |
+ if (!new) {
|
|
|
6bbd11 |
+ error(logopt, MODPREFIX
|
|
|
6bbd11 |
+ "error: couldn't allocate storage for sublink");
|
|
|
6bbd11 |
+ return;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ strcpy(new, entry->fs);
|
|
|
6bbd11 |
+ strcat(new, "/");
|
|
|
6bbd11 |
+ strcat(new, entry->sublink);
|
|
|
6bbd11 |
+ debug(logopt, MODPREFIX
|
|
|
6bbd11 |
+ "rfs dequote(\"%.*s\") -> %s",
|
|
|
6bbd11 |
+ strlen(entry->sublink), entry->sublink, new);
|
|
|
6bbd11 |
+ free(entry->sublink);
|
|
|
6bbd11 |
+ entry->sublink = new;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ return;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static struct amd_entry *dup_defaults_entry(struct amd_entry *defaults)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ struct amd_entry *entry;
|
|
|
6bbd11 |
+ char *tmp;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ entry = malloc(sizeof(struct amd_entry));
|
|
|
6bbd11 |
+ if (!entry)
|
|
|
6bbd11 |
+ return NULL;
|
|
|
6bbd11 |
+ memset(entry, 0, sizeof(struct amd_entry));
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ entry->flags = defaults->flags;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (defaults->type) {
|
|
|
6bbd11 |
+ tmp = strdup(defaults->type);
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ entry->type = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (defaults->map_type) {
|
|
|
6bbd11 |
+ tmp = strdup(defaults->map_type);
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ entry->map_type = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (defaults->pref) {
|
|
|
6bbd11 |
+ tmp = strdup(defaults->pref);
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ entry->pref = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (defaults->fs) {
|
|
|
6bbd11 |
+ tmp = strdup(defaults->fs);
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ entry->fs = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (defaults->rfs) {
|
|
|
6bbd11 |
+ tmp = strdup(defaults->rfs);
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ entry->rfs = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (defaults->rhost) {
|
|
|
6bbd11 |
+ tmp = strdup(defaults->rhost);
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ entry->rhost = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (defaults->opts) {
|
|
|
6bbd11 |
+ tmp = strdup(defaults->opts);
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ entry->opts = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (defaults->addopts) {
|
|
|
6bbd11 |
+ tmp = strdup(defaults->addopts);
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ entry->addopts = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (defaults->remopts) {
|
|
|
6bbd11 |
+ tmp = strdup(defaults->remopts);
|
|
|
6bbd11 |
+ if (tmp)
|
|
|
6bbd11 |
+ entry->remopts = tmp;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ INIT_LIST_HEAD(&entry->list);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ return entry;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+struct amd_entry *make_default_entry(struct autofs_point *ap,
|
|
|
6bbd11 |
+ struct substvar *sv)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ char *defaults = "opts:=rw,defaults";
|
|
|
6bbd11 |
+ struct amd_entry *defaults_entry;
|
|
|
6bbd11 |
+ struct list_head dflts;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ INIT_LIST_HEAD(&dflts);
|
|
|
6bbd11 |
+ if (amd_parse_list(ap, defaults, &dflts, &sv))
|
|
|
6bbd11 |
+ return NULL;
|
|
|
6bbd11 |
+ defaults_entry = list_entry(dflts.next, struct amd_entry, list);
|
|
|
6bbd11 |
+ list_del_init(&defaults_entry->list);
|
|
|
6bbd11 |
+ /* The list should now be empty .... */
|
|
|
6bbd11 |
+ free_amd_entry_list(&dflts);
|
|
|
6bbd11 |
+ return defaults_entry;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static struct amd_entry *select_default_entry(struct autofs_point *ap,
|
|
|
6bbd11 |
+ struct list_head *entries,
|
|
|
6bbd11 |
+ struct substvar *sv)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ unsigned long flags = conf_amd_get_flags(ap->path);
|
|
|
6bbd11 |
+ struct amd_entry *defaults_entry = NULL;
|
|
|
6bbd11 |
+ struct amd_entry *entry_default = NULL;
|
|
|
6bbd11 |
+ struct list_head *p, *head;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!(flags & CONF_SELECTORS_IN_DEFAULTS))
|
|
|
6bbd11 |
+ goto no_sel;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ head = entries;
|
|
|
6bbd11 |
+ p = head->next;
|
|
|
6bbd11 |
+ while (p != head) {
|
|
|
6bbd11 |
+ struct amd_entry *this = list_entry(p, struct amd_entry, list);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ p = p->next;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (this->flags & AMD_DEFAULTS_MERGE) {
|
|
|
6bbd11 |
+ if (entry_default)
|
|
|
6bbd11 |
+ free_amd_entry(entry_default);
|
|
|
6bbd11 |
+ list_del_init(&this->list);
|
|
|
6bbd11 |
+ entry_default = this;
|
|
|
6bbd11 |
+ continue;
|
|
|
6bbd11 |
+ } else if (this->flags & AMD_DEFAULTS_RESET) {
|
|
|
6bbd11 |
+ struct amd_entry *new;
|
|
|
6bbd11 |
+ new = dup_defaults_entry(defaults_entry);
|
|
|
6bbd11 |
+ if (new) {
|
|
|
6bbd11 |
+ free_amd_entry(entry_default);
|
|
|
6bbd11 |
+ entry_default = new;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ list_del_init(&this->list);
|
|
|
6bbd11 |
+ free_amd_entry(this);
|
|
|
6bbd11 |
+ continue;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ /* Not strickly amd semantics but ... */
|
|
|
6bbd11 |
+ if (!defaults_entry && entry_default) {
|
|
|
6bbd11 |
+ defaults_entry = entry_default;
|
|
|
6bbd11 |
+ goto done;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!defaults_entry) {
|
|
|
6bbd11 |
+ debug(ap->logopt, MODPREFIX
|
|
|
6bbd11 |
+ "no matching selector(s) found in defaults, "
|
|
|
6bbd11 |
+ "using internal defaults");
|
|
|
6bbd11 |
+ goto ret_default;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ goto done;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+no_sel:
|
|
|
6bbd11 |
+ if (list_empty(entries))
|
|
|
6bbd11 |
+ goto ret_default;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ defaults_entry = list_entry(entries->next, struct amd_entry, list);
|
|
|
6bbd11 |
+ list_del_init(&defaults_entry->list);
|
|
|
6bbd11 |
+ if (!list_empty(entries)) {
|
|
|
6bbd11 |
+ free_amd_entry(defaults_entry);
|
|
|
6bbd11 |
+ goto ret_default;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+done:
|
|
|
6bbd11 |
+ /*merge_entry_options(ap, defaults_entry, sv);*/
|
|
|
6bbd11 |
+ /*normalize_sublink(ap->logopt, defaults_entry, sv);*/
|
|
|
6bbd11 |
+ return defaults_entry;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ret_default:
|
|
|
6bbd11 |
+ return make_default_entry(ap, sv);
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+static struct amd_entry *get_defaults_entry(struct autofs_point *ap,
|
|
|
6bbd11 |
+ const char *defaults,
|
|
|
6bbd11 |
+ struct substvar *sv)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ struct amd_entry *entry;
|
|
|
6bbd11 |
+ struct list_head dflts;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ INIT_LIST_HEAD(&dflts);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ entry = NULL;
|
|
|
6bbd11 |
+ if (!defaults)
|
|
|
6bbd11 |
+ goto out;
|
|
|
6bbd11 |
+ else {
|
|
|
6bbd11 |
+ char *expand;
|
|
|
6bbd11 |
+ if (!expand_selectors(ap, defaults, &expand, sv))
|
|
|
6bbd11 |
+ goto out;
|
|
|
6bbd11 |
+ if (amd_parse_list(ap, expand, &dflts, &sv))
|
|
|
6bbd11 |
+ goto out;
|
|
|
6bbd11 |
+ entry = select_default_entry(ap, &dflts, sv);
|
|
|
6bbd11 |
+ free(expand);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ return entry;
|
|
|
6bbd11 |
+out:
|
|
|
6bbd11 |
+ return make_default_entry(ap, sv);
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+int parse_mount(struct autofs_point *ap, const char *name,
|
|
|
6bbd11 |
+ int name_len, const char *mapent, void *context)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ struct parse_context *ctxt = (struct parse_context *) context;
|
|
|
6bbd11 |
+ unsigned int flags = conf_amd_get_flags(ap->path);
|
|
|
6bbd11 |
+ struct substvar *sv = NULL;
|
|
|
6bbd11 |
+ struct map_source *source;
|
|
|
6bbd11 |
+ struct mapent_cache *mc;
|
|
|
6bbd11 |
+ struct mapent *me;
|
|
|
6bbd11 |
+ struct list_head entries, *p, *head;
|
|
|
6bbd11 |
+ struct amd_entry *defaults_entry;
|
|
|
6bbd11 |
+ struct amd_entry *cur_defaults;
|
|
|
6bbd11 |
+ char *defaults;
|
|
|
6bbd11 |
+ char *pmapent;
|
|
|
6bbd11 |
+ int len, rv = 1;
|
|
|
6bbd11 |
+ int cur_state;
|
|
|
6bbd11 |
+ int ret;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ source = ap->entry->current;
|
|
|
6bbd11 |
+ ap->entry->current = NULL;
|
|
|
6bbd11 |
+ master_source_current_signal(ap->entry);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ mc = source->mc;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (!mapent) {
|
|
|
6bbd11 |
+ warn(ap->logopt, MODPREFIX "error: empty map entry");
|
|
|
6bbd11 |
+ return 1;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ len = expand_selectors(ap, mapent, &pmapent, sv);
|
|
|
6bbd11 |
+ if (!len) {
|
|
|
6bbd11 |
+ macro_free_table(sv);
|
|
|
6bbd11 |
+ pthread_setcancelstate(cur_state, NULL);
|
|
|
6bbd11 |
+ return 1;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ pthread_setcancelstate(cur_state, NULL);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ debug(ap->logopt, MODPREFIX "expanded mapent: %s", pmapent);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ defaults = conf_amd_get_map_defaults(ap->path);
|
|
|
6bbd11 |
+ if (defaults) {
|
|
|
6bbd11 |
+ debug(ap->logopt, MODPREFIX
|
|
|
6bbd11 |
+ "using map_defaults %s for %s", defaults, ap->path);
|
|
|
6bbd11 |
+ } else if ((me = cache_lookup_distinct(mc, "/defaults"))) {
|
|
|
6bbd11 |
+ defaults = strdup(me->mapent);
|
|
|
6bbd11 |
+ if (defaults)
|
|
|
6bbd11 |
+ debug(ap->logopt, MODPREFIX
|
|
|
6bbd11 |
+ "using /defaults %s from map", defaults);
|
|
|
6bbd11 |
+ else {
|
|
|
6bbd11 |
+ char buf[MAX_ERR_BUF];
|
|
|
6bbd11 |
+ char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
|
|
|
6bbd11 |
+ error(ap->logopt, MODPREFIX "malloc: %s", estr);
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ defaults_entry = get_defaults_entry(ap, defaults, sv);
|
|
|
6bbd11 |
+ if (!defaults_entry) {
|
|
|
6bbd11 |
+ error(ap->logopt, MODPREFIX "failed to get a defaults entry");
|
|
|
6bbd11 |
+ if (defaults)
|
|
|
6bbd11 |
+ free(defaults);
|
|
|
6bbd11 |
+ free(pmapent);
|
|
|
6bbd11 |
+ macro_free_table(sv);
|
|
|
6bbd11 |
+ return 1;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ if (defaults)
|
|
|
6bbd11 |
+ free(defaults);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ INIT_LIST_HEAD(&entries);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ ret = amd_parse_list(ap, pmapent, &entries, &sv;;
|
|
|
6bbd11 |
+ if (ret) {
|
|
|
6bbd11 |
+ error(ap->logopt,
|
|
|
6bbd11 |
+ MODPREFIX "failed to parse entry: %s", pmapent);
|
|
|
6bbd11 |
+ free(pmapent);
|
|
|
6bbd11 |
+ goto done;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ free(pmapent);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (list_empty(&entries)) {
|
|
|
6bbd11 |
+ error(ap->logopt, MODPREFIX "no location found after parse");
|
|
|
6bbd11 |
+ goto done;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ cur_defaults = dup_defaults_entry(defaults_entry);
|
|
|
6bbd11 |
+ if (!cur_defaults) {
|
|
|
6bbd11 |
+ error(ap->logopt, MODPREFIX
|
|
|
6bbd11 |
+ "failed to duplicate defaults entry");
|
|
|
6bbd11 |
+ goto done;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ head = &entries;
|
|
|
6bbd11 |
+ p = head->next;
|
|
|
6bbd11 |
+ while (p != head) {
|
|
|
6bbd11 |
+ struct amd_entry *this = list_entry(p, struct amd_entry, list);
|
|
|
6bbd11 |
+ p = p->next;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (this->flags & AMD_DEFAULTS_MERGE) {
|
|
|
6bbd11 |
+ free_amd_entry(cur_defaults);
|
|
|
6bbd11 |
+ list_del_init(&this->list);
|
|
|
6bbd11 |
+ cur_defaults = this;
|
|
|
6bbd11 |
+ continue;
|
|
|
6bbd11 |
+ } else if (this->flags & AMD_DEFAULTS_RESET) {
|
|
|
6bbd11 |
+ struct amd_entry *new;
|
|
|
6bbd11 |
+ new = dup_defaults_entry(defaults_entry);
|
|
|
6bbd11 |
+ if (new) {
|
|
|
6bbd11 |
+ free_amd_entry(cur_defaults);
|
|
|
6bbd11 |
+ cur_defaults = new;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ list_del_init(&this->list);
|
|
|
6bbd11 |
+ free_amd_entry(this);
|
|
|
6bbd11 |
+ continue;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ update_with_defaults(cur_defaults, this, sv);
|
|
|
6bbd11 |
+ sv = expand_entry(ap, this, flags, sv);
|
|
|
6bbd11 |
+ sv = merge_entry_options(ap, this, sv);
|
|
|
6bbd11 |
+ normalize_sublink(ap->logopt, this, sv);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ dequote_entry(ap, this);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ rv = amd_mount(ap, name, this, source, sv, flags, ctxt);
|
|
|
6bbd11 |
+ if (!rv)
|
|
|
6bbd11 |
+ break;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ free_amd_entry(cur_defaults);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ if (rv)
|
|
|
6bbd11 |
+ debug(ap->logopt, "no more locations to try, returning fail");
|
|
|
6bbd11 |
+done:
|
|
|
6bbd11 |
+ free_amd_entry_list(&entries);
|
|
|
6bbd11 |
+ free_amd_entry(defaults_entry);
|
|
|
6bbd11 |
+ macro_free_table(sv);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ return rv;
|
|
|
6bbd11 |
+}
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+int parse_done(void *context)
|
|
|
6bbd11 |
+{
|
|
|
6bbd11 |
+ int rv = 0;
|
|
|
6bbd11 |
+ struct parse_context *ctxt = (struct parse_context *) context;
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ instance_mutex_lock();
|
|
|
6bbd11 |
+ if (--init_ctr == 0) {
|
|
|
6bbd11 |
+ rv = close_mount(mount_nfs);
|
|
|
6bbd11 |
+ mount_nfs = NULL;
|
|
|
6bbd11 |
+ }
|
|
|
6bbd11 |
+ instance_mutex_unlock();
|
|
|
6bbd11 |
+ if (ctxt)
|
|
|
6bbd11 |
+ kill_context(ctxt);
|
|
|
6bbd11 |
+
|
|
|
6bbd11 |
+ return rv;
|
|
|
6bbd11 |
+}
|