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