2 7be7cc45 2018-04-02 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
4 7be7cc45 2018-04-02 stsp * Permission to use, copy, modify, and distribute this software for any
5 7be7cc45 2018-04-02 stsp * purpose with or without fee is hereby granted, provided that the above
6 7be7cc45 2018-04-02 stsp * copyright notice and this permission notice appear in all copies.
8 7be7cc45 2018-04-02 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 7be7cc45 2018-04-02 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 7be7cc45 2018-04-02 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 7be7cc45 2018-04-02 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 7be7cc45 2018-04-02 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 7be7cc45 2018-04-02 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 7be7cc45 2018-04-02 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 7be7cc45 2018-04-02 stsp * All code runs under the same UID but sensitive code paths are
19 7be7cc45 2018-04-02 stsp * run in a separate process with tighter pledge(2) promises.
20 7be7cc45 2018-04-02 stsp * Data is communicated between processes via imsg_read(3)/imsg_compose(3).
21 7be7cc45 2018-04-02 stsp * This behaviour is transparent to users of the library.
23 1e4880cb 2018-04-02 stsp * We generally transmit data in imsg buffers, split across several messages
24 1e4880cb 2018-04-02 stsp * if necessary. File descriptor passing is used in cases where this is
25 1e4880cb 2018-04-02 stsp * impractical, such as when accessing pack files or when transferring
26 1e4880cb 2018-04-02 stsp * large blobs.
28 7be7cc45 2018-04-02 stsp * We currently do not exec(2) after a fork(2).
29 0dacc2d1 2018-04-02 stsp * To achieve fork+exec, relevant parts of our library functionality could
30 7be7cc45 2018-04-02 stsp * be made accessible via separate executables in a libexec directory.
33 7be7cc45 2018-04-02 stsp enum got_imsg_type {
34 c025a41e 2018-04-02 stsp /* An error occured while processing a request. */
35 c025a41e 2018-04-02 stsp GOT_IMSG_ERROR,
37 1e4880cb 2018-04-02 stsp /* Messages for transmitting deltas and associated delta streams. */
38 1e4880cb 2018-04-02 stsp GOT_IMSG_DELTA,
39 1e4880cb 2018-04-02 stsp GOT_IMSG_DELTA_STREAM,
42 7be7cc45 2018-04-02 stsp * Messages concerned with read access to objects in a repository.
43 7be7cc45 2018-04-02 stsp * Object and pack files are opened by the main process, where
44 7be7cc45 2018-04-02 stsp * data may be read as a byte string but without any interpretation.
45 7be7cc45 2018-04-02 stsp * Decompression and parsing of object and pack files occurs in a
46 7be7cc45 2018-04-02 stsp * separate process which runs under pledge("stdio").
47 7be7cc45 2018-04-02 stsp * This sandboxes our own repository parsing code, as well as zlib.
49 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_LOOSE_OBJECT_HEADER_REQUEST,
50 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_LOOSE_OBJECT_HEADER_REPLY,
51 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_LOOSE_BLOB_OBJECT_REQUEST,
52 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_LOOSE_BLOB_OBJECT_REPLY,
53 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_LOOSE_TREE_OBJECT_REQUEST,
54 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_LOOSE_TREE_OBJECT_REPLY,
55 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_LOOSE_COMMIT_OBJECT_REQUEST,
56 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_LOOSE_COMMIT_OBJECT_REPLY,
57 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_PACKED_BLOB_OBJECT_REQUEST,
58 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_PACKED_BLOB_OBJECT_REPLY,
59 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_PACKED_TREE_OBJECT_REQUEST,
60 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_PACKED_TREE_OBJECT_REPLY,
61 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_PACKED_COMMIT_OBJECT_REQUEST,
62 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_PACKED_COMMIT_OBJECT_REPLY
65 c025a41e 2018-04-02 stsp /* Structure for GOT_IMSG_ERROR. */
66 c025a41e 2018-04-02 stsp struct got_imsg_error {
67 c025a41e 2018-04-02 stsp int code; /* an error code from got_error.h */
70 1e4880cb 2018-04-02 stsp /* Structure for GOT_IMSG_DELTA data. */
71 1e4880cb 2018-04-02 stsp struct got_imsg_delta {
72 1e4880cb 2018-04-02 stsp /* These fields are the same as in struct got_delta. */
73 1e4880cb 2018-04-02 stsp off_t offset;
74 1e4880cb 2018-04-02 stsp size_t tslen;
76 1e4880cb 2018-04-02 stsp size_t size;
77 1e4880cb 2018-04-02 stsp off_t data_offset;
78 1e4880cb 2018-04-02 stsp size_t delta_len;
81 1e4880cb 2018-04-02 stsp * Followed by DELTA_STREAM messages until delta_len bytes
82 1e4880cb 2018-04-02 stsp * of delta stream data have been transmitted.
86 1e4880cb 2018-04-02 stsp /* Structure for GOT_IMSG_DELTA_STREAM data. */
87 1e4880cb 2018-04-02 stsp struct got_imsg_delta_stream {
89 1e4880cb 2018-04-02 stsp * Empty since the following is implied:
90 1e4880cb 2018-04-02 stsp * Read delta stream data from imsg buffer.
94 7be7cc45 2018-04-02 stsp /* Structure for GOT_IMSG_READ_LOOSE_OBJECT_HEADER_REQUEST data. */
95 7be7cc45 2018-04-02 stsp struct got_imsg_read_loose_object_header_request {
97 7be7cc45 2018-04-02 stsp * Empty since the following is implied: If imsg fd == -1 then
98 7be7cc45 2018-04-02 stsp * read raw object data from imsg buffer, else read from fd.
102 7be7cc45 2018-04-02 stsp /* Structure for GOT_IMSG_READ_LOOSE_OBJECT_HEADER_REPLY data. */
103 7be7cc45 2018-04-02 stsp struct got_imsg_read_loose_object_header_reply {
104 7be7cc45 2018-04-02 stsp /* These fields are the same as in struct got_object. */
107 7be7cc45 2018-04-02 stsp size_t hdrlen;
108 7be7cc45 2018-04-02 stsp size_t size;
109 7be7cc45 2018-04-02 stsp struct got_object_id id;
111 7be7cc45 2018-04-02 stsp int ndeltas; /* this many GOT_IMSG_DELTA messages follow */
114 7be7cc45 2018-04-02 stsp /* TODO: Implement the above, and then add more message data types here. */