2 * SPDX-License-Identifier: BSD-4-Clause
4 * Copyright (c) 1995, 1996
5 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Bill Paul.
18 * 4. Neither the name of the author nor the names of any co-contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
45 #include <sys/types.h>
46 #include <sys/param.h>
48 #include <sys/fcntl.h>
49 #include <machine/endian.h>
50 #include "ypxfrd_extern.h"
57 xdr_my_xfr(register XDR *xdrs, xfr *objp)
59 unsigned char buf[XFRBLOCKSIZE];
62 if ((objp->xfr_u.xfrblock_buf.xfrblock_buf_len =
63 read(fp, &buf, XFRBLOCKSIZE)) != -1) {
65 objp->xfr_u.xfrblock_buf.xfrblock_buf_val = (char *)&buf;
68 objp->xfr_u.xfrstat = XFR_READ_ERR;
69 yp_error("read error: %s", strerror(errno));
73 if (!xdr_xfr(xdrs, objp))
75 if (objp->ok == FALSE)
77 if (objp->xfr_u.xfrblock_buf.xfrblock_buf_len < XFRBLOCKSIZE) {
79 objp->xfr_u.xfrstat = XFR_DONE;
80 if (!xdr_xfr(xdrs, objp))
88 ypxfrd_getmap_1_svc(ypxfr_mapname *argp, struct svc_req *rqstp)
90 static struct xfr result;
94 result.xfr_u.xfrstat = XFR_DENIED;
96 if (yp_validdomain(argp->xfrdomain)) {
100 if (yp_access(argp->xfrmap, (struct svc_req *)rqstp)) {
104 snprintf (buf, sizeof(buf), "%s/%s/%s", yp_dir, argp->xfrdomain,
106 if (access(buf, R_OK) == -1) {
107 result.xfr_u.xfrstat = XFR_ACCESS;
111 if (argp->xfr_db_type != XFR_DB_BSD_HASH &&
112 argp->xfr_db_type != XFR_DB_ANY) {
113 result.xfr_u.xfrstat = XFR_DB_TYPE_MISMATCH;
117 #if BYTE_ORDER == LITTLE_ENDIAN
118 if (argp->xfr_byte_order == XFR_ENDIAN_BIG) {
120 if (argp->xfr_byte_order == XFR_ENDIAN_LITTLE) {
122 result.xfr_u.xfrstat = XFR_DB_ENDIAN_MISMATCH;
127 if (children < MAX_CHILDREN && fork()) {
135 if ((fp = open(buf, O_RDONLY)) == -1) {
136 result.xfr_u.xfrstat = XFR_READ_ERR;
140 /* Start sending the file. */
142 svc_sendreply(rqstp->rq_xprt, (xdrproc_t)xdr_my_xfr, &result);