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 2ca3a24b 2018-04-02 stsp * Data is communicated between processes via imsg_flush(3) and imsg_read(3).
21 7be7cc45 2018-04-02 stsp * This behaviour is transparent to users of the library.
22 7be7cc45 2018-04-02 stsp *
23 1e4880cb 2018-04-02 stsp * We generally transmit data in imsg buffers, split across several messages
24 1e4880cb 2018-04-02 stsp * if necessary. File descriptor passing is used in cases where this is
25 1e4880cb 2018-04-02 stsp * impractical, such as when accessing pack files or when transferring
26 1e4880cb 2018-04-02 stsp * large blobs.
27 7be7cc45 2018-04-02 stsp *
28 7be7cc45 2018-04-02 stsp * We currently do not exec(2) after a fork(2).
29 0dacc2d1 2018-04-02 stsp * To achieve fork+exec, relevant parts of our library functionality could
30 7be7cc45 2018-04-02 stsp * be made accessible via separate executables in a libexec directory.
31 7be7cc45 2018-04-02 stsp */
32 7be7cc45 2018-04-02 stsp
33 7be7cc45 2018-04-02 stsp enum got_imsg_type {
34 c025a41e 2018-04-02 stsp /* An error occured while processing a request. */
35 c025a41e 2018-04-02 stsp GOT_IMSG_ERROR,
36 c025a41e 2018-04-02 stsp
37 1e4880cb 2018-04-02 stsp /* Messages for transmitting deltas and associated delta streams. */
38 1e4880cb 2018-04-02 stsp GOT_IMSG_DELTA,
39 1e4880cb 2018-04-02 stsp GOT_IMSG_DELTA_STREAM,
40 1e4880cb 2018-04-02 stsp
41 7be7cc45 2018-04-02 stsp /*
42 7be7cc45 2018-04-02 stsp * Messages concerned with read access to objects in a repository.
43 7be7cc45 2018-04-02 stsp * Object and pack files are opened by the main process, where
44 7be7cc45 2018-04-02 stsp * data may be read as a byte string but without any interpretation.
45 7be7cc45 2018-04-02 stsp * Decompression and parsing of object and pack files occurs in a
46 7be7cc45 2018-04-02 stsp * separate process which runs under pledge("stdio").
47 7be7cc45 2018-04-02 stsp * This sandboxes our own repository parsing code, as well as zlib.
48 7be7cc45 2018-04-02 stsp */
49 2178c42e 2018-04-22 stsp GOT_IMSG_OBJECT,
50 bff6ca00 2018-04-23 stsp GOT_IMSG_COMMIT,
51 bff6ca00 2018-04-23 stsp GOT_IMSG_OBJ_ID,
52 f7171542 2018-04-02 stsp GOT_IMSG_LOOSE_BLOB_OBJECT_REQUEST,
53 f7171542 2018-04-02 stsp GOT_IMSG_LOOSE_TREE_OBJECT_REQUEST,
54 f7171542 2018-04-02 stsp GOT_IMSG_PACKED_BLOB_OBJECT_REQUEST,
55 f7171542 2018-04-02 stsp GOT_IMSG_PACKED_TREE_OBJECT_REQUEST,
56 f7171542 2018-04-02 stsp GOT_IMSG_PACKED_COMMIT_OBJECT_REQUEST,
57 d80ab12b 2018-04-02 stsp GOT_IMSG_BLOB_OBJECT_REQUEST_OUTPUT,
58 d80ab12b 2018-04-02 stsp GOT_IMSG_BLOB_OBJECT_REPLY,
59 d80ab12b 2018-04-02 stsp GOT_IMSG_TREE_OBJECT_REPLY,
60 d80ab12b 2018-04-02 stsp GOT_IMSG_TREE_ENTRY,
61 d80ab12b 2018-04-02 stsp GOT_IMSG_COMMIT_OBJECT_REPLY
62 7be7cc45 2018-04-02 stsp };
63 7be7cc45 2018-04-02 stsp
64 c025a41e 2018-04-02 stsp /* Structure for GOT_IMSG_ERROR. */
65 c025a41e 2018-04-02 stsp struct got_imsg_error {
66 c025a41e 2018-04-02 stsp int code; /* an error code from got_error.h */
67 2178c42e 2018-04-22 stsp int errno_code; /* in case code equals GOT_ERR_ERRNO */
68 c025a41e 2018-04-02 stsp };
69 c025a41e 2018-04-02 stsp
70 1e4880cb 2018-04-02 stsp /* Structure for GOT_IMSG_DELTA data. */
71 1e4880cb 2018-04-02 stsp struct got_imsg_delta {
72 1e4880cb 2018-04-02 stsp /* These fields are the same as in struct got_delta. */
73 1e4880cb 2018-04-02 stsp off_t offset;
74 1e4880cb 2018-04-02 stsp size_t tslen;
75 1e4880cb 2018-04-02 stsp int type;
76 1e4880cb 2018-04-02 stsp size_t size;
77 1e4880cb 2018-04-02 stsp off_t data_offset;
78 1e4880cb 2018-04-02 stsp size_t delta_len;
79 1e4880cb 2018-04-02 stsp
80 1e4880cb 2018-04-02 stsp /*
81 48f392b2 2018-04-02 stsp * Followed by delta stream in remaining bytes of imsg buffer.
82 48f392b2 2018-04-02 stsp * If delta_len exceeds imsg buffer length, followed by one or
83 48f392b2 2018-04-02 stsp * more DELTA_STREAM messages until delta_len bytes of delta
84 48f392b2 2018-04-02 stsp * stream have been transmitted.
85 1e4880cb 2018-04-02 stsp */
86 1e4880cb 2018-04-02 stsp };
87 1e4880cb 2018-04-02 stsp
88 1e4880cb 2018-04-02 stsp /* Structure for GOT_IMSG_DELTA_STREAM data. */
89 1e4880cb 2018-04-02 stsp struct got_imsg_delta_stream {
90 1e4880cb 2018-04-02 stsp /*
91 1e4880cb 2018-04-02 stsp * Empty since the following is implied:
92 48f392b2 2018-04-02 stsp * Read additional delta stream data from imsg buffer.
93 1e4880cb 2018-04-02 stsp */
94 1e4880cb 2018-04-02 stsp };
95 1e4880cb 2018-04-02 stsp
96 2178c42e 2018-04-22 stsp /* Structure for GOT_IMSG_OBJECT data. */
97 f7171542 2018-04-02 stsp struct got_imsg_object {
98 7be7cc45 2018-04-02 stsp /* These fields are the same as in struct got_object. */
99 7be7cc45 2018-04-02 stsp int type;
100 7be7cc45 2018-04-02 stsp int flags;
101 7be7cc45 2018-04-02 stsp size_t hdrlen;
102 7be7cc45 2018-04-02 stsp size_t size;
103 7be7cc45 2018-04-02 stsp
104 7be7cc45 2018-04-02 stsp int ndeltas; /* this many GOT_IMSG_DELTA messages follow */
105 94fbf93a 2018-04-22 stsp };
106 7be7cc45 2018-04-02 stsp
107 bff6ca00 2018-04-23 stsp struct got_imsg_commit_object {
108 bff6ca00 2018-04-23 stsp uint8_t tree_id[SHA1_DIGEST_STRING_LENGTH];
109 bff6ca00 2018-04-23 stsp size_t author_len;
110 bff6ca00 2018-04-23 stsp size_t committer_len;
111 bff6ca00 2018-04-23 stsp size_t logmsg_len;
112 bff6ca00 2018-04-23 stsp int nparents;
113 bff6ca00 2018-04-23 stsp
114 bff6ca00 2018-04-23 stsp /* Followed by author_len + committer_len + logmsg_len data bytes */
115 bff6ca00 2018-04-23 stsp
116 bff6ca00 2018-04-23 stsp /* Followed by 'nparents' SHA1_DIGEST_STRING_LENGTH length strings */
117 bff6ca00 2018-04-23 stsp
118 bff6ca00 2018-04-23 stsp /* XXX should use more messages to support very large log messages */
119 bff6ca00 2018-04-23 stsp } __attribute__((__packed__));
120 bff6ca00 2018-04-23 stsp
121 f7171542 2018-04-02 stsp /* Structure for GOT_IMSG_LOOSE_OBJECT_HEADER_REPLY data. */
122 f7171542 2018-04-02 stsp struct got_imsg_loose_object_header_reply {
123 f7171542 2018-04-02 stsp struct got_imsg_object iobj;
124 f7171542 2018-04-02 stsp };
125 f7171542 2018-04-02 stsp
126 48f392b2 2018-04-02 stsp /* Structure for GOT_IMSG_LOOSE_BLOB_OBJECT_REQUEST data. */
127 48f392b2 2018-04-02 stsp struct got_imsg_loose_blob_object_request {
128 48f392b2 2018-04-02 stsp struct got_imsg_object iobj;
129 48f392b2 2018-04-02 stsp
130 48f392b2 2018-04-02 stsp /*
131 48f392b2 2018-04-02 stsp * The following is implied: If imsg fd == -1 then read raw
132 48f392b2 2018-04-02 stsp * blob data from imsg buffer, else read from fd.
133 d80ab12b 2018-04-02 stsp *
134 d80ab12b 2018-04-02 stsp * This message is followed by an OBJECT_REQUEST_OUTPUT message.
135 48f392b2 2018-04-02 stsp */
136 48f392b2 2018-04-02 stsp };
137 48f392b2 2018-04-02 stsp
138 d80ab12b 2018-04-02 stsp /* Structure for GOT_IMSG_BLOB_OBJECT_REQUEST_OUTPUT data. */
139 d80ab12b 2018-04-02 stsp struct got_imsg_blob_object_request_output {
140 48f392b2 2018-04-02 stsp /*
141 48f392b2 2018-04-02 stsp * Empty since the following is implied: If imsg fd == -1 then
142 48f392b2 2018-04-02 stsp * respond with blob data in imsg buffer, else write to fd.
143 48f392b2 2018-04-02 stsp */
144 48f392b2 2018-04-02 stsp };
145 48f392b2 2018-04-02 stsp
146 48f392b2 2018-04-02 stsp /* Structure for GOT_IMSG_LOOSE_TREE_OBJECT_REQUEST data. */
147 48f392b2 2018-04-02 stsp struct got_imsg_loose_tree_object_request {
148 48f392b2 2018-04-02 stsp struct got_imsg_object iobj;
149 48f392b2 2018-04-02 stsp
150 48f392b2 2018-04-02 stsp /*
151 48f392b2 2018-04-02 stsp * The following is implied: If imsg fd == -1 then read raw tree
152 48f392b2 2018-04-02 stsp * data from imsg buffer, else read from fd.
153 48f392b2 2018-04-02 stsp */
154 48f392b2 2018-04-02 stsp };
155 48f392b2 2018-04-02 stsp
156 48f392b2 2018-04-02 stsp /* Structure for GOT_IMSG_TREE_ENTRY. */
157 48f392b2 2018-04-02 stsp struct got_imsg_tree_entry {
158 48f392b2 2018-04-02 stsp struct got_object_id id;
159 48f392b2 2018-04-02 stsp mode_t mode;
160 48f392b2 2018-04-02 stsp /* Followed by entry's name in remaining data of imsg buffer. */
161 8d98bcfb 2018-04-02 stsp } __attribute__((__packed__));
162 48f392b2 2018-04-02 stsp
163 d80ab12b 2018-04-02 stsp /* Structure for GOT_IMSG_TREE_OBJECT_REPLY data. */
164 48f392b2 2018-04-02 stsp struct got_imsg_tree_object {
165 48f392b2 2018-04-02 stsp int nentries; /* This many TREE_ENTRY messages follow. */
166 48f392b2 2018-04-02 stsp };
167 48f392b2 2018-04-02 stsp
168 2178c42e 2018-04-22 stsp void got_privsep_send_error(struct imsgbuf *, const struct got_error *);
169 2178c42e 2018-04-22 stsp const struct got_error *got_privsep_send_obj(struct imsgbuf *,
170 2178c42e 2018-04-22 stsp struct got_object *, int);
171 2178c42e 2018-04-22 stsp const struct got_error *got_privsep_recv_obj(struct got_object **,
172 2178c42e 2018-04-22 stsp struct imsgbuf *);
173 bff6ca00 2018-04-23 stsp const struct got_error *got_privsep_send_commit_obj(struct imsgbuf *,
174 bff6ca00 2018-04-23 stsp struct got_commit_object *);
175 bff6ca00 2018-04-23 stsp const struct got_error *got_privsep_recv_commit_obj(struct got_commit_object **,
176 bff6ca00 2018-04-23 stsp struct imsgbuf *);
177 2178c42e 2018-04-22 stsp
178 7be7cc45 2018-04-02 stsp /* TODO: Implement the above, and then add more message data types here. */