[comp.unix.questions] Need Help!

jaw7_ltd@uhura.cc.rochester.edu (Joe Unix User) (02/26/91)

Question:
	I have two accounts on the same machine and for disk quota
purposes split my files so that some are in one directory & some in the other, 
and for security reasons I am not willing to set any global write permissions 
(too many people like me out there :^)); it is very inconvienient (sp?) to
relogin with id#2 just to edit a file or such . . . 
and I was wondering if there was some way to set the UID to id#2 
while logged in as id#1 ???

	I tried using a setuid( geteuid() )  with the file owned by id#2
but this does not work (UID and EUID both =id#1).   Am I misunderstanding
the concept of EUID's?  Is there a way to do this ( in say 'c' ) ????
I've searched the man pages but they were very sparse in this area.
I'm on a Sun3 with SunOS 4.0.3.


                         Thanks,
                               Jeff (Joe Unix User)
 
preferably here =>>  jaw7_ltd@uhura.cc.rochester.edu
         or          sa2cs220@uhura.cc.rochester.edu
         or          weisberg@ee.rochester.edu

jik@athena.mit.edu (Jonathan I. Kamens) (02/26/91)

  The easiest way to switch to another UID temporarily is to run "su
username2" and type the second user's password.  You'll get a new shell as the
second user, and you can continue to work with access to that user's files
etc.  You can suspend that shell and go back to it as you wish, or exit from
it when you're done and get back to your original shell as username1.

  It is possible to use the setuid() etc. calls to switch to another UID, but
to do that, the program doing the setuid() has to either be root, or be
running setuid the user that you want to switch to.  So, if you create a
program as username2, assign it a group that has only username1 in it, make it
group and world-executable but not world-executable, and then make it setuid
username2, that program will be able to switch to username2's UID when it is
run.  You can put calls in it to do the appropriate setuid() calls (although
you might not even have to do any such calls, since it's running setuid
username2) and run it as username1.

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710