Blob


1 /*
2 * Copyright (c) 2019 Ori Bernstein <ori@openbsd.org>
3 * Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
18 #include <sys/types.h>
19 #include <sys/queue.h>
20 #include <sys/uio.h>
21 #include <sys/time.h>
22 #include <sys/stat.h>
24 #include <stdint.h>
25 #include <errno.h>
26 #include <imsg.h>
27 #include <limits.h>
28 #include <poll.h>
29 #include <signal.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <ctype.h>
34 #include <sha1.h>
35 #include <sha2.h>
36 #include <fcntl.h>
37 #include <unistd.h>
38 #include <zlib.h>
39 #include <err.h>
41 #include "got_error.h"
42 #include "got_object.h"
43 #include "got_path.h"
44 #include "got_version.h"
45 #include "got_fetch.h"
46 #include "got_reference.h"
48 #include "got_lib_hash.h"
49 #include "got_lib_delta.h"
50 #include "got_lib_object.h"
51 #include "got_lib_object_parse.h"
52 #include "got_lib_privsep.h"
53 #include "got_lib_pack.h"
54 #include "got_lib_pkt.h"
55 #include "got_lib_gitproto.h"
56 #include "got_lib_ratelimit.h"
57 #include "got_lib_poll.h"
59 #ifndef nitems
60 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
61 #endif
63 struct got_object *indexed;
64 static int chattygot;
66 static const struct got_capability got_capabilities[] = {
67 { GOT_CAPA_AGENT, "got/" GOT_VERSION_STR },
68 { GOT_CAPA_OFS_DELTA, NULL },
69 #if 0
70 { GOT_CAPA_SIDE_BAND_64K, NULL },
71 #endif
72 { GOT_CAPA_REPORT_STATUS, NULL },
73 { GOT_CAPA_DELETE_REFS, NULL },
74 };
76 static const struct got_error *
77 send_upload_progress(struct imsgbuf *ibuf, off_t bytes,
78 struct got_ratelimit *rl)
79 {
80 const struct got_error *err = NULL;
81 int elapsed = 0;
83 if (rl) {
84 err = got_ratelimit_check(&elapsed, rl);
85 if (err || !elapsed)
86 return err;
87 }
89 if (imsg_compose(ibuf, GOT_IMSG_SEND_UPLOAD_PROGRESS, 0, 0, -1,
90 &bytes, sizeof(bytes)) == -1)
91 return got_error_from_errno(
92 "imsg_compose SEND_UPLOAD_PROGRESS");
94 return got_privsep_flush_imsg(ibuf);
95 }
97 static const struct got_error *
98 send_pack_request(struct imsgbuf *ibuf)
99 {
100 if (imsg_compose(ibuf, GOT_IMSG_SEND_PACK_REQUEST, 0, 0, -1,
101 NULL, 0) == -1)
102 return got_error_from_errno("imsg_compose SEND_PACK_REQUEST");
103 return got_privsep_flush_imsg(ibuf);
106 static const struct got_error *
107 send_done(struct imsgbuf *ibuf)
109 if (imsg_compose(ibuf, GOT_IMSG_SEND_DONE, 0, 0, -1, NULL, 0) == -1)
110 return got_error_from_errno("imsg_compose SEND_DONE");
111 return got_privsep_flush_imsg(ibuf);
114 static const struct got_error *
115 recv_packfd(int *packfd, struct imsgbuf *ibuf)
117 const struct got_error *err;
118 struct imsg imsg;
120 *packfd = -1;
122 err = got_privsep_recv_imsg(&imsg, ibuf, 0);
123 if (err)
124 return err;
126 if (imsg.hdr.type == GOT_IMSG_STOP) {
127 err = got_error(GOT_ERR_CANCELLED);
128 goto done;
131 if (imsg.hdr.type != GOT_IMSG_SEND_PACKFD) {
132 err = got_error(GOT_ERR_PRIVSEP_MSG);
133 goto done;
136 if (imsg.hdr.len - IMSG_HEADER_SIZE != 0) {
137 err = got_error(GOT_ERR_PRIVSEP_LEN);
138 goto done;
141 *packfd = imsg_get_fd(&imsg);
142 done:
143 imsg_free(&imsg);
144 return err;
147 static const struct got_error *
148 send_pack_file(int sendfd, int packfd, struct imsgbuf *ibuf)
150 const struct got_error *err;
151 unsigned char buf[8192];
152 ssize_t r;
153 off_t wtotal = 0;
154 struct got_ratelimit rl;
156 if (lseek(packfd, 0L, SEEK_SET) == -1)
157 return got_error_from_errno("lseek");
159 got_ratelimit_init(&rl, 0, 500);
161 for (;;) {
162 r = read(packfd, buf, sizeof(buf));
163 if (r == -1)
164 return got_error_from_errno("read");
165 if (r == 0)
166 break;
167 err = got_poll_write_full(sendfd, buf, r);
168 if (err)
169 return NULL;
170 wtotal += r;
171 err = send_upload_progress(ibuf, wtotal, &rl);
172 if (err)
173 return err;
176 return send_upload_progress(ibuf, wtotal, NULL);
179 static const struct got_error *
180 send_error(const char *buf, size_t len)
182 static char msg[1024];
183 size_t i;
185 for (i = 0; i < len && i < sizeof(msg) - 1; i++) {
186 if (!isprint((unsigned char)buf[i]))
187 return got_error_msg(GOT_ERR_BAD_PACKET,
188 "non-printable error message received from server");
189 msg[i] = buf[i];
191 msg[i] = '\0';
192 return got_error_msg(GOT_ERR_SEND_FAILED, msg);
195 static const struct got_error *
196 send_their_ref(struct imsgbuf *ibuf, struct got_object_id *refid,
197 const char *refname)
199 struct ibuf *wbuf;
200 size_t len, reflen = strlen(refname);
202 len = sizeof(struct got_imsg_send_remote_ref) + reflen;
203 if (len >= MAX_IMSGSIZE - IMSG_HEADER_SIZE)
204 return got_error(GOT_ERR_NO_SPACE);
206 wbuf = imsg_create(ibuf, GOT_IMSG_SEND_REMOTE_REF, 0, 0, len);
207 if (wbuf == NULL)
208 return got_error_from_errno("imsg_create SEND_REMOTE_REF");
210 /* Keep in sync with struct got_imsg_send_remote_ref definition! */
211 if (imsg_add(wbuf, refid, sizeof(*refid)) == -1)
212 return got_error_from_errno("imsg_add SEND_REMOTE_REF");
213 if (imsg_add(wbuf, &reflen, sizeof(reflen)) == -1)
214 return got_error_from_errno("imsg_add SEND_REMOTE_REF");
215 if (imsg_add(wbuf, refname, reflen) == -1)
216 return got_error_from_errno("imsg_add SEND_REMOTE_REF");
218 imsg_close(ibuf, wbuf);
219 return got_privsep_flush_imsg(ibuf);
222 static const struct got_error *
223 send_ref_status(struct imsgbuf *ibuf, const char *refname, int success,
224 struct got_pathlist_head *refs, struct got_pathlist_head *delete_refs)
226 struct ibuf *wbuf;
227 size_t i, len, reflen, errmsglen = 0;
228 struct got_pathlist_entry *pe;
229 int ref_valid = 0;
230 char *eol, *sp;
231 const char *errmsg = "";
233 eol = strchr(refname, '\n');
234 if (eol == NULL) {
235 return got_error_msg(GOT_ERR_BAD_PACKET,
236 "unexpected message from server");
238 *eol = '\0';
240 sp = strchr(refname, ' ');
241 if (sp != NULL) {
242 *sp++ = '\0';
243 errmsg = sp;
244 errmsglen = strlen(errmsg);
246 for (i = 0; i < errmsglen; ++i) {
247 if (!isprint((unsigned char)errmsg[i])) {
248 return got_error_msg(GOT_ERR_BAD_PACKET,
249 "non-printable error message received "
250 "from the server");
255 reflen = strlen(refname);
256 if (!got_ref_name_is_valid(refname)) {
257 return got_error_msg(GOT_ERR_BAD_PACKET,
258 "unexpected message from server");
261 TAILQ_FOREACH(pe, refs, entry) {
262 if (strcmp(refname, pe->path) == 0) {
263 ref_valid = 1;
264 break;
267 if (!ref_valid) {
268 TAILQ_FOREACH(pe, delete_refs, entry) {
269 if (strcmp(refname, pe->path) == 0) {
270 ref_valid = 1;
271 break;
275 if (!ref_valid) {
276 return got_error_msg(GOT_ERR_BAD_PACKET,
277 "unexpected message from server");
280 len = sizeof(struct got_imsg_send_ref_status) + reflen + errmsglen;
281 if (len >= MAX_IMSGSIZE - IMSG_HEADER_SIZE)
282 return got_error(GOT_ERR_NO_SPACE);
284 wbuf = imsg_create(ibuf, GOT_IMSG_SEND_REF_STATUS,
285 0, 0, len);
286 if (wbuf == NULL)
287 return got_error_from_errno("imsg_create SEND_REF_STATUS");
289 /* Keep in sync with struct got_imsg_send_ref_status definition! */
290 if (imsg_add(wbuf, &success, sizeof(success)) == -1)
291 return got_error_from_errno("imsg_add SEND_REF_STATUS");
292 if (imsg_add(wbuf, &reflen, sizeof(reflen)) == -1)
293 return got_error_from_errno("imsg_add SEND_REF_STATUS");
294 if (imsg_add(wbuf, &errmsglen, sizeof(errmsglen)) == -1)
295 return got_error_from_errno("imsg_add SEND_REF_STATUS");
296 if (imsg_add(wbuf, refname, reflen) == -1)
297 return got_error_from_errno("imsg_add SEND_REF_STATUS");
298 if (imsg_add(wbuf, errmsg, errmsglen) == -1)
299 return got_error_from_errno("imsg_add SEND_REF_STATUS");
301 imsg_close(ibuf, wbuf);
302 return got_privsep_flush_imsg(ibuf);
305 static const struct got_error *
306 describe_refchange(int *n, int *sent_my_capabilites,
307 const char *my_capabilities, char *buf, size_t bufsize,
308 const char *refname, const char *old_hashstr, const char *new_hashstr)
310 *n = snprintf(buf, bufsize, "%s %s %s",
311 old_hashstr, new_hashstr, refname);
312 if (*n < 0 || (size_t)*n >= bufsize)
313 return got_error(GOT_ERR_NO_SPACE);
315 /*
316 * We must announce our capabilities along with the first
317 * reference. Unfortunately, the protocol requires an embedded
318 * NUL as a separator between reference name and capabilities,
319 * which we have to deal with here.
320 * It also requires a linefeed for terminating packet data.
321 */
322 if (!*sent_my_capabilites && my_capabilities != NULL) {
323 int m;
324 if (*n >= bufsize - 1)
325 return got_error(GOT_ERR_NO_SPACE);
326 m = snprintf(buf + *n + 1, /* offset after '\0' */
327 bufsize - (*n + 1), "%s\n", my_capabilities);
328 if (m < 0 || *n + m >= bufsize)
329 return got_error(GOT_ERR_NO_SPACE);
330 *n += m;
331 *sent_my_capabilites = 1;
332 } else {
333 *n = strlcat(buf, "\n", bufsize);
334 if (*n >= bufsize)
335 return got_error(GOT_ERR_NO_SPACE);
338 return NULL;
341 static const struct got_error *
342 send_pack(int fd, struct got_pathlist_head *refs,
343 struct got_pathlist_head *delete_refs, struct imsgbuf *ibuf)
345 const struct got_error *err = NULL;
346 char buf[GOT_PKT_MAX];
347 const unsigned char zero_id[SHA1_DIGEST_LENGTH] = { 0 };
348 char old_hashstr[SHA1_DIGEST_STRING_LENGTH];
349 char new_hashstr[SHA1_DIGEST_STRING_LENGTH];
350 struct got_pathlist_head their_refs;
351 int is_firstpkt = 1;
352 int n, nsent = 0;
353 int packfd = -1;
354 char *id_str = NULL, *refname = NULL;
355 struct got_object_id *id = NULL;
356 char *server_capabilities = NULL, *my_capabilities = NULL;
357 struct got_pathlist_entry *pe;
358 int sent_my_capabilites = 0;
360 TAILQ_INIT(&their_refs);
362 if (TAILQ_EMPTY(refs) && TAILQ_EMPTY(delete_refs))
363 return got_error(GOT_ERR_SEND_EMPTY);
365 while (1) {
366 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot,
367 INFTIM);
368 if (err)
369 goto done;
370 if (n == 0)
371 break;
372 if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
373 err = send_error(&buf[4], n - 4);
374 goto done;
376 free(id_str);
377 free(refname);
378 err = got_gitproto_parse_refline(&id_str, &refname,
379 &server_capabilities, buf, n);
380 if (err)
381 goto done;
382 if (is_firstpkt) {
383 if (server_capabilities == NULL) {
384 server_capabilities = strdup("");
385 if (server_capabilities == NULL) {
386 err = got_error_from_errno("strdup");
387 goto done;
390 if (chattygot && server_capabilities[0] != '\0')
391 fprintf(stderr, "%s: server capabilities: %s\n",
392 getprogname(), server_capabilities);
393 err = got_gitproto_match_capabilities(&my_capabilities,
394 NULL, server_capabilities, got_capabilities,
395 nitems(got_capabilities));
396 if (err)
397 goto done;
398 if (chattygot)
399 fprintf(stderr, "%s: my capabilities:%s\n",
400 getprogname(),
401 my_capabilities ? my_capabilities : "");
402 is_firstpkt = 0;
404 if (strstr(refname, "^{}")) {
405 if (chattygot) {
406 fprintf(stderr, "%s: ignoring %s\n",
407 getprogname(), refname);
409 continue;
412 id = malloc(sizeof(*id));
413 if (id == NULL) {
414 err = got_error_from_errno("malloc");
415 goto done;
417 if (!got_parse_object_id(id, id_str, GOT_HASH_SHA1)) {
418 err = got_error(GOT_ERR_BAD_OBJ_ID_STR);
419 goto done;
421 err = send_their_ref(ibuf, id, refname);
422 if (err)
423 goto done;
425 err = got_pathlist_append(&their_refs, refname, id);
426 if (err)
427 goto done;
429 if (chattygot)
430 fprintf(stderr, "%s: remote has %s %s\n",
431 getprogname(), refname, id_str);
432 free(id_str);
433 id_str = NULL;
434 refname = NULL; /* do not free; owned by their_refs */
435 id = NULL; /* do not free; owned by their_refs */
438 if (!TAILQ_EMPTY(delete_refs)) {
439 if (my_capabilities == NULL ||
440 strstr(my_capabilities, GOT_CAPA_DELETE_REFS) == NULL) {
441 err = got_error(GOT_ERR_CAPA_DELETE_REFS);
442 goto done;
446 TAILQ_FOREACH(pe, delete_refs, entry) {
447 const char *refname = pe->path;
448 struct got_pathlist_entry *their_pe;
449 struct got_object_id *their_id = NULL;
451 TAILQ_FOREACH(their_pe, &their_refs, entry) {
452 const char *their_refname = their_pe->path;
453 if (got_path_cmp(refname, their_refname,
454 strlen(refname), strlen(their_refname)) == 0) {
455 their_id = their_pe->data;
456 break;
459 if (their_id == NULL) {
460 err = got_error_fmt(GOT_ERR_NOT_REF,
461 "%s does not exist in remote repository",
462 refname);
463 goto done;
466 got_sha1_digest_to_str(their_id->sha1, old_hashstr,
467 sizeof(old_hashstr));
468 got_sha1_digest_to_str(zero_id, new_hashstr,
469 sizeof(new_hashstr));
470 err = describe_refchange(&n, &sent_my_capabilites,
471 my_capabilities, buf, sizeof(buf), refname,
472 old_hashstr, new_hashstr);
473 if (err)
474 goto done;
475 err = got_pkt_writepkt(fd, buf, n, chattygot);
476 if (err)
477 goto done;
478 if (chattygot) {
479 fprintf(stderr, "%s: deleting %s %s\n",
480 getprogname(), refname, old_hashstr);
482 nsent++;
485 TAILQ_FOREACH(pe, refs, entry) {
486 const char *refname = pe->path;
487 struct got_object_id *id = pe->data;
488 struct got_object_id *their_id = NULL;
489 struct got_pathlist_entry *their_pe;
491 TAILQ_FOREACH(their_pe, &their_refs, entry) {
492 const char *their_refname = their_pe->path;
493 if (got_path_cmp(refname, their_refname,
494 strlen(refname), strlen(their_refname)) == 0) {
495 their_id = their_pe->data;
496 break;
499 if (their_id) {
500 if (got_object_id_cmp(id, their_id) == 0) {
501 if (chattygot) {
502 fprintf(stderr,
503 "%s: no change for %s\n",
504 getprogname(), refname);
506 continue;
508 got_sha1_digest_to_str(their_id->sha1, old_hashstr,
509 sizeof(old_hashstr));
510 } else {
511 got_sha1_digest_to_str(zero_id, old_hashstr,
512 sizeof(old_hashstr));
514 got_sha1_digest_to_str(id->sha1, new_hashstr,
515 sizeof(new_hashstr));
516 err = describe_refchange(&n, &sent_my_capabilites,
517 my_capabilities, buf, sizeof(buf), refname,
518 old_hashstr, new_hashstr);
519 if (err)
520 goto done;
521 err = got_pkt_writepkt(fd, buf, n, chattygot);
522 if (err)
523 goto done;
524 if (chattygot) {
525 if (their_id) {
526 fprintf(stderr, "%s: updating %s %s -> %s\n",
527 getprogname(), refname, old_hashstr,
528 new_hashstr);
529 } else {
530 fprintf(stderr, "%s: creating %s %s\n",
531 getprogname(), refname, new_hashstr);
534 nsent++;
536 err = got_pkt_flushpkt(fd, chattygot);
537 if (err)
538 goto done;
540 err = send_pack_request(ibuf);
541 if (err)
542 goto done;
544 err = recv_packfd(&packfd, ibuf);
545 if (err)
546 goto done;
548 if (packfd != -1) {
549 err = send_pack_file(fd, packfd, ibuf);
550 if (err)
551 goto done;
554 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot, INFTIM);
555 if (err)
556 goto done;
557 if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
558 err = send_error(&buf[4], n - 4);
559 goto done;
560 } else if (n < 10 || strncmp(buf, "unpack ok\n", 10) != 0) {
561 err = got_error_msg(GOT_ERR_BAD_PACKET,
562 "unexpected message from server");
563 goto done;
566 while (nsent > 0) {
567 err = got_pkt_readpkt(&n, fd, buf, sizeof(buf), chattygot,
568 INFTIM);
569 if (err)
570 goto done;
571 if (n < 3) {
572 err = got_error_msg(GOT_ERR_BAD_PACKET,
573 "unexpected message from server");
574 goto done;
575 } else if (n >= 4 && strncmp(buf, "ERR ", 4) == 0) {
576 err = send_error(&buf[4], n - 4);
577 goto done;
578 } else if (strncmp(buf, "ok ", 3) == 0) {
579 err = send_ref_status(ibuf, buf + 3, 1,
580 refs, delete_refs);
581 if (err)
582 goto done;
583 } else if (strncmp(buf, "ng ", 3) == 0) {
584 err = send_ref_status(ibuf, buf + 3, 0,
585 refs, delete_refs);
586 if (err)
587 goto done;
588 } else {
589 err = got_error_msg(GOT_ERR_BAD_PACKET,
590 "unexpected message from server");
591 goto done;
593 nsent--;
596 err = send_done(ibuf);
597 done:
598 got_pathlist_free(&their_refs, GOT_PATHLIST_FREE_ALL);
599 free(id_str);
600 free(id);
601 free(refname);
602 free(server_capabilities);
603 return err;
606 int
607 main(int argc, char **argv)
609 const struct got_error *err = NULL;
610 int sendfd = -1;
611 struct imsgbuf ibuf;
612 struct imsg imsg;
613 struct got_pathlist_head refs;
614 struct got_pathlist_head delete_refs;
615 struct got_imsg_send_request send_req;
616 struct got_imsg_send_ref href;
617 size_t datalen, i;
618 #if 0
619 static int attached;
620 while (!attached)
621 sleep (1);
622 #endif
624 TAILQ_INIT(&refs);
625 TAILQ_INIT(&delete_refs);
627 imsg_init(&ibuf, GOT_IMSG_FD_CHILD);
628 #ifndef PROFILE
629 /* revoke access to most system calls */
630 if (pledge("stdio recvfd", NULL) == -1) {
631 err = got_error_from_errno("pledge");
632 got_privsep_send_error(&ibuf, err);
633 return 1;
635 #endif
636 if ((err = got_privsep_recv_imsg(&imsg, &ibuf, 0)) != 0) {
637 if (err->code == GOT_ERR_PRIVSEP_PIPE)
638 err = NULL;
639 goto done;
641 if (imsg.hdr.type == GOT_IMSG_STOP)
642 goto done;
643 if (imsg.hdr.type != GOT_IMSG_SEND_REQUEST) {
644 err = got_error(GOT_ERR_PRIVSEP_MSG);
645 goto done;
647 datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
648 if (datalen < sizeof(send_req)) {
649 err = got_error(GOT_ERR_PRIVSEP_LEN);
650 goto done;
652 memcpy(&send_req, imsg.data, sizeof(send_req));
653 sendfd = imsg_get_fd(&imsg);
654 imsg_free(&imsg);
656 if (send_req.verbosity > 0)
657 chattygot += send_req.verbosity;
659 for (i = 0; i < send_req.nrefs; i++) {
660 struct got_object_id *id;
661 char *refname;
663 if ((err = got_privsep_recv_imsg(&imsg, &ibuf, 0)) != 0) {
664 if (err->code == GOT_ERR_PRIVSEP_PIPE)
665 err = NULL;
666 goto done;
668 if (imsg.hdr.type == GOT_IMSG_STOP)
669 goto done;
670 if (imsg.hdr.type != GOT_IMSG_SEND_REF) {
671 err = got_error(GOT_ERR_PRIVSEP_MSG);
672 goto done;
674 datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
675 if (datalen < sizeof(href)) {
676 err = got_error(GOT_ERR_PRIVSEP_LEN);
677 goto done;
679 memcpy(&href, imsg.data, sizeof(href));
680 if (datalen - sizeof(href) < href.name_len) {
681 err = got_error(GOT_ERR_PRIVSEP_LEN);
682 goto done;
684 refname = malloc(href.name_len + 1);
685 if (refname == NULL) {
686 err = got_error_from_errno("malloc");
687 goto done;
689 memcpy(refname, imsg.data + sizeof(href), href.name_len);
690 refname[href.name_len] = '\0';
692 /*
693 * Prevent sending of references that won't make any
694 * sense outside the local repository's context.
695 */
696 if (strncmp(refname, "refs/got/", 9) == 0 ||
697 strncmp(refname, "refs/remotes/", 13) == 0) {
698 err = got_error_fmt(GOT_ERR_SEND_BAD_REF,
699 "%s", refname);
700 goto done;
703 id = malloc(sizeof(*id));
704 if (id == NULL) {
705 free(refname);
706 err = got_error_from_errno("malloc");
707 goto done;
709 memcpy(id, &href.id, sizeof(*id));
710 if (href.delete)
711 err = got_pathlist_append(&delete_refs, refname, id);
712 else
713 err = got_pathlist_append(&refs, refname, id);
714 if (err) {
715 free(refname);
716 free(id);
717 goto done;
720 imsg_free(&imsg);
723 err = send_pack(sendfd, &refs, &delete_refs, &ibuf);
724 done:
725 got_pathlist_free(&refs, GOT_PATHLIST_FREE_ALL);
726 got_pathlist_free(&delete_refs, GOT_PATHLIST_FREE_ALL);
727 if (sendfd != -1 && close(sendfd) == -1 && err == NULL)
728 err = got_error_from_errno("close");
729 if (err != NULL && err->code != GOT_ERR_CANCELLED) {
730 fprintf(stderr, "%s: %s\n", getprogname(), err->msg);
731 got_privsep_send_error(&ibuf, err);
734 exit(0);