summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorperry <perry@NetBSD.org>2006-04-03 02:01:28 +0000
committerperry <perry@NetBSD.org>2006-04-03 02:01:28 +0000
commiteee85da04cbc41d01502bd32fa473f5d328a2ea0 (patch)
tree9f42b8d2a899cc84448d8f7dfe8c90c5054dc5df
parent896b79dbc83d48339904c4fec0700c1c76dcecfc (diff)
Remove support for uucp style locking.
This means we can get rid of the suid/sgid parts of the code (which have been removed). The program is now installed with normal permissions. To prevent accidents, we now flock the tty line, attempting to get an exclusive lock. Reviewed by: tls
-rw-r--r--usr.bin/tip/Makefile7
-rw-r--r--usr.bin/tip/aculib/biz31.c5
-rw-r--r--usr.bin/tip/cmds.c9
-rw-r--r--usr.bin/tip/cu.c24
-rw-r--r--usr.bin/tip/hunt.c13
-rw-r--r--usr.bin/tip/tip.c76
-rw-r--r--usr.bin/tip/tip.h8
-rw-r--r--usr.bin/tip/uucplock.c118
8 files changed, 27 insertions, 233 deletions
diff --git a/usr.bin/tip/Makefile b/usr.bin/tip/Makefile
index 0b4a27f297b..bb6c479b937 100644
--- a/usr.bin/tip/Makefile
+++ b/usr.bin/tip/Makefile
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.17 2006/04/03 01:47:20 tls Exp $
+# $NetBSD: Makefile,v 1.18 2006/04/03 02:01:28 perry Exp $
# @(#)Makefile 8.1 (Berkeley) 6/6/93
#
# Files are:
@@ -37,11 +37,8 @@ CPPFLAGS+=-I${.CURDIR} \
-DDEFBR=9600 -DDEFFS=BUFSIZ -DCONNECT \
-DHAYES #-DV831 -DVENTEL -DHAYES -DCOURIER -DT3000 -DACULOG -DPRISTINE
.PATH: ${.CURDIR}/aculib
-BINOWN= uucp
-BINGRP= dialer
-BINMODE=4554
SRCS= acu.c acutab.c cmds.c cmdtab.c cu.c hunt.c partab.c \
- remote.c tip.c tipout.c uucplock.c value.c vars.c \
+ remote.c tip.c tipout.c value.c vars.c \
df.c hayes.c # log.c biz22.c courier.c dn11.c hayes.c t3000.c v3451.c v831.c ventel.c
# -- acutab is configuration dependent, and so depends on the Makefile
diff --git a/usr.bin/tip/aculib/biz31.c b/usr.bin/tip/aculib/biz31.c
index 72907468913..fc05e7bc2cc 100644
--- a/usr.bin/tip/aculib/biz31.c
+++ b/usr.bin/tip/aculib/biz31.c
@@ -1,4 +1,4 @@
-/* $NetBSD: biz31.c,v 1.9 2006/04/03 00:51:14 perry Exp $ */
+/* $NetBSD: biz31.c,v 1.10 2006/04/03 02:01:28 perry Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)biz31.c 8.1 (Berkeley) 6/6/93";
#endif
-__RCSID("$NetBSD: biz31.c,v 1.9 2006/04/03 00:51:14 perry Exp $");
+__RCSID("$NetBSD: biz31.c,v 1.10 2006/04/03 02:01:28 perry Exp $");
#endif /* not lint */
#include "tip.h"
@@ -59,7 +59,6 @@ biz_dialer(char *num, char *mod)
if (!bizsync(FD)) {
logent(value(HOST), "", "biz", "out of sync");
printf("bizcomp out of sync\n");
- delock(uucplock);
exit(0);
}
if (boolean(value(VERBOSE)))
diff --git a/usr.bin/tip/cmds.c b/usr.bin/tip/cmds.c
index 045b08b420e..5a2e732f828 100644
--- a/usr.bin/tip/cmds.c
+++ b/usr.bin/tip/cmds.c
@@ -1,4 +1,4 @@
-/* $NetBSD: cmds.c,v 1.20 2006/04/03 00:51:13 perry Exp $ */
+/* $NetBSD: cmds.c,v 1.21 2006/04/03 02:01:28 perry Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)cmds.c 8.1 (Berkeley) 6/6/93";
#endif
-__RCSID("$NetBSD: cmds.c,v 1.20 2006/04/03 00:51:13 perry Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.21 2006/04/03 02:01:28 perry Exp $");
#endif /* not lint */
#include "tip.h"
@@ -589,7 +589,6 @@ shell(char dummy)
cp = value(SHELL);
else
cp++;
- shell_uid();
execl(value(SHELL), cp, 0);
fprintf(stderr, "\r\n");
err(1, "can't execl");
@@ -653,8 +652,6 @@ tipabort(const char *msg)
if (msg != NULL)
printf("\r\n%s", msg);
printf("\r\n[EOT]\r\n");
- daemon_uid();
- (void)uu_unlock(uucplock);
unraw();
exit(0);
}
@@ -690,7 +687,6 @@ execute(char *s)
cp = value(SHELL);
else
cp++;
- shell_uid();
execl(value(SHELL), cp, "-c", s, 0);
}
@@ -877,7 +873,6 @@ expand(char name[])
dup(pivec[1]);
close(pivec[1]);
close(2);
- shell_uid();
execl(Shell, Shell, "-c", cmdbuf, 0);
_exit(1);
}
diff --git a/usr.bin/tip/cu.c b/usr.bin/tip/cu.c
index 433a954ed64..51edae92e95 100644
--- a/usr.bin/tip/cu.c
+++ b/usr.bin/tip/cu.c
@@ -1,4 +1,4 @@
-/* $NetBSD: cu.c,v 1.14 2006/04/03 01:48:22 tls Exp $ */
+/* $NetBSD: cu.c,v 1.15 2006/04/03 02:01:28 perry Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -36,7 +36,7 @@
#if 0
static char sccsid[] = "@(#)cu.c 8.1 (Berkeley) 6/6/93";
#endif
-__RCSID("$NetBSD: cu.c,v 1.14 2006/04/03 01:48:22 tls Exp $");
+__RCSID("$NetBSD: cu.c,v 1.15 2006/04/03 02:01:28 perry Exp $");
#endif /* not lint */
#include "tip.h"
@@ -203,15 +203,12 @@ cumain(int argc, char *argv[])
errx(3,"all ports busy");
}
if (i == -1) {
- warnx("link down");
- (void)uu_unlock(uucplock);
- exit(3);
+ errx(3, "link down");
}
setbuf(stdout, NULL);
#ifdef ACULOG
loginit();
#endif
- user_uid();
vinit();
switch (parity) {
case -1:
@@ -255,24 +252,15 @@ cumain(int argc, char *argv[])
setboolean(value(LECHO), TRUE);
if (HW) {
if (ttysetup(BR) != 0) {
- warnx("unsupported speed %ld", BR);
- daemon_uid();
- (void)uu_unlock(uucplock);
- exit(3);
+ errx(3, "unsupported speed %ld", BR);
}
}
if (connect()) {
- warnx("Connect failed");
- daemon_uid();
- (void)uu_unlock(uucplock);
- exit(1);
+ errx(1, "Connect failed");
}
if (!HW) {
if (ttysetup(BR) != 0) {
- warnx("unsupported speed %ld", BR);
- daemon_uid();
- (void)uu_unlock(uucplock);
- exit(3);
+ errx(3, "unsupported speed %ld", BR);
}
}
}
diff --git a/usr.bin/tip/hunt.c b/usr.bin/tip/hunt.c
index 167e83244bf..2ec66a786f5 100644
--- a/usr.bin/tip/hunt.c
+++ b/usr.bin/tip/hunt.c
@@ -1,4 +1,4 @@
-/* $NetBSD: hunt.c,v 1.12 2006/04/03 00:51:13 perry Exp $ */
+/* $NetBSD: hunt.c,v 1.13 2006/04/03 02:01:28 perry Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)hunt.c 8.1 (Berkeley) 6/6/93";
#endif
-__RCSID("$NetBSD: hunt.c,v 1.12 2006/04/03 00:51:13 perry Exp $");
+__RCSID("$NetBSD: hunt.c,v 1.13 2006/04/03 02:01:28 perry Exp $");
#endif /* not lint */
#include "tip.h"
@@ -61,9 +61,6 @@ hunt(char *name)
f = signal(SIGALRM, dead);
while ((cp = getremote(name)) != NULL) {
deadfl = 0;
- uucplock = strrchr(cp, '/')+1;
- if (uu_lock(uucplock) < 0)
- continue;
/*
* Straight through call units, such as the BIZCOMP,
* VADIC and the DF, must indicate they're hardwired in
@@ -85,6 +82,11 @@ hunt(char *name)
if (!deadfl) {
struct termios cntrl;
+ if (flock(FD, (LOCK_EX|LOCK_NB)) != 0) {
+ close(FD);
+ continue;
+ }
+
tcgetattr(FD, &cntrl);
if (!DC)
cntrl.c_cflag |= HUPCL;
@@ -93,7 +95,6 @@ hunt(char *name)
signal(SIGALRM, SIG_DFL);
return (cp != NULL);
}
- (void)uu_unlock(uucplock);
}
signal(SIGALRM, f);
return (deadfl ? -1 : cp != NULL);
diff --git a/usr.bin/tip/tip.c b/usr.bin/tip/tip.c
index 21c0abe0b36..e883b725160 100644
--- a/usr.bin/tip/tip.c
+++ b/usr.bin/tip/tip.c
@@ -1,4 +1,4 @@
-/* $NetBSD: tip.c,v 1.35 2006/04/03 00:51:13 perry Exp $ */
+/* $NetBSD: tip.c,v 1.36 2006/04/03 02:01:28 perry Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
#if 0
static char sccsid[] = "@(#)tip.c 8.1 (Berkeley) 6/6/93";
#endif
-__RCSID("$NetBSD: tip.c,v 1.35 2006/04/03 00:51:13 perry Exp $");
+__RCSID("$NetBSD: tip.c,v 1.36 2006/04/03 02:01:28 perry Exp $");
#endif /* not lint */
/*
@@ -141,9 +141,7 @@ notnumber:
exit(3);
}
if (i == -1) {
- printf("link down\n");
- (void)uu_unlock(uucplock);
- exit(3);
+ errx(3, "link down\n");
}
setbuf(stdout, NULL);
#ifdef ACULOG
@@ -151,15 +149,6 @@ notnumber:
#endif
/*
- * Now that we have the logfile and the ACU open
- * return to the real uid and gid. These things will
- * be closed on exit. Swap real and effective uid's
- * so we can get the original permissions back
- * for removing the uucp lock.
- */
- user_uid();
-
- /*
* Kludge, their's no easy way to get the initialization
* in the right order, so force it here
*/
@@ -175,26 +164,17 @@ notnumber:
*/
if (HW) {
if (ttysetup(i) != 0) {
- warnx("bad baud rate %d",
+ errx(3, "bad baud rate %d",
(int)number(value(BAUDRATE)));
- daemon_uid();
- (void)uu_unlock(uucplock);
- exit(3);
}
}
if ((q = connect()) != NULL) {
- printf("\07%s\n[EOT]\n", q);
- daemon_uid();
- (void)uu_unlock(uucplock);
- exit(1);
+ errx(1, "\07%s\n[EOT]\n", q);
}
if (!HW) {
if (ttysetup(i) != 0) {
- warnx("bad baud rate %d",
+ errx(3, "bad baud rate %d",
(int)number(value(BAUDRATE)));
- daemon_uid();
- (void)uu_unlock(uucplock);
- exit(3);
}
}
@@ -207,10 +187,7 @@ notnumber:
if (DC &&
((fcarg = fcntl(FD, F_GETFL, 0)) < 0 ||
fcntl(FD, F_SETFL, fcarg & ~O_NONBLOCK) < 0)) {
- warn("can't clear O_NONBLOCK");
- daemon_uid();
- (void)uu_unlock(uucplock);
- exit(1);
+ err(1, "can't clear O_NONBLOCK");
}
cucommon:
@@ -261,51 +238,12 @@ void
cleanup(int dummy)
{
- daemon_uid();
- (void)uu_unlock(uucplock);
if (odisc)
ioctl(0, TIOCSETD, (char *)&odisc);
exit(0);
}
/*
- * Muck with user ID's. We are setuid to the owner of the lock
- * directory when we start. user_uid() reverses real and effective
- * ID's after startup, to run with the user's permissions.
- * daemon_uid() switches back to the privileged uid for unlocking.
- * Finally, to avoid running a shell with the wrong real uid,
- * shell_uid() sets real and effective uid's to the user's real ID.
- */
-static int uidswapped;
-
-void
-user_uid(void)
-{
-
- if (uidswapped == 0) {
- seteuid(uid);
- uidswapped = 1;
- }
-}
-
-void
-daemon_uid(void)
-{
-
- if (uidswapped) {
- seteuid(euid);
- uidswapped = 0;
- }
-}
-
-void
-shell_uid(void)
-{
-
- seteuid(uid);
-}
-
-/*
* put the controlling keyboard into raw mode
*/
void
diff --git a/usr.bin/tip/tip.h b/usr.bin/tip/tip.h
index cf6efad2da3..dfcd29be16f 100644
--- a/usr.bin/tip/tip.h
+++ b/usr.bin/tip/tip.h
@@ -1,4 +1,4 @@
-/* $NetBSD: tip.h,v 1.20 2006/04/03 00:51:13 perry Exp $ */
+/* $NetBSD: tip.h,v 1.21 2006/04/03 02:01:28 perry Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -256,7 +256,6 @@ char fname[80]; /* file name buffer for ~< */
char copyname[80]; /* file name buffer for ~> */
char ccc; /* synchronization character */
char ch; /* for tipout */
-char *uucplock; /* name of lock file for uucp's */
int odisc; /* initial tty line discipline */
extern int disc; /* current tty discpline */
@@ -275,7 +274,6 @@ char *ctrl(char);
void cumain(int, char **);
void cu_put(char);
void cu_take(char);
-void daemon_uid(void);
void disconnect(const char *);
char *expand(char *);
void finish(char);
@@ -298,16 +296,12 @@ void sendfile(char);
void setparity(const char *);
void setscript(void);
void shell(char);
-void shell_uid(void);
void suspend(char);
void tandem(const char *);
void tipabort(const char *);
void tipout(void);
int ttysetup(int);
void unraw(void);
-void user_uid(void);
-int uu_lock(char *);
-int uu_unlock(char *);
void variable(char);
void vinit(void);
char *vinterp(char *, char);
diff --git a/usr.bin/tip/uucplock.c b/usr.bin/tip/uucplock.c
deleted file mode 100644
index cb093d23272..00000000000
--- a/usr.bin/tip/uucplock.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/* $NetBSD: uucplock.c,v 1.14 2006/04/03 00:51:13 perry Exp $ */
-
-/*
- * Copyright (c) 1988, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 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. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)uucplock.c 8.1 (Berkeley) 6/6/93";
-#endif
-__RCSID("$NetBSD: uucplock.c,v 1.14 2006/04/03 00:51:13 perry Exp $");
-#endif /* not lint */
-
-#include "pathnames.h"
-#include "tip.h"
-
-/*
- * uucp style locking routines
- * return: 0 - success
- * -1 - failure
- */
-
-int
-uu_lock(char *ttname)
-{
- int fd, mypid;
- char tbuf[sizeof(_PATH_LOCKDIRNAME) + MAXNAMLEN];
- char text_pid[81];
- int len;
-
- (void)snprintf(tbuf, sizeof tbuf, _PATH_LOCKDIRNAME, ttname);
- fd = open(tbuf, O_RDWR|O_CREAT|O_EXCL, 0660);
- if (fd < 0) {
- /*
- * file is already locked
- * check to see if the process holding the lock still exists
- */
- fd = open(tbuf, O_RDWR, 0);
- if (fd < 0) {
- warn(tbuf);
- warnx("Can't open lock file.");
- return(-1);
- }
- len = read(fd, text_pid, sizeof(text_pid)-1);
- if(len <= 0) {
- warn(tbuf);
- (void)close(fd);
- warnx("Can't read lock file.");
- return(-1);
- }
- text_pid[len] = 0;
- mypid = atol(text_pid);
-
- if (kill(mypid, 0) == 0 || errno != ESRCH) {
- (void)close(fd); /* process is still running */
- return(-1);
- }
- /*
- * The process that locked the file isn't running, so
- * we'll lock it ourselves
- */
- warnx("Stale lock on %s PID=%d... overriding.",
- ttname, mypid);
- if (lseek(fd, (off_t)0, SEEK_SET) < 0) {
- warn(tbuf);
- (void)close(fd);
- warnx("Can't seek lock file.");
- return(-1);
- }
- /* fall out and finish the locking process */
- }
- mypid = getpid();
- (void)snprintf(text_pid, sizeof text_pid, "%10d\n", mypid);
- len = strlen(text_pid);
- if (write(fd, text_pid, len) != len) {
- (void)close(fd);
- (void)unlink(tbuf);
- warn("lock write");
- return(-1);
- }
- (void)close(fd);
- return(0);
-}
-
-int
-uu_unlock(char *ttname)
-{
- char tbuf[sizeof(_PATH_LOCKDIRNAME) + MAXNAMLEN];
-
- (void)snprintf(tbuf, sizeof tbuf, _PATH_LOCKDIRNAME, ttname);
- return(unlink(tbuf));
-}