public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] base-files-4.2-1: Change prompt if running with admin rights
@ 2014-04-09 17:15 Christian Franke
  2014-04-09 18:32 ` Achim Gratz
  0 siblings, 1 reply; 9+ messages in thread
From: Christian Franke @ 2014-04-09 17:15 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 150 bytes --]

Thanks to Achim Gratz for adopting base-files.

Attached is an updated version of:
https://sourceware.org/ml/cygwin/2012-02/msg00806.html

Christian


[-- Attachment #2: base-files-4.2-1-rootprompt.patch --]
[-- Type: text/x-patch, Size: 2237 bytes --]

diff -rup base-files-4.2-1.orig/etc/defaults/etc/bash.bashrc base-files-4.2-1/etc/defaults/etc/bash.bashrc
--- base-files-4.2-1.orig/etc/defaults/etc/bash.bashrc	2014-03-23 14:56:28.412930900 +0100
+++ base-files-4.2-1/etc/defaults/etc/bash.bashrc	2014-04-09 13:42:05.000000000 +0200
@@ -27,7 +27,7 @@
 export EXECIGNORE="*.dll"
 
 # Set a default prompt of: user@host and current_directory
-PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '
+PS1='\[\e]0;\w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n'"${PS1a:-\\\$ }"
 
 # Uncomment to use the terminal colours set in DIR_COLORS
 # eval "$(dircolors -b /etc/DIR_COLORS)"
diff -rup base-files-4.2-1.orig/etc/defaults/etc/profile base-files-4.2-1/etc/defaults/etc/profile
--- base-files-4.2-1.orig/etc/defaults/etc/profile	2014-03-23 14:56:28.312931800 +0100
+++ base-files-4.2-1/etc/defaults/etc/profile	2014-04-09 12:59:43.000000000 +0200
@@ -109,6 +109,12 @@ else
   cd "${HOME}" || echo "WARNING: Failed attempt to cd into ${HOME}!"
 fi
 
+# Set PS1a if user has admin rights
+unset PS1a
+if [ -r /proc/registry/HKEY_LOCAL_MACHINE/SECURITY ]; then
+  PS1a="# "
+fi
+
 # Shell dependent settings
 profile_d ()
 {
@@ -135,15 +141,17 @@ if [ ! "x${BASH_VERSION}" = "x"  ]; then
   [ -f "/etc/bash.bashrc" ] && . "/etc/bash.bashrc"
 elif [ ! "x${KSH_VERSION}" = "x" ]; then
   typeset -l HOSTNAME="$(/usr/bin/hostname)"
-  [ "${PS1-null}" = "null" ] || PS1=$(print '\033]0;${PWD}\n\033[32m${USER}@${HOSTNAME} \033[33m${PWD/${HOME}/~}\033[0m\n$ ')
+  [ "${PS1-null}" = "null" ] || PS1=$(print '\033]0;${PWD}\n\033[32m${USER}@${HOSTNAME} \033[33m${PWD/${HOME}/~}\033[0m\n'"${PS1a:-\$ }")
 elif [ ! "x${ZSH_VERSION}" = "x" ]; then
   # zsh is in shell compatibility mode here, so we probably shouldn't do this
   profile_d zsh
+  [ "${PS1-null}" = "null" ] || PS1='(%n@%m)[%h] %~ '"${PS1a:-%% }"
 elif [ ! "x${POSH_VERSION}" = "x" ]; then
-  : # [ "${PS1-null}" = "null" ] || PS1="$ "
+  : # [ "${PS1-null}" = "null" ] || PS1="${PS1a:-\$ }"
 else
-  : # [ "${PS1-null}" = "null" ] || PS1="$ "
+  : # [ "${PS1-null}" = "null" ] || PS1="${PS1a:-\$ }"
 fi
+unset PS1a
 
 export PROFILEREAD PATH ORIGINAL_PATH MANPATH INFOPATH USER TMP TEMP PRINTER HOSTNAME PS1 SHELL tmp temp
 


[-- Attachment #3: Type: text/plain, Size: 218 bytes --]

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] base-files-4.2-1: Change prompt if running with admin rights
  2014-04-09 17:15 [PATCH] base-files-4.2-1: Change prompt if running with admin rights Christian Franke
@ 2014-04-09 18:32 ` Achim Gratz
  2014-04-09 21:51   ` Christian Franke
  2014-04-10  1:50   ` Andrey Repin
  0 siblings, 2 replies; 9+ messages in thread
