Print this page
3091 add -n to zlogin so its more compatible with rsh command line

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/zlogin/zlogin.c
          +++ new/usr/src/cmd/zlogin/zlogin.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  23   23   * Copyright 2013 DEY Storage Systems, Inc.
       24 + * Copyright (c) 2014 Gary Mills
  24   25   */
  25   26  
  26   27  /*
  27   28   * zlogin provides three types of login which allow users in the global
  28   29   * zone to access non-global zones.
  29   30   *
  30   31   * - "interactive login" is similar to rlogin(1); for example, the user could
  31   32   *   issue 'zlogin my-zone' or 'zlogin -e ^ -l me my-zone'.   The user is
  32   33   *   granted a new pty (which is then shoved into the zone), and an I/O
  33   34   *   loop between parent and child processes takes care of the interactive
↓ open down ↓ 19 lines elided ↑ open up ↑
  53   54  #include <sys/utsname.h>
  54   55  #include <sys/stat.h>
  55   56  #include <sys/types.h>
  56   57  #include <sys/contract/process.h>
  57   58  #include <sys/ctfs.h>
  58   59  #include <sys/brand.h>
  59   60  #include <sys/wait.h>
  60   61  #include <alloca.h>
  61   62  #include <assert.h>
  62   63  #include <ctype.h>
       64 +#include <paths.h>
  63   65  #include <door.h>
  64   66  #include <errno.h>
  65   67  #include <nss_dbdefs.h>
  66   68  #include <poll.h>
  67   69  #include <priv.h>
  68   70  #include <pwd.h>
  69   71  #include <unistd.h>
  70   72  #include <utmpx.h>
  71   73  #include <sac.h>
  72   74  #include <signal.h>
↓ open down ↓ 69 lines elided ↑ open up ↑
 142  144  
 143  145  /*
 144  146   * See canonify() below.  CANONIFY_LEN is the maximum length that a
 145  147   * "canonical" sequence will expand to (backslash, three octal digits, NUL).
 146  148   */
 147  149  #define CANONIFY_LEN 5
 148  150  
 149  151  static void
 150  152  usage(void)
 151  153  {
 152      -        (void) fprintf(stderr, gettext("usage: %s [ -QCES ] [ -e cmdchar ] "
      154 +        (void) fprintf(stderr, gettext("usage: %s [ -nQCES ] [ -e cmdchar ] "
 153  155              "[-l user] zonename [command [args ...] ]\n"), pname);
 154  156          exit(2);
 155  157  }
 156  158  
 157  159  static const char *
 158  160  getpname(const char *arg0)
 159  161  {
 160  162          const char *p = strrchr(arg0, '/');
 161  163  
 162  164          if (p == NULL)
↓ open down ↓ 1559 lines elided ↑ open up ↑
1722 1724  }
1723 1725  
1724 1726  int
1725 1727  main(int argc, char **argv)
1726 1728  {
1727 1729          int arg, console = 0;
1728 1730          zoneid_t zoneid;
1729 1731          zone_state_t st;
1730 1732          char *login = "root";
1731 1733          int lflag = 0;
     1734 +        int nflag = 0;
1732 1735          char *zonename = NULL;
1733 1736          char **proc_args = NULL;
1734 1737          char **new_args, **new_env;
1735 1738          sigset_t block_cld;
1736 1739          char devroot[MAXPATHLEN];
1737 1740          char *slavename, slaveshortname[MAXPATHLEN];
1738 1741          priv_set_t *privset;
1739 1742          int tmpl_fd;
1740 1743          char zonebrand[MAXNAMELEN];
1741 1744          char default_brand[MAXNAMELEN];
↓ open down ↓ 2 lines elided ↑ open up ↑
1744 1747          brand_handle_t bh;
1745 1748          char user_cmd[MAXPATHLEN];
1746 1749          char authname[MAXAUTHS];
1747 1750  
1748 1751          (void) setlocale(LC_ALL, "");
1749 1752          (void) textdomain(TEXT_DOMAIN);
1750 1753  
1751 1754          (void) getpname(argv[0]);
1752 1755          username = get_username();
1753 1756  
1754      -        while ((arg = getopt(argc, argv, "ECR:Se:l:Q")) != EOF) {
     1757 +        while ((arg = getopt(argc, argv, "nECR:Se:l:Q")) != EOF) {
1755 1758                  switch (arg) {
1756 1759                  case 'C':
1757 1760                          console = 1;
1758 1761                          break;
1759 1762                  case 'E':
1760 1763                          nocmdchar = 1;
1761 1764                          break;
1762 1765                  case 'R':       /* undocumented */
1763 1766                          if (*optarg != '/') {
1764 1767                                  zerror(gettext("root path must be absolute."));
↓ open down ↓ 12 lines elided ↑ open up ↑
1777 1780                  case 'S':
1778 1781                          failsafe = 1;
1779 1782                          break;
1780 1783                  case 'e':
1781 1784                          set_cmdchar(optarg);
1782 1785                          break;
1783 1786                  case 'l':
1784 1787                          login = optarg;
1785 1788                          lflag = 1;
1786 1789                          break;
     1790 +                case 'n':
     1791 +                        nflag = 1;
     1792 +                        break;
1787 1793                  default:
1788 1794                          usage();
1789 1795                  }
1790 1796          }
1791 1797  
1792      -        if (console != 0 && lflag != 0) {
1793      -                zerror(gettext("-l may not be specified for console login"));
1794      -                usage();
1795      -        }
     1798 +        if (console != 0) {
1796 1799  
1797      -        if (console != 0 && failsafe != 0) {
1798      -                zerror(gettext("-S may not be specified for console login"));
1799      -                usage();
1800      -        }
     1800 +                if (lflag != 0) {
     1801 +                        zerror(gettext(
     1802 +                            "-l may not be specified for console login"));
     1803 +                        usage();
     1804 +                }
1801 1805  
1802      -        if (console != 0 && zonecfg_in_alt_root()) {
1803      -                zerror(gettext("-R may not be specified for console login"));
1804      -                exit(2);
     1806 +                if (nflag != 0) {
     1807 +                        zerror(gettext(
     1808 +                            "-n may not be specified for console login"));
     1809 +                        usage();
     1810 +                }
     1811 +
     1812 +                if (failsafe != 0) {
     1813 +                        zerror(gettext(
     1814 +                            "-S may not be specified for console login"));
     1815 +                        usage();
     1816 +                }
     1817 +
     1818 +                if (zonecfg_in_alt_root()) {
     1819 +                        zerror(gettext(
     1820 +                            "-R may not be specified for console login"));
     1821 +                        exit(2);
     1822 +                }
     1823 +
1805 1824          }
1806 1825  
1807 1826          if (failsafe != 0 && lflag != 0) {
1808 1827                  zerror(gettext("-l may not be specified for failsafe login"));
1809 1828                  usage();
1810 1829          }
1811 1830  
1812 1831          if (optind == (argc - 1)) {
1813 1832                  /*
1814 1833                   * zone name, no process name; this should be an interactive
1815 1834                   * as long as STDIN is really a tty.
1816 1835                   */
     1836 +                if (nflag != 0) {
     1837 +                        zerror(gettext(
     1838 +                            "-n may not be specified for interactive login"));
     1839 +                        usage();
     1840 +                }
1817 1841                  if (isatty(STDIN_FILENO))
1818 1842                          interactive = 1;
1819 1843                  zonename = argv[optind];
1820 1844          } else if (optind < (argc - 1)) {
1821 1845                  if (console) {
1822 1846                          zerror(gettext("Commands may not be specified for "
1823 1847                              "console login."));
1824 1848                          usage();
1825 1849                  }
1826 1850                  /* zone name and process name, and possibly some args */
↓ open down ↓ 209 lines elided ↑ open up ↑
2036 2060                          return (1);
2037 2061                  }
2038 2062          }
2039 2063          brand_close(bh);
2040 2064  
2041 2065          if ((new_env = prep_env()) == NULL) {
2042 2066                  zperror(gettext("could not assemble new environment"));
2043 2067                  return (1);
2044 2068          }
2045 2069  
2046      -        if (!interactive)
     2070 +        if (!interactive) {
     2071 +                if (nflag) {
     2072 +                        int nfd;
     2073 +
     2074 +                        if ((nfd = open(_PATH_DEVNULL, O_RDONLY)) < 0) {
     2075 +                                zperror(gettext("failed to open null device"));
     2076 +                                return (1);
     2077 +                        }
     2078 +                        if (nfd != STDIN_FILENO) {
     2079 +                                if (dup2(nfd, STDIN_FILENO) < 0) {
     2080 +                                        zperror(gettext(
     2081 +                                            "failed to dup2 null device"));
     2082 +                                        return (1);
     2083 +                                }
     2084 +                                (void) close(nfd);
     2085 +                        }
     2086 +                        /* /dev/null is now standard input */
     2087 +                }
2047 2088                  return (noninteractive_login(zonename, user_cmd, zoneid,
2048 2089                      new_args, new_env));
     2090 +        }
2049 2091  
2050 2092          if (zonecfg_in_alt_root()) {
2051 2093                  zerror(gettext("cannot use interactive login with scratch "
2052 2094                      "zone"));
2053 2095                  return (1);
2054 2096          }
2055 2097  
2056 2098          /*
2057 2099           * Things are more complex in interactive mode; we get the
2058 2100           * master side of the pty, then place the user's terminal into
↓ open down ↓ 181 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX