Deleted Added
full compact
nfs_prot_svc.c (131706) nfs_prot_svc.c (174313)
1/*
1/*
2 * Copyright (c) 1997-2004 Erez Zadok
2 * Copyright (c) 1997-2006 Erez Zadok
3 * Copyright (c) 1989 Jan-Simon Pendry
4 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
5 * Copyright (c) 1989 The Regents of the University of California.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry at Imperial College, London.
10 *

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

31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
3 * Copyright (c) 1989 Jan-Simon Pendry
4 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
5 * Copyright (c) 1989 The Regents of the University of California.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry at Imperial College, London.
10 *

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

31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * %W% (Berkeley) %G%
40 *
39 *
41 * $Id: nfs_prot_svc.c,v 1.5.2.6 2004/01/21 04:04:58 ib42 Exp $
42 * $FreeBSD: head/contrib/amd/amd/nfs_prot_svc.c 131706 2004-07-06 13:16:49Z mbr $
40 * File: am-utils/amd/nfs_prot_svc.c
43 *
44 */
45
46#ifdef HAVE_CONFIG_H
47# include <config.h>
48#endif /* HAVE_CONFIG_H */
49#include <am_defs.h>
50#include <amd.h>

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

65extern nfsstat *nfsproc_link_2_svc(nfslinkargs *, struct svc_req *);
66extern nfsstat *nfsproc_symlink_2_svc(nfssymlinkargs *, struct svc_req *);
67extern nfsdiropres *nfsproc_mkdir_2_svc(nfscreateargs *, struct svc_req *);
68extern nfsstat *nfsproc_rmdir_2_svc(nfsdiropargs *, struct svc_req *);
69extern nfsreaddirres *nfsproc_readdir_2_svc(nfsreaddirargs *, struct svc_req *);
70extern nfsstatfsres *nfsproc_statfs_2_svc(am_nfs_fh *, struct svc_req *);
71
72/* global variables */
41 *
42 */
43
44#ifdef HAVE_CONFIG_H
45# include <config.h>
46#endif /* HAVE_CONFIG_H */
47#include <am_defs.h>
48#include <amd.h>

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

