diff --git a/APKBUILD b/APKBUILD index 2cc29d1..0c2767e 100644 --- a/APKBUILD +++ b/APKBUILD @@ -25,9 +25,9 @@ package() { } sha512sums=" -ae9e049ba65f70bac3acc6c37d0b40b4ce52593b687672a507b753ad3ca55ef02e0d0bcb1a2310982edab9c1ec77b0439fcadbd9762ccecb3143cb22ebe97562 moerx.c +cc8a8de425c3149ca7e66df304330f3ceb13851b31986afc28bdbfe92e854fbea44ca3955178e4a8e5507a04cf9eb08f6093b2f92fd3b865ccad9df58777fa8b moerx.c e6336e712a9a6071b16cbde83cd6f591c480da68cf5185f0db27f321b26adb075844a958e792da419dcb82a930de6cff28bc64a98e9b0facd9350e382aa95ce1 Makefile -1158a716d81fc33b850bf1fbb2e2ca821297da173d5024bd88418fc0f82273f9889bebe6ace5b8d9d09c21f833f96a56e5d7cb58f9b96c827b57b2e02640f7c2 moerx.1 -e801f1c949bd4a8f4420660787587ca844cc5be739925e2ea8195bc3a5ec8185c7c2517e1e10c2f6f34aac65f2bbd08ac86be07b732d499a97f1987bfda4a7c6 README.md +cc677bc8c9637963dd19a031c0920f7178e71a93d236d1445ef4a5cbabefd3b3a68d9696444d2a6d0a9993ed05df55e8de876e7e515bd31effaeb7425c90a52a moerx.1 +1c062a64ce9a9578cee00eda52c0efe895a695aa8ff989250a4a1f0a84ef06ed8be7800e90942ebbe11b5feb8a464941c0084f1bd975efb038c0884278f95565 README.md 2fe33ba22c5f68e124904be594208f050be20f33d115f9a56f60cac93304102da32e6a7e78154e831d3704da7ca8bfefd7025e7b8901e65babcd83e7342f6382 LICENSE " diff --git a/PKGBUILD b/PKGBUILD index ccbbb89..5e55ab4 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -9,10 +9,10 @@ license=('Apache-2.0') depends=('glibc') source=('moerx.c' 'Makefile' 'moerx.1' 'README.md' 'LICENSE') sha256sums=( - '85c51d8bcfb660287ea1cc2dbb8a0edd6ab137ce766a929ddb4f0ae0e7e37d32' + '94d908770434001bf677d00127fb27e956e032e96ae4074fdac3ea46d6304e3d' 'ad08bd0acd671f1f1716250528c2d4e5acc78a83bf55fcebdf41fa101fbb71d5' - '5787b0b3f36e5369511d165bb7097492888d39a35a936b1a2e2d47760156d6cf' - 'be0803b92b688e125133cc62f5df31bb925203e88d8f31749fb7b5ebcdb4c71c' + '38b60956c86513c53bd129cb3541b28ac161c17d56c58441e8904cba7ea501d8' + 'aabf1e9e829802d845d3d3d71b774fcadb83c5f3d5e525cbb4d366edca5749d4' '31c5556be4cdd9bf52bb55f18ead0c68a4f0e793c2c2dab0a2a2c6d92407d0d4' ) diff --git a/README.md b/README.md index 720b58d..81fc51c 100644 --- a/README.md +++ b/README.md @@ -105,12 +105,21 @@ Without a matching title, the window name remains `local-hostname:ssh`. Names refresh within one second; disconnecting restores the local hostname and shell name in the terminal title and window list. +For root detection after `su` or `sudo -i`, install the matching hook in +**both the regular user's and root's shell startup files on the remote host**. +The hooks also activate in interactive `screen-256color` terminals, so they +continue working when privilege-switching tools remove `$SSH_CONNECTION`. +Root prompts and commands then turn the active window name red; exiting back +to the regular shell restores yellow. A reported remote `su` command is red +while it runs, even before the new shell reports its UID. SSH disconnects +restore local detection. No SSH server configuration change is required. + ### Zsh For **zsh**, add this to `~/.zshrc` on the **remote host**: ```zsh -if [[ -n $SSH_CONNECTION ]]; then +if [[ -o interactive && ( -n $SSH_CONNECTION || $TERM == screen-256color ) ]]; then autoload -Uz add-zsh-hook moerx_ssh_title() { local program=${1:t} @@ -149,7 +158,8 @@ existing moerx servers and reload the remote shell configuration after upgrading For **Bash**, add this to `~/.bashrc` on the **remote host**: ```bash -if [[ $- == *i* && -n $SSH_CONNECTION && -z ${moerx_ssh_installed-} ]]; then +if [[ $- == *i* && ( -n $SSH_CONNECTION || $TERM == screen-256color ) && + -z ${moerx_ssh_installed-} ]]; then moerx_ssh_title() { local program=$1 directory=$PWD program=${program##*/} diff --git a/moerx.1 b/moerx.1 index 8dc4614..51d672e 100644 --- a/moerx.1 +++ b/moerx.1 @@ -278,14 +278,20 @@ Disconnecting SSH restores the local shell's path and name. With splits the window and status follow the active pane. OSC 777;moerx-root;1 reports a root shell and OSC 777;moerx-root;0 clears it. The report is tied to the foreground SSH job and is ignored after disconnect. -Remote shells without the hooks cannot report privilege changes. +Remote su command titles also mark the active window red, even before a UID +report arrives. Remote shells without hooks cannot report their UID. +Install the matching hook in both the regular user's and root's startup files. +The examples activate in interactive screen-256color terminals as well as when +SSH_CONNECTION is set, so su and sudo login shells can report status even if +they clear the SSH environment. The parent shell clears root status at its +next prompt after the root shell exits. .SS Zsh Add the following to ~/.zshrc on the remote host. The preexec hook reports the first command of a pipeline; precmd restores the shell name and reports the directory after cd. .nf .ft CR -if [[ \-n $SSH_CONNECTION ]]; then +if [[ \-o interactive && ( \-n $SSH_CONNECTION || $TERM == screen\-256color ) ]]; then autoload \-Uz add\-zsh\-hook moerx_ssh_title() { local program=${1:t} @@ -320,7 +326,8 @@ with that framework instead of replacing its trap. Do not enable function tracing (set -T) for these hooks. .nf .ft CR -if [[ $\- == *i* && \-n $SSH_CONNECTION && \-z ${moerx_ssh_installed\-} ]]; then +if [[ $\- == *i* && ( \-n $SSH_CONNECTION || $TERM == screen\-256color ) && + \-z ${moerx_ssh_installed\-} ]]; then moerx_ssh_title() { local program=$1 directory=$PWD program=${program##*/} diff --git a/moerx.c b/moerx.c index 4206623..317dd2c 100644 --- a/moerx.c +++ b/moerx.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -1249,8 +1250,14 @@ static int window_update_name(Session *s, Window *w) { if ((unsigned char)*s < 32 || (unsigned char)*s == 127) *s = '?'; } int privileged = strcmp(base, "su") == 0 || process_is_root(pid); - if (strcmp(base, "ssh") == 0 && p->reported_root_pgrp == pid) - privileged = p->reported_root; + if (strcmp(base, "ssh") == 0) { + /* An SSH process's local UID says nothing about the remote user. */ + privileged = p->reported_root_pgrp == pid && p->reported_root; + if (p->remote_title_pgrp == pid) { + const char *program = strchr(p->remote_title, ':'); + if (program && strcmp(program + 1, "su") == 0) privileged = 1; + } + } int changed = w->privileged != privileged; w->privileged = privileged; char next[sizeof w->name];