1
--- autofs-4.1.3/modules/lookup_nssldap.c 1970-01-01 01:00:00.000000000 +0100
2
+++ autofs-4.1.3/modules/lookup_nssldap.c 2005-06-28 15:13:49.000000000 +0200
4
+#ident "$Id: autofs-4.1.3-lookup-nssldap.patch,v 1.1 2005/08/08 23:28:37 lukeh Exp $"
5
+/* ----------------------------------------------------------------------- *
7
+ * lookup_nss.c - module for Linux automountd to access a NSS
10
+ * Copyright 1997 Transmeta Corporation - All Rights Reserved
11
+ * Copyright 2001-2003 Ian Kent <raven@themaw.net>
12
+ * Copyright 2005 PADL Software Pty Ltd - All Rights Reserved
14
+ * This program is free software; you can redistribute it and/or modify
15
+ * it under the terms of the GNU General Public License as published by
16
+ * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
17
+ * USA; either version 2 of the License, or (at your option) any later
18
+ * version; incorporated herein by reference.
20
+ * ----------------------------------------------------------------------- */
22
+#include <sys/types.h>
29
+#include <netinet/in.h>
30
+#include <arpa/nameser.h>
35
+#define MODULE_LOOKUP
36
+#include "automount.h"
38
+#define MAPFMT_DEFAULT "sun"
40
+#define NAMESERVICE "ldap"
42
+#define MODPREFIX "lookup(nss" NAMESERVICE "): "
44
+struct lookup_context {
47
+ struct parse_mod *parse;
49
+ enum nss_status (*setautomntent)(const char *, void **);
50
+ enum nss_status (*getautomntent_r)(void *, const char **, const char **,
51
+ char *, size_t, int *);
52
+ enum nss_status (*endautomntent)(void **);
53
+ enum nss_status (*getautomntbyname_r)(void *, const char *,
54
+ const char **, const char **,
55
+ char *, size_t, int *);
58
+int lookup_version = AUTOFS_LOOKUP_VERSION;
60
+int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **context_p)
62
+ struct lookup_context *context;
65
+ context = (struct lookup_context *)malloc(sizeof(*context));
66
+ if (context == NULL) {
67
+ crit(MODPREFIX "malloc: %m");
70
+ memset(context, 0, sizeof(*context));
72
+ context->nsname = NULL;
73
+ context->parse = NULL;
74
+ context->dlhandle = NULL;
75
+ context->setautomntent = NULL;
76
+ context->getautomntent_r = NULL;
77
+ context->endautomntent = NULL;
79
+ if (mapfmt == NULL) {
80
+ mapfmt = MAPFMT_DEFAULT;
84
+ crit(MODPREFIX "invalid number of arguments");
88
+ asprintf(&context->nsname, "nss%s", NAMESERVICE);
89
+ if (context->nsname == NULL) {
90
+ crit(MODPREFIX "strdup: %m");
94
+ snprintf(buf, sizeof(buf), "/lib/libnss_%s.so.2", NAMESERVICE);
96
+ context->dlhandle = dlopen(buf, RTLD_NOW | RTLD_LOCAL);
97
+ if (context->dlhandle == NULL) {
98
+ crit(MODPREFIX "failed to load %s nameservice provider: %s", NAMESERVICE, dlerror());
102
+ snprintf(buf, sizeof(buf), "_nss_%s_setautomntent", NAMESERVICE);
103
+ context->setautomntent = dlsym(context->dlhandle, buf);
104
+ if (context->setautomntent == NULL) {
105
+ crit(MODPREFIX "failed to load %s nameservice provider: %s", NAMESERVICE, dlerror());
109
+ snprintf(buf, sizeof(buf), "_nss_%s_getautomntent_r", NAMESERVICE);
110
+ context->getautomntent_r = dlsym(context->dlhandle, buf);
111
+ if (context->getautomntent_r == NULL) {
112
+ crit(MODPREFIX "failed to load %s nameservice provider: %s", NAMESERVICE, dlerror());
116
+ snprintf(buf, sizeof(buf), "_nss_%s_endautomntent", NAMESERVICE);
117
+ context->endautomntent = dlsym(context->dlhandle, buf);
118
+ if (context->endautomntent == NULL) {
119
+ crit(MODPREFIX "failed to load %s nameservice provider: %s", NAMESERVICE, dlerror());
123
+ snprintf(buf, sizeof(buf), "_nss_%s_getautomntbyname_r", NAMESERVICE);
124
+ context->getautomntbyname_r = dlsym(context->dlhandle, buf);
125
+ if (context->getautomntbyname_r == NULL) {
126
+ crit(MODPREFIX "failed to load %s nameservice provider: %s", NAMESERVICE, dlerror());
130
+ context->mapname = strdup(argv[0]);
131
+ if (context->mapname == NULL) {
132
+ crit(MODPREFIX "strdup: %m");
136
+ context->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
137
+ if (context->parse == NULL) {
142
+ *context_p = context;
146
+static const char *nsserr_string(enum nss_status status)
149
+ case NSS_STATUS_TRYAGAIN:
150
+ return "Insufficient buffer space";
152
+ case NSS_STATUS_UNAVAIL:
153
+ return "Name service unavailable";
155
+ case NSS_STATUS_NOTFOUND:
156
+ return "Not found";
158
+ case NSS_STATUS_SUCCESS:
165
+ return "Unknown error";
168
+static int read_map(const char *root, struct lookup_context *context)
170
+ enum nss_status status;
171
+ void *private = NULL;
172
+ time_t age = time(NULL);
173
+ const char *key, *mapent;
175
+ char buffer[KEY_MAX_LEN + 1 + MAPENT_MAX_LEN + 1];
177
+ status = (*context->setautomntent)(context->mapname, &private);
178
+ if (status != NSS_STATUS_SUCCESS) {
179
+ warn(MODPREFIX "failed to read map %s: %s",
180
+ context->mapname, nsserr_string(status));
185
+ status = (*context->getautomntent_r)(private, &key, &mapent,
186
+ buffer, sizeof(buffer),
188
+ if (status != NSS_STATUS_SUCCESS)
191
+ cache_update(key, mapent, age);
194
+ (*context->endautomntent)(&private);
196
+ cache_clean(root, age);
200
+int lookup_ghost(const char *root, int ghost, void *context)
202
+ struct lookup_context *ctxt = (struct lookup_context *)context;
203
+ struct mapent_cache *me;
206
+ if (!read_map(root, ctxt))
209
+ status = cache_ghost(root, ghost, ctxt->mapname, ctxt->nsname, ctxt->parse);
211
+ me = cache_lookup_first();
215
+ if (*me->key == '/' && *(root + 1) != '-') {
216
+ me = cache_partial_match(root);
217
+ /* me NULL => no entries for this direct mount root or indirect map */
219
+ return LKP_FAIL | LKP_INDIRECT;
225
+int lookup_mount(const char *root, const char *name, int name_len, void *context)
227
+ struct lookup_context *ctxt = (struct lookup_context *)context;
228
+ char key[KEY_MAX_LEN + 1];
229
+ char buffer[KEY_MAX_LEN + 1 + MAPENT_MAX_LEN + 1];
230
+ const char *canon_key, *mapent;
231
+ struct mapent_cache *me = NULL;
232
+ time_t age = time(NULL);
233
+ enum nss_status status;
235
+ debug(MODPREFIX "looking up %s", name);
237
+ snprintf(key, sizeof(key), "%s/%s", root, name);
239
+ me = cache_lookup(name);
241
+ me = cache_lookup(key);
245
+ /* path component, do submount */
246
+ me = cache_partial_match(key);
249
+ snprintf(buffer, sizeof(buffer), "-fstype=autofs %s:%s",
250
+ ctxt->nsname, ctxt->mapname);
254
+ snprintf(buffer, sizeof(buffer), "%s", me->mapent);
259
+ const char *keys[3];
262
+ void *private = NULL;
264
+ status = (*ctxt->setautomntent)(ctxt->mapname, &private);
265
+ if (status != NSS_STATUS_SUCCESS) {
266
+ warn(MODPREFIX "failed to read map %s: %s", ctxt->mapname, nsserr_string(status));
274
+ for (i = 0; i < sizeof(keys)/sizeof(keys[0]); i++) {
275
+ status = (*ctxt->getautomntbyname_r)(private, name,
276
+ &canon_key, &mapent,
277
+ buffer, sizeof(buffer),
279
+ if (status != NSS_STATUS_NOTFOUND)
283
+ (*ctxt->endautomntent)(&private);
285
+ if (status != NSS_STATUS_SUCCESS) {
286
+ warn(MODPREFIX "failed to read map %s: %s", ctxt->mapname, nsserr_string(status));
290
+ cache_update(keys[i], mapent, age);
293
+ debug(MODPREFIX "%s -> %s", name, mapent);
295
+ return ctxt->parse->parse_mount(root, name, name_len, mapent, ctxt->parse->context);
298
+ warn(MODPREFIX "lookup for %s failed: %d", name, status);
302
+int lookup_done(void *context)
304
+ struct lookup_context *ctxt = (struct lookup_context *)context;
307
+ if (ctxt->nsname != NULL) {
308
+ free(ctxt->nsname);
309
+ ctxt->nsname = NULL;
312
+ if (ctxt->mapname != NULL) {
313
+ free(ctxt->mapname);
314
+ ctxt->mapname = NULL;
317
+ ret = close_parse(ctxt->parse);
319
+ if (ctxt->dlhandle != NULL) {
320
+ dlclose(ctxt->dlhandle);
321
+ ctxt->dlhandle = NULL;
324
+ memset(ctxt, 0, sizeof(*ctxt));
330
--- autofs-4.1.3/modules/lookup_nssldap.c 2005-06-28 15:13:49.000000000 +0200
331
+++ autofs-4.1.3/modules/lookup_nssldap.c 2005-07-21 11:32:58.000000000 +0200
334
* ----------------------------------------------------------------------- */
338
#include <sys/types.h>
345
- snprintf(buf, sizeof(buf), "/lib/libnss_%s.so.2", NAMESERVICE);
346
+ snprintf(buf, sizeof(buf), "libnss_%s.so.2", NAMESERVICE);
348
context->dlhandle = dlopen(buf, RTLD_NOW | RTLD_LOCAL);
349
if (context->dlhandle == NULL) {
352
if (status != NSS_STATUS_SUCCESS)
356
+ cache_update(root, key, mapent, age);
358
cache_update(key, mapent, age);
362
(*context->endautomntent)(&private);
367
-int lookup_ghost(const char *root, int ghost, void *context)
368
+int lookup_ghost(const char *root, int ghost, time_t now, void *context)
370
struct lookup_context *ctxt = (struct lookup_context *)context;
371
struct mapent_cache *me;
377
+ cache_update(root, keys[i], mapent, age);
379
cache_update(keys[i], mapent, age);
383
debug(MODPREFIX "%s -> %s", name, mapent);
384
--- autofs-4.1.3/modules/Makefile 2004-04-03 09:14:33.000000000 +0200
385
+++ autofs-4.1.3/modules/Makefile 2005-07-21 11:39:35.000000000 +0200
387
include ../Makefile.rules
389
SRCS := lookup_yp.c lookup_file.c lookup_program.c lookup_userhome.c \
391
+ lookup_multi.c lookup_nssldap.c \
393
mount_generic.c mount_nfs.c mount_afs.c mount_autofs.c \
394
mount_changer.c mount_bind.c
396
MODS := lookup_yp.so lookup_file.so lookup_program.so lookup_userhome.so \
398
+ lookup_multi.so lookup_nssldap.so \
400
mount_generic.so mount_nfs.so mount_afs.so mount_autofs.so \
401
mount_changer.so mount_bind.so