Print this page
OS-4335 ipadm_door_call should work in a branded zone without chroot
OS-4336 ipmgmtd should work in a branded zone without chroot
Reviewed by: Robert Mustacchi <rm@joyent.com>
OS-2837 lx brand only works with shared IP stacks

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libipadm/common/libipadm.c
          +++ new/usr/src/lib/libipadm/common/libipadm.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  /*
  23   23   * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
       24 + * Copyright 2015 Joyent, Inc.
  24   25   * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
  25   26   */
  26   27  
  27   28  #include <stdio.h>
  28   29  #include <stdlib.h>
  29   30  #include <string.h>
  30   31  #include <errno.h>
  31   32  #include <fcntl.h>
  32   33  #include <unistd.h>
  33   34  #include <stropts.h>
↓ open down ↓ 244 lines elided ↑ open up ↑
 278  279          free(iph);
 279  280  }
 280  281  
 281  282  /*
 282  283   * Checks if the caller has the authorization to configure network
 283  284   * interfaces.
 284  285   */
 285  286  boolean_t
 286  287  ipadm_check_auth(void)
 287  288  {
      289 +        int             uid;
 288  290          struct passwd   pwd;
 289  291          char            buf[NSS_BUFLEN_PASSWD];
 290  292  
      293 +        /*
      294 +         * Branded zones may have different kinds of auth, but root always
      295 +         * allowed.
      296 +         */
      297 +        if ((uid = getuid()) == 0)
      298 +                return (B_TRUE);
      299 +
 291  300          /* get the password entry for the given user ID */
 292      -        if (getpwuid_r(getuid(), &pwd, buf, sizeof (buf)) == NULL)
      301 +        if (getpwuid_r(uid, &pwd, buf, sizeof (buf)) == NULL)
 293  302                  return (B_FALSE);
 294  303  
 295  304          /* check for presence of given authorization */
 296  305          return (chkauthattr(NETWORK_INTERFACE_CONFIG_AUTH, pwd.pw_name) != 0);
 297  306  }
 298  307  
 299  308  /*
 300  309   * Stores the index value of the interface in `ifname' for the address
 301  310   * family `af' into the buffer pointed to by `index'.
 302  311   */
↓ open down ↓ 587 lines elided ↑ open up ↑
 890  899  
 891  900          darg.data_ptr = arg;
 892  901          darg.data_size = asize;
 893  902          darg.desc_ptr = NULL;
 894  903          darg.desc_num = 0;
 895  904          darg.rbuf = *rbufp;
 896  905          darg.rsize = rsize;
 897  906  
 898  907  reopen:
 899  908          (void) pthread_mutex_lock(&iph->iph_lock);
 900      -        /* The door descriptor is opened if it isn't already */
      909 +        /*
      910 +         * The door descriptor is opened if it isn't already.
      911 +         */
 901  912          if (iph->iph_door_fd == -1) {
 902      -                if ((iph->iph_door_fd = open(IPMGMT_DOOR, O_RDONLY)) < 0) {
      913 +                char door[MAXPATHLEN];
      914 +                const char *zroot = zone_get_nroot();
      915 +
      916 +                /*
      917 +                 * If this is a branded zone, make sure we use the "/native"
      918 +                 * prefix for the door path:
      919 +                 */
      920 +                (void) snprintf(door, sizeof (door), "%s%s", zroot != NULL ?
      921 +                    zroot : "", IPMGMT_DOOR);
      922 +
      923 +                if ((iph->iph_door_fd = open(door, O_RDONLY)) < 0) {
 903  924                          err = errno;
 904  925                          (void) pthread_mutex_unlock(&iph->iph_lock);
 905  926                          return (err);
 906  927                  }
 907  928          }
 908  929          (void) pthread_mutex_unlock(&iph->iph_lock);
 909  930  
 910  931          if (door_call(iph->iph_door_fd, &darg) == -1) {
 911  932                  /*
 912  933                   * Stale door descriptor is possible if ipmgmtd was restarted
↓ open down ↓ 46 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX