summaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1998-08-15 21:02:24 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1998-08-15 21:02:24 +0000
commit419d35e63268d3263b1b2192a4e4d85e883ae103 (patch)
tree642b346b262e2513dd63d8a280d1db3793579757 /libexec
parent05f405bf353395695619cad53097ca6ba07ace64 (diff)
Move the spool locking functionality of "mail.local -H" into its own
program so we can take the setuid bit off of mail.local.
Diffstat (limited to 'libexec')
-rw-r--r--libexec/Makefile4
-rw-r--r--libexec/lockspool/Makefile10
-rw-r--r--libexec/lockspool/lockspool.171
-rw-r--r--libexec/lockspool/lockspool.c106
4 files changed, 189 insertions, 2 deletions
diff --git a/libexec/Makefile b/libexec/Makefile
index a3de2afbb80..17ddcb4e4ab 100644
--- a/libexec/Makefile
+++ b/libexec/Makefile
@@ -1,9 +1,9 @@
# from: @(#)Makefile 5.7 (Berkeley) 4/1/91
-# $OpenBSD: Makefile,v 1.14 1997/12/12 06:10:46 beck Exp $
+# $OpenBSD: Makefile,v 1.15 1998/08/15 21:02:20 millert Exp $
.include <bsd.own.mk>
-SUBDIR= atrun comsat fingerd ftpd getNAME getty identd \
+SUBDIR= atrun comsat fingerd ftpd getNAME getty identd lockspool \
mail.local makewhatis rexecd rlogind rshd \
rpc.rquotad rpc.rstatd rpc.rusersd rpc.rwalld rpc.sprayd \
talkd tcpd telnetd tftpd uucpd smtpd
diff --git a/libexec/lockspool/Makefile b/libexec/lockspool/Makefile
new file mode 100644
index 00000000000..63928844288
--- /dev/null
+++ b/libexec/lockspool/Makefile
@@ -0,0 +1,10 @@
+# $OpenBSD: Makefile,v 1.1 1998/08/15 21:02:22 millert Exp $
+
+PROG= lockspool
+SRCS= lockspool.c locking.c
+BINOWN= root
+BINMODE=4555
+CFLAGS+=-I${.CURDIR}/../mail.local
+.PATH: ${.CURDIR}/../mail.local
+
+.include <bsd.prog.mk>
diff --git a/libexec/lockspool/lockspool.1 b/libexec/lockspool/lockspool.1
new file mode 100644
index 00000000000..959e567e5f5
--- /dev/null
+++ b/libexec/lockspool/lockspool.1
@@ -0,0 +1,71 @@
+.\"
+.\" Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
+.\" 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. The name of the author may not be used to endorse or promote products
+.\" derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED ``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 AUTHOR 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.
+.\"
+.Dd August 13, 1998
+.Dt LOCKSPOOL 1
+.Os
+.Sh NAME
+.Nm lockspool
+.Nd lock user's system mailbox
+.Sh SYNOPSIS
+.Nm lockspool
+.Sh DESCRIPTION
+.Nm Lockspool
+is useful for a client mail program to attain proper locking.
+.Nm Lockspool
+obtains a
+.Nm username.lock
+for the calling user and retains it until stdin is closed or a signal
+like SIGINT, SIGTERM, or SIGHUP is received. If
+.Nm lockspool
+is able to create the lock file, ``1'' is written to stdout, otherwise
+``0'' is written and an error message is written to stderr.
+.Nm Lockspool
+will try up to 10 times to get the lock (sleeping
+for a short period in between tries).
+.Pp
+The
+.Nm lockspool
+utility exits 0 on success, and 1 if an error occurs.
+.Sh ENVIRONMENT
+.Bl -tag -width indent
+.It Ev TZ
+Used to set the appropriate time zone on the timestamp.
+.El
+.Sh FILES
+.Bl -tag -width /var/mail/user.lock -compact
+.It Pa /var/mail/username.lock
+user's mail lock file.
+.El
+.Sh HISTORY
+The
+.Nm lockspool
+program appeared in
+.Ox 2.4 .
+.Sh SEE ALSO
+.Xr mail 1 ,
+.Xr mail.local 1 ,
+.Xr sendmail 8
diff --git a/libexec/lockspool/lockspool.c b/libexec/lockspool/lockspool.c
new file mode 100644
index 00000000000..888971ca2f2
--- /dev/null
+++ b/libexec/lockspool/lockspool.c
@@ -0,0 +1,106 @@
+/* $OpenBSD: lockspool.c,v 1.1 1998/08/15 21:02:23 millert Exp $ */
+
+/*
+ * Copyright (c) 1998 Theo de Raadt <deraadt@theos.com>
+ * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
+ * 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. The name of the authors may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``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 AUTHORS 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.
+ */
+
+#ifndef lint
+static char rcsid[] = "$OpenBSD: lockspool.c,v 1.1 1998/08/15 21:02:23 millert Exp $";
+#endif /* not lint */
+
+#include <sys/signal.h>
+#include <pwd.h>
+#include <syslog.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdio.h>
+#include "mail.local.h"
+
+void unhold __P((int));
+void usage __P((void));
+
+extern char *__progname;
+
+int
+main(argc, argv)
+ int argc;
+ char **argv;
+{
+ struct passwd *pw;
+ char *from, c;
+ int holdfd;
+
+ openlog(__progname, LOG_PERROR, LOG_MAIL);
+
+ if (argc != 1)
+ usage();
+
+ signal(SIGTERM, unhold);
+ signal(SIGINT, unhold);
+ signal(SIGHUP, unhold);
+
+ from = getlogin();
+ if (from) {
+ pw = getpwnam(from);
+ if (pw == NULL)
+ exit (1);
+ } else {
+ pw = getpwuid(getuid());
+ if (pw)
+ from = pw->pw_name;
+ else
+ exit (1);
+ }
+
+ holdfd = getlock(from, pw);
+ if (holdfd == -1) {
+ write(STDOUT_FILENO, "0\n", 2);
+ exit (1);
+ }
+ write(STDOUT_FILENO, "1\n", 2);
+
+ while (read(0, &c, 1) == -1 && errno == EINTR)
+ ;
+ rellock();
+ exit (0);
+}
+
+void
+unhold(sig)
+ int sig;
+{
+
+ rellock();
+ exit(0);
+}
+
+void
+usage()
+{
+
+ err(FATAL, "usage: %s", __progname);
+}