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 descriptors are used in cases where this is impractical,
25 * such as when accessing pack files or when transferring large blobs.
26 *
27 * We currently do not exec(2) after a fork(2).
28 * To achieve fork+exec, relevant parts of our library functionality could
29 * be made accessible via separate executables in a libexec directory.
30 */
32 enum got_imsg_type {
33 /* An error occured while processing a request. */
34 GOT_IMSG_ERROR,
36 /* Messages for transmitting deltas and associated delta streams. */
37 GOT_IMSG_DELTA,
38 GOT_IMSG_DELTA_STREAM,
40 /*
41 * Messages concerned with read access to objects in a repository.
42 * Object and pack files are opened by the main process, where
43 * data may be read as a byte string but without any interpretation.
44 * Decompression and parsing of object and pack files occurs in a
45 * separate process which runs under pledge("stdio").
46 * This sandboxes our own repository parsing code, as well as zlib.
47 */
48 GOT_IMSG_OBJECT,
49 GOT_IMSG_COMMIT,
50 GOT_IMSG_TREE,
51 GOT_IMSG_TREE_ENTRY,
52 GOT_IMSG_BLOB,
53 };
55 /* Structure for GOT_IMSG_ERROR. */
56 struct got_imsg_error {
57 int code; /* an error code from got_error.h */
58 int errno_code; /* in case code equals GOT_ERR_ERRNO */
59 };
61 /* Structure for GOT_IMSG_DELTA data. */
62 struct got_imsg_delta {
63 /* These fields are the same as in struct got_delta. */
64 off_t offset;
65 size_t tslen;
66 int type;
67 size_t size;
68 off_t data_offset;
69 size_t delta_len;
71 /*
72 * Followed by delta stream in remaining bytes of imsg buffer.
73 * If delta_len exceeds imsg buffer length, followed by one or
74 * more DELTA_STREAM messages until delta_len bytes of delta
75 * stream have been transmitted.
76 */
77 };
79 /* Structure for GOT_IMSG_DELTA_STREAM data. */
80 struct got_imsg_delta_stream {
81 /*
82 * Empty since the following is implied:
83 * Read additional delta stream data from imsg buffer.
84 */
85 };
87 /* Structure for GOT_IMSG_OBJECT data. */
88 struct got_imsg_object {
89 /* These fields are the same as in struct got_object. */
90 int type;
91 int flags;
92 size_t hdrlen;
93 size_t size;
95 int ndeltas; /* this many GOT_IMSG_DELTA messages follow */
96 };
98 /* Structure for GOT_IMSG_COMMIT data. */
99 struct got_imsg_commit_object {
100 uint8_t tree_id[SHA1_DIGEST_LENGTH];
101 size_t author_len;
102 time_t author_time;
103 size_t author_tzoff_len;
104 size_t committer_len;
105 time_t committer_time;
106 size_t committer_tzoff_len;
107 size_t logmsg_len;
108 int nparents;
110 /*
111 * Followed by author_len + author_tzoff_len + committer_len +
112 * committer_tzoff_len + logmsg_len data bytes
113 */
115 /* Followed by 'nparents' SHA1_DIGEST_LENGTH length strings */
117 /* XXX should use more messages to support very large log messages */
118 } __attribute__((__packed__));
121 /* Structure for GOT_IMSG_TREE_ENTRY. */
122 struct got_imsg_tree_entry {
123 char id[SHA1_DIGEST_LENGTH];
124 mode_t mode;
125 /* Followed by entry's name in remaining data of imsg buffer. */
126 } __attribute__((__packed__));
128 /* Structure for GOT_IMSG_TREE_OBJECT_REPLY data. */
129 struct got_imsg_tree_object {
130 int nentries; /* This many TREE_ENTRY messages follow. */
131 };
133 /* Structure for GOT_IMSG_BLOB. */
134 struct got_imsg_blob {
135 size_t size;
136 };
138 void got_privsep_send_error(struct imsgbuf *, const struct got_error *);
139 const struct got_error *got_privsep_send_obj(struct imsgbuf *,
140 struct got_object *, int);
141 const struct got_error *got_privsep_recv_obj(struct got_object **,
142 struct imsgbuf *);
143 const struct got_error *got_privsep_send_commit(struct imsgbuf *,
144 struct got_commit_object *);
145 const struct got_error *got_privsep_recv_commit(struct got_commit_object **,
146 struct imsgbuf *);
147 const struct got_error *got_privsep_recv_tree(struct got_tree_object **,
148 struct imsgbuf *);
149 const struct got_error *got_privsep_send_tree(struct imsgbuf *,
150 struct got_tree_object *);
151 const struct got_error *got_privsep_send_blob(struct imsgbuf *, size_t);
152 const struct got_error *got_privsep_recv_blob(size_t *, struct imsgbuf *);
154 /* TODO: Implement the above, and then add more message data types here. */