patch to 'with' v13i048 (unexpected side-effect)

Paul Lew lew at gsg.UUCP
Fri Feb 19 15:09:39 AEST 1988


Index: v13i048 (Resource allocation program)
Description:
	'With' will change file mode, group ID, and user ID to that of
	the user. At end, it will set file mode to read only by root,
	group ID to 3.  This may confuse users who do not know about
	'with' and found out he could not open the device after some
	one just finish using 'with'.  This patch will save the
	original mode, gid, uid and restore them when 'with' terminates.

Repeat-by:
	> ls -l /dev/rmt0
	crw-rw-rw-  1 root      16,   0 Nov 11 11:37 /dev/rmt0
	> with tape
	> .....
	> ^D
	> ls -l /dev/rmt0
	crw-------  1 root      16,   0 Nov 11 11:37 /dev/rmt0

Fix:
*** with.c.old	Thu Feb 18 23:17:37 1988
--- with.c	Thu Feb 18 23:20:27 1988
***************
*** 12,17 ****
--- 12,20 ----
   * /usr/spool/uucp/LCK..cul0 cul0 /dev/cul0
   *
   * $Log:	with.c,v $
+  * Revision 2.0.1.1  88/02/18  22:14:28  lew
+  * save device mode, uid, gid before with and restore at end
+  * 
   * Revision 2.0  87/10/26  09:32:15  cudcv
   * "Stable"
   * 
***************
*** 52,58 ****
   * Initial revision
   * 
   */
! static char RCSid[] = "$Header: with.c,v 2.0 87/10/26 09:32:15 cudcv Exp $";
  #include <ctype.h>
  #include <pwd.h>
  #include <signal.h>
--- 55,61 ----
   * Initial revision
   * 
   */
! static char RCSid[] = "$Header: with.c,v 2.0.1.1 88/02/18 22:14:28 lew Exp $";
  #include <ctype.h>
  #include <pwd.h>
  #include <signal.h>
***************
*** 124,129 ****
--- 127,138 ----
  
  void	print_locks();
  
+ struct	{
+ 	u_short	sv_mode;		/* mode */
+ 	short	sv_uid;			/* user ID of owner */
+ 	short	sv_gid;			/* group ID of owner */
+ 	} saved_id [MAXPDEV];
+ 
  main(argc,argv)
  int argc;
  char *argv[];
***************
*** 257,262 ****
--- 266,272 ----
  	(void) ftruncate(lockfile, sizeof(int) + PW_NAMEL);
  	lkp->locked++;
  	for(pdev = 0;pdev < MAXPDEV && (*subdev(lkp,pdev));pdev++){
+ 	    save_id (subdev(lkp,pdev), pdev);
  	    (void) chown( subdev(lkp,pdev),uuid,ugid );
  	    (void) chmod( subdev(lkp,pdev),OWNERONLY);
  	}
***************
*** 471,478 ****
          register int pdev;
  
          for(pdev = 0;pdev < MAXPDEV && (*subdev(lkp,pdev));pdev++){
!                 (void) chown( subdev(lkp,pdev),Rootuid,Rootgid );
!                 (void) chmod( subdev(lkp,pdev),OWNERONLY);
  		}
  }
  
--- 481,489 ----
          register int pdev;
  
          for(pdev = 0;pdev < MAXPDEV && (*subdev(lkp,pdev));pdev++){
!                 (void) chown( subdev(lkp,pdev),
! 			      saved_id[pdev].sv_uid, saved_id[pdev].sv_gid);
!                 (void) chmod( subdev(lkp,pdev), saved_id[pdev].sv_mode);
  		}
  }
  
***************
*** 513,516 ****
--- 524,539 ----
  	if (!resource)
  		(void) unlink(nolok.lok);
          exit(sig ? -1 : nerrs);
+ }
+ 
+ save_id (fname, idx)
+ char	*fname;				/* filename */
+ int	idx;				/* index to saved_id structure */
+ {
+ 	struct	stat	statbuf;
+ 
+ 	stat (fname, &statbuf);
+ 	saved_id[idx].sv_mode = statbuf.st_mode;
+ 	saved_id[idx].sv_uid = statbuf.st_uid;
+ 	saved_id[idx].sv_gid = statbuf.st_gid;
  }
-- 
Paul Lew			{oliveb,harvard,decvax}!gsg!lew	(UUCP)
General Systems Group, 5 Manor Parkway, Salem, NH 03079	(603) 893-1000



More information about the Comp.sources.bugs mailing list