summaryrefslogtreecommitdiff
path: root/usr.bin/vacation/vacation.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1998-02-07 02:47:22 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1998-02-07 02:47:22 +0000
commit5759f6ac45f202510b37976b8e8aa812d3d59384 (patch)
treed553749b9452725bc1db3e4c587d0478b8205142 /usr.bin/vacation/vacation.c
parent40eaa7a6f4fec628aa311a20224267e2babd089b (diff)
o Don't put newlines in syslog() messages and use %m, not strerror()
o If .vacation.db is size 0, dbopen() with O_TRUNC (otherwise vacation will do exit(1) and sendmail will be unhappy. dbopen() should probably deal with zero-length files sanely.
Diffstat (limited to 'usr.bin/vacation/vacation.c')
-rw-r--r--usr.bin/vacation/vacation.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/usr.bin/vacation/vacation.c b/usr.bin/vacation/vacation.c
index e8f2105bb88..4b7cbd34c75 100644
--- a/usr.bin/vacation/vacation.c
+++ b/usr.bin/vacation/vacation.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vacation.c,v 1.8 1997/08/06 23:47:09 deraadt Exp $ */
+/* $OpenBSD: vacation.c,v 1.9 1998/02/07 02:47:21 millert Exp $ */
/* $NetBSD: vacation.c,v 1.7 1995/04/29 05:58:27 cgd Exp $ */
/*
@@ -44,7 +44,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)vacation.c 8.2 (Berkeley) 1/26/94";
#endif
-static char rcsid[] = "$OpenBSD: vacation.c,v 1.8 1997/08/06 23:47:09 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: vacation.c,v 1.9 1998/02/07 02:47:21 millert Exp $";
#endif /* not lint */
/*
@@ -105,12 +105,11 @@ main(argc, argv)
int argc;
char **argv;
{
- extern int optind, opterr;
- extern char *optarg;
struct passwd *pw;
+ struct stat sb;
ALIAS *cur;
time_t interval;
- int ch, iflag;
+ int ch, iflag, flags;
opterr = iflag = 0;
interval = -1;
@@ -148,24 +147,31 @@ main(argc, argv)
usage();
if (!(pw = getpwuid(getuid()))) {
syslog(LOG_ERR,
- "vacation: no such user uid %u.\n", getuid());
+ "vacation: no such user uid %u.", getuid());
exit(1);
}
}
else if (!(pw = getpwnam(*argv))) {
- syslog(LOG_ERR, "vacation: no such user %s.\n", *argv);
+ syslog(LOG_ERR, "vacation: no such user %s.", *argv);
exit(1);
}
if (chdir(pw->pw_dir)) {
syslog(LOG_NOTICE,
- "vacation: no such directory %s.\n", pw->pw_dir);
+ "vacation: no such directory %s.", pw->pw_dir);
exit(1);
}
- db = dbopen(VDB, O_CREAT|O_RDWR | (iflag ? O_TRUNC : 0),
- S_IRUSR|S_IWUSR, DB_HASH, NULL);
+ /*
+ * dbopen(3) can not deal with a zero-length file w/o O_TRUNC.
+ */
+ if (iflag == 1 || (stat(VDB, &sb) == 0 && sb.st_size == (off_t)0))
+ flags = O_CREAT|O_RDWR|O_TRUNC;
+ else
+ flags = O_CREAT|O_RDWR;
+
+ db = dbopen(VDB, flags, S_IRUSR|S_IWUSR, DB_HASH, NULL);
if (!db) {
- syslog(LOG_NOTICE, "vacation: %s: %s\n", VDB, strerror(errno));
+ syslog(LOG_NOTICE, "vacation: %s: %m", VDB);
exit(1);
}
@@ -258,7 +264,7 @@ findme: for (cur = names; !tome && cur; cur = cur->next)
if (!tome)
exit(0);
if (!*from) {
- syslog(LOG_NOTICE, "vacation: no initial \"From\" line.\n");
+ syslog(LOG_NOTICE, "vacation: no initial \"From\" line.");
exit(1);
}
}
@@ -404,16 +410,16 @@ sendmessage(myname)
mfp = fopen(VMSG, "r");
if (mfp == NULL) {
- syslog(LOG_NOTICE, "vacation: no ~%s/%s file.\n", myname, VMSG);
+ syslog(LOG_NOTICE, "vacation: no ~%s/%s file.", myname, VMSG);
exit(1);
}
if (pipe(pvect) < 0) {
- syslog(LOG_ERR, "vacation: pipe: %s", strerror(errno));
+ syslog(LOG_ERR, "vacation: pipe: %m");
exit(1);
}
i = vfork();
if (i < 0) {
- syslog(LOG_ERR, "vacation: fork: %s", strerror(errno));
+ syslog(LOG_ERR, "vacation: fork: %m");
exit(1);
}
if (i == 0) {
@@ -423,8 +429,7 @@ sendmessage(myname)
fclose(mfp);
execl(_PATH_SENDMAIL, "sendmail", "-f", myname, "--",
from, NULL);
- syslog(LOG_ERR, "vacation: can't exec %s: %s",
- _PATH_SENDMAIL, strerror(errno));
+ syslog(LOG_ERR, "vacation: can't exec %s: %m", _PATH_SENDMAIL);
_exit(1);
}
close(pvect[0]);
@@ -439,7 +444,7 @@ sendmessage(myname)
void
usage()
{
- syslog(LOG_NOTICE, "uid %u: usage: vacation [-i] [-a alias] login\n",
+ syslog(LOG_NOTICE, "uid %u: usage: vacation [-i] [-a alias] login",
getuid());
exit(1);
}