style(9) only; no functional changes
[got-portable.git] / lib / got_lib_privsep.h
blob7dcc1e80f53fa249b30e5aa7ce4a8e337967d80b
1 /*
2 * Copyright (c) 2018, 2019 Stefan Sperling <stsp@openbsd.org>
3 * Copyright (c) 2019, Ori Bernstein <ori@openbsd.org>
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.
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.
19 * All code runs under the same UID but sensitive code paths are run in a
20 * separate process with tighter pledge(2) promises; data is communicated
21 * between processes via imsgbuf_flush(3) and imsgbuf_read(3).
22 * This behaviour is transparent to users of the library.
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.
28 * We exec(2) after a fork(2). Parts of our library functionality are
29 * accessible via separate executables in a libexec directory.
32 #define GOT_IMSG_FD_CHILD (STDERR_FILENO + 1)
34 #ifndef GOT_LIBEXECDIR
35 #define GOT_LIBEXECDIR /usr/local/bin
36 #endif
38 /* Names of helper programs in libexec directory */
39 #define GOT_PROG_READ_OBJECT got-read-object
40 #define GOT_PROG_READ_TREE got-read-tree
41 #define GOT_PROG_READ_COMMIT got-read-commit
42 #define GOT_PROG_READ_BLOB got-read-blob
43 #define GOT_PROG_READ_TAG got-read-tag
44 #define GOT_PROG_READ_PACK got-read-pack
45 #define GOT_PROG_READ_GITCONFIG got-read-gitconfig
46 #define GOT_PROG_READ_GOTCONFIG got-read-gotconfig
47 #define GOT_PROG_READ_PATCH got-read-patch
48 #define GOT_PROG_FETCH_PACK got-fetch-pack
49 #define GOT_PROG_INDEX_PACK got-index-pack
50 #define GOT_PROG_SEND_PACK got-send-pack
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 occurred while processing a request. */
86 GOT_IMSG_ERROR,
88 /* Stop the child process. */
89 GOT_IMSG_STOP,
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.
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 /* Reuse 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,
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__));
224 * Structure for GOT_IMSG_TREE_REQUEST and GOT_IMSG_OBJECT data.
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;
251 * Followed by author_len + committer_len data bytes
254 /* Followed by 'nparents' struct got_object_id */
257 * Followed by 'logmsg_len' bytes of commit log message data in
258 * one or more GOT_IMSG_COMMIT_LOGMSG messages.
260 } __attribute__((__packed__));
262 struct got_imsg_tree_entry {
263 char id[GOT_HASH_DIGEST_MAXLEN];
264 int algo;
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 */
277 /* Structure for GOT_IMSG_TREE_OBJECT_REPLY data. */
278 struct got_imsg_tree_object {
279 int nentries; /* This many tree entries follow. */
282 /* Structure for GOT_IMSG_BLOB. */
283 struct got_imsg_blob {
284 size_t size;
285 size_t hdrlen;
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.
292 #define GOT_PRIVSEP_INLINE_BLOB_DATA_MAX \
293 (MAX_IMSGSIZE - IMSG_HEADER_SIZE - sizeof(struct got_imsg_blob))
296 /* Structure for GOT_IMSG_RAW_OBJECT. */
297 struct got_imsg_raw_obj {
298 off_t size;
299 size_t hdrlen;
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.
306 #define GOT_PRIVSEP_INLINE_OBJECT_DATA_MAX \
307 (MAX_IMSGSIZE - IMSG_HEADER_SIZE - sizeof(struct got_imsg_raw_obj))
310 /* Structure for GOT_IMSG_RAW_DELTA. */
311 struct got_imsg_raw_delta {
312 struct got_object_id base_id;
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;
321 * Delta data has been written at delta_out_offset to the file
322 * descriptor passed via the GOT_IMSG_RAW_DELTA_OUTFD imsg.
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;
336 struct got_imsg_reused_deltas {
337 size_t ndeltas;
340 * Followed by ndeltas * struct got_imsg_reused_delta.
343 #define GOT_IMSG_REUSED_DELTAS_MAX_NDELTAS \
344 ((MAX_IMSGSIZE - IMSG_HEADER_SIZE - \
345 sizeof(struct got_imsg_reused_deltas)) \
346 / sizeof(struct got_imsg_reused_delta))
349 /* Structure for GOT_IMSG_COMMIT_PAINTING_REQUEST. */
350 struct got_imsg_commit_painting_request {
351 struct got_object_id id;
352 int idx;
353 int color;
354 } __attribute__((__packed__));
356 /* Structure for GOT_IMSG_PAINTED_COMMITS. */
357 struct got_imsg_painted_commit {
358 struct got_object_id id;
359 intptr_t color;
360 } __attribute__((__packed__));
362 struct got_imsg_painted_commits {
363 int ncommits;
364 int present_in_pack;
366 * Followed by ncommits * struct got_imsg_painted_commit.
368 } __attribute__((__packed__));
370 /* Structure for GOT_IMSG_TAG data. */
371 struct got_imsg_tag_object {
372 struct got_object_id id;
373 int obj_type;
374 size_t tag_len;
375 size_t tagger_len;
376 time_t tagger_time;
377 time_t tagger_gmtoff;
378 size_t tagmsg_len;
381 * Followed by tag_len + tagger_len data bytes
385 * Followed by 'tagmsg_len' bytes of tag message data in
386 * one or more GOT_IMSG_TAG_TAGMSG messages.
388 } __attribute__((__packed__));
390 /* Structure for GOT_IMSG_FETCH_HAVE_REF data. */
391 struct got_imsg_fetch_have_ref {
392 struct got_object_id id;
393 size_t name_len;
394 /* Followed by name_len data bytes. */
395 } __attribute__((__packed__));
397 /* Structure for GOT_IMSG_FETCH_WANTED_BRANCH data. */
398 struct got_imsg_fetch_wanted_branch {
399 size_t name_len;
400 /* Followed by name_len data bytes. */
401 } __attribute__((__packed__));
403 /* Structure for GOT_IMSG_FETCH_WANTED_REF data. */
404 struct got_imsg_fetch_wanted_ref {
405 size_t name_len;
406 /* Followed by name_len data bytes. */
407 } __attribute__((__packed__));
409 /* Structure for GOT_IMSG_FETCH_REQUEST data. */
410 struct got_imsg_fetch_request {
411 int no_head;
412 int fetch_all_branches;
413 int list_refs_only;
414 int verbosity;
415 size_t worktree_branch_len;
416 size_t remote_head_len;
417 size_t n_have_refs;
418 size_t n_wanted_branches;
419 size_t n_wanted_refs;
420 /* Followed by worktree_branch_len bytes of reference name. */
421 /* Followed by remote_head_len bytes of reference name. */
422 /* Followed by n_have_refs GOT_IMSG_FETCH_HAVE_REF messages. */
423 /* Followed by n_wanted_branches times GOT_IMSG_FETCH_WANTED_BRANCH. */
424 /* Followed by n_wanted_refs times GOT_IMSG_FETCH_WANTED_REF. */
425 } __attribute__((__packed__));
427 /* Structures for GOT_IMSG_FETCH_SYMREFS data. */
428 struct got_imsg_fetch_symref {
429 size_t name_len;
430 size_t target_len;
433 * Followed by name_len + target_len data bytes.
435 } __attribute__((__packed__));
437 struct got_imsg_fetch_symrefs {
438 size_t nsymrefs;
440 /* Followed by nsymrefs times of got_imsg_fetch_symref data. */
441 } __attribute__((__packed__));
443 /* Structure for GOT_IMSG_FETCH_REF data. */
444 struct got_imsg_fetch_ref {
445 /* Describes a reference which will be fetched. */
446 struct got_object_id refid;
447 /* Followed by reference name in remaining data of imsg buffer. */
450 /* Structure for GOT_IMSG_FETCH_DOWNLOAD_PROGRESS data. */
451 struct got_imsg_fetch_download_progress {
452 /* Number of packfile data bytes downloaded so far. */
453 off_t packfile_bytes;
456 /* Structure for GOT_IMSG_SEND_REQUEST data. */
457 struct got_imsg_send_request {
458 int verbosity;
459 size_t nrefs;
460 /* Followed by nrefs GOT_IMSG_SEND_REF messages. */
461 } __attribute__((__packed__));
463 /* Structure for GOT_IMSG_SEND_UPLOAD_PROGRESS data. */
464 struct got_imsg_send_upload_progress {
465 /* Number of packfile data bytes uploaded so far. */
466 off_t packfile_bytes;
469 /* Structure for GOT_IMSG_SEND_REF data. */
470 struct got_imsg_send_ref {
471 struct got_object_id id;
472 int delete;
473 size_t name_len;
474 /* Followed by name_len data bytes. */
475 } __attribute__((__packed__));
477 /* Structure for GOT_IMSG_SEND_REMOTE_REF data. */
478 struct got_imsg_send_remote_ref {
479 struct got_object_id id;
480 size_t name_len;
481 /* Followed by name_len data bytes. */
482 } __attribute__((__packed__));
484 /* Structure for GOT_IMSG_SEND_REF_STATUS data. */
485 struct got_imsg_send_ref_status {
486 int success;
487 size_t name_len;
488 size_t errmsg_len;
489 /* Followed by name_len data bytes. */
490 /* Followed by errmsg_len data bytes. */
491 } __attribute__((__packed__));
493 /* Structure for GOT_IMSG_IDXPACK_REQUEST data. */
494 struct got_imsg_index_pack_request {
495 struct got_object_id id;
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;
513 /* Structure for GOT_IMSG_PACKIDX. */
514 struct got_imsg_packidx {
515 size_t len;
516 off_t packfile_size;
517 int algo;
518 /* Additionally, a file descriptor is passed via imsg. */
521 /* Structure for GOT_IMSG_PACK. */
522 struct got_imsg_pack {
523 char path_packfile[PATH_MAX];
524 off_t filesize;
525 int algo;
526 /* Additionally, a file descriptor is passed via imsg. */
527 } __attribute__((__packed__));
530 * Structure for GOT_IMSG_OBJECT_REQUEST, GOT_IMSG_BLOB_REQUEST,
531 * GOT_IMSG_TREE_REQUEST, GOT_IMSG_COMMIT_REQUEST, and
532 * GOT_IMSG_TAG_REQUEST data.
534 struct got_object_id;
537 * Structure for GOT_IMSG_PACKED_OBJECT_REQUEST and
538 * GOT_IMSG_PACKED_RAW_OBJECT_REQUEST data.
540 struct got_imsg_packed_object {
541 struct got_object_id id;
542 int idx;
543 } __attribute__((__packed__));
546 * Structure for GOT_IMSG_DELTA data.
548 struct got_imsg_delta {
549 /* These fields are the same as in struct got_delta. */
550 off_t offset;
551 size_t tslen;
552 int type;
553 size_t size;
554 off_t data_offset;
558 * Structure for GOT_IMSG_RAW_DELTA_REQUEST data.
560 struct got_imsg_raw_delta_request {
561 struct got_object_id id;
562 int idx;
566 * Structure for GOT_IMSG_OBJ_ID_LIST data.
567 * Multiple such messages may be sent back-to-back, where each message
568 * contains a chunk of IDs. The entire list must be terminated with a
569 * GOT_IMSG_OBJ_ID_LIST_DONE message.
571 struct got_imsg_object_idlist {
572 size_t nids;
575 * Followed by nids * struct got_object_id.
578 #define GOT_IMSG_OBJ_ID_LIST_MAX_NIDS \
579 ((MAX_IMSGSIZE - IMSG_HEADER_SIZE - \
580 sizeof(struct got_imsg_object_idlist)) / sizeof(struct got_object_id))
583 /* Structure for GOT_IMSG_COMMIT_TRAVERSAL_REQUEST */
584 struct got_imsg_commit_traversal_request {
585 struct got_imsg_packed_object iobj;
586 size_t path_len;
587 /* Followed by path_len bytes of path data */
588 } __attribute__((__packed__));
590 /* Structure for GOT_IMSG_TRAVERSED_COMMITS */
591 struct got_imsg_traversed_commits {
592 size_t ncommits;
593 /* Followed by ncommit struct got_object_id */
594 } __attribute__((__packed__));
596 /* Structure for GOT_IMSG_ENUMERATED_COMMIT */
597 struct got_imsg_enumerated_commit {
598 struct got_object_id id;
599 time_t mtime;
600 } __attribute__((__packed__));
602 /* Structure for GOT_IMSG_ENUMERATED_TREE */
603 struct got_imsg_enumerated_tree {
604 struct got_object_id id; /* tree ID */
605 int nentries; /* number of tree entries */
607 /* Followed by tree's path in remaining data of imsg buffer. */
609 /* Followed by nentries * GOT_IMSG_TREE_ENTRY messages. */
610 } __attribute__((__packed__));
613 * Structure for GOT_IMSG_GOTCONFIG_REMOTE and
614 * GOT_IMSG_GOTCONFIG_REMOTE data.
616 struct got_imsg_remote {
617 size_t name_len;
618 size_t fetch_url_len;
619 size_t send_url_len;
620 int mirror_references;
621 int fetch_all_branches;
622 int nfetch_branches;
623 int nsend_branches;
624 int nfetch_refs;
626 /* Followed by name_len data bytes. */
627 /* Followed by fetch_url_len + send_url_len data bytes. */
628 /* Followed by nfetch_branches GOT_IMSG_GITCONFIG_STR_VAL messages. */
629 /* Followed by nsend_branches GOT_IMSG_GITCONFIG_STR_VAL messages. */
630 /* Followed by nfetch_refs GOT_IMSG_GITCONFIG_STR_VAL messages. */
631 } __attribute__((__packed__));
634 * Structure for GOT_IMSG_GITCONFIG_REMOTES data.
636 struct got_imsg_remotes {
637 int nremotes; /* This many GOT_IMSG_GITCONFIG_REMOTE messages follow. */
641 * Structure for GOT_IMSG_GITCONFIG_PAIR.
643 struct got_imsg_gitconfig_pair {
644 size_t klen;
645 size_t vlen;
646 /* Followed by klen data bytes of key string. */
647 /* Followed by vlen data bytes of value string. */
651 * Structure for GOT_IMSG_PATCH data.
653 struct got_imsg_patch {
654 int git;
655 int xbit;
656 char old[PATH_MAX];
657 char new[PATH_MAX];
658 char cid[GOT_HASH_DIGEST_STRING_MAXLEN];
659 char blob[GOT_HASH_DIGEST_STRING_MAXLEN];
663 * Structure for GOT_IMSG_PATCH_HUNK data.
665 struct got_imsg_patch_hunk {
666 int oldfrom;
667 int oldlines;
668 int newfrom;
669 int newlines;
672 struct got_remote_repo;
673 struct got_pack;
674 struct got_packidx;
675 struct got_pathlist_head;
677 const struct got_error *got_send_ack(pid_t);
678 const struct got_error *got_privsep_wait_for_child(pid_t);
679 const struct got_error *got_privsep_flush_imsg(struct imsgbuf *);
680 const struct got_error *got_privsep_send_stop(int);
681 const struct got_error *got_privsep_recv_imsg(struct imsg *, struct imsgbuf *,
682 size_t);
683 void got_privsep_send_error(struct imsgbuf *, const struct got_error *);
684 const struct got_error *got_privsep_send_ack(struct imsgbuf *);
685 const struct got_error *got_privsep_wait_ack(struct imsgbuf *);
686 const struct got_error *got_privsep_send_obj_req(struct imsgbuf *, int,
687 struct got_object_id *);
688 const struct got_error *got_privsep_send_raw_obj_req(struct imsgbuf *, int,
689 struct got_object_id *);
690 const struct got_error *got_privsep_send_raw_obj_outfd(struct imsgbuf *, int);
691 const struct got_error *got_privsep_send_commit_req(struct imsgbuf *, int,
692 struct got_object_id *, int);
693 const struct got_error *got_privsep_send_tree_req(struct imsgbuf *, int,
694 struct got_object_id *, int);
695 const struct got_error *got_privsep_send_tag_req(struct imsgbuf *, int,
696 struct got_object_id *, int);
697 const struct got_error *got_privsep_send_blob_req(struct imsgbuf *, int,
698 struct got_object_id *, int);
699 const struct got_error *got_privsep_send_blob_outfd(struct imsgbuf *, int);
700 const struct got_error *got_privsep_send_tmpfd(struct imsgbuf *, int);
701 const struct got_error *got_privsep_send_obj(struct imsgbuf *,
702 struct got_object *);
703 const struct got_error *got_privsep_send_index_pack_req(struct imsgbuf *,
704 struct got_object_id *, int);
705 const struct got_error *got_privsep_send_index_pack_outfd(struct imsgbuf *,
706 int);
707 const struct got_error *got_privsep_recv_index_progress(int *, int *, int *,
708 int *, int *, struct imsgbuf *ibuf);
709 const struct got_error *got_privsep_send_fetch_req(struct imsgbuf *, int,
710 struct got_pathlist_head *, int, struct got_pathlist_head *,
711 struct got_pathlist_head *, int, const char *, const char *, int, int);
712 const struct got_error *got_privsep_send_fetch_outfd(struct imsgbuf *, int);
713 const struct got_error *got_privsep_recv_fetch_progress(int *,
714 struct got_object_id **, char **, struct got_pathlist_head *, char **,
715 off_t *, uint8_t *, struct imsgbuf *);
716 const struct got_error *got_privsep_send_send_req(struct imsgbuf *, int,
717 struct got_pathlist_head *, struct got_pathlist_head *, int);
718 const struct got_error *got_privsep_recv_send_remote_refs(
719 struct got_pathlist_head *, struct imsgbuf *);
720 const struct got_error *got_privsep_send_packfd(struct imsgbuf *, int);
721 const struct got_error *got_privsep_recv_send_progress(int *, off_t *,
722 int *, char **, char **, struct imsgbuf *);
723 const struct got_error *got_privsep_get_imsg_obj(struct got_object **,
724 struct imsg *, struct imsgbuf *);
725 const struct got_error *got_privsep_recv_obj(struct got_object **,
726 struct imsgbuf *);
727 const struct got_error *got_privsep_send_raw_obj(struct imsgbuf *, off_t,
728 size_t, uint8_t *);
729 const struct got_error *got_privsep_recv_raw_obj(uint8_t **, off_t *, size_t *,
730 struct imsgbuf *);
731 const struct got_error *got_privsep_send_commit(struct imsgbuf *,
732 struct got_commit_object *);
733 const struct got_error *got_privsep_recv_commit(struct got_commit_object **,
734 struct imsgbuf *);
735 const struct got_error *got_privsep_recv_tree(struct got_tree_object **,
736 struct imsgbuf *);
737 struct got_parsed_tree_entry;
738 const struct got_error *got_privsep_send_tree(struct imsgbuf *,
739 struct got_parsed_tree_entry *, int);
740 const struct got_error *got_privsep_send_blob(struct imsgbuf *, size_t, size_t,
741 const uint8_t *);
742 const struct got_error *got_privsep_recv_blob(uint8_t **, size_t *, size_t *,
743 struct imsgbuf *);
744 const struct got_error *got_privsep_send_tag(struct imsgbuf *,
745 struct got_tag_object *);
746 const struct got_error *got_privsep_recv_tag(struct got_tag_object **,
747 struct imsgbuf *);
748 const struct got_error *got_privsep_init_pack_child(struct imsgbuf *,
749 struct got_pack *, struct got_packidx *);
750 const struct got_error *got_privsep_send_packed_obj_req(struct imsgbuf *, int,
751 struct got_object_id *);
752 const struct got_error *got_privsep_send_packed_raw_obj_req(struct imsgbuf *,
753 int, struct got_object_id *);
754 const struct got_error *got_privsep_send_pack_child_ready(struct imsgbuf *);
756 const struct got_error *got_privsep_send_gitconfig_parse_req(struct imsgbuf *,
757 int);
758 const struct got_error *
759 got_privsep_send_gitconfig_repository_format_version_req(struct imsgbuf *);
760 const struct got_error *got_privsep_send_gitconfig_repository_extensions_req(
761 struct imsgbuf *);
762 const struct got_error *got_privsep_send_gitconfig_author_name_req(
763 struct imsgbuf *);
764 const struct got_error *got_privsep_send_gitconfig_author_email_req(
765 struct imsgbuf *);
766 const struct got_error *got_privsep_send_gitconfig_remotes_req(
767 struct imsgbuf *);
768 const struct got_error *got_privsep_send_gitconfig_owner_req(struct imsgbuf *);
769 const struct got_error *got_privsep_recv_gitconfig_str(char **,
770 struct imsgbuf *);
771 const struct got_error *got_privsep_recv_gitconfig_pair(char **, char **,
772 struct imsgbuf *);
773 const struct got_error *got_privsep_recv_gitconfig_int(int *, struct imsgbuf *);
774 const struct got_error *got_privsep_recv_gitconfig_remotes(
775 struct got_remote_repo **, int *, struct imsgbuf *);
777 const struct got_error *got_privsep_send_gotconfig_parse_req(struct imsgbuf *,
778 int);
779 const struct got_error *got_privsep_send_gotconfig_author_req(struct imsgbuf *);
780 const struct got_error *got_privsep_send_gotconfig_allowed_signers_req(
781 struct imsgbuf *);
782 const struct got_error *got_privsep_send_gotconfig_revoked_signers_req(
783 struct imsgbuf *);
784 const struct got_error *got_privsep_send_gotconfig_signer_id_req(
785 struct imsgbuf *);
786 const struct got_error *got_privsep_send_gotconfig_remotes_req(
787 struct imsgbuf *);
788 const struct got_error *got_privsep_recv_gotconfig_str(char **,
789 struct imsgbuf *);
790 const struct got_error *got_privsep_recv_gotconfig_remotes(
791 struct got_remote_repo **, int *, struct imsgbuf *);
793 const struct got_error *got_privsep_send_commit_traversal_request(
794 struct imsgbuf *, struct got_object_id *, int, const char *);
795 const struct got_error *got_privsep_recv_traversed_commits(
796 struct got_commit_object **, struct got_object_id_queue *,
797 struct imsgbuf *);
798 const struct got_error *got_privsep_send_enumerated_tree(size_t *,
799 struct imsgbuf *, struct got_object_id *, const char *,
800 struct got_parsed_tree_entry *, int);
801 const struct got_error *got_privsep_send_object_enumeration_request(
802 struct imsgbuf *);
803 const struct got_error *got_privsep_send_object_enumeration_done(
804 struct imsgbuf *);
805 const struct got_error *got_privsep_send_object_enumeration_incomplete(
806 struct imsgbuf *);
807 const struct got_error *got_privsep_send_enumerated_commit(struct imsgbuf *,
808 struct got_object_id *, time_t);
809 const struct got_error *got_privsep_recv_enumerated_objects(int *,
810 struct imsgbuf *, got_object_enumerate_commit_cb,
811 got_object_enumerate_tree_cb, void *, struct got_repository *);
813 const struct got_error *got_privsep_send_raw_delta_req(struct imsgbuf *, int,
814 struct got_object_id *);
815 const struct got_error *got_privsep_send_raw_delta_outfd(struct imsgbuf *, int);
816 const struct got_error *got_privsep_send_raw_delta(struct imsgbuf *, uint64_t,
817 uint64_t, off_t, off_t, off_t, off_t, struct got_object_id *);
818 const struct got_error *got_privsep_recv_raw_delta(uint64_t *, uint64_t *,
819 off_t *, off_t *, off_t *, off_t *, struct got_object_id **,
820 struct imsgbuf *);
822 const struct got_error *got_privsep_send_object_idlist(struct imsgbuf *,
823 struct got_object_id **, size_t);
824 const struct got_error *got_privsep_send_object_idlist_done(struct imsgbuf *);
825 const struct got_error *got_privsep_recv_object_idlist(int *,
826 struct got_object_id **, size_t *, struct imsgbuf *);
828 const struct got_error *got_privsep_send_delta_reuse_req(struct imsgbuf *);
829 const struct got_error *got_privsep_send_reused_deltas(struct imsgbuf *,
830 struct got_imsg_reused_delta *, size_t);
831 const struct got_error *got_privsep_send_reused_deltas_done(struct imsgbuf *);
832 const struct got_error *got_privsep_recv_reused_deltas(int *,
833 struct got_imsg_reused_delta *, size_t *, struct imsgbuf *);
835 const struct got_error *got_privsep_init_commit_painting(struct imsgbuf *);
836 const struct got_error *got_privsep_send_painting_request(struct imsgbuf *,
837 int, struct got_object_id *, intptr_t);
838 typedef const struct got_error *(*got_privsep_recv_painted_commit_cb)(void *,
839 struct got_object_id *, intptr_t);
840 const struct got_error *got_privsep_send_painted_commits(struct imsgbuf *,
841 struct got_object_id_queue *, int *, int, int);
842 const struct got_error *got_privsep_send_painting_commits_done(struct imsgbuf *);
843 const struct got_error *got_privsep_recv_painted_commits(
844 struct got_object_id_queue *, got_privsep_recv_painted_commit_cb, void *,
845 struct imsgbuf *);
847 void got_privsep_exec_child(int[2], const char *, const char *);