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,
154 /* Message sending file descriptor to a temporary file. */
155 GOT_IMSG_TMPFD,
157 /* Messages related to gitconfig files. */
158 GOT_IMSG_GITCONFIG_PARSE_REQUEST,
159 GOT_IMSG_GITCONFIG_REPOSITORY_FORMAT_VERSION_REQUEST,
160 GOT_IMSG_GITCONFIG_REPOSITORY_EXTENSIONS_REQUEST,
161 GOT_IMSG_GITCONFIG_AUTHOR_NAME_REQUEST,
162 GOT_IMSG_GITCONFIG_AUTHOR_EMAIL_REQUEST,
163 GOT_IMSG_GITCONFIG_REMOTES_REQUEST,
164 GOT_IMSG_GITCONFIG_INT_VAL,
165 GOT_IMSG_GITCONFIG_STR_VAL,
166 GOT_IMSG_GITCONFIG_REMOTES,
167 GOT_IMSG_GITCONFIG_REMOTE,
168 GOT_IMSG_GITCONFIG_OWNER_REQUEST,
169 GOT_IMSG_GITCONFIG_OWNER,
171 /* Messages related to gotconfig files. */
172 GOT_IMSG_GOTCONFIG_PARSE_REQUEST,
173 GOT_IMSG_GOTCONFIG_AUTHOR_REQUEST,
174 GOT_IMSG_GOTCONFIG_REMOTES_REQUEST,
175 GOT_IMSG_GOTCONFIG_INT_VAL,
176 GOT_IMSG_GOTCONFIG_STR_VAL,
177 GOT_IMSG_GOTCONFIG_REMOTES,
178 GOT_IMSG_GOTCONFIG_REMOTE,
180 /* Raw object access. Uncompress object data but do not parse it. */
181 GOT_IMSG_RAW_OBJECT_REQUEST,
182 GOT_IMSG_RAW_OBJECT_OUTFD,
183 GOT_IMSG_PACKED_RAW_OBJECT_REQUEST,
184 GOT_IMSG_RAW_OBJECT,
186 /* Read raw delta data from pack files. */
187 GOT_IMSG_RAW_DELTA_OUTFD,
188 GOT_IMSG_RAW_DELTA_REQUEST,
189 GOT_IMSG_RAW_DELTA,
191 /* Re-use deltas found in a pack file. */
192 GOT_IMSG_DELTA_REUSE_REQUEST,
193 GOT_IMSG_REUSED_DELTAS,
194 GOT_IMSG_DELTA_REUSE_DONE,
196 /* Transfer a list of object IDs. */
197 GOT_IMSG_OBJ_ID_LIST,
198 GOT_IMSG_OBJ_ID_LIST_DONE,
200 /* Messages related to patch files. */
201 GOT_IMSG_PATCH_FILE,
202 GOT_IMSG_PATCH_HUNK,
203 GOT_IMSG_PATCH_DONE,
204 GOT_IMSG_PATCH_LINE,
205 GOT_IMSG_PATCH,
206 GOT_IMSG_PATCH_EOF,
207 };
209 /* Structure for GOT_IMSG_ERROR. */
210 struct got_imsg_error {
211 int code; /* an error code from got_error.h */
212 int errno_code; /* in case code equals GOT_ERR_ERRNO */
213 } __attribute__((__packed__));
215 /*
216 * Structure for GOT_IMSG_TREE_REQUEST and GOT_IMSG_OBJECT data.
217 */
218 struct got_imsg_object {
219 uint8_t id[SHA1_DIGEST_LENGTH];
221 /* These fields are the same as in struct got_object. */
222 int type;
223 int flags;
224 size_t hdrlen;
225 size_t size;
226 off_t pack_offset;
227 int pack_idx;
228 } __attribute__((__packed__));
230 /* Structure for GOT_IMSG_COMMIT data. */
231 struct got_imsg_commit_object {
232 uint8_t tree_id[SHA1_DIGEST_LENGTH];
233 size_t author_len;
234 time_t author_time;
235 time_t author_gmtoff;
236 size_t committer_len;
237 time_t committer_time;
238 time_t committer_gmtoff;
239 size_t logmsg_len;
240 int nparents;
242 /*
243 * Followed by author_len + committer_len data bytes
244 */
246 /* Followed by 'nparents' SHA1_DIGEST_LENGTH length strings */
248 /*
249 * Followed by 'logmsg_len' bytes of commit log message data in
250 * one or more GOT_IMSG_COMMIT_LOGMSG messages.
251 */
252 } __attribute__((__packed__));
254 struct got_imsg_tree_entry {
255 char id[SHA1_DIGEST_LENGTH];
256 mode_t mode;
257 size_t namelen;
258 /* Followed by namelen bytes of entry's name, not NUL-terminated. */
259 } __attribute__((__packed__));
261 /* Structure for GOT_IMSG_TREE_ENTRIES. */
262 struct got_imsg_tree_entries {
263 size_t nentries; /* Number of tree entries contained in this message. */
265 /* Followed by nentries * struct got_imsg_tree_entry */
266 };
268 /* Structure for GOT_IMSG_TREE_OBJECT_REPLY data. */
269 struct got_imsg_tree_object {
270 int nentries; /* This many tree entries follow. */
271 };
273 /* Structure for GOT_IMSG_BLOB. */
274 struct got_imsg_blob {
275 size_t size;
276 size_t hdrlen;
278 /*
279 * If size <= GOT_PRIVSEP_INLINE_BLOB_DATA_MAX, blob data follows
280 * in the imsg buffer. Otherwise, blob data has been written to a
281 * file descriptor passed via the GOT_IMSG_BLOB_OUTFD imsg.
282 */
283 #define GOT_PRIVSEP_INLINE_BLOB_DATA_MAX \
284 (MAX_IMSGSIZE - IMSG_HEADER_SIZE - sizeof(struct got_imsg_blob))
285 };
287 /* Structure for GOT_IMSG_RAW_OBJECT. */
288 struct got_imsg_raw_obj {
289 off_t size;
290 size_t hdrlen;
292 /*
293 * If size <= GOT_PRIVSEP_INLINE_OBJECT_DATA_MAX, object data follows
294 * in the imsg buffer. Otherwise, object data has been written to a
295 * file descriptor passed via the GOT_IMSG_RAW_OBJECT_OUTFD imsg.
296 */
297 #define GOT_PRIVSEP_INLINE_OBJECT_DATA_MAX \
298 (MAX_IMSGSIZE - IMSG_HEADER_SIZE - sizeof(struct got_imsg_raw_obj))
299 };
301 /* Structure for GOT_IMSG_RAW_DELTA. */
302 struct got_imsg_raw_delta {
303 uint8_t base_id[SHA1_DIGEST_LENGTH];
304 uint64_t base_size;
305 uint64_t result_size;
306 off_t delta_size;
307 off_t delta_compressed_size;
308 off_t delta_offset;
309 off_t delta_out_offset;
311 /*
312 * Delta data has been written at delta_out_offset to the file
313 * descriptor passed via the GOT_IMSG_RAW_DELTA_OUTFD imsg.
314 */
315 };
317 /* Structures for GOT_IMSG_REUSED_DELTAS. */
318 struct got_imsg_reused_delta {
319 struct got_object_id id;
320 struct got_object_id base_id;
321 uint64_t base_size;
322 uint64_t result_size;
323 off_t delta_size;
324 off_t delta_compressed_size;
325 off_t delta_offset;
326 off_t delta_out_offset;
328 /*
329 * Delta data has been written at delta_out_offset to the file
330 * descriptor passed via the GOT_IMSG_RAW_DELTA_OUTFD imsg.
331 */
332 };
333 struct got_imsg_reused_deltas {
334 size_t ndeltas;
336 /*
337 * Followed by ndeltas * struct got_imsg_reused_delta.
338 */
340 #define GOT_IMSG_REUSED_DELTAS_MAX_NDELTAS \
341 ((MAX_IMSGSIZE - IMSG_HEADER_SIZE - \
342 sizeof(struct got_imsg_reused_deltas)) \
343 / sizeof(struct got_imsg_reused_delta))
344 };
346 /* Structure for GOT_IMSG_TAG data. */
347 struct got_imsg_tag_object {
348 uint8_t id[SHA1_DIGEST_LENGTH];
349 int obj_type;
350 size_t tag_len;
351 size_t tagger_len;
352 time_t tagger_time;
353 time_t tagger_gmtoff;
354 size_t tagmsg_len;
356 /*
357 * Followed by tag_len + tagger_len data bytes
358 */
360 /*
361 * Followed by 'tagmsg_len' bytes of tag message data in
362 * one or more GOT_IMSG_TAG_TAGMSG messages.
363 */
364 } __attribute__((__packed__));
366 /* Structure for GOT_IMSG_FETCH_HAVE_REF data. */
367 struct got_imsg_fetch_have_ref {
368 uint8_t id[SHA1_DIGEST_LENGTH];
369 size_t name_len;
370 /* Followed by name_len data bytes. */
371 } __attribute__((__packed__));
373 /* Structure for GOT_IMSG_FETCH_WANTED_BRANCH data. */
374 struct got_imsg_fetch_wanted_branch {
375 size_t name_len;
376 /* Followed by name_len data bytes. */
377 } __attribute__((__packed__));
379 /* Structure for GOT_IMSG_FETCH_WANTED_REF data. */
380 struct got_imsg_fetch_wanted_ref {
381 size_t name_len;
382 /* Followed by name_len data bytes. */
383 } __attribute__((__packed__));
385 /* Structure for GOT_IMSG_FETCH_REQUEST data. */
386 struct got_imsg_fetch_request {
387 int fetch_all_branches;
388 int list_refs_only;
389 int verbosity;
390 size_t n_have_refs;
391 size_t n_wanted_branches;
392 size_t n_wanted_refs;
393 /* Followed by n_have_refs GOT_IMSG_FETCH_HAVE_REF messages. */
394 /* Followed by n_wanted_branches times GOT_IMSG_FETCH_WANTED_BRANCH. */
395 /* Followed by n_wanted_refs times GOT_IMSG_FETCH_WANTED_REF. */
396 } __attribute__((__packed__));
398 /* Structures for GOT_IMSG_FETCH_SYMREFS data. */
399 struct got_imsg_fetch_symref {
400 size_t name_len;
401 size_t target_len;
403 /*
404 * Followed by name_len + target_len data bytes.
405 */
406 } __attribute__((__packed__));
408 struct got_imsg_fetch_symrefs {
409 size_t nsymrefs;
411 /* Followed by nsymrefs times of got_imsg_fetch_symref data. */
412 } __attribute__((__packed__));
414 /* Structure for GOT_IMSG_FETCH_REF data. */
415 struct got_imsg_fetch_ref {
416 /* Describes a reference which will be fetched. */
417 uint8_t refid[SHA1_DIGEST_LENGTH];
418 /* Followed by reference name in remaining data of imsg buffer. */
419 };
421 /* Structure for GOT_IMSG_FETCH_DOWNLOAD_PROGRESS data. */
422 struct got_imsg_fetch_download_progress {
423 /* Number of packfile data bytes downloaded so far. */
424 off_t packfile_bytes;
425 };
427 /* Structure for GOT_IMSG_SEND_REQUEST data. */
428 struct got_imsg_send_request {
429 int verbosity;
430 size_t nrefs;
431 /* Followed by nrefs GOT_IMSG_SEND_REF messages. */
432 } __attribute__((__packed__));
434 /* Structure for GOT_IMSG_SEND_UPLOAD_PROGRESS data. */
435 struct got_imsg_send_upload_progress {
436 /* Number of packfile data bytes uploaded so far. */
437 off_t packfile_bytes;
438 };
440 /* Structure for GOT_IMSG_SEND_REF data. */
441 struct got_imsg_send_ref {
442 uint8_t id[SHA1_DIGEST_LENGTH];
443 int delete;
444 size_t name_len;
445 /* Followed by name_len data bytes. */
446 } __attribute__((__packed__));
448 /* Structure for GOT_IMSG_SEND_REMOTE_REF data. */
449 struct got_imsg_send_remote_ref {
450 uint8_t id[SHA1_DIGEST_LENGTH];
451 size_t name_len;
452 /* Followed by name_len data bytes. */
453 } __attribute__((__packed__));
455 /* Structure for GOT_IMSG_SEND_REF_STATUS data. */
456 struct got_imsg_send_ref_status {
457 int success;
458 size_t name_len;
459 /* Followed by name_len data bytes. */
460 } __attribute__((__packed__));
462 /* Structure for GOT_IMSG_IDXPACK_REQUEST data. */
463 struct got_imsg_index_pack_request {
464 uint8_t pack_hash[SHA1_DIGEST_LENGTH];
465 } __attribute__((__packed__));
467 /* Structure for GOT_IMSG_IDXPACK_PROGRESS data. */
468 struct got_imsg_index_pack_progress {
469 /* Total number of objects in pack file. */
470 int nobj_total;
472 /* Number of objects indexed so far. */
473 int nobj_indexed;
475 /* Number of non-deltified objects in pack file. */
476 int nobj_loose;
478 /* Number of deltified objects resolved so far. */
479 int nobj_resolved;
480 };
482 /* Structure for GOT_IMSG_PACKIDX. */
483 struct got_imsg_packidx {
484 size_t len;
485 off_t packfile_size;
486 /* Additionally, a file desciptor is passed via imsg. */
487 };
489 /* Structure for GOT_IMSG_PACK. */
490 struct got_imsg_pack {
491 char path_packfile[PATH_MAX];
492 size_t filesize;
493 /* Additionally, a file desciptor is passed via imsg. */
494 } __attribute__((__packed__));
496 /*
497 * Structure for GOT_IMSG_OBJECT_REQUEST, GOT_IMSG_BLOB_REQUEST,
498 * GOT_IMSG_TREE_REQUEST, GOT_IMSG_COMMIT_REQUEST, and
499 * GOT_IMSG_TAG_REQUEST data.
500 */
501 struct got_object_id;
503 /*
504 * Structure for GOT_IMSG_PACKED_OBJECT_REQUEST and
505 * GOT_IMSG_PACKED_RAW_OBJECT_REQUEST data.
506 */
507 struct got_imsg_packed_object {
508 uint8_t id[SHA1_DIGEST_LENGTH];
509 int idx;
510 } __attribute__((__packed__));
512 /*
513 * Structure for GOT_IMSG_DELTA data.
514 */
515 struct got_imsg_delta {
516 /* These fields are the same as in struct got_delta. */
517 off_t offset;
518 size_t tslen;
519 int type;
520 size_t size;
521 off_t data_offset;
522 };
524 /*
525 * Structure for GOT_IMSG_RAW_DELTA_REQUEST data.
526 */
527 struct got_imsg_raw_delta_request {
528 uint8_t id[SHA1_DIGEST_LENGTH];
529 int idx;
530 };
532 /*
533 * Structure for GOT_IMSG_OBJ_ID_LIST data.
534 * Multiple such messages may be sent back-to-back, where each message
535 * contains a chunk of IDs. The entire list must be terminated with a
536 * GOT_IMSG_OBJ_ID_LIST_DONE message.
537 */
538 struct got_imsg_object_idlist {
539 size_t nids;
541 /*
542 * Followed by nids * struct got_object_id.
543 */
545 #define GOT_IMSG_OBJ_ID_LIST_MAX_NIDS \
546 ((MAX_IMSGSIZE - IMSG_HEADER_SIZE - \
547 sizeof(struct got_imsg_object_idlist)) / sizeof(struct got_object_id))
548 };
550 /* Structure for GOT_IMSG_COMMIT_TRAVERSAL_REQUEST */
551 struct got_imsg_commit_traversal_request {
552 uint8_t id[SHA1_DIGEST_LENGTH];
553 int idx;
554 size_t path_len;
555 /* Followed by path_len bytes of path data */
556 } __attribute__((__packed__));
558 /* Structure for GOT_IMSG_TRAVERSED_COMMITS */
559 struct got_imsg_traversed_commits {
560 size_t ncommits;
561 /* Followed by ncommit IDs of SHA1_DIGEST_LENGTH each */
562 } __attribute__((__packed__));
564 /* Structure for GOT_IMSG_ENUMERATED_COMMIT */
565 struct got_imsg_enumerated_commit {
566 uint8_t id[SHA1_DIGEST_LENGTH];
567 time_t mtime;
568 } __attribute__((__packed__));
570 /* Structure for GOT_IMSG_ENUMERATED_TREE */
571 struct got_imsg_enumerated_tree {
572 uint8_t id[SHA1_DIGEST_LENGTH]; /* tree ID */
573 int nentries; /* number of tree entries */
575 /* Followed by tree's path in remaining data of imsg buffer. */
577 /* Followed by nentries * GOT_IMSG_TREE_ENTRY messages. */
578 } __attribute__((__packed__));
580 /*
581 * Structure for GOT_IMSG_GOTCONFIG_REMOTE and
582 * GOT_IMSG_GOTCONFIG_REMOTE data.
583 */
584 struct got_imsg_remote {
585 size_t name_len;
586 size_t fetch_url_len;
587 size_t send_url_len;
588 int mirror_references;
589 int fetch_all_branches;
590 int nfetch_branches;
591 int nsend_branches;
592 int nfetch_refs;
594 /* Followed by name_len data bytes. */
595 /* Followed by fetch_url_len + send_url_len data bytes. */
596 /* Followed by nfetch_branches GOT_IMSG_GITCONFIG_STR_VAL messages. */
597 /* Followed by nsend_branches GOT_IMSG_GITCONFIG_STR_VAL messages. */
598 /* Followed by nfetch_refs GOT_IMSG_GITCONFIG_STR_VAL messages. */
599 } __attribute__((__packed__));
601 /*
602 * Structure for GOT_IMSG_GITCONFIG_REMOTES data.
603 */
604 struct got_imsg_remotes {
605 int nremotes; /* This many GOT_IMSG_GITCONFIG_REMOTE messages follow. */
606 };
608 /*
609 * Structure for GOT_IMSG_PATCH data.
610 */
611 struct got_imsg_patch {
612 int git;
613 char old[PATH_MAX];
614 char new[PATH_MAX];
615 };
617 /*
618 * Structure for GOT_IMSG_PATCH_HUNK data.
619 */
620 struct got_imsg_patch_hunk {
621 int oldfrom;
622 int oldlines;
623 int newfrom;
624 int newlines;
625 };
627 struct got_remote_repo;
628 struct got_pack;
629 struct got_packidx;
630 struct got_pathlist_head;
632 const struct got_error *got_send_ack(pid_t);
633 const struct got_error *got_privsep_wait_for_child(pid_t);
634 const struct got_error *got_privsep_flush_imsg(struct imsgbuf *);
635 const struct got_error *got_privsep_send_stop(int);
636 const struct got_error *got_privsep_recv_imsg(struct imsg *, struct imsgbuf *,
637 size_t);
638 void got_privsep_send_error(struct imsgbuf *, const struct got_error *);
639 const struct got_error *got_privsep_send_ack(struct imsgbuf *);
640 const struct got_error *got_privsep_wait_ack(struct imsgbuf *);
641 const struct got_error *got_privsep_send_obj_req(struct imsgbuf *, int,
642 struct got_object_id *);
643 const struct got_error *got_privsep_send_raw_obj_req(struct imsgbuf *, int,
644 struct got_object_id *);
645 const struct got_error *got_privsep_send_raw_obj_outfd(struct imsgbuf *, int);
646 const struct got_error *got_privsep_send_commit_req(struct imsgbuf *, int,
647 struct got_object_id *, int);
648 const struct got_error *got_privsep_send_tree_req(struct imsgbuf *, int,
649 struct got_object_id *, int);
650 const struct got_error *got_privsep_send_tag_req(struct imsgbuf *, int,
651 struct got_object_id *, int);
652 const struct got_error *got_privsep_send_blob_req(struct imsgbuf *, int,
653 struct got_object_id *, int);
654 const struct got_error *got_privsep_send_blob_outfd(struct imsgbuf *, int);
655 const struct got_error *got_privsep_send_tmpfd(struct imsgbuf *, int);
656 const struct got_error *got_privsep_send_obj(struct imsgbuf *,
657 struct got_object *);
658 const struct got_error *got_privsep_send_index_pack_req(struct imsgbuf *,
659 uint8_t *, int);
660 const struct got_error *got_privsep_send_index_pack_outfd(struct imsgbuf *,
661 int);
662 const struct got_error *got_privsep_recv_index_progress(int *, int *, int *,
663 int *, int *, struct imsgbuf *ibuf);
664 const struct got_error *got_privsep_send_fetch_req(struct imsgbuf *, int,
665 struct got_pathlist_head *, int, struct got_pathlist_head *,
666 struct got_pathlist_head *, int, int);
667 const struct got_error *got_privsep_send_fetch_outfd(struct imsgbuf *, int);
668 const struct got_error *got_privsep_recv_fetch_progress(int *,
669 struct got_object_id **, char **, struct got_pathlist_head *, char **,
670 off_t *, uint8_t *, struct imsgbuf *);
671 const struct got_error *got_privsep_send_send_req(struct imsgbuf *, int,
672 struct got_pathlist_head *, struct got_pathlist_head *, int);
673 const struct got_error *got_privsep_recv_send_remote_refs(
674 struct got_pathlist_head *, struct imsgbuf *);
675 const struct got_error *got_privsep_send_packfd(struct imsgbuf *, int);
676 const struct got_error *got_privsep_recv_send_progress(int *, off_t *,
677 int *, char **, struct imsgbuf *);
678 const struct got_error *got_privsep_get_imsg_obj(struct got_object **,
679 struct imsg *, struct imsgbuf *);
680 const struct got_error *got_privsep_recv_obj(struct got_object **,
681 struct imsgbuf *);
682 const struct got_error *got_privsep_send_raw_obj(struct imsgbuf *, off_t,
683 size_t, uint8_t *);
684 const struct got_error *got_privsep_recv_raw_obj(uint8_t **, off_t *, size_t *,
685 struct imsgbuf *);
686 const struct got_error *got_privsep_send_commit(struct imsgbuf *,
687 struct got_commit_object *);
688 const struct got_error *got_privsep_recv_commit(struct got_commit_object **,
689 struct imsgbuf *);
690 const struct got_error *got_privsep_recv_tree(struct got_tree_object **,
691 struct imsgbuf *);
692 struct got_parsed_tree_entry;
693 const struct got_error *got_privsep_send_tree(struct imsgbuf *,
694 struct got_parsed_tree_entry *, int);
695 const struct got_error *got_privsep_send_blob(struct imsgbuf *, size_t, size_t,
696 const uint8_t *);
697 const struct got_error *got_privsep_recv_blob(uint8_t **, size_t *, size_t *,
698 struct imsgbuf *);
699 const struct got_error *got_privsep_send_tag(struct imsgbuf *,
700 struct got_tag_object *);
701 const struct got_error *got_privsep_recv_tag(struct got_tag_object **,
702 struct imsgbuf *);
703 const struct got_error *got_privsep_init_pack_child(struct imsgbuf *,
704 struct got_pack *, struct got_packidx *);
705 const struct got_error *got_privsep_send_packed_obj_req(struct imsgbuf *, int,
706 struct got_object_id *);
707 const struct got_error *got_privsep_send_packed_raw_obj_req(struct imsgbuf *,
708 int, struct got_object_id *);
709 const struct got_error *got_privsep_send_pack_child_ready(struct imsgbuf *);
711 const struct got_error *got_privsep_send_gitconfig_parse_req(struct imsgbuf *,
712 int);
713 const struct got_error *
714 got_privsep_send_gitconfig_repository_format_version_req(struct imsgbuf *);
715 const struct got_error *got_privsep_send_gitconfig_repository_extensions_req(
716 struct imsgbuf *);
717 const struct got_error *got_privsep_send_gitconfig_author_name_req(
718 struct imsgbuf *);
719 const struct got_error *got_privsep_send_gitconfig_author_email_req(
720 struct imsgbuf *);
721 const struct got_error *got_privsep_send_gitconfig_remotes_req(
722 struct imsgbuf *);
723 const struct got_error *got_privsep_send_gitconfig_owner_req(struct imsgbuf *);
724 const struct got_error *got_privsep_recv_gitconfig_str(char **,
725 struct imsgbuf *);
726 const struct got_error *got_privsep_recv_gitconfig_int(int *, struct imsgbuf *);
727 const struct got_error *got_privsep_recv_gitconfig_remotes(
728 struct got_remote_repo **, int *, struct imsgbuf *);
730 const struct got_error *got_privsep_send_gotconfig_parse_req(struct imsgbuf *,
731 int);
732 const struct got_error *got_privsep_send_gotconfig_author_req(struct imsgbuf *);
733 const struct got_error *got_privsep_send_gotconfig_remotes_req(
734 struct imsgbuf *);
735 const struct got_error *got_privsep_recv_gotconfig_str(char **,
736 struct imsgbuf *);
737 const struct got_error *got_privsep_recv_gotconfig_remotes(
738 struct got_remote_repo **, int *, struct imsgbuf *);
740 const struct got_error *got_privsep_send_commit_traversal_request(
741 struct imsgbuf *, struct got_object_id *, int, const char *);
742 const struct got_error *got_privsep_recv_traversed_commits(
743 struct got_commit_object **, struct got_object_id **,
744 struct got_object_id_queue *, struct imsgbuf *);
745 const struct got_error *got_privsep_send_enumerated_tree(size_t *,
746 struct imsgbuf *, struct got_object_id *, const char *,
747 struct got_parsed_tree_entry *, int);
748 const struct got_error *got_privsep_send_object_enumeration_request(
749 struct imsgbuf *);
750 const struct got_error *got_privsep_send_object_enumeration_done(
751 struct imsgbuf *);
752 const struct got_error *got_privsep_send_enumerated_commit(struct imsgbuf *,
753 struct got_object_id *, time_t);
754 const struct got_error *got_privsep_recv_enumerated_objects(struct imsgbuf *,
755 got_object_enumerate_commit_cb, got_object_enumerate_tree_cb, void *,
756 struct got_repository *);
758 const struct got_error *got_privsep_send_raw_delta_req(struct imsgbuf *, int,
759 struct got_object_id *);
760 const struct got_error *got_privsep_send_raw_delta_outfd(struct imsgbuf *, int);
761 const struct got_error *got_privsep_send_raw_delta(struct imsgbuf *, uint64_t,
762 uint64_t, off_t, off_t, off_t, off_t, struct got_object_id *);
763 const struct got_error *got_privsep_recv_raw_delta(uint64_t *, uint64_t *,
764 off_t *, off_t *, off_t *, off_t *, struct got_object_id **,
765 struct imsgbuf *);
767 const struct got_error *got_privsep_send_object_idlist(struct imsgbuf *,
768 struct got_object_id **, size_t);
769 const struct got_error *got_privsep_send_object_idlist_done(struct imsgbuf *);
770 const struct got_error *got_privsep_recv_object_idlist(int *,
771 struct got_object_id **, size_t *, struct imsgbuf *);
773 const struct got_error *got_privsep_send_delta_reuse_req(struct imsgbuf *);
774 const struct got_error *got_privsep_send_reused_deltas(struct imsgbuf *,
775 struct got_imsg_reused_delta *, size_t);
776 const struct got_error *got_privsep_send_reused_deltas_done(struct imsgbuf *);
777 const struct got_error *got_privsep_recv_reused_deltas(int *,
778 struct got_imsg_reused_delta *, size_t *, struct imsgbuf *);
780 void got_privsep_exec_child(int[2], const char *, const char *);