userland.py revision 117
45N/A#!/usr/bin/python
45N/A#
45N/A# CDDL HEADER START
45N/A#
45N/A# The contents of this file are subject to the terms of the
45N/A# Common Development and Distribution License (the "License").
45N/A# You may not use this file except in compliance with the License.
45N/A#
45N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
45N/A# or http://www.opensolaris.org/os/licensing.
45N/A# See the License for the specific language governing permissions
45N/A# and limitations under the License.
45N/A#
45N/A# When distributing Covered Code, include this CDDL HEADER in each
45N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
45N/A# If applicable, add the following below this CDDL HEADER, with the
45N/A# fields enclosed by brackets "[]" replaced with your own identifying
45N/A# information: Portions Copyright [yyyy] [name of copyright owner]
45N/A#
45N/A# CDDL HEADER END
45N/A#
45N/A
45N/A#
84N/A# Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
45N/A#
45N/A
45N/A# Some userland consolidation specific lint checks
45N/A
45N/Aimport pkg.lint.base as base
84N/Aimport pkg.elf as elf
45N/Aimport re
45N/Aimport os.path
45N/A
84N/A
45N/Aclass UserlandActionChecker(base.ActionChecker):
45N/A """An opensolaris.org-specific class to check actions."""
45N/A
45N/A name = "userland.action"
45N/A
45N/A def __init__(self, config):
45N/A self.description = _(
45N/A "checks Userland packages for common content errors")
117N/A path = os.getenv('PROTO_PATH')
117N/A if path != None:
117N/A self.proto_path = path.split()
117N/A else:
117N/A self.proto_path = None
45N/A self.runpath_re = [
99N/A re.compile('^/lib(/.*)?$'),
45N/A re.compile('^/usr/'),
45N/A re.compile('^\$ORIGIN/')
45N/A ]
84N/A self.initscript_re = re.compile("^etc/(rc.|init)\.d")
45N/A super(UserlandActionChecker, self).__init__(config)
45N/A
45N/A def startup(self, engine):
117N/A pass
84N/A
84N/A def __realpath(self, path, target):
84N/A """Combine path and target to get the real path."""
84N/A
84N/A result = os.path.dirname(path)
84N/A
84N/A for frag in target.split(os.sep):
84N/A if frag == '..':
84N/A result = os.path.dirname(result)
84N/A elif frag == '.':
84N/A pass
84N/A else:
84N/A result = os.path.join(result, frag)
84N/A
84N/A return result
84N/A
84N/A def __elf_runpath_check(self, path):
84N/A result = None
84N/A list = []
84N/A
84N/A ed = elf.get_dynamic(path)
84N/A for dir in ed.get("runpath", "").split(":"):
84N/A if dir == None or dir == '':
84N/A continue
45N/A
84N/A match = False
84N/A for expr in self.runpath_re:
84N/A if expr.match(dir):
84N/A match = True
84N/A break
84N/A
84N/A if match == False:
84N/A list.append(dir)
84N/A
84N/A if len(list) > 0:
84N/A result = _("bad RUNPATH, '%%s' includes '%s'" %
84N/A ":".join(list))
84N/A
84N/A return result
84N/A
84N/A def __elf_wrong_location_check(self, path):
84N/A result = None
84N/A
84N/A ei = elf.get_info(path)
84N/A bits = ei.get("bits")
84N/A frag = os.path.basename(os.path.dirname(path))
84N/A
84N/A if bits == 32 and frag in ["sparcv9", "amd64", "64"]:
84N/A result = _("32-bit object '%s' in 64-bit path")
84N/A elif bits == 64 and frag not in ["sparcv9", "amd64", "64"]:
84N/A result = _("64-bit object '%s' in 32-bit path")
84N/A
84N/A return result
84N/A
84N/A def file_action(self, action, manifest, engine, pkglint_id="001"):
45N/A """Checks for existence in the proto area."""
45N/A
84N/A if action.name not in ["file"]:
45N/A return
45N/A
117N/A path = action.hash
117N/A if path == None or path == 'NOHASH':
117N/A path = action.attrs["path"]
84N/A
84N/A # check for writable files without a preserve attribute
84N/A if 'mode' in action.attrs:
84N/A mode = action.attrs["mode"]
84N/A
84N/A if (int(mode, 8) & 0222) != 0 and "preserve" not in action.attrs:
84N/A engine.error(
84N/A _("%(path)s is writable (%(mode)s), but missing a preserve"
84N/A " attribute") % {"path": path, "mode": mode},
84N/A msgid="%s%s.0" % (self.name, pkglint_id))
84N/A
84N/A # checks that require a physical file to look at
117N/A if self.proto_path is not None:
117N/A for directory in self.proto_path:
117N/A fullpath = directory + "/" + path
117N/A
117N/A if os.path.exists(fullpath):
117N/A break
84N/A
84N/A if not os.path.exists(fullpath):
84N/A engine.info(
84N/A _("%s missing from proto area, skipping"
84N/A " content checks") % path,
84N/A msgid="%s%s.1" % (self.name, pkglint_id))
84N/A elif elf.is_elf_object(fullpath):
84N/A # 32/64 bit in wrong place
84N/A result = self.__elf_wrong_location_check(fullpath)
84N/A if result != None:
84N/A engine.error(result % path,
84N/A msgid="%s%s.2" % (self.name, pkglint_id))
84N/A result = self.__elf_runpath_check(fullpath)
84N/A if result != None:
84N/A engine.error(result % path,
84N/A msgid="%s%s.3" % (self.name, pkglint_id))
84N/A
84N/A file_action.pkglint_desc = _("Paths should exist in the proto area.")
84N/A
84N/A def link_resolves(self, action, manifest, engine, pkglint_id="002"):
84N/A """Checks for link resolution."""
84N/A
84N/A if action.name not in ["link", "hardlink"]:
84N/A return
84N/A
84N/A path = action.attrs["path"]
84N/A target = action.attrs["target"]
84N/A realtarget = self.__realpath(path, target)
84N/A
84N/A resolved = False
84N/A for maction in manifest.gen_actions():
84N/A mpath = None
84N/A if maction.name in ["dir", "file", "link",
84N/A "hardlink"]:
84N/A mpath = maction.attrs["path"]
84N/A
84N/A if mpath and mpath == realtarget:
84N/A resolved = True
84N/A break
84N/A
84N/A if resolved != True:
84N/A engine.error(
84N/A _("%s %s has unresolvable target '%s'") %
84N/A (action.name, path, target),
84N/A msgid="%s%s.0" % (self.name, pkglint_id))
84N/A
84N/A link_resolves.pkglint_desc = _("links should resolve.")
84N/A
84N/A def init_script(self, action, manifest, engine, pkglint_id="003"):
84N/A """Checks for SVR4 startup scripts."""
84N/A
45N/A if action.name not in ["file", "dir", "link", "hardlink"]:
45N/A return
45N/A
45N/A path = action.attrs["path"]
84N/A if self.initscript_re.match(path):
84N/A engine.warning(
84N/A _("SVR4 startup '%s', deliver SMF"
84N/A " service instead") % path,
45N/A msgid="%s%s.0" % (self.name, pkglint_id))
45N/A
84N/A init_script.pkglint_desc = _(
84N/A "SVR4 startup scripts should not be delivered.")
45N/A
45N/Aclass UserlandManifestChecker(base.ManifestChecker):
45N/A """An opensolaris.org-specific class to check manifests."""
45N/A
45N/A name = "userland.manifest"
45N/A
45N/A def __init__(self, config):
45N/A super(UserlandManifestChecker, self).__init__(config)
45N/A
84N/A def license_check(self, manifest, engine, pkglint_id="001"):
84N/A manifest_paths = []
84N/A files = False
84N/A license = False
84N/A
84N/A for action in manifest.gen_actions_by_type("file"):
84N/A files = True
84N/A break
84N/A
84N/A if files == False:
45N/A return
45N/A
84N/A for action in manifest.gen_actions_by_type("license"):
84N/A return
45N/A
84N/A engine.error( _("missing license action"),
84N/A msgid="%s%s.0" % (self.name, pkglint_id))
45N/A
84N/A license_check.pkglint_dest = _(
84N/A "license actions are required if you deliver files.")