From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26774 invoked by alias); 15 Oct 2013 15:18:25 -0000 Mailing-List: contact cygwin-apps-help@cygwin.com; run by ezmlm Precedence: bulk Sender: cygwin-apps-owner@cygwin.com List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Mail-Followup-To: cygwin-apps@cygwin.com Received: (qmail 26759 invoked by uid 89); 15 Oct 2013 15:18:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-HELO: mail109.syd.optusnet.com.au Received: from mail109.syd.optusnet.com.au (HELO mail109.syd.optusnet.com.au) (211.29.132.80) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 15 Oct 2013 15:18:23 +0000 Received: from [0.0.0.0] (c122-106-16-37.rivrw1.nsw.optusnet.com.au [122.106.16.37]) by mail109.syd.optusnet.com.au (Postfix) with ESMTP id 2EC97D62BCB for ; Wed, 16 Oct 2013 02:18:19 +1100 (EST) Message-ID: <525D5CBA.7050201@shaddybaddah.name> Date: Tue, 15 Oct 2013 15:18:00 -0000 From: Shaddy Baddah User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130828 Icedove/17.0.8 MIME-Version: 1.0 To: cygwin-apps@cygwin.com Subject: Re: cannot run setup64.exe without admin privileges (even if renamed foo.exe) References: <6CF2FC1279D0844C9357664DC5A08BA215F56A@MLBXV06.nih.gov> <523F9C4F.6010109@cygwin.com> <6CF2FC1279D0844C9357664DC5A08BA215F9C7@MLBXV06.nih.gov> <20131015090805.GC19383@calimero.vinschen.de> <525D1731.5080801@shaddybaddah.name> <20131015122210.GA3745@calimero.vinschen.de> In-Reply-To: <20131015122210.GA3745@calimero.vinschen.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=DstvpgP+ c=1 sm=1 tr=0 a=RkPObcNqpdaXDoCDBSw5Xw==:117 a=RkPObcNqpdaXDoCDBSw5Xw==:17 a=PO7r1zJSAAAA:8 a=sSMKkBCuBxkA:10 a=hmhdb2IkdaIA:10 a=IkcTkHD0fZMA:10 a=9jAJZebTa1AA:10 a=8kwRay2inb2yuVjdevMA:9 a=QEXdDO2ut3YA:10 X-IsSubscribed: yes X-SW-Source: 2013-10/txt/msg00134.txt.bz2 Hi Corinna, On 15/10/13 23:22, Corinna Vinschen wrote: > Hi Shaddy, > > On Oct 15 21:21, Shaddy Baddah wrote: >> Hi Corinna, >> >> On 15/10/13 20:08, Corinna Vinschen wrote: >>> [...] >>> Assuming setup would get an "asInvoker" manifest, so it runs with the >>> privileges of the current user. First thing it would check its user >>> token. There are three cases: >>> >>> - When started by a non-admin user, the user token would contain no >>> trace of the administrators group in the user token group list. >>> In this case, setup would just run along as usual for the current user. >>> >>> - When started elevated (with "Run as administrator...", for instance), >>> the user token group list would contain the administrators group, >>> enabled. So setup knows it has admin rights anyway and just runs along >>> as in the non-admin user case. So, in fact, these two cases are just >>> one case. >>> >>> - Now, when started by an admin user, but not elevated, the group list >>> would contain the administrators group, too, but with the "Use for >>> deny only" flag set. If setup recognizes this flag, rather than running >>> along, it calls ShellExecute on itself, with the "runas" flag set. >>> So it elevates a copy of itself and just exits. The elevated copy >>> then runs as usual. >>> >>> The only downside with this concept, as far as I can see, is, somebody >>> would have to implement it... >>> >>> Does that sound feasible? >> >> I apologise... I've been sitting on an almost-there implementation of >> this for almost two weeks, waiting for a moment to polish it properly >> for patch submission. >> >> I can't elaborate on the pros and cons of the patch at the moment, as >> I am accessing my desktop remotely. But I will follow-up later tonight >> with more details. > > thanks for letting us know and your patch. I had a look and it looks > good for a start. You just call the CheckTokenMembership function, > though. The problem is, you won't know if the process has been started > by a non-admin or by an admin without elevation. So you always call > ShellExecute if setup is started without admin rights, for non-admins > and non-elevated admins alike, unless the --no-admin option is given. Yes that is deliberate. Initially I coded this for how I viewed was desirable, that being that it would use CheckTokenMembership to see if it was elevated (or just run as Administrator on XP). If it was not, it would attempt to elevate using "runas" flag. If that was rejected, it would carry on. The --no-admin was still used as per the patch submitted to avoid infinite loop just in-case ShellExecuteEx didn't honour "runas" and just ran setup all over again with no Administrator rights. However I sensed from previous discussions that really it was desirable to steer users towards running as Admin/elevated privilege. Unless they really knew what they were doing. So much so that building a custom setup.exe was being recommended without much discussion of an alternative... until now. So this patch tries to be as backwards compatible as possible. That is, unless the user has already explicitly elevated privilege (context menu -> Run as ...), setup.exe forces an attempt. And fails if it does not elevate. The forced attempt can be avoided by explicitly specifying --no-admin. The patch I provided doesn't match exactly the behaviour of setup on various systems at the moment, in the following ways: * I don't know how, and did not bother too much about emulating the "access denied" when the user rejects the privilege elevation. * Under x86 (32bit), where the user has performed the rename magic that normally circumvents the UAC Installer Detection Technology, setup will still behave as if they hadn't and continue to try to elevate. IMO this is minor, but if we were going for 100% compatibility, we could check the exe filename against the same list that cygports uses, and avoid the privilege elevation attempt: /usr/share/cygport/lib/src_postinst.cygpart:1112: find * -type f -executable -a \( -name '*instal*.exe' -o -name '*patch*.exe' -o -name '*setup*.exe' -o -name '*update*.exe' \) -print0 | \ * Under XP (32 bit... I don't know about any other archs (if they exist?) or other XP like editions (server???)), for a non-Administrator the attempt to elevate privilege is also an extra behaviour that wouldn't have been normally encountered. Again, it may have been easy to detect that and do something about it too. Another bit of polish this patch needs is a effective way to close off logging once and for all when we are about to call ShellExecuteEx. Putting in the line: + l->msg.clear(); staved off the doubling up of logging when LogFile::exit was being called. But unfortunately a bunch of newlines where being logged instead. I never got around to knocking all that on the head. > Is that what we want? Or should the process only be elevated when > started by a non-elevated admin as I proposed. I'm not sure, really. If I understand right, you were proposing that if the user was not an Admin at all, then just let them run as they were. As I wrote earlier, it seemed from discussion that it was desirable (if not pseudo policy) that regular Cygwin users run with privilege elevated. And knowing of various features built into setup that require elevated privilege, eg. replace on boot, I can see why that is. But I am happy to be guided either way. I can help out too, but as you can see by the latency in my communication/implementation, I am not a pillar of reliability :-( -- Regards, Shaddy