diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-05-26 18:33:27 +0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2018-05-26 18:33:27 +0200 |
commit | b42538956a08f009060a56c48f8844f96165daa4 (patch) | |
tree | bdbf3754b2eeb57f4b233e9570f786e1f6442ec6 /src/blogc-git-receiver/main.c | |
parent | 151b096f3d2859a9c77915477047c998cf2c1a95 (diff) | |
download | blogc-b42538956a08f009060a56c48f8844f96165daa4.tar.gz blogc-b42538956a08f009060a56c48f8844f96165daa4.tar.bz2 blogc-b42538956a08f009060a56c48f8844f96165daa4.zip |
git-receiver: added support to use as an authorized_keys commmand
Diffstat (limited to 'src/blogc-git-receiver/main.c')
-rw-r--r-- | src/blogc-git-receiver/main.c | 14 |
1 files changed, 13 insertions, 1 deletions
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 <stdio.h> +#include <stdlib.h> #include <string.h> #include <libgen.h> #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; |