Bug #162542 - When dropping privileges for FEATURES=userpriv,
authorZac Medico <zmedico@gentoo.org>
Thu, 10 Jan 2008 23:07:06 +0000 (23:07 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 10 Jan 2008 23:07:06 +0000 (23:07 -0000)
automatically detect permission problems with CCACHE_DIR and
recursively adjust permissions only when necessary.
(trunk r9160)

svn path=/main/branches/2.1.2/; revision=9161

pym/portage.py

index a7efc64b4644c599ce1def7ab6605f6e0d6815f5..d83cd6e0e52ce5d4dfabdcb99adb8d890ffe52ec 100644 (file)
@@ -4038,6 +4038,11 @@ def prepare_build_dirs(myroot, mysettings, cleanup):
        dirmode  = 02070
        filemode =   060
        modemask =    02
+       restrict = mysettings.get("PORTAGE_RESTRICT","").split()
+       from portage_data import secpass
+       droppriv = secpass >= 2 and \
+               "userpriv" in mysettings.features and \
+               "userpriv" not in restrict
        for myfeature, kwargs in features_dirs.iteritems():
                if myfeature in mysettings.features:
                        basedir = mysettings[kwargs["basedir_var"]]
@@ -4054,7 +4059,13 @@ def prepare_build_dirs(myroot, mysettings, cleanup):
                                        # Generally, we only want to apply permissions for
                                        # initial creation.  Otherwise, we don't know exactly what
                                        # permissions the user wants, so should leave them as-is.
-                                       if modified or kwargs["always_recurse"]:
+                                       droppriv_fix = False
+                                       if droppriv:
+                                               st = os.stat(mydir)
+                                               if st.st_gid != portage_gid or \
+                                                       not stat.S_IMODE(st.st_mode) & dirmode:
+                                                       droppriv_fix = True
+                                       if modified or kwargs["always_recurse"] or droppriv_fix:
                                                if modified:
                                                        writemsg("Adjusting permissions recursively: '%s'\n" % mydir,
                                                                noiselevel=-1)