~ubuntu-branches/ubuntu/trusty/libnss-ldap/trusty-proposed

« back to all changes in this revision

Viewing changes to doc/autofs-4.1.3-lookup-nssldap.patch

  • Committer: Bazaar Package Importer
  • Author(s): Richard A Nelson (Rick)
  • Date: 2007-05-14 19:40:00 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070514194000-40u9ndh540lgliqe
Tags: 255-1
Survived i386 and amd64, let it loose

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
3
 
@@ -0,0 +1,326 @@
4
 
+#ident "$Id: autofs-4.1.3-lookup-nssldap.patch,v 1.1 2005/08/08 23:28:37 lukeh Exp $"
5
 
+/* ----------------------------------------------------------------------- *
6
 
+ *
7
 
+ *  lookup_nss.c - module for Linux automountd to access a NSS
8
 
+ *              automount map
9
 
+ *
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
13
 
+ *
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.
19
 
+ *
20
 
+ * ----------------------------------------------------------------------- */
21
 
+
22
 
+#include <sys/types.h>
23
 
+#include <ctype.h>
24
 
+#include <string.h>
25
 
+#include <syslog.h>
26
 
+#include <unistd.h>
27
 
+#include <stdlib.h>
28
 
+#include <time.h>
29
 
+#include <netinet/in.h>
30
 
+#include <arpa/nameser.h>
31
 
+#include <resolv.h>
32
 
+#include <dlfcn.h>
33
 
+#include <nss.h>
34
 
+
35
 
+#define MODULE_LOOKUP
36
 
+#include "automount.h"
37
 
+
38
 
+#define MAPFMT_DEFAULT "sun"
39
 
+
40
 
+#define NAMESERVICE "ldap"
41
 
+
42
 
+#define MODPREFIX "lookup(nss" NAMESERVICE "): "
43
 
+
44
 
+struct lookup_context {
45
 
+       char *nsname;
46
 
+       char *mapname;
47
 
+       struct parse_mod *parse;
48
 
+       void *dlhandle;
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 *);
56
 
+};
57
 
+
58
 
+int lookup_version = AUTOFS_LOOKUP_VERSION;
59
 
+
60
 
+int lookup_init(const char *mapfmt, int argc, const char *const *argv, void **context_p)
61
 
+{
62
 
+       struct lookup_context *context;
63
 
+       char buf[1024];
64
 
+
65
 
+       context = (struct lookup_context *)malloc(sizeof(*context));
66
 
+       if (context == NULL) {
67
 
+               crit(MODPREFIX "malloc: %m");
68
 
+               return 1;
69
 
+       }
70
 
+       memset(context, 0, sizeof(*context));
71
 
+
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;
78
 
+
79
 
+       if (mapfmt == NULL) {
80
 
+               mapfmt = MAPFMT_DEFAULT;
81
 
+       }
82
 
+
83
 
+       if (argc < 1) {
84
 
+               crit(MODPREFIX "invalid number of arguments");
85
 
+               return 1;
86
 
+       }
87
 
+
88
 
+       asprintf(&context->nsname, "nss%s", NAMESERVICE);
89
 
+       if (context->nsname == NULL) {
90
 
+               crit(MODPREFIX "strdup: %m");
91
 
+               return 1;
92
 
+       }
93
 
+
94
 
+       snprintf(buf, sizeof(buf), "/lib/libnss_%s.so.2", NAMESERVICE);
95
 
+
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());
99
 
+               return 1;
100
 
+       }
101
 
+
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());
106
 
+               return 1;
107
 
+       }
108
 
+
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());
113
 
+               return 1;
114
 
+       }
115
 
+
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());
120
 
+               return 1;
121
 
+       }
122
 
+
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());
127
 
+               return 1;
128
 
+       }
129
 
+
130
 
+       context->mapname = strdup(argv[0]);
131
 
+       if (context->mapname == NULL) {
132
 
+               crit(MODPREFIX "strdup: %m");
133
 
+               return 1;
134
 
+       }
135
 
+
136
 
+       context->parse = open_parse(mapfmt, MODPREFIX, argc - 1, argv + 1);
137
 
+       if (context->parse == NULL) {
138
 
+               free(context);
139
 
+               return 1;
140
 
+       }
141
 
+
142
 
+       *context_p = context;
143
 
+       return 0;
144
 
+}
145
 
+
146
 
+static const char *nsserr_string(enum nss_status status)
147
 
