From owner-freebsd-questions@FreeBSD.ORG Fri Sep 17 19:26:19 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2A1FD16A4CE for ; Fri, 17 Sep 2004 19:26:19 +0000 (GMT) Received: from internet.potentialtech.com (h-66-167-251-6.phlapafg.covad.net [66.167.251.6]) by mx1.FreeBSD.org (Postfix) with ESMTP id F36E943D48 for ; Fri, 17 Sep 2004 19:26:18 +0000 (GMT) (envelope-from wmoran@potentialtech.com) Received: from working.potentialtech.com (pa-plum-cmts1e-68-68-113-64.pittpa.adelphia.net [68.68.113.64]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by internet.potentialtech.com (Postfix) with ESMTP id 2417869A71; Fri, 17 Sep 2004 15:26:18 -0400 (EDT) Date: Fri, 17 Sep 2004 15:26:17 -0400 From: Bill Moran To: Richard Bradley Message-Id: <20040917152617.2cbdf4c5.wmoran@potentialtech.com> In-Reply-To: <200409171950.19717.rtb27@cam.ac.uk> References: <200409171950.19717.rtb27@cam.ac.uk> Organization: Potential Technologies X-Mailer: Sylpheed version 0.9.12 (GTK+ 1.2.10; i386-portbld-freebsd4.9) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit cc: freebsd-questions@freebsd.org Subject: Re: how to make an executable run as another user X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Sep 2004 19:26:19 -0000 Richard Bradley wrote: > Um. I feel silly asking this. But I can't work it out. Not silly, common problem for shell script writers. > I want a shell script to run as another user. I always thought this was easy > to do with the setuid bit, but never tried it before. I read "man chmod" and > found this: > > ..... > 4000 (the setuid bit). Executable files with this bit set will > run with effective uid set to the uid of the file owner. > ..... > s The set-user-ID-on-execution and set-group-ID-on-execution > bits. > .... > > And off I went. I wrote a shell script to output the current uid. I chown'ed > it to another user. I "chmod +s"ed it. I ran it. > > It didn't work. > > ----- > > rtb27# cat test > #! /bin/sh > whoami > rtb27# ll test > -rwsr-sr-x 1 rich wheel 20 Sep 17 19:34 test > rtb27# ./test > root Interpreted programs (i.e. scripts) don't honor setuid/setgid (with the notable exception of setuidperl, which is installed but disabled on FreeBSD) Clever use of su or sudo can work around this. Also, writing a C or C++ wrapper program will help. That's a bit of a PITA, though. -- Bill Moran Potential Technologies http://www.potentialtech.com