From: Achim Gratz @ 2014-04-09 18:32 UTC (permalink / raw)
  To: cygwin

Christian Franke writes:
> Attached is an updated version of:
> https://sourceware.org/ml/cygwin/2012-02/msg00806.html

I'll put this on hold until the AD integration has landed in Cygwin
(which will require some larger changes anyway).

Generally I'd prefer to move such things that depend on personal
preferences like setting up prompts into profile.d where they are easier
to change and maintain independently from core system functionality.
Using the registry to check for administrative privileges is clever,
however I'm wondering why we shouldn't simply check via id (that's what
I'm doing personally at the moment).


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Wavetables for the Waldorf Blofeld:
http://Synth.Stromeko.net/Downloads.html#BlofeldUserWavetables

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] base-files-4.2-1: Change prompt if running with admin rights
  2014-04-09 18:32 ` Achim Gratz
@ 2014-04-09 21:51   ` Christian Franke
  2014-04-10  8:11     ` Corinna Vinschen
  2014-04-10  1:50   ` Andrey Repin
  1 sibling, 1 reply; 9+ messages in thread
From: Christian Franke @ 2014-04-09 21:51 UTC (permalink / raw)
  To: cygwin

Achim Gratz wrote:
> Christian Franke writes:
>> Attached is an updated version of:
>> https://sourceware.org/ml/cygwin/2012-02/msg00806.html
> I'll put this on hold until the AD integration has landed in Cygwin
> (which will require some larger changes anyway).

Agree.

> Generally I'd prefer to move such things that depend on personal
> preferences like setting up prompts into profile.d where they are easier
> to change and maintain independently from core system functionality.

The user could disable the root prompt by an "unset PS1a" in a profile.d 
script. The default behavior of Cygwin should IMO be close to 
traditional *nix behavior: Use a special (#) prompt if root(-like) 
privileges are effective.


> Using the registry to check for administrative privileges is clever,
> however I'm wondering why we shouldn't simply check via id (that's what
> I'm doing personally at the moment).

For standard local administrator users, both would work to check for 
privilege elevation.

I used the registry check in the past because it only uses shell 
builtins and does not rely on specific SID->gid mappings in /etc/group.

Christian


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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] base-files-4.2-1: Change prompt if running with admin rights
  2014-04-09 18:32 ` Achim Gratz
  2014-04-09 21:51   ` Christian Franke
@ 2014-04-10  1:50   ` Andrey Repin
  2014-04-11  7:20     ` Thomas Wolff
  1 sibling, 1 reply; 9+ messages in thread
From: Andrey Repin @ 2014-04-10  1:50 UTC (permalink / raw)
  To: Achim Gratz, cygwin

Greetings, Achim Gratz!

> Christian Franke writes:
>> Attached is an updated version of:
>> https://sourceware.org/ml/cygwin/2012-02/msg00806.html

> I'll put this on hold until the AD integration has landed in Cygwin
> (which will require some larger changes anyway).

> Generally I'd prefer to move such things that depend on personal
> preferences like setting up prompts into profile.d where they are easier
> to change and maintain independently from core system functionality.
> Using the registry to check for administrative privileges is clever,

But indirect.
It does not guarantee, that a user have administrator rights, only that it has
access to the specified registry key.

> however I'm wondering why we shouldn't simply check via id (that's what
> I'm doing personally at the moment).

Unless there's a way to ask "if we're a part of <certain group>" or more
direct questions, it would involve much tinkering.
And I agree, that all tinkering needs to go into personal profile.


--
WBR,
Andrey Repin (anrdaemon@yandex.ru) 10.04.2014, <04:31>

Sorry for my terrible english...


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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] base-files-4.2-1: Change prompt if running with admin rights
  2014-04-09 21:51   ` Christian Franke
@ 2014-04-10  8:11     ` Corinna Vinschen
  2014-04-10 15:36       ` Achim Gratz
  2014-04-10 15:57       ` Christian Franke
  0 siblings, 2 replies; 9+ messages in thread
From: Corinna Vinschen @ 2014-04-10  8:11 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1615 bytes --]

