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 enum got_imsg_type {
82 /* An error occured while processing a request. */
83 GOT_IMSG_ERROR,
85 /* Stop the child process. */
86 GOT_IMSG_STOP,
88 /*
89 * Messages concerned with read access to objects in a repository.
90 * Object and pack files are opened by the main process, where
91 * data may be read as a byte string but without any interpretation.
92 * Decompression and parsing of object and pack files occurs in a
93 * separate process which runs under pledge("stdio recvfd").
94 * This sandboxes our own repository parsing code, as well as zlib.
95 */
96 GOT_IMSG_OBJECT_REQUEST,
97 GOT_IMSG_OBJECT,
98 GOT_IMSG_COMMIT_REQUEST,
99 GOT_IMSG_COMMIT,
100 GOT_IMSG_COMMIT_LOGMSG,
101 GOT_IMSG_TREE_REQUEST,
102 GOT_IMSG_TREE,
103 GOT_IMSG_TREE_ENTRIES,
104 GOT_IMSG_BLOB_REQUEST,
105 GOT_IMSG_BLOB_OUTFD,
106 GOT_IMSG_BLOB,
107 GOT_IMSG_TAG_REQUEST,
108 GOT_IMSG_TAG,
109 GOT_IMSG_TAG_TAGMSG,
111 /* Messages related to networking. */
112 GOT_IMSG_FETCH_REQUEST,
113 GOT_IMSG_FETCH_HAVE_REF,
114 GOT_IMSG_FETCH_WANTED_BRANCH,
115 GOT_IMSG_FETCH_WANTED_REF,
116 GOT_IMSG_FETCH_OUTFD,
117 GOT_IMSG_FETCH_SYMREFS,
118 GOT_IMSG_FETCH_REF,
119 GOT_IMSG_FETCH_SERVER_PROGRESS,
120 GOT_IMSG_FETCH_DOWNLOAD_PROGRESS,
121 GOT_IMSG_FETCH_DONE,
122 GOT_IMSG_IDXPACK_REQUEST,
123 GOT_IMSG_IDXPACK_OUTFD,
124 GOT_IMSG_IDXPACK_PROGRESS,
125 GOT_IMSG_IDXPACK_DONE,
126 GOT_IMSG_SEND_REQUEST,
127 GOT_IMSG_SEND_REF,
128 GOT_IMSG_SEND_REMOTE_REF,
129 GOT_IMSG_SEND_REF_STATUS,
130 GOT_IMSG_SEND_PACK_REQUEST,
131 GOT_IMSG_SEND_PACKFD,
132 GOT_IMSG_SEND_UPLOAD_PROGRESS,
133 GOT_IMSG_SEND_DONE,
135 /* Messages related to pack files. */
136 GOT_IMSG_PACKIDX,
137 GOT_IMSG_PACK,
138 GOT_IMSG_PACKED_OBJECT_REQUEST,
139 GOT_IMSG_COMMIT_TRAVERSAL_REQUEST,
140 GOT_IMSG_TRAVERSED_COMMITS,
141 GOT_IMSG_COMMIT_TRAVERSAL_DONE,
142 GOT_IMSG_OBJECT_ENUMERATION_REQUEST,
143 GOT_IMSG_ENUMERATED_COMMIT,
144 GOT_IMSG_ENUMERATED_TREE,
145 GOT_IMSG_TREE_ENUMERATION_DONE,
146 GOT_IMSG_OBJECT_ENUMERATION_DONE,
147 GOT_IMSG_OBJECT_ENUMERATION_INCOMPLETE,
149 /* Message sending file descriptor to a temporary file. */
150 GOT_IMSG_TMPFD,
152 /* Messages related to gitconfig files. */
153 GOT_IMSG_GITCONFIG_PARSE_REQUEST,
154 GOT_IMSG_GITCONFIG_REPOSITORY_FORMAT_VERSION_REQUEST,
155 GOT_IMSG_GITCONFIG_REPOSITORY_EXTENSIONS_REQUEST,
156 GOT_IMSG_GITCONFIG_AUTHOR_NAME_REQUEST,
157 GOT_IMSG_GITCONFIG_AUTHOR_EMAIL_REQUEST,
158 GOT_IMSG_GITCONFIG_REMOTES_REQUEST,
159 GOT_IMSG_GITCONFIG_INT_VAL,
160 GOT_IMSG_GITCONFIG_STR_VAL,
161 GOT_IMSG_GITCONFIG_PAIR,
162 GOT_IMSG_GITCONFIG_REMOTES,
163 GOT_IMSG_GITCONFIG_REMOTE,
164 GOT_IMSG_GITCONFIG_OWNER_REQUEST,
165 GOT_IMSG_GITCONFIG_OWNER,
167 /* Messages related to gotconfig files. */
168 GOT_IMSG_GOTCONFIG_PARSE_REQUEST,
169 GOT_IMSG_GOTCONFIG_AUTHOR_REQUEST,
170 GOT_IMSG_GOTCONFIG_ALLOWEDSIGNERS_REQUEST,
171 GOT_IMSG_GOTCONFIG_REVOKEDSIGNERS_REQUEST,
172 GOT_IMSG_GOTCONFIG_SIGNERID_REQUEST,
173 GOT_IMSG_GOTCONFIG_REMOTES_REQUEST,
174 GOT_IMSG_GOTCONFIG_INT_VAL,
175 GOT_IMSG_GOTCONFIG_STR_VAL,
176 GOT_IMSG_GOTCONFIG_REMOTES,
177 GOT_IMSG_GOTCONFIG_REMOTE,
179 /* Raw object access. Uncompress object data but do not parse it. */
180 GOT_IMSG_RAW_OBJECT_REQUEST,
181 GOT_IMSG_RAW_OBJECT_OUTFD,
182 GOT_IMSG_PACKED_RAW_OBJECT_REQUEST,
183 GOT_IMSG_RAW_OBJECT,
185 /* Read raw delta data from pack files. */
186 GOT_IMSG_RAW_DELTA_OUTFD,
187 GOT_IMSG_RAW_DELTA_REQUEST,
188 GOT_IMSG_RAW_DELTA,
190 /* Re-use deltas found in a pack file. */
191 GOT_IMSG_DELTA_REUSE_REQUEST,
192 GOT_IMSG_REUSED_DELTAS,
193 GOT_IMSG_DELTA_REUSE_DONE,
195 /* Commit coloring in got-read-pack. */
196 GOT_IMSG_COMMIT_PAINTING_INIT,
197 GOT_IMSG_COMMIT_PAINTING_REQUEST,
198 GOT_IMSG_PAINTED_COMMITS,
199 GOT_IMSG_COMMIT_PAINTING_DONE,
201 /* Transfer a list of object IDs. */
202 GOT_IMSG_OBJ_ID_LIST,
203 GOT_IMSG_OBJ_ID_LIST_DONE,
205 /* Messages related to patch files. */
206 GOT_IMSG_PATCH_FILE,
207 GOT_IMSG_PATCH_HUNK,
208 GOT_IMSG_PATCH_DONE,
209 GOT_IMSG_PATCH_LINE,
210 GOT_IMSG_PATCH,
211 GOT_IMSG_PATCH_EOF,
212 };
214 /* Structure for GOT_IMSG_ERROR. */
215 struct got_imsg_error {
216 int code; /* an error code from got_error.h */
217 int errno_code; /* in case code equals GOT_ERR_ERRNO */
218 } __attribute__((__packed__));
220 /*
221 * Structure for GOT_IMSG_TREE_REQUEST and GOT_IMSG_OBJECT data.
222 */
223 struct got_imsg_object {
224 struct got_object_id id;
226 /* These fields are the same as in struct got_object. */
227 int type;
228 int flags;
229 size_t hdrlen;
230 size_t size;
231 off_t pack_offset;
232 int pack_idx;
233 } __attribute__((__packed__));
235 /* Structure for GOT_IMSG_COMMIT data. */
236 struct got_imsg_commit_object {
237 struct got_object_id tree_id;
238 size_t author_len;
239 time_t author_time;
240 time_t author_gmtoff;
241 size_t committer_len;
242 time_t committer_time;
243 time_t committer_gmtoff;
244 size_t logmsg_len;
245 int nparents;
247 /*
248 * Followed by author_len + committer_len data bytes
249 */
251 /* Followed by 'nparents' struct got_object_id */
253 /*
254 * Followed by 'logmsg_len' bytes of commit log message data in
255 * one or more GOT_IMSG_COMMIT_LOGMSG messages.
256 */
257 } __attribute__((__packed__));
259 struct got_imsg_tree_entry {
260 char id[GOT_OBJECT_ID_MAXLEN];
261 int algo;
262 mode_t mode;
263 size_t namelen;
264 /* Followed by namelen bytes of entry's name, not NUL-terminated. */
265 } __attribute__((__packed__));
267 /* Structure for GOT_IMSG_TREE_ENTRIES. */
268 struct got_imsg_tree_entries {
269 size_t nentries; /* Number of tree entries contained in this message. */
271 /* Followed by nentries * struct got_imsg_tree_entry */
272 };
274 /* Structure for GOT_IMSG_TREE_OBJECT_REPLY data. */
275 struct got_imsg_tree_object {
276 int nentries; /* This many tree entries follow. */
277 };
279 /* Structure for GOT_IMSG_BLOB. */
280 struct got_imsg_blob {
281 size_t size;
282 size_t hdrlen;
284 /*
285 * If size <= GOT_PRIVSEP_INLINE_BLOB_DATA_MAX, blob data follows
286 * in the imsg buffer. Otherwise, blob data has been written to a
287 * file descriptor passed via the GOT_IMSG_BLOB_OUTFD imsg.
288 */
289 #define GOT_PRIVSEP_INLINE_BLOB_DATA_MAX \
290 (MAX_IMSGSIZE - IMSG_HEADER_SIZE - sizeof(struct got_imsg_blob))
291 };
293 /* Structure for GOT_IMSG_RAW_OBJECT. */
294 struct got_imsg_raw_obj {
295 off_t size;
296 size_t hdrlen;
298 /*
299 * If size <= GOT_PRIVSEP_INLINE_OBJECT_DATA_MAX, object data follows
300 * in the imsg buffer. Otherwise, object data has been written to a
301 * file descriptor passed via the GOT_IMSG_RAW_OBJECT_OUTFD imsg.
302 */
303 #define GOT_PRIVSEP_INLINE_OBJECT_DATA_MAX \
304 (MAX_IMSGSIZE - IMSG_HEADER_SIZE - sizeof(struct got_imsg_raw_obj))
305 };
307 /* Structure for GOT_IMSG_RAW_DELTA. */
308 struct got_imsg_raw_delta {
309 struct got_object_id base_id;
310 uint64_t base_size;
311 uint64_t result_size;
312 off_t delta_size;
313 off_t delta_compressed_size;
314 off_t delta_offset;
315 off_t delta_out_offset;
317 /*
318 * Delta data has been written at delta_out_offset to the file
319 * descriptor passed via the GOT_IMSG_RAW_DELTA_OUTFD imsg.
320 */
321 };
323 /* Structures for GOT_IMSG_REUSED_DELTAS. */
324 struct got_imsg_reused_delta {
325 struct got_object_id id;
326 struct got_object_id base_id;
327 uint64_t base_size;
328 uint64_t result_size;
329 off_t delta_size;
330 off_t delta_compressed_size;
331 off_t delta_offset;
332 };
333 struct got_imsg_reused_deltas {
334 size_t ndeltas;
336 /*
337 * Followed by ndeltas * struct got_imsg_reused_delta.
338 */
340 #define GOT_IMSG_REUSED_DELTAS_MAX_NDELTAS \
341 ((MAX_IMSGSIZE - IMSG_HEADER_SIZE - \
342 sizeof(struct got_imsg_reused_deltas)) \
343 / sizeof(struct got_imsg_reused_delta))
344 };
346 /* Structure for GOT_IMSG_COMMIT_PAINTING_REQUEST. */
347 struct got_imsg_commit_painting_request {
348 uint8_t id[SHA1_DIGEST_LENGTH];
349 int idx;
350 int color;
351 } __attribute__((__packed__));
353 /* Structure for GOT_IMSG_PAINTED_COMMITS. */
354 struct got_imsg_painted_commit {
355 uint8_t id[SHA1_DIGEST_LENGTH];
356 intptr_t color;
357 } __attribute__((__packed__));
359 struct got_imsg_painted_commits {
360 int ncommits;
361 int present_in_pack;
362 /*
363 * Followed by ncommits * struct got_imsg_painted_commit.
364 */
365 } __attribute__((__packed__));
367 /* Structure for GOT_IMSG_TAG data. */
368 struct got_imsg_tag_object {
369 uint8_t id[SHA1_DIGEST_LENGTH];
370 int obj_type;
371 size_t tag_len;
372 size_t tagger_len;
373 time_t tagger_time;
374 time_t tagger_gmtoff;
375 size_t tagmsg_len;
377 /*
378 * Followed by tag_len + tagger_len data bytes
379 */
381 /*
382 * Followed by 'tagmsg_len' bytes of tag message data in
383 * one or more GOT_IMSG_TAG_TAGMSG messages.
384 */
385 } __attribute__((__packed__));
387 /* Structure for GOT_IMSG_FETCH_HAVE_REF data. */
388 struct got_imsg_fetch_have_ref {
389 struct got_object_id id;
390 size_t name_len;
391 /* Followed by name_len data bytes. */
392 } __attribute__((__packed__));
394 /* Structure for GOT_IMSG_FETCH_WANTED_BRANCH data. */
395 struct got_imsg_fetch_wanted_branch {
396 size_t name_len;
397 /* Followed by name_len data bytes. */
398 } __attribute__((__packed__));
400 /* Structure for GOT_IMSG_FETCH_WANTED_REF data. */
401 struct got_imsg_fetch_wanted_ref {
402 size_t name_len;
403 /* Followed by name_len data bytes. */
404 } __attribute__((__packed__));
406 /* Structure for GOT_IMSG_FETCH_REQUEST data. */
407 struct got_imsg_fetch_request {
408 int fetch_all_branches;
409 int list_refs_only;
410 int verbosity;
411 size_t worktree_branch_len;
412 size_t n_have_refs;
413 size_t n_wanted_branches;
414 size_t n_wanted_refs;
415 /* Followed by worktree_branch_len bytes of reference name. */
416 /* Followed by n_have_refs GOT_IMSG_FETCH_HAVE_REF messages. */
417 /* Followed by n_wanted_branches times GOT_IMSG_FETCH_WANTED_BRANCH. */
418 /* Followed by n_wanted_refs times GOT_IMSG_FETCH_WANTED_REF. */
419 } __attribute__((__packed__));
421 /* Structures for GOT_IMSG_FETCH_SYMREFS data. */
422 struct got_imsg_fetch_symref {
423 size_t name_len;
424 size_t target_len;
426 /*
427 * Followed by name_len + target_len data bytes.
428 */
429 } __attribute__((__packed__));
431 struct got_imsg_fetch_symrefs {
432 size_t nsymrefs;
434 /* Followed by nsymrefs times of got_imsg_fetch_symref data. */
435 } __attribute__((__packed__));
437 /* Structure for GOT_IMSG_FETCH_REF data. */
438 struct got_imsg_fetch_ref {
439 /* Describes a reference which will be fetched. */
440 struct got_object_id refid;
441 /* Followed by reference name in remaining data of imsg buffer. */
442 };
444 /* Structure for GOT_IMSG_FETCH_DOWNLOAD_PROGRESS data. */
445 struct got_imsg_fetch_download_progress {
446 /* Number of packfile data bytes downloaded so far. */
447 off_t packfile_bytes;
448 };
450 /* Structure for GOT_IMSG_SEND_REQUEST data. */
451 struct got_imsg_send_request {
452 int verbosity;
453 size_t nrefs;
454 /* Followed by nrefs GOT_IMSG_SEND_REF messages. */
455 } __attribute__((__packed__));
457 /* Structure for GOT_IMSG_SEND_UPLOAD_PROGRESS data. */
458 struct got_imsg_send_upload_progress {
459 /* Number of packfile data bytes uploaded so far. */
460 off_t packfile_bytes;
461 };
463 /* Structure for GOT_IMSG_SEND_REF data. */
464 struct got_imsg_send_ref {
465 struct got_object_id id;
466 int delete;
467 size_t name_len;
468 /* Followed by name_len data bytes. */
469 } __attribute__((__packed__));
471 /* Structure for GOT_IMSG_SEND_REMOTE_REF data. */
472 struct got_imsg_send_remote_ref {
473 struct got_object_id id;
474 size_t name_len;
475 /* Followed by name_len data bytes. */
476 } __attribute__((__packed__));
478 /* Structure for GOT_IMSG_SEND_REF_STATUS data. */
479 struct got_imsg_send_ref_status {
480 int success;
481 size_t name_len;
482 size_t errmsg_len;
483 /* Followed by name_len data bytes. */
484 /* Followed by errmsg_len data bytes. */
485 } __attribute__((__packed__));
487 /* Structure for GOT_IMSG_IDXPACK_REQUEST data. */
488 struct got_imsg_index_pack_request {
489 uint8_t pack_hash[SHA1_DIGEST_LENGTH];
490 } __attribute__((__packed__));
492 /* Structure for GOT_IMSG_IDXPACK_PROGRESS data. */
493 struct got_imsg_index_pack_progress {
494 /* Total number of objects in pack file. */
495 int nobj_total;
497 /* Number of objects indexed so far. */
498 int nobj_indexed;
500 /* Number of non-deltified objects in pack file. */
501 int nobj_loose;
503 /* Number of deltified objects resolved so far. */
504 int nobj_resolved;
505 };
507 /* Structure for GOT_IMSG_PACKIDX. */
508 struct got_imsg_packidx {
509 size_t len;
510 off_t packfile_size;
511 int algo;
512 /* Additionally, a file desciptor is passed via imsg. */
513 };
515 /* Structure for GOT_IMSG_PACK. */
516 struct got_imsg_pack {
517 char path_packfile[PATH_MAX];
518 off_t filesize;
519 int algo;
520 /* Additionally, a file desciptor is passed via imsg. */
521 } __attribute__((__packed__));
523 /*
524 * Structure for GOT_IMSG_OBJECT_REQUEST, GOT_IMSG_BLOB_REQUEST,
525 * GOT_IMSG_TREE_REQUEST, GOT_IMSG_COMMIT_REQUEST, and
526 * GOT_IMSG_TAG_REQUEST data.
527 */
528 struct got_object_id;
530 /*
531 * Structure for GOT_IMSG_PACKED_OBJECT_REQUEST and
532 * GOT_IMSG_PACKED_RAW_OBJECT_REQUEST data.
533 */
534 struct got_imsg_packed_object {
535 struct got_object_id id;
536 int idx;
537 } __attribute__((__packed__));
539 /*
540 * Structure for GOT_IMSG_DELTA data.
541 */
542 struct got_imsg_delta {
543 /* These fields are the same as in struct got_delta. */
544 off_t offset;
545 size_t tslen;
546 int type;
547 size_t size;
548 off_t data_offset;
549 };
551 /*
552 * Structure for GOT_IMSG_RAW_DELTA_REQUEST data.
553 */
554 struct got_imsg_raw_delta_request {
555 struct got_object_id id;
556 int idx;
557 };
559 /*
560 * Structure for GOT_IMSG_OBJ_ID_LIST data.
561 * Multiple such messages may be sent back-to-back, where each message
562 * contains a chunk of IDs. The entire list must be terminated with a
563 * GOT_IMSG_OBJ_ID_LIST_DONE message.
564 */
565 struct got_imsg_object_idlist {
566 size_t nids;
568 /*
569 * Followed by nids * struct got_object_id.
570 */
572 #define GOT_IMSG_OBJ_ID_LIST_MAX_NIDS \
573 ((MAX_IMSGSIZE - IMSG_HEADER_SIZE - \
574 sizeof(struct got_imsg_object_idlist)) / sizeof(struct got_object_id))
575 };
577 /* Structure for GOT_IMSG_COMMIT_TRAVERSAL_REQUEST */
578 struct got_imsg_commit_traversal_request {
579 uint8_t id[SHA1_DIGEST_LENGTH];
580 int idx;
581 size_t path_len;
582 /* Followed by path_len bytes of path data */
583 } __attribute__((__packed__));
585 /* Structure for GOT_IMSG_TRAVERSED_COMMITS */
586 struct got_imsg_traversed_commits {
587 size_t ncommits;
588 /* Followed by ncommit IDs of SHA1_DIGEST_LENGTH each */
589 } __attribute__((__packed__));
591 /* Structure for GOT_IMSG_ENUMERATED_COMMIT */
592 struct got_imsg_enumerated_commit {
593 uint8_t id[SHA1_DIGEST_LENGTH];
594 time_t mtime;
595 } __attribute__((__packed__));
597 /* Structure for GOT_IMSG_ENUMERATED_TREE */
598 struct got_imsg_enumerated_tree {
599 uint8_t id[SHA1_DIGEST_LENGTH]; /* tree ID */
600 int nentries; /* number of tree entries */
602 /* Followed by tree's path in remaining data of imsg buffer. */
604 /* Followed by nentries * GOT_IMSG_TREE_ENTRY messages. */
605 } __attribute__((__packed__));
607 /*
608 * Structure for GOT_IMSG_GOTCONFIG_REMOTE and
609 * GOT_IMSG_GOTCONFIG_REMOTE data.
610 */
611 struct got_imsg_remote {
612 size_t name_len;
613 size_t fetch_url_len;
614 size_t send_url_len;
615 int mirror_references;
616 int fetch_all_branches;
617 int nfetch_branches;
618 int nsend_branches;
619 int nfetch_refs;
621 /* Followed by name_len data bytes. */
622 /* Followed by fetch_url_len + send_url_len data bytes. */
623 /* Followed by nfetch_branches GOT_IMSG_GITCONFIG_STR_VAL messages. */
624 /* Followed by nsend_branches GOT_IMSG_GITCONFIG_STR_VAL messages. */
625 /* Followed by nfetch_refs GOT_IMSG_GITCONFIG_STR_VAL messages. */
626 } __attribute__((__packed__));
628 /*
629 * Structure for GOT_IMSG_GITCONFIG_REMOTES data.
630 */
631 struct got_imsg_remotes {
632 int nremotes; /* This many GOT_IMSG_GITCONFIG_REMOTE messages follow. */
633 };
635 /*
636 * Structure for GOT_IMSG_GITCONFIG_PAIR.
637 */
638 struct got_imsg_gitconfig_pair {
639 size_t klen;
640 size_t vlen;
641 /* Followed by klen data bytes of key string. */
642 /* Followed by vlen data bytes of value string. */
643 };
645 /*
646 * Structure for GOT_IMSG_PATCH data.
647 */
648 struct got_imsg_patch {
649 int git;
650 int xbit;
651 char old[PATH_MAX];
652 char new[PATH_MAX];
653 char cid[41];
654 char blob[41];
655 };
657 /*
658 * Structure for GOT_IMSG_PATCH_HUNK data.
659 */
660 struct got_imsg_patch_hunk {
661 int oldfrom;
662 int oldlines;
663 int newfrom;
664 int newlines;
665 };
667 struct got_remote_repo;
668 struct got_pack;
669 struct got_packidx;
670 struct got_pathlist_head;
672 const struct got_error *got_send_ack(pid_t);
673 const struct got_error *got_privsep_wait_for_child(pid_t);
674 const struct got_error *got_privsep_flush_imsg(struct imsgbuf *);
675 const struct got_error *got_privsep_send_stop(int);
676 const struct got_error *got_privsep_recv_imsg(struct imsg *, struct imsgbuf *,
677 size_t);
678 void got_privsep_send_error(struct imsgbuf *, const struct got_error *);
679 const struct got_error *got_privsep_send_ack(struct imsgbuf *);
680 const struct got_error *got_privsep_wait_ack(struct imsgbuf *);
681 const struct got_error *got_privsep_send_obj_req(struct imsgbuf *, int,
682 struct got_object_id *);
683 const struct got_error *got_privsep_send_raw_obj_req(struct imsgbuf *, int,
684 struct got_object_id *);
685 const struct got_error *got_privsep_send_raw_obj_outfd(struct imsgbuf *, int);
686 const struct got_error *got_privsep_send_commit_req(struct imsgbuf *, int,
687 struct got_object_id *, int);
688 const struct got_error *got_privsep_send_tree_req(struct imsgbuf *, int,
689 struct got_object_id *, int);
690 const struct got_error *got_privsep_send_tag_req(struct imsgbuf *, int,
691 struct got_object_id *, int);
692 const struct got_error *got_privsep_send_blob_req(struct imsgbuf *, int,
693 struct got_object_id *, int);
694 const struct got_error *got_privsep_send_blob_outfd(struct imsgbuf *, int);
695 const struct got_error *got_privsep_send_tmpfd(struct imsgbuf *, int);
696 const struct got_error *got_privsep_send_obj(struct imsgbuf *,
697 struct got_object *);
698 const struct got_error *got_privsep_send_index_pack_req(struct imsgbuf *,
699 uint8_t *, int);
700 const struct got_error *got_privsep_send_index_pack_outfd(struct imsgbuf *,
701 int);
702 const struct got_error *got_privsep_recv_index_progress(int *, int *, int *,
703 int *, int *, struct imsgbuf *ibuf);
704 const struct got_error *got_privsep_send_fetch_req(struct imsgbuf *, int,
705 struct got_pathlist_head *, int, struct got_pathlist_head *,
706 struct got_pathlist_head *, int, const char *, int);
707 const struct got_error *got_privsep_send_fetch_outfd(struct imsgbuf *, int);
708 const struct got_error *got_privsep_recv_fetch_progress(int *,
709 struct got_object_id **, char **, struct got_pathlist_head *, char **,
710 off_t *, uint8_t *, struct imsgbuf *);
711 const struct got_error *got_privsep_send_send_req(struct imsgbuf *, int,
712 struct got_pathlist_head *, struct got_pathlist_head *, int);
713 const struct got_error *got_privsep_recv_send_remote_refs(
714 struct got_pathlist_head *, struct imsgbuf *);
715 const struct got_error *got_privsep_send_packfd(struct imsgbuf *, int);
716 const struct got_error *got_privsep_recv_send_progress(int *, off_t *,
717 int *, char **, char **, struct imsgbuf *);
718 const struct got_error *got_privsep_get_imsg_obj(struct got_object **,
719 struct imsg *, struct imsgbuf *);
720 const struct got_error *got_privsep_recv_obj(struct got_object **,
721 struct imsgbuf *);
722 const struct got_error *got_privsep_send_raw_obj(struct imsgbuf *, off_t,
723 size_t, uint8_t *);
724 const struct got_error *got_privsep_recv_raw_obj(uint8_t **, off_t *, size_t *,
725 struct imsgbuf *);
726 const struct got_error *got_privsep_send_commit(struct imsgbuf *,
727 struct got_commit_object *);
728 const struct got_error *got_privsep_recv_commit(struct got_commit_object **,
729 struct imsgbuf *);
730 const struct got_error *got_privsep_recv_tree(struct got_tree_object **,
731 struct imsgbuf *);
732 struct got_parsed_tree_entry;
733 const struct got_error *got_privsep_send_tree(struct imsgbuf *,
734 struct got_parsed_tree_entry *, int);
735 const struct got_error *got_privsep_send_blob(struct imsgbuf *, size_t, size_t,
736 const uint8_t *);
737 const struct got_error *got_privsep_recv_blob(uint8_t **, size_t *, size_t *,
738 struct imsgbuf *);
739 const struct got_error *got_privsep_send_tag(struct imsgbuf *,
740 struct got_tag_object *);
741 const struct got_error *got_privsep_recv_tag(struct got_tag_object **,
742 struct imsgbuf *);
743 const struct got_error *got_privsep_init_pack_child(struct imsgbuf *,
744 struct got_pack *, struct got_packidx *);
745 const struct got_error *got_privsep_send_packed_obj_req(struct imsgbuf *, int,
746 struct got_object_id *);
747 const struct got_error *got_privsep_send_packed_raw_obj_req(struct imsgbuf *,
748 int, struct got_object_id *);
749 const struct got_error *got_privsep_send_pack_child_ready(struct imsgbuf *);
751 const struct got_error *got_privsep_send_gitconfig_parse_req(struct imsgbuf *,
752 int);
753 const struct got_error *
754 got_privsep_send_gitconfig_repository_format_version_req(struct imsgbuf *);
755 const struct got_error *got_privsep_send_gitconfig_repository_extensions_req(
756 struct imsgbuf *);
757 const struct got_error *got_privsep_send_gitconfig_author_name_req(
758 struct imsgbuf *);
759 const struct got_error *got_privsep_send_gitconfig_author_email_req(
760 struct imsgbuf *);
761 const struct got_error *got_privsep_send_gitconfig_remotes_req(
762 struct imsgbuf *);
763 const struct got_error *got_privsep_send_gitconfig_owner_req(struct imsgbuf *);
764 const struct got_error *got_privsep_recv_gitconfig_str(char **,
765 struct imsgbuf *);
766 const struct got_error *got_privsep_recv_gitconfig_pair(char **, char **,
767 struct imsgbuf *);
768 const struct got_error *got_privsep_recv_gitconfig_int(int *, struct imsgbuf *);
769 const struct got_error *got_privsep_recv_gitconfig_remotes(
770 struct got_remote_repo **, int *, struct imsgbuf *);
772 const struct got_error *got_privsep_send_gotconfig_parse_req(struct imsgbuf *,
773 int);
774 const struct got_error *got_privsep_send_gotconfig_author_req(struct imsgbuf *);
775 const struct got_error *got_privsep_send_gotconfig_allowed_signers_req(
776 struct imsgbuf *);
777 const struct got_error *got_privsep_send_gotconfig_revoked_signers_req(
778 struct imsgbuf *);
779 const struct got_error *got_privsep_send_gotconfig_signer_id_req(
780 struct imsgbuf *);
781 const struct got_error *got_privsep_send_gotconfig_remotes_req(
782 struct imsgbuf *);
783 const struct got_error *got_privsep_recv_gotconfig_str(char **,
784 struct imsgbuf *);
785 const struct got_error *got_privsep_recv_gotconfig_remotes(
786 struct got_remote_repo **, int *, struct imsgbuf *);
788 const struct got_error *got_privsep_send_commit_traversal_request(
789 struct imsgbuf *, struct got_object_id *, int, const char *);
790 const struct got_error *got_privsep_recv_traversed_commits(
791 struct got_commit_object **, struct got_object_id **,
792 struct got_object_id_queue *, struct imsgbuf *);
793 const struct got_error *got_privsep_send_enumerated_tree(size_t *,
794 struct imsgbuf *, struct got_object_id *, const char *,
795 struct got_parsed_tree_entry *, int);
796 const struct got_error *got_privsep_send_object_enumeration_request(
797 struct imsgbuf *);
798 const struct got_error *got_privsep_send_object_enumeration_done(
799 struct imsgbuf *);
800 const struct got_error *got_privsep_send_object_enumeration_incomplete(
801 struct imsgbuf *);
802 const struct got_error *got_privsep_send_enumerated_commit(struct imsgbuf *,
803 struct got_object_id *, time_t);
804 const struct got_error *got_privsep_recv_enumerated_objects(int *,
805 struct imsgbuf *, got_object_enumerate_commit_cb,
806 got_object_enumerate_tree_cb, void *, struct got_repository *);
808 const struct got_error *got_privsep_send_raw_delta_req(struct imsgbuf *, int,
809 struct got_object_id *);
810 const struct got_error *got_privsep_send_raw_delta_outfd(struct imsgbuf *, int);
811 const struct got_error *got_privsep_send_raw_delta(struct imsgbuf *, uint64_t,
812 uint64_t, off_t, off_t, off_t, off_t, struct got_object_id *);
813 const struct got_error *got_privsep_recv_raw_delta(uint64_t *, uint64_t *,
814 off_t *, off_t *, off_t *, off_t *, struct got_object_id **,
815 struct imsgbuf *);
817 const struct got_error *got_privsep_send_object_idlist(struct imsgbuf *,
818 struct got_object_id **, size_t);
819 const struct got_error *got_privsep_send_object_idlist_done(struct imsgbuf *);
820 const struct got_error *got_privsep_recv_object_idlist(int *,
821 struct got_object_id **, size_t *, struct imsgbuf *);
823 const struct got_error *got_privsep_send_delta_reuse_req(struct imsgbuf *);
824 const struct got_error *got_privsep_send_reused_deltas(struct imsgbuf *,
825 struct got_imsg_reused_delta *, size_t);
826 const struct got_error *got_privsep_send_reused_deltas_done(struct imsgbuf *);
827 const struct got_error *got_privsep_recv_reused_deltas(int *,
828 struct got_imsg_reused_delta *, size_t *, struct imsgbuf *);
830 const struct got_error *got_privsep_init_commit_painting(struct imsgbuf *);
831 const struct got_error *got_privsep_send_painting_request(struct imsgbuf *,
832 int, struct got_object_id *, intptr_t);
833 typedef const struct got_error *(*got_privsep_recv_painted_commit_cb)(void *,
834 struct got_object_id *, intptr_t);
835 const struct got_error *got_privsep_send_painted_commits(struct imsgbuf *,
836 struct got_object_id_queue *, int *, int, int);
837 const struct got_error *got_privsep_send_painting_commits_done(struct imsgbuf *);
838 const struct got_error *got_privsep_recv_painted_commits(
839 struct got_object_id_queue *, got_privsep_recv_painted_commit_cb, void *,
840 struct imsgbuf *);
842 void got_privsep_exec_child(int[2], const char *, const char *);