Changeset View
Changeset View
Standalone View
Standalone View
head/usr.sbin/mountd/mountd.c
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/fcntl.h> | #include <sys/fcntl.h> | ||||
#include <sys/linker.h> | #include <sys/linker.h> | ||||
#include <sys/module.h> | #include <sys/module.h> | ||||
#include <sys/mount.h> | #include <sys/mount.h> | ||||
#include <sys/queue.h> | |||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include <sys/sysctl.h> | #include <sys/sysctl.h> | ||||
#include <sys/syslog.h> | #include <sys/syslog.h> | ||||
#include <rpc/rpc.h> | #include <rpc/rpc.h> | ||||
#include <rpc/rpc_com.h> | #include <rpc/rpc_com.h> | ||||
#include <rpc/pmap_clnt.h> | #include <rpc/pmap_clnt.h> | ||||
#include <rpc/pmap_prot.h> | #include <rpc/pmap_prot.h> | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | struct dirlist { | ||||
struct hostlist *dp_hosts; /* List of hosts this dir exported to */ | struct hostlist *dp_hosts; /* List of hosts this dir exported to */ | ||||
char *dp_dirp; | char *dp_dirp; | ||||
}; | }; | ||||
/* dp_flag bits */ | /* dp_flag bits */ | ||||
#define DP_DEFSET 0x1 | #define DP_DEFSET 0x1 | ||||
#define DP_HOSTSET 0x2 | #define DP_HOSTSET 0x2 | ||||
struct exportlist { | struct exportlist { | ||||
struct exportlist *ex_next; | |||||
struct dirlist *ex_dirl; | struct dirlist *ex_dirl; | ||||
struct dirlist *ex_defdir; | struct dirlist *ex_defdir; | ||||
int ex_flag; | int ex_flag; | ||||
fsid_t ex_fs; | fsid_t ex_fs; | ||||
char *ex_fsdir; | char *ex_fsdir; | ||||
char *ex_indexfile; | char *ex_indexfile; | ||||
int ex_numsecflavors; | int ex_numsecflavors; | ||||
int ex_secflavors[MAXSECFLAVORS]; | int ex_secflavors[MAXSECFLAVORS]; | ||||
int ex_defnumsecflavors; | int ex_defnumsecflavors; | ||||
int ex_defsecflavors[MAXSECFLAVORS]; | int ex_defsecflavors[MAXSECFLAVORS]; | ||||
SLIST_ENTRY(exportlist) entries; | |||||
}; | }; | ||||
/* ex_flag bits */ | /* ex_flag bits */ | ||||
#define EX_LINKED 0x1 | #define EX_LINKED 0x1 | ||||
struct netmsk { | struct netmsk { | ||||
struct sockaddr_storage nt_net; | struct sockaddr_storage nt_net; | ||||
struct sockaddr_storage nt_mask; | struct sockaddr_storage nt_mask; | ||||
char *nt_name; | char *nt_name; | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | |||||
static int xdr_dir(XDR *, char *); | static int xdr_dir(XDR *, char *); | ||||
static int xdr_explist(XDR *, caddr_t); | static int xdr_explist(XDR *, caddr_t); | ||||
static int xdr_explist_brief(XDR *, caddr_t); | static int xdr_explist_brief(XDR *, caddr_t); | ||||
static int xdr_explist_common(XDR *, caddr_t, int); | static int xdr_explist_common(XDR *, caddr_t, int); | ||||
static int xdr_fhs(XDR *, caddr_t); | static int xdr_fhs(XDR *, caddr_t); | ||||
static int xdr_mlist(XDR *, caddr_t); | static int xdr_mlist(XDR *, caddr_t); | ||||
static void terminate(int); | static void terminate(int); | ||||
static struct exportlist *exphead; | static SLIST_HEAD(, exportlist) exphead = SLIST_HEAD_INITIALIZER(exphead); | ||||
static struct mountlist *mlhead; | static struct mountlist *mlhead; | ||||
static struct grouplist *grphead; | static struct grouplist *grphead; | ||||
static char *exnames_default[2] = { _PATH_EXPORTS, NULL }; | static char *exnames_default[2] = { _PATH_EXPORTS, NULL }; | ||||
static char **exnames; | static char **exnames; | ||||
static char **hosts = NULL; | static char **hosts = NULL; | ||||
static struct xucred def_anon = { | static struct xucred def_anon = { | ||||
XUCRED_VERSION, | XUCRED_VERSION, | ||||
(uid_t)65534, | (uid_t)65534, | ||||
▲ Show 20 Lines • Show All 206 Lines • ▼ Show 20 Lines | if (modfind("nfsd") < 0) { | ||||
/* Not present in kernel, try loading it */ | /* Not present in kernel, try loading it */ | ||||
if (kldload("nfsd") < 0 || modfind("nfsd") < 0) | if (kldload("nfsd") < 0 || modfind("nfsd") < 0) | ||||
errx(1, "NFS server is not available"); | errx(1, "NFS server is not available"); | ||||
} | } | ||||
argc -= optind; | argc -= optind; | ||||
argv += optind; | argv += optind; | ||||
grphead = (struct grouplist *)NULL; | grphead = (struct grouplist *)NULL; | ||||
exphead = (struct exportlist *)NULL; | |||||
mlhead = (struct mountlist *)NULL; | mlhead = (struct mountlist *)NULL; | ||||
if (argc > 0) | if (argc > 0) | ||||
exnames = argv; | exnames = argv; | ||||
else | else | ||||
exnames = exnames_default; | exnames = exnames_default; | ||||
openlog("mountd", LOG_PID, LOG_DAEMON); | openlog("mountd", LOG_PID, LOG_DAEMON); | ||||
if (debug) | if (debug) | ||||
warnx("getting export list"); | warnx("getting export list"); | ||||
▲ Show 20 Lines • Show All 822 Lines • ▼ Show 20 Lines | xdr_explist_common(XDR *xdrsp, caddr_t cp __unused, int brief) | ||||
struct exportlist *ep; | struct exportlist *ep; | ||||
int false = 0; | int false = 0; | ||||
int putdef; | int putdef; | ||||
sigset_t sighup_mask; | sigset_t sighup_mask; | ||||
sigemptyset(&sighup_mask); | sigemptyset(&sighup_mask); | ||||
sigaddset(&sighup_mask, SIGHUP); | sigaddset(&sighup_mask, SIGHUP); | ||||
sigprocmask(SIG_BLOCK, &sighup_mask, NULL); | sigprocmask(SIG_BLOCK, &sighup_mask, NULL); | ||||
ep = exphead; | |||||
while (ep) { | SLIST_FOREACH(ep, &exphead, entries) { | ||||
putdef = 0; | putdef = 0; | ||||
if (put_exlist(ep->ex_dirl, xdrsp, ep->ex_defdir, | if (put_exlist(ep->ex_dirl, xdrsp, ep->ex_defdir, | ||||
&putdef, brief)) | &putdef, brief)) | ||||
goto errout; | goto errout; | ||||
if (ep->ex_defdir && putdef == 0 && | if (ep->ex_defdir && putdef == 0 && | ||||
put_exlist(ep->ex_defdir, xdrsp, (struct dirlist *)NULL, | put_exlist(ep->ex_defdir, xdrsp, (struct dirlist *)NULL, | ||||
&putdef, brief)) | &putdef, brief)) | ||||
goto errout; | goto errout; | ||||
ep = ep->ex_next; | |||||
} | } | ||||
sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL); | sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL); | ||||
if (!xdr_bool(xdrsp, &false)) | if (!xdr_bool(xdrsp, &false)) | ||||
return (0); | return (0); | ||||
return (1); | return (1); | ||||
errout: | errout: | ||||
sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL); | sigprocmask(SIG_UNBLOCK, &sighup_mask, NULL); | ||||
return (0); | return (0); | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | |||||
static FILE *exp_file; | static FILE *exp_file; | ||||
/* | /* | ||||
* Get the export list from one, currently open file | * Get the export list from one, currently open file | ||||
*/ | */ | ||||
static void | static void | ||||
get_exportlist_one(void) | get_exportlist_one(void) | ||||
{ | { | ||||
struct exportlist *ep, *ep2; | struct exportlist *ep; | ||||
struct grouplist *grp, *tgrp; | struct grouplist *grp, *tgrp; | ||||
struct exportlist **epp; | |||||
struct dirlist *dirhead; | struct dirlist *dirhead; | ||||
struct statfs fsb; | struct statfs fsb; | ||||
struct xucred anon; | struct xucred anon; | ||||
char *cp, *endcp, *dirp, *hst, *usr, *dom, savedc; | char *cp, *endcp, *dirp, *hst, *usr, *dom, savedc; | ||||
int len, has_host, exflags, got_nondir, dirplen, netgrp; | int len, has_host, exflags, got_nondir, dirplen, netgrp; | ||||
v4root_phase = 0; | v4root_phase = 0; | ||||
dirhead = (struct dirlist *)NULL; | dirhead = (struct dirlist *)NULL; | ||||
▲ Show 20 Lines • Show All 260 Lines • ▼ Show 20 Lines | if (has_host) { | ||||
grphead = tgrp; | grphead = tgrp; | ||||
} else { | } else { | ||||
hang_dirp(dirhead, (struct grouplist *)NULL, ep, | hang_dirp(dirhead, (struct grouplist *)NULL, ep, | ||||
opt_flags); | opt_flags); | ||||
free_grp(grp); | free_grp(grp); | ||||
} | } | ||||
dirhead = (struct dirlist *)NULL; | dirhead = (struct dirlist *)NULL; | ||||
if ((ep->ex_flag & EX_LINKED) == 0) { | if ((ep->ex_flag & EX_LINKED) == 0) { | ||||
ep2 = exphead; | SLIST_INSERT_HEAD(&exphead, ep, entries); | ||||
epp = &exphead; | |||||
/* | |||||
* Insert in the list in alphabetical order. | |||||
*/ | |||||
while (ep2 && strcmp(ep2->ex_fsdir, ep->ex_fsdir) < 0) { | |||||
epp = &ep2->ex_next; | |||||
ep2 = ep2->ex_next; | |||||
} | |||||
if (ep2) | |||||
ep->ex_next = ep2; | |||||
*epp = ep; | |||||
ep->ex_flag |= EX_LINKED; | ep->ex_flag |= EX_LINKED; | ||||
} | } | ||||
nextline: | nextline: | ||||
v4root_phase = 0; | v4root_phase = 0; | ||||
if (dirhead) { | if (dirhead) { | ||||
free_dir(dirhead); | free_dir(dirhead); | ||||
dirhead = (struct dirlist *)NULL; | dirhead = (struct dirlist *)NULL; | ||||
} | } | ||||
Show All 25 Lines | get_exportlist(void) | ||||
export.ex_flags = MNT_DELEXPORT; | export.ex_flags = MNT_DELEXPORT; | ||||
iov = NULL; | iov = NULL; | ||||
iovlen = 0; | iovlen = 0; | ||||
bzero(errmsg, sizeof(errmsg)); | bzero(errmsg, sizeof(errmsg)); | ||||
/* | /* | ||||
* First, get rid of the old list | * First, get rid of the old list | ||||
*/ | */ | ||||
ep = exphead; | SLIST_FOREACH_SAFE(ep, &exphead, entries, ep2) { | ||||
while (ep) { | SLIST_REMOVE(&exphead, ep, exportlist, entries); | ||||
ep2 = ep; | free_exp(ep); | ||||
ep = ep->ex_next; | |||||
free_exp(ep2); | |||||
} | } | ||||
exphead = (struct exportlist *)NULL; | |||||
grp = grphead; | grp = grphead; | ||||
while (grp) { | while (grp) { | ||||
tgrp = grp; | tgrp = grp; | ||||
grp = grp->gr_next; | grp = grp->gr_next; | ||||
free_grp(tgrp); | free_grp(tgrp); | ||||
} | } | ||||
grphead = (struct grouplist *)NULL; | grphead = (struct grouplist *)NULL; | ||||
▲ Show 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* Search the export list for a matching fs. | * Search the export list for a matching fs. | ||||
*/ | */ | ||||
static struct exportlist * | static struct exportlist * | ||||
ex_search(fsid_t *fsid) | ex_search(fsid_t *fsid) | ||||
{ | { | ||||
struct exportlist *ep; | struct exportlist *ep; | ||||
ep = exphead; | SLIST_FOREACH(ep, &exphead, entries) { | ||||
while (ep) { | |||||
if (ep->ex_fs.val[0] == fsid->val[0] && | if (ep->ex_fs.val[0] == fsid->val[0] && | ||||
ep->ex_fs.val[1] == fsid->val[1]) | ep->ex_fs.val[1] == fsid->val[1]) | ||||
return (ep); | return (ep); | ||||
ep = ep->ex_next; | |||||
} | } | ||||
return (ep); | return (ep); | ||||
} | } | ||||
/* | /* | ||||
* Add a directory path to the list. | * Add a directory path to the list. | ||||
*/ | */ | ||||
static char * | static char * | ||||
add_expdir(struct dirlist **dpp, char *cp, int len) | add_expdir(struct dirlist **dpp, char *cp, int len) | ||||
▲ Show 20 Lines • Show All 1,354 Lines • Show Last 20 Lines |