Home | History | Annotate | Line # | Download | only in mountd
mountd.c revision 1.2
      1  1.1  cgd /*
      2  1.1  cgd  * Copyright (c) 1989 The Regents of the University of California.
      3  1.1  cgd  * All rights reserved.
      4  1.1  cgd  *
      5  1.1  cgd  * This code is derived from software contributed to Berkeley by
      6  1.1  cgd  * Rick Macklem at The University of Guelph.
      7  1.1  cgd  *
      8  1.1  cgd  * Redistribution and use in source and binary forms, with or without
      9  1.1  cgd  * modification, are permitted provided that the following conditions
     10  1.1  cgd  * are met:
     11  1.1  cgd  * 1. Redistributions of source code must retain the above copyright
     12  1.1  cgd  *    notice, this list of conditions and the following disclaimer.
     13  1.1  cgd  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  cgd  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  cgd  *    documentation and/or other materials provided with the distribution.
     16  1.1  cgd  * 3. All advertising materials mentioning features or use of this software
     17  1.1  cgd  *    must display the following acknowledgement:
     18  1.1  cgd  *	This product includes software developed by the University of
     19  1.1  cgd  *	California, Berkeley and its contributors.
     20  1.1  cgd  * 4. Neither the name of the University nor the names of its contributors
     21  1.1  cgd  *    may be used to endorse or promote products derived from this software
     22  1.1  cgd  *    without specific prior written permission.
     23  1.1  cgd  *
     24  1.1  cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  1.1  cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  1.1  cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  1.1  cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  1.1  cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  1.1  cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  1.1  cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  1.1  cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  1.1  cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  1.1  cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  1.1  cgd  * SUCH DAMAGE.
     35  1.2  cgd  *
     36  1.2  cgd  * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
     37  1.2  cgd  * --------------------         -----   ----------------------
     38  1.2  cgd  * CURRENT PATCH LEVEL:         1       00054
     39  1.2  cgd  * --------------------         -----   ----------------------
     40  1.2  cgd  *
     41  1.2  cgd  * 08 Sep 92    Rick "gopher I"         Fix infinite loop when subdirs
     42  1.2  cgd  *						of local mount exported
     43  1.1  cgd  */
     44  1.1  cgd 
     45  1.1  cgd #ifndef lint
     46  1.1  cgd char copyright[] =
     47  1.1  cgd "@(#) Copyright (c) 1989 Regents of the University of California.\n\
     48  1.1  cgd  All rights reserved.\n";
     49  1.1  cgd #endif not lint
     50  1.1  cgd 
     51  1.1  cgd #ifndef lint
     52  1.1  cgd static char sccsid[] = "@(#)mountd.c	5.14 (Berkeley) 2/26/91";
     53  1.1  cgd #endif not lint
     54  1.1  cgd 
     55  1.1  cgd #include <sys/param.h>
     56  1.1  cgd #include <sys/ioctl.h>
     57  1.1  cgd #include <sys/stat.h>
     58  1.1  cgd #include <sys/file.h>
     59  1.1  cgd #include <sys/mount.h>
     60  1.1  cgd #include <sys/socket.h>
     61  1.1  cgd #include <sys/errno.h>
     62  1.1  cgd #include <sys/signal.h>
     63  1.1  cgd #include <stdio.h>
     64  1.1  cgd #include <string.h>
     65  1.1  cgd #include <syslog.h>
     66  1.1  cgd #include <netdb.h>
     67  1.1  cgd #include <rpc/rpc.h>
     68  1.1  cgd #include <rpc/pmap_clnt.h>
     69  1.1  cgd #include <rpc/pmap_prot.h>
     70  1.1  cgd #include <nfs/rpcv2.h>
     71  1.1  cgd #include <nfs/nfsv2.h>
     72  1.1  cgd #include "pathnames.h"
     73  1.1  cgd 
     74  1.1  cgd struct ufid {
     75  1.1  cgd 	u_short	ufid_len;
     76  1.1  cgd 	ino_t	ufid_ino;
     77  1.1  cgd 	long	ufid_gen;
     78  1.1  cgd };
     79  1.1  cgd /*
     80  1.1  cgd  * Structures for keeping the mount list and export list
     81  1.1  cgd  */
     82  1.1  cgd struct mountlist {
     83  1.1  cgd 	struct mountlist *ml_next;
     84  1.1  cgd 	char	ml_host[RPCMNT_NAMELEN+1];
     85  1.1  cgd 	char	ml_dirp[RPCMNT_PATHLEN+1];
     86  1.1  cgd };
     87  1.1  cgd 
     88  1.1  cgd struct exportlist {
     89  1.1  cgd 	struct exportlist *ex_next;
     90  1.1  cgd 	struct exportlist *ex_prev;
     91  1.1  cgd 	struct grouplist *ex_groups;
     92  1.1  cgd 	int	ex_rootuid;
     93  1.1  cgd 	int	ex_exflags;
     94  1.1  cgd 	dev_t	ex_dev;
     95  1.1  cgd 	char	ex_dirp[RPCMNT_PATHLEN+1];
     96  1.1  cgd };
     97  1.1  cgd 
     98  1.1  cgd struct grouplist {
     99  1.1  cgd 	struct grouplist *gr_next;
    100  1.1  cgd 	struct hostent *gr_hp;
    101  1.1  cgd };
    102  1.1  cgd 
    103  1.1  cgd /* Global defs */
    104  1.1  cgd int mntsrv(), umntall_each(), xdr_fhs(), xdr_mlist(), xdr_dir(), xdr_explist();
    105  1.1  cgd void add_mlist(), del_mlist(), get_exportlist(), get_mountlist();
    106  1.1  cgd void send_umntall();
    107  1.1  cgd struct exportlist exphead;
    108  1.1  cgd struct mountlist *mlhead;
    109  1.1  cgd char exname[MAXPATHLEN];
    110  1.1  cgd int def_rootuid = -2;
    111  1.1  cgd int root_only = 1;
    112  1.1  cgd extern int errno;
    113  1.1  cgd #ifdef DEBUG
    114  1.1  cgd int debug = 1;
    115  1.1  cgd #else
    116  1.1  cgd int debug = 0;
    117  1.1  cgd #endif
    118  1.1  cgd 
    119  1.1  cgd /*
    120  1.1  cgd  * Mountd server for NFS mount protocol as described in:
    121  1.1  cgd  * NFS: Network File System Protocol Specification, RFC1094, Appendix A
    122  1.1  cgd  * The optional arguments are the exports file name
    123  1.1  cgd  * default: _PATH_EXPORTS
    124  1.1  cgd  * and "-n" to allow nonroot mount.
    125  1.1  cgd  */
    126  1.1  cgd main(argc, argv)
    127  1.1  cgd 	int argc;
    128  1.1  cgd 	char **argv;
    129  1.1  cgd {
    130  1.1  cgd 	SVCXPRT *transp;
    131  1.1  cgd 	int c;
    132  1.1  cgd 	extern int optind;
    133  1.1  cgd 	extern char *optarg;
    134  1.1  cgd 
    135  1.1  cgd 	while ((c = getopt(argc, argv, "n")) != EOF)
    136  1.1  cgd 		switch (c) {
    137  1.1  cgd 		case 'n':
    138  1.1  cgd 			root_only = 0;
    139  1.1  cgd 			break;
    140  1.1  cgd 		default:
    141  1.1  cgd 			fprintf(stderr, "Usage: mountd [-n] [export_file]\n");
    142  1.1  cgd 			exit(1);
    143  1.1  cgd 		};
    144  1.1  cgd 	argc -= optind;
    145  1.1  cgd 	argv += optind;
    146  1.1  cgd 	exphead.ex_next = exphead.ex_prev = (struct exportlist *)0;
    147  1.1  cgd 	mlhead = (struct mountlist *)0;
    148  1.1  cgd 	if (argc == 1) {
    149  1.1  cgd 		strncpy(exname, *argv, MAXPATHLEN-1);
    150  1.1  cgd 		exname[MAXPATHLEN-1] = '\0';
    151  1.1  cgd 	} else
    152  1.1  cgd 		strcpy(exname, _PATH_EXPORTS);
    153  1.1  cgd 	openlog("mountd:", LOG_PID, LOG_DAEMON);
    154  1.1  cgd 	get_exportlist();
    155  1.1  cgd 	get_mountlist();
    156  1.1  cgd 	if (debug == 0) {
    157  1.1  cgd 		daemon(0, 0);
    158  1.1  cgd 		signal(SIGINT, SIG_IGN);
    159  1.1  cgd 		signal(SIGQUIT, SIG_IGN);
    160  1.1  cgd 	}
    161  1.1  cgd 	signal(SIGHUP, get_exportlist);
    162  1.1  cgd 	signal(SIGTERM, send_umntall);
    163  1.1  cgd 	{ FILE *pidfile = fopen(_PATH_MOUNTDPID, "w");
    164  1.1  cgd 	  if (pidfile != NULL) {
    165  1.1  cgd 		fprintf(pidfile, "%d\n", getpid());
    166  1.1  cgd 		fclose(pidfile);
    167  1.1  cgd 	  }
    168  1.1  cgd 	}
    169  1.1  cgd 	if ((transp = svcudp_create(RPC_ANYSOCK)) == NULL) {
    170  1.1  cgd 		syslog(LOG_ERR, "Can't create socket");
    171  1.1  cgd 		exit(1);
    172  1.1  cgd 	}
    173  1.1  cgd 	pmap_unset(RPCPROG_MNT, RPCMNT_VER1);
    174  1.1  cgd 	if (!svc_register(transp, RPCPROG_MNT, RPCMNT_VER1, mntsrv, IPPROTO_UDP)) {
    175  1.1  cgd 		syslog(LOG_ERR, "Can't register mount");
    176  1.1  cgd 		exit(1);
    177  1.1  cgd 	}
    178  1.1  cgd 	svc_run();
    179  1.1  cgd 	syslog(LOG_ERR, "Mountd died");
    180  1.1  cgd 	exit(1);
    181  1.1  cgd }
    182  1.1  cgd 
    183  1.1  cgd /*
    184  1.1  cgd  * The mount rpc service
    185  1.1  cgd  */
    186  1.1  cgd mntsrv(rqstp, transp)
    187  1.1  cgd 	register struct svc_req *rqstp;
    188  1.1  cgd 	register SVCXPRT *transp;
    189  1.1  cgd {
    190  1.1  cgd 	register struct grouplist *grp;
    191  1.1  cgd 	register u_long **addrp;
    192  1.1  cgd 	register struct exportlist *ep;
    193  1.1  cgd 	nfsv2fh_t nfh;
    194  1.1  cgd 	struct authunix_parms *ucr;
    195  1.1  cgd 	struct stat stb;
    196  1.1  cgd 	struct hostent *hp;
    197  1.1  cgd 	u_long saddr;
    198  1.1  cgd 	char dirpath[RPCMNT_PATHLEN+1];
    199  1.1  cgd 	int bad = ENOENT;
    200  1.1  cgd 	int omask;
    201  1.1  cgd 	uid_t uid = -2;
    202  1.1  cgd 
    203  1.1  cgd 	/* Get authorization */
    204  1.1  cgd 	switch (rqstp->rq_cred.oa_flavor) {
    205  1.1  cgd 	case AUTH_UNIX:
    206  1.1  cgd 		ucr = (struct authunix_parms *)rqstp->rq_clntcred;
    207  1.1  cgd 		uid = ucr->aup_uid;
    208  1.1  cgd 		break;
    209  1.1  cgd 	case AUTH_NULL:
    210  1.1  cgd 	default:
    211  1.1  cgd 		break;
    212  1.1  cgd 	}
    213  1.1  cgd 
    214  1.1  cgd 	saddr = transp->xp_raddr.sin_addr.s_addr;
    215  1.1  cgd 	hp = (struct hostent *)0;
    216  1.1  cgd 	switch (rqstp->rq_proc) {
    217  1.1  cgd 	case NULLPROC:
    218  1.1  cgd 		if (!svc_sendreply(transp, xdr_void, (caddr_t)0))
    219  1.1  cgd 			syslog(LOG_ERR, "Can't send reply");
    220  1.1  cgd 		return;
    221  1.1  cgd 	case RPCMNT_MOUNT:
    222  1.1  cgd 		if (uid != 0 && root_only) {
    223  1.1  cgd 			svcerr_weakauth(transp);
    224  1.1  cgd 			return;
    225  1.1  cgd 		}
    226  1.1  cgd 		if (!svc_getargs(transp, xdr_dir, dirpath)) {
    227  1.1  cgd 			svcerr_decode(transp);
    228  1.1  cgd 			return;
    229  1.1  cgd 		}
    230  1.1  cgd 
    231  1.1  cgd 		/* Check to see if it's a valid dirpath */
    232  1.1  cgd 		if (stat(dirpath, &stb) < 0 || (stb.st_mode&S_IFMT) !=
    233  1.1  cgd 			S_IFDIR) {
    234  1.1  cgd 			if (!svc_sendreply(transp, xdr_long, (caddr_t)&bad))
    235  1.1  cgd 				syslog(LOG_ERR, "Can't send reply");
    236  1.1  cgd 			return;
    237  1.1  cgd 		}
    238  1.1  cgd 
    239  1.1  cgd 		/* Check in the exports list */
    240  1.1  cgd 		omask = sigblock(sigmask(SIGHUP));
    241  1.1  cgd 		ep = exphead.ex_next;
    242  1.1  cgd 		while (ep != NULL) {
    243  1.1  cgd 			if (!strcmp(ep->ex_dirp, dirpath)) {
    244  1.1  cgd 				grp = ep->ex_groups;
    245  1.1  cgd 				if (grp == NULL)
    246  1.1  cgd 					break;
    247  1.1  cgd 
    248  1.1  cgd 				/* Check for a host match */
    249  1.1  cgd 				addrp = (u_long **)grp->gr_hp->h_addr_list;
    250  1.1  cgd 				for (;;) {
    251  1.1  cgd 					if (**addrp == saddr)
    252  1.1  cgd 						break;
    253  1.1  cgd 					if (*++addrp == NULL)
    254  1.1  cgd 						if (grp = grp->gr_next) {
    255  1.1  cgd 							addrp = (u_long **)
    256  1.1  cgd 								grp->gr_hp->h_addr_list;
    257  1.1  cgd 						} else {
    258  1.1  cgd 							bad = EACCES;
    259  1.1  cgd 							if (!svc_sendreply(transp, xdr_long, (caddr_t)&bad))
    260  1.1  cgd 								syslog(LOG_ERR, "Can't send reply");
    261  1.1  cgd 							sigsetmask(omask);
    262  1.1  cgd 							return;
    263  1.1  cgd 						}
    264  1.1  cgd 				}
    265  1.1  cgd 				hp = grp->gr_hp;
    266  1.1  cgd 				break;
    267  1.1  cgd 			}
    268  1.1  cgd 			ep = ep->ex_next;
    269  1.1  cgd 		}
    270  1.1  cgd 		sigsetmask(omask);
    271  1.1  cgd 		if (ep == NULL) {
    272  1.1  cgd 			bad = EACCES;
    273  1.1  cgd 			if (!svc_sendreply(transp, xdr_long, (caddr_t)&bad))
    274  1.1  cgd 				syslog(LOG_ERR, "Can't send reply");
    275  1.1  cgd 			return;
    276  1.1  cgd 		}
    277  1.1  cgd 
    278  1.1  cgd 		/* Get the file handle */
    279  1.1  cgd 		bzero((caddr_t)&nfh, sizeof(nfh));
    280  1.1  cgd 		if (getfh(dirpath, (fhandle_t *)&nfh) < 0) {
    281  1.1  cgd 			bad = errno;
    282  1.1  cgd 			if (!svc_sendreply(transp, xdr_long, (caddr_t)&bad))
    283  1.1  cgd 				syslog(LOG_ERR, "Can't send reply");
    284  1.1  cgd 			return;
    285  1.1  cgd 		}
    286  1.1  cgd 		if (!svc_sendreply(transp, xdr_fhs, (caddr_t)&nfh))
    287  1.1  cgd 			syslog(LOG_ERR, "Can't send reply");
    288  1.1  cgd 		if (hp == NULL)
    289  1.1  cgd 			hp = gethostbyaddr((caddr_t)&saddr, sizeof(saddr), AF_INET);
    290  1.1  cgd 		if (hp)
    291  1.1  cgd 			add_mlist(hp->h_name, dirpath);
    292  1.1  cgd 		return;
    293  1.1  cgd 	case RPCMNT_DUMP:
    294  1.1  cgd 		if (!svc_sendreply(transp, xdr_mlist, (caddr_t)0))
    295  1.1  cgd 			syslog(LOG_ERR, "Can't send reply");
    296  1.1  cgd 		return;
    297  1.1  cgd 	case RPCMNT_UMOUNT:
    298  1.1  cgd 		if (uid != 0 && root_only) {
    299  1.1  cgd 			svcerr_weakauth(transp);
    300  1.1  cgd 			return;
    301  1.1  cgd 		}
    302  1.1  cgd 		if (!svc_getargs(transp, xdr_dir, dirpath)) {
    303  1.1  cgd 			svcerr_decode(transp);
    304  1.1  cgd 			return;
    305  1.1  cgd 		}
    306  1.1  cgd 		if (!svc_sendreply(transp, xdr_void, (caddr_t)0))
    307  1.1  cgd 			syslog(LOG_ERR, "Can't send reply");
    308  1.1  cgd 		hp = gethostbyaddr((caddr_t)&saddr, sizeof(saddr), AF_INET);
    309  1.1  cgd 		if (hp)
    310  1.1  cgd 			del_mlist(hp->h_name, dirpath);
    311  1.1  cgd 		return;
    312  1.1  cgd 	case RPCMNT_UMNTALL:
    313  1.1  cgd 		if (uid != 0 && root_only) {
    314  1.1  cgd 			svcerr_weakauth(transp);
    315  1.1  cgd 			return;
    316  1.1  cgd 		}
    317  1.1  cgd 		if (!svc_sendreply(transp, xdr_void, (caddr_t)0))
    318  1.1  cgd 			syslog(LOG_ERR, "Can't send reply");
    319  1.1  cgd 		hp = gethostbyaddr((caddr_t)&saddr, sizeof(saddr), AF_INET);
    320  1.1  cgd 		if (hp)
    321  1.1  cgd 			del_mlist(hp->h_name, (char *)0);
    322  1.1  cgd 		return;
    323  1.1  cgd 	case RPCMNT_EXPORT:
    324  1.1  cgd 		if (!svc_sendreply(transp, xdr_explist, (caddr_t)0))
    325  1.1  cgd 			syslog(LOG_ERR, "Can't send reply");
    326  1.1  cgd 		return;
    327  1.1  cgd 	default:
    328  1.1  cgd 		svcerr_noproc(transp);
    329  1.1  cgd 		return;
    330  1.1  cgd 	}
    331  1.1  cgd }
    332  1.1  cgd 
    333  1.1  cgd /*
    334  1.1  cgd  * Xdr conversion for a dirpath string
    335  1.1  cgd  */
    336  1.1  cgd xdr_dir(xdrsp, dirp)
    337  1.1  cgd 	XDR *xdrsp;
    338  1.1  cgd 	char *dirp;
    339  1.1  cgd {
    340  1.1  cgd 	return (xdr_string(xdrsp, &dirp, RPCMNT_PATHLEN));
    341  1.1  cgd }
    342  1.1  cgd 
    343  1.1  cgd /*
    344  1.1  cgd  * Xdr routine to generate fhstatus
    345  1.1  cgd  */
    346  1.1  cgd xdr_fhs(xdrsp, nfh)
    347  1.1  cgd 	XDR *xdrsp;
    348  1.1  cgd 	nfsv2fh_t *nfh;
    349  1.1  cgd {
    350  1.1  cgd 	int ok = 0;
    351  1.1  cgd 
    352  1.1  cgd 	if (!xdr_long(xdrsp, &ok))
    353  1.1  cgd 		return (0);
    354  1.1  cgd 	return (xdr_opaque(xdrsp, (caddr_t)nfh, NFSX_FH));
    355  1.1  cgd }
    356  1.1  cgd 
    357  1.1  cgd xdr_mlist(xdrsp, cp)
    358  1.1  cgd 	XDR *xdrsp;
    359  1.1  cgd 	caddr_t cp;
    360  1.1  cgd {
    361  1.1  cgd 	register struct mountlist *mlp;
    362  1.1  cgd 	int true = 1;
    363  1.1  cgd 	int false = 0;
    364  1.1  cgd 	char *strp;
    365  1.1  cgd 
    366  1.1  cgd 	mlp = mlhead;
    367  1.1  cgd 	while (mlp) {
    368  1.1  cgd 		if (!xdr_bool(xdrsp, &true))
    369  1.1  cgd 			return (0);
    370  1.1  cgd 		strp = &mlp->ml_host[0];
    371  1.1  cgd 		if (!xdr_string(xdrsp, &strp, RPCMNT_NAMELEN))
    372  1.1  cgd 			return (0);
    373  1.1  cgd 		strp = &mlp->ml_dirp[0];
    374  1.1  cgd 		if (!xdr_string(xdrsp, &strp, RPCMNT_PATHLEN))
    375  1.1  cgd 			return (0);
    376  1.1  cgd 		mlp = mlp->ml_next;
    377  1.1  cgd 	}
    378  1.1  cgd 	if (!xdr_bool(xdrsp, &false))
    379  1.1  cgd 		return (0);
    380  1.1  cgd 	return (1);
    381  1.1  cgd }
    382  1.1  cgd 
    383  1.1  cgd /*
    384  1.1  cgd  * Xdr conversion for export list
    385  1.1  cgd  */
    386  1.1  cgd xdr_explist(xdrsp, cp)
    387  1.1  cgd 	XDR *xdrsp;
    388  1.1  cgd 	caddr_t cp;
    389  1.1  cgd {
    390  1.1  cgd 	register struct exportlist *ep;
    391  1.1  cgd 	register struct grouplist *grp;
    392  1.1  cgd 	int true = 1;
    393  1.1  cgd 	int false = 0;
    394  1.1  cgd 	char *strp;
    395  1.1  cgd 	int omask;
    396  1.1  cgd 
    397  1.1  cgd 	omask = sigblock(sigmask(SIGHUP));
    398  1.1  cgd 	ep = exphead.ex_next;
    399  1.1  cgd 	while (ep != NULL) {
    400  1.1  cgd 		if (!xdr_bool(xdrsp, &true))
    401  1.1  cgd 			goto errout;
    402  1.1  cgd 		strp = &ep->ex_dirp[0];
    403  1.1  cgd 		if (!xdr_string(xdrsp, &strp, RPCMNT_PATHLEN))
    404  1.1  cgd 			goto errout;
    405  1.1  cgd 		grp = ep->ex_groups;
    406  1.1  cgd 		while (grp != NULL) {
    407  1.1  cgd 			if (!xdr_bool(xdrsp, &true))
    408  1.1  cgd 				goto errout;
    409  1.1  cgd 			strp = grp->gr_hp->h_name;
    410  1.1  cgd 			if (!xdr_string(xdrsp, &strp, RPCMNT_NAMELEN))
    411  1.1  cgd 				goto errout;
    412  1.1  cgd 			grp = grp->gr_next;
    413  1.1  cgd 		}
    414  1.1  cgd 		if (!xdr_bool(xdrsp, &false))
    415  1.1  cgd 			goto errout;
    416  1.1  cgd 		ep = ep->ex_next;
    417  1.1  cgd 	}
    418  1.1  cgd 	sigsetmask(omask);
    419  1.1  cgd 	if (!xdr_bool(xdrsp, &false))
    420  1.1  cgd 		return (0);
    421  1.1  cgd 	return (1);
    422  1.1  cgd errout:
    423  1.1  cgd 	sigsetmask(omask);
    424  1.1  cgd 	return (0);
    425  1.1  cgd }
    426  1.1  cgd 
    427  1.1  cgd #define LINESIZ	10240
    428  1.1  cgd char line[LINESIZ];
    429  1.1  cgd 
    430  1.1  cgd /*
    431  1.1  cgd  * Get the export list
    432  1.1  cgd  */
    433  1.1  cgd void
    434  1.1  cgd get_exportlist()
    435  1.1  cgd {
    436  1.1  cgd 	register struct hostent *hp, *nhp;
    437  1.1  cgd 	register char **addrp, **naddrp;
    438  1.1  cgd 	register int i;
    439  1.1  cgd 	register struct grouplist *grp;
    440  1.1  cgd 	register struct exportlist *ep, *ep2;
    441  1.1  cgd 	struct statfs stfsbuf;
    442  1.1  cgd 	struct ufs_args args;
    443  1.1  cgd 	struct stat sb;
    444  1.1  cgd 	FILE *inf;
    445  1.1  cgd 	char *cp, *endcp;
    446  1.1  cgd 	char savedc;
    447  1.1  cgd 	int len, dirplen;
    448  1.1  cgd 	int rootuid, exflags;
    449  1.1  cgd 	u_long saddr;
    450  1.1  cgd 	struct exportlist *fep;
    451  1.1  cgd 
    452  1.1  cgd 	/*
    453  1.1  cgd 	 * First, get rid of the old list
    454  1.1  cgd 	 */
    455  1.1  cgd 	ep = exphead.ex_next;
    456  1.1  cgd 	while (ep != NULL) {
    457  1.1  cgd 		ep2 = ep;
    458  1.1  cgd 		ep = ep->ex_next;
    459  1.1  cgd 		free_exp(ep2);
    460  1.1  cgd 	}
    461  1.1  cgd 
    462  1.1  cgd 	/*
    463  1.1  cgd 	 * Read in the exports file and build the list, calling
    464  1.1  cgd 	 * exportfs() as we go along
    465  1.1  cgd 	 */
    466  1.1  cgd 	exphead.ex_next = exphead.ex_prev = (struct exportlist *)0;
    467  1.1  cgd 	if ((inf = fopen(exname, "r")) == NULL) {
    468  1.1  cgd 		syslog(LOG_ERR, "Can't open %s", exname);
    469  1.1  cgd 		exit(2);
    470  1.1  cgd 	}
    471  1.1  cgd 	while (fgets(line, LINESIZ, inf)) {
    472  1.1  cgd 		exflags = MNT_EXPORTED;
    473  1.1  cgd 		rootuid = def_rootuid;
    474  1.1  cgd 		cp = line;
    475  1.1  cgd 		nextfield(&cp, &endcp);
    476  1.1  cgd 
    477  1.1  cgd 		/*
    478  1.1  cgd 		 * Get file system devno and see if an entry for this
    479  1.1  cgd 		 * file system already exists.
    480  1.1  cgd 		 */
    481  1.1  cgd 		savedc = *endcp;
    482  1.1  cgd 		*endcp = '\0';
    483  1.1  cgd 		if (stat(cp, &sb) < 0 || (sb.st_mode & S_IFMT) != S_IFDIR) {
    484  1.1  cgd 			syslog(LOG_ERR,
    485  1.1  cgd 			    "Bad Exports File, %s: %s, mountd Failed",
    486  1.1  cgd 			    cp, "Not a directory");
    487  1.1  cgd 			exit(2);
    488  1.1  cgd 		}
    489  1.1  cgd 		fep = (struct exportlist *)0;
    490  1.1  cgd 		ep = exphead.ex_next;
    491  1.1  cgd 		while (ep) {
    492  1.1  cgd 			if (ep->ex_dev == sb.st_dev) {
    493  1.1  cgd 				fep = ep;
    494  1.1  cgd 				break;
    495  1.1  cgd 			}
    496  1.1  cgd 			ep = ep->ex_next;
    497  1.1  cgd 		}
    498  1.1  cgd 		*endcp = savedc;
    499  1.1  cgd 
    500  1.1  cgd 		/*
    501  1.1  cgd 		 * Create new exports list entry
    502  1.1  cgd 		 */
    503  1.1  cgd 		len = endcp-cp;
    504  1.1  cgd 		if (len <= RPCMNT_PATHLEN && len > 0) {
    505  1.1  cgd 			ep = (struct exportlist *)malloc(sizeof(*ep));
    506  1.1  cgd 			if (ep == NULL)
    507  1.1  cgd 				goto err;
    508  1.1  cgd 			ep->ex_next = ep->ex_prev = (struct exportlist *)0;
    509  1.1  cgd 			ep->ex_groups = (struct grouplist *)0;
    510  1.1  cgd 			bcopy(cp, ep->ex_dirp, len);
    511  1.1  cgd 			ep->ex_dirp[len] = '\0';
    512  1.1  cgd 			dirplen = len;
    513  1.1  cgd 		} else {
    514  1.1  cgd 			syslog(LOG_ERR, "Bad Exports File, mountd Failed");
    515  1.1  cgd 			exit(2);
    516  1.1  cgd 		}
    517  1.1  cgd 		cp = endcp;
    518  1.1  cgd 		nextfield(&cp, &endcp);
    519  1.1  cgd 		len = endcp-cp;
    520  1.1  cgd 		while (len > 0) {
    521  1.1  cgd 			savedc = *endcp;
    522  1.1  cgd 			*endcp = '\0';
    523  1.1  cgd 			if (len > RPCMNT_NAMELEN)
    524  1.1  cgd 				goto more;
    525  1.1  cgd 			if (*cp == '-') {
    526  1.1  cgd 				do_opt(cp + 1, fep, ep, &exflags, &rootuid);
    527  1.1  cgd 				goto more;
    528  1.1  cgd 			}
    529  1.1  cgd 			if (isdigit(*cp)) {
    530  1.1  cgd 				saddr = inet_addr(cp);
    531  1.1  cgd 				if (saddr == -1 ||
    532  1.1  cgd 				    (hp = gethostbyaddr((caddr_t)&saddr,
    533  1.1  cgd 				     sizeof(saddr), AF_INET)) == NULL) {
    534  1.1  cgd 					syslog(LOG_ERR,
    535  1.1  cgd 					    "Bad Exports File, %s: %s", cp,
    536  1.1  cgd 					    "Gethostbyaddr failed, ignored");
    537  1.1  cgd 					goto more;
    538  1.1  cgd 				}
    539  1.1  cgd 			} else if ((hp = gethostbyname(cp)) == NULL) {
    540  1.1  cgd 				syslog(LOG_ERR, "Bad Exports File, %s: %s",
    541  1.1  cgd 				    cp, "Gethostbyname failed, ignored");
    542  1.1  cgd 				goto more;
    543  1.1  cgd 			}
    544  1.1  cgd 			grp = (struct grouplist *)
    545  1.1  cgd 				malloc(sizeof(struct grouplist));
    546  1.1  cgd 			if (grp == NULL)
    547  1.1  cgd 				goto err;
    548  1.1  cgd 			nhp = grp->gr_hp = (struct hostent *)
    549  1.1  cgd 				malloc(sizeof(struct hostent));
    550  1.1  cgd 			if (nhp == NULL)
    551  1.1  cgd 				goto err;
    552  1.1  cgd 			bcopy((caddr_t)hp, (caddr_t)nhp,
    553  1.1  cgd 				sizeof(struct hostent));
    554  1.1  cgd 			i = strlen(hp->h_name)+1;
    555  1.1  cgd 			nhp->h_name = (char *)malloc(i);
    556  1.1  cgd 			if (nhp->h_name == NULL)
    557  1.1  cgd 				goto err;
    558  1.1  cgd 			bcopy(hp->h_name, nhp->h_name, i);
    559  1.1  cgd 			addrp = hp->h_addr_list;
    560  1.1  cgd 			i = 1;
    561  1.1  cgd 			while (*addrp++)
    562  1.1  cgd 				i++;
    563  1.1  cgd 			naddrp = nhp->h_addr_list = (char **)
    564  1.1  cgd 				malloc(i*sizeof(char *));
    565  1.1  cgd 			if (naddrp == NULL)
    566  1.1  cgd 				goto err;
    567  1.1  cgd 			addrp = hp->h_addr_list;
    568  1.1  cgd 			while (*addrp) {
    569  1.1  cgd 				*naddrp = (char *)
    570  1.1  cgd 				    malloc(hp->h_length);
    571  1.1  cgd 				if (*naddrp == NULL)
    572  1.1  cgd 				    goto err;
    573  1.1  cgd 				bcopy(*addrp, *naddrp,
    574  1.1  cgd 					hp->h_length);
    575  1.1  cgd 				addrp++;
    576  1.1  cgd 				naddrp++;
    577  1.1  cgd 			}
    578  1.1  cgd 			*naddrp = (char *)0;
    579  1.1  cgd 			grp->gr_next = ep->ex_groups;
    580  1.1  cgd 			ep->ex_groups = grp;
    581  1.1  cgd 		more:
    582  1.1  cgd 			cp = endcp;
    583  1.1  cgd 			*cp = savedc;
    584  1.1  cgd 			nextfield(&cp, &endcp);
    585  1.1  cgd 			len = endcp - cp;
    586  1.1  cgd 		}
    587  1.1  cgd 		if (fep == NULL) {
    588  1.1  cgd 			args.fspec = 0;
    589  1.1  cgd 			args.exflags = exflags;
    590  1.1  cgd 			args.exroot = rootuid;
    591  1.1  cgd 			cp = (char *)0;
    592  1.1  cgd 			while (statfs(ep->ex_dirp, &stfsbuf) < 0 ||
    593  1.1  cgd 			       mount(MOUNT_UFS, ep->ex_dirp,
    594  1.1  cgd 				     stfsbuf.f_flags|MNT_UPDATE, &args) < 0) {
    595  1.2  cgd /* 08 Sep 92*/			if (cp)
    596  1.2  cgd 					*cp-- = savedc;
    597  1.2  cgd 				else
    598  1.2  cgd 					cp = ep->ex_dirp + dirplen - 1;
    599  1.2  cgd #ifdef OMIT
    600  1.1  cgd 				if (cp == NULL)
    601  1.1  cgd 					cp = ep->ex_dirp + dirplen - 1;
    602  1.1  cgd 				else
    603  1.1  cgd 					*cp = savedc;
    604  1.2  cgd #endif	/* OMIT*/
    605  1.1  cgd 				/* back up over the last component */
    606  1.1  cgd 				while (*cp == '/' && cp > ep->ex_dirp)
    607  1.1  cgd 					cp--;
    608  1.2  cgd /* 08 Sep 92*/			while (cp > ep->ex_dirp && *(cp - 1) != '/')
    609  1.1  cgd 					cp--;
    610  1.1  cgd 				if (cp == ep->ex_dirp) {
    611  1.1  cgd 					syslog(LOG_WARNING,
    612  1.1  cgd 					      "Can't export %s", ep->ex_dirp);
    613  1.1  cgd 					free_exp(ep);
    614  1.1  cgd 					goto nextline;
    615  1.1  cgd 				}
    616  1.1  cgd 				savedc = *cp;
    617  1.1  cgd 				*cp = '\0';
    618  1.1  cgd 			}
    619  1.1  cgd 			if (cp)
    620  1.1  cgd 				*cp = savedc;
    621  1.1  cgd 			ep->ex_rootuid = rootuid;
    622  1.1  cgd 			ep->ex_exflags = exflags;
    623  1.1  cgd 		} else {
    624  1.1  cgd 			ep->ex_rootuid = fep->ex_rootuid;
    625  1.1  cgd 			ep->ex_exflags = fep->ex_exflags;
    626  1.1  cgd 		}
    627  1.1  cgd 		ep->ex_dev = sb.st_dev;
    628  1.1  cgd 		ep->ex_next = exphead.ex_next;
    629  1.1  cgd 		ep->ex_prev = &exphead;
    630  1.1  cgd 		if (ep->ex_next != NULL)
    631  1.1  cgd 			ep->ex_next->ex_prev = ep;
    632  1.1  cgd 		exphead.ex_next = ep;
    633  1.1  cgd nextline:
    634  1.1  cgd 		;
    635  1.1  cgd 	}
    636  1.1  cgd 	fclose(inf);
    637  1.1  cgd 	return;
    638  1.1  cgd err:
    639  1.1  cgd 	syslog(LOG_ERR, "No more memory: mountd Failed");
    640  1.1  cgd 	exit(2);
    641  1.1  cgd }
    642  1.1  cgd 
    643  1.1  cgd /*
    644  1.1  cgd  * Parse out the next white space separated field
    645  1.1  cgd  */
    646  1.1  cgd nextfield(cp, endcp)
    647  1.1  cgd 	char **cp;
    648  1.1  cgd 	char **endcp;
    649  1.1  cgd {
    650  1.1  cgd 	register char *p;
    651  1.1  cgd 
    652  1.1  cgd 	p = *cp;
    653  1.1  cgd 	while (*p == ' ' || *p == '\t')
    654  1.1  cgd 		p++;
    655  1.1  cgd 	if (*p == '\n' || *p == '\0') {
    656  1.1  cgd 		*cp = *endcp = p;
    657  1.1  cgd 		return;
    658  1.1  cgd 	}
    659  1.1  cgd 	*cp = p++;
    660  1.1  cgd 	while (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\0')
    661  1.1  cgd 		p++;
    662  1.1  cgd 	*endcp = p;
    663  1.1  cgd }
    664  1.1  cgd 
    665  1.1  cgd /*
    666  1.1  cgd  * Parse the option string
    667  1.1  cgd  */
    668  1.1  cgd do_opt(cpopt, fep, ep, exflagsp, rootuidp)
    669  1.1  cgd 	register char *cpopt;
    670  1.1  cgd 	struct exportlist *fep, *ep;
    671  1.1  cgd 	int *exflagsp, *rootuidp;
    672  1.1  cgd {
    673  1.1  cgd 	register char *cpoptarg, *cpoptend;
    674  1.1  cgd 
    675  1.1  cgd 	while (cpopt && *cpopt) {
    676  1.1  cgd 		if (cpoptend = index(cpopt, ','))
    677  1.1  cgd 			*cpoptend++ = '\0';
    678  1.1  cgd 		if (cpoptarg = index(cpopt, '='))
    679  1.1  cgd 			*cpoptarg++ = '\0';
    680  1.1  cgd 		if (!strcmp(cpopt, "ro") || !strcmp(cpopt, "o")) {
    681  1.1  cgd 			if (fep && (fep->ex_exflags & MNT_EXRDONLY) == 0)
    682  1.1  cgd 				syslog(LOG_WARNING, "ro failed for %s",
    683  1.1  cgd 				       ep->ex_dirp);
    684  1.1  cgd 			else
    685  1.1  cgd 				*exflagsp |= MNT_EXRDONLY;
    686  1.1  cgd 		} else if (!strcmp(cpopt, "root") || !strcmp(cpopt, "r")) {
    687  1.1  cgd 			if (cpoptarg && isdigit(*cpoptarg)) {
    688  1.1  cgd 				*rootuidp = atoi(cpoptarg);
    689  1.1  cgd 				if (fep && fep->ex_rootuid != *rootuidp)
    690  1.1  cgd 					syslog(LOG_WARNING,
    691  1.1  cgd 					       "uid failed for %s",
    692  1.1  cgd 					       ep->ex_dirp);
    693  1.1  cgd 			} else
    694  1.1  cgd 				syslog(LOG_WARNING,
    695  1.1  cgd 				       "uid failed for %s",
    696  1.1  cgd 				       ep->ex_dirp);
    697  1.1  cgd 		} else
    698  1.1  cgd 			syslog(LOG_WARNING, "opt %s ignored for %s", cpopt,
    699  1.1  cgd 			       ep->ex_dirp);
    700  1.1  cgd 		cpopt = cpoptend;
    701  1.1  cgd 	}
    702  1.1  cgd }
    703  1.1  cgd 
    704  1.1  cgd #define	STRSIZ	(RPCMNT_NAMELEN+RPCMNT_PATHLEN+50)
    705  1.1  cgd /*
    706  1.1  cgd  * Routines that maintain the remote mounttab
    707  1.1  cgd  */
    708  1.1  cgd void get_mountlist()
    709  1.1  cgd {
    710  1.1  cgd 	register struct mountlist *mlp, **mlpp;
    711  1.1  cgd 	register char *eos, *dirp;
    712  1.1  cgd 	int len;
    713  1.1  cgd 	char str[STRSIZ];
    714  1.1  cgd 	FILE *mlfile;
    715  1.1  cgd 
    716  1.1  cgd 	if (((mlfile = fopen(_PATH_RMOUNTLIST, "r")) == NULL) &&
    717  1.1  cgd 	    ((mlfile = fopen(_PATH_RMOUNTLIST, "w")) == NULL)) {
    718  1.1  cgd 		syslog(LOG_WARNING, "Can't open %s", _PATH_RMOUNTLIST);
    719  1.1  cgd 		return;
    720  1.1  cgd 	}
    721  1.1  cgd 	mlpp = &mlhead;
    722  1.1  cgd 	while (fgets(str, STRSIZ, mlfile) != NULL) {
    723  1.1  cgd 		if ((dirp = index(str, '\t')) == NULL &&
    724  1.1  cgd 		    (dirp = index(str, ' ')) == NULL)
    725  1.1  cgd 			continue;
    726  1.1  cgd 		mlp = (struct mountlist *)malloc(sizeof (*mlp));
    727  1.1  cgd 		len = dirp-str;
    728  1.1  cgd 		if (len > RPCMNT_NAMELEN)
    729  1.1  cgd 			len = RPCMNT_NAMELEN;
    730  1.1  cgd 		bcopy(str, mlp->ml_host, len);
    731  1.1  cgd 		mlp->ml_host[len] = '\0';
    732  1.1  cgd 		while (*dirp == '\t' || *dirp == ' ')
    733  1.1  cgd 			dirp++;
    734  1.1  cgd 		if ((eos = index(dirp, '\t')) == NULL &&
    735  1.1  cgd 		    (eos = index(dirp, ' ')) == NULL &&
    736  1.1  cgd 		    (eos = index(dirp, '\n')) == NULL)
    737  1.1  cgd 			len = strlen(dirp);
    738  1.1  cgd 		else
    739  1.1  cgd 			len = eos-dirp;
    740  1.1  cgd 		if (len > RPCMNT_PATHLEN)
    741  1.1  cgd 			len = RPCMNT_PATHLEN;
    742  1.1  cgd 		bcopy(dirp, mlp->ml_dirp, len);
    743  1.1  cgd 		mlp->ml_dirp[len] = '\0';
    744  1.1  cgd 		mlp->ml_next = (struct mountlist *)0;
    745  1.1  cgd 		*mlpp = mlp;
    746  1.1  cgd 		mlpp = &mlp->ml_next;
    747  1.1  cgd 	}
    748  1.1  cgd 	fclose(mlfile);
    749  1.1  cgd }
    750  1.1  cgd 
    751  1.1  cgd void del_mlist(hostp, dirp)
    752  1.1  cgd 	register char *hostp, *dirp;
    753  1.1  cgd {
    754  1.1  cgd 	register struct mountlist *mlp, **mlpp;
    755  1.1  cgd 	FILE *mlfile;
    756  1.1  cgd 	int fnd = 0;
    757  1.1  cgd 
    758  1.1  cgd 	mlpp = &mlhead;
    759  1.1  cgd 	mlp = mlhead;
    760  1.1  cgd 	while (mlp) {
    761  1.1  cgd 		if (!strcmp(mlp->ml_host, hostp) &&
    762  1.1  cgd 		    (!dirp || !strcmp(mlp->ml_dirp, dirp))) {
    763  1.1  cgd 			fnd = 1;
    764  1.1  cgd 			*mlpp = mlp->ml_next;
    765  1.1  cgd 			free((caddr_t)mlp);
    766  1.1  cgd 		}
    767  1.1  cgd 		mlpp = &mlp->ml_next;
    768  1.1  cgd 		mlp = mlp->ml_next;
    769  1.1  cgd 	}
    770  1.1  cgd 	if (fnd) {
    771  1.1  cgd 		if ((mlfile = fopen(_PATH_RMOUNTLIST, "w")) == NULL) {
    772  1.1  cgd 			syslog(LOG_WARNING, "Can't update %s", _PATH_RMOUNTLIST);
    773  1.1  cgd 			return;
    774  1.1  cgd 		}
    775  1.1  cgd 		mlp = mlhead;
    776  1.1  cgd 		while (mlp) {
    777  1.1  cgd 			fprintf(mlfile, "%s %s\n", mlp->ml_host, mlp->ml_dirp);
    778  1.1  cgd 			mlp = mlp->ml_next;
    779  1.1  cgd 		}
    780  1.1  cgd 		fclose(mlfile);
    781  1.1  cgd 	}
    782  1.1  cgd }
    783  1.1  cgd 
    784  1.1  cgd void add_mlist(hostp, dirp)
    785  1.1  cgd 	register char *hostp, *dirp;
    786  1.1  cgd {
    787  1.1  cgd 	register struct mountlist *mlp, **mlpp;
    788  1.1  cgd 	FILE *mlfile;
    789  1.1  cgd 
    790  1.1  cgd 	mlpp = &mlhead;
    791  1.1  cgd 	mlp = mlhead;
    792  1.1  cgd 	while (mlp) {
    793  1.1  cgd 		if (!strcmp(mlp->ml_host, hostp) && !strcmp(mlp->ml_dirp, dirp))
    794  1.1  cgd 			return;
    795  1.1  cgd 		mlpp = &mlp->ml_next;
    796  1.1  cgd 		mlp = mlp->ml_next;
    797  1.1  cgd 	}
    798  1.1  cgd 	mlp = (struct mountlist *)malloc(sizeof (*mlp));
    799  1.1  cgd 	strncpy(mlp->ml_host, hostp, RPCMNT_NAMELEN);
    800  1.1  cgd 	mlp->ml_host[RPCMNT_NAMELEN] = '\0';
    801  1.1  cgd 	strncpy(mlp->ml_dirp, dirp, RPCMNT_PATHLEN);
    802  1.1  cgd 	mlp->ml_dirp[RPCMNT_PATHLEN] = '\0';
    803  1.1  cgd 	mlp->ml_next = (struct mountlist *)0;
    804  1.1  cgd 	*mlpp = mlp;
    805  1.1  cgd 	if ((mlfile = fopen(_PATH_RMOUNTLIST, "a")) == NULL) {
    806  1.1  cgd 		syslog(LOG_WARNING, "Can't update %s", _PATH_RMOUNTLIST);
    807  1.1  cgd 		return;
    808  1.1  cgd 	}
    809  1.1  cgd 	fprintf(mlfile, "%s %s\n", mlp->ml_host, mlp->ml_dirp);
    810  1.1  cgd 	fclose(mlfile);
    811  1.1  cgd }
    812  1.1  cgd 
    813  1.1  cgd /*
    814  1.1  cgd  * This function is called via. SIGTERM when the system is going down.
    815  1.1  cgd  * It sends a broadcast RPCMNT_UMNTALL.
    816  1.1  cgd  */
    817  1.1  cgd void
    818  1.1  cgd send_umntall()
    819  1.1  cgd {
    820  1.1  cgd 	(void) clnt_broadcast(RPCPROG_MNT, RPCMNT_VER1, RPCMNT_UMNTALL,
    821  1.1  cgd 		xdr_void, (caddr_t)0, xdr_void, (caddr_t)0, umntall_each);
    822  1.1  cgd 	exit();
    823  1.1  cgd }
    824  1.1  cgd 
    825  1.1  cgd umntall_each(resultsp, raddr)
    826  1.1  cgd 	caddr_t resultsp;
    827  1.1  cgd 	struct sockaddr_in *raddr;
    828  1.1  cgd {
    829  1.1  cgd 	return (1);
    830  1.1  cgd }
    831  1.1  cgd 
    832  1.1  cgd /*
    833  1.1  cgd  * Free up an exports list component
    834  1.1  cgd  */
    835  1.1  cgd free_exp(ep)
    836  1.1  cgd 	register struct exportlist *ep;
    837  1.1  cgd {
    838  1.1  cgd 	register struct grouplist *grp;
    839  1.1  cgd 	register char **addrp;
    840  1.1  cgd 	struct grouplist *grp2;
    841  1.1  cgd 
    842  1.1  cgd 	grp = ep->ex_groups;
    843  1.1  cgd 	while (grp != NULL) {
    844  1.1  cgd 		addrp = grp->gr_hp->h_addr_list;
    845  1.1  cgd 		while (*addrp)
    846  1.1  cgd 			free(*addrp++);
    847  1.1  cgd 		free((caddr_t)grp->gr_hp->h_addr_list);
    848  1.1  cgd 		free(grp->gr_hp->h_name);
    849  1.1  cgd 		free((caddr_t)grp->gr_hp);
    850  1.1  cgd 		grp2 = grp;
    851  1.1  cgd 		grp = grp->gr_next;
    852  1.1  cgd 		free((caddr_t)grp2);
    853  1.1  cgd 	}
    854  1.1  cgd 	free((caddr_t)ep);
    855  1.1  cgd }
    856