static char SccsId
[] = "@(#)vacation.c 3.3 %G%";
** 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.
** Positional Parameters:
** -I initialize the database.
** A message is sent back to the sender.
# define MAXLINE 256 /* max size of a line */
# define MAXNAME 128 /* max size of one name */
# define ONEWEEK (60L*60L*24L*7L)
long Timeout
= ONEWEEK
; /* timeout between notices per user */
extern struct passwd
*getpwnam();
while (--argc
> 0 && (p
= *++argv
) != NULL
&& *p
== '-')
case 'I': /* initialize */
homedir
= getenv("HOME");
strcat(buf
, "/.vacation.dir");
if (close(creat(buf
, 0644)) < 0)
syserr("Cannot create %s", buf
);
strcat(buf
, "/.vacation.pag");
if (close(creat(buf
, 0644)) < 0)
syserr("Cannot create %s", buf
);
case 't': /* set timeout */
usrerr("Unknown flag -%s", p
);
/* verify recipient argument */
usrerr("Usage: vacation username (or) vacation -I");
/* find user's home directory */
usrerr("Unknown user %s", p
);
homedir
= newstr(pw
->pw_dir
);
strcat(buf
, "/.vacation");
/* read message from standard input (just from line) */
/* check if this person is already informed */
/* mark this person as knowing */
/* send the message back */
** GETFROM -- read message from standard input and return sender
** pointer to the sender address.
** Reads first line from standard input.
static char line
[MAXLINE
];
if (fgets(line
, sizeof line
, stdin
) == NULL
||
strncmp(line
, "From ", 5) != NULL
)
usrerr("No initial From line");
/* find the end of the sender address and terminate it */
p
= index(&line
[5], ' ');
usrerr("Funny From line '%s'", line
);
/* return the sender address */
** KNOWS -- predicate telling if user has already been informed.
** user -- the user who sent this message.
** TRUE if 'user' has already been informed that the
** recipient is on vacation.
k
.dsize
= strlen(user
) + 1;
if (d
.dptr
== NULL
|| ((struct dbrec
*) d
.dptr
)->sentdate
+ Timeout
< now
)
** SETKNOWS -- set that this user knows about the vacation.
** user -- the user who should be marked.
** The dbm file is updated as appropriate.
k
.dsize
= strlen(user
) + 1;
** SENDMESSAGE -- send a message to a particular user.
** msgf -- filename containing the message.
** user -- user who should receive it.
** sends mail to 'user' using /usr/lib/sendmail.
/* find the message to send */
f
= freopen(msgf
, "r", stdin
);
f
= freopen("/usr/lib/vacation.def", "r", stdin
);
syserr("No message to send");
execl("/usr/lib/sendmail", "sendmail", "-n", user
, NULL
);
syserr("Cannot exec /usr/lib/sendmail");
** USRERR -- print user error
fprintf(stderr
, "vacation: ");
** SYSERR -- print system error
fprintf(stderr
, "vacation: ");
** CONVTIME -- convert time
** p -- pointer to ascii time.
t
= t
* 10 + (*p
++ - '0');