1 /* $OpenBSD: yppush_svc.c,v 1.13 2009/10/27 23:59:58 deraadt Exp $ */ 2 3 /* 4 * Copyright (c) 1996 Mats O Jansson <moj@stacken.kth.se> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 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 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 17 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #include <sys/types.h> 30 #include <sys/ttycom.h> 31 #include <sys/socket.h> 32 #include <netinet/in.h> 33 #include <stdio.h> 34 #include <stdlib.h> 35 #include <netdb.h> 36 #include <memory.h> 37 #include <syslog.h> 38 #include <rpcsvc/yp.h> 39 40 #include "yppush.h" 41 42 #ifdef DEBUG 43 #define RPC_SVC_FG 44 #endif 45 46 #define _RPCSVC_CLOSEDOWN 120 47 int _rpcpmstart; /* Started by a port monitor ? */ 48 int _rpcfdtype; /* Whether Stream or Datagram ? */ 49 int _rpcsvcdirty; /* Still serving ? */ 50 51 static 52 void _msgout(char *msg) 53 { 54 #ifdef RPC_SVC_FG 55 if (_rpcpmstart) 56 syslog(LOG_ERR, "%s", msg); 57 else 58 (void) fprintf(stderr, "%s\n", msg); 59 #else 60 syslog(LOG_ERR, "%s", msg); 61 #endif 62 } 63 64 void 65 yppush_xfrrespprog_1(struct svc_req *rqstp, SVCXPRT *transp) 66 { 67 union argument { 68 int fill; 69 } argument; 70 char *result; 71 xdrproc_t xdr_argument, xdr_result; 72 char *(*local)(union argument *, struct svc_req *); 73 74 _rpcsvcdirty = 1; 75 switch (rqstp->rq_proc) { 76 case YPPUSHPROC_NULL: 77 xdr_argument = xdr_void; 78 xdr_result = xdr_void; 79 local = (char *(*)(union argument *, struct svc_req *)) 80 yppushproc_null_1_svc; 81 break; 82 83 case YPPUSHPROC_XFRRESP: 84 xdr_argument = xdr_yppushresp_xfr; 85 xdr_result = xdr_void; 86 local = (char *(*)(union argument *, struct svc_req *)) 87 yppushproc_xfrresp_1_svc; 88 break; 89 90 default: 91 svcerr_noproc(transp); 92 _rpcsvcdirty = 0; 93 exit(1); 94 return; 95 } 96 (void) memset(&argument, 0, sizeof(argument)); 97 if (!svc_getargs(transp, xdr_argument, (caddr_t)&argument)) { 98 svcerr_decode(transp); 99 _rpcsvcdirty = 0; 100 exit(1); 101 return; 102 } 103 result = (*local)(&argument, rqstp); 104 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) { 105 svcerr_systemerr(transp); 106 } 107 if (!svc_freeargs(transp, xdr_argument, (caddr_t)&argument)) { 108 _msgout("unable to free arguments"); 109 exit(1); 110 } 111 _rpcsvcdirty = 0; 112 if (rqstp->rq_proc!=YPPUSHPROC_NULL) 113 exit(0); 114 } 115