]>
Commit | Line | Data |
---|---|---|
3d551623 PG |
1 | diff --git a/CHANGELOG b/CHANGELOG |
2 | index 91903e9..6b16b0f 100644 | |
3 | --- a/CHANGELOG | |
4 | +++ b/CHANGELOG | |
5 | @@ -2,6 +2,7 @@ | |
6 | ----------------------- | |
7 | - include krb5.h in lookup_ldap.h (some openssl doesn't implicitly include it). | |
8 | - correct initialization of local var in parse_server_string. | |
9 | +- add missing "multi" map support. | |
10 | ||
11 | 18/06/2007 autofs-5.0.2 | |
12 | ----------------------- | |
13 | diff --git a/daemon/lookup.c b/daemon/lookup.c | |
14 | index 06fcecc..70b9e02 100644 | |
15 | --- a/daemon/lookup.c | |
16 | +++ b/daemon/lookup.c | |
17 | @@ -456,8 +456,12 @@ int lookup_nss_read_map(struct autofs_point *ap, struct map_source *source, time | |
18 | } | |
19 | ||
20 | if (map->type) { | |
21 | - debug(ap->logopt, | |
22 | - "reading map %s %s", map->type, map->argv[0]); | |
23 | + if (!strncmp(map->type, "multi", 5)) | |
24 | + debug(ap->logopt, "reading multi map"); | |
25 | + else | |
26 | + debug(ap->logopt, | |
27 | + "reading map %s %s", | |
28 | + map->type, map->argv[0]); | |
29 | result = do_read_map(ap, map, age); | |
30 | map = map->next; | |
31 | continue; | |
32 | diff --git a/include/automount.h b/include/automount.h | |
33 | index 85e6e9c..106ed0a 100644 | |
34 | --- a/include/automount.h | |
35 | +++ b/include/automount.h | |
36 | @@ -192,6 +192,7 @@ char *cache_get_offset(const char *prefix, char *offset, int start, struct list_ | |
37 | /* Utility functions */ | |
38 | ||
39 | char **add_argv(int argc, char **argv, char *str); | |
40 | +char **append_argv(int argc1, char **argv1, int argc2, char **argv2); | |
41 | const char **copy_argv(int argc, const char **argv); | |
42 | int compare_argv(int argc1, const char **argv1, int argc2, const char **argv2); | |
43 | int free_argv(int argc, const char **argv); | |
44 | diff --git a/lib/args.c b/lib/args.c | |
45 | index 9e35388..fbfb004 100644 | |
46 | --- a/lib/args.c | |
47 | +++ b/lib/args.c | |
48 | @@ -62,6 +62,45 @@ char **add_argv(int argc, char **argv, char *str) | |
49 | return vector; | |
50 | } | |
51 | ||
52 | +char **append_argv(int argc1, char **argv1, int argc2, char **argv2) | |
53 | +{ | |
54 | + char **vector; | |
55 | + size_t vector_size; | |
56 | + int len, i, j; | |
57 | + | |
58 | + len = argc1 + argc2; | |
59 | + vector_size = (len + 1) * sizeof(char *); | |
60 | + vector = (char **) realloc(argv1, vector_size); | |
61 | + if (!vector) { | |
62 | + free_argv(argc1, (const char **) argv1); | |
63 | + free_argv(argc2, (const char **) argv2); | |
64 | + return NULL; | |
65 | + } | |
66 | + | |
67 | + for (i = argc1, j = 0; i <= len; i++, j++) { | |
68 | + if (argv2[j]) { | |
69 | + vector[i] = strdup(argv2[j]); | |
70 | + if (!vector[i]) { | |
71 | + error(LOGOPT_ANY, "failed to strdup arg"); | |
72 | + break; | |
73 | + } | |
74 | + } else | |
75 | + vector[i] = NULL; | |
76 | + } | |
77 | + | |
78 | + if (i < len) { | |
79 | + free_argv(len, (const char **) vector); | |
80 | + free_argv(argc2, (const char **) argv2); | |
81 | + return NULL; | |
82 | + } | |
83 | + | |
84 | + vector[len] = NULL; | |
85 | + | |
86 | + free_argv(argc2, (const char **) argv2); | |
87 | + | |
88 | + return vector; | |
89 | +} | |
90 | + | |
91 | const char **copy_argv(int argc, const char **argv) | |
92 | { | |
93 | char **vector; | |
94 | diff --git a/lib/master_parse.y b/lib/master_parse.y | |
95 | index 8d2be02..f9cba05 100644 | |
96 | --- a/lib/master_parse.y | |
97 | +++ b/lib/master_parse.y | |
98 | @@ -22,6 +22,7 @@ | |
99 | #include <string.h> | |
100 | #include <stdlib.h> | |
101 | #include <stdarg.h> | |
102 | +#include <ctype.h> | |
103 | #include <sys/ioctl.h> | |
104 | ||
105 | #include "automount.h" | |
106 | @@ -44,6 +45,7 @@ extern void master_set_scan_buffer(const char *); | |
107 | static char *master_strdup(char *); | |
108 | static void local_init_vars(void); | |
109 | static void local_free_vars(void); | |
110 | +static int add_multi_mapstr(void); | |
111 | ||
112 | static int master_error(const char *s); | |
113 | static int master_notify(const char *s); | |
114 | @@ -53,6 +55,8 @@ static char *type; | |
115 | static char *format; | |
116 | static long timeout; | |
117 | static unsigned ghost; | |
118 | +static char **tmp_argv; | |
119 | +static int tmp_argc; | |
120 | static char **local_argv; | |
121 | static int local_argc; | |
122 | ||
123 | @@ -89,7 +93,7 @@ static int master_fprintf(FILE *, char *, ...); | |
124 | %token COMMENT | |
125 | %token MAP | |
126 | %token OPT_TIMEOUT OPT_NOGHOST OPT_GHOST OPT_VERBOSE OPT_DEBUG | |
127 | -%token COLON COMMA NL | |
128 | +%token COLON COMMA NL DDASH | |
129 | %type <strtype> map | |
130 | %type <strtype> options | |
131 | %type <strtype> dn | |
132 | @@ -103,6 +107,7 @@ static int master_fprintf(FILE *, char *, ...); | |
133 | %token <strtype> NILL | |
134 | %token <strtype> SPACE | |
135 | %token <strtype> EQUAL | |
136 | +%token <strtype> MULTITYPE | |
137 | %token <strtype> MAPTYPE | |
138 | %token <strtype> DNSERVER | |
139 | %token <strtype> DNATTR | |
140 | @@ -126,7 +131,7 @@ file: { | |
141 | ; | |
142 | ||
143 | line: | |
144 | - | PATH map | |
145 | + | PATH mapspec | |
146 | { | |
147 | path = master_strdup($1); | |
148 | if (!path) { | |
149 | @@ -134,14 +139,49 @@ line: | |
150 | YYABORT; | |
151 | } | |
152 | } | |
153 | - | PATH map options | |
154 | + | PATH MULTITYPE maplist | |
155 | { | |
156 | + char *tmp; | |
157 | + | |
158 | + tmp = strchr($2, ':'); | |
159 | + if (tmp) | |
160 | + *tmp = '\0'; | |
161 | + else { | |
162 | + int len = strlen($2); | |
163 | + while (len-- && isblank($2[len])) | |
164 | + $2[len] = '\0'; | |
165 | + if (len < 4) { | |
166 | + master_notify($2); | |
167 | + local_free_vars(); | |
168 | + YYABORT; | |
169 | + } | |
170 | + } | |
171 | + | |
172 | path = master_strdup($1); | |
173 | if (!path) { | |
174 | + master_error("memory allocation error"); | |
175 | local_free_vars(); | |
176 | YYABORT; | |
177 | } | |
178 | - } | |
179 | + | |
180 | + if ((tmp = strchr($2, ','))) | |
181 | + *tmp++ = '\0'; | |
182 | + | |
183 | + type = master_strdup($2); | |
184 | + if (!type) { | |
185 | + master_error("memory allocation error"); | |
186 | + local_free_vars(); | |
187 | + YYABORT; | |
188 | + } | |
189 | + if (tmp) { | |
190 | + format = master_strdup(tmp); | |
191 | + if (!format) { | |
192 | + master_error("memory allocation error"); | |
193 | + local_free_vars(); | |
194 | + YYABORT; | |
195 | + } | |
196 | + } | |
197 | + } | |
198 | | PATH COLON { master_notify($1); YYABORT; } | |
199 | | PATH OPTION { master_notify($2); YYABORT; } | |
200 | | PATH NILL { master_notify($2); YYABORT; } | |
201 | @@ -157,25 +197,89 @@ line: | |
202 | | COMMENT { YYABORT; } | |
203 | ; | |
204 | ||
205 | -map: PATH | |
206 | +mapspec: map | |
207 | + { | |
208 | + local_argc = tmp_argc; | |
209 | + local_argv = tmp_argv; | |
210 | + tmp_argc = 0; | |
211 | + tmp_argv = NULL; | |
212 | + } | |
213 | + | map options | |
214 | + { | |
215 | + local_argc = tmp_argc; | |
216 | + local_argv = tmp_argv; | |
217 | + tmp_argc = 0; | |
218 | + tmp_argv = NULL; | |
219 | + } | |
220 | + ; | |
221 | + | |
222 | +maplist: map | |
223 | + { | |
224 | + if (!add_multi_mapstr()) { | |
225 | + master_error("memory allocation error"); | |
226 | + local_free_vars(); | |
227 | + YYABORT; | |
228 | + } | |
229 | + } | |
230 | + | map options | |
231 | + { | |
232 | + if (!add_multi_mapstr()) { | |
233 | + master_error("memory allocation error"); | |
234 | + local_free_vars(); | |
235 | + YYABORT; | |
236 | + } | |
237 | + } | |
238 | + | maplist DDASH map | |
239 | { | |
240 | local_argc++; | |
241 | - local_argv = add_argv(local_argc, local_argv, $1); | |
242 | + local_argv = add_argv(local_argc, local_argv, "--"); | |
243 | if (!local_argv) { | |
244 | master_error("memory allocation error"); | |
245 | local_free_vars(); | |
246 | YYABORT; | |
247 | } | |
248 | + if (!add_multi_mapstr()) { | |
249 | + master_error("memory allocation error"); | |
250 | + local_free_vars(); | |
251 | + YYABORT; | |
252 | + } | |
253 | } | |
254 | - | MAPNAME | |
255 | + | maplist DDASH map options | |
256 | { | |
257 | local_argc++; | |
258 | - local_argv = add_argv(local_argc, local_argv, $1); | |
259 | + local_argv = add_argv(local_argc, local_argv, "--"); | |
260 | if (!local_argv) { | |
261 | master_error("memory allocation error"); | |
262 | local_free_vars(); | |
263 | YYABORT; | |
264 | } | |
265 | + if (!add_multi_mapstr()) { | |
266 | + master_error("memory allocation error"); | |
267 | + local_free_vars(); | |
268 | + YYABORT; | |
269 | + } | |
270 | + } | |
271 | + ; | |
272 | + | |
273 | +map: PATH | |
274 | + { | |
275 | + tmp_argc++; | |
276 | + tmp_argv = add_argv(tmp_argc, tmp_argv, $1); | |
277 | + if (!tmp_argv) { | |
278 | + master_error("memory allocation error"); | |
279 | + local_free_vars(); | |
280 | + YYABORT; | |
281 | + } | |
282 | + } | |
283 | + | MAPNAME | |
284 | + { | |
285 | + tmp_argc++; | |
286 | + tmp_argv = add_argv(tmp_argc, tmp_argv, $1); | |
287 | + if (!tmp_argv) { | |
288 | + master_error("memory allocation error"); | |
289 | + local_free_vars(); | |
290 | + YYABORT; | |
291 | + } | |
292 | } | |
293 | | MAPHOSTS | |
294 | { | |
295 | @@ -200,9 +304,9 @@ map: PATH | |
296 | local_free_vars(); | |
297 | YYABORT; | |
298 | } | |
299 | - local_argc++; | |
300 | - local_argv = add_argv(local_argc, local_argv, $1); | |
301 | - if (!local_argv) { | |
302 | + tmp_argc++; | |
303 | + tmp_argv = add_argv(tmp_argc, tmp_argv, $1); | |
304 | + if (!tmp_argv) { | |
305 | master_error("memory allocation error"); | |
306 | local_free_vars(); | |
307 | YYABORT; | |
308 | @@ -227,9 +331,9 @@ map: PATH | |
309 | YYABORT; | |
310 | } | |
311 | } | |
312 | - local_argc++; | |
313 | - local_argv = add_argv(local_argc, local_argv, $3); | |
314 | - if (!local_argv) { | |
315 | + tmp_argc++; | |
316 | + tmp_argv = add_argv(tmp_argc, tmp_argv, $3); | |
317 | + if (!tmp_argv) { | |
318 | master_error("memory allocation error"); | |
319 | local_free_vars(); | |
320 | YYABORT; | |
321 | @@ -254,9 +358,9 @@ map: PATH | |
322 | YYABORT; | |
323 | } | |
324 | } | |
325 | - local_argc++; | |
326 | - local_argv = add_argv(local_argc, local_argv, $3); | |
327 | - if (!local_argv) { | |
328 | + tmp_argc++; | |
329 | + tmp_argv = add_argv(tmp_argc, tmp_argv, $3); | |
330 | + if (!tmp_argv) { | |
331 | master_error("memory allocation error"); | |
332 | local_free_vars(); | |
333 | YYABORT; | |
334 | @@ -281,25 +385,25 @@ map: PATH | |
335 | YYABORT; | |
336 | } | |
337 | } | |
338 | - local_argc++; | |
339 | - local_argv = add_argv(local_argc, local_argv, $3); | |
340 | - if (!local_argv) { | |
341 | + tmp_argc++; | |
342 | + tmp_argv = add_argv(tmp_argc, tmp_argv, $3); | |
343 | + if (!tmp_argv) { | |
344 | master_error("memory allocation error"); | |
345 | local_free_vars(); | |
346 | YYABORT; | |
347 | } | |
348 | /* Add back the type for lookup_ldap.c to handle ldaps */ | |
349 | - if (*local_argv[0]) { | |
350 | - tmp = malloc(strlen(type) + strlen(local_argv[0]) + 2); | |
351 | + if (*tmp_argv[0]) { | |
352 | + tmp = malloc(strlen(type) + strlen(tmp_argv[0]) + 2); | |
353 | if (!tmp) { | |
354 | local_free_vars(); | |
355 | YYABORT; | |
356 | } | |
357 | strcpy(tmp, type); | |
358 | strcat(tmp, ":"); | |
359 | - strcat(tmp, local_argv[0]); | |
360 | - free(local_argv[0]); | |
361 | - local_argv[0] = tmp; | |
362 | + strcat(tmp, tmp_argv[0]); | |
363 | + free(tmp_argv[0]); | |
364 | + tmp_argv[0] = tmp; | |
365 | } | |
366 | } | |
367 | ; | |
368 | @@ -441,9 +545,9 @@ daemon_option: OPT_TIMEOUT NUMBER { timeout = $2; } | |
369 | ||
370 | mount_option: OPTION | |
371 | { | |
372 | - local_argc++; | |
373 | - local_argv = add_argv(local_argc, local_argv, $1); | |
374 | - if (!local_argv) { | |
375 | + tmp_argc++; | |
376 | + tmp_argv = add_argv(tmp_argc, tmp_argv, $1); | |
377 | + if (!tmp_argv) { | |
378 | master_error("memory allocation error"); | |
379 | local_free_vars(); | |
380 | YYABORT; | |
381 | @@ -494,6 +598,8 @@ static void local_init_vars(void) | |
382 | debug = 0; | |
383 | timeout = -1; | |
384 | ghost = defaults_get_browse_mode(); | |
385 | + tmp_argv = NULL; | |
386 | + tmp_argc = 0; | |
387 | local_argv = NULL; | |
388 | local_argc = 0; | |
389 | } | |
390 | @@ -509,8 +615,62 @@ static void local_free_vars(void) | |
391 | if (format) | |
392 | free(format); | |
393 | ||
394 | - if (local_argv) | |
395 | + if (local_argv) { | |
396 | free_argv(local_argc, (const char **) local_argv); | |
397 | + local_argv = NULL; | |
398 | + local_argc = 0; | |
399 | + } | |
400 | + | |
401 | + if (tmp_argv) { | |
402 | + free_argv(tmp_argc, (const char **) tmp_argv); | |
403 | + tmp_argv = NULL; | |
404 | + tmp_argc = 0; | |
405 | + } | |
406 | +} | |
407 | + | |
408 | +static int add_multi_mapstr(void) | |
409 | +{ | |
410 | + /* We need the individual map types for a multi map */ | |
411 | + if (!type) { | |
412 | + if (tmp_argc > 0 && *tmp_argv[0] == '/') | |
413 | + type = strdup("file"); | |
414 | + else | |
415 | + return 0; | |
416 | + } | |
417 | + | |
418 | + if (format) { | |
419 | + char *tmp = realloc(type, strlen(type) + strlen(format) + 2); | |
420 | + if (!tmp) | |
421 | + return 0; | |
422 | + type = tmp; | |
423 | + strcat(type, ","); | |
424 | + strcat(type, format); | |
425 | + free(format); | |
426 | + format = NULL; | |
427 | + } | |
428 | + | |
429 | + local_argc++; | |
430 | + local_argv = add_argv(local_argc, local_argv, type); | |
431 | + if (!local_argv) { | |
432 | + free(type); | |
433 | + type = NULL; | |
434 | + return 0; | |
435 | + } | |
436 | + | |
437 | + local_argv = append_argv(local_argc, local_argv, tmp_argc, tmp_argv); | |
438 | + if (!local_argv) { | |
439 | + free(type); | |
440 | + type = NULL; | |
441 | + return 0; | |
442 | + } | |
443 | + local_argc += tmp_argc; | |
444 | + | |
445 | + tmp_argc = 0; | |
446 | + tmp_argv = NULL; | |
447 | + free(type); | |
448 | + type = NULL; | |
449 | + | |
450 | + return 1; | |
451 | } | |
452 | ||
453 | void master_init_scan(void) | |
454 | diff --git a/lib/master_tok.l b/lib/master_tok.l | |
455 | index ee2a4eb..0548de1 100644 | |
456 | --- a/lib/master_tok.l | |
457 | +++ b/lib/master_tok.l | |
458 | @@ -27,6 +27,7 @@ static void master_echo(void); /* forward definition */ | |
459 | #include <stdio.h> | |
460 | #include <stdlib.h> | |
461 | #include <string.h> | |
462 | +#include <ctype.h> | |
463 | #include "master_parse.tab.h" | |
464 | ||
465 | /* | |
466 | @@ -110,7 +111,9 @@ DNATTRSTR {AT_CN}|{AT_NMN}|{AT_AMN}|{AT_OU}|{AT_DC}|{AT_O}|{AT_C} | |
467 | DNNAMESTR ([[:alnum:]_.\-]+) | |
468 | ||
469 | INTMAP (-hosts|-null) | |
470 | -MTYPE ((file|program|yp|nis|nisplus|ldap|ldaps|hesiod|userdir)(,(sun|hesiod))?) | |
471 | +MULTI ((multi)(,(sun|hesiod))?[\:]?{OPTWS}) | |
472 | +MULTISEP ([\-]{2}[[:blank:]]+) | |
473 | +MTYPE ((file|program|yp|nis|nisplus|ldap|ldaps|hesiod|userdir)(,(sun|hesiod))?) | |
474 | ||
475 | ||
476 | OPTTOUT (-t{OPTWS}|-t{OPTWS}={OPTWS}|--timeout{OPTWS}|--timeout{OPTWS}={OPTWS}) | |
477 | @@ -184,11 +187,18 @@ OPTTOUT (-t{OPTWS}|-t{OPTWS}={OPTWS}|--timeout{OPTWS}|--timeout{OPTWS}={OPTWS}) | |
478 | <MAPSTR>{ | |
479 | {OPTWS}\\\n{OPTWS} {} | |
480 | ||
481 | + {MULTI} { | |
482 | + strcpy(master_lval.strtype, master_text); | |
483 | + return(MULTITYPE); | |
484 | + } | |
485 | + | |
486 | {MTYPE}/":" { | |
487 | strcpy(master_lval.strtype, master_text); | |
488 | return(MAPTYPE); | |
489 | } | |
490 | ||
491 | + {MULTISEP} { return(DDASH); } | |
492 | + | |
493 | ":" { return(COLON); } | |
494 | ||
495 | "-hosts" { | |
496 | @@ -298,6 +308,11 @@ OPTTOUT (-t{OPTWS}|-t{OPTWS}={OPTWS}|--timeout{OPTWS}|--timeout{OPTWS}={OPTWS}) | |
497 | <OPTSTR>{ | |
498 | {OPTWS}\\\n{OPTWS} {} | |
499 | ||
500 | + {MULTISEP} { | |
501 | + BEGIN(MAPSTR); | |
502 | + return(DDASH); | |
503 | + } | |
504 | + | |
505 | {OPTTOUT} { return(OPT_TIMEOUT); } | |
506 | ||
507 | {NUMBER} { | |
508 | diff --git a/modules/lookup_multi.c b/modules/lookup_multi.c | |
509 | index 00ab28e..38ca36c 100644 | |
510 | --- a/modules/lookup_multi.c | |
511 | +++ b/modules/lookup_multi.c | |
512 | @@ -45,7 +45,7 @@ int lookup_init(const char *my_mapfmt, int argc, const char *const *argv, void * | |
513 | struct lookup_context *ctxt; | |
514 | char buf[MAX_ERR_BUF]; | |
515 | char *map, *mapfmt; | |
516 | - int i, j, an; | |
517 | + int i, an; | |
518 | char *estr; | |
519 | ||
520 | ctxt = malloc(sizeof(struct lookup_context)); | |
521 | @@ -73,7 +73,7 @@ int lookup_init(const char *my_mapfmt, int argc, const char *const *argv, void * | |
522 | ||
523 | memcpy(ctxt->argl, argv, (argc + 1) * sizeof(const char *)); | |
524 | ||
525 | - for (i = j = an = 0; ctxt->argl[an]; an++) { | |
526 | + for (i = an = 0; ctxt->argl[an]; an++) { | |
527 | if (ctxt->m[i].argc == 0) { | |
528 | ctxt->m[i].argv = &ctxt->argl[an]; | |
529 | } | |
530 | @@ -100,9 +100,12 @@ int lookup_init(const char *my_mapfmt, int argc, const char *const *argv, void * | |
531 | if (!(ctxt->m[i].mod = open_lookup(map, MODPREFIX, | |
532 | mapfmt ? mapfmt : my_mapfmt, | |
533 | ctxt->m[i].argc - 1, | |
534 | - ctxt->m[i].argv + 1))) | |
535 | + ctxt->m[i].argv + 1))) { | |
536 | error(LOGOPT_ANY, MODPREFIX "error opening module"); | |
537 | + free(map); | |
538 | goto error_out; | |
539 | + } | |
540 | + free(map); | |
541 | } | |
542 | ||
543 | *context = ctxt; |