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