updating an executing setid file when not root

Joe Steffen steffen at ihu1h.UUCP
Thu Aug 9 23:57:41 AEST 1984


I'm porting a System V program to BSD 4.2 and ran into this problem.  How
do you create a file with the setid bits set from a program that is setid to
a login other than root?  In System III and V this will do it:

	fd = open(target, O_WRONLY | O_CREAT | O_EXCL, 06711);
	
BSD does not have this form of open, so I tried:

	fd = creat(target, 06711);

but the setid bits were ignored.  I added

	chmod(target, 06711);
	
but the setid bits were still ignored.

This program is executed by a command set with a file over a network.  The
program verifies a passwd in the command, and the replaces a file in the
setid login with the file received from the network.

Since the file may be executing, it is linked to a temp name,
the real name is unlinked, and a new file is created with the real name and
the old permissions.  Since this program needs to update itself
occasionally, it needs to set the setid bits in the created file.

-- 


	Joe Steffen, AT&T Bell Labs, Naperville, IL, (312) 979-5381



More information about the Comp.unix.wizards mailing list