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/local/bin
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[SHA1_DIGEST_LENGTH];
261 mode_t mode;
262 size_t namelen;
263 /* Followed by namelen bytes of entry's name, not NUL-terminated. */
264 } __attribute__((__packed__));
266 /* Structure for GOT_IMSG_TREE_ENTRIES. */
267 struct got_imsg_tree_entries {
268 size_t nentries; /* Number of tree entries contained in this message. */
270 /* Followed by nentries * struct got_imsg_tree_entry */
271 };
273 /* Structure for GOT_IMSG_TREE_OBJECT_REPLY data. */
274 struct got_imsg_tree_object {
275 int nentries; /* This many tree entries follow. */
276 };
278 /* Structure for GOT_IMSG_BLOB. */
279 struct got_imsg_blob {
280 size_t size;
281 size_t hdrlen;
283 /*
284 * If size <= GOT_PRIVSEP_INLINE_BLOB_DATA_MAX, blob data follows
285 * in the imsg buffer. Otherwise, blob data has been written to a
286 * file descriptor passed via the GOT_IMSG_BLOB_OUTFD imsg.
287 */
288 #define GOT_PRIVSEP_INLINE_BLOB_DATA_MAX \
289 (MAX_IMSGSIZE - IMSG_HEADER_SIZE - sizeof(struct got_imsg_blob))
290 };
292 /* Structure for GOT_IMSG_RAW_OBJECT. */
293 struct got_imsg_raw_obj {
294 off_t size;
295 size_t hdrlen;
297 /*
298 * If size <= GOT_PRIVSEP_INLINE_OBJECT_DATA_MAX, object data follows
299 * in the imsg buffer. Otherwise, object data has been written to a
300 * file descriptor passed via the GOT_IMSG_RAW_OBJECT_OUTFD imsg.
301 */
302 #define GOT_PRIVSEP_INLINE_OBJECT_DATA_MAX \
303 (MAX_IMSGSIZE - IMSG_HEADER_SIZE - sizeof(struct got_imsg_raw_obj))
304 };
306 /* Structure for GOT_IMSG_RAW_DELTA. */
307 struct got_imsg_raw_delta {
308 struct got_object_id base_id;
309 uint64_t base_size;
310 uint64_t result_size;
311 off_t delta_size;
312 off_t delta_compressed_size;
313 off_t delta_offset;
314 off_t delta_out_offset;
316 /*
317 * Delta data has been written at delta_out_offset to the file
318 * descriptor passed via the GOT_IMSG_RAW_DELTA_OUTFD imsg.
319 */
320 };
322 /* Structures for GOT_IMSG_REUSED_DELTAS. */
323 struct got_imsg_reused_delta {
324 struct got_object_id id;
325 struct got_object_id base_id;
326 uint64_t base_size;
327 uint64_t result_size;
328 off_t delta_size;
329 off_t delta_compressed_size;
330 off_t delta_offset;
331 };
332 struct got_imsg_reused_deltas {
333 size_t ndeltas;
335 /*
336 * Followed by ndeltas * struct got_imsg_reused_delta.
337 */
339 #define GOT_IMSG_REUSED_DELTAS_MAX_NDELTAS \
340 ((MAX_IMSGSIZE - IMSG_HEADER_SIZE - \
341 sizeof(struct got_imsg_reused_deltas)) \
342 / sizeof(struct got_imsg_reused_delta))
343 };
345 /* Structure for GOT_IMSG_COMMIT_PAINTING_REQUEST. */
346 struct got_imsg_commit_painting_request {
347 uint8_t id[SHA1_DIGEST_LENGTH];
348 int idx;
349 int color;
350 } __attribute__((__packed__));
352 /* Structure for GOT_IMSG_PAINTED_COMMITS. */
353 struct got_imsg_painted_commit {
354 uint8_t id[SHA1_DIGEST_LENGTH];
355 intptr_t color;
356 } __attribute__((__packed__));
358 struct got_imsg_painted_commits {
359 int ncommits;
360 int present_in_pack;
361 /*
362 * Followed by ncommits * struct got_imsg_painted_commit.
363 */
364 } __attribute__((__packed__));
366 /* Structure for GOT_IMSG_TAG data. */
367 struct got_imsg_tag_object {
368 uint8_t id[SHA1_DIGEST_LENGTH];
369 int obj_type;
370 size_t tag_len;
371 size_t tagger_len;
372 time_t tagger_time;
373 time_t tagger_gmtoff;
374 size_t tagmsg_len;
376 /*
377 * Followed by tag_len + tagger_len data bytes
378 */
380 /*
381 * Followed by 'tagmsg_len' bytes of tag message data in
382 * one or more GOT_IMSG_TAG_TAGMSG messages.
383 */
384 } __attribute__((__packed__));
386 /* Structure for GOT_IMSG_FETCH_HAVE_REF data. */
387 struct got_imsg_fetch_have_ref {
388 struct got_object_id id;
389 size_t name_len;
390 /* Followed by name_len data bytes. */
391 } __attribute__((__packed__));
393 /* Structure for GOT_IMSG_FETCH_WANTED_BRANCH data. */
394 struct got_imsg_fetch_wanted_branch {
395 size_t name_len;
396 /* Followed by name_len data bytes. */
397 } __attribute__((__packed__));
399 /* Structure for GOT_IMSG_FETCH_WANTED_REF data. */
400 struct got_imsg_fetch_wanted_ref {
401 size_t name_len;
402 /* Followed by name_len data bytes. */
403 } __attribute__((__packed__));
405 /* Structure for GOT_IMSG_FETCH_REQUEST data. */
406 struct got_imsg_fetch_request {
407 int fetch_all_branches;
408 int list_refs_only;
409 int verbosity;
410 size_t worktree_branch_len;
411 size_t n_have_refs;
412 size_t n_wanted_branches;
413 size_t n_wanted_refs;
414 /* Followed by worktree_branch_len bytes of reference name. */
415 /* Followed by n_have_refs GOT_IMSG_FETCH_HAVE_REF messages. */
416 /* Followed by n_wanted_branches times GOT_IMSG_FETCH_WANTED_BRANCH. */
417 /* Followed by n_wanted_refs times GOT_IMSG_FETCH_WANTED_REF. */
418 } __attribute__((__packed__));
420 /* Structures for GOT_IMSG_FETCH_SYMREFS data. */
421 struct got_imsg_fetch_symref {
422 size_t name_len;
423 size_t target_len;
425 /*
426 * Followed by name_len + target_len data bytes.
427 */
428 } __attribute__((__packed__));
430 struct got_imsg_fetch_symrefs {
431 size_t nsymrefs;
433 /* Followed by nsymrefs times of got_imsg_fetch_symref data. */
434 } __attribute__((__packed__));
436 /* Structure for GOT_IMSG_FETCH_REF data. */
437 struct got_imsg_fetch_ref {
438 /* Describes a reference which will be fetched. */
439 struct got_object_id refid;
440 /* Followed by reference name in remaining data of imsg buffer. */
441 };
443 /* Structure for GOT_IMSG_FETCH_DOWNLOAD_PROGRESS data. */
444 struct got_imsg_fetch_download_progress {
445 /* Number of packfile data bytes downloaded so far. */
446 off_t packfile_bytes;
447 };
449 /* Structure for GOT_IMSG_SEND_REQUEST data. */
450 struct got_imsg_send_request {
451 int verbosity;
452 size_t nrefs;
453 /* Followed by nrefs GOT_IMSG_SEND_REF messages. */
454 } __attribute__((__packed__));
456 /* Structure for GOT_IMSG_SEND_UPLOAD_PROGRESS data. */
457 struct got_imsg_send_upload_progress {
458 /* Number of packfile data bytes uploaded so far. */
459 off_t packfile_bytes;
460 };
462 /* Structure for GOT_IMSG_SEND_REF data. */
463 struct got_imsg_send_ref {
464 struct got_object_id id;
465 int delete;
466 size_t name_len;
467 /* Followed by name_len data bytes. */
468 } __attribute__((__packed__));
470 /* Structure for GOT_IMSG_SEND_REMOTE_REF data. */
471 struct got_imsg_send_remote_ref {
472 struct got_object_id id;
473 size_t name_len;
474 /* Followed by name_len data bytes. */
475 } __attribute__((__packed__));
477 /* Structure for GOT_IMSG_SEND_REF_STATUS data. */
478 struct got_imsg_send_ref_status {
479 int success;
480 size_t name_len;
481 size_t errmsg_len;
482 /* Followed by name_len data bytes. */
483 /* Followed by errmsg_len data bytes. */
484 } __attribute__((__packed__));
486 /* Structure for GOT_IMSG_IDXPACK_REQUEST data. */
487 struct got_imsg_index_pack_request {
488 uint8_t pack_hash[SHA1_DIGEST_LENGTH];
489 } __attribute__((__packed__));
491 /* Structure for GOT_IMSG_IDXPACK_PROGRESS data. */
492 struct got_imsg_index_pack_progress {
493 /* Total number of objects in pack file. */
494 int nobj_total;
496 /* Number of objects indexed so far. */
497 int nobj_indexed;
499 /* Number of non-deltified objects in pack file. */
500 int nobj_loose;
502 /* Number of deltified objects resolved so far. */
503 int nobj_resolved;
504 };
506 /* Structure for GOT_IMSG_PACKIDX. */
507 struct got_imsg_packidx {
508 size_t len;
509 off_t packfile_size;
510 /* Additionally, a file desciptor is passed via imsg. */
511 };
513 /* Structure for GOT_IMSG_PACK. */
514 struct got_imsg_pack {
515 char path_packfile[PATH_MAX];
516 off_t filesize;
517 /* Additionally, a file desciptor is passed via imsg. */
518 } __attribute__((__packed__));
520 /*
521 * Structure for GOT_IMSG_OBJECT_REQUEST, GOT_IMSG_BLOB_REQUEST,
522 * GOT_IMSG_TREE_REQUEST, GOT_IMSG_COMMIT_REQUEST, and
523 * GOT_IMSG_TAG_REQUEST data.
524 */
525 struct got_object_id;
527 /*
528 * Structure for GOT_IMSG_PACKED_OBJECT_REQUEST and
529 * GOT_IMSG_PACKED_RAW_OBJECT_REQUEST data.
530 */
531 struct got_imsg_packed_object {
532 struct got_object_id id;
533 int idx;
534 } __attribute__((__packed__));
536 /*
537 * Structure for GOT_IMSG_DELTA data.
538 */
539 struct got_imsg_delta {
540 /* These fields are the same as in struct got_delta. */
541 off_t offset;
542 size_t tslen;
543 int type;
544 size_t size;
545 off_t data_offset;
546 };
548 /*
549 * Structure for GOT_IMSG_RAW_DELTA_REQUEST data.
550 */
551 struct got_imsg_raw_delta_request {
552 struct got_object_id id;
553 int idx;
554 };
556 /*
557 * Structure for GOT_IMSG_OBJ_ID_LIST data.
558 * Multiple such messages may be sent back-to-back, where each message
559 * contains a chunk of IDs. The entire list must be terminated with a
560 * GOT_IMSG_OBJ_ID_LIST_DONE message.
561 */
562 struct got_imsg_object_idlist {
563 size_t nids;
565 /*
566 * Followed by nids * struct got_object_id.
567 */
569 #define GOT_IMSG_OBJ_ID_LIST_MAX_NIDS \
570 ((MAX_IMSGSIZE - IMSG_HEADER_SIZE - \
571 sizeof(struct got_imsg_object_idlist)) / sizeof(struct got_object_id))
572 };
574 /* Structure for GOT_IMSG_COMMIT_TRAVERSAL_REQUEST */
575 struct got_imsg_commit_traversal_request {
576 uint8_t id[SHA1_DIGEST_LENGTH];
577 int idx;
578 size_t path_len;
579 /* Followed by path_len bytes of path data */
580 } __attribute__((__packed__));
582 /* Structure for GOT_IMSG_TRAVERSED_COMMITS */
583 struct got_imsg_traversed_commits {
584 size_t ncommits;
585 /* Followed by ncommit IDs of SHA1_DIGEST_LENGTH each */
586 } __attribute__((__packed__));
588 /* Structure for GOT_IMSG_ENUMERATED_COMMIT */
589 struct got_imsg_enumerated_commit {
590 uint8_t id[SHA1_DIGEST_LENGTH];
591 time_t mtime;
592 } __attribute__((__packed__));
594 /* Structure for GOT_IMSG_ENUMERATED_TREE */
595 struct got_imsg_enumerated_tree {
596 uint8_t id[SHA1_DIGEST_LENGTH]; /* tree ID */
597 int nentries; /* number of tree entries */
599 /* Followed by tree's path in remaining data of imsg buffer. */
601 /* Followed by nentries * GOT_IMSG_TREE_ENTRY messages. */
602 } __attribute__((__packed__));
604 /*
605 * Structure for GOT_IMSG_GOTCONFIG_REMOTE and
606 * GOT_IMSG_GOTCONFIG_REMOTE data.
607 */
608 struct got_imsg_remote {
609 size_t name_len;
610 size_t fetch_url_len;
611 size_t send_url_len;
612 int mirror_references;
613 int fetch_all_branches;
614 int nfetch_branches;
615 int nsend_branches;
616 int nfetch_refs;
618 /* Followed by name_len data bytes. */
619 /* Followed by fetch_url_len + send_url_len data bytes. */
620 /* Followed by nfetch_branches GOT_IMSG_GITCONFIG_STR_VAL messages. */
621 /* Followed by nsend_branches GOT_IMSG_GITCONFIG_STR_VAL messages. */
622 /* Followed by nfetch_refs GOT_IMSG_GITCONFIG_STR_VAL messages. */
623 } __attribute__((__packed__));
625 /*
626 * Structure for GOT_IMSG_GITCONFIG_REMOTES data.
627 */
628 struct got_imsg_remotes {
629 int nremotes; /* This many GOT_IMSG_GITCONFIG_REMOTE messages follow. */
630 };
632 /*
633 * Structure for GOT_IMSG_GITCONFIG_PAIR.
634 */
635 struct got_imsg_gitconfig_pair {
636 size_t klen;
637 size_t vlen;
638 /* Followed by klen data bytes of key string. */
639 /* Followed by vlen data bytes of value string. */
640 };
642 /*
643 * Structure for GOT_IMSG_PATCH data.
644 */
645 struct got_imsg_patch {
646 int git;
647 int xbit;
648 char old[PATH_MAX];
649 char new[PATH_MAX];
650 char cid[41];
651 char blob[41];
652 };
654 /*
655 * Structure for GOT_IMSG_PATCH_HUNK data.
656 */
657 struct got_imsg_patch_hunk {
658 int oldfrom;
659 int oldlines;
660 int newfrom;
661 int newlines;
662 };
664 struct got_remote_repo;
665 struct got_pack;
666 struct got_packidx;
667 struct got_pathlist_head;
669 const struct got_error *got_send_ack(pid_t);
670 const struct got_error *got_privsep_wait_for_child(pid_t);
671 const struct got_error *got_privsep_flush_imsg(struct imsgbuf *);
672 const struct got_error *got_privsep_send_stop(int);
673 const struct got_error *got_privsep_recv_imsg(struct imsg *, struct imsgbuf *,
674 size_t);
675 void got_privsep_send_error(struct imsgbuf *, const struct got_error *);
676 const struct got_error *got_privsep_send_ack(struct imsgbuf *);
677 const struct got_error *got_privsep_wait_ack(struct imsgbuf *);
678 const struct got_error *got_privsep_send_obj_req(struct imsgbuf *, int,
679 struct got_object_id *);
680 const struct got_error *got_privsep_send_raw_obj_req(struct imsgbuf *, int,
681 struct got_object_id *);
682 const struct got_error *got_privsep_send_raw_obj_outfd(struct imsgbuf *, int);
683 const struct got_error *got_privsep_send_commit_req(struct imsgbuf *, int,
684 struct got_object_id *, int);
685 const struct got_error *got_privsep_send_tree_req(struct imsgbuf *, int,
686 struct got_object_id *, int);
687 const struct got_error *got_privsep_send_tag_req(struct imsgbuf *, int,
688 struct got_object_id *, int);
689 const struct got_error *got_privsep_send_blob_req(struct imsgbuf *, int,
690 struct got_object_id *, int);
691 const struct got_error *got_privsep_send_blob_outfd(struct imsgbuf *, int);
692 const struct got_error *got_privsep_send_tmpfd(struct imsgbuf *, int);
693 const struct got_error *got_privsep_send_obj(struct imsgbuf *,
694 struct got_object *);
695 const struct got_error *got_privsep_send_index_pack_req(struct imsgbuf *,
696 uint8_t *, int);
697 const struct got_error *got_privsep_send_index_pack_outfd(struct imsgbuf *,
698 int);
699 const struct got_error *got_privsep_recv_index_progress(int *, int *, int *,
700 int *, int *, struct imsgbuf *ibuf);
701 const struct got_error *got_privsep_send_fetch_req(struct imsgbuf *, int,
702 struct got_pathlist_head *, int, struct got_pathlist_head *,
703 struct got_pathlist_head *, int, const char *, int);
704 const struct got_error *got_privsep_send_fetch_outfd(struct imsgbuf *, int);
705 const struct got_error *got_privsep_recv_fetch_progress(int *,
706 struct got_object_id **, char **, struct got_pathlist_head *, char **,
707 off_t *, uint8_t *, struct imsgbuf *);
708 const struct got_error *got_privsep_send_send_req(struct imsgbuf *, int,
709 struct got_pathlist_head *, struct got_pathlist_head *, int);
710 const struct got_error *got_privsep_recv_send_remote_refs(
711 struct got_pathlist_head *, struct imsgbuf *);
712 const struct got_error *got_privsep_send_packfd(struct imsgbuf *, int);
713 const struct got_error *got_privsep_recv_send_progress(int *, off_t *,
714 int *, char **, char **, struct imsgbuf *);
715 const struct got_error *got_privsep_get_imsg_obj(struct got_object **,
716 struct imsg *, struct imsgbuf *);
717 const struct got_error *got_privsep_recv_obj(struct got_object **,
718 struct imsgbuf *);
719 const struct got_error *got_privsep_send_raw_obj(struct imsgbuf *, off_t,
720 size_t, uint8_t *);
721 const struct got_error *got_privsep_recv_raw_obj(uint8_t **, off_t *, size_t *,
722 struct imsgbuf *);
723 const struct got_error *got_privsep_send_commit(struct imsgbuf *,
724 struct got_commit_object *);
725 const struct got_error *got_privsep_recv_commit(struct got_commit_object **,
726 struct imsgbuf *);
727 const struct got_error *got_privsep_recv_tree(struct got_tree_object **,
728 struct imsgbuf *);
729 struct got_parsed_tree_entry;
730 const struct got_error *got_privsep_send_tree(struct imsgbuf *,
731 struct got_parsed_tree_entry *, int);
732 const struct got_error *got_privsep_send_blob(struct imsgbuf *, size_t, size_t,
733 const uint8_t *);
734 const struct got_error *got_privsep_recv_blob(uint8_t **, size_t *, size_t *,
735 struct imsgbuf *);
736 const struct got_error *got_privsep_send_tag(struct imsgbuf *,
737 struct got_tag_object *);
738 const struct got_error *got_privsep_recv_tag(struct got_tag_object **,
739 struct imsgbuf *);
740 const struct got_error *got_privsep_init_pack_child(struct imsgbuf *,
741 struct got_pack *, struct got_packidx *);
742 const struct got_error *got_privsep_send_packed_obj_req(struct imsgbuf *, int,
743 struct got_object_id *);
744 const struct got_error *got_privsep_send_packed_raw_obj_req(struct imsgbuf *,
745 int, struct got_object_id *);
746 const struct got_error *got_privsep_send_pack_child_ready(struct imsgbuf *);
748 const struct got_error *got_privsep_send_gitconfig_parse_req(struct imsgbuf *,
749 int);
750 const struct got_error *
751 got_privsep_send_gitconfig_repository_format_version_req(struct imsgbuf *);
752 const struct got_error *got_privsep_send_gitconfig_repository_extensions_req(
753 struct imsgbuf *);
754 const struct got_error *got_privsep_send_gitconfig_author_name_req(
755 struct imsgbuf *);
756 const struct got_error *got_privsep_send_gitconfig_author_email_req(
757 struct imsgbuf *);
758 const struct got_error *got_privsep_send_gitconfig_remotes_req(
759 struct imsgbuf *);
760 const struct got_error *got_privsep_send_gitconfig_owner_req(struct imsgbuf *);
761 const struct got_error *got_privsep_recv_gitconfig_str(char **,
762 struct imsgbuf *);
763 const struct got_error *got_privsep_recv_gitconfig_pair(char **, char **,
764 struct imsgbuf *);
765 const struct got_error *got_privsep_recv_gitconfig_int(int *, struct imsgbuf *);
766 const struct got_error *got_privsep_recv_gitconfig_remotes(
767 struct got_remote_repo **, int *, struct imsgbuf *);
769 const struct got_error *got_privsep_send_gotconfig_parse_req(struct imsgbuf *,
770 int);
771 const struct got_error *got_privsep_send_gotconfig_author_req(struct imsgbuf *);
772 const struct got_error *got_privsep_send_gotconfig_allowed_signers_req(
773 struct imsgbuf *);
774 const struct got_error *got_privsep_send_gotconfig_revoked_signers_req(
775 struct imsgbuf *);
776 const struct got_error *got_privsep_send_gotconfig_signer_id_req(
777 struct imsgbuf *);
778 const struct got_error *got_privsep_send_gotconfig_remotes_req(
779 struct imsgbuf *);
780 const struct got_error *got_privsep_recv_gotconfig_str(char **,
781 struct imsgbuf *);
782 const struct got_error *got_privsep_recv_gotconfig_remotes(
783 struct got_remote_repo **, int *, struct imsgbuf *);
785 const struct got_error *got_privsep_send_commit_traversal_request(
786 struct imsgbuf *, struct got_object_id *, int, const char *);
787 const struct got_error *got_privsep_recv_traversed_commits(
788 struct got_commit_object **, struct got_object_id **,
789 struct got_object_id_queue *, struct imsgbuf *);
790 const struct got_error *got_privsep_send_enumerated_tree(size_t *,
791 struct imsgbuf *, struct got_object_id *, const char *,
792 struct got_parsed_tree_entry *, int);
793 const struct got_error *got_privsep_send_object_enumeration_request(
794 struct imsgbuf *);
795 const struct got_error *got_privsep_send_object_enumeration_done(
796 struct imsgbuf *);
797 const struct got_error *got_privsep_send_object_enumeration_incomplete(
798 struct imsgbuf *);
799 const struct got_error *got_privsep_send_enumerated_commit(struct imsgbuf *,
800 struct got_object_id *, time_t);
801 const struct got_error *got_privsep_recv_enumerated_objects(int *,
802 struct imsgbuf *, got_object_enumerate_commit_cb,
803 got_object_enumerate_tree_cb, void *, struct got_repository *);
805 const struct got_error *got_privsep_send_raw_delta_req(struct imsgbuf *, int,
806 struct got_object_id *);
807 const struct got_error *got_privsep_send_raw_delta_outfd(struct imsgbuf *, int);
808 const struct got_error *got_privsep_send_raw_delta(struct imsgbuf *, uint64_t,
809 uint64_t, off_t, off_t, off_t, off_t, struct got_object_id *);
810 const struct got_error *got_privsep_recv_raw_delta(uint64_t *, uint64_t *,
811 off_t *, off_t *, off_t *, off_t *, struct got_object_id **,
812 struct imsgbuf *);
814 const struct got_error *got_privsep_send_object_idlist(struct imsgbuf *,
815 struct got_object_id **, size_t);
816 const struct got_error *got_privsep_send_object_idlist_done(struct imsgbuf *);
817 const struct got_error *got_privsep_recv_object_idlist(int *,
818 struct got_object_id **, size_t *, struct imsgbuf *);
820 const struct got_error *got_privsep_send_delta_reuse_req(struct imsgbuf *);
821 const struct got_error *got_privsep_send_reused_deltas(struct imsgbuf *,
822 struct got_imsg_reused_delta *, size_t);
823 const struct got_error *got_privsep_send_reused_deltas_done(struct imsgbuf *);
824 const struct got_error *got_privsep_recv_reused_deltas(int *,
825 struct got_imsg_reused_delta *, size_t *, struct imsgbuf *);
827 const struct got_error *got_privsep_init_commit_painting(struct imsgbuf *);
828 const struct got_error *got_privsep_send_painting_request(struct imsgbuf *,
829 int, struct got_object_id *, intptr_t);
830 typedef const struct got_error *(*got_privsep_recv_painted_commit_cb)(void *,
831 struct got_object_id *, intptr_t);
832 const struct got_error *got_privsep_send_painted_commits(struct imsgbuf *,
833 struct got_object_id_queue *, int *, int, int);
834 const struct got_error *got_privsep_send_painting_commits_done(struct imsgbuf *);
835 const struct got_error *got_privsep_recv_painted_commits(
836 struct got_object_id_queue *, got_privsep_recv_painted_commit_cb, void *,
837 struct imsgbuf *);
839 void got_privsep_exec_child(int[2], const char *, const char *);