1: /*
2: * Copyright (c) 2008, 2010-2013 Todd C. Miller <Todd.Miller@courtesan.com>
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: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
16: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17: */
18:
19: #include <config.h>
20:
21: #include <sys/types.h>
22: #include <limits.h>
23: #include <stdio.h>
24: #include <stdlib.h>
25: #include <string.h>
26: #include <signal.h>
27: #include <unistd.h>
28: #ifdef HAVE_STDBOOL_H
29: # include <stdbool.h>
30: #else
31: # include "compat/stdbool.h"
32: #endif /* HAVE_STDBOOL_H */
33:
34: #include "gettext.h" /* must be included before missing.h */
35:
36: #include "missing.h"
37: #include "alloc.h"
38: #include "fatal.h"
39: #include "sudo_conf.h"
40: #include "sudo_debug.h"
41: #include "sudo_exec.h"
42: #include "sudo_plugin.h"
43:
44: __dso_public int main(int argc, char *argv[], char *envp[]);
45:
46: int
47: main(int argc, char *argv[], char *envp[])
48: {
49: char *cp, *cmnd;
50: bool login_shell, noexec = false;
51: debug_decl(main, SUDO_DEBUG_MAIN)
52:
53: setlocale(LC_ALL, "");
54: bindtextdomain(PACKAGE_NAME, LOCALEDIR);
55: textdomain(PACKAGE_NAME);
56:
57: if (argc < 2)
58: fatalx(U_("requires at least one argument"));
59:
60: /* Read sudo.conf. */
61: sudo_conf_read(NULL);
62:
63: /* If the first char of argv[0] is '-', we are running as a login shell. */
64: login_shell = argv[0][0] == '-';
65:
66: /* If argv[0] ends in -noexec, pass the flag to sudo_execve() */
67: if ((cp = strrchr(argv[0], '-')) != NULL && cp != argv[0])
68: noexec = strcmp(cp, "-noexec") == 0;
69:
70: /* Shift argv and make a copy of the command to execute. */
71: argv++;
72: argc--;
73: cmnd = estrdup(argv[0]);
74:
75: /* If invoked as a login shell, modify argv[0] accordingly. */
76: if (login_shell) {
77: if ((cp = strrchr(argv[0], '/')) == NULL)
78: cp = argv[0];
79: *cp = '-';
80: }
81: sudo_execve(cmnd, argv, envp, noexec);
82: warning(U_("unable to execute %s"), argv[0]);
83: sudo_debug_exit_int(__func__, __FILE__, __LINE__, sudo_debug_subsys, EXIT_FAILURE);
84: _exit(EXIT_FAILURE);
85: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>