Deleted Added
full compact
mount_nfs.c (193191) mount_nfs.c (194880)
1/*
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 28 unchanged lines hidden (view full) ---

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41static char sccsid[] = "@(#)mount_nfs.c 8.11 (Berkeley) 5/4/95";
42#endif /* not lint */
43#endif
44#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 28 unchanged lines hidden (view full) ---

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41static char sccsid[] = "@(#)mount_nfs.c 8.11 (Berkeley) 5/4/95";
42#endif /* not lint */
43#endif
44#include <sys/cdefs.h>
45__FBSDID("$FreeBSD: head/sbin/mount_nfs/mount_nfs.c 193191 2009-06-01 00:40:39Z rodrigc $");
45__FBSDID("$FreeBSD: head/sbin/mount_nfs/mount_nfs.c 194880 2009-06-24 18:42:21Z dfr $");
46
47#include <sys/param.h>
48#include <sys/linker.h>
49#include <sys/module.h>
50#include <sys/mount.h>
51#include <sys/socket.h>
52#include <sys/stat.h>
53#include <sys/syslog.h>
54#include <sys/uio.h>
55
56#include <rpc/rpc.h>
57#include <rpc/pmap_clnt.h>
58#include <rpc/pmap_prot.h>
46
47#include <sys/param.h>
48#include <sys/linker.h>
49#include <sys/module.h>
50#include <sys/mount.h>
51#include <sys/socket.h>
52#include <sys/stat.h>
53#include <sys/syslog.h>
54#include <sys/uio.h>
55
56#include <rpc/rpc.h>
57#include <rpc/pmap_clnt.h>
58#include <rpc/pmap_prot.h>
59#include <rpcsvc/nfs_prot.h>
60#include <rpcsvc/mount.h>
59
61
60#include <nfs/rpcv2.h>
61#include <nfs/nfsproto.h>
62#include <nfsclient/nfs.h>
63
64#include <arpa/inet.h>
65
66#include <ctype.h>
67#include <err.h>
68#include <errno.h>
69#include <fcntl.h>

--- 21 unchanged lines hidden (view full) ---

91 {NULL, 0, 0}
92};
93
94struct nfhret {
95 u_long stat;
96 long vers;
97 long auth;
98 long fhsize;
62#include <nfsclient/nfs.h>
63
64#include <arpa/inet.h>
65
66#include <ctype.h>
67#include <err.h>
68#include <errno.h>
69#include <fcntl.h>

--- 21 unchanged lines hidden (view full) ---

91 {NULL, 0, 0}
92};
93
94struct nfhret {
95 u_long stat;
96 long vers;
97 long auth;
98 long fhsize;
99 u_char nfh[NFSX_V3FHMAX];
99 u_char nfh[NFS3_FHSIZE];
100};
101#define BGRND 1
102#define ISBGRND 2
103#define OF_NOINET4 4
104#define OF_NOINET6 8
105int retrycnt = -1;
106int opflags = 0;
107int nfsproto = IPPROTO_UDP;

--- 801 unchanged lines hidden (view full) ---

909 /* `ai' contains the complete nfsd sockaddr. */
910 nfs_nb.buf = ai->ai_addr;
911 nfs_nb.len = nfs_nb.maxlen = ai->ai_addrlen;
912 } else {
913 /* Ask the remote rpcbind. */
914 nfs_nb.buf = &nfs_ss;
915 nfs_nb.len = nfs_nb.maxlen = sizeof nfs_ss;
916
100};
101#define BGRND 1
102#define ISBGRND 2
103#define OF_NOINET4 4
104#define OF_NOINET6 8
105int retrycnt = -1;
106int opflags = 0;
107int nfsproto = IPPROTO_UDP;

--- 801 unchanged lines hidden (view full) ---

