Blob


1 /*
2 * Copyright (c) 2018, 2019 Stefan Sperling <stsp@openbsd.org>
3 * Copyright (c) 2019, Ori Bernstein <ori@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 /*
19 * All code runs under the same UID but sensitive code paths are
20 * run in a separate process with tighter pledge(2) promises.
21 * Data is communicated between processes via imsg_flush(3) and imsg_read(3).
22 * This behaviour is transparent to users of the library.
23 *
24 * We generally transmit data in imsg buffers, split across several messages
25 * if necessary. File descriptors are used in cases where this is impractical,
26 * such as when accessing pack files or when transferring large blobs.
27 *
28 * We exec(2) after a fork(2). Parts of our library functionality are
29 * accessible via separate executables in a libexec directory.
30 */
32 #define GOT_IMSG_FD_CHILD (STDERR_FILENO + 1)
34 #ifndef GOT_LIBEXECDIR
35 #define GOT_LIBEXECDIR /usr/libexec
36 #endif
38 /* Names of helper programs in libexec directory */
39 #define GOT_PROG_READ_OBJECT got-read-object
40 #define GOT_PROG_READ_TREE got-read-tree
41 #define GOT_PROG_READ_COMMIT got-read-commit
42 #define GOT_PROG_READ_BLOB got-read-blob
43 #define GOT_PROG_READ_TAG got-read-tag
44 #define GOT_PROG_READ_PACK got-read-pack
45 #define GOT_PROG_READ_GITCONFIG got-read-gitconfig
46 #define GOT_PROG_READ_GOTCONFIG got-read-gotconfig
47 #define GOT_PROG_READ_PATCH got-read-patch
48 #define GOT_PROG_FETCH_PACK got-fetch-pack
49 #define GOT_PROG_INDEX_PACK got-index-pack
50 #define GOT_PROG_SEND_PACK got-send-pack
52 #define GOT_STRINGIFY(x) #x
53 #define GOT_STRINGVAL(x) GOT_STRINGIFY(x)
55 /* Paths to helper programs in libexec directory */
56 #define GOT_PATH_PROG_READ_OBJECT \
57 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_OBJECT)
58 #define GOT_PATH_PROG_READ_TREE \
59 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_TREE)
60 #define GOT_PATH_PROG_READ_COMMIT \
61 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_COMMIT)
62 #define GOT_PATH_PROG_READ_BLOB \
63 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_BLOB)
64 #define GOT_PATH_PROG_READ_TAG \
65 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_TAG)
66 #define GOT_PATH_PROG_READ_PACK \
67 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_PACK)
68 #define GOT_PATH_PROG_READ_GITCONFIG \
69 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_GITCONFIG)
70 #define GOT_PATH_PROG_READ_GOTCONFIG \
71 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_GOTCONFIG)
72 #define GOT_PATH_PROG_READ_PATCH \
73 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_PATCH)
74 #define GOT_PATH_PROG_FETCH_PACK \
75 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_FETCH_PACK)
76 #define GOT_PATH_PROG_SEND_PACK \
77 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_SEND_PACK)
78 #define GOT_PATH_PROG_INDEX_PACK \
79 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_INDEX_PACK)
81 struct got_privsep_child {
82 int imsg_fd;
83 pid_t pid;
84 struct imsgbuf *ibuf;
85 };
87 enum got_imsg_type {
88 /* An error occured while processing a request. */
89 GOT_IMSG_ERROR,
91 /* Stop the child process. */
92 GOT_IMSG_STOP,
94 /*
95 * Messages concerned with read access to objects in a repository.
96 * Object and pack files are opened by the main process, where
97 * data may be read as a byte string but without any interpretation.
98 * Decompression and parsing of object and pack files occurs in a
99 * separate process which runs under pledge("stdio recvfd").
100 * This sandboxes our own repository parsing code, as well as zlib.
101 */
102 GOT_IMSG_OBJECT_REQUEST,
103 GOT_IMSG_OBJECT,
104 GOT_IMSG_COMMIT_REQUEST,
105 GOT_IMSG_COMMIT,
106 GOT_IMSG_COMMIT_LOGMSG,
107 GOT_IMSG_TREE_REQUEST,
108 GOT_IMSG_TREE,
109 GOT_IMSG_TREE_ENTRIES,
110 GOT_IMSG_BLOB_REQUEST,
111 GOT_IMSG_BLOB_OUTFD,
112 GOT_IMSG_BLOB,
113 GOT_IMSG_TAG_REQUEST,
114 GOT_IMSG_TAG,
115 GOT_IMSG_TAG_TAGMSG,
117 /* Messages related to networking. */
118 GOT_IMSG_FETCH_REQUEST,
119 GOT_IMSG_FETCH_HAVE_REF,
120 GOT_IMSG_FETCH_WANTED_BRANCH,
121 GOT_IMSG_FETCH_WANTED_REF,
122 GOT_IMSG_FETCH_OUTFD,
123 GOT_IMSG_FETCH_SYMREFS,
124 GOT_IMSG_FETCH_REF,
125 GOT_IMSG_FETCH_SERVER_PROGRESS,
126 GOT_IMSG_FETCH_DOWNLOAD_PROGRESS,
127 GOT_IMSG_FETCH_DONE,
128 GOT_IMSG_IDXPACK_REQUEST,
129 GOT_IMSG_IDXPACK_OUTFD,
130 GOT_IMSG_IDXPACK_PROGRESS,
131 GOT_IMSG_IDXPACK_DONE,
132 GOT_IMSG_SEND_REQUEST,
133 GOT_IMSG_SEND_REF,
134 GOT_IMSG_SEND_REMOTE_REF,
135 GOT_IMSG_SEND_REF_STATUS,
136 GOT_IMSG_SEND_PACK_REQUEST,
137 GOT_IMSG_SEND_PACKFD,
138 GOT_IMSG_SEND_UPLOAD_PROGRESS,
139 GOT_IMSG_SEND_DONE,
141 /* Messages related to pack files. */
142 GOT_IMSG_PACKIDX,
143 GOT_IMSG_PACK,
144 GOT_IMSG_PACKED_OBJECT_REQUEST,
145 GOT_IMSG_COMMIT_TRAVERSAL_REQUEST,
146 GOT_IMSG_TRAVERSED_COMMITS,
147 GOT_IMSG_COMMIT_TRAVERSAL_DONE,
148 GOT_IMSG_OBJECT_ENUMERATION_REQUEST,
149 GOT_IMSG_ENUMERATED_COMMIT,
150 GOT_IMSG_ENUMERATED_TREE,
151 GOT_IMSG_TREE_ENUMERATION_DONE,
152 GOT_IMSG_OBJECT_ENUMERATION_DONE,
153 GOT_IMSG_OBJECT_ENUMERATION_INCOMPLETE,
155 /* Message sending file descriptor to a temporary file. */
156 GOT_IMSG_TMPFD,
158 /* Messages related to gitconfig files. */
159 GOT_IMSG_GITCONFIG_PARSE_REQUEST,
160 GOT_IMSG_GITCONFIG_REPOSITORY_FORMAT_VERSION_REQUEST,
161 GOT_IMSG_GITCONFIG_REPOSITORY_EXTENSIONS_REQUEST,
162 GOT_IMSG_GITCONFIG_AUTHOR_NAME_REQUEST,
163 GOT_IMSG_GITCONFIG_AUTHOR_EMAIL_REQUEST,
164 GOT_IMSG_GITCONFIG_REMOTES_REQUEST,
165 GOT_IMSG_GITCONFIG_INT_VAL,
166 GOT_IMSG_GITCONFIG_STR_VAL,
167 GOT_IMSG_GITCONFIG_REMOTES,
168 GOT_IMSG_GITCONFIG_REMOTE,
169 GOT_IMSG_GITCONFIG_OWNER_REQUEST,
170 GOT_IMSG_GITCONFIG_OWNER,
172 /* Messages related to gotconfig files. */
173 GOT_IMSG_GOTCONFIG_PARSE_REQUEST,
174 GOT_IMSG_GOTCONFIG_AUTHOR_REQUEST,
175 GOT_IMSG_GOTCONFIG_REMOTES_REQUEST,
176 GOT_IMSG_GOTCONFIG_INT_VAL,
177 GOT_IMSG_GOTCONFIG_STR_VAL,
178 GOT_IMSG_GOTCONFIG_REMOTES,
179 GOT_IMSG_GOTCONFIG_REMOTE,
181 /* Raw object access. Uncompress object data but do not parse it. */
182 GOT_IMSG_RAW_OBJECT_REQUEST,
183 GOT_IMSG_RAW_OBJECT_OUTFD,
184 GOT_IMSG_PACKED_RAW_OBJECT_REQUEST,
185 GOT_IMSG_RAW_OBJECT,
187 /* Read raw delta data from pack files. */
188 GOT_IMSG_RAW_DELTA_OUTFD,
189 GOT_IMSG_RAW_DELTA_REQUEST,
190 GOT_IMSG_RAW_DELTA,
192 /* Re-use deltas found in a pack file. */
193 GOT_IMSG_DELTA_REUSE_REQUEST,
194 GOT_IMSG_REUSED_DELTAS,
195 GOT_IMSG_DELTA_REUSE_DONE,
197 /* Transfer a list of object IDs. */
198 GOT_IMSG_OBJ_ID_LIST,
199 GOT_IMSG_OBJ_ID_LIST_DONE,
201 /* Messages related to patch files. */
202 GOT_IMSG_PATCH_FILE,
203 GOT_IMSG_PATCH_HUNK,
204 GOT_IMSG_PATCH_DONE,
205 GOT_IMSG_PATCH_LINE,
206 GOT_IMSG_PATCH,
207 GOT_IMSG_PATCH_EOF,
208 };
210 /* Structure for GOT_IMSG_ERROR. */
211 struct got_imsg_error {
212 int code; /* an error code from got_error.h */
213 int errno_code; /* in case code equals GOT_ERR_ERRNO */
214 } __attribute__((__packed__));
216 /*
217 * Structure for GOT_IMSG_TREE_REQUEST and GOT_IMSG_OBJECT data.
218 */
219 struct got_imsg_object {
220 uint8_t id[SHA1_DIGEST_LENGTH];
222 /* These fields are the same as in struct got_object. */
223 int type;
224 int flags;
225 size_t hdrlen;
226 size_t size;
227 off_t pack_offset;
228 int pack_idx;
229 } __attribute__((__packed__));
231 /* Structure for GOT_IMSG_COMMIT data. */
232 struct got_imsg_commit_object {
233 uint8_t tree_id[SHA1_DIGEST_LENGTH];
234 size_t author_len;
235 time_t author_time;
236 time_t author_gmtoff;
237 size_t committer_len;
238 time_t committer_time;
239 time_t committer_gmtoff;
240 size_t logmsg_len;
241 int nparents;
243 /*
244 * Followed by author_len + committer_len data bytes
245 */
247 /* Followed by 'nparents' SHA1_DIGEST_LENGTH length strings */
249 /*
250 * Followed by 'logmsg_len' bytes of commit log message data in
251 * one or more GOT_IMSG_COMMIT_LOGMSG messages.
252 */
253 } __attribute__((__packed__));
255 struct got_imsg_tree_entry {
256 char id[SHA1_DIGEST_LENGTH];
257 mode_t mode;
258 size_t namelen;
259 /* Followed by namelen bytes of entry's name, not NUL-terminated. */
260 } __attribute__((__packed__));
262 /* Structure for GOT_IMSG_TREE_ENTRIES. */
263 struct got_imsg_tree_entries {
264 size_t nentries; /* Number of tree entries contained in this message. */
266 /* Followed by nentries * struct got_imsg_tree_entry */
267 };
269 /* Structure for GOT_IMSG_TREE_OBJECT_REPLY data. */
270 struct got_imsg_tree_object {
271 int nentries; /* This many tree entries follow. */
272 };
274 /* Structure for GOT_IMSG_BLOB. */
275 struct got_imsg_blob {
276 size_t size;
277 size_t hdrlen;
279 /*
280 * If size <= GOT_PRIVSEP_INLINE_BLOB_DATA_MAX, blob data follows
281 * in the imsg buffer. Otherwise, blob data has been written to a
282 * file descriptor passed via the GOT_IMSG_BLOB_OUTFD imsg.
283 */
284 #define GOT_PRIVSEP_INLINE_BLOB_DATA_MAX \
285 (MAX_IMSGSIZE - IMSG_HEADER_SIZE - sizeof(struct got_imsg_blob))
286 };
288 /* Structure for GOT_IMSG_RAW_OBJECT. */
289 struct got_imsg_raw_obj {
290 off_t size;
291 size_t hdrlen;
293 /*
294 * If size <= GOT_PRIVSEP_INLINE_OBJECT_DATA_MAX, object data follows
295 * in the imsg buffer. Otherwise, object data has been written to a
296 * file descriptor passed via the GOT_IMSG_RAW_OBJECT_OUTFD imsg.
297 */
298 #define GOT_PRIVSEP_INLINE_OBJECT_DATA_MAX \
299 (MAX_IMSGSIZE - IMSG_HEADER_SIZE - sizeof(struct got_imsg_raw_obj))
300 };
302 /* Structure for GOT_IMSG_RAW_DELTA. */
303 struct got_imsg_raw_delta {
304 uint8_t base_id[SHA1_DIGEST_LENGTH];
305 uint64_t base_size;
306 uint64_t result_size;
307 off_t delta_size;
308 off_t delta_compressed_size;
309 off_t delta_offset;
310 off_t delta_out_offset;
312 /*
313 * Delta data has been written at delta_out_offset to the file
314 * descriptor passed via the GOT_IMSG_RAW_DELTA_OUTFD imsg.
315 */
316 };
318 /* Structures for GOT_IMSG_REUSED_DELTAS. */
319 struct got_imsg_reused_delta {
320 struct got_object_id id;
321 struct got_object_id base_id;
322 uint64_t base_size;
323 uint64_t result_size;
324 off_t delta_size;
325 off_t delta_compressed_size;
326 off_t delta_offset;
327 off_t delta_out_offset;
329 /*
330 * Delta data has been written at delta_out_offset to the file
331 * descriptor passed via the GOT_IMSG_RAW_DELTA_OUTFD imsg.
332 */
333 };
334 struct got_imsg_reused_deltas {
335 size_t ndeltas;
337 /*
338 * Followed by ndeltas * struct got_imsg_reused_delta.
339 */
341 #define GOT_IMSG_REUSED_DELTAS_MAX_NDELTAS \
342 ((MAX_IMSGSIZE - IMSG_HEADER_SIZE - \
343 sizeof(struct got_imsg_reused_deltas)) \
344 / sizeof(struct got_imsg_reused_delta))
345 };
347 /* Structure for GOT_IMSG_TAG data. */
348 struct got_imsg_tag_object {
349 uint8_t id[SHA1_DIGEST_LENGTH];
350 int obj_type;
351 size_t tag_len;
352 size_t tagger_len;
353 time_t tagger_time;
354 time_t tagger_gmtoff;
355 size_t tagmsg_len;
357 /*
358 * Followed by tag_len + tagger_len data bytes
359 */
361 /*
362 * Followed by 'tagmsg_len' bytes of tag message data in
363 * one or more GOT_IMSG_TAG_TAGMSG messages.
364 */
365 } __attribute__((__packed__));
367 /* Structure for GOT_IMSG_FETCH_HAVE_REF data. */
368 struct got_imsg_fetch_have_ref {
369 uint8_t id[SHA1_DIGEST_LENGTH];
370 size_t name_len;
371 /* Followed by name_len data bytes. */
372 } __attribute__((__packed__));
374 /* Structure for GOT_IMSG_FETCH_WANTED_BRANCH data. */
375 struct got_imsg_fetch_wanted_branch {
376 size_t name_len;
377 /* Followed by name_len data bytes. */
378 } __attribute__((__packed__));
380 /* Structure for GOT_IMSG_FETCH_WANTED_REF data. */
381 struct got_imsg_fetch_wanted_ref {
382 size_t name_len;
383 /* Followed by name_len data bytes. */
384 } __attribute__((__packed__));
386 /* Structure for GOT_IMSG_FETCH_REQUEST data. */
387 struct got_imsg_fetch_request {
388 int fetch_all_branches;
389 int list_refs_only;
390 int verbosity;
391 size_t n_have_refs;
392 size_t n_wanted_branches;
393 size_t n_wanted_refs;
394 /* Followed by n_have_refs GOT_IMSG_FETCH_HAVE_REF messages. */
395 /* Followed by n_wanted_branches times GOT_IMSG_FETCH_WANTED_BRANCH. */
396 /* Followed by n_wanted_refs times GOT_IMSG_FETCH_WANTED_REF. */
397 } __attribute__((__packed__));
399 /* Structures for GOT_IMSG_FETCH_SYMREFS data. */
400 struct got_imsg_fetch_symref {
401 size_t name_len;
402 size_t target_len;
404 /*
405 * Followed by name_len + target_len data bytes.
406 */
407 } __attribute__((__packed__));
409 struct got_imsg_fetch_symrefs {
410 size_t nsymrefs;
412 /* Followed by nsymrefs times of got_imsg_fetch_symref data. */
413 } __attribute__((__packed__));
415 /* Structure for GOT_IMSG_FETCH_REF data. */
416 struct got_imsg_fetch_ref {
417 /* Describes a reference which will be fetched. */
418 uint8_t refid[SHA1_DIGEST_LENGTH];
419 /* Followed by reference name in remaining data of imsg buffer. */
420 };
422 /* Structure for GOT_IMSG_FETCH_DOWNLOAD_PROGRESS data. */
423 struct got_imsg_fetch_download_progress {
424 /* Number of packfile data bytes downloaded so far. */
425 off_t packfile_bytes;
426 };
428 /* Structure for GOT_IMSG_SEND_REQUEST data. */
429 struct got_imsg_send_request {
430 int verbosity;
431 size_t nrefs;
432 /* Followed by nrefs GOT_IMSG_SEND_REF messages. */
433 } __attribute__((__packed__));
435 /* Structure for GOT_IMSG_SEND_UPLOAD_PROGRESS data. */
436 struct got_imsg_send_upload_progress {
437 /* Number of packfile data bytes uploaded so far. */
438 off_t packfile_bytes;
439 };
441 /* Structure for GOT_IMSG_SEND_REF data. */
442 struct got_imsg_send_ref {
443 uint8_t id[SHA1_DIGEST_LENGTH];
444 int delete;
445 size_t name_len;
446 /* Followed by name_len data bytes. */
447 } __attribute__((__packed__));
449 /* Structure for GOT_IMSG_SEND_REMOTE_REF data. */
450 struct got_imsg_send_remote_ref {
451 uint8_t id[SHA1_DIGEST_LENGTH];
452 size_t name_len;
453 /* Followed by name_len data bytes. */
454 } __attribute__((__packed__));
456 /* Structure for GOT_IMSG_SEND_REF_STATUS data. */
457 struct got_imsg_send_ref_status {
458 int success;
459 size_t name_len;
460 /* Followed by name_len data bytes. */
461 } __attribute__((__packed__));
463 /* Structure for GOT_IMSG_IDXPACK_REQUEST data. */
464 struct got_imsg_index_pack_request {
465 uint8_t pack_hash[SHA1_DIGEST_LENGTH];
466 } __attribute__((__packed__));
468 /* Structure for GOT_IMSG_IDXPACK_PROGRESS data. */
469 struct got_imsg_index_pack_progress {
470 /* Total number of objects in pack file. */
471 int nobj_total;
473 /* Number of objects indexed so far. */
474 int nobj_indexed;
476 /* Number of non-deltified objects in pack file. */
477 int nobj_loose;
479 /* Number of deltified objects resolved so far. */
480 int nobj_resolved;
481 };
483 /* Structure for GOT_IMSG_PACKIDX. */
484 struct got_imsg_packidx {
485 size_t len;
486 off_t packfile_size;
487 /* Additionally, a file desciptor is passed via imsg. */
488 };
490 /* Structure for GOT_IMSG_PACK. */
491 struct got_imsg_pack {
492 char path_packfile[PATH_MAX];
493 size_t filesize;
494 /* Additionally, a file desciptor is passed via imsg. */
495 } __attribute__((__packed__));
497 /*
498 * Structure for GOT_IMSG_OBJECT_REQUEST, GOT_IMSG_BLOB_REQUEST,
499 * GOT_IMSG_TREE_REQUEST, GOT_IMSG_COMMIT_REQUEST, and
500 * GOT_IMSG_TAG_REQUEST data.
501 */
502 struct got_object_id;
504 /*
505 * Structure for GOT_IMSG_PACKED_OBJECT_REQUEST and
506 * GOT_IMSG_PACKED_RAW_OBJECT_REQUEST data.
507 */
508 struct got_imsg_packed_object {
509 uint8_t id[SHA1_DIGEST_LENGTH];
510 int idx;
511 } __attribute__((__packed__));
513 /*
514 * Structure for GOT_IMSG_DELTA data.
515 */
516 struct got_imsg_delta {
517 /* These fields are the same as in struct got_delta. */
518 off_t offset;
519 size_t tslen;
520 int type;
521 size_t size;
522 off_t data_offset;
523 };
525 /*
526 * Structure for GOT_IMSG_RAW_DELTA_REQUEST data.
527 */
528 struct got_imsg_raw_delta_request {
529 uint8_t id[SHA1_DIGEST_LENGTH];
530 int idx;
531 };
533 /*
534 * Structure for GOT_IMSG_OBJ_ID_LIST data.
535 * Multiple such messages may be sent back-to-back, where each message
536 * contains a chunk of IDs. The entire list must be terminated with a
537 * GOT_IMSG_OBJ_ID_LIST_DONE message.
538 */
539 struct got_imsg_object_idlist {
540 size_t nids;
542 /*
543 * Followed by nids * struct got_object_id.
544 */
546 #define GOT_IMSG_OBJ_ID_LIST_MAX_NIDS \
547 ((MAX_IMSGSIZE - IMSG_HEADER_SIZE - \
548 sizeof(struct got_imsg_object_idlist)) / sizeof(struct got_object_id))
549 };
551 /* Structure for GOT_IMSG_COMMIT_TRAVERSAL_REQUEST */
552 struct got_imsg_commit_traversal_request {
553 uint8_t id[SHA1_DIGEST_LENGTH];
554 int idx;
555 size_t path_len;
556 /* Followed by path_len bytes of path data */
557 } __attribute__((__packed__));
559 /* Structure for GOT_IMSG_TRAVERSED_COMMITS */
560 struct got_imsg_traversed_commits {
561 size_t ncommits;
562 /* Followed by ncommit IDs of SHA1_DIGEST_LENGTH each */
563 } __attribute__((__packed__));
565 /* Structure for GOT_IMSG_ENUMERATED_COMMIT */
566 struct got_imsg_enumerated_commit {
567 uint8_t id[SHA1_DIGEST_LENGTH];
568 time_t mtime;
569 } __attribute__((__packed__));
571 /* Structure for GOT_IMSG_ENUMERATED_TREE */
572 struct got_imsg_enumerated_tree {
573 uint8_t id[SHA1_DIGEST_LENGTH]; /* tree ID */
574 int nentries; /* number of tree entries */
576 /* Followed by tree's path in remaining data of imsg buffer. */
578 /* Followed by nentries * GOT_IMSG_TREE_ENTRY messages. */
579 } __attribute__((__packed__));
581 /*
582 * Structure for GOT_IMSG_GOTCONFIG_REMOTE and
583 * GOT_IMSG_GOTCONFIG_REMOTE data.
584 */
585 struct got_imsg_remote {
586 size_t name_len;
587 size_t fetch_url_len;
588 size_t send_url_len;
589 int mirror_references;
590 int fetch_all_branches;
591 int nfetch_branches;
592 int nsend_branches;
593 int nfetch_refs;
595 /* Followed by name_len data bytes. */
596 /* Followed by fetch_url_len + send_url_len data bytes. */
597 /* Followed by nfetch_branches GOT_IMSG_GITCONFIG_STR_VAL messages. */
598 /* Followed by nsend_branches GOT_IMSG_GITCONFIG_STR_VAL messages. */
599 /* Followed by nfetch_refs GOT_IMSG_GITCONFIG_STR_VAL messages. */
600 } __attribute__((__packed__));
602 /*
603 * Structure for GOT_IMSG_GITCONFIG_REMOTES data.
604 */
605 struct got_imsg_remotes {
606 int nremotes; /* This many GOT_IMSG_GITCONFIG_REMOTE messages follow. */
607 };
609 /*
610 * Structure for GOT_IMSG_PATCH data.
611 */
612 struct got_imsg_patch {
613 int git;
614 char old[PATH_MAX];
615 char new[PATH_MAX];
616 };
618 /*
619 * Structure for GOT_IMSG_PATCH_HUNK data.
620 */
621 struct got_imsg_patch_hunk {
622 int oldfrom;
623 int oldlines;
624 int newfrom;
625 int newlines;
626 };
628 struct got_remote_repo;
629 struct got_pack;
630 struct got_packidx;
631 struct got_pathlist_head;
633 const struct got_error *got_send_ack(pid_t);
634 const struct got_error *got_privsep_wait_for_child(pid_t);
635 const struct got_error *got_privsep_flush_imsg(struct imsgbuf *);
636 const struct got_error *got_privsep_send_stop(int);
637 const struct got_error *got_privsep_recv_imsg(struct imsg *, struct imsgbuf *,
638 size_t);
639 void got_privsep_send_error(struct imsgbuf *, const struct got_error *);
640 const struct got_error *got_privsep_send_ack(struct imsgbuf *);
641 const struct got_error *got_privsep_wait_ack(struct imsgbuf *);
642 const struct got_error *got_privsep_send_obj_req(struct imsgbuf *, int,
643 struct got_object_id *);
644 const struct got_error *got_privsep_send_raw_obj_req(struct imsgbuf *, int,
645 struct got_object_id *);
646 const struct got_error *got_privsep_send_raw_obj_outfd(struct imsgbuf *, int);
647 const struct got_error *got_privsep_send_commit_req(struct imsgbuf *, int,
648 struct got_object_id *, int);
649 const struct got_error *got_privsep_send_tree_req(struct imsgbuf *, int,
650 struct got_object_id *, int);
651 const struct got_error *got_privsep_send_tag_req(struct imsgbuf *, int,
652 struct got_object_id *, int);
653 const struct got_error *got_privsep_send_blob_req(struct imsgbuf *, int,
654 struct got_object_id *, int);
655 const struct got_error *got_privsep_send_blob_outfd(struct imsgbuf *, int);
656 const struct got_error *got_privsep_send_tmpfd(struct imsgbuf *, int);
657 const struct got_error *got_privsep_send_obj(struct imsgbuf *,
658 struct got_object *);
659 const struct got_error *got_privsep_send_index_pack_req(struct imsgbuf *,
660 uint8_t *, int);
661 const struct got_error *got_privsep_send_index_pack_outfd(struct imsgbuf *,
662 int);
663 const struct got_error *got_privsep_recv_index_progress(int *, int *, int *,
664 int *, int *, struct imsgbuf *ibuf);
665 const struct got_error *got_privsep_send_fetch_req(struct imsgbuf *, int,
666 struct got_pathlist_head *, int, struct got_pathlist_head *,
667 struct got_pathlist_head *, int, int);
668 const struct got_error *got_privsep_send_fetch_outfd(struct imsgbuf *, int);
669 const struct got_error *got_privsep_recv_fetch_progress(int *,
670 struct got_object_id **, char **, struct got_pathlist_head *, char **,
671 off_t *, uint8_t *, struct imsgbuf *);
672 const struct got_error *got_privsep_send_send_req(struct imsgbuf *, int,
673 struct got_pathlist_head *, struct got_pathlist_head *, int);
674 const struct got_error *got_privsep_recv_send_remote_refs(
675 struct got_pathlist_head *, struct imsgbuf *);
676 const struct got_error *got_privsep_send_packfd(struct imsgbuf *, int);
677 const struct got_error *got_privsep_recv_send_progress(int *, off_t *,
678 int *, char **, struct imsgbuf *);
679 const struct got_error *got_privsep_get_imsg_obj(struct got_object **,
680 struct imsg *, struct imsgbuf *);
681 const struct got_error *got_privsep_recv_obj(struct got_object **,
682 struct imsgbuf *);
683 const struct got_error *got_privsep_send_raw_obj(struct imsgbuf *, off_t,
684 size_t, uint8_t *);
685 const struct got_error *got_privsep_recv_raw_obj(uint8_t **, off_t *, size_t *,
686 struct imsgbuf *);
687 const struct got_error *got_privsep_send_commit(struct imsgbuf *,
688 struct got_commit_object *);
689 const struct got_error *got_privsep_recv_commit(struct got_commit_object **,
690 struct imsgbuf *);
691 const struct got_error *got_privsep_recv_tree(struct got_tree_object **,
692 struct imsgbuf *);
693 struct got_parsed_tree_entry;
694 const struct got_error *got_privsep_send_tree(struct imsgbuf *,
695 struct got_parsed_tree_entry *, int);
696 const struct got_error *got_privsep_send_blob(struct imsgbuf *, size_t, size_t,
697 const uint8_t *);
698 const struct got_error *got_privsep_recv_blob(uint8_t **, size_t *, size_t *,
699 struct imsgbuf *);
700 const struct got_error *got_privsep_send_tag(struct imsgbuf *,
701 struct got_tag_object *);
702 const struct got_error *got_privsep_recv_tag(struct got_tag_object **,
703 struct imsgbuf *);
704 const struct got_error *got_privsep_init_pack_child(struct imsgbuf *,
705 struct got_pack *, struct got_packidx *);
706 const struct got_error *got_privsep_send_packed_obj_req(struct imsgbuf *, int,
707 struct got_object_id *);
708 const struct got_error *got_privsep_send_packed_raw_obj_req(struct imsgbuf *,
709 int, struct got_object_id *);
710 const struct got_error *got_privsep_send_pack_child_ready(struct imsgbuf *);
712 const struct got_error *got_privsep_send_gitconfig_parse_req(struct imsgbuf *,
713 int);
714 const struct got_error *
715 got_privsep_send_gitconfig_repository_format_version_req(struct imsgbuf *);
716 const struct got_error *got_privsep_send_gitconfig_repository_extensions_req(
717 struct imsgbuf *);
718 const struct got_error *got_privsep_send_gitconfig_author_name_req(
719 struct imsgbuf *);
720 const struct got_error *got_privsep_send_gitconfig_author_email_req(
721 struct imsgbuf *);
722 const struct got_error *got_privsep_send_gitconfig_remotes_req(
723 struct imsgbuf *);
724 const struct got_error *got_privsep_send_gitconfig_owner_req(struct imsgbuf *);
725 const struct got_error *got_privsep_recv_gitconfig_str(char **,
726 struct imsgbuf *);
727 const struct got_error *got_privsep_recv_gitconfig_int(int *, struct imsgbuf *);
728 const struct got_error *got_privsep_recv_gitconfig_remotes(
729 struct got_remote_repo **, int *, struct imsgbuf *);
731 const struct got_error *got_privsep_send_gotconfig_parse_req(struct imsgbuf *,
732 int);
733 const struct got_error *got_privsep_send_gotconfig_author_req(struct imsgbuf *);
734 const struct got_error *got_privsep_send_gotconfig_remotes_req(
735 struct imsgbuf *);
736 const struct got_error *got_privsep_recv_gotconfig_str(char **,
737 struct imsgbuf *);
738 const struct got_error *got_privsep_recv_gotconfig_remotes(
739 struct got_remote_repo **, int *, struct imsgbuf *);
741 const struct got_error *got_privsep_send_commit_traversal_request(
742 struct imsgbuf *, struct got_object_id *, int, const char *);
743 const struct got_error *got_privsep_recv_traversed_commits(
744 struct got_commit_object **, struct got_object_id **,
745 struct got_object_id_queue *, struct imsgbuf *);
746 const struct got_error *got_privsep_send_enumerated_tree(size_t *,
747 struct imsgbuf *, struct got_object_id *, const char *,
748 struct got_parsed_tree_entry *, int);
749 const struct got_error *got_privsep_send_object_enumeration_request(
750 struct imsgbuf *);
751 const struct got_error *got_privsep_send_object_enumeration_done(
752 struct imsgbuf *);
753 const struct got_error *got_privsep_send_object_enumeration_incomplete(
754 struct imsgbuf *);
755 const struct got_error *got_privsep_send_enumerated_commit(struct imsgbuf *,
756 struct got_object_id *, time_t);
757 const struct got_error *got_privsep_recv_enumerated_objects(int *,
758 struct imsgbuf *, got_object_enumerate_commit_cb,
759 got_object_enumerate_tree_cb, void *, struct got_repository *);
761 const struct got_error *got_privsep_send_raw_delta_req(struct imsgbuf *, int,
762 struct got_object_id *);
763 const struct got_error *got_privsep_send_raw_delta_outfd(struct imsgbuf *, int);
764 const struct got_error *got_privsep_send_raw_delta(struct imsgbuf *, uint64_t,
765 uint64_t, off_t, off_t, off_t, off_t, struct got_object_id *);
766 const struct got_error *got_privsep_recv_raw_delta(uint64_t *, uint64_t *,
767 off_t *, off_t *, off_t *, off_t *, struct got_object_id **,
768 struct imsgbuf *);
770 const struct got_error *got_privsep_send_object_idlist(struct imsgbuf *,
771 struct got_object_id **, size_t);
772 const struct got_error *got_privsep_send_object_idlist_done(struct imsgbuf *);
773 const struct got_error *got_privsep_recv_object_idlist(int *,
774 struct got_object_id **, size_t *, struct imsgbuf *);
776 const struct got_error *got_privsep_send_delta_reuse_req(struct imsgbuf *);
777 const struct got_error *got_privsep_send_reused_deltas(struct imsgbuf *,
778 struct got_imsg_reused_delta *, size_t);
779 const struct got_error *got_privsep_send_reused_deltas_done(struct imsgbuf *);
780 const struct got_error *got_privsep_recv_reused_deltas(int *,
781 struct got_imsg_reused_delta *, size_t *, struct imsgbuf *);
783 void got_privsep_exec_child(int[2], const char *, const char *);