Forráskód Böngészése

dpkg: Set primary group to 0 when running as root

If the user was running with a primary group that is not root, actions
performed by maintainer scripts might inherit and use the wrong primary
group when creating files, or doing group based checks.

Reported-by: Stuart Prescott <stuart@debian.org>
Guillem Jover 10 éve
szülő
commit
77fcf29f14
2 módosított fájl, 8 hozzáadás és 0 törlés
  1. 2 0
      debian/changelog
  2. 6 0
      src/main.c

+ 2 - 0
debian/changelog

@@ -20,6 +20,8 @@ dpkg (1.18.8) UNRELEASED; urgency=medium
   * Abstract ar archive handling behind a new struct dpkg_ar and functions.
   * On dpkg --force-chrootless only set changedir to instdir if defined.
     Thanks to Niall Walsh <niallwalsh@celtux.org>. Closes: #824542
+  * Set primary group to 0 in dpkg when running as root.
+    Reported by Stuart Prescott <stuart@debian.org>.
   * Perl modules:
     - Use warnings::warnif() instead of carp() for deprecated warnings.
     - Add new format_range() method and deprecate dpkg() and rfc822() methods

+ 6 - 0
src/main.c

@@ -872,6 +872,12 @@ int main(int argc, const char *const *argv) {
   dpkg_options_load(DPKG, cmdinfos);
   dpkg_options_parse(&argv, cmdinfos, printforhelp);
 
+  /* When running as root, make sure our primary group is also root, so
+   * that files created by maintainer scripts have correct ownership. */
+  if (!fc_nonroot && getuid() == 0)
+    if (setgid(0) < 0)
+      ohshite(_("cannot set primary group ID to root"));
+
   if (!cipaction) badusage(_("need an action option"));
 
   admindir = dpkg_db_set_dir(admindir);