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 struct tm tm_author;
103 size_t committer_len;
104 struct tm tm_committer;
105 size_t logmsg_len;
106 int nparents;
108 /*
109 * Followed by author_len + committer_len + logmsg_len data bytes
110 */
112 /* Followed by 'nparents' SHA1_DIGEST_LENGTH length strings */
114 /* XXX should use more messages to support very large log messages */
115 } __attribute__((__packed__));
118 /* Structure for GOT_IMSG_TREE_ENTRY. */
119 struct got_imsg_tree_entry {
120 char id[SHA1_DIGEST_LENGTH];
121 mode_t mode;
122 /* Followed by entry's name in remaining data of imsg buffer. */
123 } __attribute__((__packed__));
125 /* Structure for GOT_IMSG_TREE_OBJECT_REPLY data. */
126 struct got_imsg_tree_object {
127 int nentries; /* This many TREE_ENTRY messages follow. */
128 };
130 /* Structure for GOT_IMSG_BLOB. */
131 struct got_imsg_blob {
132 size_t size;
133 };
135 void got_privsep_send_error(struct imsgbuf *, const struct got_error *);
136 const struct got_error *got_privsep_send_obj(struct imsgbuf *,
137 struct got_object *, int);
138 const struct got_error *got_privsep_recv_obj(struct got_object **,
139 struct imsgbuf *);
140 const struct got_error *got_privsep_send_commit(struct imsgbuf *,
141 struct got_commit_object *);
142 const struct got_error *got_privsep_recv_commit(struct got_commit_object **,
143 struct imsgbuf *);
144 const struct got_error *got_privsep_recv_tree(struct got_tree_object **,
145 struct imsgbuf *);
146 const struct got_error *got_privsep_send_tree(struct imsgbuf *,
147 struct got_tree_object *);
148 const struct got_error *got_privsep_send_blob(struct imsgbuf *, size_t);
149 const struct got_error *got_privsep_recv_blob(size_t *, struct imsgbuf *);
151 /* TODO: Implement the above, and then add more message data types here. */