🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.utils.bug
Article #170

Enhancement for gnu tar/NFS

#170
From: Neal Becker
Date: Tue, 21 Jul 1992 15:07
148 lines
3930 bytes
If you are stuck with NFS/root access problems ( like on HPUX
machines ) you may find this patch useful.  This patch introduces the
same kind of kludge as the chdir option (-C) to do seteuid.  For some
reason I've forgotten, I called this (-E).  I use this to read user's
files using NFS.  Use it like this:

tar .... -E user1 ~user1 -Euser2 ~user2 ...

Thus, we backup user1's files *as* user1, ...etc.  Neat, huh?

----------------------------------------------------------
diff -c tar.c.old tar-1.10/tar.c
*** tar.c.old	Tue Jul 21 09:40:48 1992
--- tar-1.10/tar.c	Mon Jul 20 16:07:36 1992
***************
*** 309,315 ****
  
  	/* Parse options */
  	while ((c = getoldopt(argc, argv,
! 			      "-01234567Ab:BcC:df:F:g:GhikK:lL:mMN:oOpPrRsStT:uvV:wWxX:zZ",
  			      long_options, &ind)) != EOF) {
  		switch (c) {
  		case 0:		/* long options that set a single flag */
--- 309,315 ----
  
  	/* Parse options */
  	while ((c = getoldopt(argc, argv,
! 			      "-01234567Ab:BcC:df:E:F:g:GhikK:lL:mMN:oOpPrRsStT:uvV:wWxX:zZ",
  			      long_options, &ind)) != EOF) {
  		switch (c) {
  		case 0:		/* long options that set a single flag */
***************
*** 322,327 ****
--- 322,331 ----
  			name_add("-C");
  			name_add(optarg);
  			break;
+ 		case 'E':
+ 			name_add("-E");
+ 			name_add(optarg);
+ 			break;
  		case 10:	/* preserve */
  			f_use_protection = f_sorted_names = 1;
  			break;
***************
*** 735,740 ****
--- 739,746 ----
  	register char	*p;
  	register char	*q = 0;
  	register char	*q2 = 0;
+ 	register char	*q3 = 0;
+ 	register char	*q4 = 0;
  
  	extern char *un_quote_string();
  
***************
*** 770,775 ****
--- 776,793 ----
  		}
  		/* End of JF quick -C hack */
  
+ 		if(c && !q3 && p[0]=='-' && p[1]=='E' && p[2]=='\0') {
+ 			q3=p;
+ 			goto tryagain;
+ 		}
+ 		if(q3) {
+ 			if(SetUid(p)<0)
+ 				msg_perror("Can't setuid to %s",p);
+ 			q3=0;
+ 			goto tryagain;
+ 		}
+ 		/* End of JF quick -C hack */
+ 
  		if(f_exclude && check_exclude(p))
  			goto tryagain;
  		return un_quote_string(p);
***************
*** 799,805 ****
  			q2 = 0;
  			goto tryagain;
  		}
! 
  		if(f_exclude && check_exclude(p))
  			goto tryagain;
  		return un_quote_string(p);
--- 817,832 ----
  			q2 = 0;
  			goto tryagain;
  		}
! 		if(c && !q4 && p[0]=='-' && p[1]=='E' && p[2]=='\0') {
! 			q4=p;
! 			goto tryagain;
! 		}
! 		if(q4) {
! 			if(SetUid(p)<0)
! 				msg_perror("Can't setuid to %s",p);
! 			q4=0;
! 			goto tryagain;
! 		}
  		if(f_exclude && check_exclude(p))
  			goto tryagain;
  		return un_quote_string(p);
***************
*** 1312,1314 ****
--- 1339,1381 ----
  	}
  	return 0;
  }
+ 
+ #include <pwd.h>
+ 
+ static int OriginalRUid = -1;
+ static int OriginalEUid = -1;
+ 
+ static int SetUid( name )
+ char* name;
+ {
+   struct passwd* p;
+   int uid;
+ 
+   if( OriginalRUid == -1 ) {
+     OriginalRUid = getuid();
+     OriginalEUid = geteuid();
+   }
+   else {
+     if( setreuid( OriginalRUid, OriginalEUid ) != 0 ) {
+       fprintf( stderr, "Can't reset uid\n" );
+       return -1;
+     }
+   }
+   p = getpwnam( name );
+ 
+   if( p == NULL ) return -1;
+   else {
+     fprintf( stderr, "setuid %s(%d)\n", name, p->pw_uid );
+     return setreuid( p->pw_uid, p->pw_uid );
+   }
+ }
+ 
+ #ifdef __hpux
+ 
+ static int setreuid( ruid, euid ) 
+ uid_t ruid, euid;
+ {
+   return setresuid( ruid, euid, -1 );
+ }
+ 
+ #endif
Technical Details
Message-ID: <m0mALnp-0003TdC@neal.ctd.comsat.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!ctd.COMsat.COM!neal

Show Full Headers
Complete Article Headers
Newsgroups: gnu.utils.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!ctd.COMsat.COM!neal
From: neal@ctd.COMsat.COM (Neal Becker)
Subject: Enhancement for gnu tar/NFS
Message-ID: <m0mALnp-0003TdC@neal.ctd.comsat.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Tue, 21 Jul 1992 15:07:00 GMT
Approved: bug-gnu-utils@prep.ai.mit.edu
Lines: 149