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_COMMIT,
51 GOT_IMSG_TREE,
52 GOT_IMSG_TREE_ENTRY,
53 GOT_IMSG_BLOB,
54 };
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 */
60 };
62 /* Structure for GOT_IMSG_DELTA data. */
63 struct got_imsg_delta {
64 /* These fields are the same as in struct got_delta. */
65 off_t offset;
66 size_t tslen;
67 int type;
68 size_t size;
69 off_t data_offset;
70 size_t delta_len;
72 /*
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.
77 */
78 };
80 /* Structure for GOT_IMSG_DELTA_STREAM data. */
81 struct got_imsg_delta_stream {
82 /*
83 * Empty since the following is implied:
84 * Read additional delta stream data from imsg buffer.
85 */
86 };
88 /* Structure for GOT_IMSG_OBJECT data. */
89 struct got_imsg_object {
90 /* These fields are the same as in struct got_object. */
91 int type;
92 int flags;
93 size_t hdrlen;
94 size_t size;
96 int ndeltas; /* this many GOT_IMSG_DELTA messages follow */
97 };
99 /* Structure for GOT_IMSG_COMMIT data. */
100 struct got_imsg_commit_object {
101 uint8_t tree_id[SHA1_DIGEST_LENGTH];
102 size_t author_len;
103 size_t committer_len;
104 size_t logmsg_len;
105 int nparents;
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];
118 mode_t mode;
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. */
125 };
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 **,
131 struct imsgbuf *);
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 **,
135 struct imsgbuf *);
136 const struct got_error *got_privsep_recv_tree_obj(struct got_tree_object **,
137 struct imsgbuf *);
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. */