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