delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2023/08/18/04:50:55

X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 79419385040B
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1692348654;
bh=lgM3TMV4NIY/e8cEhngWEL6HoNjoNhka+KgOkkh3E04=;
h=Subject:Cc:References:Date:In-Reply-To:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
From;
b=voZ1YaA+BM7PF6x6RuphOWFRv4uOCRQOaJ/Jub+JoawhlJUc0o4SrifWYEDQySrkV
RZv68lTTeGGlB9M2YPEaUkRiCOZiz7RANeTsE36EFEPzxxm3eNgeTT0uj5QM2rtFZK
K8Q6ovFSqE/SeYwOUC0EIU0+9+2Kr+E4Fs4HdxtU=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1EBB8385084A
Subject: Re: Test for Windows Administrator permissions from Cygwin
terminal|script?
Cc: cygwin AT cygwin DOT com
References: <CANH4o6OpsvT99AeJ2uTcqyajWQHmffYJqV=RR4HBxoFaveR7sQ AT mail DOT gmail DOT com>
<CAKwdsS_Q93_Z0E2cM2iw+DZRvB0DaR6YSi9frod_uh7aoCMxUA AT mail DOT gmail DOT com>
Message-ID: <a1d6ff78-2b87-9111-8339-f0ce6d6050cd@maxrnd.com>
Date: Fri, 18 Aug 2023 01:49:18 -0700
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101
Firefox/52.0 SeaMonkey/2.49.4
MIME-Version: 1.0
In-Reply-To: <CAKwdsS_Q93_Z0E2cM2iw+DZRvB0DaR6YSi9frod_uh7aoCMxUA@mail.gmail.com>
X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS,
KAM_LAZY_DOMAIN_SECURITY, MISSING_HEADERS, NICE_REPLY_A, SPF_HELO_NONE,
SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
server2.sourceware.org
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.29
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-request AT cygwin DOT com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
<mailto:cygwin-request AT cygwin DOT com?subject=subscribe>
From: Mark Geisert via Cygwin <cygwin AT cygwin DOT com>
Reply-To: Mark Geisert <mark AT maxrnd DOT com>
Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com>
X-MIME-Autoconverted: from base64 to 8bit by delorie.com id 37I8oteD014880

Backwoods BC via Cygwin wrote:
> On Thu, Aug 17, 2023 at 7:01 PM Martin Wege via Cygwin
> <cygwin AT cygwin DOT com> wrote:
>> How can I find out whether the current Cygwin terminal has
>> Administrator rights? I want to safeguard our admin scripts with a
>> simple test and bail out with an error if someone wants to do admin
>> stuff (say: regtool) without admin privileges.
>>
>> Thanks,
>> Martin
> 
> I don't know if this is the official method, but it works for me:
> 
> ##### Shell Options
> # Elevated privilege windows have $SESSIONNAME set
> if [ "$SESSIONNAME" == "" ] ;then
>    printf -v adminPmt '[\u2022Admin\u2022] '
> else
>    export adminPmt=""
> fi

I see the opposite on my machine.  Admin window has empty $SESSIONNAME, non-Admin 
window has "Console".

What I do locally is check the output of the 'id' command.  If group 
544(Administrators) is present, that's a window with Admin rights.  Inside .bashrc 
I have a simple grep test on the output of 'id' to set PS1 (shell prompt) 
appropriately.

..mark

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019