From ab054a1da17bf19c4c3a7d3b7412eb914ba1f8e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20=C3=87a=C4=9Flayan?= Date: Mon, 27 Dec 2010 22:11:31 +0000 Subject: [PATCH] patches: Add patch to support non-root building * if config.tmp_dir is not writeable defaults to /tmp/pisi-$USER * if /var/cache/pisi/archives is not writeable defaults to /tmp/pisi-$USER * Move chowning additional files into postinstall * Assume that group == owner if no group is given for AdditionalFiles BUGS: All files extracted under work_dir and installed under install_dir has owner:group == uid:gid of the user which builds the package. TEST: Build a package with your regular user and install it EXPECTED RESULTS: You shouldn't have any exceptions but the files installed on your system will have the same ownership as your user ;) --- patches/add-non-root-build-support.patch | 180 +++++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 patches/add-non-root-build-support.patch diff --git a/patches/add-non-root-build-support.patch b/patches/add-non-root-build-support.patch new file mode 100644 index 00000000..3fe9ea68 --- /dev/null +++ b/patches/add-non-root-build-support.patch @@ -0,0 +1,180 @@ +Add non-root building support to pisi +* if config.tmp_dir is not writeable defaults to /tmp/pisi-$USER +* if /var/cache/pisi/archives is not writeable defaults to /tmp/pisi-$USER +* Move chowning additional files into postinstall +* Assume that group == owner if no group is given for AdditionalFiles + +BUGS: + +All files extracted under work_dir and installed under install_dir +has owner:group == uid:gid of the user which builds the package. + +--- + +Index: pisi/operations/build.py +=================================================================== +--- pisi/operations/build.py (revision 34443) ++++ pisi/operations/build.py (working copy) +@@ -277,7 +277,7 @@ + self.spec.getSourceVersion() + '-' + \ + self.spec.getSourceRelease() + return util.join_path(ctx.config.dest_dir(), +- ctx.config.values.dirs.tmp_dir, ++ ctx.config.tmp_dir(), + packageDir) + + def pkg_work_dir(self): +@@ -886,12 +886,43 @@ + frpath = util.removepathprefix(install_dir, fpath) # relative path + ftype, permanent = get_file_type(frpath, package.files) + fsize = long(util.dir_size(fpath)) ++ + if not os.path.islink(fpath): + st = os.stat(fpath) + else: + st = os.lstat(fpath) ++ ++ _uid = str(st.st_uid) ++ _gid = str(st.st_gid) ++ ++ for afile in package.additionalFiles: ++ # FIXME: Better way? ++ if frpath == util.removepathprefix("/",afile.target): ++ # This is an additional file, uid and gid will change ++ if afile.owner: ++ try: ++ _uid = str(pwd.getpwnam(afile.owner)[2]) ++ except KeyError: ++ ctx.ui.warning(_("No user named '%s' found " ++ "on the system") % afile.owner) ++ if afile.group: ++ try: ++ _gid = str(grp.getgrnam(afile.group)[2]) ++ except KeyError: ++ ctx.ui.warning(_("No group named '%s' found " ++ "on the system") % afile.group) ++ else: ++ try: ++ # Assume owner == root if no group is given ++ _gid = str(grp.getgrnam(afile.owner)[2]) ++ except KeyError: ++ ctx.ui.warning(_("No group named '%s' (value " ++ "guessed from owner) found " ++ "on the system") % afile.owner) ++ break ++ + d[frpath] = pisi.files.FileInfo(path=frpath, type=ftype, permanent=permanent, +- size=fsize, hash=fhash, uid=str(st.st_uid), gid=str(st.st_gid), ++ size=fsize, hash=fhash, uid=_uid, gid=_gid, + mode=oct(stat.S_IMODE(st.st_mode))) + if stat.S_IMODE(st.st_mode) & stat.S_ISUID: + ctx.ui.warning(_("/%s has suid bit set") % frpath) +@@ -960,21 +991,12 @@ + install_dir + os.path.dirname(afile.target), + os.path.basename(afile.target)) + util.copy_file(src, dest) ++ ++ # FIXME: Check that chmodding is safe for non-root builds + if afile.permission: + # mode is octal! + os.chmod(dest, int(afile.permission, 8)) +- if afile.owner: +- try: +- os.chown(dest, pwd.getpwnam(afile.owner)[2], -1) +- except KeyError: +- ctx.ui.warning(_("No user named '%s' found " +- "on the system") % afile.owner) +- if afile.group: +- try: +- os.chown(dest, -1, grp.getgrnam(afile.group)[2]) +- except KeyError: +- ctx.ui.warning(_("No group named '%s' found " +- "on the system") % afile.group) ++ + os.chdir(c) + + # Show the files those are not collected from the install dir +Index: pisi/config.py +=================================================================== +--- pisi/config.py (revision 34443) ++++ pisi/config.py (working copy) +@@ -118,8 +118,13 @@ + return self.subdir(self.values.dirs.packages_dir) + + def archives_dir(self): +- return self.subdir(self.values.dirs.archives_dir) ++ retval = self.subdir(self.values.dirs.archives_dir) ++ # check write access ++ if not os.access(retval, os.W_OK): ++ retval = self.tmp_dir() + ++ return retval ++ + def cache_root_dir(self): + return self.subdir(self.values.dirs.cache_root_dir) + +@@ -136,16 +141,15 @@ + return self.subdir(self.values.dirs.index_dir) + + def tmp_dir(self): +- sysdir = self.subdir(self.values.dirs.tmp_dir) +- if os.environ.has_key('USER'): +- userdir = self.subdir('/tmp/pisi-' + os.environ['USER']) +- else: +- userdir = self.subdir('/tmp/pisi-root') ++ retval = self.subdir(self.values.dirs.tmp_dir) ++ userdir = self.subdir("/tmp/pisi-%s" % \ ++ os.environ.get("USER", "root")) ++ + # check write access +- if os.access(sysdir, os.W_OK): +- return sysdir +- else: +- return userdir ++ if not os.access(retval, os.W_OK): ++ retval = userdir + ++ return retval ++ + #TODO: remove this + config = Config() +Index: pisi/atomicoperations.py +=================================================================== +--- pisi/atomicoperations.py (revision 34443) ++++ pisi/atomicoperations.py (working copy) +@@ -283,6 +283,12 @@ + + def postinstall(self): + self.config_later = False ++ ++ # Chowning for additional files ++ for _file in self.package.get_files().list: ++ fpath = pisi.util.join_path(ctx.config.dest_dir(), _file.path) ++ os.chown(fpath, int(_file.uid), int(_file.gid)) ++ + if ctx.comar: + import pisi.comariface + try: +Index: pisi/cli/build.py +=================================================================== +--- pisi/cli/build.py (revision 34443) ++++ pisi/cli/build.py (working copy) +@@ -160,8 +160,8 @@ + if not self.options.quiet: + self.options.debug = True + ++ self.init(False, False) + if self.options.package_format == "help": +- self.init(False, False) + ctx.ui.info(_("Supported package formats:")) + for format in pisi.package.Package.formats: + if format == pisi.package.Package.default_format: +@@ -170,8 +170,6 @@ + ctx.ui.info(" %s" % format) + return + +- self.init() +- + if ctx.get_option('output_dir'): + ctx.ui.info(_('Output directory: %s') + % ctx.config.options.output_dir)