diff options
Diffstat (limited to 'usr.sbin/mountd')
-rw-r--r-- | usr.sbin/mountd/mountd.c | 49 |
1 files changed, 16 insertions, 33 deletions
diff --git a/usr.sbin/mountd/mountd.c b/usr.sbin/mountd/mountd.c index 1501f5c7c3f1..4431f881581b 100644 --- a/usr.sbin/mountd/mountd.c +++ b/usr.sbin/mountd/mountd.c @@ -92,9 +92,10 @@ __FBSDID("$FreeBSD$"); * Structures for keeping the mount list and export list */ struct mountlist { - struct mountlist *ml_next; char ml_host[MNTNAMLEN+1]; char ml_dirp[MNTPATHLEN+1]; + + SLIST_ENTRY(mountlist) next; }; struct dirlist { @@ -225,7 +226,7 @@ static int xdr_mlist(XDR *, caddr_t); static void terminate(int); static SLIST_HEAD(, exportlist) exphead = SLIST_HEAD_INITIALIZER(exphead); -static struct mountlist *mlhead; +static SLIST_HEAD(, mountlist) mlhead = SLIST_HEAD_INITIALIZER(mlhead); static struct grouplist *grphead; static char *exnames_default[2] = { _PATH_EXPORTS, NULL }; static char **exnames; @@ -447,7 +448,6 @@ main(int argc, char **argv) argc -= optind; argv += optind; grphead = (struct grouplist *)NULL; - mlhead = (struct mountlist *)NULL; if (argc > 0) exnames = argv; else @@ -1254,8 +1254,7 @@ xdr_mlist(XDR *xdrsp, caddr_t cp __unused) int false = 0; char *strp; - mlp = mlhead; - while (mlp) { + SLIST_FOREACH(mlp, &mlhead, next) { if (!xdr_bool(xdrsp, &true)) return (0); strp = &mlp->ml_host[0]; @@ -1264,7 +1263,6 @@ xdr_mlist(XDR *xdrsp, caddr_t cp __unused) strp = &mlp->ml_dirp[0]; if (!xdr_string(xdrsp, &strp, MNTPATHLEN)) return (0); - mlp = mlp->ml_next; } if (!xdr_bool(xdrsp, &false)) return (0); @@ -2946,7 +2944,7 @@ parsecred(char *namelist, struct xucred *cr) static void get_mountlist(void) { - struct mountlist *mlp, **mlpp; + struct mountlist *mlp; char *host, *dirp, *cp; char str[STRSIZ]; FILE *mlfile; @@ -2959,7 +2957,6 @@ get_mountlist(void) return; } } - mlpp = &mlhead; while (fgets(str, STRSIZ, mlfile) != NULL) { cp = str; host = strsep(&cp, " \t\n"); @@ -2973,9 +2970,8 @@ get_mountlist(void) mlp->ml_host[MNTNAMLEN] = '\0'; strncpy(mlp->ml_dirp, dirp, MNTPATHLEN); mlp->ml_dirp[MNTPATHLEN] = '\0'; - mlp->ml_next = (struct mountlist *)NULL; - *mlpp = mlp; - mlpp = &mlp->ml_next; + + SLIST_INSERT_HEAD(&mlhead, mlp, next); } fclose(mlfile); } @@ -2983,23 +2979,16 @@ get_mountlist(void) static void del_mlist(char *hostp, char *dirp) { - struct mountlist *mlp, **mlpp; - struct mountlist *mlp2; + struct mountlist *mlp, *mlp2; FILE *mlfile; int fnd = 0; - mlpp = &mlhead; - mlp = mlhead; - while (mlp) { + SLIST_FOREACH_SAFE(mlp, &mlhead, next, mlp2) { if (!strcmp(mlp->ml_host, hostp) && (!dirp || !strcmp(mlp->ml_dirp, dirp))) { fnd = 1; - mlp2 = mlp; - *mlpp = mlp = mlp->ml_next; - free((caddr_t)mlp2); - } else { - mlpp = &mlp->ml_next; - mlp = mlp->ml_next; + SLIST_REMOVE(&mlhead, mlp, mountlist, next); + free((caddr_t)mlp); } } if (fnd) { @@ -3007,10 +2996,8 @@ del_mlist(char *hostp, char *dirp) syslog(LOG_ERR,"can't update %s", _PATH_RMOUNTLIST); return; } - mlp = mlhead; - while (mlp) { + SLIST_FOREACH(mlp, &mlhead, next) { fprintf(mlfile, "%s %s\n", mlp->ml_host, mlp->ml_dirp); - mlp = mlp->ml_next; } fclose(mlfile); } @@ -3019,17 +3006,14 @@ del_mlist(char *hostp, char *dirp) static void add_mlist(char *hostp, char *dirp) { - struct mountlist *mlp, **mlpp; + struct mountlist *mlp; FILE *mlfile; - mlpp = &mlhead; - mlp = mlhead; - while (mlp) { + SLIST_FOREACH(mlp, &mlhead, next) { if (!strcmp(mlp->ml_host, hostp) && !strcmp(mlp->ml_dirp, dirp)) return; - mlpp = &mlp->ml_next; - mlp = mlp->ml_next; } + mlp = (struct mountlist *)malloc(sizeof (*mlp)); if (mlp == (struct mountlist *)NULL) out_of_mem(); @@ -3037,8 +3021,7 @@ add_mlist(char *hostp, char *dirp) mlp->ml_host[MNTNAMLEN] = '\0'; strncpy(mlp->ml_dirp, dirp, MNTPATHLEN); mlp->ml_dirp[MNTPATHLEN] = '\0'; - mlp->ml_next = (struct mountlist *)NULL; - *mlpp = mlp; + SLIST_INSERT_HEAD(&mlhead, mlp, next); if ((mlfile = fopen(_PATH_RMOUNTLIST, "a")) == NULL) { syslog(LOG_ERR, "can't update %s", _PATH_RMOUNTLIST); return; |