Sfoglia il codice sorgente

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 19 anni fa
parent
commit
744ae6fc34

+ 11 - 0
ChangeLog

@@ -1,3 +1,14 @@
+2007-01-11  Riku Voipio <riku.voipio@iki.fi>
+	    Guillem Jover <guillem@debian.org>
+
+	* 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  <jdg@polya.uklinux.net>
 
 	* scripts/dpkg-buildpackage.sh: Allow '-b' to properly override a

+ 3 - 0
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 <guillem@debian.org>  Tue,  9 Jan 2007 22:48:47 +0200
 

+ 27 - 16
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];

+ 1 - 1
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 (<X>) {

+ 1 - 1
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);

+ 1 - 1
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")) {

+ 1 - 1
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)