Blame


1 7be7cc45 2018-04-02 stsp /*
2 7be7cc45 2018-04-02 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 7be7cc45 2018-04-02 stsp *
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.
7 7be7cc45 2018-04-02 stsp *
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.
15 7be7cc45 2018-04-02 stsp */
16 7be7cc45 2018-04-02 stsp
17 7be7cc45 2018-04-02 stsp /*
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.
22 7be7cc45 2018-04-02 stsp *
23 7be7cc45 2018-04-02 stsp * File descriptor passing is used in cases where sizes exceed MAX_IMSGSIZE.
24 7be7cc45 2018-04-02 stsp *
25 7be7cc45 2018-04-02 stsp * We currently do not exec(2) after a fork(2).
26 0dacc2d1 2018-04-02 stsp * To achieve fork+exec, relevant parts of our library functionality could
27 7be7cc45 2018-04-02 stsp * be made accessible via separate executables in a libexec directory.
28 7be7cc45 2018-04-02 stsp */
29 7be7cc45 2018-04-02 stsp
30 7be7cc45 2018-04-02 stsp enum got_imsg_type {
31 7be7cc45 2018-04-02 stsp /*
32 7be7cc45 2018-04-02 stsp * Messages concerned with read access to objects in a repository.
33 7be7cc45 2018-04-02 stsp * Object and pack files are opened by the main process, where
34 7be7cc45 2018-04-02 stsp * data may be read as a byte string but without any interpretation.
35 7be7cc45 2018-04-02 stsp * Decompression and parsing of object and pack files occurs in a
36 7be7cc45 2018-04-02 stsp * separate process which runs under pledge("stdio").
37 7be7cc45 2018-04-02 stsp * This sandboxes our own repository parsing code, as well as zlib.
38 7be7cc45 2018-04-02 stsp */
39 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_LOOSE_OBJECT_HEADER_REQUEST,
40 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_LOOSE_OBJECT_HEADER_REPLY,
41 7be7cc45 2018-04-02 stsp GOT_IMSG_DELTA,
42 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_LOOSE_BLOB_OBJECT_REQUEST,
43 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_LOOSE_BLOB_OBJECT_REPLY,
44 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_LOOSE_TREE_OBJECT_REQUEST,
45 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_LOOSE_TREE_OBJECT_REPLY,
46 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_LOOSE_COMMIT_OBJECT_REQUEST,
47 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_LOOSE_COMMIT_OBJECT_REPLY,
48 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_PACKED_BLOB_OBJECT_REQUEST,
49 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_PACKED_BLOB_OBJECT_REPLY,
50 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_PACKED_TREE_OBJECT_REQUEST,
51 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_PACKED_TREE_OBJECT_REPLY,
52 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_PACKED_COMMIT_OBJECT_REQUEST,
53 7be7cc45 2018-04-02 stsp GOT_IMSG_READ_PACKED_COMMIT_OBJECT_REPLY
54 7be7cc45 2018-04-02 stsp };
55 7be7cc45 2018-04-02 stsp
56 7be7cc45 2018-04-02 stsp /* Structure for GOT_IMSG_READ_LOOSE_OBJECT_HEADER_REQUEST data. */
57 7be7cc45 2018-04-02 stsp struct got_imsg_read_loose_object_header_request {
58 7be7cc45 2018-04-02 stsp /*
59 7be7cc45 2018-04-02 stsp * Empty since the following is implied: If imsg fd == -1 then
60 7be7cc45 2018-04-02 stsp * read raw object data from imsg buffer, else read from fd.
61 7be7cc45 2018-04-02 stsp */
62 7be7cc45 2018-04-02 stsp };
63 7be7cc45 2018-04-02 stsp
64 7be7cc45 2018-04-02 stsp /* Structure for GOT_IMSG_READ_LOOSE_OBJECT_HEADER_REPLY data. */
65 7be7cc45 2018-04-02 stsp struct got_imsg_read_loose_object_header_reply {
66 7be7cc45 2018-04-02 stsp /* These fields are the same as in struct got_object. */
67 7be7cc45 2018-04-02 stsp int type;
68 7be7cc45 2018-04-02 stsp int flags;
69 7be7cc45 2018-04-02 stsp size_t hdrlen;
70 7be7cc45 2018-04-02 stsp size_t size;
71 7be7cc45 2018-04-02 stsp struct got_object_id id;
72 7be7cc45 2018-04-02 stsp
73 7be7cc45 2018-04-02 stsp int ndeltas; /* this many GOT_IMSG_DELTA messages follow */
74 7be7cc45 2018-04-02 stsp };
75 7be7cc45 2018-04-02 stsp
76 7be7cc45 2018-04-02 stsp /* Structure for GOT_IMSG_DELTA data. */
77 7be7cc45 2018-04-02 stsp struct got_imsg_delta {
78 7be7cc45 2018-04-02 stsp /* These fields are the same as in struct got_delta. */
79 7be7cc45 2018-04-02 stsp off_t offset;
80 7be7cc45 2018-04-02 stsp size_t tslen;
81 7be7cc45 2018-04-02 stsp int type;
82 7be7cc45 2018-04-02 stsp size_t size;
83 7be7cc45 2018-04-02 stsp off_t data_offset;
84 7be7cc45 2018-04-02 stsp size_t delta_len;
85 7be7cc45 2018-04-02 stsp
86 7be7cc45 2018-04-02 stsp /*
87 7be7cc45 2018-04-02 stsp * Followed by raw delta data: If imsg fd == -1 then read
88 7be7cc45 2018-04-02 stsp * delta data from imsg buffer, else read from fd.
89 7be7cc45 2018-04-02 stsp */
90 7be7cc45 2018-04-02 stsp };
91 7be7cc45 2018-04-02 stsp
92 7be7cc45 2018-04-02 stsp /* TODO: Implement the above, and then add more message data types here. */