summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2018-02-07 11:22:40 +0000
committerMarc Espie <espie@cvs.openbsd.org>2018-02-07 11:22:40 +0000
commit1d788f7f8556e4cbb6e8c2e3f0a5c73997ac9e77 (patch)
tree15db1f3db73e79de657ffbe2547e5fa5b2c2a8c2 /usr.sbin
parent85b68b14b5ea666155f5ab2c687b03f1bcc6ae82 (diff)
prepare for session saving by separating the pkgfetch code.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/pkg_add/OpenBSD/PackageRepository.pm46
1 files changed, 33 insertions, 13 deletions
diff --git a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm
index 86b98240354..e85889778dd 100644
--- a/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm
+++ b/usr.sbin/pkg_add/OpenBSD/PackageRepository.pm
@@ -1,5 +1,5 @@
# ex:ts=8 sw=4:
-# $OpenBSD: PackageRepository.pm,v 1.153 2018/02/06 16:34:35 espie Exp $
+# $OpenBSD: PackageRepository.pm,v 1.154 2018/02/07 11:22:39 espie Exp $
#
# Copyright (c) 2003-2010 Marc Espie <espie@openbsd.org>
#
@@ -743,23 +743,43 @@ our @ISA=qw(OpenBSD::PackageRepository::Distant);
our %distant = ();
-sub drop_privileges_and_setup_env
+my ($fetch_uid, $fetch_gid, $fetch_user);
+
+sub fill_up_fetch_data
{
my $self = shift;
- my $user = '_pkgfetch';
if ($< == 0) {
- # we can't cache anything, we happen after the fork,
- # right before exec
- if (my (undef, undef, $uid, $gid) = getpwnam($user)) {
- $( = $gid;
- $) = "$gid $gid";
- $< = $uid;
- $> = $uid;
- } else {
- $self->{state}->fatal("Couldn't change identity: can't find #1 user", $user);
+ $fetch_user = '_pkgfetch';
+ unless ((undef, undef, $fetch_uid, $fetch_gid) =
+ getpwnam($fetch_user)) {
+ $self->{state}->fatal(
+ "Couldn't change identity: can't find #1 user",
+ $fetch_user);
}
} else {
- ($user) = getpwuid($<);
+ ($fetch_user) = getpwuid($<);
+ }
+}
+
+sub fetch_id
+{
+ my $self = shift;
+ if (!defined $fetch_user) {
+ $self->fill_up_fetch_data;
+ }
+ return ($fetch_uid, $fetch_gid, $fetch_user);
+}
+
+sub drop_privileges_and_setup_env
+{
+ my $self = shift;
+ my ($uid, $gid, $user) = $self->fetch_id;
+ if (defined $uid) {
+ # we happen right before exec, so change id permanently
+ $( = $gid;
+ $) = "$gid $gid";
+ $< = $uid;
+ $> = $uid;
}
# create sanitized env for ftp
my %newenv = (