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