1 /* $NetBSD: rwalld.c,v 1.19 2003/07/26 19:32:09 salo Exp $ */
4 * Copyright (c) 1993 Christopher G. Demetriou
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the
18 * NetBSD Project. See http://www.NetBSD.org/ for
19 * information about NetBSD.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
37 #include <sys/cdefs.h>
39 __RCSID("$NetBSD: rwalld.c,v 1.19 2003/07/26 19:32:09 salo Exp $");
44 #include <sys/types.h>
50 #include <sys/socket.h>
54 #include <rpcsvc/rwall.h>
57 #define WALL_CMD "/usr/sbin/wall"
59 #define WALL_CMD "/usr/bin/wall -n"
62 static int from_inetd
= 1;
64 static void cleanup(int);
65 static void wallprog_1(struct svc_req
*, SVCXPRT
*);
67 int main(int, char *[]);
73 (void)rpcb_unset(WALLPROG
, WALLVERS
, NULL
);
78 main(int argc
, char *argv
[])
81 struct sockaddr_storage from
;
85 struct passwd
*pep
= getpwnam("nobody");
93 * See if inetd started us
95 fromlen
= sizeof(from
);
96 if (getsockname(0, (struct sockaddr
*)&from
, &fromlen
) < 0)
102 (void) rpcb_unset(WALLPROG
, WALLVERS
, NULL
);
104 (void) signal(SIGINT
, cleanup
);
105 (void) signal(SIGTERM
, cleanup
);
106 (void) signal(SIGHUP
, cleanup
);
109 openlog("rpc.rwalld", LOG_PID
, LOG_DAEMON
);
112 transp
= svc_dg_create(0, 0, 0);
113 if (transp
== NULL
) {
114 syslog(LOG_ERR
, "cannot create udp service.");
117 if (!svc_reg(transp
, WALLPROG
, WALLVERS
, wallprog_1
, NULL
)) {
118 syslog(LOG_ERR
, "unable to register "
119 "(WALLPROG, WALLVERS).");
123 if (!svc_create(wallprog_1
, WALLPROG
, WALLVERS
, "udp")) {
124 syslog(LOG_ERR
, "unable to create "
125 "(WALLPROG, WALLVERS.)");
131 syslog(LOG_ERR
, "svc_run returned");
137 wallproc_wall_1_svc(char **s
, struct svc_req
*rqstp
)
141 pfp
= popen(WALL_CMD
, "w");
143 fprintf(pfp
, "\007\007%s", *s
);
151 wallprog_1(struct svc_req
*rqstp
, SVCXPRT
*transp
)
154 char *wallproc_wall_1_arg
;
157 xdrproc_t xdr_argument
, xdr_result
;
158 char *(*local
) __P((char **, struct svc_req
*));
160 switch (rqstp
->rq_proc
) {
162 (void)svc_sendreply(transp
, xdr_void
, (char *)NULL
);
166 xdr_argument
= (xdrproc_t
)xdr_wrapstring
;
167 xdr_result
= (xdrproc_t
)xdr_void
;
168 local
= (char *(*) __P((char **, struct svc_req
*)))
173 svcerr_noproc(transp
);
176 memset((char *)&argument
, 0, sizeof(argument
));
177 if (!svc_getargs(transp
, xdr_argument
, (caddr_t
)&argument
)) {
178 svcerr_decode(transp
);
181 result
= (*local
)((char **)&argument
, rqstp
);
182 if (result
!= NULL
&& !svc_sendreply(transp
, xdr_result
, result
)) {
183 svcerr_systemerr(transp
);
185 if (!svc_freeargs(transp
, xdr_argument
, (caddr_t
)&argument
)) {
186 syslog(LOG_ERR
, "unable to free arguments");