2 * Copyright (c) 1993 Christopher G. Demetriou
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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
14 * products derived from this software without specific prior written
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 static const char rcsid[] =
32 "$Id: rwalld.c,v 1.6 1997/12/02 12:20:17 charnier Exp $";
43 #include <rpc/pmap_clnt.h>
44 #include <rpcsvc/rwall.h>
45 #include <sys/socket.h>
46 #include <sys/types.h>
51 #define WALL_CMD "/usr/sbin/wall"
53 #define WALL_CMD "/usr/bin/wall -n"
59 static void usage __P((void));
71 struct sockaddr_in sa;
75 if (argc == 2 && !strcmp(argv[1], "-n"))
77 if (argc != 1 && !nodaemon)
81 struct passwd *pep = getpwnam("nobody");
89 * See if inetd started us
92 if (getsockname(0, (struct sockaddr *)&sa, &salen) < 0) {
102 (void)pmap_unset(WALLPROG, WALLVERS);
103 if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
105 bzero((char *)&sa, sizeof sa);
106 if (bind(s, (struct sockaddr *)&sa, sizeof sa) < 0)
110 if (getsockname(s, (struct sockaddr *)&sa, &salen))
111 err(1, "getsockname");
113 pmap_set(WALLPROG, WALLVERS, IPPROTO_UDP, ntohs(sa.sin_port));
116 (void)pmap_unset(WALLPROG, WALLVERS);
119 (void)signal(SIGCHLD, killkids);
121 openlog("rpc.rwalld", LOG_CONS|LOG_PID, LOG_DAEMON);
123 transp = svcudp_create(sock);
124 if (transp == NULL) {
125 syslog(LOG_ERR, "cannot create udp service");
128 if (!svc_register(transp, WALLPROG, WALLVERS, wallprog_1, proto)) {
129 syslog(LOG_ERR, "unable to register (WALLPROG, WALLVERS, %s)", proto?"udp":"(inetd)");
133 syslog(LOG_ERR, "svc_run returned");
140 fprintf(stderr, "usage: rpc.rwalld [-n]\n");
151 while(wait4(-1, NULL, WNOHANG, NULL) > 0)
155 void *wallproc_wall_1_svc(s, rqstp)
157 struct svc_req *rqstp;
159 static void *dummy = NULL;
161 /* fork, popen wall with special option, and send the message */
165 pfp = popen(WALL_CMD, "w");
167 fprintf(pfp, "\007\007%s", *s);
176 wallprog_1(rqstp, transp)
177 struct svc_req *rqstp;
181 char *wallproc_wall_1_arg;
184 bool_t (*xdr_argument)(), (*xdr_result)();
187 switch (rqstp->rq_proc) {
189 (void)svc_sendreply(transp, xdr_void, (char *)NULL);
193 xdr_argument = xdr_wrapstring;
194 xdr_result = xdr_void;
195 local = (char *(*)()) wallproc_wall_1_svc;
199 svcerr_noproc(transp);
202 bzero((char *)&argument, sizeof(argument));
203 if (!svc_getargs(transp, xdr_argument, (caddr_t)&argument)) {
204 svcerr_decode(transp);
207 result = (*local)(&argument, rqstp);
208 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) {
209 svcerr_systemerr(transp);
211 if (!svc_freeargs(transp, xdr_argument, (caddr_t)&argument)) {
212 syslog(LOG_ERR, "unable to free arguments");