+{
148
 
+       switch (status) {
149
 
+       case NSS_STATUS_TRYAGAIN:
150
 
+               return "Insufficient buffer space";
151
 
+               break;
152
 
+       case NSS_STATUS_UNAVAIL:
153
 
+               return "Name service unavailable";
154
 
+               break;
155
 
+       case NSS_STATUS_NOTFOUND:
156
 
+               return "Not found";
157
 
+               break;
158
 
+       case NSS_STATUS_SUCCESS:
159
 
+               return "Success";
160
 
+               break;
161
 
+       default:
162
 
+               break;
163
 
+       }
164
 
+
165
 
+       return "Unknown error";
166
 
+}
167
 
+
168
 
+static int read_map(const char *root, struct lookup_context *context)
169
 
+{
170
 
+       enum nss_status status;
171
 
+       void *private = NULL;
172
 
+       time_t age = time(NULL);
173
 
+       const char *key, *mapent;
174
 
+       int nss_errno;
175
 
+       char buffer[KEY_MAX_LEN + 1 + MAPENT_MAX_LEN + 1];
176
 
+
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));
181
 
+               return 0;
182
 
+       }
183
 
+
184
 
+       for (;;) {
185
 
+               status = (*context->getautomntent_r)(private, &key, &mapent,
186
 
+                                                    buffer, sizeof(buffer),
187
 
+                                                    &nss_errno);
188
 
+               if (status != NSS_STATUS_SUCCESS)
189
 
+                       break;
190
 
+
191
 
+               cache_update(key, mapent, age);
192
 
+       }
193
 
+
194
 
+       (*context->endautomntent)(&private);
195
 
+       
196
 
+       cache_clean(root, age);
197
 
+       return 1;
198
 
+}
199
 
+
200
 
+int lookup_ghost(const char *root, int ghost, void *context)
201
 
+{
202
 
+       struct lookup_context *ctxt = (struct lookup_context *)context;
203
 
+       struct mapent_cache *me;
204
 
+       int status = 1;
205
 
+
206
 
+       if (!read_map(root, ctxt))
207
 
+               return LKP_FAIL;
208
 
+
209
 
+       status = cache_ghost(root, ghost, ctxt->mapname, ctxt->nsname, ctxt->parse);
210
 
+
211
 
+       me = cache_lookup_first();
212
 
+       if (me == NULL)
213
 
+               return LKP_FAIL;
214
 
+
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 */
218
 
+               if (me == NULL)
219
 
+                       return LKP_FAIL | LKP_INDIRECT;
220
 
+       }
221
 
+
222
 
+       return status;
223
 
+}
224
 
+
225
 
+int lookup_mount(const char *root, const char *name, int name_len, void *context)
226
 
+{
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;
234
 
+
235
 
+       debug(MODPREFIX "looking up %s", name);
236
 
+
237
 
+       snprintf(key, sizeof(key), "%s/%s", root, name);
238
 
+
239
 
+       me = cache_lookup(name);
240
 
+       if (me == NULL) {
241
 
+               me = cache_lookup(key);
242
 
+       }
243
 
+
244
 
+       if (me == NULL) {
245
 
+               /* path component, do submount */
246
 
+               me = cache_partial_match(key);
247
 
+
248
 
+               if (me) {
249
 
+                       snprintf(buffer, sizeof(buffer), "-fstype=autofs %s:%s",
250
 
+                                ctxt->nsname, ctxt->mapname);
251
 
+                       mapent = buffer;
252
 
+               }
253
 
+       } else {
254
 
+               snprintf(buffer, sizeof(buffer), "%s", me->mapent);
255
 
+               mapent = buffer;
256
 
+       }
257
 
+
258
 
+       if (me == NULL) {
259
 
+               const char *keys[3];
260
 
+               int i;
261
 
+               int nss_errno;
262
 
+               void *private = NULL;
263
 
+
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));
267
 
+                       goto out_err;
268
 
+               }
269
 
+
270
 
+               keys[0] = name,
271
 
+               keys[1] = key;
272
 
+               keys[2] = "*";
273
 
+
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),
278
 
+                                                            &nss_errno);
279
 
+                       if (status != NSS_STATUS_NOTFOUND)
280
 
+                               break;
281
 
+               }
282
 
+
283
 
+               (*ctxt->endautomntent)(&private);
284
 
+
285
 
+               if (status != NSS_STATUS_SUCCESS) {
286
 
+                       warn(MODPREFIX "failed to read map %s: %s", ctxt->mapname, nsserr_string(status));
287
 
+                       goto out_err;
288
 
+               }
289
 
