Home | History | Annotate | Line # | Download | only in rpc.rusersd
rusersd.c revision 1.9
      1 /*	$NetBSD: rusersd.c,v 1.9 1996/08/30 20:19:45 thorpej Exp $	*/
      2 
      3 /*-
      4  *  Copyright (c) 1993 John Brezak
      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  *  3. The name of the author may not be used to endorse or promote products
     16  *     derived from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     21  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     22  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     27  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     28  * POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #ifndef lint
     32 static char rcsid[] = "$NetBSD: rusersd.c,v 1.9 1996/08/30 20:19:45 thorpej Exp $";
     33 #endif /* not lint */
     34 
     35 #include <stdio.h>
     36 #include <rpc/rpc.h>
     37 #include <signal.h>
     38 #include <syslog.h>
     39 #include <rpcsvc/rusers.h>	/* New version */
     40 #include <rpcsvc/rnusers.h>	/* Old version */
     41 
     42 extern void rusers_service();
     43 
     44 int from_inetd = 1;
     45 
     46 void
     47 cleanup()
     48 {
     49 	(void) pmap_unset(RUSERSPROG, RUSERSVERS_3);
     50 	(void) pmap_unset(RUSERSPROG, RUSERSVERS_IDLE);
     51 	exit(0);
     52 }
     53 
     54 main(argc, argv)
     55 	int argc;
     56 	char *argv[];
     57 {
     58 	SVCXPRT *transp;
     59 	int sock = 0;
     60 	int proto = 0;
     61 	struct sockaddr_in from;
     62 	int fromlen;
     63 
     64 	/*
     65 	 * See if inetd started us
     66 	 */
     67 	fromlen = sizeof(from);
     68 	if (getsockname(0, (struct sockaddr *)&from, &fromlen) < 0) {
     69 		from_inetd = 0;
     70 		sock = RPC_ANYSOCK;
     71 		proto = IPPROTO_UDP;
     72 	}
     73 
     74 	if (!from_inetd) {
     75 		daemon(0, 0);
     76 
     77 		(void) pmap_unset(RUSERSPROG, RUSERSVERS_3);
     78 		(void) pmap_unset(RUSERSPROG, RUSERSVERS_IDLE);
     79 
     80 		(void) signal(SIGINT, cleanup);
     81 		(void) signal(SIGTERM, cleanup);
     82 		(void) signal(SIGHUP, cleanup);
     83 	}
     84 
     85 	openlog("rpc.rusersd", LOG_CONS|LOG_PID, LOG_DAEMON);
     86 
     87 	transp = svcudp_create(sock);
     88 	if (transp == NULL) {
     89 		syslog(LOG_ERR, "cannot create udp service.");
     90 		exit(1);
     91 	}
     92 	if (!svc_register(transp, RUSERSPROG, RUSERSVERS_3, rusers_service, proto)) {
     93 		syslog(LOG_ERR, "unable to register (RUSERSPROG, RUSERSVERS_3, %s).", proto?"udp":"(inetd)");
     94 		exit(1);
     95 	}
     96 	if (!svc_register(transp, RUSERSPROG, RUSERSVERS_IDLE, rusers_service, proto)) {
     97 		syslog(LOG_ERR, "unable to register (RUSERSPROG, RUSERSVERS_IDLE, %s).", proto?"udp":"(inetd)");
     98 		exit(1);
     99 	}
    100 
    101 	svc_run();
    102 	syslog(LOG_ERR, "svc_run returned");
    103 	exit(1);
    104 }
    105