Annotation of embedaddon/sudo/src/sesh.c, revision 1.1.1.3

1.1       misho       1: /*
                      2:  * Copyright (c) 2008, 2010 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>
1.1.1.3 ! misho      26: #include <signal.h>
1.1       misho      27: #include <unistd.h>
                     28: #ifdef HAVE_SETLOCALE
                     29: # include <locale.h>
                     30: #endif
1.1.1.2   misho      31: #ifdef HAVE_STDBOOL_H
                     32: # include <stdbool.h>
                     33: #else
                     34: # include "compat/stdbool.h"
                     35: #endif /* HAVE_STDBOOL_H */
1.1       misho      36: 
                     37: #include "missing.h"
1.1.1.2   misho      38: #include "alloc.h"
                     39: #include "error.h"
1.1       misho      40: #include "gettext.h"
1.1.1.2   misho      41: #include "sudo_conf.h"
                     42: #include "sudo_debug.h"
                     43: #include "sudo_exec.h"
                     44: #include "sudo_plugin.h"
                     45: 
                     46: sudo_conv_t sudo_conv;  /* NULL in non-plugin */
                     47: 
                     48: /*
                     49:  * Cleanup hook for error()/errorx()
                     50:  */
                     51: void
                     52: cleanup(int gotsignal)
                     53: {
                     54:     return;
                     55: }
1.1       misho      56: 
                     57: int
1.1.1.2   misho      58: main(int argc, char *argv[], char *envp[])
1.1       misho      59: {
                     60:     char *cp, *cmnd;
1.1.1.2   misho      61:     int noexec = 0;
                     62:     debug_decl(main, SUDO_DEBUG_MAIN)
1.1       misho      63: 
                     64: #ifdef HAVE_SETLOCALE 
                     65:     setlocale(LC_ALL, "");
                     66: #endif
                     67:     bindtextdomain(PACKAGE_NAME, LOCALEDIR);
                     68:     textdomain(PACKAGE_NAME);
                     69: 
                     70:     if (argc < 2)
1.1.1.2   misho      71:        errorx(EXIT_FAILURE, _("requires at least one argument"));
                     72: 
                     73:     /* Read sudo.conf. */
                     74:     sudo_conf_read();
                     75: 
                     76:     /* If argv[0] ends in -noexec, pass the flag to sudo_execve() */
                     77:     if ((cp = strrchr(argv[0], '-')) != NULL && cp != argv[0])
                     78:        noexec = strcmp(cp, "-noexec") == 0;
1.1       misho      79: 
                     80:     /* Shift argv and make a copy of the command to execute. */
                     81:     argv++;
                     82:     argc--;
1.1.1.2   misho      83:     cmnd = estrdup(argv[0]);
1.1       misho      84: 
                     85:     /* If invoked as a login shell, modify argv[0] accordingly. */
1.1.1.2   misho      86:     if (argv[-1][0] == '-') {
1.1       misho      87:        if ((cp = strrchr(argv[0], '/')) == NULL)
                     88:            cp = argv[0];
                     89:        *cp = '-';
                     90:     }
1.1.1.2   misho      91:     sudo_execve(cmnd, argv, envp, noexec);
                     92:     warning(_("unable to execute %s"), argv[0]);
                     93:     sudo_debug_exit_int(__func__, __FILE__, __LINE__, sudo_debug_subsys, EXIT_FAILURE);                
1.1       misho      94:     _exit(EXIT_FAILURE);
                     95: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>