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_REMOTES_REQUEST,
178 GOT_IMSG_GOTCONFIG_INT_VAL,
179 GOT_IMSG_GOTCONFIG_STR_VAL,
180 GOT_IMSG_GOTCONFIG_REMOTES,
181 GOT_IMSG_GOTCONFIG_REMOTE,
183 /* Raw object access. Uncompress object data but do not parse it. */
184 GOT_IMSG_RAW_OBJECT_REQUEST,
185 GOT_IMSG_RAW_OBJECT_OUTFD,
186 GOT_IMSG_PACKED_RAW_OBJECT_REQUEST,
187 GOT_IMSG_RAW_OBJECT,
189 /* Read raw delta data from pack files. */
190 GOT_IMSG_RAW_DELTA_OUTFD,
191 GOT_IMSG_RAW_DELTA_REQUEST,
192 GOT_IMSG_RAW_DELTA,
194 /* Re-use deltas found in a pack file. */
195 GOT_IMSG_DELTA_REUSE_REQUEST,
196 GOT_IMSG_REUSED_DELTAS,
197 GOT_IMSG_DELTA_REUSE_DONE,
199 /* Commit coloring in got-read-pack. */
200 GOT_IMSG_COMMIT_PAINTING_INIT,
201 GOT_IMSG_COMMIT_PAINTING_REQUEST,
202 GOT_IMSG_PAINTED_COMMITS,
203 GOT_IMSG_COMMIT_PAINTING_DONE,
205 /* Transfer a list of object IDs. */
206 GOT_IMSG_OBJ_ID_LIST,
207 GOT_IMSG_OBJ_ID_LIST_DONE,
209 /* Messages related to patch files. */
210 GOT_IMSG_PATCH_FILE,
211 GOT_IMSG_PATCH_HUNK,
212 GOT_IMSG_PATCH_DONE,
213 GOT_IMSG_PATCH_LINE,
214 GOT_IMSG_PATCH,
215 GOT_IMSG_PATCH_EOF,
216 };
218 /* Structure for GOT_IMSG_ERROR. */
219 struct got_imsg_error {
220 int code; /* an error code from got_error.h */
221 int errno_code; /* in case code equals GOT_ERR_ERRNO */
222 } __attribute__((__packed__));
224 /*
225 * Structure for GOT_IMSG_TREE_REQUEST and GOT_IMSG_OBJECT data.
226 */
227 struct got_imsg_object {
228 uint8_t id[SHA1_DIGEST_LENGTH];
230 /* These fields are the same as in struct got_object. */
231 int type;
232 int flags;
233 size_t hdrlen;
234 size_t size;
235 off_t pack_offset;
236 int pack_idx;
237 } __attribute__((__packed__));
239 /* Structure for GOT_IMSG_COMMIT data. */
240 struct got_imsg_commit_object {
241 uint8_t tree_id[SHA1_DIGEST_LENGTH];
242 size_t author_len;
243 time_t author_time;
244 time_t author_gmtoff;
245 size_t committer_len;
246 time_t committer_time;
247 time_t committer_gmtoff;
248 size_t logmsg_len;
249 int nparents;
251 /*
252 * Followed by author_len + committer_len data bytes
253 */
255 /* Followed by 'nparents' SHA1_DIGEST_LENGTH length strings */
257 /*
258 * Followed by 'logmsg_len' bytes of commit log message data in
259 * one or more GOT_IMSG_COMMIT_LOGMSG messages.
260 */
261 } __attribute__((__packed__));
263 struct got_imsg_tree_entry {
264 char id[SHA1_DIGEST_LENGTH];
265 mode_t mode;
266 size_t namelen;
267 /* Followed by namelen bytes of entry's name, not NUL-terminated. */
268 } __attribute__((__packed__));
270 /* Structure for GOT_IMSG_TREE_ENTRIES. */
271 struct got_imsg_tree_entries {
272 size_t nentries; /* Number of tree entries contained in this message. */
274 /* Followed by nentries * struct got_imsg_tree_entry */
275 };
277 /* Structure for GOT_IMSG_TREE_OBJECT_REPLY data. */
278 struct got_imsg_tree_object {
279 int nentries; /* This many tree entries follow. */
280 };
282 /* Structure for GOT_IMSG_BLOB. */
283 struct got_imsg_blob {
284 size_t size;
285 size_t hdrlen;
287 /*
288 * If size <= GOT_PRIVSEP_INLINE_BLOB_DATA_MAX, blob data follows
289 * in the imsg buffer. Otherwise, blob data has been written to a
290 * file descriptor passed via the GOT_IMSG_BLOB_OUTFD imsg.
291 */
292 #define GOT_PRIVSEP_INLINE_BLOB_DATA_MAX \
293 (MAX_IMSGSIZE - IMSG_HEADER_SIZE - sizeof(struct got_imsg_blob))
294 };
296 /* Structure for GOT_IMSG_RAW_OBJECT. */
297 struct got_imsg_raw_obj {
298 off_t size;
299 size_t hdrlen;
301 /*
302 * If size <= GOT_PRIVSEP_INLINE_OBJECT_DATA_MAX, object data follows
303 * in the imsg buffer. Otherwise, object data has been written to a
304 * file descriptor passed via the GOT_IMSG_RAW_OBJECT_OUTFD imsg.
305 */
306 #define GOT_PRIVSEP_INLINE_OBJECT_DATA_MAX \
307 (MAX_IMSGSIZE - IMSG_HEADER_SIZE - sizeof(struct got_imsg_raw_obj))
308 };
310 /* Structure for GOT_IMSG_RAW_DELTA. */
311 struct got_imsg_raw_delta {
312 uint8_t base_id[SHA1_DIGEST_LENGTH];
313 uint64_t base_size;
314 uint64_t result_size;
315 off_t delta_size;
316 off_t delta_compressed_size;
317 off_t delta_offset;
318 off_t delta_out_offset;
320 /*
321 * Delta data has been written at delta_out_offset to the file
322 * descriptor passed via the GOT_IMSG_RAW_DELTA_OUTFD imsg.
323 */
324 };
326 /* Structures for GOT_IMSG_REUSED_DELTAS. */
327 struct got_imsg_reused_delta {
328 struct got_object_id id;
329 struct got_object_id base_id;
330 uint64_t base_size;
331 uint64_t result_size;
332 off_t delta_size;
333 off_t delta_compressed_size;
334 off_t delta_offset;
335 off_t delta_out_offset;
337 /*
338 * Delta data has been written at delta_out_offset to the file
339 * descriptor passed via the GOT_IMSG_RAW_DELTA_OUTFD imsg.
340 */
341 };
342 struct got_imsg_reused_deltas {
343 size_t ndeltas;
345 /*
346 * Followed by ndeltas * struct got_imsg_reused_delta.
347 */
349 #define GOT_IMSG_REUSED_DELTAS_MAX_NDELTAS \
350 ((MAX_IMSGSIZE - IMSG_HEADER_SIZE - \
351 sizeof(struct got_imsg_reused_deltas)) \
352 / sizeof(struct got_imsg_reused_delta))
353 };
355 /* Structure for GOT_IMSG_COMMIT_PAINTING_REQUEST. */
356 struct got_imsg_commit_painting_request {
357 uint8_t id[SHA1_DIGEST_LENGTH];
358 int idx;
359 int color;
360 } __attribute__((__packed__));
362 /* Structure for GOT_IMSG_PAINTED_COMMITS. */
363 struct got_imsg_painted_commit {
364 uint8_t id[SHA1_DIGEST_LENGTH];
365 intptr_t color;
366 } __attribute__((__packed__));
368 struct got_imsg_painted_commits {
369 int ncommits;
370 int present_in_pack;
371 /*
372 * Followed by ncommits * struct got_imsg_painted_commit.
373 */
374 } __attribute__((__packed__));
376 /* Structure for GOT_IMSG_TAG data. */
377 struct got_imsg_tag_object {
378 uint8_t id[SHA1_DIGEST_LENGTH];
379 int obj_type;
380 size_t tag_len;
381 size_t tagger_len;
382 time_t tagger_time;
383 time_t tagger_gmtoff;
384 size_t tagmsg_len;
386 /*
387 * Followed by tag_len + tagger_len data bytes
388 */
390 /*
391 * Followed by 'tagmsg_len' bytes of tag message data in
392 * one or more GOT_IMSG_TAG_TAGMSG messages.
393 */
394 } __attribute__((__packed__));
396 /* Structure for GOT_IMSG_FETCH_HAVE_REF data. */
397 struct got_imsg_fetch_have_ref {
398 uint8_t id[SHA1_DIGEST_LENGTH];
399 size_t name_len;
400 /* Followed by name_len data bytes. */
401 } __attribute__((__packed__));
403 /* Structure for GOT_IMSG_FETCH_WANTED_BRANCH data. */
404 struct got_imsg_fetch_wanted_branch {
405 size_t name_len;
406 /* Followed by name_len data bytes. */
407 } __attribute__((__packed__));
409 /* Structure for GOT_IMSG_FETCH_WANTED_REF data. */
410 struct got_imsg_fetch_wanted_ref {
411 size_t name_len;
412 /* Followed by name_len data bytes. */
413 } __attribute__((__packed__));
415 /* Structure for GOT_IMSG_FETCH_REQUEST data. */
416 struct got_imsg_fetch_request {
417 int fetch_all_branches;
418 int list_refs_only;
419 int verbosity;
420 size_t n_have_refs;
421 size_t n_wanted_branches;
422 size_t n_wanted_refs;
423 /* Followed by n_have_refs GOT_IMSG_FETCH_HAVE_REF messages. */
424 /* Followed by n_wanted_branches times GOT_IMSG_FETCH_WANTED_BRANCH. */
425 /* Followed by n_wanted_refs times GOT_IMSG_FETCH_WANTED_REF. */
426 } __attribute__((__packed__));
428 /* Structures for GOT_IMSG_FETCH_SYMREFS data. */
429 struct got_imsg_fetch_symref {
430 size_t name_len;
431 size_t target_len;
433 /*
434 * Followed by name_len + target_len data bytes.
435 */
436 } __attribute__((__packed__));
438 struct got_imsg_fetch_symrefs {
439 size_t nsymrefs;
441 /* Followed by nsymrefs times of got_imsg_fetch_symref data. */
442 } __attribute__((__packed__));
444 /* Structure for GOT_IMSG_FETCH_REF data. */
445 struct got_imsg_fetch_ref {
446 /* Describes a reference which will be fetched. */
447 uint8_t refid[SHA1_DIGEST_LENGTH];
448 /* Followed by reference name in remaining data of imsg buffer. */
449 };
451 /* Structure for GOT_IMSG_FETCH_DOWNLOAD_PROGRESS data. */
452 struct got_imsg_fetch_download_progress {
453 /* Number of packfile data bytes downloaded so far. */
454 off_t packfile_bytes;
455 };
457 /* Structure for GOT_IMSG_SEND_REQUEST data. */
458 struct got_imsg_send_request {
459 int verbosity;
460 size_t nrefs;
461 /* Followed by nrefs GOT_IMSG_SEND_REF messages. */
462 } __attribute__((__packed__));
464 /* Structure for GOT_IMSG_SEND_UPLOAD_PROGRESS data. */
465 struct got_imsg_send_upload_progress {
466 /* Number of packfile data bytes uploaded so far. */
467 off_t packfile_bytes;
468 };
470 /* Structure for GOT_IMSG_SEND_REF data. */
471 struct got_imsg_send_ref {
472 uint8_t id[SHA1_DIGEST_LENGTH];
473 int delete;
474 size_t name_len;
475 /* Followed by name_len data bytes. */
476 } __attribute__((__packed__));
478 /* Structure for GOT_IMSG_SEND_REMOTE_REF data. */
479 struct got_imsg_send_remote_ref {
480 uint8_t id[SHA1_DIGEST_LENGTH];
481 size_t name_len;
482 /* Followed by name_len data bytes. */
483 } __attribute__((__packed__));
485 /* Structure for GOT_IMSG_SEND_REF_STATUS data. */
486 struct got_imsg_send_ref_status {
487 int success;
488 size_t name_len;
489 /* Followed by name_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 size_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 uint8_t id[SHA1_DIGEST_LENGTH];
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 uint8_t id[SHA1_DIGEST_LENGTH];
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 uint8_t id[SHA1_DIGEST_LENGTH];
583 int idx;
584 size_t path_len;
585 /* Followed by path_len bytes of path data */
586 } __attribute__((__packed__));
588 /* Structure for GOT_IMSG_TRAVERSED_COMMITS */
589 struct got_imsg_traversed_commits {
590 size_t ncommits;
591 /* Followed by ncommit IDs of SHA1_DIGEST_LENGTH each */
592 } __attribute__((__packed__));
594 /* Structure for GOT_IMSG_ENUMERATED_COMMIT */
595 struct got_imsg_enumerated_commit {
596 uint8_t id[SHA1_DIGEST_LENGTH];
597 time_t mtime;
598 } __attribute__((__packed__));
600 /* Structure for GOT_IMSG_ENUMERATED_TREE */
601 struct got_imsg_enumerated_tree {
602 uint8_t id[SHA1_DIGEST_LENGTH]; /* tree ID */
603 int nentries; /* number of tree entries */
605 /* Followed by tree's path in remaining data of imsg buffer. */
607 /* Followed by nentries * GOT_IMSG_TREE_ENTRY messages. */
608 } __attribute__((__packed__));
610 /*
611 * Structure for GOT_IMSG_GOTCONFIG_REMOTE and
612 * GOT_IMSG_GOTCONFIG_REMOTE data.
613 */
614 struct got_imsg_remote {
615 size_t name_len;
616 size_t fetch_url_len;
617 size_t send_url_len;
618 int mirror_references;
619 int fetch_all_branches;
620 int nfetch_branches;
621 int nsend_branches;
622 int nfetch_refs;
624 /* Followed by name_len data bytes. */
625 /* Followed by fetch_url_len + send_url_len data bytes. */
626 /* Followed by nfetch_branches GOT_IMSG_GITCONFIG_STR_VAL messages. */
627 /* Followed by nsend_branches GOT_IMSG_GITCONFIG_STR_VAL messages. */
628 /* Followed by nfetch_refs GOT_IMSG_GITCONFIG_STR_VAL messages. */
629 } __attribute__((__packed__));
631 /*
632 * Structure for GOT_IMSG_GITCONFIG_REMOTES data.
633 */
634 struct got_imsg_remotes {
635 int nremotes; /* This many GOT_IMSG_GITCONFIG_REMOTE messages follow. */
636 };
638 /*
639 * Structure for GOT_IMSG_PATCH data.
640 */
641 struct got_imsg_patch {
642 int git;
643 char old[PATH_MAX];
644 char new[PATH_MAX];
645 char cid[41];
646 char blob[41];
647 };
649 /*
650 * Structure for GOT_IMSG_PATCH_HUNK data.
651 */
652 struct got_imsg_patch_hunk {
653 int oldfrom;
654 int oldlines;
655 int newfrom;
656 int newlines;
657 };
659 struct got_remote_repo;
660 struct got_pack;
661 struct got_packidx;
662 struct got_pathlist_head;
664 const struct got_error *got_send_ack(pid_t);
665 const struct got_error *got_privsep_wait_for_child(pid_t);
666 const struct got_error *got_privsep_flush_imsg(struct imsgbuf *);
667 const struct got_error *got_privsep_send_stop(int);
668 const struct got_error *got_privsep_recv_imsg(struct imsg *, struct imsgbuf *,
669 size_t);
670 void got_privsep_send_error(struct imsgbuf *, const struct got_error *);
671 const struct got_error *got_privsep_send_ack(struct imsgbuf *);
672 const struct got_error *got_privsep_wait_ack(struct imsgbuf *);
673 const struct got_error *got_privsep_send_obj_req(struct imsgbuf *, int,
674 struct got_object_id *);
675 const struct got_error *got_privsep_send_raw_obj_req(struct imsgbuf *, int,
676 struct got_object_id *);
677 const struct got_error *got_privsep_send_raw_obj_outfd(struct imsgbuf *, int);
678 const struct got_error *got_privsep_send_commit_req(struct imsgbuf *, int,
679 struct got_object_id *, int);
680 const struct got_error *got_privsep_send_tree_req(struct imsgbuf *, int,
681 struct got_object_id *, int);
682 const struct got_error *got_privsep_send_tag_req(struct imsgbuf *, int,
683 struct got_object_id *, int);
684 const struct got_error *got_privsep_send_blob_req(struct imsgbuf *, int,
685 struct got_object_id *, int);
686 const struct got_error *got_privsep_send_blob_outfd(struct imsgbuf *, int);
687 const struct got_error *got_privsep_send_tmpfd(struct imsgbuf *, int);
688 const struct got_error *got_privsep_send_obj(struct imsgbuf *,
689 struct got_object *);
690 const struct got_error *got_privsep_send_index_pack_req(struct imsgbuf *,
691 uint8_t *, int);
692 const struct got_error *got_privsep_send_index_pack_outfd(struct imsgbuf *,
693 int);
694 const struct got_error *got_privsep_recv_index_progress(int *, int *, int *,
695 int *, int *, struct imsgbuf *ibuf);
696 const struct got_error *got_privsep_send_fetch_req(struct imsgbuf *, int,
697 struct got_pathlist_head *, int, struct got_pathlist_head *,
698 struct got_pathlist_head *, int, int);
699 const struct got_error *got_privsep_send_fetch_outfd(struct imsgbuf *, int);
700 const struct got_error *got_privsep_recv_fetch_progress(int *,
701 struct got_object_id **, char **, struct got_pathlist_head *, char **,
702 off_t *, uint8_t *, struct imsgbuf *);
703 const struct got_error *got_privsep_send_send_req(struct imsgbuf *, int,
704 struct got_pathlist_head *, struct got_pathlist_head *, int);
705 const struct got_error *got_privsep_recv_send_remote_refs(
706 struct got_pathlist_head *, struct imsgbuf *);
707 const struct got_error *got_privsep_send_packfd(struct imsgbuf *, int);
708 const struct got_error *got_privsep_recv_send_progress(int *, off_t *,
709 int *, char **, struct imsgbuf *);
710 const struct got_error *got_privsep_get_imsg_obj(struct got_object **,
711 struct imsg *, struct imsgbuf *);
712 const struct got_error *got_privsep_recv_obj(struct got_object **,
713 struct imsgbuf *);
714 const struct got_error *got_privsep_send_raw_obj(struct imsgbuf *, off_t,
715 size_t, uint8_t *);
716 const struct got_error *got_privsep_recv_raw_obj(uint8_t **, off_t *, size_t *,
717 struct imsgbuf *);
718 const struct got_error *got_privsep_send_commit(struct imsgbuf *,
719 struct got_commit_object *);
720 const struct got_error *got_privsep_recv_commit(struct got_commit_object **,
721 struct imsgbuf *);
722 const struct got_error *got_privsep_recv_tree(struct got_tree_object **,
723 struct imsgbuf *);
724 struct got_parsed_tree_entry;
725 const struct got_error *got_privsep_send_tree(struct imsgbuf *,
726 struct got_parsed_tree_entry *, int);
727 const struct got_error *got_privsep_send_blob(struct imsgbuf *, size_t, size_t,
728 const uint8_t *);
729 const struct got_error *got_privsep_recv_blob(uint8_t **, size_t *, size_t *,
730 struct imsgbuf *);
731 const struct got_error *got_privsep_send_tag(struct imsgbuf *,
732 struct got_tag_object *);
733 const struct got_error *got_privsep_recv_tag(struct got_tag_object **,
734 struct imsgbuf *);
735 const struct got_error *got_privsep_init_pack_child(struct imsgbuf *,
736 struct got_pack *, struct got_packidx *);
737 const struct got_error *got_privsep_send_packed_obj_req(struct imsgbuf *, int,
738 struct got_object_id *);
739 const struct got_error *got_privsep_send_packed_raw_obj_req(struct imsgbuf *,
740 int, struct got_object_id *);
741 const struct got_error *got_privsep_send_pack_child_ready(struct imsgbuf *);
743 const struct got_error *got_privsep_send_gitconfig_parse_req(struct imsgbuf *,
744 int);
745 const struct got_error *
746 got_privsep_send_gitconfig_repository_format_version_req(struct imsgbuf *);
747 const struct got_error *got_privsep_send_gitconfig_repository_extensions_req(
748 struct imsgbuf *);
749 const struct got_error *got_privsep_send_gitconfig_author_name_req(
750 struct imsgbuf *);
751 const struct got_error *got_privsep_send_gitconfig_author_email_req(
752 struct imsgbuf *);
753 const struct got_error *got_privsep_send_gitconfig_remotes_req(
754 struct imsgbuf *);
755 const struct got_error *got_privsep_send_gitconfig_owner_req(struct imsgbuf *);
756 const struct got_error *got_privsep_recv_gitconfig_str(char **,
757 struct imsgbuf *);
758 const struct got_error *got_privsep_recv_gitconfig_int(int *, struct imsgbuf *);
759 const struct got_error *got_privsep_recv_gitconfig_remotes(
760 struct got_remote_repo **, int *, struct imsgbuf *);
762 const struct got_error *got_privsep_send_gotconfig_parse_req(struct imsgbuf *,
763 int);
764 const struct got_error *got_privsep_send_gotconfig_author_req(struct imsgbuf *);
765 const struct got_error *got_privsep_send_gotconfig_allowed_signers_req(
766 struct imsgbuf *);
767 const struct got_error *got_privsep_send_gotconfig_revoked_signers_req(
768 struct imsgbuf *);
769 const struct got_error *got_privsep_send_gotconfig_remotes_req(
770 struct imsgbuf *);
771 const struct got_error *got_privsep_recv_gotconfig_str(char **,
772 struct imsgbuf *);
773 const struct got_error *got_privsep_recv_gotconfig_remotes(
774 struct got_remote_repo **, int *, struct imsgbuf *);
776 const struct got_error *got_privsep_send_commit_traversal_request(
777 struct imsgbuf *, struct got_object_id *, int, const char *);
778 const struct got_error *got_privsep_recv_traversed_commits(
779 struct got_commit_object **, struct got_object_id **,
780 struct got_object_id_queue *, struct imsgbuf *);
781 const struct got_error *got_privsep_send_enumerated_tree(size_t *,
782 struct imsgbuf *, struct got_object_id *, const char *,
783 struct got_parsed_tree_entry *, int);
784 const struct got_error *got_privsep_send_object_enumeration_request(
785 struct imsgbuf *);
786 const struct got_error *got_privsep_send_object_enumeration_done(
787 struct imsgbuf *);
788 const struct got_error *got_privsep_send_object_enumeration_incomplete(
789 struct imsgbuf *);
790 const struct got_error *got_privsep_send_enumerated_commit(struct imsgbuf *,
791 struct got_object_id *, time_t);
792 const struct got_error *got_privsep_recv_enumerated_objects(int *,
793 struct imsgbuf *, got_object_enumerate_commit_cb,
794 got_object_enumerate_tree_cb, void *, struct got_repository *);
796 const struct got_error *got_privsep_send_raw_delta_req(struct imsgbuf *, int,
797 struct got_object_id *);
798 const struct got_error *got_privsep_send_raw_delta_outfd(struct imsgbuf *, int);
799 const struct got_error *got_privsep_send_raw_delta(struct imsgbuf *, uint64_t,
800 uint64_t, off_t, off_t, off_t, off_t, struct got_object_id *);
801 const struct got_error *got_privsep_recv_raw_delta(uint64_t *, uint64_t *,
802 off_t *, off_t *, off_t *, off_t *, struct got_object_id **,
803 struct imsgbuf *);
805 const struct got_error *got_privsep_send_object_idlist(struct imsgbuf *,
806 struct got_object_id **, size_t);
807 const struct got_error *got_privsep_send_object_idlist_done(struct imsgbuf *);
808 const struct got_error *got_privsep_recv_object_idlist(int *,
809 struct got_object_id **, size_t *, struct imsgbuf *);
811 const struct got_error *got_privsep_send_delta_reuse_req(struct imsgbuf *);
812 const struct got_error *got_privsep_send_reused_deltas(struct imsgbuf *,
813 struct got_imsg_reused_delta *, size_t);
814 const struct got_error *got_privsep_send_reused_deltas_done(struct imsgbuf *);
815 const struct got_error *got_privsep_recv_reused_deltas(int *,
816 struct got_imsg_reused_delta *, size_t *, struct imsgbuf *);
818 const struct got_error *got_privsep_init_commit_painting(struct imsgbuf *);
819 const struct got_error *got_privsep_send_painting_request(struct imsgbuf *,
820 int, struct got_object_id *, intptr_t);
821 typedef const struct got_error *(*got_privsep_recv_painted_commit_cb)(void *,
822 struct got_object_id *, intptr_t);
823 const struct got_error *got_privsep_send_painted_commits(struct imsgbuf *,
824 struct got_object_id_queue *, int *, int, int);
825 const struct got_error *got_privsep_send_painting_commits_done(struct imsgbuf *);
826 const struct got_error *got_privsep_recv_painted_commits(
827 struct got_object_id_queue *, got_privsep_recv_painted_commit_cb, void *,
828 struct imsgbuf *);
830 void got_privsep_exec_child(int[2], const char *, const char *);