63extern nfsstat *nfsproc_link_2_svc(nfslinkargs *, struct svc_req *);
64extern nfsstat *nfsproc_symlink_2_svc(nfssymlinkargs *, struct svc_req *);
65extern nfsdiropres *nfsproc_mkdir_2_svc(nfscreateargs *, struct svc_req *);
66extern nfsstat *nfsproc_rmdir_2_svc(nfsdiropargs *, struct svc_req *);
67extern nfsreaddirres *nfsproc_readdir_2_svc(nfsreaddirargs *, struct svc_req *);
68extern nfsstatfsres *nfsproc_statfs_2_svc(am_nfs_fh *, struct svc_req *);
69
70/* global variables */
73SVCXPRT *nfs_program_2_transp;
71SVCXPRT *current_transp;
74
75/* typedefs */
76typedef char *(*nfssvcproc_t)(voidp, struct svc_req *);
77
78
79void
80nfs_program_2(struct svc_req *rqstp, SVCXPRT *transp)
81{

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

94 nfscreateargs nfsproc_mkdir_2_arg;
95 nfsdiropargs fsproc_rmdir_2_arg;
96 nfsreaddirargs nfsproc_readdir_2_arg;
97 am_nfs_fh nfsproc_statfs_2_arg;
98 } argument;
99 char *result;
100 xdrproc_t xdr_argument, xdr_result;
101 nfssvcproc_t local;
72
73/* typedefs */
74typedef char *(*nfssvcproc_t)(voidp, struct svc_req *);
75
76
77void
78nfs_program_2(struct svc_req *rqstp, SVCXPRT *transp)
79{

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

92 nfscreateargs nfsproc_mkdir_2_arg;
93 nfsdiropargs fsproc_rmdir_2_arg;
94 nfsreaddirargs nfsproc_readdir_2_arg;
95 am_nfs_fh nfsproc_statfs_2_arg;
96 } argument;
97 char *result;
98 xdrproc_t xdr_argument, xdr_result;
99 nfssvcproc_t local;
100
101#ifdef HAVE_TRANSPORT_TYPE_TLI
102 /*
103 * On TLI systems we don't use an INET network type, but a "ticlts" (see
104 * /etc/netconfig and conf/transp_tli.c:create_nfs_service). This means
105 * that packets could only come from the loopback interface, and we don't
106 * need to check them and filter possibly spoofed packets. Therefore we
107 * only need to check if the UID caller is correct.
108 */
109# ifdef HAVE___RPC_GET_LOCAL_UID
110 uid_t u;
111 /* extern definition for an internal libnsl function */
112 extern int __rpc_get_local_uid(SVCXPRT *transp, uid_t *uid);
113 if (__rpc_get_local_uid(transp, &u) >= 0 && u != 0) {
114 plog(XLOG_WARNING, "ignoring request from UID %ld, must be 0", (long) u);
115 return;
116 }
117# else /* not HAVE___RPC_GET_LOCAL_UID */
118 dlog("cannot verify local uid for rpc request");
119# endif /* HAVE___RPC_GET_LOCAL_UID */
120#else /* not HAVE_TRANPORT_TYPE_TLI */
102 struct sockaddr_in *sinp;
103 char dq[20], dq2[28];
121 struct sockaddr_in *sinp;
122 char dq[20], dq2[28];
104
105 sinp = amu_svc_getcaller(rqstp->rq_xprt);
123 sinp = amu_svc_getcaller(rqstp->rq_xprt);
106#ifdef MNT2_NFS_OPT_RESVPORT
124# ifdef MNT2_NFS_OPT_RESVPORT
107 /* Verify that the request comes from a reserved port */
125 /* Verify that the request comes from a reserved port */
108 if ((ntohs(sinp->sin_port) >= IPPORT_RESERVED) &&
126 if (sinp &&
127 ntohs(sinp->sin_port) >= IPPORT_RESERVED &&
109 !(gopt.flags & CFM_NFS_INSECURE_PORT)) {
110 plog(XLOG_WARNING, "ignoring request from %s:%u, port not reserved",
128 !(gopt.flags & CFM_NFS_INSECURE_PORT)) {
129 plog(XLOG_WARNING, "ignoring request from %s:%u, port not reserved",
111 inet_dquad(dq, sinp->sin_addr.s_addr),
130 inet_dquad(dq, sizeof(dq), sinp->sin_addr.s_addr),
112 ntohs(sinp->sin_port));
113 return;
114 }
131 ntohs(sinp->sin_port));
132 return;
133 }
115#endif /* MNT2_NFS_OPT_RESVPORT */
134# endif /* MNT2_NFS_OPT_RESVPORT */
116 /* if the address does not match, ignore the request */
135 /* if the address does not match, ignore the request */
117 if (sinp->sin_addr.s_addr && sinp->sin_addr.s_addr != myipaddr.s_addr) {
118 plog(XLOG_WARNING, "ignoring request from %s:%u, expected %s",
119 inet_dquad(dq, sinp->sin_addr.s_addr),
120 ntohs(sinp->sin_port),
121 inet_dquad(dq2, myipaddr.s_addr));
122 return;
136 if (sinp && (sinp->sin_addr.s_addr != myipaddr.s_addr)) {
137 if (gopt.flags & CFM_NFS_ANY_INTERFACE) {
138 if (!is_interface_local(sinp->sin_addr.s_addr)) {
139 plog(XLOG_WARNING, "ignoring request from %s:%u, not a local interface",
140 inet_dquad(dq, sizeof(dq), sinp->sin_addr.s_addr),
141 ntohs(sinp->sin_port));
142 }
143 } else {
144 plog(XLOG_WARNING, "ignoring request from %s:%u, expected %s",
145 inet_dquad(dq, sizeof(dq), sinp->sin_addr.s_addr),
146 ntohs(sinp->sin_port),
147 inet_dquad(dq2, sizeof(dq2), myipaddr.s_addr));
148 return;
149 }
123 }
150 }
151#endif /* not HAVE_TRANPORT_TYPE_TLI */
124
152
125 nfs_program_2_transp = NULL;
153 current_transp = NULL;
126
127 switch (rqstp->rq_proc) {
128
129 case NFSPROC_NULL:
130 xdr_argument = (xdrproc_t) xdr_void;
131 xdr_result = (xdrproc_t) xdr_void;
132 local = (nfssvcproc_t) nfsproc_null_2_svc;
133 break;

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

154 xdr_argument = (xdrproc_t) xdr_diropargs;
155 xdr_result = (xdrproc_t) xdr_diropres;
156 local = (nfssvcproc_t) nfsproc_lookup_2_svc;
157 /*
158 * Cheap way to pass transp down to amfs_auto_lookuppn so it can
159 * be stored in the am_node structure and later used for
160 * quick_reply().
161 */
154
155 switch (rqstp->rq_proc) {
156
157 case NFSPROC_NULL:
158 xdr_argument = (xdrproc_t) xdr_void;
159 xdr_result = (xdrproc_t) xdr_void;
160 local = (nfssvcproc_t) nfsproc_null_2_svc;
161 break;

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

182 xdr_argument = (xdrproc_t) xdr_diropargs;
183 xdr_result = (xdrproc_t) xdr_diropres;
184 local = (nfssvcproc_t) nfsproc_lookup_2_svc;
185 /*
186 * Cheap way to pass transp down to amfs_auto_lookuppn so it can
187 * be stored in the am_node structure and later used for
188 * quick_reply().
189 */
162 nfs_program_2_transp = transp;
190 current_transp = transp;
163 break;
164
165 case NFSPROC_READLINK:
166 xdr_argument = (xdrproc_t) xdr_nfs_fh;
167 xdr_result = (xdrproc_t) xdr_readlinkres;
168 local = (nfssvcproc_t) nfsproc_readlink_2_svc;
169 break;
170

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

252 plog(XLOG_ERROR,
253 "NFS xdr decode failed for %d %d %d",
254 (int) rqstp->rq_prog, (int) rqstp->rq_vers, (int) rqstp->rq_proc);
255 svcerr_decode(transp);
256 return;
257 }
258 result = (*local) (&argument, rqstp);
259
191 break;
192
193 case NFSPROC_READLINK:
194 xdr_argument = (xdrproc_t) xdr_nfs_fh;
195 xdr_result = (xdrproc_t) xdr_readlinkres;
196 local = (nfssvcproc_t) nfsproc_readlink_2_svc;
197 break;
198

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

280 plog(XLOG_ERROR,
281 "NFS xdr decode failed for %d %d %d",
282 (int) rqstp->rq_prog, (int) rqstp->rq_vers, (int) rqstp->rq_proc);
283 svcerr_decode(transp);
284 return;
285 }
286 result = (*local) (&argument, rqstp);
287
260 nfs_program_2_transp = NULL;
288 current_transp = NULL;
261
262 if (result != NULL && !svc_sendreply(transp,
263 (XDRPROC_T_TYPE) xdr_result,
264 result)) {
265 svcerr_systemerr(transp);
266 }
267 if (!svc_freeargs(transp,
268 (XDRPROC_T_TYPE) xdr_argument,
269 (SVC_IN_ARG_TYPE) & argument)) {
270 plog(XLOG_FATAL, "unable to free rpc arguments in nfs_program_2");
271 going_down(1);
272 }
273}
289
290 if (result != NULL && !svc_sendreply(transp,
291 (XDRPROC_T_TYPE) xdr_result,
292 result)) {
293 svcerr_systemerr(transp);
294 }
295 if (!svc_freeargs(transp,
296 (XDRPROC_T_TYPE) xdr_argument,
297 (SVC_IN_ARG_TYPE) & argument)) {
298 plog(XLOG_FATAL, "unable to free rpc arguments in nfs_program_2");
299 going_down(1);
300 }
301}