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_OBJECT,
50 GOT_IMSG_LOOSE_BLOB_OBJECT_REQUEST,
51 GOT_IMSG_LOOSE_TREE_OBJECT_REQUEST,
52 GOT_IMSG_LOOSE_COMMIT_OBJECT_REQUEST,
53 GOT_IMSG_PACKED_BLOB_OBJECT_REQUEST,
54 GOT_IMSG_PACKED_TREE_OBJECT_REQUEST,
55 GOT_IMSG_PACKED_COMMIT_OBJECT_REQUEST,
56 GOT_IMSG_BLOB_OBJECT_REQUEST_OUTPUT,
57 GOT_IMSG_BLOB_OBJECT_REPLY,
58 GOT_IMSG_TREE_OBJECT_REPLY,
59 GOT_IMSG_TREE_ENTRY,
60 GOT_IMSG_COMMIT_OBJECT_REPLY
61 };
63 /* Structure for GOT_IMSG_ERROR. */
64 struct got_imsg_error {
65 int code; /* an error code from got_error.h */
66 int errno_code; /* in case code equals GOT_ERR_ERRNO */
67 };
69 /* Structure for GOT_IMSG_DELTA data. */
70 struct got_imsg_delta {
71 /* These fields are the same as in struct got_delta. */
72 off_t offset;
73 size_t tslen;
74 int type;
75 size_t size;
76 off_t data_offset;
77 size_t delta_len;
79 /*
80 * Followed by delta stream in remaining bytes of imsg buffer.
81 * If delta_len exceeds imsg buffer length, followed by one or
82 * more DELTA_STREAM messages until delta_len bytes of delta
83 * stream have been transmitted.
84 */
85 };
87 /* Structure for GOT_IMSG_DELTA_STREAM data. */
88 struct got_imsg_delta_stream {
89 /*
90 * Empty since the following is implied:
91 * Read additional delta stream data from imsg buffer.
92 */
93 };
95 /* Structure for GOT_IMSG_OBJECT data. */
96 struct got_imsg_object {
97 /* These fields are the same as in struct got_object. */
98 int type;
99 int flags;
100 size_t hdrlen;
101 size_t size;
103 int ndeltas; /* this many GOT_IMSG_DELTA messages follow */
104 };
106 /* Structure for GOT_IMSG_LOOSE_OBJECT_HEADER_REPLY data. */
107 struct got_imsg_loose_object_header_reply {
108 struct got_imsg_object iobj;
109 };
111 /* Structure for GOT_IMSG_LOOSE_BLOB_OBJECT_REQUEST data. */
112 struct got_imsg_loose_blob_object_request {
113 struct got_imsg_object iobj;
115 /*
116 * The following is implied: If imsg fd == -1 then read raw
117 * blob data from imsg buffer, else read from fd.
119 * This message is followed by an OBJECT_REQUEST_OUTPUT message.
120 */
121 };
123 /* Structure for GOT_IMSG_BLOB_OBJECT_REQUEST_OUTPUT data. */
124 struct got_imsg_blob_object_request_output {
125 /*
126 * Empty since the following is implied: If imsg fd == -1 then
127 * respond with blob data in imsg buffer, else write to fd.
128 */
129 };
131 /* Structure for GOT_IMSG_LOOSE_TREE_OBJECT_REQUEST data. */
132 struct got_imsg_loose_tree_object_request {
133 struct got_imsg_object iobj;
135 /*
136 * The following is implied: If imsg fd == -1 then read raw tree
137 * data from imsg buffer, else read from fd.
138 */
139 };
141 /* Structure for GOT_IMSG_TREE_ENTRY. */
142 struct got_imsg_tree_entry {
143 struct got_object_id id;
144 mode_t mode;
145 /* Followed by entry's name in remaining data of imsg buffer. */
146 } __attribute__((__packed__));
148 /* Structure for GOT_IMSG_TREE_OBJECT_REPLY data. */
149 struct got_imsg_tree_object {
150 int nentries; /* This many TREE_ENTRY messages follow. */
151 };
153 void got_privsep_send_error(struct imsgbuf *, const struct got_error *);
154 const struct got_error *got_privsep_send_obj(struct imsgbuf *,
155 struct got_object *, int);
156 const struct got_error *got_privsep_recv_obj(struct got_object **,
157 struct imsgbuf *);
159 /* TODO: Implement the above, and then add more message data types here. */