On Apr  9 23:50, Christian Franke wrote:
> Achim Gratz wrote:
> >Christian Franke writes:
> >>Attached is an updated version of:
> >>https://sourceware.org/ml/cygwin/2012-02/msg00806.html
> >I'll put this on hold until the AD integration has landed in Cygwin
> >(which will require some larger changes anyway).
> 
> Agree.
> 
> >Generally I'd prefer to move such things that depend on personal
> >preferences like setting up prompts into profile.d where they are easier
> >to change and maintain independently from core system functionality.
> 
> The user could disable the root prompt by an "unset PS1a" in a
> profile.d script. The default behavior of Cygwin should IMO be close
> to traditional *nix behavior: Use a special (#) prompt if
> root(-like) privileges are effective.
> 
> 
> >Using the registry to check for administrative privileges is clever,
> >however I'm wondering why we shouldn't simply check via id (that's what
> >I'm doing personally at the moment).
> 
> For standard local administrator users, both would work to check for
> privilege elevation.
> 
> I used the registry check in the past because it only uses shell
> builtins and does not rely on specific SID->gid mappings in
> /etc/group.

Especially given that in future there might be no /etc/group to begin
with.

But even without /etc/group, the administrator's group will have the
gid 544.  I think such a test should be sufficient?


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] base-files-4.2-1: Change prompt if running with admin rights
  2014-04-10  8:11     ` Corinna Vinschen
@ 2014-04-10 15:36       ` Achim Gratz
  2014-04-10 15:57       ` Christian Franke
  1 sibling, 0 replies; 9+ messages in thread
From: Achim Gratz @ 2014-04-10 15:36 UTC (permalink / raw)
  To: cygwin

Corinna Vinschen writes:
> But even without /etc/group, the administrator's group will have the
> gid 544.  I think such a test should be sufficient?

That's what I've been using for quite some time and I guess that's the
right thing to check for.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf Q+, Q and microQ:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] base-files-4.2-1: Change prompt if running with admin rights
  2014-04-10  8:11     ` Corinna Vinschen
  2014-04-10 15:36       ` Achim Gratz
@ 2014-04-10 15:57       ` Christian Franke
  1 sibling, 0 replies; 9+ messages in thread
From: Christian Franke @ 2014-04-10 15:57 UTC (permalink / raw)
  To: cygwin

Corinna Vinschen wrote:
> On Apr  9 23:50, Christian Franke wrote:
>> I used the registry check in the past because it only uses shell
>> builtins and does not rely on specific SID->gid mappings in
>> /etc/group.
> Especially given that in future there might be no /etc/group to begin
> with.
>
> But even without /etc/group, the administrator's group will have the
> gid 544.  I think such a test should be sufficient?

Yes.

Result would only differ for special accounts like "Backup 
Administrator" (has SeBackup/RestorePrivilege but is not member of local 
admin group).

This change for my patch uses shell builtins for the string matching:

  # Set PS1a if user has admin rights
  unset PS1a
-if [ -r /proc/registry/HKEY_LOCAL_MACHINE/SECURITY ]; then
-  PS1a="# "
-fi
+case " $(/usr/bin/id -G) " in
+  *\ 544\ *) PS1a="# " ;;
+esac

