xref: /openbsd/usr.sbin/ypserv/yppush/yppush_svc.c (revision da449d5a)
1*da449d5aStedu /*	$OpenBSD: yppush_svc.c,v 1.15 2015/11/17 18:21:48 tedu Exp $ */
2bbfaf3a3Sderaadt 
363ab8f9cSdm /*
463ab8f9cSdm  * Copyright (c) 1996 Mats O Jansson <moj@stacken.kth.se>
563ab8f9cSdm  * All rights reserved.
663ab8f9cSdm  *
763ab8f9cSdm  * Redistribution and use in source and binary forms, with or without
863ab8f9cSdm  * modification, are permitted provided that the following conditions
963ab8f9cSdm  * are met:
1063ab8f9cSdm  * 1. Redistributions of source code must retain the above copyright
1163ab8f9cSdm  *    notice, this list of conditions and the following disclaimer.
1263ab8f9cSdm  * 2. Redistributions in binary form must reproduce the above copyright
1363ab8f9cSdm  *    notice, this list of conditions and the following disclaimer in the
1463ab8f9cSdm  *    documentation and/or other materials provided with the distribution.
1563ab8f9cSdm  *
1663ab8f9cSdm  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
1763ab8f9cSdm  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1863ab8f9cSdm  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1963ab8f9cSdm  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
2063ab8f9cSdm  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2163ab8f9cSdm  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2263ab8f9cSdm  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2363ab8f9cSdm  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2463ab8f9cSdm  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2563ab8f9cSdm  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2663ab8f9cSdm  * SUCH DAMAGE.
2763ab8f9cSdm  */
2863ab8f9cSdm 
29c4c5f39cSderaadt #include <sys/types.h>
3063ab8f9cSdm #include <sys/socket.h>
3163ab8f9cSdm #include <netinet/in.h>
32c4c5f39cSderaadt #include <stdio.h>
33c4c5f39cSderaadt #include <stdlib.h>
34c4c5f39cSderaadt #include <netdb.h>
35*da449d5aStedu #include <string.h>
3663ab8f9cSdm #include <syslog.h>
375325fcc5Sderaadt #include <rpcsvc/yp.h>
385325fcc5Sderaadt 
395325fcc5Sderaadt #include "yppush.h"
4063ab8f9cSdm 
4163ab8f9cSdm #ifdef DEBUG
4263ab8f9cSdm #define RPC_SVC_FG
4363ab8f9cSdm #endif
4463ab8f9cSdm 
4563ab8f9cSdm #define _RPCSVC_CLOSEDOWN 120
4663ab8f9cSdm int _rpcpmstart;		/* Started by a port monitor ? */
4763ab8f9cSdm int _rpcfdtype;			/* Whether Stream or Datagram ? */
4863ab8f9cSdm int _rpcsvcdirty;		/* Still serving ? */
4963ab8f9cSdm 
5063ab8f9cSdm static
_msgout(char * msg)5133dd5606Sderaadt void _msgout(char *msg)
5263ab8f9cSdm {
5363ab8f9cSdm #ifdef RPC_SVC_FG
5463ab8f9cSdm 	if (_rpcpmstart)
5549c64088Sderaadt 		syslog(LOG_ERR, "%s", msg);
5663ab8f9cSdm 	else
5763ab8f9cSdm 		(void) fprintf(stderr, "%s\n", msg);
5863ab8f9cSdm #else
5949c64088Sderaadt 	syslog(LOG_ERR, "%s", msg);
6063ab8f9cSdm #endif
6163ab8f9cSdm }
6263ab8f9cSdm 
6363ab8f9cSdm void
yppush_xfrrespprog_1(struct svc_req * rqstp,SVCXPRT * transp)6433dd5606Sderaadt yppush_xfrrespprog_1(struct svc_req *rqstp, SVCXPRT *transp)
6563ab8f9cSdm {
665325fcc5Sderaadt 	union argument {
6763ab8f9cSdm 		int fill;
6863ab8f9cSdm 	} argument;
6963ab8f9cSdm 	char *result;
705325fcc5Sderaadt 	xdrproc_t xdr_argument, xdr_result;
715325fcc5Sderaadt 	char *(*local)(union argument *, struct svc_req *);
7263ab8f9cSdm 
7363ab8f9cSdm 	_rpcsvcdirty = 1;
7463ab8f9cSdm 	switch (rqstp->rq_proc) {
7563ab8f9cSdm 	case YPPUSHPROC_NULL:
7663ab8f9cSdm 		xdr_argument = xdr_void;
7763ab8f9cSdm 		xdr_result = xdr_void;
785325fcc5Sderaadt 		local = (char *(*)(union argument *, struct svc_req *))
795325fcc5Sderaadt 		    yppushproc_null_1_svc;
8063ab8f9cSdm 		break;
8163ab8f9cSdm 
8263ab8f9cSdm 	case YPPUSHPROC_XFRRESP:
8363ab8f9cSdm 		xdr_argument = xdr_yppushresp_xfr;
8463ab8f9cSdm 		xdr_result = xdr_void;
855325fcc5Sderaadt 		local = (char *(*)(union argument *, struct svc_req *))
865325fcc5Sderaadt 		    yppushproc_xfrresp_1_svc;
8763ab8f9cSdm 		break;
8863ab8f9cSdm 
8963ab8f9cSdm 	default:
9063ab8f9cSdm 		svcerr_noproc(transp);
9163ab8f9cSdm 		_rpcsvcdirty = 0;
9263ab8f9cSdm 		exit(1);
9363ab8f9cSdm 		return;
9463ab8f9cSdm 	}
95fb92953eSderaadt 	(void) memset(&argument, 0, sizeof(argument));
9663ab8f9cSdm 	if (!svc_getargs(transp, xdr_argument, (caddr_t)&argument)) {
9763ab8f9cSdm 		svcerr_decode(transp);
9863ab8f9cSdm 		_rpcsvcdirty = 0;
9963ab8f9cSdm 		exit(1);
10063ab8f9cSdm 		return;
10163ab8f9cSdm 	}
10263ab8f9cSdm 	result = (*local)(&argument, rqstp);
10363ab8f9cSdm 	if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
10463ab8f9cSdm 		svcerr_systemerr(transp);
10563ab8f9cSdm 	}
10663ab8f9cSdm 	if (!svc_freeargs(transp, xdr_argument, (caddr_t)&argument)) {
10763ab8f9cSdm 		_msgout("unable to free arguments");
10863ab8f9cSdm 		exit(1);
10963ab8f9cSdm 	}
11063ab8f9cSdm 	_rpcsvcdirty = 0;
11163ab8f9cSdm 	if (rqstp->rq_proc!=YPPUSHPROC_NULL)
11263ab8f9cSdm 		exit(0);
11363ab8f9cSdm }
114