1 /*
2 * Copyright (c) 2017 Gilles Chehade <gilles@poolp.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include <sys/wait.h>
18
19 #include <err.h>
20 #include <errno.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <sysexits.h>
24 #include <unistd.h>
25
26 int
main(int argc,char * argv[])27 main(int argc, char *argv[])
28 {
29 int ch;
30 int ret;
31
32 if (! geteuid())
33 errx(1, "mail.mda: may not be executed as root");
34
35 while ((ch = getopt(argc, argv, "")) != -1) {
36 switch (ch) {
37 default:
38 break;
39 }
40 }
41 argc -= optind;
42 argv += optind;
43
44 if (argc == 0)
45 errx(1, "mail.mda: command required");
46
47 if (argc > 1)
48 errx(1, "mail.mda: only one command is supported");
49
50 /* could not obtain a shell or could not obtain wait status,
51 * tempfail */
52 if ((ret = system(argv[0])) == -1)
53 errx(EX_TEMPFAIL, "%s", strerror(errno));
54
55 /* not exited properly but we have no details,
56 * tempfail */
57 if (! WIFEXITED(ret))
58 exit(EX_TEMPFAIL);
59
60 exit(WEXITSTATUS(ret));
61 }
62