18fae3551SRodney W. Grimes /* 28fae3551SRodney W. Grimes * Copyright (c) 1989, 1993 38fae3551SRodney W. Grimes * The Regents of the University of California. All rights reserved. 48fae3551SRodney W. Grimes * 58fae3551SRodney W. Grimes * This code is derived from software contributed to Berkeley by 68fae3551SRodney W. Grimes * Herb Hasler and Rick Macklem at The University of Guelph. 78fae3551SRodney W. Grimes * 88fae3551SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 98fae3551SRodney W. Grimes * modification, are permitted provided that the following conditions 108fae3551SRodney W. Grimes * are met: 118fae3551SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 128fae3551SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 138fae3551SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 148fae3551SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 158fae3551SRodney W. Grimes * documentation and/or other materials provided with the distribution. 168fae3551SRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 178fae3551SRodney W. Grimes * must display the following acknowledgement: 188fae3551SRodney W. Grimes * This product includes software developed by the University of 198fae3551SRodney W. Grimes * California, Berkeley and its contributors. 208fae3551SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 218fae3551SRodney W. Grimes * may be used to endorse or promote products derived from this software 228fae3551SRodney W. Grimes * without specific prior written permission. 238fae3551SRodney W. Grimes * 248fae3551SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 258fae3551SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 268fae3551SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 278fae3551SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 288fae3551SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 298fae3551SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 308fae3551SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 318fae3551SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 328fae3551SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 338fae3551SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 348fae3551SRodney W. Grimes * SUCH DAMAGE. 358fae3551SRodney W. Grimes */ 368fae3551SRodney W. Grimes 378fae3551SRodney W. Grimes #ifndef lint 388fae3551SRodney W. Grimes static char copyright[] = 398fae3551SRodney W. Grimes "@(#) Copyright (c) 1989, 1993\n\ 408fae3551SRodney W. Grimes The Regents of the University of California. All rights reserved.\n"; 41d599144dSGarrett Wollman #endif /*not lint*/ 428fae3551SRodney W. Grimes 438fae3551SRodney W. Grimes #ifndef lint 44d599144dSGarrett Wollman /*static char sccsid[] = "From: @(#)mountd.c 8.8 (Berkeley) 2/20/94";*/ 45d599144dSGarrett Wollman static const char rcsid[] = 46d599144dSGarrett Wollman "$Id$"; 47d599144dSGarrett Wollman #endif /*not lint*/ 488fae3551SRodney W. Grimes 498fae3551SRodney W. Grimes #include <sys/param.h> 508fae3551SRodney W. Grimes #include <sys/file.h> 518fae3551SRodney W. Grimes #include <sys/ioctl.h> 528fae3551SRodney W. Grimes #include <sys/mount.h> 538fae3551SRodney W. Grimes #include <sys/socket.h> 548fae3551SRodney W. Grimes #include <sys/stat.h> 558fae3551SRodney W. Grimes #include <sys/syslog.h> 568fae3551SRodney W. Grimes #include <sys/ucred.h> 578fae3551SRodney W. Grimes 588fae3551SRodney W. Grimes #include <rpc/rpc.h> 598fae3551SRodney W. Grimes #include <rpc/pmap_clnt.h> 608fae3551SRodney W. Grimes #include <rpc/pmap_prot.h> 618fae3551SRodney W. Grimes #ifdef ISO 628fae3551SRodney W. Grimes #include <netiso/iso.h> 638fae3551SRodney W. Grimes #endif 648fae3551SRodney W. Grimes #include <nfs/rpcv2.h> 658fae3551SRodney W. Grimes #include <nfs/nfsv2.h> 668fae3551SRodney W. Grimes 678fae3551SRodney W. Grimes #include <arpa/inet.h> 688fae3551SRodney W. Grimes 698fae3551SRodney W. Grimes #include <ctype.h> 708fae3551SRodney W. Grimes #include <errno.h> 718fae3551SRodney W. Grimes #include <grp.h> 728fae3551SRodney W. Grimes #include <netdb.h> 738fae3551SRodney W. Grimes #include <pwd.h> 748fae3551SRodney W. Grimes #include <signal.h> 758fae3551SRodney W. Grimes #include <stdio.h> 768fae3551SRodney W. Grimes #include <stdlib.h> 778fae3551SRodney W. Grimes #include <string.h> 788fae3551SRodney W. Grimes #include <unistd.h> 798fae3551SRodney W. Grimes #include "pathnames.h" 808fae3551SRodney W. Grimes 818fae3551SRodney W. Grimes #ifdef DEBUG 828fae3551SRodney W. Grimes #include <stdarg.h> 838fae3551SRodney W. Grimes #endif 848fae3551SRodney W. Grimes 858fae3551SRodney W. Grimes /* 868fae3551SRodney W. Grimes * Structures for keeping the mount list and export list 878fae3551SRodney W. Grimes */ 888fae3551SRodney W. Grimes struct mountlist { 898fae3551SRodney W. Grimes struct mountlist *ml_next; 908fae3551SRodney W. Grimes char ml_host[RPCMNT_NAMELEN+1]; 918fae3551SRodney W. Grimes char ml_dirp[RPCMNT_PATHLEN+1]; 928fae3551SRodney W. Grimes }; 938fae3551SRodney W. Grimes 948fae3551SRodney W. Grimes struct dirlist { 958fae3551SRodney W. Grimes struct dirlist *dp_left; 968fae3551SRodney W. Grimes struct dirlist *dp_right; 978fae3551SRodney W. Grimes int dp_flag; 988fae3551SRodney W. Grimes struct hostlist *dp_hosts; /* List of hosts this dir exported to */ 998fae3551SRodney W. Grimes char dp_dirp[1]; /* Actually malloc'd to size of dir */ 1008fae3551SRodney W. Grimes }; 1018fae3551SRodney W. Grimes /* dp_flag bits */ 1028fae3551SRodney W. Grimes #define DP_DEFSET 0x1 1038fae3551SRodney W. Grimes 1048fae3551SRodney W. Grimes struct exportlist { 1058fae3551SRodney W. Grimes struct exportlist *ex_next; 1068fae3551SRodney W. Grimes struct dirlist *ex_dirl; 1078fae3551SRodney W. Grimes struct dirlist *ex_defdir; 1088fae3551SRodney W. Grimes int ex_flag; 1098fae3551SRodney W. Grimes fsid_t ex_fs; 1108fae3551SRodney W. Grimes char *ex_fsdir; 1118fae3551SRodney W. Grimes }; 1128fae3551SRodney W. Grimes /* ex_flag bits */ 1138fae3551SRodney W. Grimes #define EX_LINKED 0x1 1148fae3551SRodney W. Grimes 1158fae3551SRodney W. Grimes struct netmsk { 1168fae3551SRodney W. Grimes u_long nt_net; 1178fae3551SRodney W. Grimes u_long nt_mask; 1188fae3551SRodney W. Grimes char *nt_name; 1198fae3551SRodney W. Grimes }; 1208fae3551SRodney W. Grimes 1218fae3551SRodney W. Grimes union grouptypes { 1228fae3551SRodney W. Grimes struct hostent *gt_hostent; 1238fae3551SRodney W. Grimes struct netmsk gt_net; 1248fae3551SRodney W. Grimes #ifdef ISO 1258fae3551SRodney W. Grimes struct sockaddr_iso *gt_isoaddr; 1268fae3551SRodney W. Grimes #endif 1278fae3551SRodney W. Grimes }; 1288fae3551SRodney W. Grimes 1298fae3551SRodney W. Grimes struct grouplist { 1308fae3551SRodney W. Grimes int gr_type; 1318fae3551SRodney W. Grimes union grouptypes gr_ptr; 1328fae3551SRodney W. Grimes struct grouplist *gr_next; 1338fae3551SRodney W. Grimes }; 1348fae3551SRodney W. Grimes /* Group types */ 1358fae3551SRodney W. Grimes #define GT_NULL 0x0 1368fae3551SRodney W. Grimes #define GT_HOST 0x1 1378fae3551SRodney W. Grimes #define GT_NET 0x2 1388fae3551SRodney W. Grimes #define GT_ISO 0x4 1398fae3551SRodney W. Grimes 1408fae3551SRodney W. Grimes struct hostlist { 1418fae3551SRodney W. Grimes struct grouplist *ht_grp; 1428fae3551SRodney W. Grimes struct hostlist *ht_next; 1438fae3551SRodney W. Grimes }; 1448fae3551SRodney W. Grimes 1458fae3551SRodney W. Grimes /* Global defs */ 1468fae3551SRodney W. Grimes char *add_expdir __P((struct dirlist **, char *, int)); 1478fae3551SRodney W. Grimes void add_dlist __P((struct dirlist **, struct dirlist *, 1488fae3551SRodney W. Grimes struct grouplist *)); 1498fae3551SRodney W. Grimes void add_mlist __P((char *, char *)); 1508fae3551SRodney W. Grimes int check_dirpath __P((char *)); 1518fae3551SRodney W. Grimes int check_options __P((struct dirlist *)); 1528fae3551SRodney W. Grimes int chk_host __P((struct dirlist *, u_long, int *)); 1538fae3551SRodney W. Grimes void del_mlist __P((char *, char *)); 1548fae3551SRodney W. Grimes struct dirlist *dirp_search __P((struct dirlist *, char *)); 1558fae3551SRodney W. Grimes int do_mount __P((struct exportlist *, struct grouplist *, int, 1568fae3551SRodney W. Grimes struct ucred *, char *, int, struct statfs *)); 1578fae3551SRodney W. Grimes int do_opt __P((char **, char **, struct exportlist *, struct grouplist *, 1588fae3551SRodney W. Grimes int *, int *, struct ucred *)); 1598fae3551SRodney W. Grimes struct exportlist *ex_search __P((fsid_t *)); 1608fae3551SRodney W. Grimes struct exportlist *get_exp __P((void)); 1618fae3551SRodney W. Grimes void free_dir __P((struct dirlist *)); 1628fae3551SRodney W. Grimes void free_exp __P((struct exportlist *)); 1638fae3551SRodney W. Grimes void free_grp __P((struct grouplist *)); 1648fae3551SRodney W. Grimes void free_host __P((struct hostlist *)); 1658fae3551SRodney W. Grimes void get_exportlist __P((void)); 1668fae3551SRodney W. Grimes int get_host __P((char *, struct grouplist *)); 1678fae3551SRodney W. Grimes struct hostlist *get_ht __P((void)); 1688fae3551SRodney W. Grimes int get_line __P((void)); 1698fae3551SRodney W. Grimes void get_mountlist __P((void)); 1708fae3551SRodney W. Grimes int get_net __P((char *, struct netmsk *, int)); 1718fae3551SRodney W. Grimes void getexp_err __P((struct exportlist *, struct grouplist *)); 1728fae3551SRodney W. Grimes struct grouplist *get_grp __P((void)); 1738fae3551SRodney W. Grimes void hang_dirp __P((struct dirlist *, struct grouplist *, 1748fae3551SRodney W. Grimes struct exportlist *, int)); 1758fae3551SRodney W. Grimes void mntsrv __P((struct svc_req *, SVCXPRT *)); 1768fae3551SRodney W. Grimes void nextfield __P((char **, char **)); 1778fae3551SRodney W. Grimes void out_of_mem __P((void)); 1788fae3551SRodney W. Grimes void parsecred __P((char *, struct ucred *)); 1798fae3551SRodney W. Grimes int put_exlist __P((struct dirlist *, XDR *, struct dirlist *, int *)); 1808fae3551SRodney W. Grimes int scan_tree __P((struct dirlist *, u_long)); 1818fae3551SRodney W. Grimes void send_umntall __P((void)); 1828fae3551SRodney W. Grimes int umntall_each __P((caddr_t, struct sockaddr_in *)); 1838fae3551SRodney W. Grimes int xdr_dir __P((XDR *, char *)); 1848fae3551SRodney W. Grimes int xdr_explist __P((XDR *, caddr_t)); 1858fae3551SRodney W. Grimes int xdr_fhs __P((XDR *, nfsv2fh_t *)); 1868fae3551SRodney W. Grimes int xdr_mlist __P((XDR *, caddr_t)); 1878fae3551SRodney W. Grimes 1888fae3551SRodney W. Grimes /* C library */ 1898fae3551SRodney W. Grimes int getnetgrent(); 1908fae3551SRodney W. Grimes void endnetgrent(); 1918fae3551SRodney W. Grimes void setnetgrent(); 1928fae3551SRodney W. Grimes 1938fae3551SRodney W. Grimes #ifdef ISO 1948fae3551SRodney W. Grimes struct iso_addr *iso_addr(); 1958fae3551SRodney W. Grimes #endif 1968fae3551SRodney W. Grimes 1978fae3551SRodney W. Grimes struct exportlist *exphead; 1988fae3551SRodney W. Grimes struct mountlist *mlhead; 1998fae3551SRodney W. Grimes struct grouplist *grphead; 2008fae3551SRodney W. Grimes char exname[MAXPATHLEN]; 2018fae3551SRodney W. Grimes struct ucred def_anon = { 2028fae3551SRodney W. Grimes 1, 2038fae3551SRodney W. Grimes (uid_t) -2, 2048fae3551SRodney W. Grimes 1, 2058fae3551SRodney W. Grimes { (gid_t) -2 } 2068fae3551SRodney W. Grimes }; 2078fae3551SRodney W. Grimes int root_only = 1; 2088fae3551SRodney W. Grimes int opt_flags; 2098fae3551SRodney W. Grimes /* Bits for above */ 2108fae3551SRodney W. Grimes #define OP_MAPROOT 0x01 2118fae3551SRodney W. Grimes #define OP_MAPALL 0x02 2128fae3551SRodney W. Grimes #define OP_KERB 0x04 2138fae3551SRodney W. Grimes #define OP_MASK 0x08 2148fae3551SRodney W. Grimes #define OP_NET 0x10 2158fae3551SRodney W. Grimes #define OP_ISO 0x20 2168fae3551SRodney W. Grimes #define OP_ALLDIRS 0x40 2178fae3551SRodney W. Grimes 2188fae3551SRodney W. Grimes #ifdef DEBUG 2198fae3551SRodney W. Grimes int debug = 1; 2208fae3551SRodney W. Grimes void SYSLOG __P((int, const char *, ...)); 2218fae3551SRodney W. Grimes #define syslog SYSLOG 2228fae3551SRodney W. Grimes #else 2238fae3551SRodney W. Grimes int debug = 0; 2248fae3551SRodney W. Grimes #endif 2258fae3551SRodney W. Grimes 2268fae3551SRodney W. Grimes /* 2278fae3551SRodney W. Grimes * Mountd server for NFS mount protocol as described in: 2288fae3551SRodney W. Grimes * NFS: Network File System Protocol Specification, RFC1094, Appendix A 2298fae3551SRodney W. Grimes * The optional arguments are the exports file name 2308fae3551SRodney W. Grimes * default: _PATH_EXPORTS 2318fae3551SRodney W. Grimes * and "-n" to allow nonroot mount. 2328fae3551SRodney W. Grimes */ 2338fae3551SRodney W. Grimes int 2348fae3551SRodney W. Grimes main(argc, argv) 2358fae3551SRodney W. Grimes int argc; 2368fae3551SRodney W. Grimes char **argv; 2378fae3551SRodney W. Grimes { 2388fae3551SRodney W. Grimes SVCXPRT *transp; 2398fae3551SRodney W. Grimes int c; 240d599144dSGarrett Wollman struct vfsconf *vfc; 241d599144dSGarrett Wollman 242d599144dSGarrett Wollman vfc = getvfsbyname("nfs"); 243d599144dSGarrett Wollman if(!vfc && vfsisloadable("nfs")) { 244d599144dSGarrett Wollman if(vfsload("nfs")) 245d599144dSGarrett Wollman err(1, "vfsload(nfs)"); 246d599144dSGarrett Wollman endvfsent(); /* flush cache */ 247d599144dSGarrett Wollman vfc = getvfsbyname("nfs"); 248d599144dSGarrett Wollman } 249d599144dSGarrett Wollman if(!vfc) { 250d599144dSGarrett Wollman errx(1, "NFS support is not available in the running kernel"); 251d599144dSGarrett Wollman } 2528fae3551SRodney W. Grimes 2538fae3551SRodney W. Grimes while ((c = getopt(argc, argv, "n")) != EOF) 2548fae3551SRodney W. Grimes switch (c) { 2558fae3551SRodney W. Grimes case 'n': 2568fae3551SRodney W. Grimes root_only = 0; 2578fae3551SRodney W. Grimes break; 2588fae3551SRodney W. Grimes default: 2598fae3551SRodney W. Grimes fprintf(stderr, "Usage: mountd [-n] [export_file]\n"); 2608fae3551SRodney W. Grimes exit(1); 2618fae3551SRodney W. Grimes }; 2628fae3551SRodney W. Grimes argc -= optind; 2638fae3551SRodney W. Grimes argv += optind; 2648fae3551SRodney W. Grimes grphead = (struct grouplist *)NULL; 2658fae3551SRodney W. Grimes exphead = (struct exportlist *)NULL; 2668fae3551SRodney W. Grimes mlhead = (struct mountlist *)NULL; 2678fae3551SRodney W. Grimes if (argc == 1) { 2688fae3551SRodney W. Grimes strncpy(exname, *argv, MAXPATHLEN-1); 2698fae3551SRodney W. Grimes exname[MAXPATHLEN-1] = '\0'; 2708fae3551SRodney W. Grimes } else 2718fae3551SRodney W. Grimes strcpy(exname, _PATH_EXPORTS); 2728fae3551SRodney W. Grimes openlog("mountd", LOG_PID, LOG_DAEMON); 2738fae3551SRodney W. Grimes if (debug) 2748fae3551SRodney W. Grimes fprintf(stderr,"Getting export list.\n"); 2758fae3551SRodney W. Grimes get_exportlist(); 2768fae3551SRodney W. Grimes if (debug) 2778fae3551SRodney W. Grimes fprintf(stderr,"Getting mount list.\n"); 2788fae3551SRodney W. Grimes get_mountlist(); 2798fae3551SRodney W. Grimes if (debug) 2808fae3551SRodney W. Grimes fprintf(stderr,"Here we go.\n"); 2818fae3551SRodney W. Grimes if (debug == 0) { 2828fae3551SRodney W. Grimes daemon(0, 0); 2838fae3551SRodney W. Grimes signal(SIGINT, SIG_IGN); 2848fae3551SRodney W. Grimes signal(SIGQUIT, SIG_IGN); 2858fae3551SRodney W. Grimes } 2868fae3551SRodney W. Grimes signal(SIGHUP, (void (*) __P((int))) get_exportlist); 2878fae3551SRodney W. Grimes signal(SIGTERM, (void (*) __P((int))) send_umntall); 2888fae3551SRodney W. Grimes { FILE *pidfile = fopen(_PATH_MOUNTDPID, "w"); 2898fae3551SRodney W. Grimes if (pidfile != NULL) { 2908fae3551SRodney W. Grimes fprintf(pidfile, "%d\n", getpid()); 2918fae3551SRodney W. Grimes fclose(pidfile); 2928fae3551SRodney W. Grimes } 2938fae3551SRodney W. Grimes } 2948fae3551SRodney W. Grimes if ((transp = svcudp_create(RPC_ANYSOCK)) == NULL) { 2958fae3551SRodney W. Grimes syslog(LOG_ERR, "Can't create socket"); 2968fae3551SRodney W. Grimes exit(1); 2978fae3551SRodney W. Grimes } 2988fae3551SRodney W. Grimes pmap_unset(RPCPROG_MNT, RPCMNT_VER1); 2998fae3551SRodney W. Grimes if (!svc_register(transp, RPCPROG_MNT, RPCMNT_VER1, mntsrv, 3008fae3551SRodney W. Grimes IPPROTO_UDP)) { 3018fae3551SRodney W. Grimes syslog(LOG_ERR, "Can't register mount"); 3028fae3551SRodney W. Grimes exit(1); 3038fae3551SRodney W. Grimes } 3048fae3551SRodney W. Grimes svc_run(); 3058fae3551SRodney W. Grimes syslog(LOG_ERR, "Mountd died"); 3068fae3551SRodney W. Grimes exit(1); 3078fae3551SRodney W. Grimes } 3088fae3551SRodney W. Grimes 3098fae3551SRodney W. Grimes /* 3108fae3551SRodney W. Grimes * The mount rpc service 3118fae3551SRodney W. Grimes */ 3128fae3551SRodney W. Grimes void 3138fae3551SRodney W. Grimes mntsrv(rqstp, transp) 3148fae3551SRodney W. Grimes struct svc_req *rqstp; 3158fae3551SRodney W. Grimes SVCXPRT *transp; 3168fae3551SRodney W. Grimes { 3178fae3551SRodney W. Grimes struct exportlist *ep; 3188fae3551SRodney W. Grimes struct dirlist *dp; 3198fae3551SRodney W. Grimes nfsv2fh_t nfh; 3208fae3551SRodney W. Grimes struct authunix_parms *ucr; 3218fae3551SRodney W. Grimes struct stat stb; 3228fae3551SRodney W. Grimes struct statfs fsb; 3238fae3551SRodney W. Grimes struct hostent *hp; 3248fae3551SRodney W. Grimes u_long saddr; 3258fae3551SRodney W. Grimes char rpcpath[RPCMNT_PATHLEN+1], dirpath[MAXPATHLEN]; 3268fae3551SRodney W. Grimes int bad = ENOENT, omask, defset; 3278fae3551SRodney W. Grimes uid_t uid = -2; 3288fae3551SRodney W. Grimes 3298fae3551SRodney W. Grimes /* Get authorization */ 3308fae3551SRodney W. Grimes switch (rqstp->rq_cred.oa_flavor) { 3318fae3551SRodney W. Grimes case AUTH_UNIX: 3328fae3551SRodney W. Grimes ucr = (struct authunix_parms *)rqstp->rq_clntcred; 3338fae3551SRodney W. Grimes uid = ucr->aup_uid; 3348fae3551SRodney W. Grimes break; 3358fae3551SRodney W. Grimes case AUTH_NULL: 3368fae3551SRodney W. Grimes default: 3378fae3551SRodney W. Grimes break; 3388fae3551SRodney W. Grimes } 3398fae3551SRodney W. Grimes 3408fae3551SRodney W. Grimes saddr = transp->xp_raddr.sin_addr.s_addr; 3418fae3551SRodney W. Grimes hp = (struct hostent *)NULL; 3428fae3551SRodney W. Grimes switch (rqstp->rq_proc) { 3438fae3551SRodney W. Grimes case NULLPROC: 3448fae3551SRodney W. Grimes if (!svc_sendreply(transp, xdr_void, (caddr_t)NULL)) 3458fae3551SRodney W. Grimes syslog(LOG_ERR, "Can't send reply"); 3468fae3551SRodney W. Grimes return; 3478fae3551SRodney W. Grimes case RPCMNT_MOUNT: 3488fae3551SRodney W. Grimes if ((uid != 0 && root_only) || uid == -2) { 3498fae3551SRodney W. Grimes svcerr_weakauth(transp); 3508fae3551SRodney W. Grimes return; 3518fae3551SRodney W. Grimes } 3528fae3551SRodney W. Grimes if (!svc_getargs(transp, xdr_dir, rpcpath)) { 3538fae3551SRodney W. Grimes svcerr_decode(transp); 3548fae3551SRodney W. Grimes return; 3558fae3551SRodney W. Grimes } 3568fae3551SRodney W. Grimes 3578fae3551SRodney W. Grimes /* 3588fae3551SRodney W. Grimes * Get the real pathname and make sure it is a directory 3598fae3551SRodney W. Grimes * that exists. 3608fae3551SRodney W. Grimes */ 3618fae3551SRodney W. Grimes if (realpath(rpcpath, dirpath) == 0 || 3628fae3551SRodney W. Grimes stat(dirpath, &stb) < 0 || 3638fae3551SRodney W. Grimes (stb.st_mode & S_IFMT) != S_IFDIR || 3648fae3551SRodney W. Grimes statfs(dirpath, &fsb) < 0) { 3658fae3551SRodney W. Grimes chdir("/"); /* Just in case realpath doesn't */ 3668fae3551SRodney W. Grimes if (debug) 3678fae3551SRodney W. Grimes fprintf(stderr, "stat failed on %s\n", dirpath); 3688fae3551SRodney W. Grimes if (!svc_sendreply(transp, xdr_long, (caddr_t)&bad)) 3698fae3551SRodney W. Grimes syslog(LOG_ERR, "Can't send reply"); 3708fae3551SRodney W. Grimes return; 3718fae3551SRodney W. Grimes } 3728fae3551SRodney W. Grimes 3738fae3551SRodney W. Grimes /* Check in the exports list */ 3748fae3551SRodney W. Grimes omask = sigblock(sigmask(SIGHUP)); 3758fae3551SRodney W. Grimes ep = ex_search(&fsb.f_fsid); 3768fae3551SRodney W. Grimes defset = 0; 3778fae3551SRodney W. Grimes if (ep && (chk_host(ep->ex_defdir, saddr, &defset) || 3788fae3551SRodney W. Grimes ((dp = dirp_search(ep->ex_dirl, dirpath)) && 3798fae3551SRodney W. Grimes chk_host(dp, saddr, &defset)) || 3808fae3551SRodney W. Grimes (defset && scan_tree(ep->ex_defdir, saddr) == 0 && 3818fae3551SRodney W. Grimes scan_tree(ep->ex_dirl, saddr) == 0))) { 3828fae3551SRodney W. Grimes /* Get the file handle */ 3838fae3551SRodney W. Grimes bzero((caddr_t)&nfh, sizeof(nfh)); 3848fae3551SRodney W. Grimes if (getfh(dirpath, (fhandle_t *)&nfh) < 0) { 3858fae3551SRodney W. Grimes bad = errno; 3868fae3551SRodney W. Grimes syslog(LOG_ERR, "Can't get fh for %s", dirpath); 3878fae3551SRodney W. Grimes if (!svc_sendreply(transp, xdr_long, 3888fae3551SRodney W. Grimes (caddr_t)&bad)) 3898fae3551SRodney W. Grimes syslog(LOG_ERR, "Can't send reply"); 3908fae3551SRodney W. Grimes sigsetmask(omask); 3918fae3551SRodney W. Grimes return; 3928fae3551SRodney W. Grimes } 3938fae3551SRodney W. Grimes if (!svc_sendreply(transp, xdr_fhs, (caddr_t)&nfh)) 3948fae3551SRodney W. Grimes syslog(LOG_ERR, "Can't send reply"); 3958fae3551SRodney W. Grimes if (hp == NULL) 3968fae3551SRodney W. Grimes hp = gethostbyaddr((caddr_t)&saddr, 3978fae3551SRodney W. Grimes sizeof(saddr), AF_INET); 3988fae3551SRodney W. Grimes if (hp) 3998fae3551SRodney W. Grimes add_mlist(hp->h_name, dirpath); 4008fae3551SRodney W. Grimes else 4018fae3551SRodney W. Grimes add_mlist(inet_ntoa(transp->xp_raddr.sin_addr), 4028fae3551SRodney W. Grimes dirpath); 4038fae3551SRodney W. Grimes if (debug) 4048fae3551SRodney W. Grimes fprintf(stderr,"Mount successfull.\n"); 4058fae3551SRodney W. Grimes } else { 4068fae3551SRodney W. Grimes bad = EACCES; 4078fae3551SRodney W. Grimes if (!svc_sendreply(transp, xdr_long, (caddr_t)&bad)) 4088fae3551SRodney W. Grimes syslog(LOG_ERR, "Can't send reply"); 4098fae3551SRodney W. Grimes } 4108fae3551SRodney W. Grimes sigsetmask(omask); 4118fae3551SRodney W. Grimes return; 4128fae3551SRodney W. Grimes case RPCMNT_DUMP: 4138fae3551SRodney W. Grimes if (!svc_sendreply(transp, xdr_mlist, (caddr_t)NULL)) 4148fae3551SRodney W. Grimes syslog(LOG_ERR, "Can't send reply"); 4158fae3551SRodney W. Grimes return; 4168fae3551SRodney W. Grimes case RPCMNT_UMOUNT: 4178fae3551SRodney W. Grimes if ((uid != 0 && root_only) || uid == -2) { 4188fae3551SRodney W. Grimes svcerr_weakauth(transp); 4198fae3551SRodney W. Grimes return; 4208fae3551SRodney W. Grimes } 4218fae3551SRodney W. Grimes if (!svc_getargs(transp, xdr_dir, dirpath)) { 4228fae3551SRodney W. Grimes svcerr_decode(transp); 4238fae3551SRodney W. Grimes return; 4248fae3551SRodney W. Grimes } 4258fae3551SRodney W. Grimes if (!svc_sendreply(transp, xdr_void, (caddr_t)NULL)) 4268fae3551SRodney W. Grimes syslog(LOG_ERR, "Can't send reply"); 4278fae3551SRodney W. Grimes hp = gethostbyaddr((caddr_t)&saddr, sizeof(saddr), AF_INET); 4288fae3551SRodney W. Grimes if (hp) 4298fae3551SRodney W. Grimes del_mlist(hp->h_name, dirpath); 4308fae3551SRodney W. Grimes del_mlist(inet_ntoa(transp->xp_raddr.sin_addr), dirpath); 4318fae3551SRodney W. Grimes return; 4328fae3551SRodney W. Grimes case RPCMNT_UMNTALL: 4338fae3551SRodney W. Grimes if ((uid != 0 && root_only) || uid == -2) { 4348fae3551SRodney W. Grimes svcerr_weakauth(transp); 4358fae3551SRodney W. Grimes return; 4368fae3551SRodney W. Grimes } 4378fae3551SRodney W. Grimes if (!svc_sendreply(transp, xdr_void, (caddr_t)NULL)) 4388fae3551SRodney W. Grimes syslog(LOG_ERR, "Can't send reply"); 4398fae3551SRodney W. Grimes hp = gethostbyaddr((caddr_t)&saddr, sizeof(saddr), AF_INET); 4408fae3551SRodney W. Grimes if (hp) 4418fae3551SRodney W. Grimes del_mlist(hp->h_name, (char *)NULL); 4428fae3551SRodney W. Grimes del_mlist(inet_ntoa(transp->xp_raddr.sin_addr), (char *)NULL); 4438fae3551SRodney W. Grimes return; 4448fae3551SRodney W. Grimes case RPCMNT_EXPORT: 4458fae3551SRodney W. Grimes if (!svc_sendreply(transp, xdr_explist, (caddr_t)NULL)) 4468fae3551SRodney W. Grimes syslog(LOG_ERR, "Can't send reply"); 4478fae3551SRodney W. Grimes return; 4488fae3551SRodney W. Grimes default: 4498fae3551SRodney W. Grimes svcerr_noproc(transp); 4508fae3551SRodney W. Grimes return; 4518fae3551SRodney W. Grimes } 4528fae3551SRodney W. Grimes } 4538fae3551SRodney W. Grimes 4548fae3551SRodney W. Grimes /* 4558fae3551SRodney W. Grimes * Xdr conversion for a dirpath string 4568fae3551SRodney W. Grimes */ 4578fae3551SRodney W. Grimes int 4588fae3551SRodney W. Grimes xdr_dir(xdrsp, dirp) 4598fae3551SRodney W. Grimes XDR *xdrsp; 4608fae3551SRodney W. Grimes char *dirp; 4618fae3551SRodney W. Grimes { 4628fae3551SRodney W. Grimes return (xdr_string(xdrsp, &dirp, RPCMNT_PATHLEN)); 4638fae3551SRodney W. Grimes } 4648fae3551SRodney W. Grimes 4658fae3551SRodney W. Grimes /* 4668fae3551SRodney W. Grimes * Xdr routine to generate fhstatus 4678fae3551SRodney W. Grimes */ 4688fae3551SRodney W. Grimes int 4698fae3551SRodney W. Grimes xdr_fhs(xdrsp, nfh) 4708fae3551SRodney W. Grimes XDR *xdrsp; 4718fae3551SRodney W. Grimes nfsv2fh_t *nfh; 4728fae3551SRodney W. Grimes { 4738fae3551SRodney W. Grimes int ok = 0; 4748fae3551SRodney W. Grimes 4758fae3551SRodney W. Grimes if (!xdr_long(xdrsp, &ok)) 4768fae3551SRodney W. Grimes return (0); 4778fae3551SRodney W. Grimes return (xdr_opaque(xdrsp, (caddr_t)nfh, NFSX_FH)); 4788fae3551SRodney W. Grimes } 4798fae3551SRodney W. Grimes 4808fae3551SRodney W. Grimes int 4818fae3551SRodney W. Grimes xdr_mlist(xdrsp, cp) 4828fae3551SRodney W. Grimes XDR *xdrsp; 4838fae3551SRodney W. Grimes caddr_t cp; 4848fae3551SRodney W. Grimes { 4858fae3551SRodney W. Grimes struct mountlist *mlp; 4868fae3551SRodney W. Grimes int true = 1; 4878fae3551SRodney W. Grimes int false = 0; 4888fae3551SRodney W. Grimes char *strp; 4898fae3551SRodney W. Grimes 4908fae3551SRodney W. Grimes mlp = mlhead; 4918fae3551SRodney W. Grimes while (mlp) { 4928fae3551SRodney W. Grimes if (!xdr_bool(xdrsp, &true)) 4938fae3551SRodney W. Grimes return (0); 4948fae3551SRodney W. Grimes strp = &mlp->ml_host[0]; 4958fae3551SRodney W. Grimes if (!xdr_string(xdrsp, &strp, RPCMNT_NAMELEN)) 4968fae3551SRodney W. Grimes return (0); 4978fae3551SRodney W. Grimes strp = &mlp->ml_dirp[0]; 4988fae3551SRodney W. Grimes if (!xdr_string(xdrsp, &strp, RPCMNT_PATHLEN)) 4998fae3551SRodney W. Grimes return (0); 5008fae3551SRodney W. Grimes mlp = mlp->ml_next; 5018fae3551SRodney W. Grimes } 5028fae3551SRodney W. Grimes if (!xdr_bool(xdrsp, &false)) 5038fae3551SRodney W. Grimes return (0); 5048fae3551SRodney W. Grimes return (1); 5058fae3551SRodney W. Grimes } 5068fae3551SRodney W. Grimes 5078fae3551SRodney W. Grimes /* 5088fae3551SRodney W. Grimes * Xdr conversion for export list 5098fae3551SRodney W. Grimes */ 5108fae3551SRodney W. Grimes int 5118fae3551SRodney W. Grimes xdr_explist(xdrsp, cp) 5128fae3551SRodney W. Grimes XDR *xdrsp; 5138fae3551SRodney W. Grimes caddr_t cp; 5148fae3551SRodney W. Grimes { 5158fae3551SRodney W. Grimes struct exportlist *ep; 5168fae3551SRodney W. Grimes int false = 0; 5178fae3551SRodney W. Grimes int omask, putdef; 5188fae3551SRodney W. Grimes 5198fae3551SRodney W. Grimes omask = sigblock(sigmask(SIGHUP)); 5208fae3551SRodney W. Grimes ep = exphead; 5218fae3551SRodney W. Grimes while (ep) { 5228fae3551SRodney W. Grimes putdef = 0; 5238fae3551SRodney W. Grimes if (put_exlist(ep->ex_dirl, xdrsp, ep->ex_defdir, &putdef)) 5248fae3551SRodney W. Grimes goto errout; 5258fae3551SRodney W. Grimes if (ep->ex_defdir && putdef == 0 && 5268fae3551SRodney W. Grimes put_exlist(ep->ex_defdir, xdrsp, (struct dirlist *)NULL, 5278fae3551SRodney W. Grimes &putdef)) 5288fae3551SRodney W. Grimes goto errout; 5298fae3551SRodney W. Grimes ep = ep->ex_next; 5308fae3551SRodney W. Grimes } 5318fae3551SRodney W. Grimes sigsetmask(omask); 5328fae3551SRodney W. Grimes if (!xdr_bool(xdrsp, &false)) 5338fae3551SRodney W. Grimes return (0); 5348fae3551SRodney W. Grimes return (1); 5358fae3551SRodney W. Grimes errout: 5368fae3551SRodney W. Grimes sigsetmask(omask); 5378fae3551SRodney W. Grimes return (0); 5388fae3551SRodney W. Grimes } 5398fae3551SRodney W. Grimes 5408fae3551SRodney W. Grimes /* 5418fae3551SRodney W. Grimes * Called from xdr_explist() to traverse the tree and export the 5428fae3551SRodney W. Grimes * directory paths. 5438fae3551SRodney W. Grimes */ 5448fae3551SRodney W. Grimes int 5458fae3551SRodney W. Grimes put_exlist(dp, xdrsp, adp, putdefp) 5468fae3551SRodney W. Grimes struct dirlist *dp; 5478fae3551SRodney W. Grimes XDR *xdrsp; 5488fae3551SRodney W. Grimes struct dirlist *adp; 5498fae3551SRodney W. Grimes int *putdefp; 5508fae3551SRodney W. Grimes { 5518fae3551SRodney W. Grimes struct grouplist *grp; 5528fae3551SRodney W. Grimes struct hostlist *hp; 5538fae3551SRodney W. Grimes int true = 1; 5548fae3551SRodney W. Grimes int false = 0; 5558fae3551SRodney W. Grimes int gotalldir = 0; 5568fae3551SRodney W. Grimes char *strp; 5578fae3551SRodney W. Grimes 5588fae3551SRodney W. Grimes if (dp) { 5598fae3551SRodney W. Grimes if (put_exlist(dp->dp_left, xdrsp, adp, putdefp)) 5608fae3551SRodney W. Grimes return (1); 5618fae3551SRodney W. Grimes if (!xdr_bool(xdrsp, &true)) 5628fae3551SRodney W. Grimes return (1); 5638fae3551SRodney W. Grimes strp = dp->dp_dirp; 5648fae3551SRodney W. Grimes if (!xdr_string(xdrsp, &strp, RPCMNT_PATHLEN)) 5658fae3551SRodney W. Grimes return (1); 5668fae3551SRodney W. Grimes if (adp && !strcmp(dp->dp_dirp, adp->dp_dirp)) { 5678fae3551SRodney W. Grimes gotalldir = 1; 5688fae3551SRodney W. Grimes *putdefp = 1; 5698fae3551SRodney W. Grimes } 5708fae3551SRodney W. Grimes if ((dp->dp_flag & DP_DEFSET) == 0 && 5718fae3551SRodney W. Grimes (gotalldir == 0 || (adp->dp_flag & DP_DEFSET) == 0)) { 5728fae3551SRodney W. Grimes hp = dp->dp_hosts; 5738fae3551SRodney W. Grimes while (hp) { 5748fae3551SRodney W. Grimes grp = hp->ht_grp; 5758fae3551SRodney W. Grimes if (grp->gr_type == GT_HOST) { 5768fae3551SRodney W. Grimes if (!xdr_bool(xdrsp, &true)) 5778fae3551SRodney W. Grimes return (1); 5788fae3551SRodney W. Grimes strp = grp->gr_ptr.gt_hostent->h_name; 5798fae3551SRodney W. Grimes if (!xdr_string(xdrsp, &strp, 5808fae3551SRodney W. Grimes RPCMNT_NAMELEN)) 5818fae3551SRodney W. Grimes return (1); 5828fae3551SRodney W. Grimes } else if (grp->gr_type == GT_NET) { 5838fae3551SRodney W. Grimes if (!xdr_bool(xdrsp, &true)) 5848fae3551SRodney W. Grimes return (1); 5858fae3551SRodney W. Grimes strp = grp->gr_ptr.gt_net.nt_name; 5868fae3551SRodney W. Grimes if (!xdr_string(xdrsp, &strp, 5878fae3551SRodney W. Grimes RPCMNT_NAMELEN)) 5888fae3551SRodney W. Grimes return (1); 5898fae3551SRodney W. Grimes } 5908fae3551SRodney W. Grimes hp = hp->ht_next; 5918fae3551SRodney W. Grimes if (gotalldir && hp == (struct hostlist *)NULL) { 5928fae3551SRodney W. Grimes hp = adp->dp_hosts; 5938fae3551SRodney W. Grimes gotalldir = 0; 5948fae3551SRodney W. Grimes } 5958fae3551SRodney W. Grimes } 5968fae3551SRodney W. Grimes } 5978fae3551SRodney W. Grimes if (!xdr_bool(xdrsp, &false)) 5988fae3551SRodney W. Grimes return (1); 5998fae3551SRodney W. Grimes if (put_exlist(dp->dp_right, xdrsp, adp, putdefp)) 6008fae3551SRodney W. Grimes return (1); 6018fae3551SRodney W. Grimes } 6028fae3551SRodney W. Grimes return (0); 6038fae3551SRodney W. Grimes } 6048fae3551SRodney W. Grimes 6058fae3551SRodney W. Grimes #define LINESIZ 10240 6068fae3551SRodney W. Grimes char line[LINESIZ]; 6078fae3551SRodney W. Grimes FILE *exp_file; 6088fae3551SRodney W. Grimes 6098fae3551SRodney W. Grimes /* 6108fae3551SRodney W. Grimes * Get the export list 6118fae3551SRodney W. Grimes */ 6128fae3551SRodney W. Grimes void 6138fae3551SRodney W. Grimes get_exportlist() 6148fae3551SRodney W. Grimes { 6158fae3551SRodney W. Grimes struct exportlist *ep, *ep2; 6168fae3551SRodney W. Grimes struct grouplist *grp, *tgrp; 6178fae3551SRodney W. Grimes struct exportlist **epp; 6188fae3551SRodney W. Grimes struct dirlist *dirhead; 6198fae3551SRodney W. Grimes struct statfs fsb, *fsp; 6208fae3551SRodney W. Grimes struct hostent *hpe; 6218fae3551SRodney W. Grimes struct ucred anon; 6228fae3551SRodney W. Grimes char *cp, *endcp, *dirp, *hst, *usr, *dom, savedc; 6238fae3551SRodney W. Grimes int len, has_host, exflags, got_nondir, dirplen, num, i, netgrp; 6248fae3551SRodney W. Grimes 6258fae3551SRodney W. Grimes /* 6268fae3551SRodney W. Grimes * First, get rid of the old list 6278fae3551SRodney W. Grimes */ 6288fae3551SRodney W. Grimes ep = exphead; 6298fae3551SRodney W. Grimes while (ep) { 6308fae3551SRodney W. Grimes ep2 = ep; 6318fae3551SRodney W. Grimes ep = ep->ex_next; 6328fae3551SRodney W. Grimes free_exp(ep2); 6338fae3551SRodney W. Grimes } 6348fae3551SRodney W. Grimes exphead = (struct exportlist *)NULL; 6358fae3551SRodney W. Grimes 6368fae3551SRodney W. Grimes grp = grphead; 6378fae3551SRodney W. Grimes while (grp) { 6388fae3551SRodney W. Grimes tgrp = grp; 6398fae3551SRodney W. Grimes grp = grp->gr_next; 6408fae3551SRodney W. Grimes free_grp(tgrp); 6418fae3551SRodney W. Grimes } 6428fae3551SRodney W. Grimes grphead = (struct grouplist *)NULL; 6438fae3551SRodney W. Grimes 6448fae3551SRodney W. Grimes /* 6458fae3551SRodney W. Grimes * And delete exports that are in the kernel for all local 6468fae3551SRodney W. Grimes * file systems. 6478fae3551SRodney W. Grimes * XXX: Should know how to handle all local exportable file systems 6488fae3551SRodney W. Grimes * instead of just MOUNT_UFS. 6498fae3551SRodney W. Grimes */ 6508fae3551SRodney W. Grimes num = getmntinfo(&fsp, MNT_NOWAIT); 6518fae3551SRodney W. Grimes for (i = 0; i < num; i++) { 6528fae3551SRodney W. Grimes union { 6538fae3551SRodney W. Grimes struct ufs_args ua; 6548fae3551SRodney W. Grimes struct iso_args ia; 6558fae3551SRodney W. Grimes struct mfs_args ma; 6568fae3551SRodney W. Grimes } targs; 6578fae3551SRodney W. Grimes 6588fae3551SRodney W. Grimes switch (fsp->f_type) { 6598fae3551SRodney W. Grimes case MOUNT_MFS: 6608fae3551SRodney W. Grimes case MOUNT_UFS: 6618fae3551SRodney W. Grimes case MOUNT_CD9660: 662541758b1SDoug Rabson case MOUNT_MSDOS: 6638fae3551SRodney W. Grimes targs.ua.fspec = NULL; 6648fae3551SRodney W. Grimes targs.ua.export.ex_flags = MNT_DELEXPORT; 6658fae3551SRodney W. Grimes if (mount(fsp->f_type, fsp->f_mntonname, 6668fae3551SRodney W. Grimes fsp->f_flags | MNT_UPDATE, 6678fae3551SRodney W. Grimes (caddr_t)&targs) < 0) 6688fae3551SRodney W. Grimes syslog(LOG_ERR, "Can't delete exports for %s", 6698fae3551SRodney W. Grimes fsp->f_mntonname); 6708fae3551SRodney W. Grimes } 6718fae3551SRodney W. Grimes fsp++; 6728fae3551SRodney W. Grimes } 6738fae3551SRodney W. Grimes 6748fae3551SRodney W. Grimes /* 6758fae3551SRodney W. Grimes * Read in the exports file and build the list, calling 6768fae3551SRodney W. Grimes * mount() as we go along to push the export rules into the kernel. 6778fae3551SRodney W. Grimes */ 6788fae3551SRodney W. Grimes if ((exp_file = fopen(exname, "r")) == NULL) { 6798fae3551SRodney W. Grimes syslog(LOG_ERR, "Can't open %s", exname); 6808fae3551SRodney W. Grimes exit(2); 6818fae3551SRodney W. Grimes } 6828fae3551SRodney W. Grimes dirhead = (struct dirlist *)NULL; 6838fae3551SRodney W. Grimes while (get_line()) { 6848fae3551SRodney W. Grimes if (debug) 6858fae3551SRodney W. Grimes fprintf(stderr,"Got line %s\n",line); 6868fae3551SRodney W. Grimes cp = line; 6878fae3551SRodney W. Grimes nextfield(&cp, &endcp); 6888fae3551SRodney W. Grimes if (*cp == '#') 6898fae3551SRodney W. Grimes goto nextline; 6908fae3551SRodney W. Grimes 6918fae3551SRodney W. Grimes /* 6928fae3551SRodney W. Grimes * Set defaults. 6938fae3551SRodney W. Grimes */ 6948fae3551SRodney W. Grimes has_host = FALSE; 6958fae3551SRodney W. Grimes anon = def_anon; 6968fae3551SRodney W. Grimes exflags = MNT_EXPORTED; 6978fae3551SRodney W. Grimes got_nondir = 0; 6988fae3551SRodney W. Grimes opt_flags = 0; 6998fae3551SRodney W. Grimes ep = (struct exportlist *)NULL; 7008fae3551SRodney W. Grimes 7018fae3551SRodney W. Grimes /* 7028fae3551SRodney W. Grimes * Create new exports list entry 7038fae3551SRodney W. Grimes */ 7048fae3551SRodney W. Grimes len = endcp-cp; 7058fae3551SRodney W. Grimes tgrp = grp = get_grp(); 7068fae3551SRodney W. Grimes while (len > 0) { 7078fae3551SRodney W. Grimes if (len > RPCMNT_NAMELEN) { 7088fae3551SRodney W. Grimes getexp_err(ep, tgrp); 7098fae3551SRodney W. Grimes goto nextline; 7108fae3551SRodney W. Grimes } 7118fae3551SRodney W. Grimes if (*cp == '-') { 7128fae3551SRodney W. Grimes if (ep == (struct exportlist *)NULL) { 7138fae3551SRodney W. Grimes getexp_err(ep, tgrp); 7148fae3551SRodney W. Grimes goto nextline; 7158fae3551SRodney W. Grimes } 7168fae3551SRodney W. Grimes if (debug) 7178fae3551SRodney W. Grimes fprintf(stderr, "doing opt %s\n", cp); 7188fae3551SRodney W. Grimes got_nondir = 1; 7198fae3551SRodney W. Grimes if (do_opt(&cp, &endcp, ep, grp, &has_host, 7208fae3551SRodney W. Grimes &exflags, &anon)) { 7218fae3551SRodney W. Grimes getexp_err(ep, tgrp); 7228fae3551SRodney W. Grimes goto nextline; 7238fae3551SRodney W. Grimes } 7248fae3551SRodney W. Grimes } else if (*cp == '/') { 7258fae3551SRodney W. Grimes savedc = *endcp; 7268fae3551SRodney W. Grimes *endcp = '\0'; 7278fae3551SRodney W. Grimes if (check_dirpath(cp) && 7288fae3551SRodney W. Grimes statfs(cp, &fsb) >= 0) { 7298fae3551SRodney W. Grimes if (got_nondir) { 7308fae3551SRodney W. Grimes syslog(LOG_ERR, "Dirs must be first"); 7318fae3551SRodney W. Grimes getexp_err(ep, tgrp); 7328fae3551SRodney W. Grimes goto nextline; 7338fae3551SRodney W. Grimes } 7348fae3551SRodney W. Grimes if (ep) { 7358fae3551SRodney W. Grimes if (ep->ex_fs.val[0] != fsb.f_fsid.val[0] || 7368fae3551SRodney W. Grimes ep->ex_fs.val[1] != fsb.f_fsid.val[1]) { 7378fae3551SRodney W. Grimes getexp_err(ep, tgrp); 7388fae3551SRodney W. Grimes goto nextline; 7398fae3551SRodney W. Grimes } 7408fae3551SRodney W. Grimes } else { 7418fae3551SRodney W. Grimes /* 7428fae3551SRodney W. Grimes * See if this directory is already 7438fae3551SRodney W. Grimes * in the list. 7448fae3551SRodney W. Grimes */ 7458fae3551SRodney W. Grimes ep = ex_search(&fsb.f_fsid); 7468fae3551SRodney W. Grimes if (ep == (struct exportlist *)NULL) { 7478fae3551SRodney W. Grimes ep = get_exp(); 7488fae3551SRodney W. Grimes ep->ex_fs = fsb.f_fsid; 7498fae3551SRodney W. Grimes ep->ex_fsdir = (char *) 7508fae3551SRodney W. Grimes malloc(strlen(fsb.f_mntonname) + 1); 7518fae3551SRodney W. Grimes if (ep->ex_fsdir) 7528fae3551SRodney W. Grimes strcpy(ep->ex_fsdir, 7538fae3551SRodney W. Grimes fsb.f_mntonname); 7548fae3551SRodney W. Grimes else 7558fae3551SRodney W. Grimes out_of_mem(); 7568fae3551SRodney W. Grimes if (debug) 7578fae3551SRodney W. Grimes fprintf(stderr, 7588fae3551SRodney W. Grimes "Making new ep fs=0x%x,0x%x\n", 7598fae3551SRodney W. Grimes fsb.f_fsid.val[0], 7608fae3551SRodney W. Grimes fsb.f_fsid.val[1]); 7618fae3551SRodney W. Grimes } else if (debug) 7628fae3551SRodney W. Grimes fprintf(stderr, 7638fae3551SRodney W. Grimes "Found ep fs=0x%x,0x%x\n", 7648fae3551SRodney W. Grimes fsb.f_fsid.val[0], 7658fae3551SRodney W. Grimes fsb.f_fsid.val[1]); 7668fae3551SRodney W. Grimes } 7678fae3551SRodney W. Grimes 7688fae3551SRodney W. Grimes /* 7698fae3551SRodney W. Grimes * Add dirpath to export mount point. 7708fae3551SRodney W. Grimes */ 7718fae3551SRodney W. Grimes dirp = add_expdir(&dirhead, cp, len); 7728fae3551SRodney W. Grimes dirplen = len; 7738fae3551SRodney W. Grimes } else { 7748fae3551SRodney W. Grimes getexp_err(ep, tgrp); 7758fae3551SRodney W. Grimes goto nextline; 7768fae3551SRodney W. Grimes } 7778fae3551SRodney W. Grimes *endcp = savedc; 7788fae3551SRodney W. Grimes } else { 7798fae3551SRodney W. Grimes savedc = *endcp; 7808fae3551SRodney W. Grimes *endcp = '\0'; 7818fae3551SRodney W. Grimes got_nondir = 1; 7828fae3551SRodney W. Grimes if (ep == (struct exportlist *)NULL) { 7838fae3551SRodney W. Grimes getexp_err(ep, tgrp); 7848fae3551SRodney W. Grimes goto nextline; 7858fae3551SRodney W. Grimes } 7868fae3551SRodney W. Grimes 7878fae3551SRodney W. Grimes /* 7888fae3551SRodney W. Grimes * Get the host or netgroup. 7898fae3551SRodney W. Grimes */ 7908fae3551SRodney W. Grimes setnetgrent(cp); 7918fae3551SRodney W. Grimes netgrp = getnetgrent(&hst, &usr, &dom); 7928fae3551SRodney W. Grimes do { 7938fae3551SRodney W. Grimes if (has_host) { 7948fae3551SRodney W. Grimes grp->gr_next = get_grp(); 7958fae3551SRodney W. Grimes grp = grp->gr_next; 7968fae3551SRodney W. Grimes } 7978fae3551SRodney W. Grimes if (netgrp) { 7988fae3551SRodney W. Grimes if (get_host(hst, grp)) { 7998fae3551SRodney W. Grimes syslog(LOG_ERR, "Bad netgroup %s", cp); 8008fae3551SRodney W. Grimes getexp_err(ep, tgrp); 8018fae3551SRodney W. Grimes goto nextline; 8028fae3551SRodney W. Grimes } 8038fae3551SRodney W. Grimes } else if (get_host(cp, grp)) { 8048fae3551SRodney W. Grimes getexp_err(ep, tgrp); 8058fae3551SRodney W. Grimes goto nextline; 8068fae3551SRodney W. Grimes } 8078fae3551SRodney W. Grimes has_host = TRUE; 8088fae3551SRodney W. Grimes } while (netgrp && getnetgrent(&hst, &usr, &dom)); 8098fae3551SRodney W. Grimes endnetgrent(); 8108fae3551SRodney W. Grimes *endcp = savedc; 8118fae3551SRodney W. Grimes } 8128fae3551SRodney W. Grimes cp = endcp; 8138fae3551SRodney W. Grimes nextfield(&cp, &endcp); 8148fae3551SRodney W. Grimes len = endcp - cp; 8158fae3551SRodney W. Grimes } 8168fae3551SRodney W. Grimes if (check_options(dirhead)) { 8178fae3551SRodney W. Grimes getexp_err(ep, tgrp); 8188fae3551SRodney W. Grimes goto nextline; 8198fae3551SRodney W. Grimes } 8208fae3551SRodney W. Grimes if (!has_host) { 8218fae3551SRodney W. Grimes grp->gr_type = GT_HOST; 8228fae3551SRodney W. Grimes if (debug) 8238fae3551SRodney W. Grimes fprintf(stderr,"Adding a default entry\n"); 8248fae3551SRodney W. Grimes /* add a default group and make the grp list NULL */ 8258fae3551SRodney W. Grimes hpe = (struct hostent *)malloc(sizeof(struct hostent)); 8268fae3551SRodney W. Grimes if (hpe == (struct hostent *)NULL) 8278fae3551SRodney W. Grimes out_of_mem(); 8288fae3551SRodney W. Grimes hpe->h_name = "Default"; 8298fae3551SRodney W. Grimes hpe->h_addrtype = AF_INET; 8308fae3551SRodney W. Grimes hpe->h_length = sizeof (u_long); 8318fae3551SRodney W. Grimes hpe->h_addr_list = (char **)NULL; 8328fae3551SRodney W. Grimes grp->gr_ptr.gt_hostent = hpe; 8338fae3551SRodney W. Grimes 8348fae3551SRodney W. Grimes /* 8358fae3551SRodney W. Grimes * Don't allow a network export coincide with a list of 8368fae3551SRodney W. Grimes * host(s) on the same line. 8378fae3551SRodney W. Grimes */ 8388fae3551SRodney W. Grimes } else if ((opt_flags & OP_NET) && tgrp->gr_next) { 8398fae3551SRodney W. Grimes getexp_err(ep, tgrp); 8408fae3551SRodney W. Grimes goto nextline; 8418fae3551SRodney W. Grimes } 8428fae3551SRodney W. Grimes 8438fae3551SRodney W. Grimes /* 8448fae3551SRodney W. Grimes * Loop through hosts, pushing the exports into the kernel. 8458fae3551SRodney W. Grimes * After loop, tgrp points to the start of the list and 8468fae3551SRodney W. Grimes * grp points to the last entry in the list. 8478fae3551SRodney W. Grimes */ 8488fae3551SRodney W. Grimes grp = tgrp; 8498fae3551SRodney W. Grimes do { 8508fae3551SRodney W. Grimes if (do_mount(ep, grp, exflags, &anon, dirp, 8518fae3551SRodney W. Grimes dirplen, &fsb)) { 8528fae3551SRodney W. Grimes getexp_err(ep, tgrp); 8538fae3551SRodney W. Grimes goto nextline; 8548fae3551SRodney W. Grimes } 8558fae3551SRodney W. Grimes } while (grp->gr_next && (grp = grp->gr_next)); 8568fae3551SRodney W. Grimes 8578fae3551SRodney W. Grimes /* 8588fae3551SRodney W. Grimes * Success. Update the data structures. 8598fae3551SRodney W. Grimes */ 8608fae3551SRodney W. Grimes if (has_host) { 8618fae3551SRodney W. Grimes hang_dirp(dirhead, tgrp, ep, (opt_flags & OP_ALLDIRS)); 8628fae3551SRodney W. Grimes grp->gr_next = grphead; 8638fae3551SRodney W. Grimes grphead = tgrp; 8648fae3551SRodney W. Grimes } else { 8658fae3551SRodney W. Grimes hang_dirp(dirhead, (struct grouplist *)NULL, ep, 8668fae3551SRodney W. Grimes (opt_flags & OP_ALLDIRS)); 8678fae3551SRodney W. Grimes free_grp(grp); 8688fae3551SRodney W. Grimes } 8698fae3551SRodney W. Grimes dirhead = (struct dirlist *)NULL; 8708fae3551SRodney W. Grimes if ((ep->ex_flag & EX_LINKED) == 0) { 8718fae3551SRodney W. Grimes ep2 = exphead; 8728fae3551SRodney W. Grimes epp = &exphead; 8738fae3551SRodney W. Grimes 8748fae3551SRodney W. Grimes /* 8758fae3551SRodney W. Grimes * Insert in the list in alphabetical order. 8768fae3551SRodney W. Grimes */ 8778fae3551SRodney W. Grimes while (ep2 && strcmp(ep2->ex_fsdir, ep->ex_fsdir) < 0) { 8788fae3551SRodney W. Grimes epp = &ep2->ex_next; 8798fae3551SRodney W. Grimes ep2 = ep2->ex_next; 8808fae3551SRodney W. Grimes } 8818fae3551SRodney W. Grimes if (ep2) 8828fae3551SRodney W. Grimes ep->ex_next = ep2; 8838fae3551SRodney W. Grimes *epp = ep; 8848fae3551SRodney W. Grimes ep->ex_flag |= EX_LINKED; 8858fae3551SRodney W. Grimes } 8868fae3551SRodney W. Grimes nextline: 8878fae3551SRodney W. Grimes if (dirhead) { 8888fae3551SRodney W. Grimes free_dir(dirhead); 8898fae3551SRodney W. Grimes dirhead = (struct dirlist *)NULL; 8908fae3551SRodney W. Grimes } 8918fae3551SRodney W. Grimes } 8928fae3551SRodney W. Grimes fclose(exp_file); 8938fae3551SRodney W. Grimes } 8948fae3551SRodney W. Grimes 8958fae3551SRodney W. Grimes /* 8968fae3551SRodney W. Grimes * Allocate an export list element 8978fae3551SRodney W. Grimes */ 8988fae3551SRodney W. Grimes struct exportlist * 8998fae3551SRodney W. Grimes get_exp() 9008fae3551SRodney W. Grimes { 9018fae3551SRodney W. Grimes struct exportlist *ep; 9028fae3551SRodney W. Grimes 9038fae3551SRodney W. Grimes ep = (struct exportlist *)malloc(sizeof (struct exportlist)); 9048fae3551SRodney W. Grimes if (ep == (struct exportlist *)NULL) 9058fae3551SRodney W. Grimes out_of_mem(); 9068fae3551SRodney W. Grimes bzero((caddr_t)ep, sizeof (struct exportlist)); 9078fae3551SRodney W. Grimes return (ep); 9088fae3551SRodney W. Grimes } 9098fae3551SRodney W. Grimes 9108fae3551SRodney W. Grimes /* 9118fae3551SRodney W. Grimes * Allocate a group list element 9128fae3551SRodney W. Grimes */ 9138fae3551SRodney W. Grimes struct grouplist * 9148fae3551SRodney W. Grimes get_grp() 9158fae3551SRodney W. Grimes { 9168fae3551SRodney W. Grimes struct grouplist *gp; 9178fae3551SRodney W. Grimes 9188fae3551SRodney W. Grimes gp = (struct grouplist *)malloc(sizeof (struct grouplist)); 9198fae3551SRodney W. Grimes if (gp == (struct grouplist *)NULL) 9208fae3551SRodney W. Grimes out_of_mem(); 9218fae3551SRodney W. Grimes bzero((caddr_t)gp, sizeof (struct grouplist)); 9228fae3551SRodney W. Grimes return (gp); 9238fae3551SRodney W. Grimes } 9248fae3551SRodney W. Grimes 9258fae3551SRodney W. Grimes /* 9268fae3551SRodney W. Grimes * Clean up upon an error in get_exportlist(). 9278fae3551SRodney W. Grimes */ 9288fae3551SRodney W. Grimes void 9298fae3551SRodney W. Grimes getexp_err(ep, grp) 9308fae3551SRodney W. Grimes struct exportlist *ep; 9318fae3551SRodney W. Grimes struct grouplist *grp; 9328fae3551SRodney W. Grimes { 9338fae3551SRodney W. Grimes struct grouplist *tgrp; 9348fae3551SRodney W. Grimes 9358fae3551SRodney W. Grimes syslog(LOG_ERR, "Bad exports list line %s", line); 9368fae3551SRodney W. Grimes if (ep && (ep->ex_flag & EX_LINKED) == 0) 9378fae3551SRodney W. Grimes free_exp(ep); 9388fae3551SRodney W. Grimes while (grp) { 9398fae3551SRodney W. Grimes tgrp = grp; 9408fae3551SRodney W. Grimes grp = grp->gr_next; 9418fae3551SRodney W. Grimes free_grp(tgrp); 9428fae3551SRodney W. Grimes } 9438fae3551SRodney W. Grimes } 9448fae3551SRodney W. Grimes 9458fae3551SRodney W. Grimes /* 9468fae3551SRodney W. Grimes * Search the export list for a matching fs. 9478fae3551SRodney W. Grimes */ 9488fae3551SRodney W. Grimes struct exportlist * 9498fae3551SRodney W. Grimes ex_search(fsid) 9508fae3551SRodney W. Grimes fsid_t *fsid; 9518fae3551SRodney W. Grimes { 9528fae3551SRodney W. Grimes struct exportlist *ep; 9538fae3551SRodney W. Grimes 9548fae3551SRodney W. Grimes ep = exphead; 9558fae3551SRodney W. Grimes while (ep) { 9568fae3551SRodney W. Grimes if (ep->ex_fs.val[0] == fsid->val[0] && 9578fae3551SRodney W. Grimes ep->ex_fs.val[1] == fsid->val[1]) 9588fae3551SRodney W. Grimes return (ep); 9598fae3551SRodney W. Grimes ep = ep->ex_next; 9608fae3551SRodney W. Grimes } 9618fae3551SRodney W. Grimes return (ep); 9628fae3551SRodney W. Grimes } 9638fae3551SRodney W. Grimes 9648fae3551SRodney W. Grimes /* 9658fae3551SRodney W. Grimes * Add a directory path to the list. 9668fae3551SRodney W. Grimes */ 9678fae3551SRodney W. Grimes char * 9688fae3551SRodney W. Grimes add_expdir(dpp, cp, len) 9698fae3551SRodney W. Grimes struct dirlist **dpp; 9708fae3551SRodney W. Grimes char *cp; 9718fae3551SRodney W. Grimes int len; 9728fae3551SRodney W. Grimes { 9738fae3551SRodney W. Grimes struct dirlist *dp; 9748fae3551SRodney W. Grimes 9758fae3551SRodney W. Grimes dp = (struct dirlist *)malloc(sizeof (struct dirlist) + len); 9768fae3551SRodney W. Grimes dp->dp_left = *dpp; 9778fae3551SRodney W. Grimes dp->dp_right = (struct dirlist *)NULL; 9788fae3551SRodney W. Grimes dp->dp_flag = 0; 9798fae3551SRodney W. Grimes dp->dp_hosts = (struct hostlist *)NULL; 9808fae3551SRodney W. Grimes strcpy(dp->dp_dirp, cp); 9818fae3551SRodney W. Grimes *dpp = dp; 9828fae3551SRodney W. Grimes return (dp->dp_dirp); 9838fae3551SRodney W. Grimes } 9848fae3551SRodney W. Grimes 9858fae3551SRodney W. Grimes /* 9868fae3551SRodney W. Grimes * Hang the dir list element off the dirpath binary tree as required 9878fae3551SRodney W. Grimes * and update the entry for host. 9888fae3551SRodney W. Grimes */ 9898fae3551SRodney W. Grimes void 9908fae3551SRodney W. Grimes hang_dirp(dp, grp, ep, alldirs) 9918fae3551SRodney W. Grimes struct dirlist *dp; 9928fae3551SRodney W. Grimes struct grouplist *grp; 9938fae3551SRodney W. Grimes struct exportlist *ep; 9948fae3551SRodney W. Grimes int alldirs; 9958fae3551SRodney W. Grimes { 9968fae3551SRodney W. Grimes struct hostlist *hp; 9978fae3551SRodney W. Grimes struct dirlist *dp2; 9988fae3551SRodney W. Grimes 9998fae3551SRodney W. Grimes if (alldirs) { 10008fae3551SRodney W. Grimes if (ep->ex_defdir) 10018fae3551SRodney W. Grimes free((caddr_t)dp); 10028fae3551SRodney W. Grimes else 10038fae3551SRodney W. Grimes ep->ex_defdir = dp; 10048fae3551SRodney W. Grimes if (grp == (struct grouplist *)NULL) 10058fae3551SRodney W. Grimes ep->ex_defdir->dp_flag |= DP_DEFSET; 10068fae3551SRodney W. Grimes else while (grp) { 10078fae3551SRodney W. Grimes hp = get_ht(); 10088fae3551SRodney W. Grimes hp->ht_grp = grp; 10098fae3551SRodney W. Grimes hp->ht_next = ep->ex_defdir->dp_hosts; 10108fae3551SRodney W. Grimes ep->ex_defdir->dp_hosts = hp; 10118fae3551SRodney W. Grimes grp = grp->gr_next; 10128fae3551SRodney W. Grimes } 10138fae3551SRodney W. Grimes } else { 10148fae3551SRodney W. Grimes 10158fae3551SRodney W. Grimes /* 10168fae3551SRodney W. Grimes * Loop throught the directories adding them to the tree. 10178fae3551SRodney W. Grimes */ 10188fae3551SRodney W. Grimes while (dp) { 10198fae3551SRodney W. Grimes dp2 = dp->dp_left; 10208fae3551SRodney W. Grimes add_dlist(&ep->ex_dirl, dp, grp); 10218fae3551SRodney W. Grimes dp = dp2; 10228fae3551SRodney W. Grimes } 10238fae3551SRodney W. Grimes } 10248fae3551SRodney W. Grimes } 10258fae3551SRodney W. Grimes 10268fae3551SRodney W. Grimes /* 10278fae3551SRodney W. Grimes * Traverse the binary tree either updating a node that is already there 10288fae3551SRodney W. Grimes * for the new directory or adding the new node. 10298fae3551SRodney W. Grimes */ 10308fae3551SRodney W. Grimes void 10318fae3551SRodney W. Grimes add_dlist(dpp, newdp, grp) 10328fae3551SRodney W. Grimes struct dirlist **dpp; 10338fae3551SRodney W. Grimes struct dirlist *newdp; 10348fae3551SRodney W. Grimes struct grouplist *grp; 10358fae3551SRodney W. Grimes { 10368fae3551SRodney W. Grimes struct dirlist *dp; 10378fae3551SRodney W. Grimes struct hostlist *hp; 10388fae3551SRodney W. Grimes int cmp; 10398fae3551SRodney W. Grimes 10408fae3551SRodney W. Grimes dp = *dpp; 10418fae3551SRodney W. Grimes if (dp) { 10428fae3551SRodney W. Grimes cmp = strcmp(dp->dp_dirp, newdp->dp_dirp); 10438fae3551SRodney W. Grimes if (cmp > 0) { 10448fae3551SRodney W. Grimes add_dlist(&dp->dp_left, newdp, grp); 10458fae3551SRodney W. Grimes return; 10468fae3551SRodney W. Grimes } else if (cmp < 0) { 10478fae3551SRodney W. Grimes add_dlist(&dp->dp_right, newdp, grp); 10488fae3551SRodney W. Grimes return; 10498fae3551SRodney W. Grimes } else 10508fae3551SRodney W. Grimes free((caddr_t)newdp); 10518fae3551SRodney W. Grimes } else { 10528fae3551SRodney W. Grimes dp = newdp; 10538fae3551SRodney W. Grimes dp->dp_left = (struct dirlist *)NULL; 10548fae3551SRodney W. Grimes *dpp = dp; 10558fae3551SRodney W. Grimes } 10568fae3551SRodney W. Grimes if (grp) { 10578fae3551SRodney W. Grimes 10588fae3551SRodney W. Grimes /* 10598fae3551SRodney W. Grimes * Hang all of the host(s) off of the directory point. 10608fae3551SRodney W. Grimes */ 10618fae3551SRodney W. Grimes do { 10628fae3551SRodney W. Grimes hp = get_ht(); 10638fae3551SRodney W. Grimes hp->ht_grp = grp; 10648fae3551SRodney W. Grimes hp->ht_next = dp->dp_hosts; 10658fae3551SRodney W. Grimes dp->dp_hosts = hp; 10668fae3551SRodney W. Grimes grp = grp->gr_next; 10678fae3551SRodney W. Grimes } while (grp); 10688fae3551SRodney W. Grimes } else 10698fae3551SRodney W. Grimes dp->dp_flag |= DP_DEFSET; 10708fae3551SRodney W. Grimes } 10718fae3551SRodney W. Grimes 10728fae3551SRodney W. Grimes /* 10738fae3551SRodney W. Grimes * Search for a dirpath on the export point. 10748fae3551SRodney W. Grimes */ 10758fae3551SRodney W. Grimes struct dirlist * 10768fae3551SRodney W. Grimes dirp_search(dp, dirpath) 10778fae3551SRodney W. Grimes struct dirlist *dp; 10788fae3551SRodney W. Grimes char *dirpath; 10798fae3551SRodney W. Grimes { 10808fae3551SRodney W. Grimes int cmp; 10818fae3551SRodney W. Grimes 10828fae3551SRodney W. Grimes if (dp) { 10838fae3551SRodney W. Grimes cmp = strcmp(dp->dp_dirp, dirpath); 10848fae3551SRodney W. Grimes if (cmp > 0) 10858fae3551SRodney W. Grimes return (dirp_search(dp->dp_left, dirpath)); 10868fae3551SRodney W. Grimes else if (cmp < 0) 10878fae3551SRodney W. Grimes return (dirp_search(dp->dp_right, dirpath)); 10888fae3551SRodney W. Grimes else 10898fae3551SRodney W. Grimes return (dp); 10908fae3551SRodney W. Grimes } 10918fae3551SRodney W. Grimes return (dp); 10928fae3551SRodney W. Grimes } 10938fae3551SRodney W. Grimes 10948fae3551SRodney W. Grimes /* 10958fae3551SRodney W. Grimes * Scan for a host match in a directory tree. 10968fae3551SRodney W. Grimes */ 10978fae3551SRodney W. Grimes int 10988fae3551SRodney W. Grimes chk_host(dp, saddr, defsetp) 10998fae3551SRodney W. Grimes struct dirlist *dp; 11008fae3551SRodney W. Grimes u_long saddr; 11018fae3551SRodney W. Grimes int *defsetp; 11028fae3551SRodney W. Grimes { 11038fae3551SRodney W. Grimes struct hostlist *hp; 11048fae3551SRodney W. Grimes struct grouplist *grp; 11058fae3551SRodney W. Grimes u_long **addrp; 11068fae3551SRodney W. Grimes 11078fae3551SRodney W. Grimes if (dp) { 11088fae3551SRodney W. Grimes if (dp->dp_flag & DP_DEFSET) 11098fae3551SRodney W. Grimes *defsetp = 1; 11108fae3551SRodney W. Grimes hp = dp->dp_hosts; 11118fae3551SRodney W. Grimes while (hp) { 11128fae3551SRodney W. Grimes grp = hp->ht_grp; 11138fae3551SRodney W. Grimes switch (grp->gr_type) { 11148fae3551SRodney W. Grimes case GT_HOST: 11158fae3551SRodney W. Grimes addrp = (u_long **) 11168fae3551SRodney W. Grimes grp->gr_ptr.gt_hostent->h_addr_list; 11178fae3551SRodney W. Grimes while (*addrp) { 11188fae3551SRodney W. Grimes if (**addrp == saddr) 11198fae3551SRodney W. Grimes return (1); 11208fae3551SRodney W. Grimes addrp++; 11218fae3551SRodney W. Grimes } 11228fae3551SRodney W. Grimes break; 11238fae3551SRodney W. Grimes case GT_NET: 11248fae3551SRodney W. Grimes if ((saddr & grp->gr_ptr.gt_net.nt_mask) == 11258fae3551SRodney W. Grimes grp->gr_ptr.gt_net.nt_net) 11268fae3551SRodney W. Grimes return (1); 11278fae3551SRodney W. Grimes break; 11288fae3551SRodney W. Grimes }; 11298fae3551SRodney W. Grimes hp = hp->ht_next; 11308fae3551SRodney W. Grimes } 11318fae3551SRodney W. Grimes } 11328fae3551SRodney W. Grimes return (0); 11338fae3551SRodney W. Grimes } 11348fae3551SRodney W. Grimes 11358fae3551SRodney W. Grimes /* 11368fae3551SRodney W. Grimes * Scan tree for a host that matches the address. 11378fae3551SRodney W. Grimes */ 11388fae3551SRodney W. Grimes int 11398fae3551SRodney W. Grimes scan_tree(dp, saddr) 11408fae3551SRodney W. Grimes struct dirlist *dp; 11418fae3551SRodney W. Grimes u_long saddr; 11428fae3551SRodney W. Grimes { 11438fae3551SRodney W. Grimes int defset; 11448fae3551SRodney W. Grimes 11458fae3551SRodney W. Grimes if (dp) { 11468fae3551SRodney W. Grimes if (scan_tree(dp->dp_left, saddr)) 11478fae3551SRodney W. Grimes return (1); 11488fae3551SRodney W. Grimes if (chk_host(dp, saddr, &defset)) 11498fae3551SRodney W. Grimes return (1); 11508fae3551SRodney W. Grimes if (scan_tree(dp->dp_right, saddr)) 11518fae3551SRodney W. Grimes return (1); 11528fae3551SRodney W. Grimes } 11538fae3551SRodney W. Grimes return (0); 11548fae3551SRodney W. Grimes } 11558fae3551SRodney W. Grimes 11568fae3551SRodney W. Grimes /* 11578fae3551SRodney W. Grimes * Traverse the dirlist tree and free it up. 11588fae3551SRodney W. Grimes */ 11598fae3551SRodney W. Grimes void 11608fae3551SRodney W. Grimes free_dir(dp) 11618fae3551SRodney W. Grimes struct dirlist *dp; 11628fae3551SRodney W. Grimes { 11638fae3551SRodney W. Grimes 11648fae3551SRodney W. Grimes if (dp) { 11658fae3551SRodney W. Grimes free_dir(dp->dp_left); 11668fae3551SRodney W. Grimes free_dir(dp->dp_right); 11678fae3551SRodney W. Grimes free_host(dp->dp_hosts); 11688fae3551SRodney W. Grimes free((caddr_t)dp); 11698fae3551SRodney W. Grimes } 11708fae3551SRodney W. Grimes } 11718fae3551SRodney W. Grimes 11728fae3551SRodney W. Grimes /* 11738fae3551SRodney W. Grimes * Parse the option string and update fields. 11748fae3551SRodney W. Grimes * Option arguments may either be -<option>=<value> or 11758fae3551SRodney W. Grimes * -<option> <value> 11768fae3551SRodney W. Grimes */ 11778fae3551SRodney W. Grimes int 11788fae3551SRodney W. Grimes do_opt(cpp, endcpp, ep, grp, has_hostp, exflagsp, cr) 11798fae3551SRodney W. Grimes char **cpp, **endcpp; 11808fae3551SRodney W. Grimes struct exportlist *ep; 11818fae3551SRodney W. Grimes struct grouplist *grp; 11828fae3551SRodney W. Grimes int *has_hostp; 11838fae3551SRodney W. Grimes int *exflagsp; 11848fae3551SRodney W. Grimes struct ucred *cr; 11858fae3551SRodney W. Grimes { 11868fae3551SRodney W. Grimes char *cpoptarg, *cpoptend; 11878fae3551SRodney W. Grimes char *cp, *endcp, *cpopt, savedc, savedc2; 11888fae3551SRodney W. Grimes int allflag, usedarg; 11898fae3551SRodney W. Grimes 11908fae3551SRodney W. Grimes cpopt = *cpp; 11918fae3551SRodney W. Grimes cpopt++; 11928fae3551SRodney W. Grimes cp = *endcpp; 11938fae3551SRodney W. Grimes savedc = *cp; 11948fae3551SRodney W. Grimes *cp = '\0'; 11958fae3551SRodney W. Grimes while (cpopt && *cpopt) { 11968fae3551SRodney W. Grimes allflag = 1; 11978fae3551SRodney W. Grimes usedarg = -2; 11988fae3551SRodney W. Grimes if (cpoptend = index(cpopt, ',')) { 11998fae3551SRodney W. Grimes *cpoptend++ = '\0'; 12008fae3551SRodney W. Grimes if (cpoptarg = index(cpopt, '=')) 12018fae3551SRodney W. Grimes *cpoptarg++ = '\0'; 12028fae3551SRodney W. Grimes } else { 12038fae3551SRodney W. Grimes if (cpoptarg = index(cpopt, '=')) 12048fae3551SRodney W. Grimes *cpoptarg++ = '\0'; 12058fae3551SRodney W. Grimes else { 12068fae3551SRodney W. Grimes *cp = savedc; 12078fae3551SRodney W. Grimes nextfield(&cp, &endcp); 12088fae3551SRodney W. Grimes **endcpp = '\0'; 12098fae3551SRodney W. Grimes if (endcp > cp && *cp != '-') { 12108fae3551SRodney W. Grimes cpoptarg = cp; 12118fae3551SRodney W. Grimes savedc2 = *endcp; 12128fae3551SRodney W. Grimes *endcp = '\0'; 12138fae3551SRodney W. Grimes usedarg = 0; 12148fae3551SRodney W. Grimes } 12158fae3551SRodney W. Grimes } 12168fae3551SRodney W. Grimes } 12178fae3551SRodney W. Grimes if (!strcmp(cpopt, "ro") || !strcmp(cpopt, "o")) { 12188fae3551SRodney W. Grimes *exflagsp |= MNT_EXRDONLY; 12198fae3551SRodney W. Grimes } else if (cpoptarg && (!strcmp(cpopt, "maproot") || 12208fae3551SRodney W. Grimes !(allflag = strcmp(cpopt, "mapall")) || 12218fae3551SRodney W. Grimes !strcmp(cpopt, "root") || !strcmp(cpopt, "r"))) { 12228fae3551SRodney W. Grimes usedarg++; 12238fae3551SRodney W. Grimes parsecred(cpoptarg, cr); 12248fae3551SRodney W. Grimes if (allflag == 0) { 12258fae3551SRodney W. Grimes *exflagsp |= MNT_EXPORTANON; 12268fae3551SRodney W. Grimes opt_flags |= OP_MAPALL; 12278fae3551SRodney W. Grimes } else 12288fae3551SRodney W. Grimes opt_flags |= OP_MAPROOT; 12298fae3551SRodney W. Grimes } else if (!strcmp(cpopt, "kerb") || !strcmp(cpopt, "k")) { 12308fae3551SRodney W. Grimes *exflagsp |= MNT_EXKERB; 12318fae3551SRodney W. Grimes opt_flags |= OP_KERB; 12328fae3551SRodney W. Grimes } else if (cpoptarg && (!strcmp(cpopt, "mask") || 12338fae3551SRodney W. Grimes !strcmp(cpopt, "m"))) { 12348fae3551SRodney W. Grimes if (get_net(cpoptarg, &grp->gr_ptr.gt_net, 1)) { 12358fae3551SRodney W. Grimes syslog(LOG_ERR, "Bad mask: %s", cpoptarg); 12368fae3551SRodney W. Grimes return (1); 12378fae3551SRodney W. Grimes } 12388fae3551SRodney W. Grimes usedarg++; 12398fae3551SRodney W. Grimes opt_flags |= OP_MASK; 12408fae3551SRodney W. Grimes } else if (cpoptarg && (!strcmp(cpopt, "network") || 12418fae3551SRodney W. Grimes !strcmp(cpopt, "n"))) { 12428fae3551SRodney W. Grimes if (grp->gr_type != GT_NULL) { 12438fae3551SRodney W. Grimes syslog(LOG_ERR, "Network/host conflict"); 12448fae3551SRodney W. Grimes return (1); 12458fae3551SRodney W. Grimes } else if (get_net(cpoptarg, &grp->gr_ptr.gt_net, 0)) { 12468fae3551SRodney W. Grimes syslog(LOG_ERR, "Bad net: %s", cpoptarg); 12478fae3551SRodney W. Grimes return (1); 12488fae3551SRodney W. Grimes } 12498fae3551SRodney W. Grimes grp->gr_type = GT_NET; 12508fae3551SRodney W. Grimes *has_hostp = 1; 12518fae3551SRodney W. Grimes usedarg++; 12528fae3551SRodney W. Grimes opt_flags |= OP_NET; 12538fae3551SRodney W. Grimes } else if (!strcmp(cpopt, "alldirs")) { 12548fae3551SRodney W. Grimes opt_flags |= OP_ALLDIRS; 12558fae3551SRodney W. Grimes #ifdef ISO 12568fae3551SRodney W. Grimes } else if (cpoptarg && !strcmp(cpopt, "iso")) { 12578fae3551SRodney W. Grimes if (get_isoaddr(cpoptarg, grp)) { 12588fae3551SRodney W. Grimes syslog(LOG_ERR, "Bad iso addr: %s", cpoptarg); 12598fae3551SRodney W. Grimes return (1); 12608fae3551SRodney W. Grimes } 12618fae3551SRodney W. Grimes *has_hostp = 1; 12628fae3551SRodney W. Grimes usedarg++; 12638fae3551SRodney W. Grimes opt_flags |= OP_ISO; 12648fae3551SRodney W. Grimes #endif /* ISO */ 12658fae3551SRodney W. Grimes } else { 12668fae3551SRodney W. Grimes syslog(LOG_ERR, "Bad opt %s", cpopt); 12678fae3551SRodney W. Grimes return (1); 12688fae3551SRodney W. Grimes } 12698fae3551SRodney W. Grimes if (usedarg >= 0) { 12708fae3551SRodney W. Grimes *endcp = savedc2; 12718fae3551SRodney W. Grimes **endcpp = savedc; 12728fae3551SRodney W. Grimes if (usedarg > 0) { 12738fae3551SRodney W. Grimes *cpp = cp; 12748fae3551SRodney W. Grimes *endcpp = endcp; 12758fae3551SRodney W. Grimes } 12768fae3551SRodney W. Grimes return (0); 12778fae3551SRodney W. Grimes } 12788fae3551SRodney W. Grimes cpopt = cpoptend; 12798fae3551SRodney W. Grimes } 12808fae3551SRodney W. Grimes **endcpp = savedc; 12818fae3551SRodney W. Grimes return (0); 12828fae3551SRodney W. Grimes } 12838fae3551SRodney W. Grimes 12848fae3551SRodney W. Grimes /* 12858fae3551SRodney W. Grimes * Translate a character string to the corresponding list of network 12868fae3551SRodney W. Grimes * addresses for a hostname. 12878fae3551SRodney W. Grimes */ 12888fae3551SRodney W. Grimes int 12898fae3551SRodney W. Grimes get_host(cp, grp) 12908fae3551SRodney W. Grimes char *cp; 12918fae3551SRodney W. Grimes struct grouplist *grp; 12928fae3551SRodney W. Grimes { 12938fae3551SRodney W. Grimes struct hostent *hp, *nhp; 12948fae3551SRodney W. Grimes char **addrp, **naddrp; 12958fae3551SRodney W. Grimes struct hostent t_host; 12968fae3551SRodney W. Grimes int i; 12978fae3551SRodney W. Grimes u_long saddr; 12988fae3551SRodney W. Grimes char *aptr[2]; 12998fae3551SRodney W. Grimes 13008fae3551SRodney W. Grimes if (grp->gr_type != GT_NULL) 13018fae3551SRodney W. Grimes return (1); 13028fae3551SRodney W. Grimes if ((hp = gethostbyname(cp)) == NULL) { 13038fae3551SRodney W. Grimes if (isdigit(*cp)) { 13048fae3551SRodney W. Grimes saddr = inet_addr(cp); 13058fae3551SRodney W. Grimes if (saddr == -1) { 13068fae3551SRodney W. Grimes syslog(LOG_ERR, "Inet_addr failed"); 13078fae3551SRodney W. Grimes return (1); 13088fae3551SRodney W. Grimes } 13098fae3551SRodney W. Grimes if ((hp = gethostbyaddr((caddr_t)&saddr, sizeof (saddr), 13108fae3551SRodney W. Grimes AF_INET)) == NULL) { 13118fae3551SRodney W. Grimes hp = &t_host; 13128fae3551SRodney W. Grimes hp->h_name = cp; 13138fae3551SRodney W. Grimes hp->h_addrtype = AF_INET; 13148fae3551SRodney W. Grimes hp->h_length = sizeof (u_long); 13158fae3551SRodney W. Grimes hp->h_addr_list = aptr; 13168fae3551SRodney W. Grimes aptr[0] = (char *)&saddr; 13178fae3551SRodney W. Grimes aptr[1] = (char *)NULL; 13188fae3551SRodney W. Grimes } 13198fae3551SRodney W. Grimes } else { 13208fae3551SRodney W. Grimes syslog(LOG_ERR, "Gethostbyname failed"); 13218fae3551SRodney W. Grimes return (1); 13228fae3551SRodney W. Grimes } 13238fae3551SRodney W. Grimes } 13248fae3551SRodney W. Grimes grp->gr_type = GT_HOST; 13258fae3551SRodney W. Grimes nhp = grp->gr_ptr.gt_hostent = (struct hostent *) 13268fae3551SRodney W. Grimes malloc(sizeof(struct hostent)); 13278fae3551SRodney W. Grimes if (nhp == (struct hostent *)NULL) 13288fae3551SRodney W. Grimes out_of_mem(); 13298fae3551SRodney W. Grimes bcopy((caddr_t)hp, (caddr_t)nhp, 13308fae3551SRodney W. Grimes sizeof(struct hostent)); 13318fae3551SRodney W. Grimes i = strlen(hp->h_name)+1; 13328fae3551SRodney W. Grimes nhp->h_name = (char *)malloc(i); 13338fae3551SRodney W. Grimes if (nhp->h_name == (char *)NULL) 13348fae3551SRodney W. Grimes out_of_mem(); 13358fae3551SRodney W. Grimes bcopy(hp->h_name, nhp->h_name, i); 13368fae3551SRodney W. Grimes addrp = hp->h_addr_list; 13378fae3551SRodney W. Grimes i = 1; 13388fae3551SRodney W. Grimes while (*addrp++) 13398fae3551SRodney W. Grimes i++; 13408fae3551SRodney W. Grimes naddrp = nhp->h_addr_list = (char **) 13418fae3551SRodney W. Grimes malloc(i*sizeof(char *)); 13428fae3551SRodney W. Grimes if (naddrp == (char **)NULL) 13438fae3551SRodney W. Grimes out_of_mem(); 13448fae3551SRodney W. Grimes addrp = hp->h_addr_list; 13458fae3551SRodney W. Grimes while (*addrp) { 13468fae3551SRodney W. Grimes *naddrp = (char *) 13478fae3551SRodney W. Grimes malloc(hp->h_length); 13488fae3551SRodney W. Grimes if (*naddrp == (char *)NULL) 13498fae3551SRodney W. Grimes out_of_mem(); 13508fae3551SRodney W. Grimes bcopy(*addrp, *naddrp, 13518fae3551SRodney W. Grimes hp->h_length); 13528fae3551SRodney W. Grimes addrp++; 13538fae3551SRodney W. Grimes naddrp++; 13548fae3551SRodney W. Grimes } 13558fae3551SRodney W. Grimes *naddrp = (char *)NULL; 13568fae3551SRodney W. Grimes if (debug) 13578fae3551SRodney W. Grimes fprintf(stderr, "got host %s\n", hp->h_name); 13588fae3551SRodney W. Grimes return (0); 13598fae3551SRodney W. Grimes } 13608fae3551SRodney W. Grimes 13618fae3551SRodney W. Grimes /* 13628fae3551SRodney W. Grimes * Free up an exports list component 13638fae3551SRodney W. Grimes */ 13648fae3551SRodney W. Grimes void 13658fae3551SRodney W. Grimes free_exp(ep) 13668fae3551SRodney W. Grimes struct exportlist *ep; 13678fae3551SRodney W. Grimes { 13688fae3551SRodney W. Grimes 13698fae3551SRodney W. Grimes if (ep->ex_defdir) { 13708fae3551SRodney W. Grimes free_host(ep->ex_defdir->dp_hosts); 13718fae3551SRodney W. Grimes free((caddr_t)ep->ex_defdir); 13728fae3551SRodney W. Grimes } 13738fae3551SRodney W. Grimes if (ep->ex_fsdir) 13748fae3551SRodney W. Grimes free(ep->ex_fsdir); 13758fae3551SRodney W. Grimes free_dir(ep->ex_dirl); 13768fae3551SRodney W. Grimes free((caddr_t)ep); 13778fae3551SRodney W. Grimes } 13788fae3551SRodney W. Grimes 13798fae3551SRodney W. Grimes /* 13808fae3551SRodney W. Grimes * Free hosts. 13818fae3551SRodney W. Grimes */ 13828fae3551SRodney W. Grimes void 13838fae3551SRodney W. Grimes free_host(hp) 13848fae3551SRodney W. Grimes struct hostlist *hp; 13858fae3551SRodney W. Grimes { 13868fae3551SRodney W. Grimes struct hostlist *hp2; 13878fae3551SRodney W. Grimes 13888fae3551SRodney W. Grimes while (hp) { 13898fae3551SRodney W. Grimes hp2 = hp; 13908fae3551SRodney W. Grimes hp = hp->ht_next; 13918fae3551SRodney W. Grimes free((caddr_t)hp2); 13928fae3551SRodney W. Grimes } 13938fae3551SRodney W. Grimes } 13948fae3551SRodney W. Grimes 13958fae3551SRodney W. Grimes struct hostlist * 13968fae3551SRodney W. Grimes get_ht() 13978fae3551SRodney W. Grimes { 13988fae3551SRodney W. Grimes struct hostlist *hp; 13998fae3551SRodney W. Grimes 14008fae3551SRodney W. Grimes hp = (struct hostlist *)malloc(sizeof (struct hostlist)); 14018fae3551SRodney W. Grimes if (hp == (struct hostlist *)NULL) 14028fae3551SRodney W. Grimes out_of_mem(); 14038fae3551SRodney W. Grimes hp->ht_next = (struct hostlist *)NULL; 14048fae3551SRodney W. Grimes return (hp); 14058fae3551SRodney W. Grimes } 14068fae3551SRodney W. Grimes 14078fae3551SRodney W. Grimes #ifdef ISO 14088fae3551SRodney W. Grimes /* 14098fae3551SRodney W. Grimes * Translate an iso address. 14108fae3551SRodney W. Grimes */ 14118fae3551SRodney W. Grimes get_isoaddr(cp, grp) 14128fae3551SRodney W. Grimes char *cp; 14138fae3551SRodney W. Grimes struct grouplist *grp; 14148fae3551SRodney W. Grimes { 14158fae3551SRodney W. Grimes struct iso_addr *isop; 14168fae3551SRodney W. Grimes struct sockaddr_iso *isoaddr; 14178fae3551SRodney W. Grimes 14188fae3551SRodney W. Grimes if (grp->gr_type != GT_NULL) 14198fae3551SRodney W. Grimes return (1); 14208fae3551SRodney W. Grimes if ((isop = iso_addr(cp)) == NULL) { 14218fae3551SRodney W. Grimes syslog(LOG_ERR, 14228fae3551SRodney W. Grimes "iso_addr failed, ignored"); 14238fae3551SRodney W. Grimes return (1); 14248fae3551SRodney W. Grimes } 14258fae3551SRodney W. Grimes isoaddr = (struct sockaddr_iso *) 14268fae3551SRodney W. Grimes malloc(sizeof (struct sockaddr_iso)); 14278fae3551SRodney W. Grimes if (isoaddr == (struct sockaddr_iso *)NULL) 14288fae3551SRodney W. Grimes out_of_mem(); 14298fae3551SRodney W. Grimes bzero((caddr_t)isoaddr, sizeof (struct sockaddr_iso)); 14308fae3551SRodney W. Grimes bcopy((caddr_t)isop, (caddr_t)&isoaddr->siso_addr, 14318fae3551SRodney W. Grimes sizeof (struct iso_addr)); 14328fae3551SRodney W. Grimes isoaddr->siso_len = sizeof (struct sockaddr_iso); 14338fae3551SRodney W. Grimes isoaddr->siso_family = AF_ISO; 14348fae3551SRodney W. Grimes grp->gr_type = GT_ISO; 14358fae3551SRodney W. Grimes grp->gr_ptr.gt_isoaddr = isoaddr; 14368fae3551SRodney W. Grimes return (0); 14378fae3551SRodney W. Grimes } 14388fae3551SRodney W. Grimes #endif /* ISO */ 14398fae3551SRodney W. Grimes 14408fae3551SRodney W. Grimes /* 14418fae3551SRodney W. Grimes * Out of memory, fatal 14428fae3551SRodney W. Grimes */ 14438fae3551SRodney W. Grimes void 14448fae3551SRodney W. Grimes out_of_mem() 14458fae3551SRodney W. Grimes { 14468fae3551SRodney W. Grimes 14478fae3551SRodney W. Grimes syslog(LOG_ERR, "Out of memory"); 14488fae3551SRodney W. Grimes exit(2); 14498fae3551SRodney W. Grimes } 14508fae3551SRodney W. Grimes 14518fae3551SRodney W. Grimes /* 14528fae3551SRodney W. Grimes * Do the mount syscall with the update flag to push the export info into 14538fae3551SRodney W. Grimes * the kernel. 14548fae3551SRodney W. Grimes */ 14558fae3551SRodney W. Grimes int 14568fae3551SRodney W. Grimes do_mount(ep, grp, exflags, anoncrp, dirp, dirplen, fsb) 14578fae3551SRodney W. Grimes struct exportlist *ep; 14588fae3551SRodney W. Grimes struct grouplist *grp; 14598fae3551SRodney W. Grimes int exflags; 14608fae3551SRodney W. Grimes struct ucred *anoncrp; 14618fae3551SRodney W. Grimes char *dirp; 14628fae3551SRodney W. Grimes int dirplen; 14638fae3551SRodney W. Grimes struct statfs *fsb; 14648fae3551SRodney W. Grimes { 14658fae3551SRodney W. Grimes char *cp = (char *)NULL; 14668fae3551SRodney W. Grimes u_long **addrp; 14678fae3551SRodney W. Grimes int done; 14688fae3551SRodney W. Grimes char savedc = '\0'; 14698fae3551SRodney W. Grimes struct sockaddr_in sin, imask; 14708fae3551SRodney W. Grimes union { 14718fae3551SRodney W. Grimes struct ufs_args ua; 14728fae3551SRodney W. Grimes struct iso_args ia; 14738fae3551SRodney W. Grimes struct mfs_args ma; 14748fae3551SRodney W. Grimes } args; 14758fae3551SRodney W. Grimes u_long net; 14768fae3551SRodney W. Grimes 14778fae3551SRodney W. Grimes args.ua.fspec = 0; 14788fae3551SRodney W. Grimes args.ua.export.ex_flags = exflags; 14798fae3551SRodney W. Grimes args.ua.export.ex_anon = *anoncrp; 14808fae3551SRodney W. Grimes bzero((char *)&sin, sizeof(sin)); 14818fae3551SRodney W. Grimes bzero((char *)&imask, sizeof(imask)); 14828fae3551SRodney W. Grimes sin.sin_family = AF_INET; 14838fae3551SRodney W. Grimes sin.sin_len = sizeof(sin); 14848fae3551SRodney W. Grimes imask.sin_family = AF_INET; 14858fae3551SRodney W. Grimes imask.sin_len = sizeof(sin); 14868fae3551SRodney W. Grimes if (grp->gr_type == GT_HOST) 14878fae3551SRodney W. Grimes addrp = (u_long **)grp->gr_ptr.gt_hostent->h_addr_list; 14888fae3551SRodney W. Grimes else 14898fae3551SRodney W. Grimes addrp = (u_long **)NULL; 14908fae3551SRodney W. Grimes done = FALSE; 14918fae3551SRodney W. Grimes while (!done) { 14928fae3551SRodney W. Grimes switch (grp->gr_type) { 14938fae3551SRodney W. Grimes case GT_HOST: 14948fae3551SRodney W. Grimes if (addrp) { 14958fae3551SRodney W. Grimes sin.sin_addr.s_addr = **addrp; 14968fae3551SRodney W. Grimes args.ua.export.ex_addrlen = sizeof(sin); 14978fae3551SRodney W. Grimes } else 14988fae3551SRodney W. Grimes args.ua.export.ex_addrlen = 0; 14998fae3551SRodney W. Grimes args.ua.export.ex_addr = (struct sockaddr *)&sin; 15008fae3551SRodney W. Grimes args.ua.export.ex_masklen = 0; 15018fae3551SRodney W. Grimes break; 15028fae3551SRodney W. Grimes case GT_NET: 15038fae3551SRodney W. Grimes if (grp->gr_ptr.gt_net.nt_mask) 15048fae3551SRodney W. Grimes imask.sin_addr.s_addr = grp->gr_ptr.gt_net.nt_mask; 15058fae3551SRodney W. Grimes else { 15068fae3551SRodney W. Grimes net = ntohl(grp->gr_ptr.gt_net.nt_net); 15078fae3551SRodney W. Grimes if (IN_CLASSA(net)) 15088fae3551SRodney W. Grimes imask.sin_addr.s_addr = inet_addr("255.0.0.0"); 15098fae3551SRodney W. Grimes else if (IN_CLASSB(net)) 15108fae3551SRodney W. Grimes imask.sin_addr.s_addr = 15118fae3551SRodney W. Grimes inet_addr("255.255.0.0"); 15128fae3551SRodney W. Grimes else 15138fae3551SRodney W. Grimes imask.sin_addr.s_addr = 15148fae3551SRodney W. Grimes inet_addr("255.255.255.0"); 15158fae3551SRodney W. Grimes grp->gr_ptr.gt_net.nt_mask = imask.sin_addr.s_addr; 15168fae3551SRodney W. Grimes } 15178fae3551SRodney W. Grimes sin.sin_addr.s_addr = grp->gr_ptr.gt_net.nt_net; 15188fae3551SRodney W. Grimes args.ua.export.ex_addr = (struct sockaddr *)&sin; 15198fae3551SRodney W. Grimes args.ua.export.ex_addrlen = sizeof (sin); 15208fae3551SRodney W. Grimes args.ua.export.ex_mask = (struct sockaddr *)&imask; 15218fae3551SRodney W. Grimes args.ua.export.ex_masklen = sizeof (imask); 15228fae3551SRodney W. Grimes break; 15238fae3551SRodney W. Grimes #ifdef ISO 15248fae3551SRodney W. Grimes case GT_ISO: 15258fae3551SRodney W. Grimes args.ua.export.ex_addr = 15268fae3551SRodney W. Grimes (struct sockaddr *)grp->gr_ptr.gt_isoaddr; 15278fae3551SRodney W. Grimes args.ua.export.ex_addrlen = 15288fae3551SRodney W. Grimes sizeof(struct sockaddr_iso); 15298fae3551SRodney W. Grimes args.ua.export.ex_masklen = 0; 15308fae3551SRodney W. Grimes break; 15318fae3551SRodney W. Grimes #endif /* ISO */ 15328fae3551SRodney W. Grimes default: 15338fae3551SRodney W. Grimes syslog(LOG_ERR, "Bad grouptype"); 15348fae3551SRodney W. Grimes if (cp) 15358fae3551SRodney W. Grimes *cp = savedc; 15368fae3551SRodney W. Grimes return (1); 15378fae3551SRodney W. Grimes }; 15388fae3551SRodney W. Grimes 15398fae3551SRodney W. Grimes /* 15408fae3551SRodney W. Grimes * XXX: 15418fae3551SRodney W. Grimes * Maybe I should just use the fsb->f_mntonname path instead 15428fae3551SRodney W. Grimes * of looping back up the dirp to the mount point?? 15438fae3551SRodney W. Grimes * Also, needs to know how to export all types of local 15448fae3551SRodney W. Grimes * exportable file systems and not just MOUNT_UFS. 15458fae3551SRodney W. Grimes */ 15468fae3551SRodney W. Grimes while (mount(fsb->f_type, dirp, 15478fae3551SRodney W. Grimes fsb->f_flags | MNT_UPDATE, (caddr_t)&args) < 0) { 15488fae3551SRodney W. Grimes if (cp) 15498fae3551SRodney W. Grimes *cp-- = savedc; 15508fae3551SRodney W. Grimes else 15518fae3551SRodney W. Grimes cp = dirp + dirplen - 1; 15528fae3551SRodney W. Grimes if (errno == EPERM) { 15538fae3551SRodney W. Grimes syslog(LOG_ERR, 15548fae3551SRodney W. Grimes "Can't change attributes for %s.\n", dirp); 15558fae3551SRodney W. Grimes return (1); 15568fae3551SRodney W. Grimes } 15578fae3551SRodney W. Grimes if (opt_flags & OP_ALLDIRS) { 15588fae3551SRodney W. Grimes syslog(LOG_ERR, "Not root dir"); 15598fae3551SRodney W. Grimes return (1); 15608fae3551SRodney W. Grimes } 15618fae3551SRodney W. Grimes /* back up over the last component */ 15628fae3551SRodney W. Grimes while (*cp == '/' && cp > dirp) 15638fae3551SRodney W. Grimes cp--; 15648fae3551SRodney W. Grimes while (*(cp - 1) != '/' && cp > dirp) 15658fae3551SRodney W. Grimes cp--; 15668fae3551SRodney W. Grimes if (cp == dirp) { 15678fae3551SRodney W. Grimes if (debug) 15688fae3551SRodney W. Grimes fprintf(stderr,"mnt unsucc\n"); 15698fae3551SRodney W. Grimes syslog(LOG_ERR, "Can't export %s", dirp); 15708fae3551SRodney W. Grimes return (1); 15718fae3551SRodney W. Grimes } 15728fae3551SRodney W. Grimes savedc = *cp; 15738fae3551SRodney W. Grimes *cp = '\0'; 15748fae3551SRodney W. Grimes } 15758fae3551SRodney W. Grimes if (addrp) { 15768fae3551SRodney W. Grimes ++addrp; 15778fae3551SRodney W. Grimes if (*addrp == (u_long *)NULL) 15788fae3551SRodney W. Grimes done = TRUE; 15798fae3551SRodney W. Grimes } else 15808fae3551SRodney W. Grimes done = TRUE; 15818fae3551SRodney W. Grimes } 15828fae3551SRodney W. Grimes if (cp) 15838fae3551SRodney W. Grimes *cp = savedc; 15848fae3551SRodney W. Grimes return (0); 15858fae3551SRodney W. Grimes } 15868fae3551SRodney W. Grimes 15878fae3551SRodney W. Grimes /* 15888fae3551SRodney W. Grimes * Translate a net address. 15898fae3551SRodney W. Grimes */ 15908fae3551SRodney W. Grimes int 15918fae3551SRodney W. Grimes get_net(cp, net, maskflg) 15928fae3551SRodney W. Grimes char *cp; 15938fae3551SRodney W. Grimes struct netmsk *net; 15948fae3551SRodney W. Grimes int maskflg; 15958fae3551SRodney W. Grimes { 15968fae3551SRodney W. Grimes struct netent *np; 15978fae3551SRodney W. Grimes long netaddr; 15988fae3551SRodney W. Grimes struct in_addr inetaddr, inetaddr2; 15998fae3551SRodney W. Grimes char *name; 16008fae3551SRodney W. Grimes 16018fae3551SRodney W. Grimes if (np = getnetbyname(cp)) 16028fae3551SRodney W. Grimes inetaddr = inet_makeaddr(np->n_net, 0); 16038fae3551SRodney W. Grimes else if (isdigit(*cp)) { 16048fae3551SRodney W. Grimes if ((netaddr = inet_network(cp)) == -1) 16058fae3551SRodney W. Grimes return (1); 16068fae3551SRodney W. Grimes inetaddr = inet_makeaddr(netaddr, 0); 16078fae3551SRodney W. Grimes /* 16088fae3551SRodney W. Grimes * Due to arbritrary subnet masks, you don't know how many 16098fae3551SRodney W. Grimes * bits to shift the address to make it into a network, 16108fae3551SRodney W. Grimes * however you do know how to make a network address into 16118fae3551SRodney W. Grimes * a host with host == 0 and then compare them. 16128fae3551SRodney W. Grimes * (What a pest) 16138fae3551SRodney W. Grimes */ 16148fae3551SRodney W. Grimes if (!maskflg) { 16158fae3551SRodney W. Grimes setnetent(0); 16168fae3551SRodney W. Grimes while (np = getnetent()) { 16178fae3551SRodney W. Grimes inetaddr2 = inet_makeaddr(np->n_net, 0); 16188fae3551SRodney W. Grimes if (inetaddr2.s_addr == inetaddr.s_addr) 16198fae3551SRodney W. Grimes break; 16208fae3551SRodney W. Grimes } 16218fae3551SRodney W. Grimes endnetent(); 16228fae3551SRodney W. Grimes } 16238fae3551SRodney W. Grimes } else 16248fae3551SRodney W. Grimes return (1); 16258fae3551SRodney W. Grimes if (maskflg) 16268fae3551SRodney W. Grimes net->nt_mask = inetaddr.s_addr; 16278fae3551SRodney W. Grimes else { 16288fae3551SRodney W. Grimes if (np) 16298fae3551SRodney W. Grimes name = np->n_name; 16308fae3551SRodney W. Grimes else 16318fae3551SRodney W. Grimes name = inet_ntoa(inetaddr); 16328fae3551SRodney W. Grimes net->nt_name = (char *)malloc(strlen(name) + 1); 16338fae3551SRodney W. Grimes if (net->nt_name == (char *)NULL) 16348fae3551SRodney W. Grimes out_of_mem(); 16358fae3551SRodney W. Grimes strcpy(net->nt_name, name); 16368fae3551SRodney W. Grimes net->nt_net = inetaddr.s_addr; 16378fae3551SRodney W. Grimes } 16388fae3551SRodney W. Grimes return (0); 16398fae3551SRodney W. Grimes } 16408fae3551SRodney W. Grimes 16418fae3551SRodney W. Grimes /* 16428fae3551SRodney W. Grimes * Parse out the next white space separated field 16438fae3551SRodney W. Grimes */ 16448fae3551SRodney W. Grimes void 16458fae3551SRodney W. Grimes nextfield(cp, endcp) 16468fae3551SRodney W. Grimes char **cp; 16478fae3551SRodney W. Grimes char **endcp; 16488fae3551SRodney W. Grimes { 16498fae3551SRodney W. Grimes char *p; 16508fae3551SRodney W. Grimes 16518fae3551SRodney W. Grimes p = *cp; 16528fae3551SRodney W. Grimes while (*p == ' ' || *p == '\t') 16538fae3551SRodney W. Grimes p++; 16548fae3551SRodney W. Grimes if (*p == '\n' || *p == '\0') 16558fae3551SRodney W. Grimes *cp = *endcp = p; 16568fae3551SRodney W. Grimes else { 16578fae3551SRodney W. Grimes *cp = p++; 16588fae3551SRodney W. Grimes while (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\0') 16598fae3551SRodney W. Grimes p++; 16608fae3551SRodney W. Grimes *endcp = p; 16618fae3551SRodney W. Grimes } 16628fae3551SRodney W. Grimes } 16638fae3551SRodney W. Grimes 16648fae3551SRodney W. Grimes /* 16658fae3551SRodney W. Grimes * Get an exports file line. Skip over blank lines and handle line 16668fae3551SRodney W. Grimes * continuations. 16678fae3551SRodney W. Grimes */ 16688fae3551SRodney W. Grimes int 16698fae3551SRodney W. Grimes get_line() 16708fae3551SRodney W. Grimes { 16718fae3551SRodney W. Grimes char *p, *cp; 16728fae3551SRodney W. Grimes int len; 16738fae3551SRodney W. Grimes int totlen, cont_line; 16748fae3551SRodney W. Grimes 16758fae3551SRodney W. Grimes /* 16768fae3551SRodney W. Grimes * Loop around ignoring blank lines and getting all continuation lines. 16778fae3551SRodney W. Grimes */ 16788fae3551SRodney W. Grimes p = line; 16798fae3551SRodney W. Grimes totlen = 0; 16808fae3551SRodney W. Grimes do { 16818fae3551SRodney W. Grimes if (fgets(p, LINESIZ - totlen, exp_file) == NULL) 16828fae3551SRodney W. Grimes return (0); 16838fae3551SRodney W. Grimes len = strlen(p); 16848fae3551SRodney W. Grimes cp = p + len - 1; 16858fae3551SRodney W. Grimes cont_line = 0; 16868fae3551SRodney W. Grimes while (cp >= p && 16878fae3551SRodney W. Grimes (*cp == ' ' || *cp == '\t' || *cp == '\n' || *cp == '\\')) { 16888fae3551SRodney W. Grimes if (*cp == '\\') 16898fae3551SRodney W. Grimes cont_line = 1; 16908fae3551SRodney W. Grimes cp--; 16918fae3551SRodney W. Grimes len--; 16928fae3551SRodney W. Grimes } 16938fae3551SRodney W. Grimes *++cp = '\0'; 16948fae3551SRodney W. Grimes if (len > 0) { 16958fae3551SRodney W. Grimes totlen += len; 16968fae3551SRodney W. Grimes if (totlen >= LINESIZ) { 16978fae3551SRodney W. Grimes syslog(LOG_ERR, "Exports line too long"); 16988fae3551SRodney W. Grimes exit(2); 16998fae3551SRodney W. Grimes } 17008fae3551SRodney W. Grimes p = cp; 17018fae3551SRodney W. Grimes } 17028fae3551SRodney W. Grimes } while (totlen == 0 || cont_line); 17038fae3551SRodney W. Grimes return (1); 17048fae3551SRodney W. Grimes } 17058fae3551SRodney W. Grimes 17068fae3551SRodney W. Grimes /* 17078fae3551SRodney W. Grimes * Parse a description of a credential. 17088fae3551SRodney W. Grimes */ 17098fae3551SRodney W. Grimes void 17108fae3551SRodney W. Grimes parsecred(namelist, cr) 17118fae3551SRodney W. Grimes char *namelist; 17128fae3551SRodney W. Grimes struct ucred *cr; 17138fae3551SRodney W. Grimes { 17148fae3551SRodney W. Grimes char *name; 17158fae3551SRodney W. Grimes int cnt; 17168fae3551SRodney W. Grimes char *names; 17178fae3551SRodney W. Grimes struct passwd *pw; 17188fae3551SRodney W. Grimes struct group *gr; 17198fae3551SRodney W. Grimes int ngroups, groups[NGROUPS + 1]; 17208fae3551SRodney W. Grimes 17218fae3551SRodney W. Grimes /* 17228fae3551SRodney W. Grimes * Set up the unpriviledged user. 17238fae3551SRodney W. Grimes */ 17248fae3551SRodney W. Grimes cr->cr_ref = 1; 17258fae3551SRodney W. Grimes cr->cr_uid = -2; 17268fae3551SRodney W. Grimes cr->cr_groups[0] = -2; 17278fae3551SRodney W. Grimes cr->cr_ngroups = 1; 17288fae3551SRodney W. Grimes /* 17298fae3551SRodney W. Grimes * Get the user's password table entry. 17308fae3551SRodney W. Grimes */ 17318fae3551SRodney W. Grimes names = strsep(&namelist, " \t\n"); 17328fae3551SRodney W. Grimes name = strsep(&names, ":"); 17338fae3551SRodney W. Grimes if (isdigit(*name) || *name == '-') 17348fae3551SRodney W. Grimes pw = getpwuid(atoi(name)); 17358fae3551SRodney W. Grimes else 17368fae3551SRodney W. Grimes pw = getpwnam(name); 17378fae3551SRodney W. Grimes /* 17388fae3551SRodney W. Grimes * Credentials specified as those of a user. 17398fae3551SRodney W. Grimes */ 17408fae3551SRodney W. Grimes if (names == NULL) { 17418fae3551SRodney W. Grimes if (pw == NULL) { 17428fae3551SRodney W. Grimes syslog(LOG_ERR, "Unknown user: %s", name); 17438fae3551SRodney W. Grimes return; 17448fae3551SRodney W. Grimes } 17458fae3551SRodney W. Grimes cr->cr_uid = pw->pw_uid; 17468fae3551SRodney W. Grimes ngroups = NGROUPS + 1; 17478fae3551SRodney W. Grimes if (getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups)) 17488fae3551SRodney W. Grimes syslog(LOG_ERR, "Too many groups"); 17498fae3551SRodney W. Grimes /* 17508fae3551SRodney W. Grimes * Convert from int's to gid_t's and compress out duplicate 17518fae3551SRodney W. Grimes */ 17528fae3551SRodney W. Grimes cr->cr_ngroups = ngroups - 1; 17538fae3551SRodney W. Grimes cr->cr_groups[0] = groups[0]; 17548fae3551SRodney W. Grimes for (cnt = 2; cnt < ngroups; cnt++) 17558fae3551SRodney W. Grimes cr->cr_groups[cnt - 1] = groups[cnt]; 17568fae3551SRodney W. Grimes return; 17578fae3551SRodney W. Grimes } 17588fae3551SRodney W. Grimes /* 17598fae3551SRodney W. Grimes * Explicit credential specified as a colon separated list: 17608fae3551SRodney W. Grimes * uid:gid:gid:... 17618fae3551SRodney W. Grimes */ 17628fae3551SRodney W. Grimes if (pw != NULL) 17638fae3551SRodney W. Grimes cr->cr_uid = pw->pw_uid; 17648fae3551SRodney W. Grimes else if (isdigit(*name) || *name == '-') 17658fae3551SRodney W. Grimes cr->cr_uid = atoi(name); 17668fae3551SRodney W. Grimes else { 17678fae3551SRodney W. Grimes syslog(LOG_ERR, "Unknown user: %s", name); 17688fae3551SRodney W. Grimes return; 17698fae3551SRodney W. Grimes } 17708fae3551SRodney W. Grimes cr->cr_ngroups = 0; 17718fae3551SRodney W. Grimes while (names != NULL && *names != '\0' && cr->cr_ngroups < NGROUPS) { 17728fae3551SRodney W. Grimes name = strsep(&names, ":"); 17738fae3551SRodney W. Grimes if (isdigit(*name) || *name == '-') { 17748fae3551SRodney W. Grimes cr->cr_groups[cr->cr_ngroups++] = atoi(name); 17758fae3551SRodney W. Grimes } else { 17768fae3551SRodney W. Grimes if ((gr = getgrnam(name)) == NULL) { 17778fae3551SRodney W. Grimes syslog(LOG_ERR, "Unknown group: %s", name); 17788fae3551SRodney W. Grimes continue; 17798fae3551SRodney W. Grimes } 17808fae3551SRodney W. Grimes cr->cr_groups[cr->cr_ngroups++] = gr->gr_gid; 17818fae3551SRodney W. Grimes } 17828fae3551SRodney W. Grimes } 17838fae3551SRodney W. Grimes if (names != NULL && *names != '\0' && cr->cr_ngroups == NGROUPS) 17848fae3551SRodney W. Grimes syslog(LOG_ERR, "Too many groups"); 17858fae3551SRodney W. Grimes } 17868fae3551SRodney W. Grimes 17878fae3551SRodney W. Grimes #define STRSIZ (RPCMNT_NAMELEN+RPCMNT_PATHLEN+50) 17888fae3551SRodney W. Grimes /* 17898fae3551SRodney W. Grimes * Routines that maintain the remote mounttab 17908fae3551SRodney W. Grimes */ 17918fae3551SRodney W. Grimes void 17928fae3551SRodney W. Grimes get_mountlist() 17938fae3551SRodney W. Grimes { 17948fae3551SRodney W. Grimes struct mountlist *mlp, **mlpp; 17958fae3551SRodney W. Grimes char *eos, *dirp; 17968fae3551SRodney W. Grimes int len; 17978fae3551SRodney W. Grimes char str[STRSIZ]; 17988fae3551SRodney W. Grimes FILE *mlfile; 17998fae3551SRodney W. Grimes 18008fae3551SRodney W. Grimes if ((mlfile = fopen(_PATH_RMOUNTLIST, "r")) == NULL) { 18018fae3551SRodney W. Grimes syslog(LOG_ERR, "Can't open %s", _PATH_RMOUNTLIST); 18028fae3551SRodney W. Grimes return; 18038fae3551SRodney W. Grimes } 18048fae3551SRodney W. Grimes mlpp = &mlhead; 18058fae3551SRodney W. Grimes while (fgets(str, STRSIZ, mlfile) != NULL) { 18068fae3551SRodney W. Grimes if ((dirp = index(str, '\t')) == NULL && 18078fae3551SRodney W. Grimes (dirp = index(str, ' ')) == NULL) 18088fae3551SRodney W. Grimes continue; 18098fae3551SRodney W. Grimes mlp = (struct mountlist *)malloc(sizeof (*mlp)); 18108fae3551SRodney W. Grimes len = dirp-str; 18118fae3551SRodney W. Grimes if (len > RPCMNT_NAMELEN) 18128fae3551SRodney W. Grimes len = RPCMNT_NAMELEN; 18138fae3551SRodney W. Grimes bcopy(str, mlp->ml_host, len); 18148fae3551SRodney W. Grimes mlp->ml_host[len] = '\0'; 18158fae3551SRodney W. Grimes while (*dirp == '\t' || *dirp == ' ') 18168fae3551SRodney W. Grimes dirp++; 18178fae3551SRodney W. Grimes if ((eos = index(dirp, '\t')) == NULL && 18188fae3551SRodney W. Grimes (eos = index(dirp, ' ')) == NULL && 18198fae3551SRodney W. Grimes (eos = index(dirp, '\n')) == NULL) 18208fae3551SRodney W. Grimes len = strlen(dirp); 18218fae3551SRodney W. Grimes else 18228fae3551SRodney W. Grimes len = eos-dirp; 18238fae3551SRodney W. Grimes if (len > RPCMNT_PATHLEN) 18248fae3551SRodney W. Grimes len = RPCMNT_PATHLEN; 18258fae3551SRodney W. Grimes bcopy(dirp, mlp->ml_dirp, len); 18268fae3551SRodney W. Grimes mlp->ml_dirp[len] = '\0'; 18278fae3551SRodney W. Grimes mlp->ml_next = (struct mountlist *)NULL; 18288fae3551SRodney W. Grimes *mlpp = mlp; 18298fae3551SRodney W. Grimes mlpp = &mlp->ml_next; 18308fae3551SRodney W. Grimes } 18318fae3551SRodney W. Grimes fclose(mlfile); 18328fae3551SRodney W. Grimes } 18338fae3551SRodney W. Grimes 18348fae3551SRodney W. Grimes void 18358fae3551SRodney W. Grimes del_mlist(hostp, dirp) 18368fae3551SRodney W. Grimes char *hostp, *dirp; 18378fae3551SRodney W. Grimes { 18388fae3551SRodney W. Grimes struct mountlist *mlp, **mlpp; 18398fae3551SRodney W. Grimes struct mountlist *mlp2; 18408fae3551SRodney W. Grimes FILE *mlfile; 18418fae3551SRodney W. Grimes int fnd = 0; 18428fae3551SRodney W. Grimes 18438fae3551SRodney W. Grimes mlpp = &mlhead; 18448fae3551SRodney W. Grimes mlp = mlhead; 18458fae3551SRodney W. Grimes while (mlp) { 18468fae3551SRodney W. Grimes if (!strcmp(mlp->ml_host, hostp) && 18478fae3551SRodney W. Grimes (!dirp || !strcmp(mlp->ml_dirp, dirp))) { 18488fae3551SRodney W. Grimes fnd = 1; 18498fae3551SRodney W. Grimes mlp2 = mlp; 18508fae3551SRodney W. Grimes *mlpp = mlp = mlp->ml_next; 18518fae3551SRodney W. Grimes free((caddr_t)mlp2); 18528fae3551SRodney W. Grimes } else { 18538fae3551SRodney W. Grimes mlpp = &mlp->ml_next; 18548fae3551SRodney W. Grimes mlp = mlp->ml_next; 18558fae3551SRodney W. Grimes } 18568fae3551SRodney W. Grimes } 18578fae3551SRodney W. Grimes if (fnd) { 18588fae3551SRodney W. Grimes if ((mlfile = fopen(_PATH_RMOUNTLIST, "w")) == NULL) { 18598fae3551SRodney W. Grimes syslog(LOG_ERR,"Can't update %s", _PATH_RMOUNTLIST); 18608fae3551SRodney W. Grimes return; 18618fae3551SRodney W. Grimes } 18628fae3551SRodney W. Grimes mlp = mlhead; 18638fae3551SRodney W. Grimes while (mlp) { 18648fae3551SRodney W. Grimes fprintf(mlfile, "%s %s\n", mlp->ml_host, mlp->ml_dirp); 18658fae3551SRodney W. Grimes mlp = mlp->ml_next; 18668fae3551SRodney W. Grimes } 18678fae3551SRodney W. Grimes fclose(mlfile); 18688fae3551SRodney W. Grimes } 18698fae3551SRodney W. Grimes } 18708fae3551SRodney W. Grimes 18718fae3551SRodney W. Grimes void 18728fae3551SRodney W. Grimes add_mlist(hostp, dirp) 18738fae3551SRodney W. Grimes char *hostp, *dirp; 18748fae3551SRodney W. Grimes { 18758fae3551SRodney W. Grimes struct mountlist *mlp, **mlpp; 18768fae3551SRodney W. Grimes FILE *mlfile; 18778fae3551SRodney W. Grimes 18788fae3551SRodney W. Grimes mlpp = &mlhead; 18798fae3551SRodney W. Grimes mlp = mlhead; 18808fae3551SRodney W. Grimes while (mlp) { 18818fae3551SRodney W. Grimes if (!strcmp(mlp->ml_host, hostp) && !strcmp(mlp->ml_dirp, dirp)) 18828fae3551SRodney W. Grimes return; 18838fae3551SRodney W. Grimes mlpp = &mlp->ml_next; 18848fae3551SRodney W. Grimes mlp = mlp->ml_next; 18858fae3551SRodney W. Grimes } 18868fae3551SRodney W. Grimes mlp = (struct mountlist *)malloc(sizeof (*mlp)); 18878fae3551SRodney W. Grimes strncpy(mlp->ml_host, hostp, RPCMNT_NAMELEN); 18888fae3551SRodney W. Grimes mlp->ml_host[RPCMNT_NAMELEN] = '\0'; 18898fae3551SRodney W. Grimes strncpy(mlp->ml_dirp, dirp, RPCMNT_PATHLEN); 18908fae3551SRodney W. Grimes mlp->ml_dirp[RPCMNT_PATHLEN] = '\0'; 18918fae3551SRodney W. Grimes mlp->ml_next = (struct mountlist *)NULL; 18928fae3551SRodney W. Grimes *mlpp = mlp; 18938fae3551SRodney W. Grimes if ((mlfile = fopen(_PATH_RMOUNTLIST, "a")) == NULL) { 18948fae3551SRodney W. Grimes syslog(LOG_ERR, "Can't update %s", _PATH_RMOUNTLIST); 18958fae3551SRodney W. Grimes return; 18968fae3551SRodney W. Grimes } 18978fae3551SRodney W. Grimes fprintf(mlfile, "%s %s\n", mlp->ml_host, mlp->ml_dirp); 18988fae3551SRodney W. Grimes fclose(mlfile); 18998fae3551SRodney W. Grimes } 19008fae3551SRodney W. Grimes 19018fae3551SRodney W. Grimes /* 19028fae3551SRodney W. Grimes * This function is called via. SIGTERM when the system is going down. 19038fae3551SRodney W. Grimes * It sends a broadcast RPCMNT_UMNTALL. 19048fae3551SRodney W. Grimes */ 19058fae3551SRodney W. Grimes void 19068fae3551SRodney W. Grimes send_umntall() 19078fae3551SRodney W. Grimes { 19088fae3551SRodney W. Grimes (void) clnt_broadcast(RPCPROG_MNT, RPCMNT_VER1, RPCMNT_UMNTALL, 19098fae3551SRodney W. Grimes xdr_void, (caddr_t)0, xdr_void, (caddr_t)0, umntall_each); 19108fae3551SRodney W. Grimes exit(0); 19118fae3551SRodney W. Grimes } 19128fae3551SRodney W. Grimes 19138fae3551SRodney W. Grimes int 19148fae3551SRodney W. Grimes umntall_each(resultsp, raddr) 19158fae3551SRodney W. Grimes caddr_t resultsp; 19168fae3551SRodney W. Grimes struct sockaddr_in *raddr; 19178fae3551SRodney W. Grimes { 19188fae3551SRodney W. Grimes return (1); 19198fae3551SRodney W. Grimes } 19208fae3551SRodney W. Grimes 19218fae3551SRodney W. Grimes /* 19228fae3551SRodney W. Grimes * Free up a group list. 19238fae3551SRodney W. Grimes */ 19248fae3551SRodney W. Grimes void 19258fae3551SRodney W. Grimes free_grp(grp) 19268fae3551SRodney W. Grimes struct grouplist *grp; 19278fae3551SRodney W. Grimes { 19288fae3551SRodney W. Grimes char **addrp; 19298fae3551SRodney W. Grimes 19308fae3551SRodney W. Grimes if (grp->gr_type == GT_HOST) { 19318fae3551SRodney W. Grimes if (grp->gr_ptr.gt_hostent->h_name) { 19328fae3551SRodney W. Grimes addrp = grp->gr_ptr.gt_hostent->h_addr_list; 19338fae3551SRodney W. Grimes while (addrp && *addrp) 19348fae3551SRodney W. Grimes free(*addrp++); 19358fae3551SRodney W. Grimes free((caddr_t)grp->gr_ptr.gt_hostent->h_addr_list); 19368fae3551SRodney W. Grimes free(grp->gr_ptr.gt_hostent->h_name); 19378fae3551SRodney W. Grimes } 19388fae3551SRodney W. Grimes free((caddr_t)grp->gr_ptr.gt_hostent); 19398fae3551SRodney W. Grimes } else if (grp->gr_type == GT_NET) { 19408fae3551SRodney W. Grimes if (grp->gr_ptr.gt_net.nt_name) 19418fae3551SRodney W. Grimes free(grp->gr_ptr.gt_net.nt_name); 19428fae3551SRodney W. Grimes } 19438fae3551SRodney W. Grimes #ifdef ISO 19448fae3551SRodney W. Grimes else if (grp->gr_type == GT_ISO) 19458fae3551SRodney W. Grimes free((caddr_t)grp->gr_ptr.gt_isoaddr); 19468fae3551SRodney W. Grimes #endif 19478fae3551SRodney W. Grimes free((caddr_t)grp); 19488fae3551SRodney W. Grimes } 19498fae3551SRodney W. Grimes 19508fae3551SRodney W. Grimes #ifdef DEBUG 19518fae3551SRodney W. Grimes void 19528fae3551SRodney W. Grimes SYSLOG(int pri, const char *fmt, ...) 19538fae3551SRodney W. Grimes { 19548fae3551SRodney W. Grimes va_list ap; 19558fae3551SRodney W. Grimes 19568fae3551SRodney W. Grimes va_start(ap, fmt); 19578fae3551SRodney W. Grimes vfprintf(stderr, fmt, ap); 19588fae3551SRodney W. Grimes va_end(ap); 19598fae3551SRodney W. Grimes } 19608fae3551SRodney W. Grimes #endif /* DEBUG */ 19618fae3551SRodney W. Grimes 19628fae3551SRodney W. Grimes /* 19638fae3551SRodney W. Grimes * Check options for consistency. 19648fae3551SRodney W. Grimes */ 19658fae3551SRodney W. Grimes int 19668fae3551SRodney W. Grimes check_options(dp) 19678fae3551SRodney W. Grimes struct dirlist *dp; 19688fae3551SRodney W. Grimes { 19698fae3551SRodney W. Grimes 19708fae3551SRodney W. Grimes if (dp == (struct dirlist *)NULL) 19718fae3551SRodney W. Grimes return (1); 19728fae3551SRodney W. Grimes if ((opt_flags & (OP_MAPROOT | OP_MAPALL)) == (OP_MAPROOT | OP_MAPALL) || 19738fae3551SRodney W. Grimes (opt_flags & (OP_MAPROOT | OP_KERB)) == (OP_MAPROOT | OP_KERB) || 19748fae3551SRodney W. Grimes (opt_flags & (OP_MAPALL | OP_KERB)) == (OP_MAPALL | OP_KERB)) { 19758fae3551SRodney W. Grimes syslog(LOG_ERR, "-mapall, -maproot and -kerb mutually exclusive"); 19768fae3551SRodney W. Grimes return (1); 19778fae3551SRodney W. Grimes } 19788fae3551SRodney W. Grimes if ((opt_flags & OP_MASK) && (opt_flags & OP_NET) == 0) { 19798fae3551SRodney W. Grimes syslog(LOG_ERR, "-mask requires -net"); 19808fae3551SRodney W. Grimes return (1); 19818fae3551SRodney W. Grimes } 19828fae3551SRodney W. Grimes if ((opt_flags & (OP_NET | OP_ISO)) == (OP_NET | OP_ISO)) { 19838fae3551SRodney W. Grimes syslog(LOG_ERR, "-net and -iso mutually exclusive"); 19848fae3551SRodney W. Grimes return (1); 19858fae3551SRodney W. Grimes } 19868fae3551SRodney W. Grimes if ((opt_flags & OP_ALLDIRS) && dp->dp_left) { 19878fae3551SRodney W. Grimes syslog(LOG_ERR, "-alldir has multiple directories"); 19888fae3551SRodney W. Grimes return (1); 19898fae3551SRodney W. Grimes } 19908fae3551SRodney W. Grimes return (0); 19918fae3551SRodney W. Grimes } 19928fae3551SRodney W. Grimes 19938fae3551SRodney W. Grimes /* 19948fae3551SRodney W. Grimes * Check an absolute directory path for any symbolic links. Return true 19958fae3551SRodney W. Grimes * if no symbolic links are found. 19968fae3551SRodney W. Grimes */ 19978fae3551SRodney W. Grimes int 19988fae3551SRodney W. Grimes check_dirpath(dirp) 19998fae3551SRodney W. Grimes char *dirp; 20008fae3551SRodney W. Grimes { 20018fae3551SRodney W. Grimes char *cp; 20028fae3551SRodney W. Grimes int ret = 1; 20038fae3551SRodney W. Grimes struct stat sb; 20048fae3551SRodney W. Grimes 20058fae3551SRodney W. Grimes cp = dirp + 1; 20068fae3551SRodney W. Grimes while (*cp && ret) { 20078fae3551SRodney W. Grimes if (*cp == '/') { 20088fae3551SRodney W. Grimes *cp = '\0'; 20098fae3551SRodney W. Grimes if (lstat(dirp, &sb) < 0 || 20108fae3551SRodney W. Grimes (sb.st_mode & S_IFMT) != S_IFDIR) 20118fae3551SRodney W. Grimes ret = 0; 20128fae3551SRodney W. Grimes *cp = '/'; 20138fae3551SRodney W. Grimes } 20148fae3551SRodney W. Grimes cp++; 20158fae3551SRodney W. Grimes } 20168fae3551SRodney W. Grimes if (lstat(dirp, &sb) < 0 || 20178fae3551SRodney W. Grimes (sb.st_mode & S_IFMT) != S_IFDIR) 20188fae3551SRodney W. Grimes ret = 0; 20198fae3551SRodney W. Grimes return (ret); 20208fae3551SRodney W. Grimes } 2021