Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/mount_nfs Split getnfsargs() out into its own file, it ...
details: https://anonhg.NetBSD.org/src/rev/d14eab1155f2
branches: trunk
changeset: 580913:d14eab1155f2
user: dsl <dsl%NetBSD.org@localhost>
date: Sun May 15 21:18:34 2005 +0000
description:
Split getnfsargs() out into its own file, it drags in 70kB of rpc code.
I might manage to write a version that doesn't pull in all the crud.
(Which will give a load of space in the install floppy images)
diffstat:
sbin/mount_nfs/Makefile | 5 +-
sbin/mount_nfs/getnfsargs.c | 412 ++++++++++++++++++++++++++++++++++++++++++++
sbin/mount_nfs/mount_nfs.c | 338 +-----------------------------------
sbin/mount_nfs/mount_nfs.h | 44 ++++
4 files changed, 464 insertions(+), 335 deletions(-)
diffs (truncated from 874 to 300 lines):
diff -r 675e94c49795 -r d14eab1155f2 sbin/mount_nfs/Makefile
--- a/sbin/mount_nfs/Makefile Sun May 15 21:12:53 2005 +0000
+++ b/sbin/mount_nfs/Makefile Sun May 15 21:18:34 2005 +0000
@@ -1,10 +1,11 @@
-# $NetBSD: Makefile,v 1.15 2005/01/10 02:58:59 lukem Exp $
+# $NetBSD: Makefile,v 1.16 2005/05/15 21:18:34 dsl Exp $
# @(#)Makefile 8.2 (Berkeley) 3/27/94
+WARNS=3
.include <bsd.own.mk>
PROG= mount_nfs
-SRCS= mount_nfs.c
+SRCS= mount_nfs.c getnfsargs.c
MAN= mount_nfs.8
CPPFLAGS+= -DNFS
diff -r 675e94c49795 -r d14eab1155f2 sbin/mount_nfs/getnfsargs.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/mount_nfs/getnfsargs.c Sun May 15 21:18:34 2005 +0000
@@ -0,0 +1,412 @@
+/* $NetBSD: getnfsargs.c,v 1.1 2005/05/15 21:18:34 dsl Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Rick Macklem at The University of Guelph.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__COPYRIGHT("@(#) Copyright (c) 1992, 1993, 1994\n\
+ The Regents of the University of California. All rights reserved.\n");
+#endif /* not lint */
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)mount_nfs.c 8.11 (Berkeley) 5/4/95";
+#else
+__RCSID("$NetBSD: getnfsargs.c,v 1.1 2005/05/15 21:18:34 dsl Exp $");
+#endif
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/mount.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <syslog.h>
+
+#include <rpc/rpc.h>
+#include <rpc/pmap_clnt.h>
+#include <rpc/pmap_prot.h>
+
+#ifdef ISO
+#include <netiso/iso.h>
+#endif
+
+#ifdef NFSKERB
+#include <des.h>
+#include <kerberosIV/krb.h>
+#endif
+
+#include <nfs/rpcv2.h>
+#include <nfs/nfsproto.h>
+#include <nfs/nfs.h>
+#include <nfs/nqnfs.h>
+#include <nfs/nfsmount.h>
+
+#include <arpa/inet.h>
+
+#include <ctype.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <util.h>
+
+#include "mount_nfs.h"
+
+struct nfhret {
+ u_long stat;
+ long vers;
+ long auth;
+ long fhsize;
+ u_char nfh[NFSX_V3FHMAX];
+};
+
+static int xdr_dir(XDR *, char *);
+static int xdr_fh(XDR *, struct nfhret *);
+
+int
+getnfsargs(char *spec, struct nfs_args *nfsargsp)
+{
+ CLIENT *clp;
+ struct addrinfo hints, *ai_nfs, *ai;
+ int ecode;
+ char host[NI_MAXHOST], serv[NI_MAXSERV];
+ static struct netbuf nfs_nb;
+ static struct sockaddr_storage nfs_ss;
+ struct netconfig *nconf;
+ const char *netid;
+#ifdef ISO
+ static struct sockaddr_iso isoaddr;
+ struct iso_addr *isop;
+ int isoflag = 0;
+#endif
+ struct timeval pertry, try;
+ enum clnt_stat clnt_stat;
+ int i, nfsvers, mntvers, orgcnt;
+ char *hostp, *delimp;
+#ifdef NFSKERB
+ char *cp;
+#endif
+ static struct nfhret nfhret;
+ static char nam[MNAMELEN + 1];
+
+ strncpy(nam, spec, MNAMELEN);
+ nam[MNAMELEN] = '\0';
+ if ((delimp = strchr(spec, '@')) != NULL) {
+ hostp = delimp + 1;
+ } else if ((delimp = strrchr(spec, ':')) != NULL) {
+ hostp = spec;
+ spec = delimp + 1;
+ } else {
+ warnx("no <host>:<dirpath> or <dirpath>@<host> spec");
+ return (0);
+ }
+ *delimp = '\0';
+ /*
+ * DUMB!! Until the mount protocol works on iso transport, we must
+ * supply both an iso and an inet address for the host.
+ */
+#ifdef ISO
+ if (!strncmp(hostp, "iso=", 4)) {
+ u_short isoport;
+
+ hostp += 4;
+ isoflag++;
+ if ((delimp = strchr(hostp, '+')) == NULL) {
+ warnx("no iso+inet address");
+ return (0);
+ }
+ *delimp = '\0';
+ if ((isop = iso_addr(hostp)) == NULL) {
+ warnx("bad ISO address");
+ return (0);
+ }
+ memset(&isoaddr, 0, sizeof (isoaddr));
+ memcpy(&isoaddr.siso_addr, isop, sizeof (struct iso_addr));
+ isoaddr.siso_len = sizeof (isoaddr);
+ isoaddr.siso_family = AF_ISO;
+ isoaddr.siso_tlen = 2;
+ isoport = htons(NFS_PORT);
+ memcpy(TSEL(&isoaddr), &isoport, isoaddr.siso_tlen);
+ hostp = delimp + 1;
+ }
+#endif /* ISO */
+
+ /*
+ * Handle an internet host address and reverse resolve it if
+ * doing Kerberos.
+ */
+ memset(&hints, 0, sizeof hints);
+ hints.ai_flags = AI_NUMERICHOST;
+ hints.ai_socktype = nfsargsp->sotype;
+ if (getaddrinfo(hostp, "nfs", &hints, &ai_nfs) == 0) {
+ if ((nfsargsp->flags & NFSMNT_KERB)) {
+ hints.ai_flags = 0;
+ if (getnameinfo(ai->ai_addr, ai->ai_addrlen, host,
+ sizeof host, serv, sizeof serv, 0) != 0) {
+ warnx("can't reverse resolve net address for "
+ "host \"%s\": %s", hostp,
+ gai_strerror(ecode));
+ return (0);
+ }
+ hostp = host;
+ }
+ } else {
+ hints.ai_flags = 0;
+ if ((ecode = getaddrinfo(hostp, "nfs", &hints, &ai_nfs)) != 0) {
+ warnx("can't get net id for host \"%s\": %s", hostp,
+ gai_strerror(ecode));
+ return (0);
+ }
+ }
+#ifdef NFSKERB
+ if (nfsargsp->flags & NFSMNT_KERB) {
+ strncpy(inst, hp->h_name, INST_SZ);
+ inst[INST_SZ - 1] = '\0';
+ if (cp = strchr(inst, '.'))
+ *cp = '\0';
+ }
+#endif /* NFSKERB */
+
+ if (force2) {
+ nfsvers = NFS_VER2;
+ mntvers = RPCMNT_VER1;
+ } else {
+ nfsvers = NFS_VER3;
+ mntvers = RPCMNT_VER3;
+ }
+ orgcnt = retrycnt;
+ nfhret.stat = EACCES; /* Mark not yet successful */
+
+ for (ai = ai_nfs; ai; ai = ai->ai_next) {
+ /*
+ * XXX. Nead a generic (family, type, proto) -> nconf interface.
+ * __rpc_*2nconf exist, maybe they should be exported.
+ */
+ if (nfsargsp->sotype == SOCK_STREAM) {
+ if (ai->ai_family == AF_INET6)
+ netid = "tcp6";
+ else
+ netid = "tcp";
+ } else {
+ if (ai->ai_family == AF_INET6)
+ netid = "udp6";
+ else
+ netid = "udp";
+ }
+
+ nconf = getnetconfigent(netid);
+
+tryagain:
+ retrycnt = orgcnt;
+
+ while (retrycnt > 0) {
+ nfs_nb.buf = &nfs_ss;
+ nfs_nb.maxlen = sizeof nfs_ss;
+ if (!rpcb_getaddr(RPCPROG_NFS, nfsvers, nconf, &nfs_nb, hostp)){
+ if (rpc_createerr.cf_stat == RPC_SYSTEMERROR) {
+ nfhret.stat = rpc_createerr.cf_error.re_errno;
+ break;
+ }
+ if (rpc_createerr.cf_stat == RPC_UNKNOWNPROTO) {
+ nfhret.stat = EPROTONOSUPPORT;
+ break;
+ }
+ if ((opflags & ISBGRND) == 0)
+ clnt_pcreateerror(
+ "mount_nfs: rpcbind to nfs on server");
+ } else {
+ pertry.tv_sec = 10;
+ pertry.tv_usec = 0;
+ /*
+ * XXX relies on clnt_tcp_create to bind to a reserved
+ * socket.
+ */
+ clp = clnt_tp_create(hostp, RPCPROG_MNT, mntvers,
+ mnttcp_ok ? nconf : getnetconfigent("udp"));
+ if (clp == NULL) {
+ if ((opflags & ISBGRND) == 0) {
+ clnt_pcreateerror(
+ "Cannot MNT RPC (mountd)");
+ }
+ } else {
+ CLNT_CONTROL(clp, CLSET_RETRY_TIMEOUT,
+ (char *)&pertry);
+ clp->cl_auth = authsys_create_default();
+ try.tv_sec = 10;
+ try.tv_usec = 0;
+ if (nfsargsp->flags & NFSMNT_KERB)
+ nfhret.auth = RPCAUTH_KERB4;
+ else
+ nfhret.auth = RPCAUTH_UNIX;
+ nfhret.vers = mntvers;
+ clnt_stat = clnt_call(clp, RPCMNT_MOUNT,
+ xdr_dir, spec, xdr_fh, &nfhret, try);
+ switch (clnt_stat) {
Home |
Main Index |
Thread Index |
Old Index