From b42538956a08f009060a56c48f8844f96165daa4 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 26 May 2018 18:33:27 +0200 Subject: git-receiver: added support to use as an authorized_keys commmand --- src/blogc-git-receiver/main.c | 14 +++++++++++++- tests/blogc-git-receiver/check_shell.sh.in | 7 +++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/blogc-git-receiver/main.c b/src/blogc-git-receiver/main.c index c18bb14..368871a 100644 --- a/src/blogc-git-receiver/main.c +++ b/src/blogc-git-receiver/main.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include "shell.h" @@ -24,8 +25,19 @@ main(int argc, char *argv[]) return bgr_post_receive_hook(argc, argv); } - if (argc == 3 && (0 == strcmp(argv[1], "-c"))) + if (argc == 3 && (0 == strcmp(argv[1], "-c"))) { return bgr_shell(argc, argv); + } + + // this is a hack to make blogc-git-receiver work out-of-the-box as a + // `command=` in authorized_keys file. it will only work if the command + // path is absolute. + char *ssh_orig = getenv("SSH_ORIGINAL_COMMAND"); + if (argc == 1 && ssh_orig != NULL && argv[0][0] == '/') { + setenv("SHELL", argv[0], 1); + char* _argv[3] = {argv[0], "-c", ssh_orig}; + return bgr_shell(3, _argv); + } fprintf(stderr, "error: this is a special shell, go away!\n"); return 3; diff --git a/tests/blogc-git-receiver/check_shell.sh.in b/tests/blogc-git-receiver/check_shell.sh.in index 1c84b8a..8743293 100755 --- a/tests/blogc-git-receiver/check_shell.sh.in +++ b/tests/blogc-git-receiver/check_shell.sh.in @@ -63,6 +63,13 @@ else grep "agent=" "${TEMP}/output.txt" &> /dev/null fi +echo 0000 | SSH_ORIGINAL_COMMAND="git-upload-pack 'lol.git'" call_bgr 2>&1 > "${TEMP}/output.txt" +if [[ -n "${VALGRIND}" ]]; then + grep "git-shell -c \"git-upload-pack '.*repos/lol.git'\"" "${TEMP}/output.txt" &> /dev/null +else + grep "agent=" "${TEMP}/output.txt" &> /dev/null +fi + echo 0000 | call_bgr -c "git-upload-archive 'lol.git'" 2>&1 > "${TEMP}/output.txt" || true if [[ -n "${VALGRIND}" ]]; then grep "git-shell -c \"git-upload-archive '.*repos/lol.git'\"" "${TEMP}/output.txt" &> /dev/null -- cgit v1.2.3-18-g5258