Subject: pkg/10477: correction to GLUnix pkg's patch-bg was incomplete
To: None <gnats-bugs@gnats.netbsd.org>
From: g r <gr@sirius.eclipsed.net>
List: netbsd-bugs
Date: 06/29/2000 13:08:13
>Number:         10477
>Category:       pkg
>Synopsis:       correction to GLUnix pkg's patch-bg was incomplete
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jun 29 13:09:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     gabriel rosenkoetter
>Release:        current pkgsrc
>Organization:
	Swarthmore College Computer Science Program
>Environment:
	
System: NetBSD sirius 1.4.2 NetBSD 1.4.2 (GENERIC) #0: Wed Mar 15 21:53:17 PST 2000 toddpw@leia.toddpw.net:/usr/src/sys/arch/macppc/compile/GENERIC macppc


>Description:
	

I goofed when repairing patch-bg. I check for uid == 0 (instead of
euid == 0), but the glupart binary has already done a su GLUNIX_UID,
so if we're root (the only one who should be able to run glupart
install), we have uid 0, euid glunix, and mkdir cares about euid, so
it won't create the directories glupart install needs it to.

The original patch-bg had vaguely the right idea (but it had Perl's $<
and $> variables confused as well as performing its transformation in
the wrong place and not putting things back the way it found them).

To *actually* fix the problem, it's necessary to exit if uid ($<) !=
0, and then to set euid ($>) to uid (no way it could be anything but 0,
but for propriety's sake), but preserve the old euid (I use a lccal var
$tid) and reset the euid to it when we're done.

>How-To-Repeat:
	

Build glunix from pkgsrc/parallel/glunix, try to do glupart install,
find that you can't even when you *are* root (though, at least you're
no longer told to try as root). Running glupart_script install as root
will work just fine (so functionality isn't impaired, just clarity).

>Fix:
	

Replace patch-bg (yes, again... sorry) with the attached version.

--- CUT HERE ---
$NetBSD$

--- progs/glupart/glupart_script.pl.orig	Wed Nov  5 17:30:11 1997
+++ progs/glupart/glupart_script.pl	Thu Jun 29 15:48:34 2000
@@ -75,3 +75,3 @@
 my $gl_tmpFile = "$gl_dataDir/.__glupart$$-tmp";
-my $gl_emailAdmin = "glunix-admin\@now.CS.Berkeley.EDU";
+my $gl_emailAdmin = "root";
 my $gl_datePath = "/bin/date";
@@ -136,3 +136,3 @@
     &unlock();
-    open(USAGE, "|/usr/sww/bin/less") || open(USAGE, "|/bin/less") ||
+    open(USAGE, "|/usr/bin/less") || open(USAGE, "|/bin/less") ||
 	open(USAGE, "|/bin/more") || open(USAGE, ">&STDOUT");
@@ -1491,3 +1491,4 @@
 		print "Creating directory $tmp\n";
-		mkdir($tmp, 0755);
+                mkdir $tmp, 0755 || die("$!");
+		system("/usr/sbin/chown glunix:glunix $tmp");
 	    }
@@ -1501,3 +1502,3 @@
 
-    umask 0755;
+    umask 0022;
     foreach $f (@files) {
@@ -1507,2 +1508,3 @@
 	    print "Created file $f\n";
+	    system("/usr/sbin/chown glunix:glunix $f");
 	}
@@ -1995,3 +1997,5 @@
 if ($command eq "install") {
-    if ($> != 0) {
+    my $tid = $>;
+
+    if ($< != 0) {
 	print STDERR "You must be root to do \"glupart install\"\n";
@@ -1999,2 +2003,5 @@
     }
+    if ($< == 0 && $> != 0) {
+        $> = $<;
+    }
     &my_mkdir($gl_dataDir);
@@ -2002,2 +2009,7 @@
 	      $gl_reservationFile, $gl_lockFile, $gl_logFile);
+
+    if ($> != $tid) {
+        $> = $tid;
+    }
+
     exit(0);
>Release-Note:
>Audit-Trail:
>Unformatted: