* Copyright (c) 1993 Christopher G. Demetriou
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char rcsid
[] = "$Id: rwalld.c,v 1.2 1993/08/02 17:50:55 mycroft Exp $";
#include <rpcsvc/rwall.h>
#define WALL_CMD "/usr/sbin/wall"
#define WALL_CMD "/usr/bin/wall -n"
if (argc
== 2 && !strcmp(argv
[1], "-n"))
if (argc
!= 1 && !nodaemon
) {
printf("usage: %s [-n]\n", argv
[0]);
struct passwd
*pep
= getpwnam("nobody");
* See if inetd started us
if (getsockname(0, (struct sockaddr
*)&sa
, &salen
) < 0) {
(void)pmap_unset(WALLPROG
, WALLVERS
);
if ((s
= socket(AF_INET
, SOCK_DGRAM
, IPPROTO_UDP
)) < 0) {
bzero((char *)&sa
, sizeof sa
);
if (bind(s
, (struct sockaddr
*)&sa
, sizeof sa
) < 0) {
if (getsockname(s
, (struct sockaddr
*)&sa
, &salen
)) {
pmap_set(WALLPROG
, WALLVERS
, IPPROTO_UDP
, ntohs(sa
.sin_port
));
(void)pmap_unset(WALLPROG
, WALLVERS
);
(void)signal(SIGCHLD
, killkids
);
transp
= svcudp_create(sock
);
(void)fprintf(stderr
, "cannot create udp service.\n");
if (!svc_register(transp
, WALLPROG
, WALLVERS
, wallprog_1
, proto
)) {
(void)fprintf(stderr
, "unable to register (WALLPROG, WALLVERS, udp).\n");
(void)fprintf(stderr
, "svc_run returned\n");
while(wait4(-1, NULL
, WNOHANG
, NULL
) > 0)
/* fork, popen wall with special option, and send the message */
pfp
= popen(WALL_CMD
, "w");
fprintf(pfp
, "\007\007%s", *s
);
wallprog_1(rqstp
, transp
)
char *wallproc_wall_1_arg
;
bool_t (*xdr_argument
)(), (*xdr_result
)();
switch (rqstp
->rq_proc
) {
(void)svc_sendreply(transp
, xdr_void
, (char *)NULL
);
xdr_argument
= xdr_wrapstring
;
local
= (char *(*)()) wallproc_wall_1
;
bzero((char *)&argument
, sizeof(argument
));
if (!svc_getargs(transp
, xdr_argument
, &argument
)) {
result
= (*local
)(&argument
, rqstp
);
if (result
!= NULL
&& !svc_sendreply(transp
, xdr_result
, result
)) {
svcerr_systemerr(transp
);
if (!svc_freeargs(transp
, xdr_argument
, &argument
)) {
(void)fprintf(stderr
, "unable to free arguments\n");