Print this page
5700 add zlogin -d option to allow graceful disconnect when zone is halted
Reviewed by: Andrew Gabriel <illumos@cucumber.demon.co.uk>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/zlogin/zlogin.c
          +++ new/usr/src/cmd/zlogin/zlogin.c
↓ open down ↓ 14 lines elided ↑ open up ↑
  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   24   * Copyright (c) 2014 Gary Mills
  25      - * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
       25 + * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
  26   26   */
  27   27  
  28   28  /*
  29   29   * zlogin provides three types of login which allow users in the global
  30   30   * zone to access non-global zones.
  31   31   *
  32   32   * - "interactive login" is similar to rlogin(1); for example, the user could
  33   33   *   issue 'zlogin my-zone' or 'zlogin -e ^ -l me my-zone'.   The user is
  34   34   *   granted a new pty (which is then shoved into the zone), and an I/O
  35   35   *   loop between parent and child processes takes care of the interactive
↓ open down ↓ 61 lines elided ↑ open up ↑
  97   97  static struct termios effective_termios;
  98   98  static int save_fd;
  99   99  static struct winsize winsize;
 100  100  static volatile int dead;
 101  101  static volatile pid_t child_pid = -1;
 102  102  static int interactive = 0;
 103  103  static priv_set_t *dropprivs;
 104  104  
 105  105  static int nocmdchar = 0;
 106  106  static int failsafe = 0;
      107 +static int disconnect = 0;
 107  108  static char cmdchar = '~';
 108  109  static int quiet = 0;
 109  110  
 110  111  static int pollerr = 0;
 111  112  
 112  113  static const char *pname;
 113  114  static char *username;
 114  115  
 115  116  /*
 116  117   * When forced_login is true, the user is not prompted
↓ open down ↓ 28 lines elided ↑ open up ↑
 145  146  
 146  147  /*
 147  148   * See canonify() below.  CANONIFY_LEN is the maximum length that a
 148  149   * "canonical" sequence will expand to (backslash, three octal digits, NUL).
 149  150   */
 150  151  #define CANONIFY_LEN 5
 151  152  
 152  153  static void
 153  154  usage(void)
 154  155  {
 155      -        (void) fprintf(stderr, gettext("usage: %s [ -nQCES ] [ -e cmdchar ] "
      156 +        (void) fprintf(stderr, gettext("usage: %s [ -dnQCES ] [ -e cmdchar ] "
 156  157              "[-l user] zonename [command [args ...] ]\n"), pname);
 157  158          exit(2);
 158  159  }
 159  160  
 160  161  static const char *
 161  162  getpname(const char *arg0)
 162  163  {
 163  164          const char *p = strrchr(arg0, '/');
 164  165  
 165  166          if (p == NULL)
↓ open down ↓ 105 lines elided ↑ open up ↑
 271  272          (void) snprintf(servaddr.sun_path, sizeof (servaddr.sun_path),
 272  273              "%s/%s.console_sock", ZONES_TMPDIR, zname);
 273  274  
 274  275          if (connect(sockfd, (struct sockaddr *)&servaddr,
 275  276              sizeof (servaddr)) == -1) {
 276  277                  zperror(gettext("Could not connect to zone console"));
 277  278                  goto bad;
 278  279          }
 279  280          masterfd = sockfd;
 280  281  
 281      -        msglen = snprintf(clientid, sizeof (clientid), "IDENT %lu %s\n",
 282      -            getpid(), setlocale(LC_MESSAGES, NULL));
      282 +        msglen = snprintf(clientid, sizeof (clientid), "IDENT %lu %s %d\n",
      283 +            getpid(), setlocale(LC_MESSAGES, NULL), disconnect);
 283  284  
 284  285          if (msglen >= sizeof (clientid) || msglen < 0) {
 285  286                  zerror("protocol error");
 286  287                  goto bad;
 287  288          }
 288  289  
 289  290          if (write(masterfd, clientid, msglen) != msglen) {
 290  291                  zerror("protocol error");
 291  292                  goto bad;
 292  293          }
↓ open down ↓ 1453 lines elided ↑ open up ↑
1746 1747          brand_handle_t bh;
1747 1748          char user_cmd[MAXPATHLEN];
1748 1749          char authname[MAXAUTHS];
1749 1750  
1750 1751          (void) setlocale(LC_ALL, "");
1751 1752          (void) textdomain(TEXT_DOMAIN);
1752 1753  
1753 1754          (void) getpname(argv[0]);
1754 1755          username = get_username();
1755 1756  
1756      -        while ((arg = getopt(argc, argv, "nECR:Se:l:Q")) != EOF) {
     1757 +        while ((arg = getopt(argc, argv, "dnECR:Se:l:Q")) != EOF) {
1757 1758                  switch (arg) {
1758 1759                  case 'C':
1759 1760                          console = 1;
1760 1761                          break;
1761 1762                  case 'E':
1762 1763                          nocmdchar = 1;
1763 1764                          break;
1764 1765                  case 'R':       /* undocumented */
1765 1766                          if (*optarg != '/') {
1766 1767                                  zerror(gettext("root path must be absolute."));
↓ open down ↓ 5 lines elided ↑ open up ↑
1772 1773                                  exit(2);
1773 1774                          }
1774 1775                          zonecfg_set_root(optarg);
1775 1776                          break;
1776 1777                  case 'Q':
1777 1778                          quiet = 1;
1778 1779                          break;
1779 1780                  case 'S':
1780 1781                          failsafe = 1;
1781 1782                          break;
     1783 +                case 'd':
     1784 +                        disconnect = 1;
     1785 +                        break;
1782 1786                  case 'e':
1783 1787                          set_cmdchar(optarg);
1784 1788                          break;
1785 1789                  case 'l':
1786 1790                          login = optarg;
1787 1791                          lflag = 1;
1788 1792                          break;
1789 1793                  case 'n':
1790 1794                          nflag = 1;
1791 1795                          break;
↓ open down ↓ 27 lines elided ↑ open up ↑
1819 1823                              "-R may not be specified for console login"));
1820 1824                          exit(2);
1821 1825                  }
1822 1826  
1823 1827          }
1824 1828  
1825 1829          if (failsafe != 0 && lflag != 0) {
1826 1830                  zerror(gettext("-l may not be specified for failsafe login"));
1827 1831                  usage();
1828 1832          }
     1833 +
     1834 +        if (!console && disconnect != 0) {
     1835 +                zerror(gettext(
     1836 +                    "-d may only be specified with console login"));
     1837 +                usage();
     1838 +        }
1829 1839  
1830 1840          if (optind == (argc - 1)) {
1831 1841                  /*
1832 1842                   * zone name, no process name; this should be an interactive
1833 1843                   * as long as STDIN is really a tty.
1834 1844                   */
1835 1845                  if (nflag != 0) {
1836 1846                          zerror(gettext(
1837 1847                              "-n may not be specified for interactive login"));
1838 1848                          usage();
↓ open down ↓ 442 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX