Blob


1 /*
2 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
17 /*
18 * All code runs under the same UID but sensitive code paths are
19 * run in a separate process with tighter pledge(2) promises.
20 * Data is communicated between processes via imsg_read(3)/imsg_compose(3).
21 * This behaviour is transparent to users of the library.
22 *
23 * File descriptor passing is used in cases where sizes exceed MAX_IMSGSIZE.
24 *
25 * We currently do not exec(2) after a fork(2).
26 * To achieve fork+exec, releveant parts of our library functionality could
27 * be made accessible via separate executables in a libexec directory.
28 */
30 enum got_imsg_type {
31 /*
32 * Messages concerned with read access to objects in a repository.
33 * Object and pack files are opened by the main process, where
34 * data may be read as a byte string but without any interpretation.
35 * Decompression and parsing of object and pack files occurs in a
36 * separate process which runs under pledge("stdio").
37 * This sandboxes our own repository parsing code, as well as zlib.
38 */
39 GOT_IMSG_READ_LOOSE_OBJECT_HEADER_REQUEST,
40 GOT_IMSG_READ_LOOSE_OBJECT_HEADER_REPLY,
41 GOT_IMSG_DELTA,
42 GOT_IMSG_READ_LOOSE_BLOB_OBJECT_REQUEST,
43 GOT_IMSG_READ_LOOSE_BLOB_OBJECT_REPLY,
44 GOT_IMSG_READ_LOOSE_TREE_OBJECT_REQUEST,
45 GOT_IMSG_READ_LOOSE_TREE_OBJECT_REPLY,
46 GOT_IMSG_READ_LOOSE_COMMIT_OBJECT_REQUEST,
47 GOT_IMSG_READ_LOOSE_COMMIT_OBJECT_REPLY,
48 GOT_IMSG_READ_PACKED_BLOB_OBJECT_REQUEST,
49 GOT_IMSG_READ_PACKED_BLOB_OBJECT_REPLY,
50 GOT_IMSG_READ_PACKED_TREE_OBJECT_REQUEST,
51 GOT_IMSG_READ_PACKED_TREE_OBJECT_REPLY,
52 GOT_IMSG_READ_PACKED_COMMIT_OBJECT_REQUEST,
53 GOT_IMSG_READ_PACKED_COMMIT_OBJECT_REPLY
54 };
56 /* Structure for GOT_IMSG_READ_LOOSE_OBJECT_HEADER_REQUEST data. */
57 struct got_imsg_read_loose_object_header_request {
58 /*
59 * Empty since the following is implied: If imsg fd == -1 then
60 * read raw object data from imsg buffer, else read from fd.
61 */
62 };
64 /* Structure for GOT_IMSG_READ_LOOSE_OBJECT_HEADER_REPLY data. */
65 struct got_imsg_read_loose_object_header_reply {
66 /* These fields are the same as in struct got_object. */
67 int type;
68 int flags;
69 size_t hdrlen;
70 size_t size;
71 struct got_object_id id;
73 int ndeltas; /* this many GOT_IMSG_DELTA messages follow */
74 };
76 /* Structure for GOT_IMSG_DELTA data. */
77 struct got_imsg_delta {
78 /* These fields are the same as in struct got_delta. */
79 off_t offset;
80 size_t tslen;
81 int type;
82 size_t size;
83 off_t data_offset;
84 size_t delta_len;
86 /*
87 * Followed by raw delta data: If imsg fd == -1 then read
88 * delta data from imsg buffer, else read from fd.
89 */
90 };
92 /* TODO: Implement the above, and then add more message data types here. */