Subject: pkg/8916: auth2 dies, need patch from coda 5.3.3
To: None <gnats-bugs@gnats.netbsd.org>
From: Harry W. Waddell <waddell@caravan.com>
List: netbsd-bugs
Date: 11/29/1999 01:54:42
>Number:         8916
>Category:       pkg
>Synopsis:       auth2 dies, need patch from coda 5.3.3
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager (NetBSD software packages system bug manager)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Nov 29 01:54:01 1999
>Last-Modified:
>Originator:     Harry W. Waddell
>Organization:
Caravan Publishing
>Release:        NetBSD-current Tue Nov 23 16:12:02 PST 1999
>Environment:
>Description:
	auth2 in coda5_server dies during simple actions, e.g. using
		
		au nu
	
	to change a new users passwd causes auth2 to dump core. 

>How-To-Repeat:
	see above
>Fix:
	apply patch for file coda-src/auth2/pwsupport.c in the diff file 
	diff-5.3.2-5.3.3 from the coda website. See below. This has not been 
	extensively tested, but it at least lets me add users beyound the coda
	admin user to the system and appears to function without adding 
	additional problems.


Index: coda/coda-src/auth2/pwsupport.c
diff -u coda/coda-src/auth2/pwsupport.c:4.8 coda/coda-src/auth2/pwsupport.c:4.9
--- coda/coda-src/auth2/pwsupport.c:4.8	Tue Sep 14 19:00:48 1999
+++ coda/coda-src/auth2/pwsupport.c	Thu Oct 21 21:52:37 1999
@@ -129,43 +129,10 @@
 	return(0);
 }
 
-int LockParent(char *fName, int lockType)
-{
-	/* lockType:    MYFLOCK_SH or MYFLOCK_EX
-	   Locks parent directory of fName and returns fd on parent.
-	   Used for syncing with mvdb */
-
-	char parent[MAXPATHLEN];
-	int pfd;
-	char *sp;
-
-	if (fName[0] != '/')
-	{
-		getcwd(parent, sizeof(parent-1));
-		strcat(parent, "/");
-		strcat(parent, fName);
-	}
-	else strcpy(parent, fName);
-	sp = rindex(parent, '/');
-	*sp = 0;
-		/* parent surely has at least one '/' by now */
-
-	strcat(parent, LockFile);
-	if ((pfd = open(parent, O_CREAT | O_RDONLY, 0)) < 0
-		|| myflock(pfd, lockType, MYFLOCK_BL) < 0)
-	{
-		perror(parent);
-		abort();
-	}
-
-	return(pfd);
-}
-
-
 void InitPW(int firsttime) 
 {
 
-	int fd, pfd, i;
+	int fd, i;
 	struct stat stbuf;
 	char *fbuf;
 	char *admin = "System:Administrators";	/* CODA_ASSERT dies on literals */
@@ -185,9 +152,6 @@
 	/* Reads in contents of PWFile and builds a sorted list of passwords
 	   in PWArray.  Frees existing storage coor to PWArray.
 	*/
-
-	pfd = LockParent(PWFile, MYFLOCK_SH);
-
 	if ((fd = open(PWFile, O_RDONLY, 0)) < 0
 		|| myflock(fd, MYFLOCK_SH, MYFLOCK_BL) < 0	/* locking is superstitious */
 		|| fstat(fd, &stbuf))
@@ -201,8 +165,10 @@
 
 	PWTime = stbuf.st_mtime;	/* time on file to check for changes */
 	fbuf[stbuf.st_size] = 0;	/* sentinel to stop sscanf() later */
-	myflock(fd, MYFLOCK_UN, MYFLOCK_BL);	close(fd);
-	myflock(pfd, MYFLOCK_UN, MYFLOCK_BL);	close(pfd);
+
+	/* and unlock the file */
+	myflock(fd, MYFLOCK_UN, MYFLOCK_BL);
+	close(fd);
 
 	CODA_ASSERT(AL_NameToId(admin, &AdminID) == 0);
 	for (i = 0; i < RPC2_KEYSIZE; i++)  
@@ -287,7 +253,7 @@
 	   Also updates PWArray, enlarging it if necessary.
 	   A periodic offline program should be run to squish old entries. */
 
-	int fd, pfd, i;
+	int fd, i;
 	char buf[100], *bnext;
 	RPC2_EncryptionKey tempkey;
 	struct stat buff;
@@ -315,8 +281,7 @@
 	cl = time(0);
 	sprintf(bnext, "\t# By %d at %s", agentId, ctime(&cl));
 
-	/* Now lock parent and append the line */
-	pfd = LockParent(PWFile, MYFLOCK_EX);
+	/* Now lock the file and append the line */
 	if ((fd = open(PWFile, O_WRONLY|O_APPEND, 0)) < 0
 		|| myflock(fd, MYFLOCK_EX, MYFLOCK_BL) < 0
 		|| write(fd, buf, strlen(buf)) < 0)
@@ -330,8 +295,8 @@
 	PWTime = buff.st_mtime;
 
 	/* Unlock and quit */
-	myflock(fd, MYFLOCK_UN, MYFLOCK_BL); close(fd);
-	myflock(pfd, MYFLOCK_UN, MYFLOCK_BL); close(pfd);
+	myflock(fd, MYFLOCK_UN, MYFLOCK_BL);
+	close(fd);
 }
 

>Audit-Trail:
>Unformatted:
>System: NetBSD morocco 1.4P NetBSD 1.4P (CARAVANWKS) #0: Tue Nov 23 16:12:02 PST 1999 waddell@morocco:/scratch/src/sys/arch/i386/compile/CARAVANWKS i386