ypxfrd_server.c revision 22997
10SN/A/* 24208SN/A * Copyright (c) 1995, 1996 30SN/A * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 40SN/A * 50SN/A * Redistribution and use in source and binary forms, with or without 60SN/A * modification, are permitted provided that the following conditions 70SN/A * are met: 80SN/A * 1. Redistributions of source code must retain the above copyright 90SN/A * notice, this list of conditions and the following disclaimer. 100SN/A * 2. Redistributions in binary form must reproduce the above copyright 110SN/A * notice, this list of conditions and the following disclaimer in the 120SN/A * documentation and/or other materials provided with the distribution. 130SN/A * 3. All advertising materials mentioning features or use of this software 140SN/A * must display the following acknowledgement: 150SN/A * This product includes software developed by Bill Paul. 160SN/A * 4. Neither the name of the author nor the names of any co-contributors 170SN/A * may be used to endorse or promote products derived from this software 180SN/A * without specific prior written permission. 191472SN/A * 201472SN/A * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 211472SN/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 220SN/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 230SN/A * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE 240SN/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 250SN/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 260SN/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 270SN/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 280SN/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 290SN/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 300SN/A * SUCH DAMAGE. 310SN/A * 320SN/A * $Id$ 330SN/A */ 340SN/A 350SN/A#include "ypxfrd.h" 360SN/A#ifndef lint 370SN/Astatic const char rcsid[] = "$Id$"; 380SN/A#endif /* not lint */ 390SN/A 400SN/A#include <stdio.h> 410SN/A#include <stdlib.h> 420SN/A#include <unistd.h> 431522SN/A#include <string.h> 441522SN/A#include <errno.h> 452307SN/A#include <sys/types.h> 461833SN/A#include <sys/param.h> 471522SN/A#include <sys/uio.h> 481522SN/A#include <sys/fcntl.h> 491522SN/A#include <machine/endian.h> 501522SN/A#include "ypxfrd_extern.h" 511522SN/A 521522SN/Aint forked = 0; 531522SN/Aint children = 0; 541522SN/Aint fp = 0; 551522SN/A 561522SN/Astatic bool_t 571522SN/Axdr_my_xfr(register XDR *xdrs, xfr *objp) 580SN/A{ 590SN/A unsigned char buf[XFRBLOCKSIZE]; 600SN/A 610SN/A while(1) { 620SN/A if ((objp->xfr_u.xfrblock_buf.xfrblock_buf_len = 630SN/A read(fp, &buf, XFRBLOCKSIZE)) != -1) { 643602SN/A objp->ok = TRUE; 653602SN/A objp->xfr_u.xfrblock_buf.xfrblock_buf_val = (char *)&buf; 663602SN/A } else { 673602SN/A objp->ok = FALSE; 683602SN/A objp->xfr_u.xfrstat = XFR_READ_ERR; 693602SN/A yp_error("read error: %s", strerror(errno)); 701385SN/A } 710SN/A 720SN/A /* Serialize */ 730SN/A if (!xdr_xfr(xdrs, objp)) 740SN/A return(FALSE); 750SN/A if (objp->ok == FALSE) 760SN/A return(TRUE); 770SN/A if (objp->xfr_u.xfrblock_buf.xfrblock_buf_len < XFRBLOCKSIZE) { 780SN/A objp->ok = FALSE; 790SN/A objp->xfr_u.xfrstat = XFR_DONE; 800SN/A if (!xdr_xfr(xdrs, objp)) 810SN/A return(FALSE); 820SN/A return(TRUE); 830SN/A } 840SN/A } 850SN/A} 860SN/A 870SN/Astruct xfr * 880SN/Aypxfrd_getmap_1_svc(ypxfr_mapname *argp, struct svc_req *rqstp) 890SN/A{ 900SN/A static struct xfr result; 910SN/A char buf[MAXPATHLEN]; 920SN/A 930SN/A result.ok = FALSE; 940SN/A result.xfr_u.xfrstat = XFR_DENIED; 950SN/A 960SN/A if (yp_validdomain(argp->xfrdomain)) { 970SN/A return(&result); 980SN/A } 990SN/A 1000SN/A if (yp_access(argp->xfrmap, (struct svc_req *)rqstp)) { 1010SN/A return(&result); 1020SN/A } 1030SN/A 1043602SN/A snprintf (buf, sizeof(buf), "%s/%s/%s", yp_dir, argp->xfrdomain, 1050SN/A argp->xfrmap); 1060SN/A if (access((char *)&buf, R_OK) == -1) { 1070SN/A result.xfr_u.xfrstat = XFR_ACCESS; 1080SN/A return(&result); 1090SN/A } 1100SN/A 1110SN/A if (argp->xfr_db_type != XFR_DB_BSD_HASH && 1120SN/A argp->xfr_db_type != XFR_DB_ANY) { 1130SN/A result.xfr_u.xfrstat = XFR_DB_TYPE_MISMATCH; 1140SN/A return(&result); 1150SN/A } 1160SN/A 1170SN/A#if BYTE_ORDER == LITTLE_ENDIAN 1180SN/A if (argp->xfr_byte_order == XFR_ENDIAN_BIG) { 1190SN/A#else 1200SN/A if (argp->xfr_byte_order == XFR_ENDIAN_LITTLE) { 1210SN/A#endif 1220SN/A result.xfr_u.xfrstat = XFR_DB_ENDIAN_MISMATCH; 1230SN/A return(&result); 1240SN/A } 1253602SN/A 1260SN/A#ifndef DEBUG 1270SN/A if (children < MAX_CHILDREN && fork()) { 1280SN/A children++; 1290SN/A forked = 0; 1300SN/A return (NULL); 1310SN/A } else { 1320SN/A forked++; 1330SN/A } 1340SN/A#endif 1353602SN/A if ((fp = open((char *)&buf, O_RDONLY)) == -1) { 1360SN/A result.xfr_u.xfrstat = XFR_READ_ERR; 1370SN/A return(&result); 1380SN/A } 1390SN/A 1400SN/A /* Start sending the file. */ 1410SN/A 1423602SN/A svc_sendreply(rqstp->rq_xprt, xdr_my_xfr, (char *)&result); 1430SN/A 1440SN/A close(fp); 1450SN/A 1460SN/A return (NULL); 1470SN/A} 1483368SN/A