2 a440fac0 2018-09-06 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
4 a440fac0 2018-09-06 stsp * Permission to use, copy, modify, and distribute this software for any
5 a440fac0 2018-09-06 stsp * purpose with or without fee is hereby granted, provided that the above
6 a440fac0 2018-09-06 stsp * copyright notice and this permission notice appear in all copies.
8 a440fac0 2018-09-06 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 a440fac0 2018-09-06 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 a440fac0 2018-09-06 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 a440fac0 2018-09-06 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 a440fac0 2018-09-06 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 a440fac0 2018-09-06 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 a440fac0 2018-09-06 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 a440fac0 2018-09-06 stsp #include <sys/types.h>
18 a440fac0 2018-09-06 stsp #include <sys/stat.h>
19 a440fac0 2018-09-06 stsp #include <sys/queue.h>
20 a440fac0 2018-09-06 stsp #include <sys/uio.h>
21 a440fac0 2018-09-06 stsp #include <sys/socket.h>
22 876c234b 2018-09-10 stsp #include <sys/syslimits.h>
23 a440fac0 2018-09-06 stsp #include <sys/wait.h>
25 a440fac0 2018-09-06 stsp #include <errno.h>
26 a440fac0 2018-09-06 stsp #include <stdio.h>
27 a440fac0 2018-09-06 stsp #include <stdlib.h>
28 a440fac0 2018-09-06 stsp #include <string.h>
29 a440fac0 2018-09-06 stsp #include <stdint.h>
30 a440fac0 2018-09-06 stsp #include <sha1.h>
31 a440fac0 2018-09-06 stsp #include <zlib.h>
32 a440fac0 2018-09-06 stsp #include <ctype.h>
33 a440fac0 2018-09-06 stsp #include <limits.h>
34 a440fac0 2018-09-06 stsp #include <imsg.h>
35 a440fac0 2018-09-06 stsp #include <time.h>
36 ad242220 2018-09-08 stsp #include <unistd.h>
38 a440fac0 2018-09-06 stsp #include "got_error.h"
39 a440fac0 2018-09-06 stsp #include "got_object.h"
40 a440fac0 2018-09-06 stsp #include "got_repository.h"
41 a440fac0 2018-09-06 stsp #include "got_opentemp.h"
43 a440fac0 2018-09-06 stsp #include "got_lib_sha1.h"
44 a440fac0 2018-09-06 stsp #include "got_lib_delta.h"
45 ad242220 2018-09-08 stsp #include "got_lib_privsep.h"
46 a440fac0 2018-09-06 stsp #include "got_lib_pack.h"
47 a440fac0 2018-09-06 stsp #include "got_lib_inflate.h"
48 a440fac0 2018-09-06 stsp #include "got_lib_object.h"
49 6bef87be 2018-09-11 stsp #include "got_lib_object_cache.h"
50 ad242220 2018-09-08 stsp #include "got_lib_repository.h"
52 a440fac0 2018-09-06 stsp #ifndef nitems
53 a440fac0 2018-09-06 stsp #define nitems(_a) (sizeof(_a) / sizeof((_a)[0]))
56 a440fac0 2018-09-06 stsp #define GOT_OBJ_TAG_COMMIT "commit"
57 a440fac0 2018-09-06 stsp #define GOT_OBJ_TAG_TREE "tree"
58 a440fac0 2018-09-06 stsp #define GOT_OBJ_TAG_BLOB "blob"
60 a440fac0 2018-09-06 stsp #define GOT_COMMIT_TAG_TREE "tree "
61 a440fac0 2018-09-06 stsp #define GOT_COMMIT_TAG_PARENT "parent "
62 a440fac0 2018-09-06 stsp #define GOT_COMMIT_TAG_AUTHOR "author "
63 a440fac0 2018-09-06 stsp #define GOT_COMMIT_TAG_COMMITTER "committer "
65 2ff12563 2018-09-15 stsp const struct got_error *
66 2ff12563 2018-09-15 stsp got_object_id_str(char **outbuf, struct got_object_id *id)
68 2ff12563 2018-09-15 stsp static const size_t len = SHA1_DIGEST_STRING_LENGTH;
70 2ff12563 2018-09-15 stsp *outbuf = malloc(len);
71 2ff12563 2018-09-15 stsp if (*outbuf == NULL)
72 2ff12563 2018-09-15 stsp return got_error_from_errno();
74 2ff12563 2018-09-15 stsp if (got_sha1_digest_to_str(id->sha1, *outbuf, len) == NULL) {
75 2ff12563 2018-09-15 stsp free(*outbuf);
76 2ff12563 2018-09-15 stsp *outbuf = NULL;
77 2ff12563 2018-09-15 stsp return got_error(GOT_ERR_BAD_OBJ_ID_STR);
80 2ff12563 2018-09-15 stsp return NULL;
84 03fa71c8 2018-09-06 stsp got_object_close(struct got_object *obj)
86 03fa71c8 2018-09-06 stsp if (obj->refcnt > 0) {
87 03fa71c8 2018-09-06 stsp obj->refcnt--;
88 03fa71c8 2018-09-06 stsp if (obj->refcnt > 0)
92 03fa71c8 2018-09-06 stsp if (obj->flags & GOT_OBJ_FLAG_DELTIFIED) {
93 03fa71c8 2018-09-06 stsp struct got_delta *delta;
94 03fa71c8 2018-09-06 stsp while (!SIMPLEQ_EMPTY(&obj->deltas.entries)) {
95 03fa71c8 2018-09-06 stsp delta = SIMPLEQ_FIRST(&obj->deltas.entries);
96 03fa71c8 2018-09-06 stsp SIMPLEQ_REMOVE_HEAD(&obj->deltas.entries, entry);
97 03fa71c8 2018-09-06 stsp got_delta_close(delta);
100 03fa71c8 2018-09-06 stsp if (obj->flags & GOT_OBJ_FLAG_PACKED)
101 03fa71c8 2018-09-06 stsp free(obj->path_packfile);
106 03fa71c8 2018-09-06 stsp got_object_qid_free(struct got_object_qid *qid)
108 03fa71c8 2018-09-06 stsp free(qid->id);
112 a440fac0 2018-09-06 stsp static const struct got_error *
113 ad242220 2018-09-08 stsp request_object(struct got_object **obj, struct got_repository *repo, int fd)
115 ad242220 2018-09-08 stsp const struct got_error *err = NULL;
116 3516b818 2018-09-08 stsp struct imsgbuf *ibuf;
118 3516b818 2018-09-08 stsp ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].ibuf;
120 3516b818 2018-09-08 stsp err = got_privsep_send_obj_req(ibuf, fd, NULL);
122 3516b818 2018-09-08 stsp return err;
124 3516b818 2018-09-08 stsp return got_privsep_recv_obj(obj, ibuf);
127 a440fac0 2018-09-06 stsp static void
128 3cab8b4d 2018-09-08 stsp exec_privsep_child(int imsg_fds[2], const char *path, const char *repo_path)
130 a440fac0 2018-09-06 stsp close(imsg_fds[0]);
132 ad242220 2018-09-08 stsp if (dup2(imsg_fds[1], GOT_IMSG_FD_CHILD) == -1) {
133 ad242220 2018-09-08 stsp fprintf(stderr, "%s: %s\n", getprogname(),
134 ad242220 2018-09-08 stsp strerror(errno));
137 ad242220 2018-09-08 stsp if (closefrom(GOT_IMSG_FD_CHILD + 1) == -1) {
138 ad242220 2018-09-08 stsp fprintf(stderr, "%s: %s\n", getprogname(),
139 ad242220 2018-09-08 stsp strerror(errno));
143 3cab8b4d 2018-09-08 stsp if (execl(path, path, repo_path, (char *)NULL) == -1) {
144 ad242220 2018-09-08 stsp fprintf(stderr, "%s: %s: %s\n", getprogname(), path,
145 ad242220 2018-09-08 stsp strerror(errno));
150 a440fac0 2018-09-06 stsp const struct got_error *
151 ad242220 2018-09-08 stsp got_object_read_header_privsep(struct got_object **obj,
152 ad242220 2018-09-08 stsp struct got_repository *repo, int obj_fd)
154 a440fac0 2018-09-06 stsp int imsg_fds[2];
156 3516b818 2018-09-08 stsp struct imsgbuf *ibuf;
158 ad242220 2018-09-08 stsp if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].imsg_fd != -1)
159 ad242220 2018-09-08 stsp return request_object(obj, repo, obj_fd);
161 3516b818 2018-09-08 stsp ibuf = calloc(1, sizeof(*ibuf));
162 3516b818 2018-09-08 stsp if (ibuf == NULL)
163 3516b818 2018-09-08 stsp return got_error_from_errno();
165 a440fac0 2018-09-06 stsp if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1)
166 a440fac0 2018-09-06 stsp return got_error_from_errno();
168 a440fac0 2018-09-06 stsp pid = fork();
169 a440fac0 2018-09-06 stsp if (pid == -1)
170 a440fac0 2018-09-06 stsp return got_error_from_errno();
171 a440fac0 2018-09-06 stsp else if (pid == 0) {
172 3cab8b4d 2018-09-08 stsp exec_privsep_child(imsg_fds, GOT_PATH_PROG_READ_OBJECT,
173 3cab8b4d 2018-09-08 stsp repo->path);
174 a440fac0 2018-09-06 stsp /* not reached */
177 a440fac0 2018-09-06 stsp close(imsg_fds[1]);
178 ad242220 2018-09-08 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].imsg_fd =
179 ad242220 2018-09-08 stsp imsg_fds[0];
180 ad242220 2018-09-08 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].pid = pid;
181 3516b818 2018-09-08 stsp imsg_init(ibuf, imsg_fds[0]);
182 3516b818 2018-09-08 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].ibuf = ibuf;
184 ad242220 2018-09-08 stsp return request_object(obj, repo, obj_fd);
187 876c234b 2018-09-10 stsp static const struct got_error *
188 876c234b 2018-09-10 stsp request_packed_object(struct got_object **obj, struct got_pack *pack, int idx,
189 876c234b 2018-09-10 stsp struct got_object_id *id)
191 876c234b 2018-09-10 stsp const struct got_error *err = NULL;
192 876c234b 2018-09-10 stsp struct imsgbuf *ibuf = pack->privsep_child->ibuf;
194 876c234b 2018-09-10 stsp err = got_privsep_send_packed_obj_req(ibuf, idx);
196 876c234b 2018-09-10 stsp return err;
198 876c234b 2018-09-10 stsp err = got_privsep_recv_obj(obj, ibuf);
200 876c234b 2018-09-10 stsp return err;
202 876c234b 2018-09-10 stsp (*obj)->path_packfile = strdup(pack->path_packfile);
203 876c234b 2018-09-10 stsp if ((*obj)->path_packfile == NULL) {
204 876c234b 2018-09-10 stsp err = got_error_from_errno();
205 876c234b 2018-09-10 stsp return err;
207 876c234b 2018-09-10 stsp memcpy(&(*obj)->id, id, sizeof((*obj)->id));
209 876c234b 2018-09-10 stsp return NULL;
212 876c234b 2018-09-10 stsp const struct got_error *
213 876c234b 2018-09-10 stsp got_object_packed_read_privsep(struct got_object **obj,
214 876c234b 2018-09-10 stsp struct got_repository *repo, struct got_pack *pack,
215 876c234b 2018-09-10 stsp struct got_packidx *packidx, int idx, struct got_object_id *id)
217 876c234b 2018-09-10 stsp const struct got_error *err = NULL;
218 876c234b 2018-09-10 stsp int imsg_fds[2];
220 876c234b 2018-09-10 stsp struct imsgbuf *ibuf;
222 876c234b 2018-09-10 stsp if (pack->privsep_child)
223 876c234b 2018-09-10 stsp return request_packed_object(obj, pack, idx, id);
225 876c234b 2018-09-10 stsp ibuf = calloc(1, sizeof(*ibuf));
226 876c234b 2018-09-10 stsp if (ibuf == NULL)
227 876c234b 2018-09-10 stsp return got_error_from_errno();
229 876c234b 2018-09-10 stsp pack->privsep_child = calloc(1, sizeof(*pack->privsep_child));
230 876c234b 2018-09-10 stsp if (pack->privsep_child == NULL) {
231 876c234b 2018-09-10 stsp err = got_error_from_errno();
232 876c234b 2018-09-10 stsp free(ibuf);
233 876c234b 2018-09-10 stsp return err;
236 876c234b 2018-09-10 stsp if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) {
237 876c234b 2018-09-10 stsp err = got_error_from_errno();
241 876c234b 2018-09-10 stsp pid = fork();
242 876c234b 2018-09-10 stsp if (pid == -1) {
243 876c234b 2018-09-10 stsp err = got_error_from_errno();
245 876c234b 2018-09-10 stsp } else if (pid == 0) {
246 876c234b 2018-09-10 stsp exec_privsep_child(imsg_fds, GOT_PATH_PROG_READ_PACK,
247 876c234b 2018-09-10 stsp pack->path_packfile);
248 876c234b 2018-09-10 stsp /* not reached */
251 876c234b 2018-09-10 stsp close(imsg_fds[1]);
252 876c234b 2018-09-10 stsp pack->privsep_child->imsg_fd = imsg_fds[0];
253 876c234b 2018-09-10 stsp pack->privsep_child->pid = pid;
254 876c234b 2018-09-10 stsp imsg_init(ibuf, imsg_fds[0]);
255 876c234b 2018-09-10 stsp pack->privsep_child->ibuf = ibuf;
257 876c234b 2018-09-10 stsp err = got_privsep_init_pack_child(ibuf, pack, packidx);
259 876c234b 2018-09-10 stsp const struct got_error *child_err;
260 876c234b 2018-09-10 stsp err = got_privsep_send_stop(pack->privsep_child->imsg_fd);
261 876c234b 2018-09-10 stsp child_err = got_privsep_wait_for_child(
262 876c234b 2018-09-10 stsp pack->privsep_child->pid);
263 876c234b 2018-09-10 stsp if (child_err && err == NULL)
264 876c234b 2018-09-10 stsp err = child_err;
265 876c234b 2018-09-10 stsp free(ibuf);
266 876c234b 2018-09-10 stsp free(pack->privsep_child);
267 876c234b 2018-09-10 stsp pack->privsep_child = NULL;
268 876c234b 2018-09-10 stsp return err;
273 876c234b 2018-09-10 stsp free(ibuf);
274 876c234b 2018-09-10 stsp free(pack->privsep_child);
275 876c234b 2018-09-10 stsp pack->privsep_child = NULL;
277 876c234b 2018-09-10 stsp err = request_packed_object(obj, pack, idx, id);
278 876c234b 2018-09-10 stsp return err;
281 a440fac0 2018-09-06 stsp struct got_commit_object *
282 a440fac0 2018-09-06 stsp got_object_commit_alloc_partial(void)
284 a440fac0 2018-09-06 stsp struct got_commit_object *commit;
286 a440fac0 2018-09-06 stsp commit = calloc(1, sizeof(*commit));
287 a440fac0 2018-09-06 stsp if (commit == NULL)
288 a440fac0 2018-09-06 stsp return NULL;
289 a440fac0 2018-09-06 stsp commit->tree_id = calloc(1, sizeof(*commit->tree_id));
290 a440fac0 2018-09-06 stsp if (commit->tree_id == NULL) {
291 a440fac0 2018-09-06 stsp free(commit);
292 a440fac0 2018-09-06 stsp return NULL;
295 a440fac0 2018-09-06 stsp SIMPLEQ_INIT(&commit->parent_ids);
297 a440fac0 2018-09-06 stsp return commit;
300 a440fac0 2018-09-06 stsp const struct got_error *
301 a440fac0 2018-09-06 stsp got_object_commit_add_parent(struct got_commit_object *commit,
302 a440fac0 2018-09-06 stsp const char *id_str)
304 a440fac0 2018-09-06 stsp const struct got_error *err = NULL;
305 a440fac0 2018-09-06 stsp struct got_object_qid *qid;
307 a440fac0 2018-09-06 stsp qid = malloc(sizeof(*qid));
308 a440fac0 2018-09-06 stsp if (qid == NULL)
309 a440fac0 2018-09-06 stsp return got_error_from_errno();
311 a440fac0 2018-09-06 stsp qid->id = malloc(sizeof(*qid->id));
312 a440fac0 2018-09-06 stsp if (qid->id == NULL) {
313 a440fac0 2018-09-06 stsp err = got_error_from_errno();
314 a440fac0 2018-09-06 stsp got_object_qid_free(qid);
315 a440fac0 2018-09-06 stsp return err;
318 a440fac0 2018-09-06 stsp if (!got_parse_sha1_digest(qid->id->sha1, id_str)) {
319 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
320 a440fac0 2018-09-06 stsp free(qid->id);
322 a440fac0 2018-09-06 stsp return err;
325 a440fac0 2018-09-06 stsp SIMPLEQ_INSERT_TAIL(&commit->parent_ids, qid, entry);
326 a440fac0 2018-09-06 stsp commit->nparents++;
328 a440fac0 2018-09-06 stsp return NULL;
331 a440fac0 2018-09-06 stsp static const struct got_error *
332 a440fac0 2018-09-06 stsp parse_gmtoff(time_t *gmtoff, const char *tzstr)
334 a440fac0 2018-09-06 stsp int sign = 1;
335 a440fac0 2018-09-06 stsp const char *p = tzstr;
336 a440fac0 2018-09-06 stsp time_t h, m;
338 a440fac0 2018-09-06 stsp *gmtoff = 0;
340 a440fac0 2018-09-06 stsp if (*p == '-')
342 a440fac0 2018-09-06 stsp else if (*p != '+')
343 a440fac0 2018-09-06 stsp return got_error(GOT_ERR_BAD_OBJ_DATA);
345 a440fac0 2018-09-06 stsp if (!isdigit(*p) && !isdigit(*(p + 1)))
346 a440fac0 2018-09-06 stsp return got_error(GOT_ERR_BAD_OBJ_DATA);
347 a440fac0 2018-09-06 stsp h = (((*p - '0') * 10) + (*(p + 1) - '0'));
350 a440fac0 2018-09-06 stsp if (!isdigit(*p) && !isdigit(*(p + 1)))
351 a440fac0 2018-09-06 stsp return got_error(GOT_ERR_BAD_OBJ_DATA);
352 a440fac0 2018-09-06 stsp m = ((*p - '0') * 10) + (*(p + 1) - '0');
354 a440fac0 2018-09-06 stsp *gmtoff = (h * 60 * 60 + m * 60) * sign;
355 a440fac0 2018-09-06 stsp return NULL;
358 a440fac0 2018-09-06 stsp static const struct got_error *
359 a440fac0 2018-09-06 stsp parse_commit_time(struct tm *tm, char *committer)
361 a440fac0 2018-09-06 stsp const struct got_error *err = NULL;
362 a440fac0 2018-09-06 stsp const char *errstr;
363 a440fac0 2018-09-06 stsp char *space, *tzstr;
364 a440fac0 2018-09-06 stsp time_t gmtoff;
365 a440fac0 2018-09-06 stsp time_t time;
367 a440fac0 2018-09-06 stsp /* Parse and strip off trailing timezone indicator string. */
368 a440fac0 2018-09-06 stsp space = strrchr(committer, ' ');
369 a440fac0 2018-09-06 stsp if (space == NULL)
370 a440fac0 2018-09-06 stsp return got_error(GOT_ERR_BAD_OBJ_DATA);
371 a440fac0 2018-09-06 stsp tzstr = strdup(space + 1);
372 a440fac0 2018-09-06 stsp if (tzstr == NULL)
373 a440fac0 2018-09-06 stsp return got_error_from_errno();
374 a440fac0 2018-09-06 stsp err = parse_gmtoff(&gmtoff, tzstr);
375 a440fac0 2018-09-06 stsp free(tzstr);
377 a440fac0 2018-09-06 stsp return err;
378 a440fac0 2018-09-06 stsp *space = '\0';
380 a440fac0 2018-09-06 stsp /* Timestamp is separated from committer name + email by space. */
381 a440fac0 2018-09-06 stsp space = strrchr(committer, ' ');
382 a440fac0 2018-09-06 stsp if (space == NULL)
383 a440fac0 2018-09-06 stsp return got_error(GOT_ERR_BAD_OBJ_DATA);
385 a440fac0 2018-09-06 stsp /* Timestamp parsed here is expressed in comitter's local time. */
386 a440fac0 2018-09-06 stsp time = strtonum(space + 1, 0, INT64_MAX, &errstr);
387 a440fac0 2018-09-06 stsp if (errstr)
388 a440fac0 2018-09-06 stsp return got_error(GOT_ERR_BAD_OBJ_DATA);
390 a440fac0 2018-09-06 stsp /* Express the time stamp in UTC. */
391 a440fac0 2018-09-06 stsp memset(tm, 0, sizeof(*tm));
392 a440fac0 2018-09-06 stsp time -= gmtoff;
393 a440fac0 2018-09-06 stsp if (localtime_r(&time, tm) == NULL)
394 a440fac0 2018-09-06 stsp return got_error_from_errno();
395 a440fac0 2018-09-06 stsp tm->tm_gmtoff = gmtoff;
397 a440fac0 2018-09-06 stsp /* Strip off parsed time information, leaving just author and email. */
398 a440fac0 2018-09-06 stsp *space = '\0';
400 a440fac0 2018-09-06 stsp return NULL;
404 03fa71c8 2018-09-06 stsp got_object_commit_close(struct got_commit_object *commit)
406 03fa71c8 2018-09-06 stsp struct got_object_qid *qid;
408 03fa71c8 2018-09-06 stsp if (commit->refcnt > 0) {
409 03fa71c8 2018-09-06 stsp commit->refcnt--;
410 03fa71c8 2018-09-06 stsp if (commit->refcnt > 0)
414 03fa71c8 2018-09-06 stsp while (!SIMPLEQ_EMPTY(&commit->parent_ids)) {
415 03fa71c8 2018-09-06 stsp qid = SIMPLEQ_FIRST(&commit->parent_ids);
416 03fa71c8 2018-09-06 stsp SIMPLEQ_REMOVE_HEAD(&commit->parent_ids, entry);
417 03fa71c8 2018-09-06 stsp got_object_qid_free(qid);
420 03fa71c8 2018-09-06 stsp free(commit->tree_id);
421 03fa71c8 2018-09-06 stsp free(commit->author);
422 03fa71c8 2018-09-06 stsp free(commit->committer);
423 03fa71c8 2018-09-06 stsp free(commit->logmsg);
424 03fa71c8 2018-09-06 stsp free(commit);
427 a440fac0 2018-09-06 stsp const struct got_error *
428 a440fac0 2018-09-06 stsp got_object_parse_commit(struct got_commit_object **commit, char *buf, size_t len)
430 a440fac0 2018-09-06 stsp const struct got_error *err = NULL;
431 a440fac0 2018-09-06 stsp char *s = buf;
432 a440fac0 2018-09-06 stsp size_t tlen;
433 a440fac0 2018-09-06 stsp ssize_t remain = (ssize_t)len;
435 a440fac0 2018-09-06 stsp *commit = got_object_commit_alloc_partial();
436 a440fac0 2018-09-06 stsp if (*commit == NULL)
437 a440fac0 2018-09-06 stsp return got_error_from_errno();
439 a440fac0 2018-09-06 stsp tlen = strlen(GOT_COMMIT_TAG_TREE);
440 a440fac0 2018-09-06 stsp if (strncmp(s, GOT_COMMIT_TAG_TREE, tlen) == 0) {
441 a440fac0 2018-09-06 stsp remain -= tlen;
442 a440fac0 2018-09-06 stsp if (remain < SHA1_DIGEST_STRING_LENGTH) {
443 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
447 a440fac0 2018-09-06 stsp if (!got_parse_sha1_digest((*commit)->tree_id->sha1, s)) {
448 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
451 a440fac0 2018-09-06 stsp remain -= SHA1_DIGEST_STRING_LENGTH;
452 a440fac0 2018-09-06 stsp s += SHA1_DIGEST_STRING_LENGTH;
454 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
458 a440fac0 2018-09-06 stsp tlen = strlen(GOT_COMMIT_TAG_PARENT);
459 a440fac0 2018-09-06 stsp while (strncmp(s, GOT_COMMIT_TAG_PARENT, tlen) == 0) {
460 a440fac0 2018-09-06 stsp remain -= tlen;
461 a440fac0 2018-09-06 stsp if (remain < SHA1_DIGEST_STRING_LENGTH) {
462 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
466 a440fac0 2018-09-06 stsp err = got_object_commit_add_parent(*commit, s);
470 a440fac0 2018-09-06 stsp remain -= SHA1_DIGEST_STRING_LENGTH;
471 a440fac0 2018-09-06 stsp s += SHA1_DIGEST_STRING_LENGTH;
474 a440fac0 2018-09-06 stsp tlen = strlen(GOT_COMMIT_TAG_AUTHOR);
475 a440fac0 2018-09-06 stsp if (strncmp(s, GOT_COMMIT_TAG_AUTHOR, tlen) == 0) {
477 a440fac0 2018-09-06 stsp size_t slen;
479 a440fac0 2018-09-06 stsp remain -= tlen;
480 a440fac0 2018-09-06 stsp if (remain <= 0) {
481 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
485 a440fac0 2018-09-06 stsp p = strchr(s, '\n');
486 a440fac0 2018-09-06 stsp if (p == NULL) {
487 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
491 a440fac0 2018-09-06 stsp slen = strlen(s);
492 a440fac0 2018-09-06 stsp err = parse_commit_time(&(*commit)->tm_author, s);
495 a440fac0 2018-09-06 stsp (*commit)->author = strdup(s);
496 a440fac0 2018-09-06 stsp if ((*commit)->author == NULL) {
497 a440fac0 2018-09-06 stsp err = got_error_from_errno();
500 a440fac0 2018-09-06 stsp s += slen + 1;
501 a440fac0 2018-09-06 stsp remain -= slen + 1;
504 a440fac0 2018-09-06 stsp tlen = strlen(GOT_COMMIT_TAG_COMMITTER);
505 a440fac0 2018-09-06 stsp if (strncmp(s, GOT_COMMIT_TAG_COMMITTER, tlen) == 0) {
507 a440fac0 2018-09-06 stsp size_t slen;
509 a440fac0 2018-09-06 stsp remain -= tlen;
510 a440fac0 2018-09-06 stsp if (remain <= 0) {
511 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
515 a440fac0 2018-09-06 stsp p = strchr(s, '\n');
516 a440fac0 2018-09-06 stsp if (p == NULL) {
517 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
521 a440fac0 2018-09-06 stsp slen = strlen(s);
522 a440fac0 2018-09-06 stsp err = parse_commit_time(&(*commit)->tm_committer, s);
525 a440fac0 2018-09-06 stsp (*commit)->committer = strdup(s);
526 a440fac0 2018-09-06 stsp if ((*commit)->committer == NULL) {
527 a440fac0 2018-09-06 stsp err = got_error_from_errno();
530 a440fac0 2018-09-06 stsp s += slen + 1;
531 a440fac0 2018-09-06 stsp remain -= slen + 1;
534 a440fac0 2018-09-06 stsp (*commit)->logmsg = strndup(s, remain);
535 a440fac0 2018-09-06 stsp if ((*commit)->logmsg == NULL) {
536 a440fac0 2018-09-06 stsp err = got_error_from_errno();
541 a440fac0 2018-09-06 stsp got_object_commit_close(*commit);
542 a440fac0 2018-09-06 stsp *commit = NULL;
544 a440fac0 2018-09-06 stsp return err;
548 ad242220 2018-09-08 stsp got_object_tree_entry_close(struct got_tree_entry *te)
550 a440fac0 2018-09-06 stsp free(te->id);
551 a440fac0 2018-09-06 stsp free(te->name);
556 03fa71c8 2018-09-06 stsp got_object_tree_close(struct got_tree_object *tree)
558 03fa71c8 2018-09-06 stsp struct got_tree_entry *te;
560 03fa71c8 2018-09-06 stsp if (tree->refcnt > 0) {
561 03fa71c8 2018-09-06 stsp tree->refcnt--;
562 03fa71c8 2018-09-06 stsp if (tree->refcnt > 0)
566 03fa71c8 2018-09-06 stsp while (!SIMPLEQ_EMPTY(&tree->entries.head)) {
567 03fa71c8 2018-09-06 stsp te = SIMPLEQ_FIRST(&tree->entries.head);
568 03fa71c8 2018-09-06 stsp SIMPLEQ_REMOVE_HEAD(&tree->entries.head, entry);
569 ad242220 2018-09-08 stsp got_object_tree_entry_close(te);
572 03fa71c8 2018-09-06 stsp free(tree);
575 a440fac0 2018-09-06 stsp struct got_tree_entry *
576 a440fac0 2018-09-06 stsp got_alloc_tree_entry_partial(void)
578 a440fac0 2018-09-06 stsp struct got_tree_entry *te;
580 a440fac0 2018-09-06 stsp te = calloc(1, sizeof(*te));
581 a440fac0 2018-09-06 stsp if (te == NULL)
582 a440fac0 2018-09-06 stsp return NULL;
584 a440fac0 2018-09-06 stsp te->id = calloc(1, sizeof(*te->id));
585 a440fac0 2018-09-06 stsp if (te->id == NULL) {
592 a440fac0 2018-09-06 stsp static const struct got_error *
593 a440fac0 2018-09-06 stsp parse_tree_entry(struct got_tree_entry **te, size_t *elen, char *buf,
594 a440fac0 2018-09-06 stsp size_t maxlen)
596 a440fac0 2018-09-06 stsp char *p = buf, *space;
597 a440fac0 2018-09-06 stsp const struct got_error *err = NULL;
599 a440fac0 2018-09-06 stsp *te = got_alloc_tree_entry_partial();
600 a440fac0 2018-09-06 stsp if (*te == NULL)
601 a440fac0 2018-09-06 stsp return got_error_from_errno();
603 a440fac0 2018-09-06 stsp *elen = strlen(buf) + 1;
604 a440fac0 2018-09-06 stsp if (*elen > maxlen) {
606 a440fac0 2018-09-06 stsp *te = NULL;
607 a440fac0 2018-09-06 stsp return got_error(GOT_ERR_BAD_OBJ_DATA);
610 a440fac0 2018-09-06 stsp space = strchr(buf, ' ');
611 a440fac0 2018-09-06 stsp if (space == NULL) {
612 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
614 a440fac0 2018-09-06 stsp *te = NULL;
615 a440fac0 2018-09-06 stsp return err;
617 a440fac0 2018-09-06 stsp while (*p != ' ') {
618 a440fac0 2018-09-06 stsp if (*p < '0' && *p > '7') {
619 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
622 a440fac0 2018-09-06 stsp (*te)->mode <<= 3;
623 a440fac0 2018-09-06 stsp (*te)->mode |= *p - '0';
627 a440fac0 2018-09-06 stsp (*te)->name = strdup(space + 1);
628 a440fac0 2018-09-06 stsp if (*elen > maxlen || maxlen - *elen < SHA1_DIGEST_LENGTH) {
629 a440fac0 2018-09-06 stsp err = got_error(GOT_ERR_BAD_OBJ_DATA);
632 a440fac0 2018-09-06 stsp buf += strlen(buf) + 1;
633 a440fac0 2018-09-06 stsp memcpy((*te)->id->sha1, buf, SHA1_DIGEST_LENGTH);
634 a440fac0 2018-09-06 stsp *elen += SHA1_DIGEST_LENGTH;
637 ad242220 2018-09-08 stsp got_object_tree_entry_close(*te);
638 a440fac0 2018-09-06 stsp *te = NULL;
640 a440fac0 2018-09-06 stsp return err;
643 a440fac0 2018-09-06 stsp const struct got_error *
644 a440fac0 2018-09-06 stsp got_object_parse_tree(struct got_tree_object **tree, uint8_t *buf, size_t len)
646 a440fac0 2018-09-06 stsp const struct got_error *err;
647 a440fac0 2018-09-06 stsp size_t remain = len;
649 a440fac0 2018-09-06 stsp *tree = calloc(1, sizeof(**tree));
650 a440fac0 2018-09-06 stsp if (*tree == NULL)
651 a440fac0 2018-09-06 stsp return got_error_from_errno();
653 a440fac0 2018-09-06 stsp SIMPLEQ_INIT(&(*tree)->entries.head);
655 a440fac0 2018-09-06 stsp while (remain > 0) {
656 a440fac0 2018-09-06 stsp struct got_tree_entry *te;
657 a440fac0 2018-09-06 stsp size_t elen;
659 a440fac0 2018-09-06 stsp err = parse_tree_entry(&te, &elen, buf, remain);
661 a440fac0 2018-09-06 stsp return err;
662 a440fac0 2018-09-06 stsp (*tree)->entries.nentries++;
663 a440fac0 2018-09-06 stsp SIMPLEQ_INSERT_TAIL(&(*tree)->entries.head, te, entry);
664 a440fac0 2018-09-06 stsp buf += elen;
665 a440fac0 2018-09-06 stsp remain -= elen;
668 a440fac0 2018-09-06 stsp if (remain != 0) {
669 a440fac0 2018-09-06 stsp got_object_tree_close(*tree);
670 a440fac0 2018-09-06 stsp return got_error(GOT_ERR_BAD_OBJ_DATA);
673 a440fac0 2018-09-06 stsp return NULL;
676 ad242220 2018-09-08 stsp const struct got_error *
677 ad242220 2018-09-08 stsp got_read_file_to_mem(uint8_t **outbuf, size_t *outlen, FILE *f)
679 a440fac0 2018-09-06 stsp const struct got_error *err = NULL;
680 a440fac0 2018-09-06 stsp static const size_t blocksize = 512;
681 a440fac0 2018-09-06 stsp size_t n, total, remain;
682 a440fac0 2018-09-06 stsp uint8_t *buf;
684 a440fac0 2018-09-06 stsp *outbuf = NULL;
685 a440fac0 2018-09-06 stsp *outlen = 0;
687 a440fac0 2018-09-06 stsp buf = malloc(blocksize);
688 a440fac0 2018-09-06 stsp if (buf == NULL)
689 a440fac0 2018-09-06 stsp return got_error_from_errno();
691 a440fac0 2018-09-06 stsp remain = blocksize;
693 a440fac0 2018-09-06 stsp while (1) {
694 a440fac0 2018-09-06 stsp if (remain == 0) {
695 a440fac0 2018-09-06 stsp uint8_t *newbuf;
696 a440fac0 2018-09-06 stsp newbuf = reallocarray(buf, 1, total + blocksize);
697 a440fac0 2018-09-06 stsp if (newbuf == NULL) {
698 a440fac0 2018-09-06 stsp err = got_error_from_errno();
701 a440fac0 2018-09-06 stsp buf = newbuf;
702 a440fac0 2018-09-06 stsp remain += blocksize;
704 a440fac0 2018-09-06 stsp n = fread(buf + total, 1, remain, f);
705 a440fac0 2018-09-06 stsp if (n == 0) {
706 a440fac0 2018-09-06 stsp if (ferror(f)) {
707 a440fac0 2018-09-06 stsp err = got_ferror(f, GOT_ERR_IO);
710 a440fac0 2018-09-06 stsp break; /* EOF */
712 a440fac0 2018-09-06 stsp remain -= n;
713 a440fac0 2018-09-06 stsp total += n;
717 a440fac0 2018-09-06 stsp if (err == NULL) {
718 a440fac0 2018-09-06 stsp *outbuf = buf;
719 a440fac0 2018-09-06 stsp *outlen = total;
722 a440fac0 2018-09-06 stsp return err;
725 a440fac0 2018-09-06 stsp static const struct got_error *
726 ad242220 2018-09-08 stsp request_commit(struct got_commit_object **commit, struct got_repository *repo,
727 ad242220 2018-09-08 stsp struct got_object *obj, int fd)
729 a440fac0 2018-09-06 stsp const struct got_error *err = NULL;
730 3516b818 2018-09-08 stsp struct imsgbuf *ibuf;
732 3516b818 2018-09-08 stsp ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].ibuf;
734 cfd633c2 2018-09-10 stsp err = got_privsep_send_obj_req(ibuf, fd, obj);
736 3516b818 2018-09-08 stsp return err;
738 3516b818 2018-09-08 stsp return got_privsep_recv_commit(commit, ibuf);
741 a440fac0 2018-09-06 stsp const struct got_error *
742 cfd633c2 2018-09-10 stsp got_object_read_packed_commit_privsep(struct got_commit_object **commit,
743 cfd633c2 2018-09-10 stsp struct got_object *obj, struct got_pack *pack)
745 cfd633c2 2018-09-10 stsp const struct got_error *err = NULL;
747 cfd633c2 2018-09-10 stsp err = got_privsep_send_obj_req(pack->privsep_child->ibuf, -1, obj);
749 cfd633c2 2018-09-10 stsp return err;
751 cfd633c2 2018-09-10 stsp return got_privsep_recv_commit(commit, pack->privsep_child->ibuf);
754 cfd633c2 2018-09-10 stsp const struct got_error *
755 a440fac0 2018-09-06 stsp got_object_read_commit_privsep(struct got_commit_object **commit,
756 ad242220 2018-09-08 stsp struct got_object *obj, int obj_fd, struct got_repository *repo)
758 a440fac0 2018-09-06 stsp int imsg_fds[2];
760 3516b818 2018-09-08 stsp struct imsgbuf *ibuf;
762 ad242220 2018-09-08 stsp if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].imsg_fd != -1)
763 ad242220 2018-09-08 stsp return request_commit(commit, repo, obj, obj_fd);
765 3516b818 2018-09-08 stsp ibuf = calloc(1, sizeof(*ibuf));
766 3516b818 2018-09-08 stsp if (ibuf == NULL)
767 3516b818 2018-09-08 stsp return got_error_from_errno();
769 a440fac0 2018-09-06 stsp if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1)
770 a440fac0 2018-09-06 stsp return got_error_from_errno();
772 a440fac0 2018-09-06 stsp pid = fork();
773 a440fac0 2018-09-06 stsp if (pid == -1)
774 a440fac0 2018-09-06 stsp return got_error_from_errno();
775 a440fac0 2018-09-06 stsp else if (pid == 0) {
776 3cab8b4d 2018-09-08 stsp exec_privsep_child(imsg_fds, GOT_PATH_PROG_READ_COMMIT,
777 3cab8b4d 2018-09-08 stsp repo->path);
778 a440fac0 2018-09-06 stsp /* not reached */
781 a440fac0 2018-09-06 stsp close(imsg_fds[1]);
782 ad242220 2018-09-08 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].imsg_fd =
783 ad242220 2018-09-08 stsp imsg_fds[0];
784 ad242220 2018-09-08 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].pid = pid;
785 3516b818 2018-09-08 stsp imsg_init(ibuf, imsg_fds[0]);
786 3516b818 2018-09-08 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].ibuf = ibuf;
788 ad242220 2018-09-08 stsp return request_commit(commit, repo, obj, obj_fd);
791 a440fac0 2018-09-06 stsp static const struct got_error *
792 ad242220 2018-09-08 stsp request_tree(struct got_tree_object **tree, struct got_repository *repo,
793 ad242220 2018-09-08 stsp struct got_object *obj, int fd)
795 a440fac0 2018-09-06 stsp const struct got_error *err = NULL;
796 3516b818 2018-09-08 stsp struct imsgbuf *ibuf;
798 3516b818 2018-09-08 stsp ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TREE].ibuf;
800 cfd633c2 2018-09-10 stsp err = got_privsep_send_obj_req(ibuf, fd, obj);
802 3516b818 2018-09-08 stsp return err;
804 3516b818 2018-09-08 stsp return got_privsep_recv_tree(tree, ibuf);
807 a440fac0 2018-09-06 stsp const struct got_error *
808 a440fac0 2018-09-06 stsp got_object_read_tree_privsep(struct got_tree_object **tree,
809 ad242220 2018-09-08 stsp struct got_object *obj, int obj_fd, struct got_repository *repo)
811 a440fac0 2018-09-06 stsp int imsg_fds[2];
813 3516b818 2018-09-08 stsp struct imsgbuf *ibuf;
815 ad242220 2018-09-08 stsp if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TREE].imsg_fd != -1)
816 ad242220 2018-09-08 stsp return request_tree(tree, repo, obj, obj_fd);
818 3516b818 2018-09-08 stsp ibuf = calloc(1, sizeof(*ibuf));
819 3516b818 2018-09-08 stsp if (ibuf == NULL)
820 3516b818 2018-09-08 stsp return got_error_from_errno();
822 a440fac0 2018-09-06 stsp if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1)
823 a440fac0 2018-09-06 stsp return got_error_from_errno();
825 a440fac0 2018-09-06 stsp pid = fork();
826 a440fac0 2018-09-06 stsp if (pid == -1)
827 a440fac0 2018-09-06 stsp return got_error_from_errno();
828 a440fac0 2018-09-06 stsp else if (pid == 0) {
829 3cab8b4d 2018-09-08 stsp exec_privsep_child(imsg_fds, GOT_PATH_PROG_READ_TREE,
830 3cab8b4d 2018-09-08 stsp repo->path);
831 a440fac0 2018-09-06 stsp /* not reached */
834 a440fac0 2018-09-06 stsp close(imsg_fds[1]);
836 ad242220 2018-09-08 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TREE].imsg_fd =
837 ad242220 2018-09-08 stsp imsg_fds[0];
838 ad242220 2018-09-08 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TREE].pid = pid;
839 3516b818 2018-09-08 stsp imsg_init(ibuf, imsg_fds[0]);
840 3516b818 2018-09-08 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TREE].ibuf = ibuf;
843 ad242220 2018-09-08 stsp return request_tree(tree, repo, obj, obj_fd);
846 e7885405 2018-09-10 stsp const struct got_error *
847 e7885405 2018-09-10 stsp got_object_read_packed_tree_privsep(struct got_tree_object **tree,
848 e7885405 2018-09-10 stsp struct got_object *obj, struct got_pack *pack)
850 e7885405 2018-09-10 stsp const struct got_error *err = NULL;
852 e7885405 2018-09-10 stsp err = got_privsep_send_obj_req(pack->privsep_child->ibuf, -1, obj);
854 e7885405 2018-09-10 stsp return err;
856 e7885405 2018-09-10 stsp return got_privsep_recv_tree(tree, pack->privsep_child->ibuf);
859 55da3778 2018-09-10 stsp static const struct got_error *
860 55da3778 2018-09-10 stsp request_blob(size_t *size, int outfd, int infd, struct imsgbuf *ibuf)
862 55da3778 2018-09-10 stsp const struct got_error *err = NULL;
863 55da3778 2018-09-10 stsp int outfd_child;
865 55da3778 2018-09-10 stsp outfd_child = dup(outfd);
866 55da3778 2018-09-10 stsp if (outfd_child == -1)
867 55da3778 2018-09-10 stsp return got_error_from_errno();
869 55da3778 2018-09-10 stsp err = got_privsep_send_blob_req(ibuf, infd);
871 55da3778 2018-09-10 stsp return err;
873 55da3778 2018-09-10 stsp err = got_privsep_send_blob_outfd(ibuf, outfd_child);
875 55da3778 2018-09-10 stsp close(outfd_child);
876 55da3778 2018-09-10 stsp return err;
879 3516b818 2018-09-08 stsp err = got_privsep_recv_blob(size, ibuf);
881 3516b818 2018-09-08 stsp return err;
883 ad242220 2018-09-08 stsp if (lseek(outfd, SEEK_SET, 0) == -1)
884 3516b818 2018-09-08 stsp return got_error_from_errno();
886 ad242220 2018-09-08 stsp return err;
889 a440fac0 2018-09-06 stsp const struct got_error *
890 ad242220 2018-09-08 stsp got_object_read_blob_privsep(size_t *size, int outfd, int infd,
891 ad242220 2018-09-08 stsp struct got_repository *repo)
893 a440fac0 2018-09-06 stsp int imsg_fds[2];
895 3516b818 2018-09-08 stsp struct imsgbuf *ibuf;
897 55da3778 2018-09-10 stsp if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].imsg_fd != -1) {
898 55da3778 2018-09-10 stsp ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].ibuf;
899 55da3778 2018-09-10 stsp return request_blob(size, outfd, infd, ibuf);
902 3516b818 2018-09-08 stsp ibuf = calloc(1, sizeof(*ibuf));
903 3516b818 2018-09-08 stsp if (ibuf == NULL)
904 3516b818 2018-09-08 stsp return got_error_from_errno();
906 a440fac0 2018-09-06 stsp if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1)
907 a440fac0 2018-09-06 stsp return got_error_from_errno();
909 a440fac0 2018-09-06 stsp pid = fork();
910 a440fac0 2018-09-06 stsp if (pid == -1)
911 a440fac0 2018-09-06 stsp return got_error_from_errno();
912 a440fac0 2018-09-06 stsp else if (pid == 0) {
913 3cab8b4d 2018-09-08 stsp exec_privsep_child(imsg_fds, GOT_PATH_PROG_READ_BLOB,
914 3cab8b4d 2018-09-08 stsp repo->path);
915 a440fac0 2018-09-06 stsp /* not reached */
918 a440fac0 2018-09-06 stsp close(imsg_fds[1]);
919 ad242220 2018-09-08 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].imsg_fd =
920 ad242220 2018-09-08 stsp imsg_fds[0];
921 ad242220 2018-09-08 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].pid = pid;
922 3516b818 2018-09-08 stsp imsg_init(ibuf, imsg_fds[0]);
923 3516b818 2018-09-08 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].ibuf = ibuf;
925 55da3778 2018-09-10 stsp return request_blob(size, outfd, infd, ibuf);