909 /* `ai' contains the complete nfsd sockaddr. */
910 nfs_nb.buf = ai->ai_addr;
911 nfs_nb.len = nfs_nb.maxlen = ai->ai_addrlen;
912 } else {
913 /* Ask the remote rpcbind. */
914 nfs_nb.buf = &nfs_ss;
915 nfs_nb.len = nfs_nb.maxlen = sizeof nfs_ss;
916
917 if (!rpcb_getaddr(RPCPROG_NFS, nfsvers, nconf, &nfs_nb,
917 if (!rpcb_getaddr(NFS_PROGRAM, nfsvers, nconf, &nfs_nb,
918 hostp)) {
919 if (rpc_createerr.cf_stat == RPC_PROGVERSMISMATCH &&
920 trymntmode == ANY) {
921 trymntmode = V2;
922 goto tryagain;
923 }
924 snprintf(errbuf, sizeof errbuf, "[%s] %s:%s: %s",
925 netid, hostp, spec,
926 clnt_spcreateerror("RPCPROG_NFS"));
927 return (returncode(rpc_createerr.cf_stat,
928 &rpc_createerr.cf_error));
929 }
930 }
931
932 /* Check that the server (nfsd) responds on the port we have chosen. */
918 hostp)) {
919 if (rpc_createerr.cf_stat == RPC_PROGVERSMISMATCH &&
920 trymntmode == ANY) {
921 trymntmode = V2;
922 goto tryagain;
923 }
924 snprintf(errbuf, sizeof errbuf, "[%s] %s:%s: %s",
925 netid, hostp, spec,
926 clnt_spcreateerror("RPCPROG_NFS"));
927 return (returncode(rpc_createerr.cf_stat,
928 &rpc_createerr.cf_error));
929 }
930 }
931
932 /* Check that the server (nfsd) responds on the port we have chosen. */
933 clp = clnt_tli_create(RPC_ANYFD, nconf, &nfs_nb, RPCPROG_NFS, nfsvers,
933 clp = clnt_tli_create(RPC_ANYFD, nconf, &nfs_nb, NFS_PROGRAM, nfsvers,
934 0, 0);
935 if (clp == NULL) {
936 snprintf(errbuf, sizeof errbuf, "[%s] %s:%s: %s", netid,
937 hostp, spec, clnt_spcreateerror("nfsd: RPCPROG_NFS"));
938 return (returncode(rpc_createerr.cf_stat,
939 &rpc_createerr.cf_error));
940 }
941 if (sotype == SOCK_DGRAM && noconn == 0) {

--- 49 unchanged lines hidden (view full) ---

991 if (secname != NULL)
992 build_iovec(iov, iovlen, "sec", secname, (size_t)-1);
993 build_iovec(iov, iovlen, "nfsv4", NULL, 0);
994 build_iovec(iov, iovlen, "dirpath", spec, (size_t)-1);
995
996 return (TRYRET_SUCCESS);
997 }
998
934 0, 0);
935 if (clp == NULL) {
936 snprintf(errbuf, sizeof errbuf, "[%s] %s:%s: %s", netid,
937 hostp, spec, clnt_spcreateerror("nfsd: RPCPROG_NFS"));
938 return (returncode(rpc_createerr.cf_stat,
939 &rpc_createerr.cf_error));
940 }
941 if (sotype == SOCK_DGRAM && noconn == 0) {

--- 49 unchanged lines hidden (view full) ---

991 if (secname != NULL)
992 build_iovec(iov, iovlen, "sec", secname, (size_t)-1);
993 build_iovec(iov, iovlen, "nfsv4", NULL, 0);
994 build_iovec(iov, iovlen, "dirpath", spec, (size_t)-1);
995
996 return (TRYRET_SUCCESS);
997 }
998
999 /* Send the RPCMNT_MOUNT RPC to get the root filehandle. */
999 /* Send the MOUNTPROC_MNT RPC to get the root filehandle. */
1000 try.tv_sec = 10;
1001 try.tv_usec = 0;
1000 try.tv_sec = 10;
1001 try.tv_usec = 0;
1002 clp = clnt_tp_create(hostp, RPCPROG_MNT, mntvers, nconf_mnt);
1002 clp = clnt_tp_create(hostp, MOUNTPROG, mntvers, nconf_mnt);
1003 if (clp == NULL) {
1004 snprintf(errbuf, sizeof errbuf, "[%s] %s:%s: %s", netid_mnt,
1005 hostp, spec, clnt_spcreateerror("RPCMNT: clnt_create"));
1006 return (returncode(rpc_createerr.cf_stat,
1007 &rpc_createerr.cf_error));
1008 }
1009 clp->cl_auth = authsys_create_default();
1010 nfhret.auth = secflavor;
1011 nfhret.vers = mntvers;
1003 if (clp == NULL) {
1004 snprintf(errbuf, sizeof errbuf, "[%s] %s:%s: %s", netid_mnt,
1005 hostp, spec, clnt_spcreateerror("RPCMNT: clnt_create"));
1006 return (returncode(rpc_createerr.cf_stat,
1007 &rpc_createerr.cf_error));
1008 }
1009 clp->cl_auth = authsys_create_default();
1010 nfhret.auth = secflavor;
1011 nfhret.vers = mntvers;
1012 stat = clnt_call(clp, RPCMNT_MOUNT, (xdrproc_t)xdr_dir, spec,
1012 stat = clnt_call(clp, MOUNTPROC_MNT, (xdrproc_t)xdr_dir, spec,
1013 (xdrproc_t)xdr_fh, &nfhret,
1014 try);
1015 auth_destroy(clp->cl_auth);
1016 if (stat != RPC_SUCCESS) {
1017 if (stat == RPC_PROGVERSMISMATCH && trymntmode == ANY) {
1018 clnt_destroy(clp);
1019 trymntmode = V2;
1020 goto tryagain;

--- 121 unchanged lines hidden (view full) ---

1142}
1143
1144/*
1145 * xdr routines for mount rpc's
1146 */
1147int
1148xdr_dir(XDR *xdrsp, char *dirp)
1149{
1013 (xdrproc_t)xdr_fh, &nfhret,
1014 try);
1015 auth_destroy(clp->cl_auth);
1016 if (stat != RPC_SUCCESS) {
1017 if (stat == RPC_PROGVERSMISMATCH && trymntmode == ANY) {
1018 clnt_destroy(clp);
1019 trymntmode = V2;
1020 goto tryagain;

--- 121 unchanged lines hidden (view full) ---

1142}
1143
1144/*
1145 * xdr routines for mount rpc's
1146 */
1147int
1148xdr_dir(XDR *xdrsp, char *dirp)
1149{
1150 return (xdr_string(xdrsp, &dirp, RPCMNT_PATHLEN));
1150 return (xdr_string(xdrsp, &dirp, MNTPATHLEN));
1151}
1152
1153int
1154xdr_fh(XDR *xdrsp, struct nfhret *np)
1155{
1156 int i;
1157 long auth, authcnt, authfnd = 0;
1158
1159 if (!xdr_u_long(xdrsp, &np->stat))
1160 return (0);
1161 if (np->stat)
1162 return (1);
1163 switch (np->vers) {
1164 case 1:
1151}
1152
1153int
1154xdr_fh(XDR *xdrsp, struct nfhret *np)
1155{
1156 int i;
1157 long auth, authcnt, authfnd = 0;
1158
1159 if (!xdr_u_long(xdrsp, &np->stat))
1160 return (0);
1161 if (np->stat)
1162 return (1);
1163 switch (np->vers) {
1164 case 1:
1165 np->fhsize = NFSX_V2FH;
1166 return (xdr_opaque(xdrsp, (caddr_t)np->nfh, NFSX_V2FH));
1165 np->fhsize = NFS_FHSIZE;
1166 return (xdr_opaque(xdrsp, (caddr_t)np->nfh, NFS_FHSIZE));
1167 case 3:
1168 if (!xdr_long(xdrsp, &np->fhsize))
1169 return (0);
1167 case 3:
1168 if (!xdr_long(xdrsp, &np->fhsize))
1169 return (0);
1170 if (np->fhsize <= 0 || np->fhsize > NFSX_V3FHMAX)
1170 if (np->fhsize <= 0 || np->fhsize > NFS3_FHSIZE)
1171 return (0);
1172 if (!xdr_opaque(xdrsp, (caddr_t)np->nfh, np->fhsize))
1173 return (0);
1174 if (!xdr_long(xdrsp, &authcnt))
1175 return (0);
1176 for (i = 0; i < authcnt; i++) {
1177 if (!xdr_long(xdrsp, &auth))
1178 return (0);

--- 30 unchanged lines hidden ---
1171 return (0);
1172 if (!xdr_opaque(xdrsp, (caddr_t)np->nfh, np->fhsize))
1173 return (0);
1174 if (!xdr_long(xdrsp, &authcnt))
1175 return (0);
1176 for (i = 0; i < authcnt; i++) {
1177 if (!xdr_long(xdrsp, &auth))
1178 return (0);

--- 30 unchanged lines hidden ---