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_flush(3) and imsg_read(3).
21 * This behaviour is transparent to users of the library.
22 *
23 * We generally transmit data in imsg buffers, split across several messages
24 * if necessary. File descriptor passing is used in cases where this is
25 * impractical, such as when accessing pack files or when transferring
26 * large blobs.
27 *
28 * We currently do not exec(2) after a fork(2).
29 * To achieve fork+exec, relevant parts of our library functionality could
30 * be made accessible via separate executables in a libexec directory.
31 */
33 enum got_imsg_type {
34 /* An error occured while processing a request. */
35 GOT_IMSG_ERROR,
37 /* Messages for transmitting deltas and associated delta streams. */
38 GOT_IMSG_DELTA,
39 GOT_IMSG_DELTA_STREAM,
41 /*
42 * Messages concerned with read access to objects in a repository.
43 * Object and pack files are opened by the main process, where
44 * data may be read as a byte string but without any interpretation.
45 * Decompression and parsing of object and pack files occurs in a
46 * separate process which runs under pledge("stdio").
47 * This sandboxes our own repository parsing code, as well as zlib.
48 */
49 GOT_IMSG_LOOSE_OBJECT_HEADER_REQUEST,
50 GOT_IMSG_LOOSE_OBJECT_HEADER_REPLY,
51 GOT_IMSG_LOOSE_BLOB_OBJECT_REQUEST,
52 GOT_IMSG_LOOSE_BLOB_OBJECT_REQUEST_OUTPUT,
53 GOT_IMSG_LOOSE_BLOB_OBJECT_REPLY,
54 GOT_IMSG_LOOSE_TREE_OBJECT_REQUEST,
55 GOT_IMSG_LOOSE_TREE_OBJECT_REPLY,
56 GOT_IMSG_TREE_ENTRY,
57 GOT_IMSG_LOOSE_COMMIT_OBJECT_REQUEST,
58 GOT_IMSG_LOOSE_COMMIT_OBJECT_REPLY,
59 GOT_IMSG_PACKED_BLOB_OBJECT_REQUEST,
60 GOT_IMSG_PACKED_BLOB_OBJECT_REQUEST_OUTPUT,
61 GOT_IMSG_PACKED_BLOB_OBJECT_REPLY,
62 GOT_IMSG_PACKED_TREE_OBJECT_REQUEST,
63 GOT_IMSG_PACKED_TREE_OBJECT_REPLY,
64 GOT_IMSG_PACKED_COMMIT_OBJECT_REQUEST,
65 GOT_IMSG_PACKED_COMMIT_OBJECT_REPLY
66 };
68 /* Structure for GOT_IMSG_ERROR. */
69 struct got_imsg_error {
70 int code; /* an error code from got_error.h */
71 };
73 /* Structure for GOT_IMSG_DELTA data. */
74 struct got_imsg_delta {
75 /* These fields are the same as in struct got_delta. */
76 off_t offset;
77 size_t tslen;
78 int type;
79 size_t size;
80 off_t data_offset;
81 size_t delta_len;
83 /*
84 * Followed by delta stream in remaining bytes of imsg buffer.
85 * If delta_len exceeds imsg buffer length, followed by one or
86 * more DELTA_STREAM messages until delta_len bytes of delta
87 * stream have been transmitted.
88 */
89 };
91 /* Structure for GOT_IMSG_DELTA_STREAM data. */
92 struct got_imsg_delta_stream {
93 /*
94 * Empty since the following is implied:
95 * Read additional delta stream data from imsg buffer.
96 */
97 };
99 /* Structure for GOT_IMSG_LOOSE_OBJECT_HEADER_REQUEST data. */
100 struct got_imsg_loose_object_header_request {
101 /*
102 * Empty since the following is implied: If imsg fd == -1 then
103 * read raw object data from imsg buffer, else read from fd.
104 */
105 };
107 /* Structure for transmitting struct got_object data in an imsg. */
108 struct got_imsg_object {
109 /* These fields are the same as in struct got_object. */
110 int type;
111 int flags;
112 size_t hdrlen;
113 size_t size;
114 struct got_object_id id;
116 int ndeltas; /* this many GOT_IMSG_DELTA messages follow */
117 } __attribute__((__packed__));
119 /* Structure for GOT_IMSG_LOOSE_OBJECT_HEADER_REPLY data. */
120 struct got_imsg_loose_object_header_reply {
121 struct got_imsg_object iobj;
122 };
124 /* Structure for GOT_IMSG_LOOSE_BLOB_OBJECT_REQUEST data. */
125 struct got_imsg_loose_blob_object_request {
126 struct got_imsg_object iobj;
128 /*
129 * The following is implied: If imsg fd == -1 then read raw
130 * blob data from imsg buffer, else read from fd.
131 */
132 };
134 /* Structure for GOT_IMSG_LOOSE_BLOB_OBJECT_REQUEST_OUTPUT data. */
135 struct got_imsg_loose_blob_object_request_output {
136 /*
137 * Empty since the following is implied: If imsg fd == -1 then
138 * respond with blob data in imsg buffer, else write to fd.
139 */
140 };
142 /* Structure for GOT_IMSG_LOOSE_TREE_OBJECT_REQUEST data. */
143 struct got_imsg_loose_tree_object_request {
144 struct got_imsg_object iobj;
146 /*
147 * The following is implied: If imsg fd == -1 then read raw tree
148 * data from imsg buffer, else read from fd.
149 */
150 };
152 /* Structure for GOT_IMSG_TREE_ENTRY. */
153 struct got_imsg_tree_entry {
154 struct got_object_id id;
155 mode_t mode;
156 /* Followed by entry's name in remaining data of imsg buffer. */
157 } __attribute__((__packed__));
159 /* Structure for transmitting struct got_tree_object data in an imsg. */
160 struct got_imsg_tree_object {
161 int nentries; /* This many TREE_ENTRY messages follow. */
162 };
164 /* TODO: Implement the above, and then add more message data types here. */