Print this page
5189 validate_pkg should support mediated links
Reviewed by: Richard Lowe <richlowe@richlowe.net>
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/scripts/validate_pkg.py
          +++ new/usr/src/tools/scripts/validate_pkg.py
↓ open down ↓ 52 lines elided ↑ open up ↑
  53   53          ("path", "path=")
  54   54      ],
  55   55      "file": [
  56   56          ("hash", ""),
  57   57          ("group", "group="),
  58   58          ("mode", "mode="),
  59   59          ("owner", "owner="),
  60   60          ("path", "path=")
  61   61      ],
  62   62      "link": [
       63 +        ("mediator", "mediator="),
  63   64          ("path", "path="),
  64   65          ("target", "target=")
  65   66      ],
  66   67      "hardlink": [
  67   68          ("path", "path="),
  68   69          ("hardkey", "target=")
  69   70      ],
  70   71  }
  71   72  
  72   73  # Mode checks used to validate safe file and directory permissions
↓ open down ↓ 116 lines elided ↑ open up ↑
 189  190          # must be the same.  For file and hardlink, see below.
 190  191          #
 191  192          typelhs = lhs.name()
 192  193          typerhs = rhs.name()
 193  194          if typelhs in ("link", "dir"):
 194  195              if typelhs != typerhs:
 195  196                  return True
 196  197  
 197  198          #
 198  199          # For symlinks, all that's left is the link target.
      200 +        # For mediated symlinks targets can differ.
 199  201          #
 200  202          if typelhs == "link":
 201      -            return lhs.target != rhs.target
      203 +            return (lhs.mediator is None) and (lhs.target != rhs.target)
 202  204  
 203  205          #
 204  206          # For a directory, it's important that both be directories,
 205  207          # the modes be identical, and the paths are identical.  We already
 206  208          # checked all but the modes above.
 207  209          #
 208  210          # If both objects are files, then we're in the same boat.
 209  211          #
 210  212          if typelhs == "dir" or (typelhs == "file" and typerhs == "file"):
 211  213              return lhs.mode != rhs.mode
↓ open down ↓ 87 lines elided ↑ open up ↑
 299  301          if action.name == "file":
 300  302              self.owner = action.attrs["owner"]
 301  303              self.group = action.attrs["group"]
 302  304              self.mode = action.attrs["mode"]
 303  305              self.hash = action.hash
 304  306              if "preserve" in action.attrs:
 305  307                  self.editable = True
 306  308          elif action.name == "link":
 307  309              target = action.attrs["target"]
 308  310              self.target = os.path.normpath(target)
      311 +            self.mediator = action.attrs.get("mediator")
 309  312          elif action.name == "dir":
 310  313              self.owner = action.attrs["owner"]
 311  314              self.group = action.attrs["group"]
 312  315              self.mode = action.attrs["mode"]
 313  316              self.isdir = True
 314  317          elif action.name == "hardlink":
 315  318              target = os.path.normpath(action.get_target_path())
 316  319              self.hardkey = target
 317  320              self.hardpaths.add(target)
 318  321  
↓ open down ↓ 40 lines elided ↑ open up ↑
 359  362  
 360  363          #
 361  364          # Per stat.py, these cases are mutually exclusive.
 362  365          #
 363  366          if stat.S_ISREG(mode):
 364  367              self.hash = self.path
 365  368          elif stat.S_ISDIR(mode):
 366  369              self.isdir = True
 367  370          elif stat.S_ISLNK(mode):
 368  371              self.target = os.path.normpath(os.readlink(path))
      372 +            self.mediator = None
 369  373          else:
 370  374              raise UnsupportedFileFormatError(path, mode)
 371  375  
 372  376          if not stat.S_ISLNK(mode):
 373  377              self.mode = "%04o" % stat.S_IMODE(mode)
 374  378              #
 375  379              # Instead of reading the group and owner from the proto area after
 376  380              # a non-root build, just drop in dummy values.  Since we don't
 377  381              # compare them anywhere, this should allow at least marginally
 378  382              # useful comparisons of protolist-style output.
↓ open down ↓ 513 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX