diff options
author | Runxi Yu <me@runxiyu.org> | 2025-02-17 21:57:09 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-02-17 21:57:09 +0800 |
commit | eb1883a8e6241bf811de13a978ebb6af79210967 (patch) | |
tree | 190197e8eee3176d2677c82ac2e470aa6141f619 /git_hooks_client | |
parent | go.mod: Bump lindenii-common (cmap split into ComparableMap and Map) (diff) | |
download | forge-eb1883a8e6241bf811de13a978ebb6af79210967.tar.gz forge-eb1883a8e6241bf811de13a978ebb6af79210967.tar.zst forge-eb1883a8e6241bf811de13a978ebb6af79210967.zip |
hooks, etc.: Authenticate hooks, and handle them in the spawning thread
Diffstat (limited to 'git_hooks_client')
-rw-r--r-- | git_hooks_client/git_hooks_client.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/git_hooks_client/git_hooks_client.c b/git_hooks_client/git_hooks_client.c index fa3e04c..541e606 100644 --- a/git_hooks_client/git_hooks_client.c +++ b/git_hooks_client/git_hooks_client.c @@ -14,6 +14,16 @@ int main(int argc, char *argv[]) { dprintf(STDERR_FILENO, "environment variable LINDENII_FORGE_HOOKS_SOCKET_PATH undefined\n"); return EXIT_FAILURE; } + const char *cookie = getenv("LINDENII_FORGE_HOOKS_COOKIE"); + if (cookie == NULL) { + dprintf(STDERR_FILENO, "environment variable LINDENII_FORGE_HOOKS_COOKIE undefined\n"); + return EXIT_FAILURE; + } + if (strlen(cookie) != 64) { + dprintf(STDERR_FILENO, "environment variable LINDENII_FORGE_HOOKS_COOKIE is not 64 characters long, something has gone wrong\n"); + dprintf(STDERR_FILENO, "%s\n", cookie); + return EXIT_FAILURE; + } /* * All hooks in git (see builtin/receive-pack.c) use a pipe by setting @@ -83,7 +93,24 @@ int main(int argc, char *argv[]) { } /* - * First we report argc and argv to the UNIX domain socket. + * We first send the 64-byte cookie to the UNIX domain socket + */ + ssize_t cookie_bytes_sent = send(sock, cookie, 64, 0); + switch (cookie_bytes_sent) { + case -1: + perror("send cookie"); + close(sock); + return EXIT_FAILURE; + case 64: + break; + default: + dprintf(STDERR_FILENO, "send returned unexpected value on internal socket\n"); + close(sock); + return EXIT_FAILURE; + } + + /* + * Next we can report argc and argv to the UNIX domain socket. */ uint64_t argc64 = (uint64_t)argc; ssize_t bytes_sent = send(sock, &argc64, sizeof(argc64), 0); |