delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/11/03/02:28:07

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Message-ID: <472C22E0.D19646B3@dessent.net>
Date: Sat, 03 Nov 2007 00:27:28 -0700
From: Brian Dessent <brian AT dessent DOT net>
X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: detecting elevation of a process running in bash in vista
References: <loom DOT 20071103T000657-49 AT post DOT gmane DOT org>
X-IsSubscribed: yes
Reply-To: cygwin AT cygwin DOT com
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

--------------FF8296F1E59ED3C9998C2524
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Kurt Franke wrote:

> does anyone found a methode to detect if a bash process
> is running so-called "elevated" with cygwin on windows vista ?
> it would be a nice feature setting the prompt to a value
> reflecting this like done when running as root under an unix os.
> or to modify the windows title to reflect the fact that
> the shell is running with special privileges.

You can use something like the attached program.  It will simply return
an exit status code so that in your shell startup you can e.g.:

if isadmin; then
	title="[Admin]"
else
	title=""
fi
PS1='\[\e]0;$title\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '

Note that w32api currently lacks the CheckTokenMembership() prototype so
you'll need to apply
<http://sourceforge.net/tracker/index.php?func=detail&aid=1825044&group_id=2435&atid=302435>
first in order to build this.

Brian
--------------FF8296F1E59ED3C9998C2524
Content-Type: text/plain; charset=us-ascii;
 name="isadmin.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="isadmin.c"

#include <stdio.h>
#define _WIN32_WINNT 0x0500
#include <windows.h>

int main (int argc, char **argv)
{
  SID_IDENTIFIER_AUTHORITY NtAuthority = {SECURITY_NT_AUTHORITY};
  PSID AdministratorsGroup;
  BOOL isAdmin;

  if (AllocateAndInitializeSid (&NtAuthority, 2,
          SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS,
          0, 0, 0, 0, 0, 0, &AdministratorsGroup) == 0 ||
      CheckTokenMembership (NULL, AdministratorsGroup, &isAdmin) == 0)
    {
      printf ("failed with win32 error %lu\n", GetLastError ());
      exit (2);
    }

  FreeSid (AdministratorsGroup);
  exit (!isAdmin);
}


--------------FF8296F1E59ED3C9998C2524
Content-Type: text/plain; charset=us-ascii

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

- Raw text -


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