From owner-freebsd-questions@FreeBSD.ORG Thu Jan 24 00:28:39 2013 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 08B167F4 for ; Thu, 24 Jan 2013 00:28:39 +0000 (UTC) (envelope-from cyberleo@cyberleo.net) Received: from paka.cyberleo.net (mtumishi.cyberleo.net [216.226.128.201]) by mx1.freebsd.org (Postfix) with ESMTP id D82F3A60 for ; Thu, 24 Jan 2013 00:28:38 +0000 (UTC) Received: from [172.16.44.4] (den.cyberleo.net [216.80.73.130]) by paka.cyberleo.net (Postfix) with ESMTPSA id 518361255CD; Wed, 23 Jan 2013 15:51:14 -0500 (EST) Message-ID: <51004D41.2070609@cyberleo.net> Date: Wed, 23 Jan 2013 14:51:13 -0600 From: CyberLeo Kitsana User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.11) Gecko/20121201 Thunderbird/10.0.11 MIME-Version: 1.0 To: Martin McCormick Subject: Re: Setuid binaries and File Ownerships in FreeBSD9.0 References: <201301232026.r0NKQGqF070301@x.it.okstate.edu> In-Reply-To: <201301232026.r0NKQGqF070301@x.it.okstate.edu> X-Enigmail-Version: 1.3.5 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: FreeBSD Questions X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Jan 2013 00:28:39 -0000 On 01/23/2013 02:26 PM, Martin McCormick wrote: > The executable in question is a C program whos file > permissions are 4755 and the file belongs to root so all files > it opens are also owned by root and that works properly, but > what I need is for this application to first open a few files owned by > the caller and then later, upgrade back to root and write to > files the caller can not write to. I was hoping to avoid using > chown and chgrp and simply let the privilege level of the > application dictate ownership of any file it opens. > > When the application first runs, it gets the UID and GID > of the user and uses > > setuid(heruid); and setgid(hergid); to temporarily downgrade and > those files are owned by the right user but setuid(0); doesn't > appear to upgrade back to root. > > Is there any other strategy that gets one back to root > short of using chown and then a system call and never > downgrading privilege? seteuid(2) ? Alternately, open the privileged files before dropping root; you should still be able to write to them afterwards. -- Fuzzy love, -CyberLeo Furry Peace! - http://www.fur.com/peace/