1
#ident "$Id: lookup_multi.c,v 1.7 2005/02/10 12:31:29 raven Exp $"
2
/* ----------------------------------------------------------------------- *
4
* lookup_multi.c - module for Linux automount to seek multiple lookup
5
* methods in succession
7
* Copyright 1999 Transmeta Corporation - All Rights Reserved
9
* This program is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
12
* USA; either version 2 of the License, or (at your option) any later
13
* version; incorporated herein by reference.
15
* ----------------------------------------------------------------------- */
27
#include "automount.h"
29
#define MODPREFIX "lookup(multi): "
33
const char *const *argv;
34
struct lookup_mod *mod;
37
struct lookup_context {
40
struct module_info *m;
43
int lookup_version = AUTOFS_LOOKUP_VERSION; /* Required by protocol */
45
int lookup_init(const char *my_mapfmt, int argc, const char *const *argv, void **context)
47
struct lookup_context *ctxt;
51
if (!(*context = ctxt = malloc(sizeof(struct lookup_context))))
54
memset(ctxt, 0, sizeof(struct lookup_context));
57
crit(MODPREFIX "No map list");
61
ctxt->n = 1; /* Always at least one map */
62
for (i = 0; i < argc; i++) {
63
if (!strcmp(argv[i], "--")) /* -- separates maps */
67
if (!(ctxt->m = malloc(ctxt->n * sizeof(struct module_info))) ||
68
!(ctxt->argl = malloc((argc + 1) * sizeof(const char *))))
71
memset(ctxt->m, 0, ctxt->n * sizeof(struct module_info));
73
memcpy(ctxt->argl, argv, (argc + 1) * sizeof(const char *));
75
for (i = j = an = 0; ctxt->argl[an]; an++) {
76
if (ctxt->m[i].argc == 0) {
77
ctxt->m[i].argv = &ctxt->argl[an];
79
if (!strcmp(ctxt->argl[an], "--")) {
80
ctxt->argl[an] = NULL;
87
for (i = 0; i < ctxt->n; i++) {
88
if (!ctxt->m[i].argv[0]) {
89
crit(MODPREFIX "missing module name");
92
map = strdup(ctxt->m[i].argv[0]);
96
if ((mapfmt = strchr(map, ',')))
99
if (!(ctxt->m[i].mod = open_lookup(map, MODPREFIX,
100
mapfmt ? mapfmt : my_mapfmt,
102
ctxt->m[i].argv + 1)))
110
crit(MODPREFIX "malloc: %m");
114
int lookup_ghost(const char *root, int ghost, time_t now, void *context)
116
struct lookup_context *ctxt = (struct lookup_context *) context;
117
int i, ret, at_least_1 = 0;
119
for (i = 0; i < ctxt->n; i++) {
120
ret = ctxt->m[i].mod->lookup_ghost(root, ghost, now,
121
ctxt->m[i].mod->context);
134
int lookup_mount(const char *root, const char *name, int name_len, void *context)
136
struct lookup_context *ctxt = (struct lookup_context *) context;
139
for (i = 0; i < ctxt->n; i++) {
140
if (ctxt->m[i].mod->lookup_mount(root, name, name_len,
141
ctxt->m[i].mod->context) == 0)
144
return 1; /* No module succeeded */
147
int lookup_done(void *context)
149
struct lookup_context *ctxt = (struct lookup_context *) context;
152
for (i = 0; i < ctxt->n; i++) {
153
rv = rv || close_lookup(ctxt->m[i].mod);