]> git.decadent.org.uk Git - nfs-utils.git/blob - support/nfs/exports.c
Merge branch 'branch-1-0'
[nfs-utils.git] / support / nfs / exports.c
1 /*
2  * support/nfs/export.c
3  *
4  * Parse the exports file. Derived from the unfsd implementation.
5  *
6  * Authors:     Donald J. Becker, <becker@super.org>
7  *              Rick Sladkey, <jrs@world.std.com>
8  *              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
9  *              Olaf Kirch, <okir@monad.swb.de>
10  *              Alexander O. Yuriev, <alex@bach.cis.temple.edu>
11  *
12  *              This software maybe be used for any purpose provided
13  *              the above copyright notice is retained.  It is supplied
14  *              as is, with no warranty expressed or implied.
15  */
16
17 #ifdef HAVE_CONFIG_H
18 #include <config.h>
19 #endif
20
21 #include <sys/param.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <stdio.h>
25 #include <ctype.h>
26 #include <unistd.h>
27 #include <errno.h>
28 #include "nfslib.h"
29 #include "exportfs.h"
30 #include "xmalloc.h"
31 #include "xlog.h"
32 #include "xio.h"
33
34 #define EXPORT_DEFAULT_FLAGS    \
35   (NFSEXP_READONLY|NFSEXP_ROOTSQUASH|NFSEXP_GATHERED_WRITES|NFSEXP_NOSUBTREECHECK)
36
37 int export_errno;
38
39 static char     *efname = NULL;
40 static XFILE    *efp = NULL;
41 static int      first;
42 static int      has_default_opts, has_default_subtree_opts;
43 static int      *squids = NULL, nsquids = 0,
44                 *sqgids = NULL, nsqgids = 0;
45
46 static int      getexport(char *exp, int len);
47 static int      getpath(char *path, int len);
48 static int      parseopts(char *cp, struct exportent *ep, int warn, int *had_subtree_opt_ptr);
49 static int      parsesquash(char *list, int **idp, int *lenp, char **ep);
50 static int      parsenum(char **cpp);
51 static int      parsemaptype(char *type);
52 static void     freesquash(void);
53 static void     syntaxerr(char *msg);
54
55 void
56 setexportent(char *fname, char *type)
57 {
58         if (efp)
59                 endexportent();
60         if (!fname)
61                 fname = _PATH_EXPORTS;
62         if (!(efp = xfopen(fname, type)))
63                 xlog(L_ERROR, "can't open %s for %sing",
64                                 fname, strcmp(type, "r")? "writ" : "read");
65         efname = strdup(fname);
66         first = 1;
67 }
68
69 struct exportent *
70 getexportent(int fromkernel, int fromexports)
71 {
72         static struct exportent ee, def_ee;
73         char            exp[512], *hostname;
74         char            rpath[MAXPATHLEN+1];
75         char            *opt, *sp;
76         int             ok;
77
78         if (!efp)
79                 return NULL;
80
81         freesquash();
82
83         if (first || (ok = getexport(exp, sizeof(exp))) == 0) {
84                 has_default_opts = 0;
85                 has_default_subtree_opts = 0;
86         
87                 def_ee.e_flags = EXPORT_DEFAULT_FLAGS;
88                 /* some kernels assume the default is sync rather than
89                  * async.  More recent kernels always report one or other,
90                  * but this test makes sure we assume same as kernel
91                  * Ditto for wgather
92                  */
93                 if (fromkernel) {
94                         def_ee.e_flags &= ~NFSEXP_ASYNC;
95                         def_ee.e_flags &= ~NFSEXP_GATHERED_WRITES;
96                 }
97                 def_ee.e_maptype = CLE_MAP_IDENT;
98                 def_ee.e_anonuid = 65534;
99                 def_ee.e_anongid = 65534;
100                 def_ee.e_squids = NULL;
101                 def_ee.e_sqgids = NULL;
102                 def_ee.e_mountpoint = NULL;
103                 def_ee.e_fslocmethod = FSLOC_NONE;
104                 def_ee.e_fslocdata = NULL;
105                 def_ee.e_nsquids = 0;
106                 def_ee.e_nsqgids = 0;
107
108                 ok = getpath(def_ee.e_path, sizeof(def_ee.e_path));
109                 if (ok <= 0)
110                         return NULL;
111
112                 strncpy (def_ee.m_path, def_ee.e_path, sizeof (def_ee.m_path) - 1);
113                 def_ee.m_path [sizeof (def_ee.m_path) - 1] = '\0';
114                 ok = getexport(exp, sizeof(exp));
115         }
116         if (ok < 0) {
117                 xlog(L_ERROR, "expected client(options...)");
118                 export_errno = EINVAL;
119                 return NULL;
120         }
121         first = 0;
122                 
123         /* Check for default options */
124         if (exp[0] == '-') {
125                 if (parseopts(exp + 1, &def_ee, 0, &has_default_subtree_opts) < 0)
126                         return NULL;
127                 
128                 has_default_opts = 1;
129
130                 ok = getexport(exp, sizeof(exp));
131                 if (ok < 0) {
132                         xlog(L_ERROR, "expected client(options...)");
133                         export_errno = EINVAL;
134                         return NULL;
135                 }
136         }
137
138         ee = def_ee;
139
140         /* Check for default client */
141         if (ok == 0)
142                 exp[0] = '\0';
143
144         hostname = exp;
145         if ((opt = strchr(exp, '(')) != NULL) {
146                 if (opt == exp) {
147                         xlog(L_WARNING, "No host name given with %s %s, suggest *%s to avoid warning", ee.e_path, exp, exp);
148                         hostname = "*";
149                 }
150                 *opt++ = '\0';
151                 if (!(sp = strchr(opt, ')')) || sp[1] != '\0') {
152                         syntaxerr("bad option list");
153                         export_errno = EINVAL;
154                         return NULL;
155                 }
156                 *sp = '\0';
157         } else {
158                 if (!has_default_opts)
159                         xlog(L_WARNING, "No options for %s %s: suggest %s(sync) to avoid warning", ee.e_path, exp, exp);
160         }
161         if (strlen(hostname) >= sizeof(ee.e_hostname)) {
162                 syntaxerr("client name too long");
163                 export_errno = EINVAL;
164                 return NULL;
165         }
166         strncpy(ee.e_hostname, hostname, sizeof (ee.e_hostname) - 1);
167         ee.e_hostname[sizeof (ee.e_hostname) - 1] = '\0';
168
169         if (parseopts(opt, &ee, fromexports && !has_default_subtree_opts, NULL) < 0)
170                 return NULL;
171
172         /* resolve symlinks */
173         if (realpath(ee.e_path, rpath) != NULL) {
174                 rpath[sizeof (rpath) - 1] = '\0';
175                 strncpy(ee.e_path, rpath, sizeof (ee.e_path) - 1);
176                 ee.e_path[sizeof (ee.e_path) - 1] = '\0';
177                 strncpy (ee.m_path, ee.e_path, sizeof (ee.m_path) - 1);
178                 ee.m_path [sizeof (ee.m_path) - 1] = '\0';
179         }
180
181         return &ee;
182 }
183
184 void
185 putexportent(struct exportent *ep)
186 {
187         FILE    *fp;
188         int     *id, i;
189         char    *esc=ep->e_path;
190
191         if (!efp)
192                 return;
193
194         fp = efp->x_fp;
195         for (i=0; esc[i]; i++)
196                 if (iscntrl(esc[i]) || esc[i] == '"' || esc[i] == '\\' || esc[i] == '#' || isspace(esc[i]))
197                         fprintf(fp, "\\%03o", esc[i]);
198                 else
199                         fprintf(fp, "%c", esc[i]);
200
201         fprintf(fp, "\t%s(", ep->e_hostname);
202         fprintf(fp, "%s,", (ep->e_flags & NFSEXP_READONLY)? "ro" : "rw");
203         fprintf(fp, "%ssync,", (ep->e_flags & NFSEXP_ASYNC)? "a" : "");
204         fprintf(fp, "%swdelay,", (ep->e_flags & NFSEXP_GATHERED_WRITES)?
205                                 "" : "no_");
206         fprintf(fp, "%shide,", (ep->e_flags & NFSEXP_NOHIDE)?
207                                 "no" : "");
208         fprintf(fp, "%scrossmnt,", (ep->e_flags & NFSEXP_CROSSMOUNT)?
209                                 "" : "no");
210         fprintf(fp, "%ssecure,", (ep->e_flags & NFSEXP_INSECURE_PORT)?
211                                 "in" : "");
212         fprintf(fp, "%sroot_squash,", (ep->e_flags & NFSEXP_ROOTSQUASH)?
213                                 "" : "no_");
214         fprintf(fp, "%sall_squash,", (ep->e_flags & NFSEXP_ALLSQUASH)?
215                                 "" : "no_");
216         fprintf(fp, "%ssubtree_check,", (ep->e_flags & NFSEXP_NOSUBTREECHECK)?
217                 "no_" : "");
218         fprintf(fp, "%ssecure_locks,", (ep->e_flags & NFSEXP_NOAUTHNLM)?
219                 "in" : "");
220         fprintf(fp, "%sacl,", (ep->e_flags & NFSEXP_NOACL)?
221                 "no_" : "");
222         if (ep->e_flags & NFSEXP_FSID) {
223                 fprintf(fp, "fsid=%d,", ep->e_fsid);
224         }
225         if (ep->e_uuid)
226                 fprintf(fp, "fsid=%s,", ep->e_uuid);
227         if (ep->e_mountpoint)
228                 fprintf(fp, "mountpoint%s%s,",
229                         ep->e_mountpoint[0]?"=":"", ep->e_mountpoint);
230         switch (ep->e_fslocmethod) {
231         case FSLOC_NONE:
232                 break;
233         case FSLOC_REFER:
234                 fprintf(fp, "refer=%s,", ep->e_fslocdata);
235                 break;
236         case FSLOC_REPLICA:
237                 fprintf(fp, "replicas=%s,", ep->e_fslocdata);
238                 break;
239 #ifdef DEBUG
240         case FSLOC_STUB:
241                 fprintf(fp, "fsloc=stub,");
242                 break;
243 #endif
244         default:
245                 xlog(L_ERROR, "unknown fsloc method for %s:%s",
246                      ep->e_hostname, ep->e_path);
247         }
248         fprintf(fp, "mapping=");
249         switch (ep->e_maptype) {
250         case CLE_MAP_IDENT:
251                 fprintf(fp, "identity,");
252                 break;
253         case CLE_MAP_UGIDD:
254                 fprintf(fp, "ugidd,");
255                 break;
256         case CLE_MAP_FILE:
257                 fprintf(fp, "file,");
258                 break;
259         default:
260                 xlog(L_ERROR, "unknown mapping type for %s:%s",
261                                         ep->e_hostname, ep->e_path);
262         }
263         if ((id = ep->e_squids) != NULL) {
264                 fprintf(fp, "squash_uids=");
265                 for (i = 0; i < ep->e_nsquids; i += 2)
266                         if (id[i] != id[i+1])
267                                 fprintf(fp, "%d-%d,", id[i], id[i+1]);
268                         else
269                                 fprintf(fp, "%d,", id[i]);
270         }
271         if ((id = ep->e_sqgids) != NULL) {
272                 fprintf(fp, "squash_gids=");
273                 for (i = 0; i < ep->e_nsquids; i += 2)
274                         if (id[i] != id[i+1])
275                                 fprintf(fp, "%d-%d,", id[i], id[i+1]);
276                         else
277                                 fprintf(fp, "%d,", id[i]);
278         }
279         fprintf(fp, "anonuid=%d,anongid=%d)\n", ep->e_anonuid, ep->e_anongid);
280 }
281
282 void
283 endexportent(void)
284 {
285         if (efp)
286                 xfclose(efp);
287         efp = NULL;
288         if (efname)
289                 free(efname);
290         efname = NULL;
291         freesquash();
292 }
293
294 void
295 dupexportent(struct exportent *dst, struct exportent *src)
296 {
297         int     n;
298
299         *dst = *src;
300         if ((n = src->e_nsquids) != 0) {
301                 dst->e_squids = (int *) xmalloc(n * sizeof(int));
302                 memcpy(dst->e_squids, src->e_squids, n * sizeof(int));
303         }
304         if ((n = src->e_nsqgids) != 0) {
305                 dst->e_sqgids = (int *) xmalloc(n * sizeof(int));
306                 memcpy(dst->e_sqgids, src->e_sqgids, n * sizeof(int));
307         }
308         if (src->e_mountpoint)
309                 dst->e_mountpoint = strdup(src->e_mountpoint);
310         if (src->e_fslocdata)
311                 dst->e_fslocdata = strdup(src->e_fslocdata);
312 }
313
314 struct exportent *
315 mkexportent(char *hname, char *path, char *options)
316 {
317         static struct exportent ee;
318
319         ee.e_flags = EXPORT_DEFAULT_FLAGS;
320         ee.e_maptype = CLE_MAP_IDENT;
321         ee.e_anonuid = 65534;
322         ee.e_anongid = 65534;
323         ee.e_squids = NULL;
324         ee.e_sqgids = NULL;
325         ee.e_mountpoint = NULL;
326         ee.e_fslocmethod = FSLOC_NONE;
327         ee.e_fslocdata = NULL;
328         ee.e_nsquids = 0;
329         ee.e_nsqgids = 0;
330         ee.e_uuid = NULL;
331
332         if (strlen(hname) >= sizeof(ee.e_hostname)) {
333                 xlog(L_WARNING, "client name %s too long", hname);
334                 return NULL;
335         }
336         strncpy(ee.e_hostname, hname, sizeof (ee.e_hostname) - 1);
337         ee.e_hostname[sizeof (ee.e_hostname) - 1] = '\0';
338         if (strlen(path) >= sizeof(ee.e_path)) {
339                 xlog(L_WARNING, "path name %s too long", path);
340                 return NULL;
341         }
342         strncpy(ee.e_path, path, sizeof (ee.e_path));
343         ee.e_path[sizeof (ee.e_path) - 1] = '\0';
344         strncpy (ee.m_path, ee.e_path, sizeof (ee.m_path) - 1);
345         ee.m_path [sizeof (ee.m_path) - 1] = '\0';
346         if (parseopts(options, &ee, 0, NULL) < 0)
347                 return NULL;
348         return &ee;
349 }
350
351 int
352 updateexportent(struct exportent *eep, char *options)
353 {
354         if (parseopts(options, eep, 0, NULL) < 0)
355                 return 0;
356         return 1;
357 }
358
359
360 static int valid_uuid(char *uuid)
361 {
362         /* must have 32 hex digits */
363         int cnt;
364         for (cnt = 0 ; *uuid; uuid++)
365                 if (isxdigit(*uuid))
366                         cnt++;
367         return cnt == 32;
368 }
369
370 /*
371  * Parse option string pointed to by cp and set mount options accordingly.
372  */
373 static int
374 parseopts(char *cp, struct exportent *ep, int warn, int *had_subtree_opt_ptr)
375 {
376         int     had_subtree_opt = 0;
377         char    *flname = efname?efname:"command line";
378         int     flline = efp?efp->x_line:0;
379
380         squids = ep->e_squids; nsquids = ep->e_nsquids;
381         sqgids = ep->e_sqgids; nsqgids = ep->e_nsqgids;
382
383         if (!cp)
384                 goto out;
385
386         while (isblank(*cp))
387                 cp++;
388
389         while (*cp) {
390                 char *opt = strdup(cp);
391                 char *optstart = cp;
392                 while (*cp && *cp != ',')
393                         cp++;
394                 if (*cp) {
395                         opt[cp-optstart] = '\0';
396                         cp++;
397                 }
398
399                 /* process keyword */
400                 if (strcmp(opt, "ro") == 0)
401                         ep->e_flags |= NFSEXP_READONLY;
402                 else if (strcmp(opt, "rw") == 0)
403                         ep->e_flags &= ~NFSEXP_READONLY;
404                 else if (!strcmp(opt, "secure"))
405                         ep->e_flags &= ~NFSEXP_INSECURE_PORT;
406                 else if (!strcmp(opt, "insecure"))
407                         ep->e_flags |= NFSEXP_INSECURE_PORT;
408                 else if (!strcmp(opt, "sync"))
409                         ep->e_flags &= ~NFSEXP_ASYNC;
410                 else if (!strcmp(opt, "async"))
411                         ep->e_flags |= NFSEXP_ASYNC;
412                 else if (!strcmp(opt, "nohide"))
413                         ep->e_flags |= NFSEXP_NOHIDE;
414                 else if (!strcmp(opt, "hide"))
415                         ep->e_flags &= ~NFSEXP_NOHIDE;
416                 else if (!strcmp(opt, "crossmnt"))
417                         ep->e_flags |= NFSEXP_CROSSMOUNT;
418                 else if (!strcmp(opt, "nocrossmnt"))
419                         ep->e_flags &= ~NFSEXP_CROSSMOUNT;
420                 else if (!strcmp(opt, "wdelay"))
421                         ep->e_flags |= NFSEXP_GATHERED_WRITES;
422                 else if (!strcmp(opt, "no_wdelay"))
423                         ep->e_flags &= ~NFSEXP_GATHERED_WRITES;
424                 else if (strcmp(opt, "root_squash") == 0)
425                         ep->e_flags |= NFSEXP_ROOTSQUASH;
426                 else if (!strcmp(opt, "no_root_squash"))
427                         ep->e_flags &= ~NFSEXP_ROOTSQUASH;
428                 else if (strcmp(opt, "all_squash") == 0)
429                         ep->e_flags |= NFSEXP_ALLSQUASH;
430                 else if (strcmp(opt, "no_all_squash") == 0)
431                         ep->e_flags &= ~NFSEXP_ALLSQUASH;
432                 else if (strcmp(opt, "subtree_check") == 0) {
433                         had_subtree_opt = 1;
434                         ep->e_flags &= ~NFSEXP_NOSUBTREECHECK;
435                 } else if (strcmp(opt, "no_subtree_check") == 0) {
436                         had_subtree_opt = 1;
437                         ep->e_flags |= NFSEXP_NOSUBTREECHECK;
438                 } else if (strcmp(opt, "auth_nlm") == 0)
439                         ep->e_flags &= ~NFSEXP_NOAUTHNLM;
440                 else if (strcmp(opt, "no_auth_nlm") == 0)
441                         ep->e_flags |= NFSEXP_NOAUTHNLM;
442                 else if (strcmp(opt, "secure_locks") == 0)
443                         ep->e_flags &= ~NFSEXP_NOAUTHNLM;
444                 else if (strcmp(opt, "insecure_locks") == 0)
445                         ep->e_flags |= NFSEXP_NOAUTHNLM;
446                 else if (strcmp(opt, "acl") == 0)
447                         ep->e_flags &= ~NFSEXP_NOACL;
448                 else if (strcmp(opt, "no_acl") == 0)
449                         ep->e_flags |= NFSEXP_NOACL;
450                 else if (strncmp(opt, "mapping=", 8) == 0)
451                         ep->e_maptype = parsemaptype(opt+8);
452                 else if (strcmp(opt, "map_identity") == 0)      /* old style */
453                         ep->e_maptype = CLE_MAP_IDENT;
454                 else if (strcmp(opt, "map_daemon") == 0)        /* old style */
455                         ep->e_maptype = CLE_MAP_UGIDD;
456                 else if (strncmp(opt, "anonuid=", 8) == 0) {
457                         char *oe;
458                         ep->e_anonuid = strtol(opt+8, &oe, 10);
459                         if (opt[8]=='\0' || *oe != '\0') {
460                                 xlog(L_ERROR, "%s: %d: bad anonuid \"%s\"\n",
461                                      flname, flline, opt);      
462 bad_option:
463                                 free(opt);
464                                 export_errno = EINVAL;
465                                 return -1;
466                         }
467                 } else if (strncmp(opt, "anongid=", 8) == 0) {
468                         char *oe;
469                         ep->e_anongid = strtol(opt+8, &oe, 10);
470                         if (opt[8]=='\0' || *oe != '\0') {
471                                 xlog(L_ERROR, "%s: %d: bad anongid \"%s\"\n",
472                                      flname, flline, opt);      
473                                 goto bad_option;
474                         }
475                 } else if (strncmp(opt, "squash_uids=", 12) == 0) {
476                         if (parsesquash(opt+12, &squids, &nsquids, &cp) < 0) {
477                                 goto bad_option;
478                         }
479                 } else if (strncmp(opt, "squash_gids=", 12) == 0) {
480                         if (parsesquash(opt+12, &sqgids, &nsqgids, &cp) < 0) {
481                                 goto bad_option;
482                         }
483                 } else if (strncmp(opt, "fsid=", 5) == 0) {
484                         char *oe;
485                         if (strcmp(opt+5, "root") == 0) {
486                                 ep->e_fsid = 0;
487                                 ep->e_flags |= NFSEXP_FSID;
488                         } else {
489                                 ep->e_fsid = strtoul(opt+5, &oe, 0);
490                                 if (opt[5]!='\0' && *oe == '\0') 
491                                         ep->e_flags |= NFSEXP_FSID;
492                                 else if (valid_uuid(opt+5))
493                                         ep->e_uuid = strdup(opt+7);
494                                 else {
495                                         xlog(L_ERROR, "%s: %d: bad fsid \"%s\"\n",
496                                              flname, flline, opt);      
497                                         goto bad_option;
498                                 }
499                         }
500                 } else if (strcmp(opt, "mountpoint")==0 ||
501                            strcmp(opt, "mp") == 0 ||
502                            strncmp(opt, "mountpoint=", 11)==0 ||
503                            strncmp(opt, "mp=", 3) == 0) {
504                         char * mp = strchr(opt, '=');
505                         if (mp)
506                                 ep->e_mountpoint = strdup(mp+1);
507                         else
508                                 ep->e_mountpoint = strdup("");
509 #ifdef DEBUG
510                 } else if (strncmp(opt, "fsloc=", 6) == 0) {
511                         if (strcmp(opt+6, "stub") == 0)
512                                 ep->e_fslocmethod = FSLOC_STUB;
513                         else {
514                                 xlog(L_ERROR, "%s:%d: bad option %s\n",
515                                      flname, flline, opt);
516                                 goto bad_option;
517                         }
518 #endif
519                 } else if (strncmp(opt, "refer=", 6) == 0) {
520                         ep->e_fslocmethod = FSLOC_REFER;
521                         ep->e_fslocdata = strdup(opt+6);
522                 } else if (strncmp(opt, "replicas=", 9) == 0) {
523                         ep->e_fslocmethod = FSLOC_REPLICA;
524                         ep->e_fslocdata = strdup(opt+9);
525                 } else {
526                         xlog(L_ERROR, "%s:%d: unknown keyword \"%s\"\n",
527                                         flname, flline, opt);
528                         ep->e_flags |= NFSEXP_ALLSQUASH | NFSEXP_READONLY;
529                         goto bad_option;
530                 }
531                 free(opt);
532                 while (isblank(*cp))
533                         cp++;
534         }
535
536         ep->e_squids = squids;
537         ep->e_sqgids = sqgids;
538         ep->e_nsquids = nsquids;
539         ep->e_nsqgids = nsqgids;
540
541 out:
542         if (warn && !had_subtree_opt)
543                 xlog(L_WARNING, "%s [%d]: Neither 'subtree_check' or 'no_subtree_check' specified for export \"%s:%s\".\n"
544                                 "  Assuming default behaviour ('no_subtree_check').\n"
545                                 "  NOTE: this default has changed since nfs-utils version 1.0.x\n",
546
547                                 flname, flline,
548                                 ep->e_hostname, ep->e_path);
549         if (had_subtree_opt_ptr)
550                 *had_subtree_opt_ptr = had_subtree_opt;
551
552         return 1;
553 }
554
555 static int
556 parsesquash(char *list, int **idp, int *lenp, char **ep)
557 {
558         char    *cp = list;
559         int     id0, id1;
560         int     len = *lenp;
561         int     *id = *idp;
562
563         if (**ep)
564             *--(*ep) = ',';
565
566         do {
567                 id0 = parsenum(&cp);
568                 if (*cp == '-') {
569                         cp++;
570                         id1 = parsenum(&cp);
571                 } else {
572                         id1 = id0;
573                 }
574                 if (id0 == -1 || id1 == -1) {
575                         syntaxerr("uid/gid -1 not permitted");
576                         return -1;
577                 }
578                 if ((len % 8) == 0)
579                         id = (int *) xrealloc(id, (len + 8) * sizeof(*id));
580                 id[len++] = id0;
581                 id[len++] = id1;
582                 if (!*cp || *cp == ')' || (*cp == ',' && !isdigit(cp[1])))
583                         break;
584                 if (*cp != ',') {
585                         syntaxerr("bad uid/gid list");
586                         return -1;
587                 }
588                 cp++;
589         } while(1);
590
591         if (**ep == ',') (*ep)++;
592
593         *lenp = len;
594         *idp = id;
595         return 1;
596 }
597
598 static void
599 freesquash(void)
600 {
601         if (squids) {
602                 xfree (squids);
603                 squids = NULL;
604                 nsquids = 0;
605         }
606         if (sqgids) {
607                 xfree (sqgids);
608                 sqgids = NULL;
609                 nsqgids = 0;
610         }
611 }
612
613 static int
614 parsenum(char **cpp)
615 {
616         char    *cp = *cpp, c;
617         int     num = 0;
618
619         if (**cpp == '-')
620                 (*cpp)++;
621         while (isdigit(**cpp))
622                 (*cpp)++;
623         c = **cpp; **cpp = '\0'; num = atoi(cp); **cpp = c;
624         return num;
625 }
626
627 static int
628 parsemaptype(char *type)
629 {
630         if (!strcmp(type, "identity"))
631                 return CLE_MAP_IDENT;
632         if (!strcmp(type, "ugidd"))
633                 return CLE_MAP_UGIDD;
634         if (!strcmp(type, "file"))
635                 return CLE_MAP_FILE;
636         syntaxerr("invalid map type");
637         return CLE_MAP_IDENT;   /* default */
638 }
639
640 static int
641 getpath(char *path, int len)
642 {
643         xskip(efp, " \t\n");
644         return xgettok(efp, 0, path, len);
645 }
646
647 static int
648 getexport(char *exp, int len)
649 {
650         int     ok;
651
652         xskip(efp, " \t");
653         if ((ok = xgettok(efp, 0, exp, len)) < 0)
654                 xlog(L_ERROR, "%s:%d: syntax error",
655                         efname?"command line":efname, efp->x_line);
656         return ok;
657 }
658
659 static void
660 syntaxerr(char *msg)
661 {
662         xlog(L_ERROR, "%s:%d: syntax error: %s",
663                         efname, efp?efp->x_line:0, msg);
664 }
665