* Copyright (c) 1983, 1987 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that this notice is preserved and that due credit is given
* to the University of California at Berkeley. The name of the University
* may not be used to endorse or promote products derived from this
* software without specific prior written permission. This software
* is provided ``as is'' without express or implied warranty.
"@(#) Copyright (c) 1983, 1987 Regents of the University of California.\n\
static char sccsid
[] = "@(#)vacation.c 5.7 (Berkeley) %G%";
** Copyright (c) 1983 Eric P. Allman
** VACATION -- return a message to the sender when on vacation.
** This program could be invoked as a message receiver when someone is
** on vacation. It returns a message specified by the user to whoever
** sent the mail, taking care not to return a message too often to
** prevent "I am on vacation" loops.
#define MAXLINE 500 /* max line from mail header */
#define PERIOD (60L*60L*24L*7L) /* week between notifications */
#define VMSG ".vacation.msg" /* vacation message */
#define VACAT ".vacation" /* dbm's database prefix */
#define VDIR ".vacation.dir" /* dbm's DB prefix, part 1 */
#define VPAG ".vacation.pag" /* dbm's DB prefix, part 2 */
static char from
[MAXLINE
]; /* sender's address */
while ((ch
= getopt(argc
, argv
, "a:Ii")) != EOF
)
if (!(cur
= (ALIAS
*)malloc((u_int
)sizeof(ALIAS
))))
case 'i': /* init the database */
case 'I': /* backward compatible */
usage
: syslog(LOG_ERR
, "uid %u: usage: vacation [-i] [-a alias] login\n", getuid());
if (!(pw
= getpwuid(getuid()))) {
syslog(LOG_ERR
, "vacation: no such user uid %u.\n", getuid());
else if (!(pw
= getpwnam(*argv
))) {
syslog(LOG_ERR
, "vacation: no such user %s.\n", *argv
);
syslog(LOG_ERR
, "vacation: no such directory %s.\n", pw
->pw_dir
);
if (!(cur
= (ALIAS
*)malloc((u_int
)sizeof(ALIAS
))))
sendmessage(pw
->pw_name
);
char buf
[MAXLINE
], *strcpy(), *index();
while (fgets(buf
, sizeof(buf
), stdin
) && *buf
!= '\n')
if (!strncmp(buf
, "From ", 5)) {
for (p
= buf
+ 5; *p
&& *p
!= ' '; ++p
);
(void)strcpy(from
, buf
+ 5);
case 'P': /* "Precedence:" */
if (strncasecmp(buf
, "Precedence", 10) || buf
[10] != ':' && buf
[10] != ' ' && buf
[10] != '\t')
if (!(p
= index(buf
, ':')))
while (*++p
&& isspace(*p
));
if (!strncasecmp(p
, "junk", 4) || !strncasecmp(p
, "bulk", 4))
if (!strncmp(buf
, "Cc:", 3))
if (strncmp(buf
, "To:", 3))
if (!isspace(*buf
) || !cont
|| tome
) {
findme
: for (cur
= names
; !tome
&& cur
; cur
= cur
->next
)
tome
+= nsearch(cur
->name
, buf
);
syslog(LOG_ERR
, "vacation: no initial \"From\" line.\n");
* read the header and return if automagic/junk/bulk mail
"-REQUEST", 8, "Postmaster", 10,
"uucp", 4, "MAILER-DAEMON", 13,
register struct ignore
*cur
;
char *index(), *rindex();
* This is mildly amusing, and I'm not positive it's right; trying
* to find the "real" name of the sender, assuming that addresses
* will be some variant of:
* From site!site!SENDER%site.domain%site.domain@site.domain
if (!(p
= index(from
, '%')))
if (!(p
= index(from
, '@'))) {
if (p
= rindex(from
, '!'))
for (cur
= ignore
; cur
->name
; ++cur
)
if (len
>= cur
->len
&& !strncasecmp(cur
->name
, p
- cur
->len
, cur
->len
))
* find out if user has gotten a vacation message recently.
time_t now
, then
, time();
k
.dsize
= strlen(from
) + 1;
bcopy(d
.dptr
, (char *)&ldbrec
, sizeof ldbrec
); /* realign data */
return ldbrec
.sentdate
+ Timeout
>= time((time_t *)0);
register char *to
, *from
;
* store that this user knows about the vacation.
k
.dsize
= strlen(from
) + 1;
(void)time(&xrec
.sentdate
);
* exec sendmail to send the vacation file to sender
if (!freopen(VMSG
, "r", stdin
)) {
syslog(LOG_ERR
, "vacation: no ~%s/%s file.\n", myname
, VMSG
);
execl("/usr/lib/sendmail", "sendmail", "-f", myname
, from
, NULL
);
syslog(LOG_ERR
, "vacation: can't exec /usr/lib/sendmail.\n");
* initialize the dbm database
extern char *sys_errlist
[];
if ((fd
= open(VDIR
, O_WRONLY
|O_CREAT
|O_TRUNC
, 0644)) < 0) {
syslog(LOG_ERR
, "vacation: %s: %s\n", VDIR
, sys_errlist
[errno
]);
if ((fd
= open(VPAG
, O_WRONLY
|O_CREAT
|O_TRUNC
, 0644)) < 0) {
syslog(LOG_ERR
, "vacation: %s: %s\n", VPAG
, sys_errlist
[errno
]);