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, relevant parts of our library functionality could
27 * be made accessible via separate executables in a libexec directory.
28 */
30 enum got_imsg_type {
31 /* An error occured while processing a request. */
32 GOT_IMSG_ERROR,
34 /*
35 * Messages concerned with read access to objects in a repository.
36 * Object and pack files are opened by the main process, where
37 * data may be read as a byte string but without any interpretation.
38 * Decompression and parsing of object and pack files occurs in a
39 * separate process which runs under pledge("stdio").
40 * This sandboxes our own repository parsing code, as well as zlib.
41 */
42 GOT_IMSG_READ_LOOSE_OBJECT_HEADER_REQUEST,
43 GOT_IMSG_READ_LOOSE_OBJECT_HEADER_REPLY,
44 GOT_IMSG_DELTA,
45 GOT_IMSG_READ_LOOSE_BLOB_OBJECT_REQUEST,
46 GOT_IMSG_READ_LOOSE_BLOB_OBJECT_REPLY,
47 GOT_IMSG_READ_LOOSE_TREE_OBJECT_REQUEST,
48 GOT_IMSG_READ_LOOSE_TREE_OBJECT_REPLY,
49 GOT_IMSG_READ_LOOSE_COMMIT_OBJECT_REQUEST,
50 GOT_IMSG_READ_LOOSE_COMMIT_OBJECT_REPLY,
51 GOT_IMSG_READ_PACKED_BLOB_OBJECT_REQUEST,
52 GOT_IMSG_READ_PACKED_BLOB_OBJECT_REPLY,
53 GOT_IMSG_READ_PACKED_TREE_OBJECT_REQUEST,
54 GOT_IMSG_READ_PACKED_TREE_OBJECT_REPLY,
55 GOT_IMSG_READ_PACKED_COMMIT_OBJECT_REQUEST,
56 GOT_IMSG_READ_PACKED_COMMIT_OBJECT_REPLY
57 };
59 /* Structure for GOT_IMSG_ERROR. */
60 struct got_imsg_error {
61 int code; /* an error code from got_error.h */
62 };
64 /* Structure for GOT_IMSG_READ_LOOSE_OBJECT_HEADER_REQUEST data. */
65 struct got_imsg_read_loose_object_header_request {
66 /*
67 * Empty since the following is implied: If imsg fd == -1 then
68 * read raw object data from imsg buffer, else read from fd.
69 */
70 };
72 /* Structure for GOT_IMSG_READ_LOOSE_OBJECT_HEADER_REPLY data. */
73 struct got_imsg_read_loose_object_header_reply {
74 /* These fields are the same as in struct got_object. */
75 int type;
76 int flags;
77 size_t hdrlen;
78 size_t size;
79 struct got_object_id id;
81 int ndeltas; /* this many GOT_IMSG_DELTA messages follow */
82 };
84 /* Structure for GOT_IMSG_DELTA data. */
85 struct got_imsg_delta {
86 /* These fields are the same as in struct got_delta. */
87 off_t offset;
88 size_t tslen;
89 int type;
90 size_t size;
91 off_t data_offset;
92 size_t delta_len;
94 /*
95 * Followed by raw delta data: If imsg fd == -1 then read
96 * delta data from imsg buffer, else read from fd.
97 */
98 };
100 /* TODO: Implement the above, and then add more message data types here. */