/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1993, John Brezak4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. Neither the name of the University nor the names of its contributors15* may be used to endorse or promote products derived from this software16* without specific prior written permission.17*18* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND19* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE22* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL23* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS24* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY27* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF28* SUCH DAMAGE.29*/3031#include <stdlib.h>32#include <rpc/rpc.h>33#include <sys/socket.h>34#include <signal.h>35#include <syslog.h>36#include <rpcsvc/rnusers.h>3738#include "extern.h"3940int from_inetd = 1;4142static void43cleanup(int sig __unused)44{45(void) rpcb_unset(RUSERSPROG, RUSERSVERS_IDLE, NULL);46(void) rpcb_unset(RUSERSPROG, RUSERSVERS_ORIG, NULL);47exit(0);48}4950int51main(int argc __unused, char *argv[] __unused)52{53SVCXPRT *transp = NULL; /* Keep compiler happy. */54int ok;55struct sockaddr_storage from;56socklen_t fromlen;5758/*59* See if inetd started us60*/61fromlen = sizeof(from);62if (getsockname(0, (struct sockaddr *)&from, &fromlen) < 0) {63from_inetd = 0;64}6566if (!from_inetd) {67daemon(0, 0);6869(void) rpcb_unset(RUSERSPROG, RUSERSVERS_IDLE, NULL);70(void) rpcb_unset(RUSERSPROG, RUSERSVERS_ORIG, NULL);7172(void) signal(SIGINT, cleanup);73(void) signal(SIGTERM, cleanup);74(void) signal(SIGHUP, cleanup);75}7677openlog("rpc.rusersd", LOG_CONS|LOG_PID, LOG_DAEMON);7879if (from_inetd) {80transp = svc_tli_create(0, NULL, NULL, 0, 0);81if (transp == NULL) {82syslog(LOG_ERR, "cannot create udp service.");83exit(1);84}85ok = svc_reg(transp, RUSERSPROG, RUSERSVERS_IDLE,86rusers_service, NULL);87} else88ok = svc_create(rusers_service,89RUSERSPROG, RUSERSVERS_IDLE, "udp");90if (!ok) {91syslog(LOG_ERR, "unable to register (RUSERSPROG, RUSERSVERS_IDLE, %s)", (!from_inetd)?"udp":"(inetd)");92exit(1);93}94if (from_inetd)95ok = svc_reg(transp, RUSERSPROG, RUSERSVERS_ORIG,96rusers_service, NULL);97else98ok = svc_create(rusers_service,99RUSERSPROG, RUSERSVERS_ORIG, "udp");100if (!ok) {101syslog(LOG_ERR, "unable to register (RUSERSPROG, RUSERSVERS_ORIG, %s)", (!from_inetd)?"udp":"(inetd)");102exit(1);103}104105svc_run();106syslog(LOG_ERR, "svc_run returned");107exit(1);108}109110111