rusersd.c revision 31422
12061Sjkh/*- 217962Speter * Copyright (c) 1993, John Brezak 32061Sjkh * All rights reserved. 42061Sjkh * 515603Smarkm * Redistribution and use in source and binary forms, with or without 62061Sjkh * modification, are permitted provided that the following conditions 72061Sjkh * are met: 83197Scsgr * 1. Redistributions of source code must retain the above copyright 93197Scsgr * notice, this list of conditions and the following disclaimer. 102061Sjkh * 2. Redistributions in binary form must reproduce the above copyright 1112483Speter * notice, this list of conditions and the following disclaimer in the 122160Scsgr * documentation and/or other materials provided with the distribution. 132834Swollman * 3. All advertising materials mentioning features or use of this software 142061Sjkh * must display the following acknowledgement: 152061Sjkh * This product includes software developed by the University of 162160Scsgr * California, Berkeley and its contributors. 1717308Speter * 4. Neither the name of the University nor the names of its contributors 181594Srgrimes * may be used to endorse or promote products derived from this software 1917308Speter * without specific prior written permission. 2017308Speter * 2117308Speter * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2217308Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2317308Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2417308Speter * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2517308Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2617308Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2717308Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2817308Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2917308Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 302061Sjkh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 312061Sjkh * SUCH DAMAGE. 321594Srgrimes */ 337407Srgrimes 347407Srgrimes#ifndef lint 357108Sphkstatic const char rcsid[] = 367108Sphk "$Id$"; 377108Sphk#endif /* not lint */ 387407Srgrimes 397407Srgrimes#include <stdio.h> 407407Srgrimes#include <stdlib.h> 417108Sphk#include <rpc/rpc.h> 422061Sjkh#include <rpc/pmap_clnt.h> 432061Sjkh#include <signal.h> 442061Sjkh#include <syslog.h> 4517308Speter#define utmp rutmp 462061Sjkh#include <rpcsvc/rnusers.h> 472061Sjkh#undef utmp 482061Sjkh 492061Sjkhextern void rusers_service(); 502061Sjkh 513197Scsgrint from_inetd = 1; 522626Scsgr 532626Scsgrvoid 542061Sjkhcleanup() 552061Sjkh{ 562061Sjkh (void) pmap_unset(RUSERSPROG, RUSERSVERS_IDLE); 572061Sjkh (void) pmap_unset(RUSERSPROG, RUSERSVERS_ORIG); 582061Sjkh exit(0); 592061Sjkh} 602061Sjkh 612061Sjkhint 622061Sjkhmain(argc, argv) 632061Sjkh int argc; 642061Sjkh char *argv[]; 652061Sjkh{ 662061Sjkh SVCXPRT *transp; 672061Sjkh int sock = 0; 682061Sjkh int proto = 0; 692061Sjkh struct sockaddr_in from; 702061Sjkh int fromlen; 712061Sjkh 722834Swollman /* 732834Swollman * See if inetd started us 742834Swollman */ 752834Swollman fromlen = sizeof(from); 762834Swollman if (getsockname(0, (struct sockaddr *)&from, &fromlen) < 0) { 772834Swollman from_inetd = 0; 781594Srgrimes sock = RPC_ANYSOCK; 794486Sphk proto = IPPROTO_UDP; 804486Sphk } 814486Sphk 824486Sphk if (!from_inetd) { 834486Sphk daemon(0, 0); 842061Sjkh 852061Sjkh (void) pmap_unset(RUSERSPROG, RUSERSVERS_IDLE); 862061Sjkh (void) pmap_unset(RUSERSPROG, RUSERSVERS_ORIG); 872061Sjkh 882061Sjkh (void) signal(SIGINT, cleanup); 892061Sjkh (void) signal(SIGTERM, cleanup); 902061Sjkh (void) signal(SIGHUP, cleanup); 912061Sjkh } 922061Sjkh 9317308Speter openlog("rpc.rusersd", LOG_CONS|LOG_PID, LOG_DAEMON); 942061Sjkh 952061Sjkh transp = svcudp_create(sock); 962061Sjkh if (transp == NULL) { 972061Sjkh syslog(LOG_ERR, "cannot create udp service"); 982061Sjkh exit(1); 9912483Speter } 10012483Speter if (!svc_register(transp, RUSERSPROG, RUSERSVERS_IDLE, rusers_service, proto)) { 10112483Speter syslog(LOG_ERR, "unable to register (RUSERSPROG, RUSERSVERS_IDLE, %s)", proto?"udp":"(inetd)"); 10212483Speter exit(1); 1032061Sjkh } 1042061Sjkh 1058854Srgrimes if (!svc_register(transp, RUSERSPROG, RUSERSVERS_ORIG, rusers_service, proto)) { 1062061Sjkh syslog(LOG_ERR, "unable to register (RUSERSPROG, RUSERSVERS_ORIG, %s)", proto?"udp":"(inetd)"); 1072061Sjkh exit(1); 10812483Speter } 1092061Sjkh 11017308Speter svc_run(); 11117308Speter syslog(LOG_ERR, "svc_run returned"); 11217308Speter exit(1); 11317308Speter} 11415603Smarkm