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