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 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 /* Commit coloring in got-read-pack. */
198 GOT_IMSG_COMMIT_PAINTING_INIT,
199 GOT_IMSG_COMMIT_PAINTING_REQUEST,
200 GOT_IMSG_PAINTED_COMMITS,
201 GOT_IMSG_COMMIT_PAINTING_DONE,
203 /* Transfer a list of object IDs. */
204 GOT_IMSG_OBJ_ID_LIST,
205 GOT_IMSG_OBJ_ID_LIST_DONE,
207 /* Messages related to patch files. */
208 GOT_IMSG_PATCH_FILE,
209 GOT_IMSG_PATCH_HUNK,
210 GOT_IMSG_PATCH_DONE,
211 GOT_IMSG_PATCH_LINE,
212 GOT_IMSG_PATCH,
213 GOT_IMSG_PATCH_EOF,
214 };
216 /* Structure for GOT_IMSG_ERROR. */
217 struct got_imsg_error {
218 int code; /* an error code from got_error.h */
219 int errno_code; /* in case code equals GOT_ERR_ERRNO */
220 } __attribute__((__packed__));
222 /*
223 * Structure for GOT_IMSG_TREE_REQUEST and GOT_IMSG_OBJECT data.
224 */
225 struct got_imsg_object {
226 uint8_t id[SHA1_DIGEST_LENGTH];
228 /* These fields are the same as in struct got_object. */
229 int type;
230 int flags;
231 size_t hdrlen;
232 size_t size;
233 off_t pack_offset;
234 int pack_idx;
235 } __attribute__((__packed__));
237 /* Structure for GOT_IMSG_COMMIT data. */
238 struct got_imsg_commit_object {
239 uint8_t tree_id[SHA1_DIGEST_LENGTH];
240 size_t author_len;
241 time_t author_time;
242 time_t author_gmtoff;
243 size_t committer_len;
244 time_t committer_time;
245 time_t committer_gmtoff;
246 size_t logmsg_len;
247 int nparents;
249 /*
250 * Followed by author_len + committer_len data bytes
251 */
253 /* Followed by 'nparents' SHA1_DIGEST_LENGTH length strings */
255 /*
256 * Followed by 'logmsg_len' bytes of commit log message data in
257 * one or more GOT_IMSG_COMMIT_LOGMSG messages.
258 */
259 } __attribute__((__packed__));
261 struct got_imsg_tree_entry {
262 char id[SHA1_DIGEST_LENGTH];
263 mode_t mode;
264 size_t namelen;
265 /* Followed by namelen bytes of entry's name, not NUL-terminated. */
266 } __attribute__((__packed__));
268 /* Structure for GOT_IMSG_TREE_ENTRIES. */
269 struct got_imsg_tree_entries {
270 size_t nentries; /* Number of tree entries contained in this message. */
272 /* Followed by nentries * struct got_imsg_tree_entry */
273 };
275 /* Structure for GOT_IMSG_TREE_OBJECT_REPLY data. */
276 struct got_imsg_tree_object {
277 int nentries; /* This many tree entries follow. */
278 };
280 /* Structure for GOT_IMSG_BLOB. */
281 struct got_imsg_blob {
282 size_t size;
283 size_t hdrlen;
285 /*
286 * If size <= GOT_PRIVSEP_INLINE_BLOB_DATA_MAX, blob data follows
287 * in the imsg buffer. Otherwise, blob data has been written to a
288 * file descriptor passed via the GOT_IMSG_BLOB_OUTFD imsg.
289 */
290 #define GOT_PRIVSEP_INLINE_BLOB_DATA_MAX \
291 (MAX_IMSGSIZE - IMSG_HEADER_SIZE - sizeof(struct got_imsg_blob))
292 };
294 /* Structure for GOT_IMSG_RAW_OBJECT. */
295 struct got_imsg_raw_obj {
296 off_t size;
297 size_t hdrlen;
299 /*
300 * If size <= GOT_PRIVSEP_INLINE_OBJECT_DATA_MAX, object data follows
301 * in the imsg buffer. Otherwise, object data has been written to a
302 * file descriptor passed via the GOT_IMSG_RAW_OBJECT_OUTFD imsg.
303 */
304 #define GOT_PRIVSEP_INLINE_OBJECT_DATA_MAX \
305 (MAX_IMSGSIZE - IMSG_HEADER_SIZE - sizeof(struct got_imsg_raw_obj))
306 };
308 /* Structure for GOT_IMSG_RAW_DELTA. */
309 struct got_imsg_raw_delta {
310 uint8_t base_id[SHA1_DIGEST_LENGTH];
311 uint64_t base_size;
312 uint64_t result_size;
313 off_t delta_size;
314 off_t delta_compressed_size;
315 off_t delta_offset;
316 off_t delta_out_offset;
318 /*
319 * Delta data has been written at delta_out_offset to the file
320 * descriptor passed via the GOT_IMSG_RAW_DELTA_OUTFD imsg.
321 */
322 };
324 /* Structures for GOT_IMSG_REUSED_DELTAS. */
325 struct got_imsg_reused_delta {
326 struct got_object_id id;
327 struct got_object_id base_id;
328 uint64_t base_size;
329 uint64_t result_size;
330 off_t delta_size;
331 off_t delta_compressed_size;
332 off_t delta_offset;
333 off_t delta_out_offset;
335 /*
336 * Delta data has been written at delta_out_offset to the file
337 * descriptor passed via the GOT_IMSG_RAW_DELTA_OUTFD imsg.
338 */
339 };
340 struct got_imsg_reused_deltas {
341 size_t ndeltas;
343 /*
344 * Followed by ndeltas * struct got_imsg_reused_delta.
345 */
347 #define GOT_IMSG_REUSED_DELTAS_MAX_NDELTAS \
348 ((MAX_IMSGSIZE - IMSG_HEADER_SIZE - \
349 sizeof(struct got_imsg_reused_deltas)) \
350 / sizeof(struct got_imsg_reused_delta))
351 };
353 /* Structure for GOT_IMSG_COMMIT_PAINTING_REQUEST. */
354 struct got_imsg_commit_painting_request {
355 uint8_t id[SHA1_DIGEST_LENGTH];
356 int idx;
357 int color;
358 } __attribute__((__packed__));
360 /* Structure for GOT_IMSG_PAINTED_COMMITS. */
361 struct got_imsg_painted_commit {
362 uint8_t id[SHA1_DIGEST_LENGTH];
363 intptr_t color;
364 } __attribute__((__packed__));
366 struct got_imsg_painted_commits {
367 int ncommits;
368 int present_in_pack;
369 /*
370 * Followed by ncommits * struct got_imsg_painted_commit.
371 */
372 } __attribute__((__packed__));
374 /* Structure for GOT_IMSG_TAG data. */
375 struct got_imsg_tag_object {
376 uint8_t id[SHA1_DIGEST_LENGTH];
377 int obj_type;
378 size_t tag_len;
379 size_t tagger_len;
380 time_t tagger_time;
381 time_t tagger_gmtoff;
382 size_t tagmsg_len;
384 /*
385 * Followed by tag_len + tagger_len data bytes
386 */
388 /*
389 * Followed by 'tagmsg_len' bytes of tag message data in
390 * one or more GOT_IMSG_TAG_TAGMSG messages.
391 */
392 } __attribute__((__packed__));
394 /* Structure for GOT_IMSG_FETCH_HAVE_REF data. */
395 struct got_imsg_fetch_have_ref {
396 uint8_t id[SHA1_DIGEST_LENGTH];
397 size_t name_len;
398 /* Followed by name_len data bytes. */
399 } __attribute__((__packed__));
401 /* Structure for GOT_IMSG_FETCH_WANTED_BRANCH data. */
402 struct got_imsg_fetch_wanted_branch {
403 size_t name_len;
404 /* Followed by name_len data bytes. */
405 } __attribute__((__packed__));
407 /* Structure for GOT_IMSG_FETCH_WANTED_REF data. */
408 struct got_imsg_fetch_wanted_ref {
409 size_t name_len;
410 /* Followed by name_len data bytes. */
411 } __attribute__((__packed__));
413 /* Structure for GOT_IMSG_FETCH_REQUEST data. */
414 struct got_imsg_fetch_request {
415 int fetch_all_branches;
416 int list_refs_only;
417 int verbosity;
418 size_t n_have_refs;
419 size_t n_wanted_branches;
420 size_t n_wanted_refs;
421 /* Followed by n_have_refs GOT_IMSG_FETCH_HAVE_REF messages. */
422 /* Followed by n_wanted_branches times GOT_IMSG_FETCH_WANTED_BRANCH. */
423 /* Followed by n_wanted_refs times GOT_IMSG_FETCH_WANTED_REF. */
424 } __attribute__((__packed__));
426 /* Structures for GOT_IMSG_FETCH_SYMREFS data. */
427 struct got_imsg_fetch_symref {
428 size_t name_len;
429 size_t target_len;
431 /*
432 * Followed by name_len + target_len data bytes.
433 */
434 } __attribute__((__packed__));
436 struct got_imsg_fetch_symrefs {
437 size_t nsymrefs;
439 /* Followed by nsymrefs times of got_imsg_fetch_symref data. */
440 } __attribute__((__packed__));
442 /* Structure for GOT_IMSG_FETCH_REF data. */
443 struct got_imsg_fetch_ref {
444 /* Describes a reference which will be fetched. */
445 uint8_t refid[SHA1_DIGEST_LENGTH];
446 /* Followed by reference name in remaining data of imsg buffer. */
447 };
449 /* Structure for GOT_IMSG_FETCH_DOWNLOAD_PROGRESS data. */
450 struct got_imsg_fetch_download_progress {
451 /* Number of packfile data bytes downloaded so far. */
452 off_t packfile_bytes;
453 };
455 /* Structure for GOT_IMSG_SEND_REQUEST data. */
456 struct got_imsg_send_request {
457 int verbosity;
458 size_t nrefs;
459 /* Followed by nrefs GOT_IMSG_SEND_REF messages. */
460 } __attribute__((__packed__));
462 /* Structure for GOT_IMSG_SEND_UPLOAD_PROGRESS data. */
463 struct got_imsg_send_upload_progress {
464 /* Number of packfile data bytes uploaded so far. */
465 off_t packfile_bytes;
466 };
468 /* Structure for GOT_IMSG_SEND_REF data. */
469 struct got_imsg_send_ref {
470 uint8_t id[SHA1_DIGEST_LENGTH];
471 int delete;
472 size_t name_len;
473 /* Followed by name_len data bytes. */
474 } __attribute__((__packed__));
476 /* Structure for GOT_IMSG_SEND_REMOTE_REF data. */
477 struct got_imsg_send_remote_ref {
478 uint8_t id[SHA1_DIGEST_LENGTH];
479 size_t name_len;
480 /* Followed by name_len data bytes. */
481 } __attribute__((__packed__));
483 /* Structure for GOT_IMSG_SEND_REF_STATUS data. */
484 struct got_imsg_send_ref_status {
485 int success;
486 size_t name_len;
487 /* Followed by name_len data bytes. */
488 } __attribute__((__packed__));
490 /* Structure for GOT_IMSG_IDXPACK_REQUEST data. */
491 struct got_imsg_index_pack_request {
492 uint8_t pack_hash[SHA1_DIGEST_LENGTH];
493 } __attribute__((__packed__));
495 /* Structure for GOT_IMSG_IDXPACK_PROGRESS data. */
496 struct got_imsg_index_pack_progress {
497 /* Total number of objects in pack file. */
498 int nobj_total;
500 /* Number of objects indexed so far. */
501 int nobj_indexed;
503 /* Number of non-deltified objects in pack file. */
504 int nobj_loose;
506 /* Number of deltified objects resolved so far. */
507 int nobj_resolved;
508 };
510 /* Structure for GOT_IMSG_PACKIDX. */
511 struct got_imsg_packidx {
512 size_t len;
513 off_t packfile_size;
514 /* Additionally, a file desciptor is passed via imsg. */
515 };
517 /* Structure for GOT_IMSG_PACK. */
518 struct got_imsg_pack {
519 char path_packfile[PATH_MAX];
520 size_t filesize;
521 /* Additionally, a file desciptor is passed via imsg. */
522 } __attribute__((__packed__));
524 /*
525 * Structure for GOT_IMSG_OBJECT_REQUEST, GOT_IMSG_BLOB_REQUEST,
526 * GOT_IMSG_TREE_REQUEST, GOT_IMSG_COMMIT_REQUEST, and
527 * GOT_IMSG_TAG_REQUEST data.
528 */
529 struct got_object_id;
531 /*
532 * Structure for GOT_IMSG_PACKED_OBJECT_REQUEST and
533 * GOT_IMSG_PACKED_RAW_OBJECT_REQUEST data.
534 */
535 struct got_imsg_packed_object {
536 uint8_t id[SHA1_DIGEST_LENGTH];
537 int idx;
538 } __attribute__((__packed__));
540 /*
541 * Structure for GOT_IMSG_DELTA data.
542 */
543 struct got_imsg_delta {
544 /* These fields are the same as in struct got_delta. */
545 off_t offset;
546 size_t tslen;
547 int type;
548 size_t size;
549 off_t data_offset;
550 };
552 /*
553 * Structure for GOT_IMSG_RAW_DELTA_REQUEST data.
554 */
555 struct got_imsg_raw_delta_request {
556 uint8_t id[SHA1_DIGEST_LENGTH];
557 int idx;
558 };
560 /*
561 * Structure for GOT_IMSG_OBJ_ID_LIST data.
562 * Multiple such messages may be sent back-to-back, where each message
563 * contains a chunk of IDs. The entire list must be terminated with a
564 * GOT_IMSG_OBJ_ID_LIST_DONE message.
565 */
566 struct got_imsg_object_idlist {
567 size_t nids;
569 /*
570 * Followed by nids * struct got_object_id.
571 */
573 #define GOT_IMSG_OBJ_ID_LIST_MAX_NIDS \
574 ((MAX_IMSGSIZE - IMSG_HEADER_SIZE - \
575 sizeof(struct got_imsg_object_idlist)) / sizeof(struct got_object_id))
576 };
578 /* Structure for GOT_IMSG_COMMIT_TRAVERSAL_REQUEST */
579 struct got_imsg_commit_traversal_request {
580 uint8_t id[SHA1_DIGEST_LENGTH];
581 int idx;
582 size_t path_len;
583 /* Followed by path_len bytes of path data */
584 } __attribute__((__packed__));
586 /* Structure for GOT_IMSG_TRAVERSED_COMMITS */
587 struct got_imsg_traversed_commits {
588 size_t ncommits;
589 /* Followed by ncommit IDs of SHA1_DIGEST_LENGTH each */
590 } __attribute__((__packed__));
592 /* Structure for GOT_IMSG_ENUMERATED_COMMIT */
593 struct got_imsg_enumerated_commit {
594 uint8_t id[SHA1_DIGEST_LENGTH];
595 time_t mtime;
596 } __attribute__((__packed__));
598 /* Structure for GOT_IMSG_ENUMERATED_TREE */
599 struct got_imsg_enumerated_tree {
600 uint8_t id[SHA1_DIGEST_LENGTH]; /* tree ID */
601 int nentries; /* number of tree entries */
603 /* Followed by tree's path in remaining data of imsg buffer. */
605 /* Followed by nentries * GOT_IMSG_TREE_ENTRY messages. */
606 } __attribute__((__packed__));
608 /*
609 * Structure for GOT_IMSG_GOTCONFIG_REMOTE and
610 * GOT_IMSG_GOTCONFIG_REMOTE data.
611 */
612 struct got_imsg_remote {
613 size_t name_len;
614 size_t fetch_url_len;
615 size_t send_url_len;
616 int mirror_references;
617 int fetch_all_branches;
618 int nfetch_branches;
619 int nsend_branches;
620 int nfetch_refs;
622 /* Followed by name_len data bytes. */
623 /* Followed by fetch_url_len + send_url_len data bytes. */
624 /* Followed by nfetch_branches GOT_IMSG_GITCONFIG_STR_VAL messages. */
625 /* Followed by nsend_branches GOT_IMSG_GITCONFIG_STR_VAL messages. */
626 /* Followed by nfetch_refs GOT_IMSG_GITCONFIG_STR_VAL messages. */
627 } __attribute__((__packed__));
629 /*
630 * Structure for GOT_IMSG_GITCONFIG_REMOTES data.
631 */
632 struct got_imsg_remotes {
633 int nremotes; /* This many GOT_IMSG_GITCONFIG_REMOTE messages follow. */
634 };
636 /*
637 * Structure for GOT_IMSG_PATCH data.
638 */
639 struct got_imsg_patch {
640 int git;
641 char old[PATH_MAX];
642 char new[PATH_MAX];
643 char cid[41];
644 char blob[41];
645 };
647 /*
648 * Structure for GOT_IMSG_PATCH_HUNK data.
649 */
650 struct got_imsg_patch_hunk {
651 int oldfrom;
652 int oldlines;
653 int newfrom;
654 int newlines;
655 };
657 struct got_remote_repo;
658 struct got_pack;
659 struct got_packidx;
660 struct got_pathlist_head;
662 const struct got_error *got_send_ack(pid_t);
663 const struct got_error *got_privsep_wait_for_child(pid_t);
664 const struct got_error *got_privsep_flush_imsg(struct imsgbuf *);
665 const struct got_error *got_privsep_send_stop(int);
666 const struct got_error *got_privsep_recv_imsg(struct imsg *, struct imsgbuf *,
667 size_t);
668 void got_privsep_send_error(struct imsgbuf *, const struct got_error *);
669 const struct got_error *got_privsep_send_ack(struct imsgbuf *);
670 const struct got_error *got_privsep_wait_ack(struct imsgbuf *);
671 const struct got_error *got_privsep_send_obj_req(struct imsgbuf *, int,
672 struct got_object_id *);
673 const struct got_error *got_privsep_send_raw_obj_req(struct imsgbuf *, int,
674 struct got_object_id *);
675 const struct got_error *got_privsep_send_raw_obj_outfd(struct imsgbuf *, int);
676 const struct got_error *got_privsep_send_commit_req(struct imsgbuf *, int,
677 struct got_object_id *, int);
678 const struct got_error *got_privsep_send_tree_req(struct imsgbuf *, int,
679 struct got_object_id *, int);
680 const struct got_error *got_privsep_send_tag_req(struct imsgbuf *, int,
681 struct got_object_id *, int);
682 const struct got_error *got_privsep_send_blob_req(struct imsgbuf *, int,
683 struct got_object_id *, int);
684 const struct got_error *got_privsep_send_blob_outfd(struct imsgbuf *, int);
685 const struct got_error *got_privsep_send_tmpfd(struct imsgbuf *, int);
686 const struct got_error *got_privsep_send_obj(struct imsgbuf *,
687 struct got_object *);
688 const struct got_error *got_privsep_send_index_pack_req(struct imsgbuf *,
689 uint8_t *, int);
690 const struct got_error *got_privsep_send_index_pack_outfd(struct imsgbuf *,
691 int);
692 const struct got_error *got_privsep_recv_index_progress(int *, int *, int *,
693 int *, int *, struct imsgbuf *ibuf);
694 const struct got_error *got_privsep_send_fetch_req(struct imsgbuf *, int,
695 struct got_pathlist_head *, int, struct got_pathlist_head *,
696 struct got_pathlist_head *, int, int);
697 const struct got_error *got_privsep_send_fetch_outfd(struct imsgbuf *, int);
698 const struct got_error *got_privsep_recv_fetch_progress(int *,
699 struct got_object_id **, char **, struct got_pathlist_head *, char **,
700 off_t *, uint8_t *, struct imsgbuf *);
701 const struct got_error *got_privsep_send_send_req(struct imsgbuf *, int,
702 struct got_pathlist_head *, struct got_pathlist_head *, int);
703 const struct got_error *got_privsep_recv_send_remote_refs(
704 struct got_pathlist_head *, struct imsgbuf *);
705 const struct got_error *got_privsep_send_packfd(struct imsgbuf *, int);
706 const struct got_error *got_privsep_recv_send_progress(int *, off_t *,
707 int *, char **, struct imsgbuf *);
708 const struct got_error *got_privsep_get_imsg_obj(struct got_object **,
709 struct imsg *, struct imsgbuf *);
710 const struct got_error *got_privsep_recv_obj(struct got_object **,
711 struct imsgbuf *);
712 const struct got_error *got_privsep_send_raw_obj(struct imsgbuf *, off_t,
713 size_t, uint8_t *);
714 const struct got_error *got_privsep_recv_raw_obj(uint8_t **, off_t *, size_t *,
715 struct imsgbuf *);
716 const struct got_error *got_privsep_send_commit(struct imsgbuf *,
717 struct got_commit_object *);
718 const struct got_error *got_privsep_recv_commit(struct got_commit_object **,
719 struct imsgbuf *);
720 const struct got_error *got_privsep_recv_tree(struct got_tree_object **,
721 struct imsgbuf *);
722 struct got_parsed_tree_entry;
723 const struct got_error *got_privsep_send_tree(struct imsgbuf *,
724 struct got_parsed_tree_entry *, int);
725 const struct got_error *got_privsep_send_blob(struct imsgbuf *, size_t, size_t,
726 const uint8_t *);
727 const struct got_error *got_privsep_recv_blob(uint8_t **, size_t *, size_t *,
728 struct imsgbuf *);
729 const struct got_error *got_privsep_send_tag(struct imsgbuf *,
730 struct got_tag_object *);
731 const struct got_error *got_privsep_recv_tag(struct got_tag_object **,
732 struct imsgbuf *);
733 const struct got_error *got_privsep_init_pack_child(struct imsgbuf *,
734 struct got_pack *, struct got_packidx *);
735 const struct got_error *got_privsep_send_packed_obj_req(struct imsgbuf *, int,
736 struct got_object_id *);
737 const struct got_error *got_privsep_send_packed_raw_obj_req(struct imsgbuf *,
738 int, struct got_object_id *);
739 const struct got_error *got_privsep_send_pack_child_ready(struct imsgbuf *);
741 const struct got_error *got_privsep_send_gitconfig_parse_req(struct imsgbuf *,
742 int);
743 const struct got_error *
744 got_privsep_send_gitconfig_repository_format_version_req(struct imsgbuf *);
745 const struct got_error *got_privsep_send_gitconfig_repository_extensions_req(
746 struct imsgbuf *);
747 const struct got_error *got_privsep_send_gitconfig_author_name_req(
748 struct imsgbuf *);
749 const struct got_error *got_privsep_send_gitconfig_author_email_req(
750 struct imsgbuf *);
751 const struct got_error *got_privsep_send_gitconfig_remotes_req(
752 struct imsgbuf *);
753 const struct got_error *got_privsep_send_gitconfig_owner_req(struct imsgbuf *);
754 const struct got_error *got_privsep_recv_gitconfig_str(char **,
755 struct imsgbuf *);
756 const struct got_error *got_privsep_recv_gitconfig_int(int *, struct imsgbuf *);
757 const struct got_error *got_privsep_recv_gitconfig_remotes(
758 struct got_remote_repo **, int *, struct imsgbuf *);
760 const struct got_error *got_privsep_send_gotconfig_parse_req(struct imsgbuf *,
761 int);
762 const struct got_error *got_privsep_send_gotconfig_author_req(struct imsgbuf *);
763 const struct got_error *got_privsep_send_gotconfig_remotes_req(
764 struct imsgbuf *);
765 const struct got_error *got_privsep_recv_gotconfig_str(char **,
766 struct imsgbuf *);
767 const struct got_error *got_privsep_recv_gotconfig_remotes(
768 struct got_remote_repo **, int *, struct imsgbuf *);
770 const struct got_error *got_privsep_send_commit_traversal_request(
771 struct imsgbuf *, struct got_object_id *, int, const char *);
772 const struct got_error *got_privsep_recv_traversed_commits(
773 struct got_commit_object **, struct got_object_id **,
774 struct got_object_id_queue *, struct imsgbuf *);
775 const struct got_error *got_privsep_send_enumerated_tree(size_t *,
776 struct imsgbuf *, struct got_object_id *, const char *,
777 struct got_parsed_tree_entry *, int);
778 const struct got_error *got_privsep_send_object_enumeration_request(
779 struct imsgbuf *);
780 const struct got_error *got_privsep_send_object_enumeration_done(
781 struct imsgbuf *);
782 const struct got_error *got_privsep_send_object_enumeration_incomplete(
783 struct imsgbuf *);
784 const struct got_error *got_privsep_send_enumerated_commit(struct imsgbuf *,
785 struct got_object_id *, time_t);
786 const struct got_error *got_privsep_recv_enumerated_objects(int *,
787 struct imsgbuf *, got_object_enumerate_commit_cb,
788 got_object_enumerate_tree_cb, void *, struct got_repository *);
790 const struct got_error *got_privsep_send_raw_delta_req(struct imsgbuf *, int,
791 struct got_object_id *);
792 const struct got_error *got_privsep_send_raw_delta_outfd(struct imsgbuf *, int);
793 const struct got_error *got_privsep_send_raw_delta(struct imsgbuf *, uint64_t,
794 uint64_t, off_t, off_t, off_t, off_t, struct got_object_id *);
795 const struct got_error *got_privsep_recv_raw_delta(uint64_t *, uint64_t *,
796 off_t *, off_t *, off_t *, off_t *, struct got_object_id **,
797 struct imsgbuf *);
799 const struct got_error *got_privsep_send_object_idlist(struct imsgbuf *,
800 struct got_object_id **, size_t);
801 const struct got_error *got_privsep_send_object_idlist_done(struct imsgbuf *);
802 const struct got_error *got_privsep_recv_object_idlist(int *,
803 struct got_object_id **, size_t *, struct imsgbuf *);
805 const struct got_error *got_privsep_send_delta_reuse_req(struct imsgbuf *);
806 const struct got_error *got_privsep_send_reused_deltas(struct imsgbuf *,
807 struct got_imsg_reused_delta *, size_t);
808 const struct got_error *got_privsep_send_reused_deltas_done(struct imsgbuf *);
809 const struct got_error *got_privsep_recv_reused_deltas(int *,
810 struct got_imsg_reused_delta *, size_t *, struct imsgbuf *);
812 const struct got_error *got_privsep_init_commit_painting(struct imsgbuf *);
813 const struct got_error *got_privsep_send_painting_request(struct imsgbuf *,
814 int, struct got_object_id *, intptr_t);
815 typedef const struct got_error *(*got_privsep_recv_painted_commit_cb)(void *,
816 struct got_object_id *, intptr_t);
817 const struct got_error *got_privsep_send_painted_commits(struct imsgbuf *,
818 struct got_object_id_queue *, int *, int, int);
819 const struct got_error *got_privsep_send_painting_commits_done(struct imsgbuf *);
820 const struct got_error *got_privsep_recv_painted_commits(
821 struct got_object_id_queue *, got_privsep_recv_painted_commit_cb, void *,
822 struct imsgbuf *);
824 void got_privsep_exec_child(int[2], const char *, const char *);