From 744ae6fc347610c40c11ba907b9038d92afd3c80 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Thu, 11 Jan 2007 12:16:51 +0000 Subject: [PATCH] Move retrieval of uid and gid information from controllib.pl into a function, so that scripts not needing it do not execute that code. Based on a patch by Riku Voipio. Closes: #396884 --- ChangeLog | 11 ++++++++++ debian/changelog | 3 +++ scripts/controllib.pl | 43 +++++++++++++++++++++++-------------- scripts/dpkg-distaddfile.pl | 2 +- scripts/dpkg-gencontrol.pl | 2 +- scripts/dpkg-shlibdeps.pl | 2 +- scripts/dpkg-source.pl | 2 +- 7 files changed, 45 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0a603048..dc7d2b7e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-01-11 Riku Voipio + Guillem Jover + + * scripts/controllib.pl: Move the getlogin and fowner initialization + to ... + (getfowner): ...here. New function. + * scripts/dpkg-source.pl: Use getfowner() instead of @fowner. + * scripts/dpkg-gencontrol.pl: Likewise. + * scripts/dpkg-distaddfile.pl: Likewise. + * scripts/dpkg-shlibdeps.pl: Likewise. + 2007-01-10 Julian Gilbey * scripts/dpkg-buildpackage.sh: Allow '-b' to properly override a diff --git a/debian/changelog b/debian/changelog index f9722ce5..d553b0aa 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,9 @@ dpkg (1.14.0) UNRELEASED; urgency=low one in the source. Thanks to Nicolas François. Closes: #379320 * Allow dpkg-buildpackage to properly override '-b' when passed after '-B'. Thanks to Julian Gilbey. Closes: #397479 + * Move retrieval of uid and gid information from controllib.pl into a + function, so that scripts not needing it do not execute that code. + Based on a patch by Riku Voipio. Closes: #396884 -- Guillem Jover Tue, 9 Jan 2007 22:48:47 +0200 diff --git a/scripts/controllib.pl b/scripts/controllib.pl index d5705327..a3be7a27 100755 --- a/scripts/controllib.pl +++ b/scripts/controllib.pl @@ -35,8 +35,10 @@ $quiet_warnings = 0; $progname= $0; $progname= $& if $progname =~ m,[^/]+$,; -$getlogin = getlogin(); -if(!defined($getlogin)) { +sub getfowner +{ + $getlogin = getlogin(); + if (!defined($getlogin)) { open(SAVEIN, "<&STDIN"); close(STDIN); open(STDIN, "<&STDERR"); @@ -46,8 +48,8 @@ if(!defined($getlogin)) { close(STDIN); open(STDIN, "<&SAVEIN"); close(SAVEIN); -} -if(!defined($getlogin)) { + } + if (!defined($getlogin)) { open(SAVEIN, "<&STDIN"); close(STDIN); open(STDIN, "<&STDOUT"); @@ -57,20 +59,29 @@ if(!defined($getlogin)) { close(STDIN); open(STDIN, "<&SAVEIN"); close(SAVEIN); -} + } + + if (defined($ENV{'LOGNAME'})) { + @fowner = getpwnam($ENV{'LOGNAME'}); + if (!@fowner) { + die(sprintf(_g('unable to get login information for username "%s"'), $ENV{'LOGNAME'})); + } + } elsif (defined($getlogin)) { + @fowner = getpwnam($getlogin); + if (!@fowner) { + die(sprintf(_g('unable to get login information for username "%s"'), $getlogin)); + } + } else { + &warn (sprintf(_g('no utmp entry available and LOGNAME not defined; using uid of process (%d)'), $<)); + @fowner = getpwuid($<); + if (!@fowner) { + die (sprintf(_g('unable to get login information for uid %d'), $<)); + } + } + @fowner = @fowner[2,3]; -if (defined ($ENV{'LOGNAME'})) { - @fowner = getpwnam ($ENV{'LOGNAME'}); - if (! @fowner) { die (sprintf (_g('unable to get login information for username "%s"'), $ENV{'LOGNAME'})); } -} elsif (defined ($getlogin)) { - @fowner = getpwnam ($getlogin); - if (! @fowner) { die (sprintf (_g('unable to get login information for username "%s"'), $getlogin)); } -} else { - &warn (sprintf (_g('no utmp entry available and LOGNAME not defined; using uid of process (%d)'), $<)); - @fowner = getpwuid ($<); - if (! @fowner) { die (sprintf (_g('unable to get login information for uid %d'), $<)); } + return @fowner; } -@fowner = @fowner[2,3]; sub capit { my @pieces = map { ucfirst(lc) } split /-/, $_[0]; diff --git a/scripts/dpkg-distaddfile.pl b/scripts/dpkg-distaddfile.pl index 93f72471..0adb63be 100755 --- a/scripts/dpkg-distaddfile.pl +++ b/scripts/dpkg-distaddfile.pl @@ -60,7 +60,7 @@ while (@ARGV && $ARGV[0] =~ m/^-/) { $fileslistfile="./$fileslistfile" if $fileslistfile =~ m/^\s/; open(Y,"> $fileslistfile.new") || &syserr(_g("open new files list file")); -chown(@fowner, "$fileslistfile.new") +chown(getfowner(), "$fileslistfile.new") || &syserr(_g("chown new files list file")); if (open(X,"< $fileslistfile")) { while () { diff --git a/scripts/dpkg-gencontrol.pl b/scripts/dpkg-gencontrol.pl index 42401f51..f52b4d90 100755 --- a/scripts/dpkg-gencontrol.pl +++ b/scripts/dpkg-gencontrol.pl @@ -255,7 +255,7 @@ for $f (keys %remove) { delete $f{&capit($f)}; } $fileslistfile="./$fileslistfile" if $fileslistfile =~ m/^\s/; open(Y,"> $fileslistfile.new") || &syserr(_g("open new files list file")); binmode(Y); -chown(@fowner, "$fileslistfile.new") +chown(getfowner(), "$fileslistfile.new") || &syserr(_g("chown new files list file")); if (open(X,"< $fileslistfile")) { binmode(X); diff --git a/scripts/dpkg-shlibdeps.pl b/scripts/dpkg-shlibdeps.pl index ff4f4243..7869caff 100755 --- a/scripts/dpkg-shlibdeps.pl +++ b/scripts/dpkg-shlibdeps.pl @@ -395,7 +395,7 @@ if (!$stdout) { open(Y,"> $varlistfile.new") || syserr(sprintf(_g("open new substvars file \`%s'"), "$varlistfile.new")); unless ($REAL_USER_ID) { - chown(@fowner, "$varlistfile.new") || + chown(getfowner(), "$varlistfile.new") || syserr(sprintf(_g("chown of \`%s'"), "$varlistfile.new")); } if (open(X,"< $varlistfile")) { diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl index b2ee7ff4..09fb291a 100755 --- a/scripts/dpkg-source.pl +++ b/scripts/dpkg-source.pl @@ -749,7 +749,7 @@ if ($opmode eq 'build') { system "chmod", "g-s", $tmp; printf(_g("%s: unpacking %s")."\n", $progname, $tarfile); extracttar("$dscdir/$tarfile",$tmp,$t); - system "chown", '-R', '-f', join(':',@fowner), "$tmp/$t"; + system "chown", '-R', '-f', join(':', getfowner()), "$tmp/$t"; rename("$tmp/$t",$target) || &syserr(sprintf(_g("unable to rename `%s' to `%s'"), "$tmp/$t", $target)); rmdir($tmp) -- 2.39.5