Package: dpkg Version: 1.15.8.10 Severity: wishlist Pascal Dupuis submitted us (privately) the attached patch with this request: > I have access to a machine where I can develop, compile, install > locally and run programs in my $HOME dir, but not install packages. > After fiddling a bit inside dpkg, I noticed the '--force-not-root' > option, but this fails as some operations are required to have root > access. I enclose a patch where the operations don't fail and exit > dpkg in case the fc_nonroot variable is set. I tried basically to not > change at all the original behaviour. I don't pretend the changes are > the right way to do, but at least I succeeded in installing packages > with this modified dpkg version. Could you please consider > incorporating those patches into upcoming dpkg version ?
I replied the following: > It's definitely not going to be included as is. First of all, if you want > just to suppress error messages we have function "forcibleerr" that > is better suited than your modification of the if test that checks the > return calls of some functions. > > Furthermore you really want to not fail only on EPERM. Other error > cases should still result in a failure. > > Maybe we need a "forciblesyserr" for this. It's not a high priority change but it would be nice to be consistently respecting this option. That's why I'm submitting this bug to not forget about it. Cheers, -- Raphaël Hertzog ◈ Debian Developer Follow my Debian News ▶ http://RaphaelHertzog.com (English) ▶ http://RaphaelHertzog.fr (Français)
diff -bBu -r ./src/archives.c ../dpkg-1.15.8.10/src/archives.c --- ./src/archives.c 2011-01-30 20:37:44.000000000 +0100 +++ ../dpkg-1.15.8.10/src/archives.c 2011-02-14 21:34:56.000000000 +0100 @@ -256,9 +256,9 @@ { if (chown(path, statoverride ? statoverride->uid : ti->uid, - statoverride ? statoverride->gid : ti->gid)) + statoverride ? statoverride->gid : ti->gid) && !fc_nonroot) ohshite(_("error setting ownership of `%.255s'"), ti->name); - if (chmod(path,(statoverride ? statoverride->mode : ti->mode) & ~S_IFMT)) + if (chmod(path, (statoverride ? statoverride->mode : ti->mode) & ~S_IFMT)) ohshite(_("error setting permissions of `%.255s'"), ti->name); newtarobject_utime(path,ti); } @@ -709,7 +709,7 @@ nifd->namenode->statoverride ? nifd->namenode->statoverride->uid : ti->uid, nifd->namenode->statoverride ? - nifd->namenode->statoverride->gid : ti->gid)) + nifd->namenode->statoverride->gid : ti->gid) && !fc_nonroot) ohshite(_("error setting ownership of `%.255s'"), ti->name); am = (nifd->namenode->statoverride ? nifd->namenode->statoverride->mode : ti->mode) & ~S_IFMT; @@ -765,7 +765,7 @@ nifd->namenode->statoverride ? nifd->namenode->statoverride->uid : ti->uid, nifd->namenode->statoverride ? - nifd->namenode->statoverride->gid : ti->gid)) + nifd->namenode->statoverride->gid : ti->gid) && !fc_nonroot) ohshite(_("error setting ownership of symlink `%.255s'"), ti->name); break; case tar_filetype_dir: @@ -825,7 +825,7 @@ varbufaddc(&symlinkfn, '\0'); if (symlink(symlinkfn.buf,fnametmpvb.buf)) ohshite(_("unable to make backup symlink for `%.255s'"), ti->name); - if (lchown(fnametmpvb.buf,stab.st_uid,stab.st_gid)) + if (lchown(fnametmpvb.buf,stab.st_uid,stab.st_gid) && !fc_nonroot) ohshite(_("unable to chown backup symlink for `%.255s'"), ti->name); set_selinux_path_context(fnamevb.buf, fnametmpvb.buf, stab.st_mode); } else { @@ -881,7 +881,7 @@ setupfnamevbs(usename); - fd = open(fnamenewvb.buf, O_WRONLY); + fd = open(fnamenewvb.buf, fc_nonroot? O_EXCL : O_WRONLY); if (fd < 0) ohshite(_("unable to open '%.255s'"), fnamenewvb.buf); sync_file_range(fd, 0, 0, SYNC_FILE_RANGE_WAIT_BEFORE); @@ -928,7 +928,7 @@ debug(dbg_eachfiledetail, "deferred extract needs fsync"); - fd = open(fnamenewvb.buf, O_WRONLY); + fd = open(fnamenewvb.buf, fc_nonroot ? O_EXCL : O_WRONLY); if (fd < 0) ohshite(_("unable to open '%.255s'"), fnamenewvb.buf); if (fsync(fd)) Only in ../dpkg-1.15.8.10/src: archives.c~ diff -bBu -r ./src/filesdb.c ../dpkg-1.15.8.10/src/filesdb.c --- ./src/filesdb.c 2011-01-30 20:37:44.000000000 +0100 +++ ../dpkg-1.15.8.10/src/filesdb.c 2011-02-14 21:31:49.000000000 +0100 @@ -478,7 +478,8 @@ file= fopen(newvb.buf,"w+"); if (!file) - ohshite(_("unable to create updated files list file for package %s"),pkg->name); + ohshite(_("unable to create updated files list file in %s for package %s"), + newvb.buf, pkg->name); push_cleanup(cu_closefile, ehflag_bombout, NULL, 0, 1, (void *)file); while (list) { if (!(leaveout && (list->namenode->flags & fnnf_elide_other_lists))) { diff -bBu -r ./src/help.c ../dpkg-1.15.8.10/src/help.c --- ./src/help.c 2011-01-30 20:37:44.000000000 +0100 +++ ../dpkg-1.15.8.10/src/help.c 2011-02-14 19:35:32.000000000 +0100 @@ -184,9 +184,14 @@ size_t instdirl; if (*instdir) { + if (!fc_nonroot) { if (chroot(instdir)) ohshite(_("failed to chroot to `%.250s'"),instdir); if (chdir("/")) ohshite(_("failed to chdir to `%.255s'"), "/"); + } else { + if (chdir(instdir)) + ohshite(_("failed to chdir to `%.255s'"), instdir); + } } if (f_debug & dbg_scripts) { struct varbuf args = VARBUF_INIT;