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
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
40 #include <arpa/inet.h>
42 #include <rpcsvc/rwall.h>
43 #include <sys/socket.h>
44 #include <sys/types.h>
49 #define WALL_CMD "/usr/sbin/wall"
51 #define WALL_CMD "/usr/bin/wall -n"
54 void wallprog_1(struct svc_req *rqstp, SVCXPRT *transp);
56 void killkids(int sig);
57 static void usage(void);
63 main(int argc, char *argv[])
68 struct sockaddr_storage sa;
70 if (argc == 2 && !strcmp(argv[1], "-n"))
72 if (argc != 1 && !nodaemon)
76 struct passwd *pep = getpwnam("nobody");
84 * See if inetd started us
87 if (getsockname(0, (struct sockaddr *)&sa, &salen) < 0) {
95 (void)rpcb_unset(WALLPROG, WALLVERS, NULL);
98 (void)signal(SIGCHLD, killkids);
100 openlog("rpc.rwalld", LOG_CONS|LOG_PID, LOG_DAEMON);
102 /* create and register the service */
104 transp = svc_tli_create(0, NULL, NULL, 0, 0);
105 if (transp == NULL) {
106 syslog(LOG_ERR, "couldn't create udp service.");
109 ok = svc_reg(transp, WALLPROG, WALLVERS,
112 ok = svc_create(wallprog_1,
113 WALLPROG, WALLVERS, "udp");
115 syslog(LOG_ERR, "unable to register (WALLPROG, WALLVERS, %s)", (!from_inetd)?"udp":"(inetd)");
119 syslog(LOG_ERR, "svc_run returned");
126 fprintf(stderr, "usage: rpc.rwalld [-n]\n");
137 killkids(int sig __unused)
139 while(wait4(-1, NULL, WNOHANG, NULL) > 0)
144 wallproc_wall_1_svc(wrapstring *s, struct svc_req *rqstp __unused)
146 static void *dummy = NULL;
148 /* fork, popen wall with special option, and send the message */
152 pfp = popen(WALL_CMD, "w");
154 fprintf(pfp, "\007\007%s", *s);
163 wallprog_1(struct svc_req *rqstp, SVCXPRT *transp)
166 char *wallproc_wall_1_arg;
169 bool_t (*xdr_argument)(), (*xdr_result)();
172 switch (rqstp->rq_proc) {
174 (void)svc_sendreply(transp, (xdrproc_t)xdr_void, NULL);
178 xdr_argument = xdr_wrapstring;
179 xdr_result = xdr_void;
180 local = (char *(*)()) wallproc_wall_1_svc;
184 svcerr_noproc(transp);
187 bzero(&argument, sizeof(argument));
188 if (!svc_getargs(transp, (xdrproc_t)xdr_argument, &argument)) {
189 svcerr_decode(transp);
192 result = (*local)(&argument, rqstp);
193 if (result != NULL &&
194 !svc_sendreply(transp, (xdrproc_t)xdr_result, result)) {
195 svcerr_systemerr(transp);
197 if (!svc_freeargs(transp, (xdrproc_t)xdr_argument, &argument)) {
198 syslog(LOG_ERR, "unable to free arguments");