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
51 #define GOT_PROG_FETCH_HTTP got-fetch-http
53 #define GOT_STRINGIFY(x) #x
54 #define GOT_STRINGVAL(x) GOT_STRINGIFY(x)
56 /* Paths to helper programs in libexec directory */
57 #define GOT_PATH_PROG_READ_OBJECT \
58 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_OBJECT)
59 #define GOT_PATH_PROG_READ_TREE \
60 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_TREE)
61 #define GOT_PATH_PROG_READ_COMMIT \
62 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_COMMIT)
63 #define GOT_PATH_PROG_READ_BLOB \
64 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_BLOB)
65 #define GOT_PATH_PROG_READ_TAG \
66 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_TAG)
67 #define GOT_PATH_PROG_READ_PACK \
68 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_PACK)
69 #define GOT_PATH_PROG_READ_GITCONFIG \
70 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_GITCONFIG)
71 #define GOT_PATH_PROG_READ_GOTCONFIG \
72 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_GOTCONFIG)
73 #define GOT_PATH_PROG_READ_PATCH \
74 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_PATCH)
75 #define GOT_PATH_PROG_FETCH_PACK \
76 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_FETCH_PACK)
77 #define GOT_PATH_PROG_SEND_PACK \
78 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_SEND_PACK)
79 #define GOT_PATH_PROG_INDEX_PACK \
80 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_INDEX_PACK)
81 #define GOT_PATH_PROG_FETCH_HTTP \
82 GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_FETCH_HTTP)
84 enum got_imsg_type {
85 /* An error occured while processing a request. */
86 GOT_IMSG_ERROR,
88 /* Stop the child process. */
89 GOT_IMSG_STOP,
91 /*
92 * Messages concerned with read access to objects in a repository.
93 * Object and pack files are opened by the main process, where
94 * data may be read as a byte string but without any interpretation.
95 * Decompression and parsing of object and pack files occurs in a
96 * separate process which runs under pledge("stdio recvfd").
97 * This sandboxes our own repository parsing code, as well as zlib.
98 */
99 GOT_IMSG_OBJECT_REQUEST,
100 GOT_IMSG_OBJECT,
101 GOT_IMSG_COMMIT_REQUEST,
102 GOT_IMSG_COMMIT,
103 GOT_IMSG_COMMIT_LOGMSG,
104 GOT_IMSG_TREE_REQUEST,
105 GOT_IMSG_TREE,
106 GOT_IMSG_TREE_ENTRIES,
107 GOT_IMSG_BLOB_REQUEST,
108 GOT_IMSG_BLOB_OUTFD,
109 GOT_IMSG_BLOB,
110 GOT_IMSG_TAG_REQUEST,
111 GOT_IMSG_TAG,
112 GOT_IMSG_TAG_TAGMSG,
114 /* Messages related to networking. */
115 GOT_IMSG_FETCH_REQUEST,
116 GOT_IMSG_FETCH_HAVE_REF,
117 GOT_IMSG_FETCH_WANTED_BRANCH,
118 GOT_IMSG_FETCH_WANTED_REF,
119 GOT_IMSG_FETCH_OUTFD,
120 GOT_IMSG_FETCH_SYMREFS,
121 GOT_IMSG_FETCH_REF,
122 GOT_IMSG_FETCH_SERVER_PROGRESS,
123 GOT_IMSG_FETCH_DOWNLOAD_PROGRESS,
124 GOT_IMSG_FETCH_DONE,
125 GOT_IMSG_IDXPACK_REQUEST,
126 GOT_IMSG_IDXPACK_OUTFD,
127 GOT_IMSG_IDXPACK_PROGRESS,
128 GOT_IMSG_IDXPACK_DONE,
129 GOT_IMSG_SEND_REQUEST,
130 GOT_IMSG_SEND_REF,
131 GOT_IMSG_SEND_REMOTE_REF,
132 GOT_IMSG_SEND_REF_STATUS,
133 GOT_IMSG_SEND_PACK_REQUEST,
134 GOT_IMSG_SEND_PACKFD,
135 GOT_IMSG_SEND_UPLOAD_PROGRESS,
136 GOT_IMSG_SEND_DONE,
138 /* Messages related to pack files. */
139 GOT_IMSG_PACKIDX,
140 GOT_IMSG_PACK,
141 GOT_IMSG_PACKED_OBJECT_REQUEST,
142 GOT_IMSG_COMMIT_TRAVERSAL_REQUEST,
143 GOT_IMSG_TRAVERSED_COMMITS,
144 GOT_IMSG_COMMIT_TRAVERSAL_DONE,
145 GOT_IMSG_OBJECT_ENUMERATION_REQUEST,
146 GOT_IMSG_ENUMERATED_COMMIT,
147 GOT_IMSG_ENUMERATED_TREE,
148 GOT_IMSG_TREE_ENUMERATION_DONE,
149 GOT_IMSG_OBJECT_ENUMERATION_DONE,
150 GOT_IMSG_OBJECT_ENUMERATION_INCOMPLETE,
152 /* Message sending file descriptor to a temporary file. */
153 GOT_IMSG_TMPFD,
155 /* Messages related to gitconfig files. */
156 GOT_IMSG_GITCONFIG_PARSE_REQUEST,
157 GOT_IMSG_GITCONFIG_REPOSITORY_FORMAT_VERSION_REQUEST,
158 GOT_IMSG_GITCONFIG_REPOSITORY_EXTENSIONS_REQUEST,
159 GOT_IMSG_GITCONFIG_AUTHOR_NAME_REQUEST,
160 GOT_IMSG_GITCONFIG_AUTHOR_EMAIL_REQUEST,
161 GOT_IMSG_GITCONFIG_REMOTES_REQUEST,
162 GOT_IMSG_GITCONFIG_INT_VAL,
163 GOT_IMSG_GITCONFIG_STR_VAL,
164 GOT_IMSG_GITCONFIG_PAIR,
165 GOT_IMSG_GITCONFIG_REMOTES,
166 GOT_IMSG_GITCONFIG_REMOTE,
167 GOT_IMSG_GITCONFIG_OWNER_REQUEST,
168 GOT_IMSG_GITCONFIG_OWNER,
170 /* Messages related to gotconfig files. */
171 GOT_IMSG_GOTCONFIG_PARSE_REQUEST,
172 GOT_IMSG_GOTCONFIG_AUTHOR_REQUEST,
173 GOT_IMSG_GOTCONFIG_ALLOWEDSIGNERS_REQUEST,
174 GOT_IMSG_GOTCONFIG_REVOKEDSIGNERS_REQUEST,
175 GOT_IMSG_GOTCONFIG_SIGNERID_REQUEST,
176 GOT_IMSG_GOTCONFIG_REMOTES_REQUEST,
177 GOT_IMSG_GOTCONFIG_INT_VAL,
178 GOT_IMSG_GOTCONFIG_STR_VAL,
179 GOT_IMSG_GOTCONFIG_REMOTES,
180 GOT_IMSG_GOTCONFIG_REMOTE,
182 /* Raw object access. Uncompress object data but do not parse it. */
183 GOT_IMSG_RAW_OBJECT_REQUEST,
184 GOT_IMSG_RAW_OBJECT_OUTFD,
185 GOT_IMSG_PACKED_RAW_OBJECT_REQUEST,
186 GOT_IMSG_RAW_OBJECT,
188 /* Read raw delta data from pack files. */
189 GOT_IMSG_RAW_DELTA_OUTFD,
190 GOT_IMSG_RAW_DELTA_REQUEST,
191 GOT_IMSG_RAW_DELTA,
193 /* Re-use deltas found in a pack file. */
194 GOT_IMSG_DELTA_REUSE_REQUEST,
195 GOT_IMSG_REUSED_DELTAS,
196 GOT_IMSG_DELTA_REUSE_DONE,
198 /* Commit coloring in got-read-pack. */
199 GOT_IMSG_COMMIT_PAINTING_INIT,
200 GOT_IMSG_COMMIT_PAINTING_REQUEST,
201 GOT_IMSG_PAINTED_COMMITS,
202 GOT_IMSG_COMMIT_PAINTING_DONE,
204 /* Transfer a list of object IDs. */
205 GOT_IMSG_OBJ_ID_LIST,
206 GOT_IMSG_OBJ_ID_LIST_DONE,
208 /* Messages related to patch files. */
209 GOT_IMSG_PATCH_FILE,
210 GOT_IMSG_PATCH_HUNK,
211 GOT_IMSG_PATCH_DONE,
212 GOT_IMSG_PATCH_LINE,
213 GOT_IMSG_PATCH,
214 GOT_IMSG_PATCH_EOF,
215 };
217 /* Structure for GOT_IMSG_ERROR. */
218 struct got_imsg_error {
219 int code; /* an error code from got_error.h */
220 int errno_code; /* in case code equals GOT_ERR_ERRNO */
221 } __attribute__((__packed__));
223 /*
224 * Structure for GOT_IMSG_TREE_REQUEST and GOT_IMSG_OBJECT data.
225 */
226 struct got_imsg_object {
227 struct got_object_id id;
229 /* These fields are the same as in struct got_object. */
230 int type;
231 int flags;
232 size_t hdrlen;
233 size_t size;
234 off_t pack_offset;
235 int pack_idx;
236 } __attribute__((__packed__));
238 /* Structure for GOT_IMSG_COMMIT data. */
239 struct got_imsg_commit_object {
240 struct got_object_id tree_id;
241 size_t author_len;
242 time_t author_time;
243 time_t author_gmtoff;
244 size_t committer_len;
245 time_t committer_time;
246 time_t committer_gmtoff;
247 size_t logmsg_len;
248 int nparents;
250 /*
251 * Followed by author_len + committer_len data bytes
252 */
254 /* Followed by 'nparents' struct got_object_id */
256 /*
257 * Followed by 'logmsg_len' bytes of commit log message data in
258 * one or more GOT_IMSG_COMMIT_LOGMSG messages.
259 */
260 } __attribute__((__packed__));
262 struct got_imsg_tree_entry {
263 char id[SHA1_DIGEST_LENGTH];
264 mode_t mode;
265 size_t namelen;
266 /* Followed by namelen bytes of entry's name, not NUL-terminated. */
267 } __attribute__((__packed__));
269 /* Structure for GOT_IMSG_TREE_ENTRIES. */
270 struct got_imsg_tree_entries {
271 size_t nentries; /* Number of tree entries contained in this message. */
273 /* Followed by nentries * struct got_imsg_tree_entry */
274 };
276 /* Structure for GOT_IMSG_TREE_OBJECT_REPLY data. */
277 struct got_imsg_tree_object {
278 int nentries; /* This many tree entries follow. */
279 };
281 /* Structure for GOT_IMSG_BLOB. */
282 struct got_imsg_blob {
283 size_t size;
284 size_t hdrlen;
286 /*
287 * If size <= GOT_PRIVSEP_INLINE_BLOB_DATA_MAX, blob data follows
288 * in the imsg buffer. Otherwise, blob data has been written to a
289 * file descriptor passed via the GOT_IMSG_BLOB_OUTFD imsg.
290 */
291 #define GOT_PRIVSEP_INLINE_BLOB_DATA_MAX \
292 (MAX_IMSGSIZE - IMSG_HEADER_SIZE - sizeof(struct got_imsg_blob))
293 };
295 /* Structure for GOT_IMSG_RAW_OBJECT. */
296 struct got_imsg_raw_obj {
297 off_t size;
298 size_t hdrlen;
300 /*
301 * If size <= GOT_PRIVSEP_INLINE_OBJECT_DATA_MAX, object data follows
302 * in the imsg buffer. Otherwise, object data has been written to a
303 * file descriptor passed via the GOT_IMSG_RAW_OBJECT_OUTFD imsg.
304 */
305 #define GOT_PRIVSEP_INLINE_OBJECT_DATA_MAX \
306 (MAX_IMSGSIZE - IMSG_HEADER_SIZE - sizeof(struct got_imsg_raw_obj))
307 };
309 /* Structure for GOT_IMSG_RAW_DELTA. */
310 struct got_imsg_raw_delta {
311 struct got_object_id base_id;
312 uint64_t base_size;
313 uint64_t result_size;
314 off_t delta_size;
315 off_t delta_compressed_size;
316 off_t delta_offset;
317 off_t delta_out_offset;
319 /*
320 * Delta data has been written at delta_out_offset to the file
321 * descriptor passed via the GOT_IMSG_RAW_DELTA_OUTFD imsg.
322 */
323 };
325 /* Structures for GOT_IMSG_REUSED_DELTAS. */
326 struct got_imsg_reused_delta {
327 struct got_object_id id;
328 struct got_object_id base_id;
329 uint64_t base_size;
330 uint64_t result_size;
331 off_t delta_size;
332 off_t delta_compressed_size;
333 off_t delta_offset;
334 };
335 struct got_imsg_reused_deltas {
336 size_t ndeltas;
338 /*
339 * Followed by ndeltas * struct got_imsg_reused_delta.
340 */
342 #define GOT_IMSG_REUSED_DELTAS_MAX_NDELTAS \
343 ((MAX_IMSGSIZE - IMSG_HEADER_SIZE - \
344 sizeof(struct got_imsg_reused_deltas)) \
345 / sizeof(struct got_imsg_reused_delta))
346 };
348 /* Structure for GOT_IMSG_COMMIT_PAINTING_REQUEST. */
349 struct got_imsg_commit_painting_request {
350 struct got_object_id id;
351 int idx;
352 int color;
353 } __attribute__((__packed__));
355 /* Structure for GOT_IMSG_PAINTED_COMMITS. */
356 struct got_imsg_painted_commit {
357 uint8_t id[SHA1_DIGEST_LENGTH];
358 intptr_t color;
359 } __attribute__((__packed__));
361 struct got_imsg_painted_commits {
362 int ncommits;
363 int present_in_pack;
364 /*
365 * Followed by ncommits * struct got_imsg_painted_commit.
366 */
367 } __attribute__((__packed__));
369 /* Structure for GOT_IMSG_TAG data. */
370 struct got_imsg_tag_object {
371 struct got_object_id id;
372 int obj_type;
373 size_t tag_len;
374 size_t tagger_len;
375 time_t tagger_time;
376 time_t tagger_gmtoff;
377 size_t tagmsg_len;
379 /*
380 * Followed by tag_len + tagger_len data bytes
381 */
383 /*
384 * Followed by 'tagmsg_len' bytes of tag message data in
385 * one or more GOT_IMSG_TAG_TAGMSG messages.
386 */
387 } __attribute__((__packed__));
389 /* Structure for GOT_IMSG_FETCH_HAVE_REF data. */
390 struct got_imsg_fetch_have_ref {
391 struct got_object_id id;
392 size_t name_len;
393 /* Followed by name_len data bytes. */
394 } __attribute__((__packed__));
396 /* Structure for GOT_IMSG_FETCH_WANTED_BRANCH data. */
397 struct got_imsg_fetch_wanted_branch {
398 size_t name_len;
399 /* Followed by name_len data bytes. */
400 } __attribute__((__packed__));
402 /* Structure for GOT_IMSG_FETCH_WANTED_REF data. */
403 struct got_imsg_fetch_wanted_ref {
404 size_t name_len;
405 /* Followed by name_len data bytes. */
406 } __attribute__((__packed__));
408 /* Structure for GOT_IMSG_FETCH_REQUEST data. */
409 struct got_imsg_fetch_request {
410 int no_head;
411 int fetch_all_branches;
412 int list_refs_only;
413 int verbosity;
414 size_t worktree_branch_len;
415 size_t remote_head_len;
416 size_t n_have_refs;
417 size_t n_wanted_branches;
418 size_t n_wanted_refs;
419 /* Followed by worktree_branch_len bytes of reference name. */
420 /* Followed by remote_head_len bytes of reference name. */
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 struct got_object_id refid;
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 struct got_object_id id;
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 struct got_object_id id;
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 size_t errmsg_len;
488 /* Followed by name_len data bytes. */
489 /* Followed by errmsg_len data bytes. */
490 } __attribute__((__packed__));
492 /* Structure for GOT_IMSG_IDXPACK_REQUEST data. */
493 struct got_imsg_index_pack_request {
494 uint8_t pack_hash[SHA1_DIGEST_LENGTH];
495 } __attribute__((__packed__));
497 /* Structure for GOT_IMSG_IDXPACK_PROGRESS data. */
498 struct got_imsg_index_pack_progress {
499 /* Total number of objects in pack file. */
500 int nobj_total;
502 /* Number of objects indexed so far. */
503 int nobj_indexed;
505 /* Number of non-deltified objects in pack file. */
506 int nobj_loose;
508 /* Number of deltified objects resolved so far. */
509 int nobj_resolved;
510 };
512 /* Structure for GOT_IMSG_PACKIDX. */
513 struct got_imsg_packidx {
514 size_t len;
515 off_t packfile_size;
516 /* Additionally, a file desciptor is passed via imsg. */
517 };
519 /* Structure for GOT_IMSG_PACK. */
520 struct got_imsg_pack {
521 char path_packfile[PATH_MAX];
522 off_t filesize;
523 /* Additionally, a file desciptor is passed via imsg. */
524 } __attribute__((__packed__));
526 /*
527 * Structure for GOT_IMSG_OBJECT_REQUEST, GOT_IMSG_BLOB_REQUEST,
528 * GOT_IMSG_TREE_REQUEST, GOT_IMSG_COMMIT_REQUEST, and
529 * GOT_IMSG_TAG_REQUEST data.
530 */
531 struct got_object_id;
533 /*
534 * Structure for GOT_IMSG_PACKED_OBJECT_REQUEST and
535 * GOT_IMSG_PACKED_RAW_OBJECT_REQUEST data.
536 */
537 struct got_imsg_packed_object {
538 struct got_object_id id;
539 int idx;
540 } __attribute__((__packed__));
542 /*
543 * Structure for GOT_IMSG_DELTA data.
544 */
545 struct got_imsg_delta {
546 /* These fields are the same as in struct got_delta. */
547 off_t offset;
548 size_t tslen;
549 int type;
550 size_t size;
551 off_t data_offset;
552 };
554 /*
555 * Structure for GOT_IMSG_RAW_DELTA_REQUEST data.
556 */
557 struct got_imsg_raw_delta_request {
558 struct got_object_id id;
559 int idx;
560 };
562 /*
563 * Structure for GOT_IMSG_OBJ_ID_LIST data.
564 * Multiple such messages may be sent back-to-back, where each message
565 * contains a chunk of IDs. The entire list must be terminated with a
566 * GOT_IMSG_OBJ_ID_LIST_DONE message.
567 */
568 struct got_imsg_object_idlist {
569 size_t nids;
571 /*
572 * Followed by nids * struct got_object_id.
573 */
575 #define GOT_IMSG_OBJ_ID_LIST_MAX_NIDS \
576 ((MAX_IMSGSIZE - IMSG_HEADER_SIZE - \
577 sizeof(struct got_imsg_object_idlist)) / sizeof(struct got_object_id))
578 };
580 /* Structure for GOT_IMSG_COMMIT_TRAVERSAL_REQUEST */
581 struct got_imsg_commit_traversal_request {
582 struct got_imsg_packed_object iobj;
583 size_t path_len;
584 /* Followed by path_len bytes of path data */
585 } __attribute__((__packed__));
587 /* Structure for GOT_IMSG_TRAVERSED_COMMITS */
588 struct got_imsg_traversed_commits {
589 size_t ncommits;
590 /* Followed by ncommit struct got_object_id */
591 } __attribute__((__packed__));
593 /* Structure for GOT_IMSG_ENUMERATED_COMMIT */
594 struct got_imsg_enumerated_commit {
595 uint8_t id[SHA1_DIGEST_LENGTH];
596 time_t mtime;
597 } __attribute__((__packed__));
599 /* Structure for GOT_IMSG_ENUMERATED_TREE */
600 struct got_imsg_enumerated_tree {
601 uint8_t id[SHA1_DIGEST_LENGTH]; /* tree ID */
602 int nentries; /* number of tree entries */
604 /* Followed by tree's path in remaining data of imsg buffer. */
606 /* Followed by nentries * GOT_IMSG_TREE_ENTRY messages. */
607 } __attribute__((__packed__));
609 /*
610 * Structure for GOT_IMSG_GOTCONFIG_REMOTE and
611 * GOT_IMSG_GOTCONFIG_REMOTE data.
612 */
613 struct got_imsg_remote {
614 size_t name_len;
615 size_t fetch_url_len;
616 size_t send_url_len;
617 int mirror_references;
618 int fetch_all_branches;
619 int nfetch_branches;
620 int nsend_branches;
621 int nfetch_refs;
623 /* Followed by name_len data bytes. */
624 /* Followed by fetch_url_len + send_url_len data bytes. */
625 /* Followed by nfetch_branches GOT_IMSG_GITCONFIG_STR_VAL messages. */
626 /* Followed by nsend_branches GOT_IMSG_GITCONFIG_STR_VAL messages. */
627 /* Followed by nfetch_refs GOT_IMSG_GITCONFIG_STR_VAL messages. */
628 } __attribute__((__packed__));
630 /*
631 * Structure for GOT_IMSG_GITCONFIG_REMOTES data.
632 */
633 struct got_imsg_remotes {
634 int nremotes; /* This many GOT_IMSG_GITCONFIG_REMOTE messages follow. */
635 };
637 /*
638 * Structure for GOT_IMSG_GITCONFIG_PAIR.
639 */
640 struct got_imsg_gitconfig_pair {
641 size_t klen;
642 size_t vlen;
643 /* Followed by klen data bytes of key string. */
644 /* Followed by vlen data bytes of value string. */
645 };
647 /*
648 * Structure for GOT_IMSG_PATCH data.
649 */
650 struct got_imsg_patch {
651 int git;
652 int xbit;
653 char old[PATH_MAX];
654 char new[PATH_MAX];
655 char cid[41];
656 char blob[41];
657 };
659 /*
660 * Structure for GOT_IMSG_PATCH_HUNK data.
661 */
662 struct got_imsg_patch_hunk {
663 int oldfrom;
664 int oldlines;
665 int newfrom;
666 int newlines;
667 };
669 struct got_remote_repo;
670 struct got_pack;
671 struct got_packidx;
672 struct got_pathlist_head;
674 const struct got_error *got_send_ack(pid_t);
675 const struct got_error *got_privsep_wait_for_child(pid_t);
676 const struct got_error *got_privsep_flush_imsg(struct imsgbuf *);
677 const struct got_error *got_privsep_send_stop(int);
678 const struct got_error *got_privsep_recv_imsg(struct imsg *, struct imsgbuf *,
679 size_t);
680 void got_privsep_send_error(struct imsgbuf *, const struct got_error *);
681 const struct got_error *got_privsep_send_ack(struct imsgbuf *);
682 const struct got_error *got_privsep_wait_ack(struct imsgbuf *);
683 const struct got_error *got_privsep_send_obj_req(struct imsgbuf *, int,
684 struct got_object_id *);
685 const struct got_error *got_privsep_send_raw_obj_req(struct imsgbuf *, int,
686 struct got_object_id *);
687 const struct got_error *got_privsep_send_raw_obj_outfd(struct imsgbuf *, int);
688 const struct got_error *got_privsep_send_commit_req(struct imsgbuf *, int,
689 struct got_object_id *, int);
690 const struct got_error *got_privsep_send_tree_req(struct imsgbuf *, int,
691 struct got_object_id *, int);
692 const struct got_error *got_privsep_send_tag_req(struct imsgbuf *, int,
693 struct got_object_id *, int);
694 const struct got_error *got_privsep_send_blob_req(struct imsgbuf *, int,
695 struct got_object_id *, int);
696 const struct got_error *got_privsep_send_blob_outfd(struct imsgbuf *, int);
697 const struct got_error *got_privsep_send_tmpfd(struct imsgbuf *, int);
698 const struct got_error *got_privsep_send_obj(struct imsgbuf *,
699 struct got_object *);
700 const struct got_error *got_privsep_send_index_pack_req(struct imsgbuf *,
701 uint8_t *, int);
702 const struct got_error *got_privsep_send_index_pack_outfd(struct imsgbuf *,
703 int);
704 const struct got_error *got_privsep_recv_index_progress(int *, int *, int *,
705 int *, int *, struct imsgbuf *ibuf);
706 const struct got_error *got_privsep_send_fetch_req(struct imsgbuf *, int,
707 struct got_pathlist_head *, int, struct got_pathlist_head *,
708 struct got_pathlist_head *, int, const char *, const char *, int, int);
709 const struct got_error *got_privsep_send_fetch_outfd(struct imsgbuf *, int);
710 const struct got_error *got_privsep_recv_fetch_progress(int *,
711 struct got_object_id **, char **, struct got_pathlist_head *, char **,
712 off_t *, uint8_t *, struct imsgbuf *);
713 const struct got_error *got_privsep_send_send_req(struct imsgbuf *, int,
714 struct got_pathlist_head *, struct got_pathlist_head *, int);
715 const struct got_error *got_privsep_recv_send_remote_refs(
716 struct got_pathlist_head *, struct imsgbuf *);
717 const struct got_error *got_privsep_send_packfd(struct imsgbuf *, int);
718 const struct got_error *got_privsep_recv_send_progress(int *, off_t *,
719 int *, char **, char **, struct imsgbuf *);
720 const struct got_error *got_privsep_get_imsg_obj(struct got_object **,
721 struct imsg *, struct imsgbuf *);
722 const struct got_error *got_privsep_recv_obj(struct got_object **,
723 struct imsgbuf *);
724 const struct got_error *got_privsep_send_raw_obj(struct imsgbuf *, off_t,
725 size_t, uint8_t *);
726 const struct got_error *got_privsep_recv_raw_obj(uint8_t **, off_t *, size_t *,
727 struct imsgbuf *);
728 const struct got_error *got_privsep_send_commit(struct imsgbuf *,
729 struct got_commit_object *);
730 const struct got_error *got_privsep_recv_commit(struct got_commit_object **,
731 struct imsgbuf *);
732 const struct got_error *got_privsep_recv_tree(struct got_tree_object **,
733 struct imsgbuf *);
734 struct got_parsed_tree_entry;
735 const struct got_error *got_privsep_send_tree(struct imsgbuf *,
736 struct got_parsed_tree_entry *, int);
737 const struct got_error *got_privsep_send_blob(struct imsgbuf *, size_t, size_t,
738 const uint8_t *);
739 const struct got_error *got_privsep_recv_blob(uint8_t **, size_t *, size_t *,
740 struct imsgbuf *);
741 const struct got_error *got_privsep_send_tag(struct imsgbuf *,
742 struct got_tag_object *);
743 const struct got_error *got_privsep_recv_tag(struct got_tag_object **,
744 struct imsgbuf *);
745 const struct got_error *got_privsep_init_pack_child(struct imsgbuf *,
746 struct got_pack *, struct got_packidx *);
747 const struct got_error *got_privsep_send_packed_obj_req(struct imsgbuf *, int,
748 struct got_object_id *);
749 const struct got_error *got_privsep_send_packed_raw_obj_req(struct imsgbuf *,
750 int, struct got_object_id *);
751 const struct got_error *got_privsep_send_pack_child_ready(struct imsgbuf *);
753 const struct got_error *got_privsep_send_gitconfig_parse_req(struct imsgbuf *,
754 int);
755 const struct got_error *
756 got_privsep_send_gitconfig_repository_format_version_req(struct imsgbuf *);
757 const struct got_error *got_privsep_send_gitconfig_repository_extensions_req(
758 struct imsgbuf *);
759 const struct got_error *got_privsep_send_gitconfig_author_name_req(
760 struct imsgbuf *);
761 const struct got_error *got_privsep_send_gitconfig_author_email_req(
762 struct imsgbuf *);
763 const struct got_error *got_privsep_send_gitconfig_remotes_req(
764 struct imsgbuf *);
765 const struct got_error *got_privsep_send_gitconfig_owner_req(struct imsgbuf *);
766 const struct got_error *got_privsep_recv_gitconfig_str(char **,
767 struct imsgbuf *);
768 const struct got_error *got_privsep_recv_gitconfig_pair(char **, char **,
769 struct imsgbuf *);
770 const struct got_error *got_privsep_recv_gitconfig_int(int *, struct imsgbuf *);
771 const struct got_error *got_privsep_recv_gitconfig_remotes(
772 struct got_remote_repo **, int *, struct imsgbuf *);
774 const struct got_error *got_privsep_send_gotconfig_parse_req(struct imsgbuf *,
775 int);
776 const struct got_error *got_privsep_send_gotconfig_author_req(struct imsgbuf *);
777 const struct got_error *got_privsep_send_gotconfig_allowed_signers_req(
778 struct imsgbuf *);
779 const struct got_error *got_privsep_send_gotconfig_revoked_signers_req(
780 struct imsgbuf *);
781 const struct got_error *got_privsep_send_gotconfig_signer_id_req(
782 struct imsgbuf *);
783 const struct got_error *got_privsep_send_gotconfig_remotes_req(
784 struct imsgbuf *);
785 const struct got_error *got_privsep_recv_gotconfig_str(char **,
786 struct imsgbuf *);
787 const struct got_error *got_privsep_recv_gotconfig_remotes(
788 struct got_remote_repo **, int *, struct imsgbuf *);
790 const struct got_error *got_privsep_send_commit_traversal_request(
791 struct imsgbuf *, struct got_object_id *, int, const char *);
792 const struct got_error *got_privsep_recv_traversed_commits(
793 struct got_commit_object **, struct got_object_id_queue *,
794 struct imsgbuf *);
795 const struct got_error *got_privsep_send_enumerated_tree(size_t *,
796 struct imsgbuf *, struct got_object_id *, const char *,
797 struct got_parsed_tree_entry *, int);
798 const struct got_error *got_privsep_send_object_enumeration_request(
799 struct imsgbuf *);
800 const struct got_error *got_privsep_send_object_enumeration_done(
801 struct imsgbuf *);
802 const struct got_error *got_privsep_send_object_enumeration_incomplete(
803 struct imsgbuf *);
804 const struct got_error *got_privsep_send_enumerated_commit(struct imsgbuf *,
805 struct got_object_id *, time_t);
806 const struct got_error *got_privsep_recv_enumerated_objects(int *,
807 struct imsgbuf *, got_object_enumerate_commit_cb,
808 got_object_enumerate_tree_cb, void *, struct got_repository *);
810 const struct got_error *got_privsep_send_raw_delta_req(struct imsgbuf *, int,
811 struct got_object_id *);
812 const struct got_error *got_privsep_send_raw_delta_outfd(struct imsgbuf *, int);
813 const struct got_error *got_privsep_send_raw_delta(struct imsgbuf *, uint64_t,
814 uint64_t, off_t, off_t, off_t, off_t, struct got_object_id *);
815 const struct got_error *got_privsep_recv_raw_delta(uint64_t *, uint64_t *,
816 off_t *, off_t *, off_t *, off_t *, struct got_object_id **,
817 struct imsgbuf *);
819 const struct got_error *got_privsep_send_object_idlist(struct imsgbuf *,
820 struct got_object_id **, size_t);
821 const struct got_error *got_privsep_send_object_idlist_done(struct imsgbuf *);
822 const struct got_error *got_privsep_recv_object_idlist(int *,
823 struct got_object_id **, size_t *, struct imsgbuf *);
825 const struct got_error *got_privsep_send_delta_reuse_req(struct imsgbuf *);
826 const struct got_error *got_privsep_send_reused_deltas(struct imsgbuf *,
827 struct got_imsg_reused_delta *, size_t);
828 const struct got_error *got_privsep_send_reused_deltas_done(struct imsgbuf *);
829 const struct got_error *got_privsep_recv_reused_deltas(int *,
830 struct got_imsg_reused_delta *, size_t *, struct imsgbuf *);
832 const struct got_error *got_privsep_init_commit_painting(struct imsgbuf *);
833 const struct got_error *got_privsep_send_painting_request(struct imsgbuf *,
834 int, struct got_object_id *, intptr_t);
835 typedef const struct got_error *(*got_privsep_recv_painted_commit_cb)(void *,
836 struct got_object_id *, intptr_t);
837 const struct got_error *got_privsep_send_painted_commits(struct imsgbuf *,
838 struct got_object_id_queue *, int *, int, int);
839 const struct got_error *got_privsep_send_painting_commits_done(struct imsgbuf *);
840 const struct got_error *got_privsep_recv_painted_commits(
841 struct got_object_id_queue *, got_privsep_recv_painted_commit_cb, void *,
842 struct imsgbuf *);
844 void got_privsep_exec_child(int[2], const char *, const char *);