send the 'host' parameter to support git-daemon's virtual hosting
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
diff --git a/lib/fetch.c b/lib/fetch.c
index b4b3247..83435ad 100644
--- a/lib/fetch.c
+++ b/lib/fetch.c
@@ -178,7 +178,7 @@ dial_git(int *fetchfd, char *host, char *port, char *path, char *direction)
const struct got_error *err = NULL;
struct addrinfo hints, *servinfo, *p;
char *cmd = NULL, *pkt = NULL;
- int fd = -1, l, r, eaicode;
+ int fd = -1, totlen, r, eaicode;
*fetchfd = -1;
@@ -201,17 +201,29 @@ dial_git(int *fetchfd, char *host, char *port, char *path, char *direction)
if (p == NULL)
goto done;
- if ((l = asprintf(&cmd, "git-%s-pack %s\n", direction, path)) == -1) {
+ if (asprintf(&cmd, "git-%s-pack %s", direction, path) == -1) {
err = got_error_from_errno("asprintf");
goto done;
}
- if ((l = asprintf(&pkt, "%04x%s", l + 4, cmd)) == -1) {
+ totlen = 4 + strlen(cmd) + 1 + strlen("host=") + strlen(host) + 1;
+ if (asprintf(&pkt, "%04x%s", totlen, cmd) == -1) {
err = got_error_from_errno("asprintf");
goto done;
}
- r = write(fd, pkt, l);
- if (r == -1)
+ r = write(fd, pkt, strlen(pkt) + 1);
+ if (r == -1) {
err = got_error_from_errno("write");
+ goto done;
+ }
+ if (asprintf(&pkt, "host=%s", host) == -1) {
+ err = got_error_from_errno("asprintf");
+ goto done;
+ }
+ r = write(fd, pkt, strlen(pkt) + 1);
+ if (r == -1) {
+ err = got_error_from_errno("write");
+ goto done;
+ }
done:
free(cmd);
free(pkt);