vacation.c revision 1.29 1 1.29 christos /* $NetBSD: vacation.c,v 1.29 2004/04/05 23:11:34 christos Exp $ */
2 1.5 jtc
3 1.1 cgd /*
4 1.5 jtc * Copyright (c) 1983, 1987, 1993
5 1.5 jtc * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.24 agc * 3. Neither the name of the University nor the names of its contributors
16 1.1 cgd * may be used to endorse or promote products derived from this software
17 1.1 cgd * without specific prior written permission.
18 1.1 cgd *
19 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 cgd * SUCH DAMAGE.
30 1.1 cgd */
31 1.1 cgd
32 1.10 mikel #include <sys/cdefs.h>
33 1.10 mikel
34 1.1 cgd #ifndef lint
35 1.10 mikel __COPYRIGHT("@(#) Copyright (c) 1983, 1987, 1993\n\
36 1.10 mikel The Regents of the University of California. All rights reserved.\n");
37 1.1 cgd #endif /* not lint */
38 1.1 cgd
39 1.1 cgd #ifndef lint
40 1.5 jtc #if 0
41 1.5 jtc static char sccsid[] = "@(#)vacation.c 8.2 (Berkeley) 1/26/94";
42 1.5 jtc #endif
43 1.29 christos __RCSID("$NetBSD: vacation.c,v 1.29 2004/04/05 23:11:34 christos Exp $");
44 1.1 cgd #endif /* not lint */
45 1.1 cgd
46 1.1 cgd /*
47 1.1 cgd ** Vacation
48 1.1 cgd ** Copyright (c) 1983 Eric P. Allman
49 1.1 cgd ** Berkeley, California
50 1.1 cgd */
51 1.1 cgd
52 1.1 cgd #include <sys/param.h>
53 1.1 cgd #include <sys/stat.h>
54 1.10 mikel
55 1.10 mikel #include <ctype.h>
56 1.10 mikel #include <db.h>
57 1.22 christos #include <err.h>
58 1.10 mikel #include <errno.h>
59 1.1 cgd #include <fcntl.h>
60 1.10 mikel #include <paths.h>
61 1.1 cgd #include <pwd.h>
62 1.10 mikel #include <stdio.h>
63 1.10 mikel #include <stdlib.h>
64 1.10 mikel #include <string.h>
65 1.10 mikel #include <syslog.h>
66 1.1 cgd #include <time.h>
67 1.1 cgd #include <tzfile.h>
68 1.1 cgd #include <unistd.h>
69 1.1 cgd
70 1.1 cgd /*
71 1.1 cgd * VACATION -- return a message to the sender when on vacation.
72 1.1 cgd *
73 1.1 cgd * This program is invoked as a message receiver. It returns a
74 1.1 cgd * message specified by the user to whomever sent the mail, taking
75 1.1 cgd * care not to return a message too often to prevent "I am on
76 1.1 cgd * vacation" loops.
77 1.1 cgd */
78 1.1 cgd
79 1.1 cgd #define MAXLINE 1024 /* max line from mail header */
80 1.1 cgd #define VDB ".vacation.db" /* dbm's database */
81 1.1 cgd #define VMSG ".vacation.msg" /* vacation message */
82 1.1 cgd
83 1.1 cgd typedef struct alias {
84 1.1 cgd struct alias *next;
85 1.15 mycroft const char *name;
86 1.17 mjl } alias_t;
87 1.17 mjl alias_t *names;
88 1.1 cgd
89 1.1 cgd DB *db;
90 1.6 jtc char from[MAXLINE];
91 1.22 christos static int tflag = 0;
92 1.25 christos #define APPARENTLY_TO 1
93 1.25 christos #define DELIVERED_TO 2
94 1.25 christos static int fflag = 0;
95 1.25 christos #define FROM_FROM 1
96 1.25 christos #define RETURN_PATH_FROM 2
97 1.25 christos #define SENDER_FROM 4
98 1.27 christos static int debug = 0;
99 1.1 cgd
100 1.17 mjl int main(int, char **);
101 1.17 mjl int junkmail(void);
102 1.17 mjl int nsearch(const char *, const char *);
103 1.27 christos int readheaders(void);
104 1.17 mjl int recent(void);
105 1.25 christos void getfrom(char *);
106 1.17 mjl void sendmessage(const char *);
107 1.17 mjl void setinterval(time_t);
108 1.17 mjl void setreply(void);
109 1.17 mjl void usage(void);
110 1.1 cgd
111 1.6 jtc int
112 1.17 mjl main(int argc, char **argv)
113 1.1 cgd {
114 1.1 cgd struct passwd *pw;
115 1.17 mjl alias_t *cur;
116 1.1 cgd time_t interval;
117 1.27 christos int ch, iflag, rv;
118 1.22 christos char *p;
119 1.1 cgd
120 1.28 wiz setprogname(argv[0]);
121 1.1 cgd opterr = iflag = 0;
122 1.1 cgd interval = -1;
123 1.25 christos openlog(getprogname(), 0, LOG_USER);
124 1.27 christos while ((ch = getopt(argc, argv, "a:df:Iir:t:")) != -1)
125 1.1 cgd switch((char)ch) {
126 1.1 cgd case 'a': /* alias */
127 1.17 mjl if (!(cur = (alias_t *)malloc((size_t)sizeof(alias_t))))
128 1.1 cgd break;
129 1.1 cgd cur->name = optarg;
130 1.1 cgd cur->next = names;
131 1.1 cgd names = cur;
132 1.1 cgd break;
133 1.27 christos case 'd':
134 1.27 christos debug++;
135 1.27 christos break;
136 1.25 christos case 'f':
137 1.25 christos for (p = optarg; *p; p++)
138 1.25 christos switch (*p) {
139 1.25 christos case 'F':
140 1.25 christos fflag |= FROM_FROM;
141 1.25 christos break;
142 1.25 christos case 'R':
143 1.25 christos fflag |= RETURN_PATH_FROM;
144 1.25 christos break;
145 1.25 christos case 'S':
146 1.25 christos fflag |= SENDER_FROM;
147 1.25 christos break;
148 1.25 christos default:
149 1.25 christos errx(1, "Unknown -f option `%c'", *p);
150 1.25 christos }
151 1.25 christos break;
152 1.1 cgd case 'I': /* backward compatible */
153 1.1 cgd case 'i': /* init the database */
154 1.1 cgd iflag = 1;
155 1.1 cgd break;
156 1.1 cgd case 'r':
157 1.16 christos if (isdigit((unsigned char)*optarg)) {
158 1.1 cgd interval = atol(optarg) * SECSPERDAY;
159 1.1 cgd if (interval < 0)
160 1.1 cgd usage();
161 1.1 cgd }
162 1.1 cgd else
163 1.7 cgd interval = (time_t)LONG_MAX; /* XXX */
164 1.1 cgd break;
165 1.22 christos case 't':
166 1.22 christos for (p = optarg; *p; p++)
167 1.22 christos switch (*p) {
168 1.22 christos case 'A':
169 1.22 christos tflag |= APPARENTLY_TO;
170 1.22 christos break;
171 1.22 christos case 'D':
172 1.22 christos tflag |= DELIVERED_TO;
173 1.22 christos break;
174 1.22 christos default:
175 1.22 christos errx(1, "Unknown -t option `%c'", *p);
176 1.22 christos }
177 1.22 christos break;
178 1.1 cgd case '?':
179 1.1 cgd default:
180 1.1 cgd usage();
181 1.1 cgd }
182 1.1 cgd argc -= optind;
183 1.1 cgd argv += optind;
184 1.1 cgd
185 1.1 cgd if (argc != 1) {
186 1.1 cgd if (!iflag)
187 1.1 cgd usage();
188 1.1 cgd if (!(pw = getpwuid(getuid()))) {
189 1.27 christos syslog(LOG_ERR, "%s: no such user uid %u.",
190 1.27 christos getprogname(), getuid());
191 1.1 cgd exit(1);
192 1.1 cgd }
193 1.1 cgd }
194 1.1 cgd else if (!(pw = getpwnam(*argv))) {
195 1.27 christos syslog(LOG_ERR, "%s: no such user %s.",
196 1.27 christos getprogname(), *argv);
197 1.1 cgd exit(1);
198 1.1 cgd }
199 1.1 cgd if (chdir(pw->pw_dir)) {
200 1.27 christos syslog(LOG_ERR, "%s: no such directory %s.",
201 1.27 christos getprogname(), pw->pw_dir);
202 1.1 cgd exit(1);
203 1.1 cgd }
204 1.1 cgd
205 1.2 proven db = dbopen(VDB, O_CREAT|O_RDWR | (iflag ? O_TRUNC : 0),
206 1.5 jtc S_IRUSR|S_IWUSR, DB_HASH, NULL);
207 1.1 cgd if (!db) {
208 1.27 christos syslog(LOG_ERR, "%s: %s: %m", getprogname(), VDB);
209 1.1 cgd exit(1);
210 1.1 cgd }
211 1.1 cgd
212 1.1 cgd if (interval != -1)
213 1.1 cgd setinterval(interval);
214 1.1 cgd
215 1.1 cgd if (iflag) {
216 1.1 cgd (void)(db->close)(db);
217 1.1 cgd exit(0);
218 1.1 cgd }
219 1.1 cgd
220 1.27 christos if (!(cur = malloc((size_t)sizeof(alias_t)))) {
221 1.27 christos syslog(LOG_ERR, "%s: %m", getprogname());
222 1.27 christos (void)(db->close)(db);
223 1.1 cgd exit(1);
224 1.27 christos }
225 1.1 cgd cur->name = pw->pw_name;
226 1.1 cgd cur->next = names;
227 1.1 cgd names = cur;
228 1.1 cgd
229 1.27 christos if ((rv = readheaders()) != -1) {
230 1.27 christos (void)(db->close)(db);
231 1.27 christos exit(rv);
232 1.27 christos }
233 1.27 christos
234 1.1 cgd if (!recent()) {
235 1.1 cgd setreply();
236 1.1 cgd (void)(db->close)(db);
237 1.1 cgd sendmessage(pw->pw_name);
238 1.1 cgd }
239 1.5 jtc else
240 1.5 jtc (void)(db->close)(db);
241 1.1 cgd exit(0);
242 1.1 cgd /* NOTREACHED */
243 1.1 cgd }
244 1.1 cgd
245 1.1 cgd /*
246 1.1 cgd * readheaders --
247 1.1 cgd * read mail headers
248 1.1 cgd */
249 1.27 christos int
250 1.20 perry readheaders(void)
251 1.1 cgd {
252 1.17 mjl alias_t *cur;
253 1.10 mikel char *p;
254 1.1 cgd int tome, cont;
255 1.1 cgd char buf[MAXLINE];
256 1.1 cgd
257 1.1 cgd cont = tome = 0;
258 1.1 cgd while (fgets(buf, sizeof(buf), stdin) && *buf != '\n')
259 1.1 cgd switch(*buf) {
260 1.25 christos case 'F': /* "From " or "From:" */
261 1.1 cgd cont = 0;
262 1.25 christos if (!strncmp(buf, "From ", 5))
263 1.25 christos getfrom(buf + 5);
264 1.26 christos if ((fflag & FROM_FROM) != 0 &&
265 1.26 christos strncmp(buf, "From:", 5) == 0)
266 1.25 christos getfrom(buf + 5);
267 1.1 cgd break;
268 1.1 cgd case 'P': /* "Precedence:" */
269 1.1 cgd cont = 0;
270 1.1 cgd if (strncasecmp(buf, "Precedence", 10) ||
271 1.10 mikel (buf[10] != ':' && buf[10] != ' ' &&
272 1.10 mikel buf[10] != '\t'))
273 1.1 cgd break;
274 1.10 mikel if (!(p = strchr(buf, ':')))
275 1.1 cgd break;
276 1.25 christos while (*++p && isspace((unsigned char)*p))
277 1.25 christos continue;
278 1.1 cgd if (!*p)
279 1.1 cgd break;
280 1.1 cgd if (!strncasecmp(p, "junk", 4) ||
281 1.5 jtc !strncasecmp(p, "bulk", 4) ||
282 1.5 jtc !strncasecmp(p, "list", 4))
283 1.1 cgd exit(0);
284 1.1 cgd break;
285 1.1 cgd case 'C': /* "Cc:" */
286 1.1 cgd if (strncmp(buf, "Cc:", 3))
287 1.1 cgd break;
288 1.1 cgd cont = 1;
289 1.1 cgd goto findme;
290 1.1 cgd case 'T': /* "To:" */
291 1.1 cgd if (strncmp(buf, "To:", 3))
292 1.21 christos break;
293 1.21 christos cont = 1;
294 1.21 christos goto findme;
295 1.25 christos case 'A': /* "Apparently-To:" */
296 1.22 christos if ((tflag & APPARENTLY_TO) == 0 ||
297 1.25 christos strncmp(buf, "Apparently-To:", 14))
298 1.21 christos break;
299 1.21 christos cont = 1;
300 1.21 christos goto findme;
301 1.25 christos case 'D': /* "Delivered-To:" */
302 1.22 christos if ((tflag & DELIVERED_TO) == 0 ||
303 1.25 christos strncmp(buf, "Delivered-To:", 13))
304 1.1 cgd break;
305 1.1 cgd cont = 1;
306 1.1 cgd goto findme;
307 1.25 christos case 'R': /* "Return-Path:" */
308 1.25 christos cont = 0;
309 1.26 christos if ((fflag & RETURN_PATH_FROM) != 0 &&
310 1.26 christos strncmp(buf, "Return-Path:", 12) == 0)
311 1.25 christos getfrom(buf + 12);
312 1.25 christos break;
313 1.25 christos case 'S': /* "Sender:" */
314 1.25 christos cont = 0;
315 1.26 christos if ((fflag & SENDER_FROM) != 0 &&
316 1.26 christos strncmp(buf, "Sender:", 7) == 0)
317 1.25 christos getfrom(buf + 7);
318 1.25 christos break;
319 1.1 cgd default:
320 1.16 christos if (!isspace((unsigned char)*buf) || !cont || tome) {
321 1.1 cgd cont = 0;
322 1.1 cgd break;
323 1.1 cgd }
324 1.1 cgd findme: for (cur = names; !tome && cur; cur = cur->next)
325 1.1 cgd tome += nsearch(cur->name, buf);
326 1.1 cgd }
327 1.1 cgd if (!tome)
328 1.27 christos return 0;
329 1.1 cgd if (!*from) {
330 1.27 christos syslog(LOG_ERR, "%s: no initial \"From\" line.",
331 1.27 christos getprogname());
332 1.27 christos return 1;
333 1.1 cgd }
334 1.27 christos return -1;
335 1.1 cgd }
336 1.1 cgd
337 1.1 cgd /*
338 1.1 cgd * nsearch --
339 1.1 cgd * do a nice, slow, search of a string for a substring.
340 1.1 cgd */
341 1.6 jtc int
342 1.17 mjl nsearch(const char *name, const char *str)
343 1.1 cgd {
344 1.10 mikel size_t len;
345 1.1 cgd
346 1.1 cgd for (len = strlen(name); *str; ++str)
347 1.17 mjl if (!strncasecmp(name, str, len))
348 1.1 cgd return(1);
349 1.1 cgd return(0);
350 1.1 cgd }
351 1.1 cgd
352 1.1 cgd /*
353 1.25 christos * getfrom --
354 1.25 christos * return the first string in the buffer, stripping leading and trailing
355 1.25 christos * blanks and <>.
356 1.25 christos */
357 1.25 christos void
358 1.25 christos getfrom(char *buf)
359 1.25 christos {
360 1.25 christos char *s, *p;
361 1.25 christos
362 1.27 christos if ((s = strchr(buf, '<')) != NULL)
363 1.27 christos s++;
364 1.27 christos else
365 1.27 christos s = buf;
366 1.27 christos
367 1.27 christos for (; *s && isspace((unsigned char)*s); s++)
368 1.25 christos continue;
369 1.25 christos for (p = s; *p && !isspace((unsigned char)*p); p++)
370 1.25 christos continue;
371 1.25 christos if (*--p == '>')
372 1.25 christos *p = '\0';
373 1.25 christos else
374 1.27 christos *++p = '\0';
375 1.25 christos (void)strlcpy(from, s, sizeof(from));
376 1.25 christos if (junkmail())
377 1.25 christos exit(0);
378 1.25 christos }
379 1.25 christos
380 1.25 christos /*
381 1.1 cgd * junkmail --
382 1.5 jtc * read the header and return if automagic/junk/bulk/list mail
383 1.1 cgd */
384 1.6 jtc int
385 1.20 perry junkmail(void)
386 1.1 cgd {
387 1.1 cgd static struct ignore {
388 1.1 cgd char *name;
389 1.1 cgd int len;
390 1.1 cgd } ignore[] = {
391 1.8 pk { "-request", 8 },
392 1.8 pk { "postmaster", 10 },
393 1.8 pk { "uucp", 4 },
394 1.8 pk { "mailer-daemon", 13 },
395 1.8 pk { "mailer", 6 },
396 1.8 pk { "-relay", 6 },
397 1.8 pk {NULL, 0 }
398 1.1 cgd };
399 1.10 mikel struct ignore *cur;
400 1.10 mikel int len;
401 1.10 mikel char *p;
402 1.1 cgd
403 1.1 cgd /*
404 1.1 cgd * This is mildly amusing, and I'm not positive it's right; trying
405 1.1 cgd * to find the "real" name of the sender, assuming that addresses
406 1.1 cgd * will be some variant of:
407 1.1 cgd *
408 1.1 cgd * From site!site!SENDER%site.domain%site.domain (at) site.domain
409 1.1 cgd */
410 1.10 mikel if (!(p = strchr(from, '%')))
411 1.10 mikel if (!(p = strchr(from, '@'))) {
412 1.10 mikel if ((p = strrchr(from, '!')))
413 1.1 cgd ++p;
414 1.1 cgd else
415 1.1 cgd p = from;
416 1.29 christos for (; *p; ++p)
417 1.29 christos continue;
418 1.1 cgd }
419 1.1 cgd len = p - from;
420 1.1 cgd for (cur = ignore; cur->name; ++cur)
421 1.1 cgd if (len >= cur->len &&
422 1.1 cgd !strncasecmp(cur->name, p - cur->len, cur->len))
423 1.1 cgd return(1);
424 1.1 cgd return(0);
425 1.1 cgd }
426 1.1 cgd
427 1.1 cgd #define VIT "__VACATION__INTERVAL__TIMER__"
428 1.1 cgd
429 1.1 cgd /*
430 1.1 cgd * recent --
431 1.1 cgd * find out if user has gotten a vacation message recently.
432 1.11 lukem * use memmove for machines with alignment restrictions
433 1.1 cgd */
434 1.6 jtc int
435 1.20 perry recent(void)
436 1.1 cgd {
437 1.1 cgd DBT key, data;
438 1.1 cgd time_t then, next;
439 1.1 cgd
440 1.1 cgd /* get interval time */
441 1.1 cgd key.data = VIT;
442 1.1 cgd key.size = sizeof(VIT);
443 1.1 cgd if ((db->get)(db, &key, &data, 0))
444 1.1 cgd next = SECSPERDAY * DAYSPERWEEK;
445 1.1 cgd else
446 1.29 christos (void)memmove(&next, data.data, sizeof(next));
447 1.1 cgd
448 1.1 cgd /* get record for this address */
449 1.1 cgd key.data = from;
450 1.1 cgd key.size = strlen(from);
451 1.1 cgd if (!(db->get)(db, &key, &data, 0)) {
452 1.29 christos (void)memmove(&then, data.data, sizeof(then));
453 1.7 cgd if (next == (time_t)LONG_MAX || /* XXX */
454 1.7 cgd then + next > time(NULL))
455 1.1 cgd return(1);
456 1.1 cgd }
457 1.1 cgd return(0);
458 1.1 cgd }
459 1.1 cgd
460 1.1 cgd /*
461 1.1 cgd * setinterval --
462 1.1 cgd * store the reply interval
463 1.1 cgd */
464 1.6 jtc void
465 1.17 mjl setinterval(time_t interval)
466 1.1 cgd {
467 1.1 cgd DBT key, data;
468 1.1 cgd
469 1.1 cgd key.data = VIT;
470 1.1 cgd key.size = sizeof(VIT);
471 1.1 cgd data.data = &interval;
472 1.1 cgd data.size = sizeof(interval);
473 1.3 mycroft (void)(db->put)(db, &key, &data, 0);
474 1.1 cgd }
475 1.1 cgd
476 1.1 cgd /*
477 1.1 cgd * setreply --
478 1.1 cgd * store that this user knows about the vacation.
479 1.1 cgd */
480 1.6 jtc void
481 1.20 perry setreply(void)
482 1.1 cgd {
483 1.1 cgd DBT key, data;
484 1.1 cgd time_t now;
485 1.1 cgd
486 1.1 cgd key.data = from;
487 1.1 cgd key.size = strlen(from);
488 1.1 cgd (void)time(&now);
489 1.1 cgd data.data = &now;
490 1.1 cgd data.size = sizeof(now);
491 1.3 mycroft (void)(db->put)(db, &key, &data, 0);
492 1.1 cgd }
493 1.1 cgd
494 1.1 cgd /*
495 1.1 cgd * sendmessage --
496 1.1 cgd * exec sendmail to send the vacation file to sender
497 1.1 cgd */
498 1.6 jtc void
499 1.17 mjl sendmessage(const char *myname)
500 1.1 cgd {
501 1.5 jtc FILE *mfp, *sfp;
502 1.5 jtc int i;
503 1.5 jtc int pvect[2];
504 1.5 jtc char buf[MAXLINE];
505 1.5 jtc
506 1.5 jtc mfp = fopen(VMSG, "r");
507 1.5 jtc if (mfp == NULL) {
508 1.27 christos syslog(LOG_ERR, "%s: no ~%s/%s file.", getprogname(),
509 1.27 christos myname, VMSG);
510 1.1 cgd exit(1);
511 1.1 cgd }
512 1.27 christos
513 1.27 christos if (debug) {
514 1.27 christos sfp = stdout;
515 1.27 christos } else {
516 1.27 christos if (pipe(pvect) < 0) {
517 1.27 christos syslog(LOG_ERR, "%s: pipe: %m", getprogname());
518 1.27 christos exit(1);
519 1.27 christos }
520 1.27 christos i = vfork();
521 1.27 christos if (i < 0) {
522 1.27 christos syslog(LOG_ERR, "%s: fork: %m", getprogname());
523 1.27 christos exit(1);
524 1.27 christos }
525 1.27 christos if (i == 0) {
526 1.29 christos (void)dup2(pvect[0], 0);
527 1.29 christos (void)close(pvect[0]);
528 1.29 christos (void)close(pvect[1]);
529 1.29 christos (void)close(fileno(mfp));
530 1.29 christos (void)execl(_PATH_SENDMAIL, "sendmail", "-f", myname,
531 1.27 christos "--", from, NULL);
532 1.27 christos syslog(LOG_ERR, "%s: can't exec %s: %m",
533 1.27 christos getprogname(), _PATH_SENDMAIL);
534 1.27 christos _exit(1);
535 1.27 christos }
536 1.27 christos (void)close(pvect[0]);
537 1.27 christos sfp = fdopen(pvect[1], "w");
538 1.29 christos if (sfp == NULL) {
539 1.29 christos syslog(LOG_ERR, "%s: can't fdopen %d: %m",
540 1.29 christos getprogname(), pvect[1]);
541 1.29 christos _exit(1);
542 1.29 christos }
543 1.27 christos }
544 1.29 christos (void)fprintf(sfp, "To: %s\n", from);
545 1.5 jtc while (fgets(buf, sizeof buf, mfp))
546 1.29 christos (void)fputs(buf, sfp);
547 1.27 christos (void)fclose(mfp);
548 1.27 christos if (sfp != stdout)
549 1.27 christos (void)fclose(sfp);
550 1.1 cgd }
551 1.1 cgd
552 1.6 jtc void
553 1.20 perry usage(void)
554 1.1 cgd {
555 1.10 mikel
556 1.28 wiz syslog(LOG_ERR, "uid %u: Usage: %s [-di] [-a alias] [-f F|R|S] [-t A|D]"
557 1.27 christos " login", getuid(), getprogname());
558 1.1 cgd exit(1);
559 1.1 cgd }
560