2 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
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.
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.
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.
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
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.
34 /* An error occured while processing a request. */
37 /* Messages for transmitting deltas and associated delta streams. */
39 GOT_IMSG_DELTA_STREAM,
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.
56 /* Structure for GOT_IMSG_ERROR. */
57 struct got_imsg_error {
58 int code; /* an error code from got_error.h */
59 int errno_code; /* in case code equals GOT_ERR_ERRNO */
62 /* Structure for GOT_IMSG_DELTA data. */
63 struct got_imsg_delta {
64 /* These fields are the same as in struct got_delta. */
73 * Followed by delta stream in remaining bytes of imsg buffer.
74 * If delta_len exceeds imsg buffer length, followed by one or
75 * more DELTA_STREAM messages until delta_len bytes of delta
76 * stream have been transmitted.
80 /* Structure for GOT_IMSG_DELTA_STREAM data. */
81 struct got_imsg_delta_stream {
83 * Empty since the following is implied:
84 * Read additional delta stream data from imsg buffer.
88 /* Structure for GOT_IMSG_OBJECT data. */
89 struct got_imsg_object {
90 /* These fields are the same as in struct got_object. */
96 int ndeltas; /* this many GOT_IMSG_DELTA messages follow */
99 /* Structure for GOT_IMSG_COMMIT data. */
100 struct got_imsg_commit_object {
101 uint8_t tree_id[SHA1_DIGEST_LENGTH];
103 size_t committer_len;
107 /* Followed by author_len + committer_len + logmsg_len data bytes */
109 /* Followed by 'nparents' SHA1_DIGEST_LENGTH length strings */
111 /* XXX should use more messages to support very large log messages */
112 } __attribute__((__packed__));
115 /* Structure for GOT_IMSG_TREE_ENTRY. */
116 struct got_imsg_tree_entry {
117 char id[SHA1_DIGEST_LENGTH];
119 /* Followed by entry's name in remaining data of imsg buffer. */
120 } __attribute__((__packed__));
122 /* Structure for GOT_IMSG_TREE_OBJECT_REPLY data. */
123 struct got_imsg_tree_object {
124 int nentries; /* This many TREE_ENTRY messages follow. */
127 void got_privsep_send_error(struct imsgbuf *, const struct got_error *);
128 const struct got_error *got_privsep_send_obj(struct imsgbuf *,
129 struct got_object *, int);
130 const struct got_error *got_privsep_recv_obj(struct got_object **,
132 const struct got_error *got_privsep_send_commit_obj(struct imsgbuf *,
133 struct got_commit_object *);
134 const struct got_error *got_privsep_recv_commit_obj(struct got_commit_object **,
136 const struct got_error *got_privsep_recv_tree_obj(struct got_tree_object **,
138 const struct got_error *got_privsep_send_tree_obj(struct imsgbuf *,
139 struct got_tree_object *);
141 /* TODO: Implement the above, and then add more message data types here. */