summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>1997-03-29 03:01:43 +0000
committermillert <millert@openbsd.org>1997-03-29 03:01:43 +0000
commit16ed9a0a3d6ba37dfa157587fa70a0565d2dec64 (patch)
tree719b0d8572f684bf3381ec77c0aaa75d385f80ce
parentMake ``mail.local -H'' explicately indicate when the lock fails or succeeds. (diff)
downloadwireguard-openbsd-16ed9a0a3d6ba37dfa157587fa70a0565d2dec64.tar.xz
wireguard-openbsd-16ed9a0a3d6ba37dfa157587fa70a0565d2dec64.zip
Use ``mail.local -H'' to do dot locking so we can have mode 755 mail
spool, change an occurrence of tempnam() to mkstemp(), change some longs and shorts to ints. Mail is now usable again.
-rw-r--r--usr.bin/mail/Makefile4
-rw-r--r--usr.bin/mail/cmd1.c6
-rw-r--r--usr.bin/mail/cmd3.c6
-rw-r--r--usr.bin/mail/def.h10
-rw-r--r--usr.bin/mail/extern.h4
-rw-r--r--usr.bin/mail/fio.c6
-rw-r--r--usr.bin/mail/pathnames.h3
-rw-r--r--usr.bin/mail/popen.c61
-rw-r--r--usr.bin/mail/quit.c47
-rw-r--r--usr.bin/mail/temp.c14
10 files changed, 116 insertions, 45 deletions
diff --git a/usr.bin/mail/Makefile b/usr.bin/mail/Makefile
index 765ebad18f0..b8c0bd5bfde 100644
--- a/usr.bin/mail/Makefile
+++ b/usr.bin/mail/Makefile
@@ -1,8 +1,8 @@
-# $OpenBSD: Makefile,v 1.4 1996/12/08 14:32:29 downsj Exp $
+# $OpenBSD: Makefile,v 1.5 1997/03/29 03:01:43 millert Exp $
# $NetBSD: Makefile,v 1.8 1996/06/08 19:48:09 christos Exp $
PROG= mail
-SRCS= version.c aux.c cmd1.c cmd2.c cmd3.c cmdtab.c collect.c dotlock.c \
+SRCS= version.c aux.c cmd1.c cmd2.c cmd3.c cmdtab.c collect.c \
edit.c fio.c getname.c head.c v7.local.c lex.c list.c main.c names.c \
popen.c quit.c send.c strings.c temp.c tty.c vars.c
SFILES= mail.help mail.tildehelp
diff --git a/usr.bin/mail/cmd1.c b/usr.bin/mail/cmd1.c
index 3ec58dd05f4..03821c6b128 100644
--- a/usr.bin/mail/cmd1.c
+++ b/usr.bin/mail/cmd1.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd1.c,v 1.3 1996/06/11 12:53:32 deraadt Exp $ */
+/* $OpenBSD: cmd1.c,v 1.4 1997/03/29 03:01:44 millert Exp $ */
/* $NetBSD: cmd1.c,v 1.5 1996/06/08 19:48:11 christos Exp $ */
/*-
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)cmd1.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: cmd1.c,v 1.3 1996/06/11 12:53:32 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: cmd1.c,v 1.4 1997/03/29 03:01:44 millert Exp $";
#endif
#endif /* not lint */
@@ -204,7 +204,7 @@ printhead(mesg)
if (mp->m_flag & MBOX)
dispc = 'M';
parse(headline, &hl, pbuf);
- sprintf(wcount, "%3d/%-5ld", mp->m_lines, mp->m_size);
+ sprintf(wcount, "%3d/%-5d", mp->m_lines, mp->m_size);
subjlen = screenwidth - 50 - strlen(wcount);
name = value("show-rcpt") != NOSTR ?
skin(hfield("to", mp)) : nameof(mp, 0);
diff --git a/usr.bin/mail/cmd3.c b/usr.bin/mail/cmd3.c
index ce3ec6bc805..2b2a4dc27ef 100644
--- a/usr.bin/mail/cmd3.c
+++ b/usr.bin/mail/cmd3.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd3.c,v 1.2 1996/06/11 12:53:34 deraadt Exp $ */
+/* $OpenBSD: cmd3.c,v 1.3 1997/03/29 03:01:44 millert Exp $ */
/* $NetBSD: cmd3.c,v 1.5 1996/06/08 19:48:14 christos Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)cmd3.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: cmd3.c,v 1.2 1996/06/11 12:53:34 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: cmd3.c,v 1.3 1997/03/29 03:01:44 millert Exp $";
#endif
#endif /* not lint */
@@ -348,7 +348,7 @@ messize(v)
for (ip = msgvec; *ip != NULL; ip++) {
mesg = *ip;
mp = &message[mesg-1];
- printf("%d: %d/%ld\n", mesg, mp->m_lines, mp->m_size);
+ printf("%d: %d/%d\n", mesg, mp->m_lines, mp->m_size);
}
return(0);
}
diff --git a/usr.bin/mail/def.h b/usr.bin/mail/def.h
index 01bb3cce20b..88132e5b7f7 100644
--- a/usr.bin/mail/def.h
+++ b/usr.bin/mail/def.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: def.h,v 1.3 1997/02/03 00:25:18 deraadt Exp $ */
+/* $OpenBSD: def.h,v 1.4 1997/03/29 03:01:45 millert Exp $ */
/* $NetBSD: def.h,v 1.8 1996/06/08 19:48:18 christos Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -71,10 +71,10 @@
struct message {
short m_flag; /* flags, see below */
- short m_block; /* block number of this message */
- short m_offset; /* offset in block of message */
- long m_size; /* Bytes in the message */
- long m_lines; /* Lines in the message */
+ int m_block; /* block number of this message */
+ int m_offset; /* offset in block of message */
+ int m_size; /* Bytes in the message */
+ int m_lines; /* Lines in the message */
};
/*
diff --git a/usr.bin/mail/extern.h b/usr.bin/mail/extern.h
index 28ed945ba35..e40ca2c6363 100644
--- a/usr.bin/mail/extern.h
+++ b/usr.bin/mail/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.3 1996/06/11 12:53:39 deraadt Exp $ */
+/* $OpenBSD: extern.h,v 1.4 1997/03/29 03:01:45 millert Exp $ */
/* $NetBSD: extern.h,v 1.4 1996/06/08 19:48:21 christos Exp $ */
/*-
@@ -236,6 +236,8 @@ int shell __P((void *));
void sigchild __P((int));
void sort __P((char **));
int source __P((void *));
+int spool_lock __P((void));
+int spool_unlock __P((void));
void spreserve __P((void));
void sreset __P((void));
int start_command __P((char *, sigset_t *, int, int, char *, char *, char *));
diff --git a/usr.bin/mail/fio.c b/usr.bin/mail/fio.c
index 80e0bdbe7d5..ca95714da09 100644
--- a/usr.bin/mail/fio.c
+++ b/usr.bin/mail/fio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fio.c,v 1.3 1997/01/17 07:12:46 millert Exp $ */
+/* $OpenBSD: fio.c,v 1.4 1997/03/29 03:01:46 millert Exp $ */
/* $NetBSD: fio.c,v 1.5 1996/06/08 19:48:22 christos Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)fio.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: fio.c,v 1.3 1997/01/17 07:12:46 millert Exp $";
+static char rcsid[] = "$OpenBSD: fio.c,v 1.4 1997/03/29 03:01:46 millert Exp $";
#endif
#endif /* not lint */
@@ -74,7 +74,7 @@ setptr(ibuf)
char linebuf[LINESIZE];
/* Get temporary file. */
- (void)sprintf(linebuf, "%s/mail.XXXXXX", tmpdir);
+ (void)sprintf(linebuf, "%s/mail.XXXXXXXXXX", tmpdir);
if ((c = mkstemp(linebuf)) == -1 ||
(mestmp = Fdopen(c, "r+")) == NULL) {
(void)fprintf(stderr, "mail: can't open %s\n", linebuf);
diff --git a/usr.bin/mail/pathnames.h b/usr.bin/mail/pathnames.h
index 5b62b79a13c..68dd05bc110 100644
--- a/usr.bin/mail/pathnames.h
+++ b/usr.bin/mail/pathnames.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pathnames.h,v 1.2 1996/06/11 12:53:46 deraadt Exp $ */
+/* $OpenBSD: pathnames.h,v 1.3 1997/03/29 03:01:46 millert Exp $ */
/* $NetBSD: pathnames.h,v 1.4 1996/06/08 19:48:34 christos Exp $ */
/*
@@ -44,3 +44,4 @@
#define _PATH_TILDE "/usr/share/misc/mail.tildehelp"
#define _PATH_MASTER_RC "/etc/mail.rc"
#define _PATH_MORE "/usr/bin/more"
+#define _PATH_MAIL_LOCAL "/usr/libexec/mail.local"
diff --git a/usr.bin/mail/popen.c b/usr.bin/mail/popen.c
index 7cdd016aee9..96909892a58 100644
--- a/usr.bin/mail/popen.c
+++ b/usr.bin/mail/popen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: popen.c,v 1.3 1996/06/26 21:22:34 dm Exp $ */
+/* $OpenBSD: popen.c,v 1.4 1997/03/29 03:01:47 millert Exp $ */
/* $NetBSD: popen.c,v 1.4 1996/06/08 19:48:35 christos Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)popen.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: popen.c,v 1.3 1996/06/26 21:22:34 dm Exp $";
+static char rcsid[] = "$OpenBSD: popen.c,v 1.4 1997/03/29 03:01:47 millert Exp $";
#endif
#endif /* not lint */
@@ -69,6 +69,7 @@ static struct child *child;
static struct child *findchild __P((int));
static void delchild __P((struct child *));
static int file_pid __P((FILE *));
+static int handle_spool_locks __P((int));
FILE *
Fopen(file, mode)
@@ -398,3 +399,59 @@ free_child(pid)
cp->free = 1;
sigprocmask(SIG_SETMASK, &oset, NULL);
}
+
+/*
+ * Lock(1)/unlock(0) mail spool using mail.local's -H flag.
+ * Returns 1 for success, 0 for failure, -1 for bad usage.
+ */
+static int
+handle_spool_locks(action)
+ int action;
+{
+ char *cmd;
+ static FILE *lockfp = NULL;
+ static int lock_pid;
+
+ if (action == 0) {
+ /* Clear the lock */
+ if (lockfp == NULL) {
+ fprintf(stderr,
+ "handle_spool_locks: no spool lock to remove.\n");
+ return (-1);
+ }
+ (void)kill(lock_pid, SIGTERM);
+ Pclose(lockfp);
+ lockfp = NULL;
+ } else if (action == 1) {
+ /* Create the lock */
+ if ((cmd = (char *) malloc(sizeof(_PATH_MAIL_LOCAL) + 3)) == NULL)
+ panic("Out of memory");
+ sprintf(cmd, "%s -H", _PATH_MAIL_LOCAL);
+ if ((lockfp = Popen(cmd, "r")) == NULL || getc(lockfp) != '1') {
+ lockfp = NULL;
+ free(cmd);
+ return (0);
+ }
+
+ lock_pid = fp_head->pid; /* new entries added at head */
+ free(cmd);
+ } else {
+ fprintf(stderr, "handle_spool_locks: unknown action %d\n",
+ action);
+ return (-1);
+ }
+
+ return (1);
+}
+
+int
+spool_lock()
+{
+ return(handle_spool_locks(1));
+}
+
+int
+spool_unlock()
+{
+ return(handle_spool_locks(0));
+}
diff --git a/usr.bin/mail/quit.c b/usr.bin/mail/quit.c
index bf63671f4cb..104101c1f47 100644
--- a/usr.bin/mail/quit.c
+++ b/usr.bin/mail/quit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: quit.c,v 1.2 1996/06/11 12:53:48 deraadt Exp $ */
+/* $OpenBSD: quit.c,v 1.3 1997/03/29 03:01:47 millert Exp $ */
/* $NetBSD: quit.c,v 1.5 1996/06/08 19:48:37 christos Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)quit.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: quit.c,v 1.2 1996/06/11 12:53:48 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: quit.c,v 1.3 1997/03/29 03:01:47 millert Exp $";
#endif
#endif /* not lint */
@@ -113,13 +113,14 @@ quit()
if (fbuf == NULL)
goto newmail;
if (flock(fileno(fbuf), LOCK_EX) == -1) {
-nolock:
perror("Unable to lock mailbox");
Fclose(fbuf);
return;
}
- if (dot_lock(mailname, 1, stdout, ".") == -1)
- goto nolock;
+ if (!spool_lock()) {
+ Fclose(fbuf);
+ return; /* mail.local printed error for us */
+ }
rbuf = NULL;
if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) {
printf("New mail has arrived.\n");
@@ -192,14 +193,14 @@ nolock:
printf("Held %d message%s in %s\n",
p, p == 1 ? "" : "s", mailname);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
if (c == 0) {
if (p != 0) {
writeback(rbuf);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
goto cream;
@@ -218,7 +219,7 @@ nolock:
if ((obuf = Fopen(tempQuit, "w")) == NULL) {
perror(tempQuit);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
if ((ibuf = Fopen(tempQuit, "r")) == NULL) {
@@ -226,7 +227,7 @@ nolock:
rm(tempQuit);
Fclose(obuf);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
rm(tempQuit);
@@ -240,7 +241,7 @@ nolock:
Fclose(ibuf);
Fclose(obuf);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
Fclose(obuf);
@@ -249,7 +250,7 @@ nolock:
perror(mbox);
Fclose(ibuf);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
}
@@ -257,7 +258,7 @@ nolock:
if ((obuf = Fopen(mbox, "a")) == NULL) {
perror(mbox);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
fchmod(fileno(obuf), 0600);
@@ -269,7 +270,7 @@ nolock:
Fclose(ibuf);
Fclose(obuf);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
@@ -296,7 +297,7 @@ nolock:
perror(mbox);
Fclose(obuf);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
Fclose(obuf);
@@ -313,7 +314,7 @@ nolock:
if (p != 0) {
writeback(rbuf);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
@@ -334,19 +335,19 @@ cream:
Fclose(abuf);
alter(mailname);
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
}
demail();
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
return;
newmail:
printf("Thou hast new mail.\n");
if (fbuf != NULL) {
Fclose(fbuf);
- dot_unlock(mailname);
+ spool_unlock();
}
}
@@ -418,7 +419,7 @@ edstop()
register struct message *mp;
FILE *obuf, *ibuf, *readstat = NULL;
struct stat statb;
- char *tempname;
+ char tempname[MAXPATHLEN];
if (readonly)
return;
@@ -447,9 +448,12 @@ edstop()
goto done;
ibuf = NULL;
if (stat(mailname, &statb) >= 0 && statb.st_size > mailsize) {
- tempname = tempnam(tmpdir, "mbox");
+ int fd;
- if ((obuf = Fopen(tempname, "w")) == NULL) {
+ snprintf(tempname, sizeof(tempname), "%s/%s", tmpdir,
+ "mboxXXXXXXXXXX");
+ if ((fd = mkstemp(tempname)) == -1 ||
+ (obuf = Fdopen(fd, "w")) == NULL) {
perror(tempname);
relsesigs();
reset(0);
@@ -473,7 +477,6 @@ edstop()
reset(0);
}
rm(tempname);
- free(tempname);
}
printf("\"%s\" ", mailname);
fflush(stdout);
diff --git a/usr.bin/mail/temp.c b/usr.bin/mail/temp.c
index 108e5bc0874..312768ae6b3 100644
--- a/usr.bin/mail/temp.c
+++ b/usr.bin/mail/temp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: temp.c,v 1.4 1996/10/28 00:42:21 millert Exp $ */
+/* $OpenBSD: temp.c,v 1.5 1997/03/29 03:01:47 millert Exp $ */
/* $NetBSD: temp.c,v 1.5 1996/06/08 19:48:42 christos Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)temp.c 8.1 (Berkeley) 6/6/93";
#else
-static char rcsid[] = "$OpenBSD: temp.c,v 1.4 1996/10/28 00:42:21 millert Exp $";
+static char rcsid[] = "$OpenBSD: temp.c,v 1.5 1997/03/29 03:01:47 millert Exp $";
#endif
#endif /* not lint */
@@ -64,8 +64,16 @@ tinit()
{
register char *cp;
- if ((tmpdir = getenv("TMPDIR")) == NULL) {
+ if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0')
tmpdir = _PATH_TMP;
+ if ((tmpdir = strdup(tmpdir)) == NULL)
+ panic("Out of memory");
+
+ /* Strip trailing '/' if necesary */
+ cp = tmpdir + strlen(tmpdir) - 1;
+ while (cp > tmpdir && *cp == '/') {
+ *cp = '\0';
+ cp--;
}
tempMail = tempnam(tmpdir, "Rs");