summaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>1996-04-28 23:56:23 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>1996-04-28 23:56:23 +0000
commit131e85afc48cafd29dbc2ecb1358a9524e3f7f5c (patch)
treea987df92ce461061132117cc7cea1720941d273d /libexec
parent314f8beeaa64def1cbf5aa7240d9f5722b7cefb5 (diff)
Fix the bugs w/ that osockaddr.
minor cleanups. this was tested w/: OpenBSD, Kleenux, BSDi (in all combinations).
Diffstat (limited to 'libexec')
-rw-r--r--libexec/talkd/Makefile2
-rw-r--r--libexec/talkd/announce.c10
-rw-r--r--libexec/talkd/print.c7
-rw-r--r--libexec/talkd/process.c36
-rw-r--r--libexec/talkd/table.c22
-rw-r--r--libexec/talkd/talkd.84
-rw-r--r--libexec/talkd/talkd.c27
7 files changed, 71 insertions, 37 deletions
diff --git a/libexec/talkd/Makefile b/libexec/talkd/Makefile
index 283d8291e65..92c85ef4cce 100644
--- a/libexec/talkd/Makefile
+++ b/libexec/talkd/Makefile
@@ -1,5 +1,5 @@
# from: @(#)Makefile 5.10 (Berkeley) 5/11/90
-# $Id: Makefile,v 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
diff --git a/libexec/talkd/announce.c b/libexec/talkd/announce.c
index 62437063df8..e267c326346 100644
--- a/libexec/talkd/announce.c
+++ b/libexec/talkd/announce.c
@@ -1,3 +1,5 @@
+/* $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.
@@ -33,7 +35,7 @@
#ifndef lint
/*static char sccsid[] = "from: @(#)announce.c 5.9 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$Id: announce.c,v 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>
@@ -51,8 +53,9 @@ static char rcsid[] = "$Id: announce.c,v 1.1 1995/10/18 08:43:22 deraadt Exp $";
#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.
@@ -61,6 +64,7 @@ extern char hostname[];
* 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;
@@ -94,6 +98,7 @@ announce(request, 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;
@@ -133,6 +138,7 @@ announce_proc(request, 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;
diff --git a/libexec/talkd/print.c b/libexec/talkd/print.c
index 2f58508049c..3b44f8b2429 100644
--- a/libexec/talkd/print.c
+++ b/libexec/talkd/print.c
@@ -1,3 +1,5 @@
+/* $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.
@@ -33,7 +35,7 @@
#ifndef lint
/*static char sccsid[] = "from: @(#)print.c 5.8 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$Id: print.c,v 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 */
@@ -43,6 +45,7 @@ static char rcsid[] = "$Id: print.c,v 1.1 1995/10/18 08:43:23 deraadt Exp $";
#include <protocols/talkd.h>
#include <syslog.h>
#include <stdio.h>
+#include "talkd.h"
static char *types[] =
{ "leave_invite", "look_up", "delete", "announce" };
@@ -52,6 +55,7 @@ static char *answers[] =
"unknown_request", "badversion", "badaddr", "badctladdr" };
#define NANSWERS (sizeof (answers) / sizeof (answers[0]))
+void
print_request(cp, mp)
char *cp;
register CTL_MSG *mp;
@@ -67,6 +71,7 @@ print_request(cp, 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;
diff --git a/libexec/talkd/process.c b/libexec/talkd/process.c
index cd5686903b3..a6dcbda2003 100644
--- a/libexec/talkd/process.c
+++ b/libexec/talkd/process.c
@@ -1,3 +1,5 @@
+/* $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.
@@ -33,7 +35,7 @@
#ifndef lint
/*static char sccsid[] = "from: @(#)process.c 5.10 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$Id: process.c,v 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 */
/*
@@ -48,22 +50,21 @@ static char rcsid[] = "$Id: process.c,v 1.1 1995/10/18 08:43:23 deraadt Exp $";
#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;
@@ -74,20 +75,28 @@ process_request(mp, rp)
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);
@@ -111,7 +120,7 @@ process_request(mp, rp)
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;
@@ -129,6 +138,7 @@ process_request(mp, rp)
print_response("process_request", rp);
}
+void
do_announce(mp, rp)
register CTL_MSG *mp;
CTL_RESPONSE *rp;
@@ -143,7 +153,6 @@ do_announce(mp, 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) {
@@ -176,6 +185,7 @@ do_announce(mp, rp)
/*
* Search utmp for the local user
*/
+int
find_user(name, tty)
char *name, *tty;
{
diff --git a/libexec/talkd/table.c b/libexec/talkd/table.c
index c5560c92422..50a21728aa3 100644
--- a/libexec/talkd/table.c
+++ b/libexec/talkd/table.c
@@ -1,3 +1,5 @@
+/* $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.
@@ -33,7 +35,7 @@
#ifndef lint
/*static char sccsid[] = "from: @(#)table.c 5.7 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$Id: table.c,v 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 */
/*
@@ -53,12 +55,12 @@ static char rcsid[] = "$Id: table.c,v 1.1 1995/10/18 08:43:23 deraadt Exp $";
#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;
@@ -70,10 +72,9 @@ struct table_entry {
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
@@ -106,6 +107,9 @@ find_match(request)
ptr->request.type == LEAVE_INVITE)
return (&ptr->request);
}
+ if (debug)
+ syslog(LOG_DEBUG, "find_match: not found\n");
+
return ((CTL_MSG *)0);
}
@@ -151,6 +155,7 @@ find_request(request)
return ((CTL_MSG *)0);
}
+void
insert_table(request, response)
CTL_MSG *request;
CTL_RESPONSE *response;
@@ -158,6 +163,8 @@ insert_table(request, 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();
@@ -180,7 +187,8 @@ insert_table(request, response)
/*
* Generate a unique non-zero sequence number
*/
-new_id()
+int
+new_id(void)
{
static int current_id = 0;
@@ -194,6 +202,7 @@ new_id()
/*
* Delete the invitation with id 'id_num'
*/
+int
delete_invite(id_num)
int id_num;
{
@@ -218,6 +227,7 @@ delete_invite(id_num)
/*
* Classic delete from a double-linked list
*/
+static void
delete(ptr)
register TABLE_ENTRY *ptr;
{
diff --git a/libexec/talkd/talkd.8 b/libexec/talkd/talkd.8
index 4a2f7db4190..96dc4aea806 100644
--- a/libexec/talkd/talkd.8
+++ b/libexec/talkd/talkd.8
@@ -1,3 +1,5 @@
+.\" $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.
.\"
@@ -30,7 +32,7 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)talkd.8 6.5 (Berkeley) 3/16/91
-.\" $Id: talkd.8,v 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
diff --git a/libexec/talkd/talkd.c b/libexec/talkd/talkd.c
index e1fed55758f..fbeee46df40 100644
--- a/libexec/talkd/talkd.c
+++ b/libexec/talkd/talkd.c
@@ -1,3 +1,5 @@
+/* $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.
@@ -39,7 +41,7 @@ char copyright[] =
#ifndef lint
/*static char sccsid[] = "from: @(#)talkd.c 5.8 (Berkeley) 2/26/91";*/
-static char rcsid[] = "$Id: talkd.c,v 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 */
/*
@@ -60,9 +62,7 @@ static char rcsid[] = "$Id: talkd.c,v 1.1 1995/10/18 08:43:23 deraadt Exp $";
#include <stdlib.h>
#include <string.h>
#include <paths.h>
-
-CTL_MSG request;
-CTL_RESPONSE response;
+#include "talkd.h"
int sockt;
int debug = 0;
@@ -78,9 +78,6 @@ main(argc, argv)
int argc;
char *argv[];
{
- register CTL_MSG *mp = &request;
- int cc;
-
if (getuid()) {
fprintf(stderr, "%s: getuid: not super-user", argv[0]);
exit(1);
@@ -99,20 +96,24 @@ main(argc, argv)
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");
}