minor cleanups.
this was tested w/: OpenBSD, Kleenux, BSDi (in all combinations).
# from: @(#)Makefile 5.10 (Berkeley) 5/11/90
-# $Id: Makefile,v 1.1.1.1 1995/10/18 08:43:22 deraadt Exp $
+# $OpenBSD: Makefile,v 1.2 1996/04/28 23:56:18 mickey Exp $
PROG= ntalkd
SRCS= talkd.c announce.c process.c table.c print.c
+/* $OpenBSD: announce.c,v 1.2 1996/04/28 23:56:18 mickey Exp $ */
+
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
#ifndef lint
/*static char sccsid[] = "from: @(#)announce.c 5.9 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$Id: announce.c,v 1.1.1.1 1995/10/18 08:43:22 deraadt Exp $";
+static char rcsid[] = "$Id: announce.c,v 1.2 1996/04/28 23:56:18 mickey Exp $";
#endif /* not lint */
#include <sys/types.h>
#include <string.h>
#include <vis.h>
#include <paths.h>
+#include "talkd.h"
-extern char hostname[];
+static void print_mesg __P((FILE *,CTL_MSG *,char *));
/*
* Announce an invitation to talk.
* process to any terminal that it writes on, we must fork a child
* to protect ourselves
*/
+int
announce(request, remote_machine)
CTL_MSG *request;
char *remote_machine;
* See if the user is accepting messages. If so, announce that
* a talk is requested.
*/
+int
announce_proc(request, remote_machine)
CTL_MSG *request;
char *remote_machine;
* try to keep the message in one piece if the recipient
* in in vi at the time
*/
+static void
print_mesg(tf, request, remote_machine)
FILE *tf;
CTL_MSG *request;
+/* $OpenBSD: print.c,v 1.2 1996/04/28 23:56:19 mickey Exp $ */
+
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
#ifndef lint
/*static char sccsid[] = "from: @(#)print.c 5.8 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$Id: print.c,v 1.1.1.1 1995/10/18 08:43:23 deraadt Exp $";
+static char rcsid[] = "$Id: print.c,v 1.2 1996/04/28 23:56:19 mickey Exp $";
#endif /* not lint */
/* debug print routines */
#include <protocols/talkd.h>
#include <syslog.h>
#include <stdio.h>
+#include "talkd.h"
static char *types[] =
{ "leave_invite", "look_up", "delete", "announce" };
"unknown_request", "badversion", "badaddr", "badctladdr" };
#define NANSWERS (sizeof (answers) / sizeof (answers[0]))
+void
print_request(cp, mp)
char *cp;
register CTL_MSG *mp;
cp, tp, mp->id_num, mp->l_name, mp->r_name, mp->r_tty);
}
+void
print_response(cp, rp)
char *cp;
register CTL_RESPONSE *rp;
+/* $OpenBSD: process.c,v 1.2 1996/04/28 23:56:20 mickey Exp $ */
+
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
#ifndef lint
/*static char sccsid[] = "from: @(#)process.c 5.10 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$Id: process.c,v 1.1.1.1 1995/10/18 08:43:23 deraadt Exp $";
+static char rcsid[] = "$Id: process.c,v 1.2 1996/04/28 23:56:20 mickey Exp $";
#endif /* not lint */
/*
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
+#include <arpa/inet.h>
#include <protocols/talkd.h>
#include <netdb.h>
#include <syslog.h>
#include <stdio.h>
#include <string.h>
#include <paths.h>
+#include "talkd.h"
-CTL_MSG *find_request();
-CTL_MSG *find_match();
-
+void
process_request(mp, rp)
register CTL_MSG *mp;
register CTL_RESPONSE *rp;
{
register CTL_MSG *ptr;
- extern int debug;
rp->vers = TALK_VERSION;
rp->type = mp->type;
return;
}
mp->id_num = ntohl(mp->id_num);
- mp->addr.sa_family = ntohs(mp->addr.sa_family);
- if (mp->addr.sa_family != AF_INET) {
+ if (ntohs(mp->addr.sa_family) != AF_INET) {
syslog(LOG_WARNING, "Bad address, family %d",
- mp->addr.sa_family);
+ ntohs(mp->addr.sa_family));
rp->answer = BADADDR;
return;
}
- mp->ctl_addr.sa_family = ntohs(mp->ctl_addr.sa_family);
- if (mp->ctl_addr.sa_family != AF_INET) {
+ if (ntohs(mp->ctl_addr.sa_family) != AF_INET) {
syslog(LOG_WARNING, "Bad control address, family %d",
- mp->ctl_addr.sa_family);
+ ntohs(mp->ctl_addr.sa_family));
rp->answer = BADCTLADDR;
return;
}
+ if (memcmp(&satosin(&rp->addr)->sin_addr,
+ &satosin(&mp->ctl_addr)->sin_addr,
+ sizeof(struct in_addr))) {
+ char buf1[32], buf2[32];
+ strcpy(buf1, inet_ntoa(satosin(&rp->addr)->sin_addr));
+ strcpy(buf2, inet_ntoa(satosin(&mp->ctl_addr)->sin_addr));
+ syslog(LOG_WARNING, "addresses are different, %s != %s\n",
+ buf1, buf2);
+ }
+ rp->addr.sa_family = 0;
mp->pid = ntohl(mp->pid);
if (debug)
print_request("process_request", mp);
if (ptr != (CTL_MSG *)0) {
rp->id_num = htonl(ptr->id_num);
rp->addr = ptr->addr;
- rp->addr.sa_family = htons(ptr->addr.sa_family);
+ rp->addr.sa_family = ptr->addr.sa_family;
rp->answer = SUCCESS;
} else
rp->answer = NOT_HERE;
print_response("process_request", rp);
}
+void
do_announce(mp, rp)
register CTL_MSG *mp;
CTL_RESPONSE *rp;
rp->answer = result;
return;
}
-#define satosin(sa) ((struct sockaddr_in *)(sa))
hp = gethostbyaddr((char *)&satosin(&mp->ctl_addr)->sin_addr,
sizeof (struct in_addr), AF_INET);
if (hp == (struct hostent *)0) {
/*
* Search utmp for the local user
*/
+int
find_user(name, tty)
char *name, *tty;
{
+/* $OpenBSD: table.c,v 1.2 1996/04/28 23:56:20 mickey Exp $ */
+
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
#ifndef lint
/*static char sccsid[] = "from: @(#)table.c 5.7 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$Id: table.c,v 1.1.1.1 1995/10/18 08:43:23 deraadt Exp $";
+static char rcsid[] = "$Id: table.c,v 1.2 1996/04/28 23:56:20 mickey Exp $";
#endif /* not lint */
/*
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "talkd.h"
#define MAX_ID 16000 /* << 2^15 so I don't have sign troubles */
#define NIL ((TABLE_ENTRY *)0)
-extern int debug;
struct timeval tp;
struct timezone txp;
TABLE_ENTRY *next;
TABLE_ENTRY *last;
};
+TABLE_ENTRY *table = NIL;
-TABLE_ENTRY *table = NIL;
-CTL_MSG *find_request();
-CTL_MSG *find_match();
+static void delete __P((register TABLE_ENTRY *));
/*
* Look in the table for an invitation that matches the current
ptr->request.type == LEAVE_INVITE)
return (&ptr->request);
}
+ if (debug)
+ syslog(LOG_DEBUG, "find_match: not found\n");
+
return ((CTL_MSG *)0);
}
return ((CTL_MSG *)0);
}
+void
insert_table(request, response)
CTL_MSG *request;
CTL_RESPONSE *response;
register TABLE_ENTRY *ptr;
time_t current_time;
+ if (debug)
+ print_request( "insert_table", request );
gettimeofday(&tp, &txp);
current_time = tp.tv_sec;
request->id_num = new_id();
/*
* Generate a unique non-zero sequence number
*/
-new_id()
+int
+new_id(void)
{
static int current_id = 0;
/*
* Delete the invitation with id 'id_num'
*/
+int
delete_invite(id_num)
int id_num;
{
/*
* Classic delete from a double-linked list
*/
+static void
delete(ptr)
register TABLE_ENTRY *ptr;
{
+.\" $OpenBSD: talkd.8,v 1.2 1996/04/28 23:56:21 mickey Exp $
+.\"
.\" Copyright (c) 1983, 1991 The Regents of the University of California.
.\" All rights reserved.
.\"
.\" SUCH DAMAGE.
.\"
.\" from: @(#)talkd.8 6.5 (Berkeley) 3/16/91
-.\" $Id: talkd.8,v 1.1.1.1 1995/10/18 08:43:23 deraadt Exp $
+.\" $Id: talkd.8,v 1.2 1996/04/28 23:56:21 mickey Exp $
.\"
.Dd March 16, 1991
.Dt TALKD 8
+/* $OpenBSD: talkd.c,v 1.2 1996/04/28 23:56:22 mickey Exp $ */
+
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
#ifndef lint
/*static char sccsid[] = "from: @(#)talkd.c 5.8 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$Id: talkd.c,v 1.1.1.1 1995/10/18 08:43:23 deraadt Exp $";
+static char rcsid[] = "$Id: talkd.c,v 1.2 1996/04/28 23:56:22 mickey Exp $";
#endif /* not lint */
/*
#include <stdlib.h>
#include <string.h>
#include <paths.h>
-
-CTL_MSG request;
-CTL_RESPONSE response;
+#include "talkd.h"
int sockt;
int debug = 0;
int argc;
char *argv[];
{
- register CTL_MSG *mp = &request;
- int cc;
-
if (getuid()) {
fprintf(stderr, "%s: getuid: not super-user", argv[0]);
exit(1);
signal(SIGALRM, timeout);
alarm(TIMEOUT);
for (;;) {
- extern int errno;
+ CTL_MSG request;
+ CTL_RESPONSE response;
+ int cc;
+ int len = sizeof(response.addr);
- cc = recv(0, (char *)mp, sizeof (*mp), 0);
- if (cc != sizeof (*mp)) {
+ cc = recvfrom(0, (char *)&request, sizeof (request), 0,
+ (struct sockaddr *)&response.addr, &len);
+ if (cc != sizeof (request)) {
if (cc < 0 && errno != EINTR)
syslog(LOG_WARNING, "recv: %m");
continue;
}
lastmsgtime = time(0);
- process_request(mp, &response);
+ process_request(&request, &response);
/* can block here, is this what I want? */
cc = sendto(sockt, (char *)&response,
- sizeof (response), 0, (struct sockaddr *)&mp->ctl_addr,
- sizeof (mp->ctl_addr));
+ sizeof (response), 0, (struct sockaddr *)&request.ctl_addr,
+ sizeof (request.ctl_addr));
if (cc != sizeof (response))
syslog(LOG_WARNING, "sendto: %m");
}