1 /* $NetBSD: faketalk.c,v 1.17 2009/07/04 07:51:35 dholland Exp $ */
3 * Copyright (c) 1983-2003, Regents of the University of California.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * + Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * + 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 * + Neither the name of the University of California, San Francisco nor
16 * the names of its contributors may be used to endorse or promote
17 * products derived from this software without specific prior written
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
35 __RCSID("$NetBSD: faketalk.c,v 1.17 2009/07/04 07:51:35 dholland Exp $");
41 #if defined(TALK_43) || defined(TALK_42)
56 /* defines for fake talk message to announce start of game */
58 #define MASQUERADE "\"Hunt Game\""
60 #define MASQUERADE "HuntGame"
62 #define RENDEZVOUS "hunt-players"
63 #define ARGV0 "HUNT-ANNOUNCE"
65 extern char *my_machine_name
;
66 extern char *First_arg
, *Last_arg
;
67 extern char **environ
;
69 static void do_announce(char *);
73 * exorcise - disspell zombies
77 exorcise(int dummy __unused
)
83 * query the local SMTP daemon to expand the RENDEZVOUS mailing list
84 * and fake a talk request to each address thus found.
93 int service
; /* socket of service */
94 struct sockaddr_in des
; /* address of destination */
97 (void) signal(SIGCHLD
, exorcise
);
102 (void) signal(SIGINT
, SIG_IGN
);
103 (void) signal(SIGPIPE
, SIG_IGN
);
106 * change argv so that a ps shows ARGV0
109 for (a
= First_arg
, b
= ARGV0
; a
< Last_arg
; a
++) {
119 get_local_name(MASQUERADE
);
123 * start fetching addresses
126 if ((sp
= getservbyname("smtp", NULL
)) == NULL
) {
128 syslog(LOG_ERR
, "faketalk: smtp protocol not supported\n");
130 warn("faketalk: stmp protocol not supported");
135 memset(&des
, 0, sizeof (des
));
136 des
.sin_family
= AF_INET
;
137 des
.sin_addr
= my_machine_addr
;
138 des
.sin_port
= sp
->s_port
;
140 if ((service
= socket(des
.sin_family
, SOCK_STREAM
, 0)) < 0) {
142 syslog(LOG_ERR
, "falktalk: socket");
144 warn("falktalk: socket");
149 if (connect(service
, (struct sockaddr
*) &des
, sizeof(des
)) != 0) {
151 syslog(LOG_ERR
, "faketalk: connect");
153 warn("faketalk: connect");
157 if ((f
= fdopen(service
, "r")) == NULL
) {
159 syslog(LOG_ERR
, "fdopen failed\n");
161 warn("faketalk: fdopen");
166 (void) fgets(buf
, BUFSIZ
, f
);
167 (void) snprintf(buf
, sizeof(buf
),
168 "HELO HuntGame@%s\r\n", my_machine_name
);
169 (void) write(service
, buf
, strlen(buf
));
170 (void) fgets(buf
, BUFSIZ
, f
);
171 (void) snprintf(buf
, sizeof(buf
),
172 "EXPN %s@%s\r\n", RENDEZVOUS
, my_machine_name
);
173 (void) write(service
, buf
, strlen(buf
));
174 while (fgets(buf
, BUFSIZ
, f
) != NULL
) {
177 if (buf
[0] != '2' || buf
[1] != '5' || buf
[2] != '0')
179 if ((s
= strchr(buf
+ 4, '<')) == NULL
)
180 s
= buf
+ 4, t
= buf
+ strlen(buf
) - 1;
183 if ((t
= strrchr(s
, '>')) == NULL
)
184 t
= s
+ strlen(s
) - 1;
195 do_announce(s
); /* construct and send talk request */
199 (void) shutdown(service
, 2);
200 (void) close(service
);
205 * The msg.id's for the invitations on the local and remote machines.
206 * These are used to delete the invitations.
212 CTL_RESPONSE response
;
214 get_remote_name(s
); /* setup his_machine_addr, msg.r_name */
217 msg
.ctl_addr
= *(struct osockaddr
*) &ctl_addr
;
218 msg
.ctl_addr
.sa_family
= htons(msg
.ctl_addr
.sa_family
);
220 msg
.ctl_addr
= ctl_addr
;
221 msg
.ctl_addr
.sin_family
= htons(msg
.ctl_addr
.sin_family
);
223 msg
.id_num
= (int) htonl((uint32_t) -1); /* an impossible id_num */
224 ctl_transact(his_machine_addr
, msg
, ANNOUNCE
, &response
);
225 if (response
.answer
!= SUCCESS
)
229 * Have the daemons delete the invitations now that we
233 /* we don't care if cleanup doesn't make it. */
235 msg
.id_num
= (int) htonl(response
.id_num
);
236 daemon_addr
.sin_addr
= his_machine_addr
;
237 if (sendto(ctl_sockt
, &msg
, sizeof (msg
), 0,
238 (struct sockaddr
*) &daemon_addr
, sizeof(daemon_addr
))
240 p_error("send delete remote");