+
290
 
+               cache_update(keys[i], mapent, age);
291
 
+       }
292
 
+
293
 
+       debug(MODPREFIX "%s -> %s", name, mapent);
294
 
+
295
 
+       return ctxt->parse->parse_mount(root, name, name_len, mapent, ctxt->parse->context);
296
 
+
297
 
+out_err:
298
 
+       warn(MODPREFIX "lookup for %s failed: %d", name, status);
299
 
+       return 1;
300
 
+}
301
 
+
302
 
+int lookup_done(void *context)
303
 
+{
304
 
+       struct lookup_context *ctxt = (struct lookup_context *)context;
305
 
+       int ret;
306
 
+
307
 
+       if (ctxt->nsname != NULL) {
308
 
+               free(ctxt->nsname);
309
 
+               ctxt->nsname = NULL;
310
 
+       }
311
 
+
312
 
+       if (ctxt->mapname != NULL) {
313
 
+               free(ctxt->mapname);
314
 
+               ctxt->mapname = NULL;
315
 
+       }
316
 
+
317
 
+       ret = close_parse(ctxt->parse);
318
 
+
319
 
+       if (ctxt->dlhandle != NULL) {
320
 
+               dlclose(ctxt->dlhandle);
321
 
+               ctxt->dlhandle = NULL;
322
 
+       }
323
 
+
324
 
+       memset(ctxt, 0, sizeof(*ctxt));
325
 
+       free(ctxt);
326
 
+
327
 
+       return ret;
328
 
+}
329
 
+
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
332
 
@@ -16,6 +16,8 @@
333
 
  *
334
 
  * ----------------------------------------------------------------------- */
335
 
 
336
 
+#define _GNU_SOURCE
337
 
+#include <stdio.h>
338
 
 #include <sys/types.h>
339
 
 #include <ctype.h>
340
 
 #include <string.h>
341
 
@@ -88,7 +90,7 @@
342
 
                return 1;
343
 
        }
344
 
 
345
 
-       snprintf(buf, sizeof(buf), "/lib/libnss_%s.so.2", NAMESERVICE);
346
 
+       snprintf(buf, sizeof(buf), "libnss_%s.so.2", NAMESERVICE);
347
 
 
348
 
        context->dlhandle = dlopen(buf, RTLD_NOW | RTLD_LOCAL);
349
 
        if (context->dlhandle == NULL) {
350
 
@@ -184,8 +186,11 @@
351
 
                                                     &nss_errno);
352
 
                if (status != NSS_STATUS_SUCCESS)
353
 
                        break;
354
 
-
355
 
+#ifdef CHE_FAIL
356
 
+                cache_update(root, key, mapent, age);
357
 
+#else
358
 
                cache_update(key, mapent, age);
359
 
+#endif
360
 
        }
361
 
 
362
 
        (*context->endautomntent)(&private);
363
 
@@ -194,7 +199,7 @@
364
 
        return 1;
365
 
 }
366
 
 
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)
369
 
 {
370
 
        struct lookup_context *ctxt = (struct lookup_context *)context;
371
 
        struct mapent_cache *me;
372
 
@@ -284,7 +289,11 @@
373
 
                        goto out_err;
374
 
                }
375
 
 
376
 
+#ifdef CHE_FAIL
377
 
+                cache_update(root, keys[i], mapent, age);
378
 
+#else
379
 
                cache_update(keys[i], mapent, age);
380
 
+#endif
381
 
        }
382
 
 
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
386
 
@@ -7,13 +7,13 @@
387
 
 include ../Makefile.rules
388
 
 
389
 
 SRCS :=        lookup_yp.c  lookup_file.c  lookup_program.c  lookup_userhome.c \
390
 
-       lookup_multi.c \
391
 
+       lookup_multi.c lookup_nssldap.c \
392
 
        parse_sun.c    \
393
 
        mount_generic.c  mount_nfs.c  mount_afs.c  mount_autofs.c \
394
 
        mount_changer.c  mount_bind.c
395
 
 
396
 
 MODS :=        lookup_yp.so lookup_file.so lookup_program.so lookup_userhome.so \
397
 
-       lookup_multi.so \
398
 
+       lookup_multi.so lookup_nssldap.so \
399
 
        parse_sun.so \
400
 
        mount_generic.so mount_nfs.so mount_afs.so mount_autofs.so \
401
 
        mount_changer.so mount_bind.so