Works for me with bash, dash, mksh, posh, and zsh.

Christian


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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] base-files-4.2-1: Change prompt if running with admin rights
  2014-04-10  1:50   ` Andrey Repin
@ 2014-04-11  7:20     ` Thomas Wolff
  2014-04-11 20:08       ` Christian Franke
  0 siblings, 1 reply; 9+ messages in thread
From: Thomas Wolff @ 2014-04-11  7:20 UTC (permalink / raw)
  To: cygwin

Am 10.04.2014 03:39, schrieb Andrey Repin:
> Greetings, Achim Gratz!
>
>> Christian Franke writes:
>>> Attached is an updated version of:
>>> https://sourceware.org/ml/cygwin/2012-02/msg00806.html
>> I'll put this on hold until the AD integration has landed in Cygwin
>> (which will require some larger changes anyway).
>> Generally I'd prefer to move such things that depend on personal
>> preferences like setting up prompts into profile.d where they are easier
>> to change and maintain independently from core system functionality.
>> Using the registry to check for administrative privileges is clever,
> But indirect.
> It does not guarantee, that a user have administrator rights, only that it has
> access to the specified registry key.
>
>> however I'm wondering why we shouldn't simply check via id (that's what
>> I'm doing personally at the moment).
> Unless there's a way to ask "if we're a part of <certain group>" or more
> direct questions, it would involve much tinkering.
> And I agree, that all tinkering needs to go into personal profile.
I use this in .bashrc (to embed $rootmark in an ESC sequence in PS1 later).
I think it doesn't have specific dependencies and also it's portable 
(except the group names are Windows ones...).

   if id | grep -e "gid=.*(root)" -e "gid=.*(Administrators)" > /dev/null
   then    rootmark="30;41"; dirmark=7
   elif id | grep -e "gid=.*(Power Users)" > /dev/null
   then    rootmark="30;43"; dirmark=7
   else    rootmark=0; dirmark="33;44"
   fi

Also I embed [$SHLVL] in PS1 unless it's 0, just as a suggestion.
------
Thomas

---
Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus Schutz ist aktiv.
http://www.avast.com


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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] base-files-4.2-1: Change prompt if running with admin rights
  2014-04-11  7:20     ` Thomas Wolff
@ 2014-04-11 20:08       ` Christian Franke
  0 siblings, 0 replies; 9+ messages in thread
From: Christian Franke @ 2014-04-11 20:08 UTC (permalink / raw)
  To: cygwin

Thomas Wolff wrote:
> I use this in .bashrc (to embed $rootmark in an ESC sequence in PS1 
> later).
> I think it doesn't have specific dependencies and also it's portable 
> (except the group names are Windows ones...).

It's not portable because Windows default user/group names are localized.


>   if id | grep -e "gid=.*(root)" -e "gid=.*(Administrators)" > /dev/null
>   then    rootmark="30;41"; dirmark=7
>   elif id | grep -e "gid=.*(Power Users)" > /dev/null

German Windows uses "Administratoren", "Hauptbenutzer", 
"Domänen-Admins', ...


>   then    rootmark="30;43"; dirmark=7
>   else    rootmark=0; dirmark="33;44"
>   fi
>
> Also I embed [$SHLVL] in PS1 unless it's 0, just as a suggestion.

Makes sense. I vote +1 for the base-file's /etc/bash.bashrc :-)

Christian


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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-04-11 20:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-09 17:15 [PATCH] base-files-4.2-1: Change prompt if running with admin rights Christian Franke
2014-04-09 18:32 ` Achim Gratz
2014-04-09 21:51   ` Christian Franke
2014-04-10  8:11     ` Corinna Vinschen
2014-04-10 15:36       ` Achim Gratz
2014-04-10 15:57       ` Christian Franke
2014-04-10  1:50   ` Andrey Repin
2014-04-11  7:20     ` Thomas Wolff
2014-04-11 20:08       ` Christian Franke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).