X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=utils%2Fmountd%2Fmountd.c;h=753fd377331598946ade574fc0ae785b334d360f;hb=c5571da8e92f87fc9ec6e8aa8075c69497361c87;hp=19dc4ee1e78d27520925dadcf9ee6348f8a2bd46;hpb=4210d6f0c9cad57907877bf1e5d32ebe4a27bf17;p=nfs-utils.git diff --git a/utils/mountd/mountd.c b/utils/mountd/mountd.c index 19dc4ee..753fd37 100644 --- a/utils/mountd/mountd.c +++ b/utils/mountd/mountd.c @@ -28,10 +28,6 @@ #include "rpcmisc.h" #include "pseudoflavors.h" -extern void cache_open(void); -extern struct nfs_fh_len *cache_get_filehandle(nfs_export *exp, int len, char *p); -extern int cache_export(nfs_export *exp, char *path); - extern void my_svc_run(void); static void usage(const char *, int exitcode); @@ -75,16 +71,34 @@ static struct option longopts[] = { NULL, 0, 0, 0 } }; -static int nfs_version = -1; +#define NFSVERSBIT(vers) (0x1 << (vers - 1)) +#define NFSVERSBIT_ALL (NFSVERSBIT(2) | NFSVERSBIT(3) | NFSVERSBIT(4)) + +static int nfs_version = NFSVERSBIT_ALL; + +static int version2(void) +{ + return nfs_version & NFSVERSBIT(2); +} + +static int version3(void) +{ + return nfs_version & NFSVERSBIT(3); +} + +static int version_any(void) +{ + return nfs_version & NFSVERSBIT_ALL; +} static void unregister_services (void) { - if (nfs_version & (0x1 << 1)) { + if (version2()) { pmap_unset (MOUNTPROG, MOUNTVERS); pmap_unset (MOUNTPROG, MOUNTVERS_POSIX); } - if (nfs_version & (0x1 << 2)) + if (version3()) pmap_unset (MOUNTPROG, MOUNTVERS_NFSV3); } @@ -275,7 +289,7 @@ mount_umntall_1_svc(struct svc_req *rqstp, void *UNUSED(argp), /* Reload /etc/xtab if necessary */ auth_reload(); - mountlist_del_all(nfs_getrpccaller_in(rqstp->rq_xprt)); + mountlist_del_all(nfs_getrpccaller(rqstp->rq_xprt)); return 1; } @@ -677,6 +691,7 @@ main(int argc, char **argv) int port = 0; int descriptors = 0; int c; + int vers; struct sigaction sa; struct rlimit rlim; @@ -720,7 +735,13 @@ main(int argc, char **argv) } break; case 'N': - nfs_version &= ~(1 << (atoi (optarg) - 1)); + vers = atoi(optarg); + if (vers < 2 || vers > 4) { + fprintf(stderr, "%s: bad version number: %s\n", + argv[0], optarg); + usage(argv[0], 1); + } + nfs_version &= ~NFSVERSBIT(vers); break; case 'n': _rpcfdtype = SOCK_DGRAM; @@ -739,7 +760,13 @@ main(int argc, char **argv) num_threads = atoi (optarg); break; case 'V': - nfs_version |= 1 << (atoi (optarg) - 1); + vers = atoi(optarg); + if (vers < 2 || vers > 4) { + fprintf(stderr, "%s: bad version number: %s\n", + argv[0], optarg); + usage(argv[0], 1); + } + nfs_version |= NFSVERSBIT(vers); break; case 'v': printf("kmountd %s\n", VERSION); @@ -754,7 +781,7 @@ main(int argc, char **argv) /* No more arguments allowed. * Require at least one valid version (2, 3, or 4) */ - if (optind != argc || !(nfs_version & 0xE)) + if (optind != argc || !version_any()) usage(argv [0], 1); if (chdir(state_dir)) { @@ -802,13 +829,13 @@ main(int argc, char **argv) if (new_cache) cache_open(); - if (nfs_version & (0x1 << 1)) { + if (version2()) { rpc_init("mountd", MOUNTPROG, MOUNTVERS, mount_dispatch, port); rpc_init("mountd", MOUNTPROG, MOUNTVERS_POSIX, mount_dispatch, port); } - if (nfs_version & (0x1 << 2)) + if (version3()) rpc_init("mountd", MOUNTPROG, MOUNTVERS_NFSV3, mount_dispatch, port);