diff --git a/atom.mk b/atom.mk index 769dc88ff..fd030aaaf 100644 --- a/atom.mk +++ b/atom.mk @@ -5,7 +5,12 @@ include $(CLEAR_VARS) LOCAL_MODULE := dropbear-pv LOCAL_DESCRIPTION := dropbear-pv -LOCAL_AUTOTOOLS_CONFIGURE_ARGS := --enable-static +LOCAL_AUTOTOOLS_CONFIGURE_ARGS := \ + --enable-static \ + --disable-lastlog \ + --disable-wtmp \ + $(NULL) + LOCAL_LIBRARIES += zlib LOCAL_CLEAN_DIRS := $(call local-get-build-dir)/usr/share/ $(call local-get-build-dir)/usr/include/ diff --git a/fallbear-cmd b/fallbear-cmd index d5b5c7646..cd7264d70 100644 --- a/fallbear-cmd +++ b/fallbear-cmd @@ -1,28 +1,48 @@ #!/bin/sh +echo_debug() { + if [ -n "$PVDEBUG" ]; then + echo $@ + fi +} + lxc_pid() { - target=$1 - nsenter -m/proc/1/ns/mnt \ - lxc-info $target | grep PID: | sed -e 's/^[^0-9]*//' + target=$1 + nsenter -m/proc/1/ns/mnt \ + lxc-info $target | grep PID: | sed -e 's/^[^0-9]*//' } target=$USER p=1 if ! [ "$target" = "/" ]; then - p=`lxc_pid $target` + p=`lxc_pid $target` - if [ -z "$p" ]; then - echo "no container found: $target" - exit 1 - fi + if [ -z "$p" ]; then + echo "no container found: $target" + exit 1 + fi fi -args=${@:-/bin/sh -l} -nsenter -m/proc/$p/ns/mnt \ - -n/proc/$p/ns/net \ - -p/proc/$p/ns/pid \ - -u/proc/$p/ns/uts \ - -i/proc/$p/ns/ipc \ - $args +PVUSER=${PVUSER:-root} +echo_debug PVUSER: $PVUSER +pwdline=`nsenter -m/proc/$p/ns/mnt -- [ -f /etc/passwd ] \ + && (nsenter -m/proc/$p/ns/mnt cat /etc/passwd | grep ^$PVUSER:) \ + || true` + +shell=`echo $pwdline | sed -e 's/^.*:\([^:]*\)$/\1/'` +home=`echo $pwdline | sed -e 's/^.*:\([^:]*\):[^:]*$/\1/'` +echo_debug shell: $shell +echo_debug home: $home + +args=${SSH_ORIGINAL_COMMAND:-${shell:-/bin/sh} -l} +echo_debug running shell: $args +USER=root LOGNAME=root HOME=${home:-/tmp1} \ + nsenter -m/proc/$p/ns/mnt \ + -n/proc/$p/ns/net \ + -p/proc/$p/ns/pid \ + -u/proc/$p/ns/uts \ + -i/proc/$p/ns/ipc \ + -- \ + $args