Blame


1 7be7cc45 2018-04-02 stsp /*
2 5d56da81 2019-01-13 stsp * Copyright (c) 2018, 2019 Stefan Sperling <stsp@openbsd.org>
3 93658fb9 2020-03-18 stsp * Copyright (c) 2019, Ori Bernstein <ori@openbsd.org>
4 7be7cc45 2018-04-02 stsp *
5 7be7cc45 2018-04-02 stsp * Permission to use, copy, modify, and distribute this software for any
6 7be7cc45 2018-04-02 stsp * purpose with or without fee is hereby granted, provided that the above
7 7be7cc45 2018-04-02 stsp * copyright notice and this permission notice appear in all copies.
8 7be7cc45 2018-04-02 stsp *
9 7be7cc45 2018-04-02 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 7be7cc45 2018-04-02 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 7be7cc45 2018-04-02 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 7be7cc45 2018-04-02 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 7be7cc45 2018-04-02 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 7be7cc45 2018-04-02 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 7be7cc45 2018-04-02 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 7be7cc45 2018-04-02 stsp */
17 7be7cc45 2018-04-02 stsp
18 7be7cc45 2018-04-02 stsp /*
19 7be7cc45 2018-04-02 stsp * All code runs under the same UID but sensitive code paths are
20 7be7cc45 2018-04-02 stsp * run in a separate process with tighter pledge(2) promises.
21 2ca3a24b 2018-04-02 stsp * Data is communicated between processes via imsg_flush(3) and imsg_read(3).
22 7be7cc45 2018-04-02 stsp * This behaviour is transparent to users of the library.
23 7be7cc45 2018-04-02 stsp *
24 1e4880cb 2018-04-02 stsp * We generally transmit data in imsg buffers, split across several messages
25 ff6b18f8 2018-04-24 stsp * if necessary. File descriptors are used in cases where this is impractical,
26 ff6b18f8 2018-04-24 stsp * such as when accessing pack files or when transferring large blobs.
27 7be7cc45 2018-04-02 stsp *
28 ad242220 2018-09-08 stsp * We exec(2) after a fork(2). Parts of our library functionality are
29 ad242220 2018-09-08 stsp * accessible via separate executables in a libexec directory.
30 7be7cc45 2018-04-02 stsp */
31 7be7cc45 2018-04-02 stsp
32 ad242220 2018-09-08 stsp #define GOT_IMSG_FD_CHILD (STDERR_FILENO + 1)
33 ad242220 2018-09-08 stsp
34 ad242220 2018-09-08 stsp #ifndef GOT_LIBEXECDIR
35 ad242220 2018-09-08 stsp #define GOT_LIBEXECDIR /usr/libexec
36 ad242220 2018-09-08 stsp #endif
37 ad242220 2018-09-08 stsp
38 ad242220 2018-09-08 stsp /* Names of helper programs in libexec directory */
39 ad242220 2018-09-08 stsp #define GOT_PROG_READ_OBJECT got-read-object
40 ad242220 2018-09-08 stsp #define GOT_PROG_READ_TREE got-read-tree
41 ad242220 2018-09-08 stsp #define GOT_PROG_READ_COMMIT got-read-commit
42 ad242220 2018-09-08 stsp #define GOT_PROG_READ_BLOB got-read-blob
43 f4a881ce 2018-11-17 stsp #define GOT_PROG_READ_TAG got-read-tag
44 876c234b 2018-09-10 stsp #define GOT_PROG_READ_PACK got-read-pack
45 aba9c984 2019-09-08 stsp #define GOT_PROG_READ_GITCONFIG got-read-gitconfig
46 257add31 2020-09-09 stsp #define GOT_PROG_READ_GOTCONFIG got-read-gotconfig
47 93658fb9 2020-03-18 stsp #define GOT_PROG_FETCH_PACK got-fetch-pack
48 93658fb9 2020-03-18 stsp #define GOT_PROG_INDEX_PACK got-index-pack
49 93658fb9 2020-03-18 stsp #define GOT_PROG_SEND_PACK got-send-pack
50 ad242220 2018-09-08 stsp
51 ad242220 2018-09-08 stsp #define GOT_STRINGIFY(x) #x
52 ad242220 2018-09-08 stsp #define GOT_STRINGVAL(x) GOT_STRINGIFY(x)
53 ad242220 2018-09-08 stsp
54 ad242220 2018-09-08 stsp /* Paths to helper programs in libexec directory */
55 ad242220 2018-09-08 stsp #define GOT_PATH_PROG_READ_OBJECT \
56 ad242220 2018-09-08 stsp GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_OBJECT)
57 ad242220 2018-09-08 stsp #define GOT_PATH_PROG_READ_TREE \
58 ad242220 2018-09-08 stsp GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_TREE)
59 ad242220 2018-09-08 stsp #define GOT_PATH_PROG_READ_COMMIT \
60 ad242220 2018-09-08 stsp GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_COMMIT)
61 ad242220 2018-09-08 stsp #define GOT_PATH_PROG_READ_BLOB \
62 ad242220 2018-09-08 stsp GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_BLOB)
63 f4a881ce 2018-11-17 stsp #define GOT_PATH_PROG_READ_TAG \
64 f4a881ce 2018-11-17 stsp GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_TAG)
65 876c234b 2018-09-10 stsp #define GOT_PATH_PROG_READ_PACK \
66 876c234b 2018-09-10 stsp GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_PACK)
67 aba9c984 2019-09-08 stsp #define GOT_PATH_PROG_READ_GITCONFIG \
68 aba9c984 2019-09-08 stsp GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_GITCONFIG)
69 257add31 2020-09-09 stsp #define GOT_PATH_PROG_READ_GOTCONFIG \
70 257add31 2020-09-09 stsp GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_READ_GOTCONFIG)
71 93658fb9 2020-03-18 stsp #define GOT_PATH_PROG_FETCH_PACK \
72 93658fb9 2020-03-18 stsp GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_FETCH_PACK)
73 93658fb9 2020-03-18 stsp #define GOT_PATH_PROG_SEND_PACK \
74 93658fb9 2020-03-18 stsp GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_SEND_PACK)
75 93658fb9 2020-03-18 stsp #define GOT_PATH_PROG_INDEX_PACK \
76 93658fb9 2020-03-18 stsp GOT_STRINGVAL(GOT_LIBEXECDIR) "/" GOT_STRINGVAL(GOT_PROG_INDEX_PACK)
77 ad242220 2018-09-08 stsp
78 876c234b 2018-09-10 stsp struct got_privsep_child {
79 876c234b 2018-09-10 stsp int imsg_fd;
80 876c234b 2018-09-10 stsp pid_t pid;
81 876c234b 2018-09-10 stsp struct imsgbuf *ibuf;
82 876c234b 2018-09-10 stsp };
83 876c234b 2018-09-10 stsp
84 7be7cc45 2018-04-02 stsp enum got_imsg_type {
85 c025a41e 2018-04-02 stsp /* An error occured while processing a request. */
86 c025a41e 2018-04-02 stsp GOT_IMSG_ERROR,
87 c025a41e 2018-04-02 stsp
88 ad242220 2018-09-08 stsp /* Stop the child process. */
89 ad242220 2018-09-08 stsp GOT_IMSG_STOP,
90 1e4880cb 2018-04-02 stsp
91 7be7cc45 2018-04-02 stsp /*
92 7be7cc45 2018-04-02 stsp * Messages concerned with read access to objects in a repository.
93 7be7cc45 2018-04-02 stsp * Object and pack files are opened by the main process, where
94 7be7cc45 2018-04-02 stsp * data may be read as a byte string but without any interpretation.
95 7be7cc45 2018-04-02 stsp * Decompression and parsing of object and pack files occurs in a
96 f0b0c746 2018-09-09 stsp * separate process which runs under pledge("stdio recvfd").
97 7be7cc45 2018-04-02 stsp * This sandboxes our own repository parsing code, as well as zlib.
98 7be7cc45 2018-04-02 stsp */
99 ad242220 2018-09-08 stsp GOT_IMSG_OBJECT_REQUEST,
100 2178c42e 2018-04-22 stsp GOT_IMSG_OBJECT,
101 ad242220 2018-09-08 stsp GOT_IMSG_COMMIT_REQUEST,
102 bff6ca00 2018-04-23 stsp GOT_IMSG_COMMIT,
103 c75f7264 2018-09-11 stsp GOT_IMSG_COMMIT_LOGMSG,
104 ad242220 2018-09-08 stsp GOT_IMSG_TREE_REQUEST,
105 366d86ca 2018-04-23 stsp GOT_IMSG_TREE,
106 d80ab12b 2018-04-02 stsp GOT_IMSG_TREE_ENTRY,
107 ad242220 2018-09-08 stsp GOT_IMSG_BLOB_REQUEST,
108 ad242220 2018-09-08 stsp GOT_IMSG_BLOB_OUTFD,
109 366d86ca 2018-04-23 stsp GOT_IMSG_BLOB,
110 f4a881ce 2018-11-17 stsp GOT_IMSG_TAG_REQUEST,
111 f4a881ce 2018-11-17 stsp GOT_IMSG_TAG,
112 f4a881ce 2018-11-17 stsp GOT_IMSG_TAG_TAGMSG,
113 876c234b 2018-09-10 stsp
114 93658fb9 2020-03-18 stsp /* Messages related to networking. */
115 93658fb9 2020-03-18 stsp GOT_IMSG_FETCH_REQUEST,
116 4ba14133 2020-03-20 stsp GOT_IMSG_FETCH_HAVE_REF,
117 4ba14133 2020-03-20 stsp GOT_IMSG_FETCH_WANTED_BRANCH,
118 0e4002ca 2020-03-21 stsp GOT_IMSG_FETCH_WANTED_REF,
119 f826addf 2020-03-18 stsp GOT_IMSG_FETCH_OUTFD,
120 abe0f35f 2020-03-18 stsp GOT_IMSG_FETCH_SYMREFS,
121 ea7396b9 2020-03-18 stsp GOT_IMSG_FETCH_REF,
122 531c3985 2020-03-18 stsp GOT_IMSG_FETCH_SERVER_PROGRESS,
123 d2cdc636 2020-03-18 stsp GOT_IMSG_FETCH_DOWNLOAD_PROGRESS,
124 93658fb9 2020-03-18 stsp GOT_IMSG_FETCH_DONE,
125 93658fb9 2020-03-18 stsp GOT_IMSG_IDXPACK_REQUEST,
126 73ab1060 2020-03-18 stsp GOT_IMSG_IDXPACK_OUTFD,
127 baa9fea0 2020-03-18 stsp GOT_IMSG_IDXPACK_PROGRESS,
128 93658fb9 2020-03-18 stsp GOT_IMSG_IDXPACK_DONE,
129 93658fb9 2020-03-18 stsp
130 876c234b 2018-09-10 stsp /* Messages related to pack files. */
131 876c234b 2018-09-10 stsp GOT_IMSG_PACKIDX,
132 876c234b 2018-09-10 stsp GOT_IMSG_PACK,
133 876c234b 2018-09-10 stsp GOT_IMSG_PACKED_OBJECT_REQUEST,
134 ca6e02ac 2020-01-07 stsp GOT_IMSG_COMMIT_TRAVERSAL_REQUEST,
135 ca6e02ac 2020-01-07 stsp GOT_IMSG_TRAVERSED_COMMITS,
136 ca6e02ac 2020-01-07 stsp GOT_IMSG_COMMIT_TRAVERSAL_DONE,
137 3840f4c9 2018-09-12 stsp
138 33ad4cbe 2019-05-12 jcs /* Message sending file descriptor to a temporary file. */
139 3840f4c9 2018-09-12 stsp GOT_IMSG_TMPFD,
140 aba9c984 2019-09-08 stsp
141 aba9c984 2019-09-08 stsp /* Messages related to gitconfig files. */
142 aba9c984 2019-09-08 stsp GOT_IMSG_GITCONFIG_PARSE_REQUEST,
143 aba9c984 2019-09-08 stsp GOT_IMSG_GITCONFIG_REPOSITORY_FORMAT_VERSION_REQUEST,
144 20b7abb3 2020-10-22 stsp GOT_IMSG_GITCONFIG_REPOSITORY_EXTENSIONS_REQUEST,
145 aba9c984 2019-09-08 stsp GOT_IMSG_GITCONFIG_AUTHOR_NAME_REQUEST,
146 aba9c984 2019-09-08 stsp GOT_IMSG_GITCONFIG_AUTHOR_EMAIL_REQUEST,
147 cd95becd 2019-11-29 stsp GOT_IMSG_GITCONFIG_REMOTES_REQUEST,
148 aba9c984 2019-09-08 stsp GOT_IMSG_GITCONFIG_INT_VAL,
149 aba9c984 2019-09-08 stsp GOT_IMSG_GITCONFIG_STR_VAL,
150 cd95becd 2019-11-29 stsp GOT_IMSG_GITCONFIG_REMOTES,
151 cd95becd 2019-11-29 stsp GOT_IMSG_GITCONFIG_REMOTE,
152 9a1cc63f 2020-02-03 stsp GOT_IMSG_GITCONFIG_OWNER_REQUEST,
153 9a1cc63f 2020-02-03 stsp GOT_IMSG_GITCONFIG_OWNER,
154 257add31 2020-09-09 stsp
155 257add31 2020-09-09 stsp /* Messages related to gotconfig files. */
156 257add31 2020-09-09 stsp GOT_IMSG_GOTCONFIG_PARSE_REQUEST,
157 257add31 2020-09-09 stsp GOT_IMSG_GOTCONFIG_AUTHOR_REQUEST,
158 257add31 2020-09-09 stsp GOT_IMSG_GOTCONFIG_REMOTES_REQUEST,
159 257add31 2020-09-09 stsp GOT_IMSG_GOTCONFIG_INT_VAL,
160 257add31 2020-09-09 stsp GOT_IMSG_GOTCONFIG_STR_VAL,
161 257add31 2020-09-09 stsp GOT_IMSG_GOTCONFIG_REMOTES,
162 257add31 2020-09-09 stsp GOT_IMSG_GOTCONFIG_REMOTE,
163 59d1e4a0 2021-03-10 stsp
164 59d1e4a0 2021-03-10 stsp /* Raw object access. Uncompress object data but do not parse it. */
165 59d1e4a0 2021-03-10 stsp GOT_IMSG_RAW_OBJECT_REQUEST,
166 59d1e4a0 2021-03-10 stsp GOT_IMSG_RAW_OBJECT_OUTFD,
167 59d1e4a0 2021-03-10 stsp GOT_IMSG_PACKED_RAW_OBJECT_REQUEST,
168 59d1e4a0 2021-03-10 stsp GOT_IMSG_RAW_OBJECT,
169 7be7cc45 2018-04-02 stsp };
170 7be7cc45 2018-04-02 stsp
171 c025a41e 2018-04-02 stsp /* Structure for GOT_IMSG_ERROR. */
172 c025a41e 2018-04-02 stsp struct got_imsg_error {
173 c025a41e 2018-04-02 stsp int code; /* an error code from got_error.h */
174 2178c42e 2018-04-22 stsp int errno_code; /* in case code equals GOT_ERR_ERRNO */
175 291624d8 2018-11-07 stsp } __attribute__((__packed__));
176 c025a41e 2018-04-02 stsp
177 ad242220 2018-09-08 stsp /*
178 1785f84a 2018-12-23 stsp * Structure for GOT_IMSG_TREE_REQUEST and GOT_IMSG_OBJECT data.
179 ad242220 2018-09-08 stsp */
180 f7171542 2018-04-02 stsp struct got_imsg_object {
181 c59b3346 2018-09-11 stsp uint8_t id[SHA1_DIGEST_LENGTH];
182 c59b3346 2018-09-11 stsp
183 7be7cc45 2018-04-02 stsp /* These fields are the same as in struct got_object. */
184 7be7cc45 2018-04-02 stsp int type;
185 7be7cc45 2018-04-02 stsp int flags;
186 7be7cc45 2018-04-02 stsp size_t hdrlen;
187 7be7cc45 2018-04-02 stsp size_t size;
188 876c234b 2018-09-10 stsp off_t pack_offset;
189 c59b3346 2018-09-11 stsp int pack_idx;
190 291624d8 2018-11-07 stsp } __attribute__((__packed__));
191 7be7cc45 2018-04-02 stsp
192 366d86ca 2018-04-23 stsp /* Structure for GOT_IMSG_COMMIT data. */
193 bff6ca00 2018-04-23 stsp struct got_imsg_commit_object {
194 86acc566 2018-04-23 stsp uint8_t tree_id[SHA1_DIGEST_LENGTH];
195 bff6ca00 2018-04-23 stsp size_t author_len;
196 ccb26ccd 2018-11-05 stsp time_t author_time;
197 ccb26ccd 2018-11-05 stsp time_t author_gmtoff;
198 bff6ca00 2018-04-23 stsp size_t committer_len;
199 ccb26ccd 2018-11-05 stsp time_t committer_time;
200 ccb26ccd 2018-11-05 stsp time_t committer_gmtoff;
201 bff6ca00 2018-04-23 stsp size_t logmsg_len;
202 bff6ca00 2018-04-23 stsp int nparents;
203 bff6ca00 2018-04-23 stsp
204 6c281f94 2018-06-11 stsp /*
205 c75f7264 2018-09-11 stsp * Followed by author_len + committer_len data bytes
206 6c281f94 2018-06-11 stsp */
207 bff6ca00 2018-04-23 stsp
208 86acc566 2018-04-23 stsp /* Followed by 'nparents' SHA1_DIGEST_LENGTH length strings */
209 bff6ca00 2018-04-23 stsp
210 c75f7264 2018-09-11 stsp /*
211 c75f7264 2018-09-11 stsp * Followed by 'logmsg_len' bytes of commit log message data in
212 c75f7264 2018-09-11 stsp * one or more GOT_IMSG_COMMIT_LOGMSG messages.
213 c75f7264 2018-09-11 stsp */
214 bff6ca00 2018-04-23 stsp } __attribute__((__packed__));
215 bff6ca00 2018-04-23 stsp
216 f7171542 2018-04-02 stsp
217 48f392b2 2018-04-02 stsp /* Structure for GOT_IMSG_TREE_ENTRY. */
218 48f392b2 2018-04-02 stsp struct got_imsg_tree_entry {
219 e033d803 2018-04-23 stsp char id[SHA1_DIGEST_LENGTH];
220 48f392b2 2018-04-02 stsp mode_t mode;
221 48f392b2 2018-04-02 stsp /* Followed by entry's name in remaining data of imsg buffer. */
222 8d98bcfb 2018-04-02 stsp } __attribute__((__packed__));
223 48f392b2 2018-04-02 stsp
224 d80ab12b 2018-04-02 stsp /* Structure for GOT_IMSG_TREE_OBJECT_REPLY data. */
225 48f392b2 2018-04-02 stsp struct got_imsg_tree_object {
226 48f392b2 2018-04-02 stsp int nentries; /* This many TREE_ENTRY messages follow. */
227 48f392b2 2018-04-02 stsp };
228 48f392b2 2018-04-02 stsp
229 2967a784 2018-04-24 stsp /* Structure for GOT_IMSG_BLOB. */
230 2967a784 2018-04-24 stsp struct got_imsg_blob {
231 2967a784 2018-04-24 stsp size_t size;
232 ebc55e2d 2018-12-24 stsp size_t hdrlen;
233 ac544f8c 2019-01-13 stsp
234 ac544f8c 2019-01-13 stsp /*
235 ac544f8c 2019-01-13 stsp * If size <= GOT_PRIVSEP_INLINE_BLOB_DATA_MAX, blob data follows
236 ac544f8c 2019-01-13 stsp * in the imsg buffer. Otherwise, blob data has been written to a
237 ac544f8c 2019-01-13 stsp * file descriptor passed via the GOT_IMSG_BLOB_OUTFD imsg.
238 ac544f8c 2019-01-13 stsp */
239 ac544f8c 2019-01-13 stsp #define GOT_PRIVSEP_INLINE_BLOB_DATA_MAX \
240 ac544f8c 2019-01-13 stsp (MAX_IMSGSIZE - IMSG_HEADER_SIZE - sizeof(struct got_imsg_blob))
241 2967a784 2018-04-24 stsp };
242 2967a784 2018-04-24 stsp
243 59d1e4a0 2021-03-10 stsp /* Structure for GOT_IMSG_RAW_OBJECT. */
244 59d1e4a0 2021-03-10 stsp struct got_imsg_raw_obj {
245 59d1e4a0 2021-03-10 stsp off_t size;
246 59d1e4a0 2021-03-10 stsp size_t hdrlen;
247 59d1e4a0 2021-03-10 stsp
248 59d1e4a0 2021-03-10 stsp /*
249 59d1e4a0 2021-03-10 stsp * If size <= GOT_PRIVSEP_INLINE_OBJECT_DATA_MAX, object data follows
250 59d1e4a0 2021-03-10 stsp * in the imsg buffer. Otherwise, object data has been written to a
251 59d1e4a0 2021-03-10 stsp * file descriptor passed via the GOT_IMSG_RAW_OBJECT_OUTFD imsg.
252 59d1e4a0 2021-03-10 stsp */
253 59d1e4a0 2021-03-10 stsp #define GOT_PRIVSEP_INLINE_OBJECT_DATA_MAX \
254 59d1e4a0 2021-03-10 stsp (MAX_IMSGSIZE - IMSG_HEADER_SIZE - sizeof(struct got_imsg_raw_obj))
255 59d1e4a0 2021-03-10 stsp };
256 ac544f8c 2019-01-13 stsp
257 f4a881ce 2018-11-17 stsp /* Structure for GOT_IMSG_TAG data. */
258 f4a881ce 2018-11-17 stsp struct got_imsg_tag_object {
259 f4a881ce 2018-11-17 stsp uint8_t id[SHA1_DIGEST_LENGTH];
260 f4a881ce 2018-11-17 stsp int obj_type;
261 f4a881ce 2018-11-17 stsp size_t tag_len;
262 f4a881ce 2018-11-17 stsp size_t tagger_len;
263 f4a881ce 2018-11-17 stsp time_t tagger_time;
264 f4a881ce 2018-11-17 stsp time_t tagger_gmtoff;
265 f4a881ce 2018-11-17 stsp size_t tagmsg_len;
266 f4a881ce 2018-11-17 stsp
267 f4a881ce 2018-11-17 stsp /*
268 f4a881ce 2018-11-17 stsp * Followed by tag_len + tagger_len data bytes
269 f4a881ce 2018-11-17 stsp */
270 f4a881ce 2018-11-17 stsp
271 f4a881ce 2018-11-17 stsp /*
272 f4a881ce 2018-11-17 stsp * Followed by 'tagmsg_len' bytes of tag message data in
273 f4a881ce 2018-11-17 stsp * one or more GOT_IMSG_TAG_TAGMSG messages.
274 f4a881ce 2018-11-17 stsp */
275 abe0f35f 2020-03-18 stsp } __attribute__((__packed__));
276 33501562 2020-03-18 stsp
277 4ba14133 2020-03-20 stsp /* Structure for GOT_IMSG_FETCH_HAVE_REF data. */
278 33501562 2020-03-18 stsp struct got_imsg_fetch_have_ref {
279 33501562 2020-03-18 stsp uint8_t id[SHA1_DIGEST_LENGTH];
280 33501562 2020-03-18 stsp size_t name_len;
281 33501562 2020-03-18 stsp /* Followed by name_len data bytes. */
282 7848a0e1 2020-03-19 stsp } __attribute__((__packed__));
283 7848a0e1 2020-03-19 stsp
284 4ba14133 2020-03-20 stsp /* Structure for GOT_IMSG_FETCH_WANTED_BRANCH data. */
285 4ba14133 2020-03-20 stsp struct got_imsg_fetch_wanted_branch {
286 0e4002ca 2020-03-21 stsp size_t name_len;
287 0e4002ca 2020-03-21 stsp /* Followed by name_len data bytes. */
288 0e4002ca 2020-03-21 stsp } __attribute__((__packed__));
289 0e4002ca 2020-03-21 stsp
290 0e4002ca 2020-03-21 stsp /* Structure for GOT_IMSG_FETCH_WANTED_REF data. */
291 0e4002ca 2020-03-21 stsp struct got_imsg_fetch_wanted_ref {
292 4ba14133 2020-03-20 stsp size_t name_len;
293 4ba14133 2020-03-20 stsp /* Followed by name_len data bytes. */
294 4ba14133 2020-03-20 stsp } __attribute__((__packed__));
295 4ba14133 2020-03-20 stsp
296 4ba14133 2020-03-20 stsp /* Structure for GOT_IMSG_FETCH_REQUEST data. */
297 659e7fbd 2020-03-20 stsp struct got_imsg_fetch_request {
298 659e7fbd 2020-03-20 stsp int fetch_all_branches;
299 41b0de12 2020-03-21 stsp int list_refs_only;
300 2690194b 2020-03-21 stsp int verbosity;
301 33501562 2020-03-18 stsp size_t n_have_refs;
302 4ba14133 2020-03-20 stsp size_t n_wanted_branches;
303 0e4002ca 2020-03-21 stsp size_t n_wanted_refs;
304 4ba14133 2020-03-20 stsp /* Followed by n_have_refs GOT_IMSG_FETCH_HAVE_REF messages. */
305 4ba14133 2020-03-20 stsp /* Followed by n_wanted_branches times GOT_IMSG_FETCH_WANTED_BRANCH. */
306 0e4002ca 2020-03-21 stsp /* Followed by n_wanted_refs times GOT_IMSG_FETCH_WANTED_REF. */
307 659e7fbd 2020-03-20 stsp } __attribute__((__packed__));
308 abe0f35f 2020-03-18 stsp
309 abe0f35f 2020-03-18 stsp /* Structures for GOT_IMSG_FETCH_SYMREFS data. */
310 abe0f35f 2020-03-18 stsp struct got_imsg_fetch_symref {
311 abe0f35f 2020-03-18 stsp size_t name_len;
312 abe0f35f 2020-03-18 stsp size_t target_len;
313 abe0f35f 2020-03-18 stsp
314 abe0f35f 2020-03-18 stsp /*
315 d45e6863 2020-03-18 stsp * Followed by name_len + target_len data bytes.
316 abe0f35f 2020-03-18 stsp */
317 abe0f35f 2020-03-18 stsp } __attribute__((__packed__));
318 abe0f35f 2020-03-18 stsp
319 abe0f35f 2020-03-18 stsp struct got_imsg_fetch_symrefs {
320 abe0f35f 2020-03-18 stsp size_t nsymrefs;
321 abe0f35f 2020-03-18 stsp
322 abe0f35f 2020-03-18 stsp /* Followed by nsymrefs times of got_imsg_fetch_symref data. */
323 f4a881ce 2018-11-17 stsp } __attribute__((__packed__));
324 b9f99abf 2020-03-18 stsp
325 ea7396b9 2020-03-18 stsp /* Structure for GOT_IMSG_FETCH_REF data. */
326 ea7396b9 2020-03-18 stsp struct got_imsg_fetch_ref {
327 abe0f35f 2020-03-18 stsp /* Describes a reference which will be fetched. */
328 b9f99abf 2020-03-18 stsp uint8_t refid[SHA1_DIGEST_LENGTH];
329 b9f99abf 2020-03-18 stsp /* Followed by reference name in remaining data of imsg buffer. */
330 b9f99abf 2020-03-18 stsp };
331 f4a881ce 2018-11-17 stsp
332 d2cdc636 2020-03-18 stsp /* Structure for GOT_IMSG_FETCH_DOWNLOAD_PROGRESS data. */
333 d2cdc636 2020-03-18 stsp struct got_imsg_fetch_download_progress {
334 d2cdc636 2020-03-18 stsp /* Number of packfile data bytes downloaded so far. */
335 d2cdc636 2020-03-18 stsp off_t packfile_bytes;
336 baa9fea0 2020-03-18 stsp };
337 668a20f6 2020-03-18 stsp
338 668a20f6 2020-03-18 stsp /* Structure for GOT_IMSG_IDXPACK_REQUEST data. */
339 668a20f6 2020-03-18 stsp struct got_imsg_index_pack_request {
340 668a20f6 2020-03-18 stsp uint8_t pack_hash[SHA1_DIGEST_LENGTH];
341 668a20f6 2020-03-18 stsp } __attribute__((__packed__));
342 baa9fea0 2020-03-18 stsp
343 baa9fea0 2020-03-18 stsp /* Structure for GOT_IMSG_IDXPACK_PROGRESS data. */
344 baa9fea0 2020-03-18 stsp struct got_imsg_index_pack_progress {
345 baa9fea0 2020-03-18 stsp /* Total number of objects in pack file. */
346 668a20f6 2020-03-18 stsp int nobj_total;
347 668a20f6 2020-03-18 stsp
348 baa9fea0 2020-03-18 stsp /* Number of objects indexed so far. */
349 668a20f6 2020-03-18 stsp int nobj_indexed;
350 668a20f6 2020-03-18 stsp
351 668a20f6 2020-03-18 stsp /* Number of non-deltified objects in pack file. */
352 668a20f6 2020-03-18 stsp int nobj_loose;
353 668a20f6 2020-03-18 stsp
354 668a20f6 2020-03-18 stsp /* Number of deltified objects resolved so far. */
355 668a20f6 2020-03-18 stsp int nobj_resolved;
356 d2cdc636 2020-03-18 stsp };
357 d2cdc636 2020-03-18 stsp
358 876c234b 2018-09-10 stsp /* Structure for GOT_IMSG_PACKIDX. */
359 876c234b 2018-09-10 stsp struct got_imsg_packidx {
360 876c234b 2018-09-10 stsp size_t len;
361 876c234b 2018-09-10 stsp /* Additionally, a file desciptor is passed via imsg. */
362 876c234b 2018-09-10 stsp };
363 876c234b 2018-09-10 stsp
364 876c234b 2018-09-10 stsp /* Structure for GOT_IMSG_PACK. */
365 876c234b 2018-09-10 stsp struct got_imsg_pack {
366 876c234b 2018-09-10 stsp char path_packfile[PATH_MAX];
367 876c234b 2018-09-10 stsp size_t filesize;
368 876c234b 2018-09-10 stsp /* Additionally, a file desciptor is passed via imsg. */
369 291624d8 2018-11-07 stsp } __attribute__((__packed__));
370 876c234b 2018-09-10 stsp
371 876c234b 2018-09-10 stsp /*
372 59d1e4a0 2021-03-10 stsp * Structure for GOT_IMSG_PACKED_OBJECT_REQUEST and
373 59d1e4a0 2021-03-10 stsp * GOT_IMSG_PACKED_RAW_OBJECT_REQUEST data.
374 876c234b 2018-09-10 stsp */
375 876c234b 2018-09-10 stsp struct got_imsg_packed_object {
376 106807b4 2018-09-15 stsp uint8_t id[SHA1_DIGEST_LENGTH];
377 876c234b 2018-09-10 stsp int idx;
378 291624d8 2018-11-07 stsp } __attribute__((__packed__));
379 876c234b 2018-09-10 stsp
380 ca6e02ac 2020-01-07 stsp /* Structure for GOT_IMSG_COMMIT_TRAVERSAL_REQUEST */
381 ca6e02ac 2020-01-07 stsp struct got_imsg_commit_traversal_request {
382 ca6e02ac 2020-01-07 stsp uint8_t id[SHA1_DIGEST_LENGTH];
383 ca6e02ac 2020-01-07 stsp int idx;
384 ca6e02ac 2020-01-07 stsp size_t path_len;
385 ca6e02ac 2020-01-07 stsp /* Followed by path_len bytes of path data */
386 ca6e02ac 2020-01-07 stsp } __attribute__((__packed__));
387 ca6e02ac 2020-01-07 stsp
388 ca6e02ac 2020-01-07 stsp /* Structure for GOT_IMSG_TRAVERSED_COMMITS */
389 ca6e02ac 2020-01-07 stsp struct got_imsg_traversed_commits {
390 ca6e02ac 2020-01-07 stsp size_t ncommits;
391 ca6e02ac 2020-01-07 stsp /* Followed by ncommit IDs of SHA1_DIGEST_LENGTH each */
392 ca6e02ac 2020-01-07 stsp } __attribute__((__packed__));
393 ca6e02ac 2020-01-07 stsp
394 cd95becd 2019-11-29 stsp /*
395 cd95becd 2019-11-29 stsp * Structure for GOT_IMSG_GITCONFIG_REMOTE data.
396 cd95becd 2019-11-29 stsp */
397 cd95becd 2019-11-29 stsp struct got_imsg_remote {
398 cd95becd 2019-11-29 stsp size_t name_len;
399 cd95becd 2019-11-29 stsp size_t url_len;
400 469dd726 2020-03-20 stsp int mirror_references;
401 0c8b29c5 2021-01-05 stsp int fetch_all_branches;
402 b8adfa55 2020-09-25 stsp int nbranches;
403 99495ddb 2021-01-10 stsp int nrefs;
404 cd95becd 2019-11-29 stsp
405 cd95becd 2019-11-29 stsp /* Followed by name_len + url_len data bytes. */
406 b8adfa55 2020-09-25 stsp /* Followed by nbranches GOT_IMSG_GITCONFIG_STR_VAL messages. */
407 99495ddb 2021-01-10 stsp /* Followed by nrefs GOT_IMSG_GITCONFIG_STR_VAL messages. */
408 4ba14133 2020-03-20 stsp } __attribute__((__packed__));
409 cd95becd 2019-11-29 stsp
410 cd95becd 2019-11-29 stsp /*
411 cd95becd 2019-11-29 stsp * Structure for GOT_IMSG_GITCONFIG_REMOTES data.
412 cd95becd 2019-11-29 stsp */
413 cd95becd 2019-11-29 stsp struct got_imsg_remotes {
414 cd95becd 2019-11-29 stsp int nremotes; /* This many GOT_IMSG_GITCONFIG_REMOTE messages follow. */
415 cd95becd 2019-11-29 stsp };
416 cd95becd 2019-11-29 stsp
417 cd95becd 2019-11-29 stsp struct got_remote_repo;
418 876c234b 2018-09-10 stsp struct got_pack;
419 876c234b 2018-09-10 stsp struct got_packidx;
420 3022d272 2019-11-14 stsp struct got_pathlist_head;
421 876c234b 2018-09-10 stsp
422 93658fb9 2020-03-18 stsp const struct got_error *got_send_ack(pid_t);
423 876c234b 2018-09-10 stsp const struct got_error *got_privsep_wait_for_child(pid_t);
424 e70bf110 2020-03-22 stsp const struct got_error *got_privsep_flush_imsg(struct imsgbuf *);
425 ad242220 2018-09-08 stsp const struct got_error *got_privsep_send_stop(int);
426 ad242220 2018-09-08 stsp const struct got_error *got_privsep_recv_imsg(struct imsg *, struct imsgbuf *,
427 ad242220 2018-09-08 stsp size_t);
428 2178c42e 2018-04-22 stsp void got_privsep_send_error(struct imsgbuf *, const struct got_error *);
429 93658fb9 2020-03-18 stsp const struct got_error *got_privsep_send_ack(struct imsgbuf *);
430 93658fb9 2020-03-18 stsp const struct got_error *got_privsep_wait_ack(struct imsgbuf *);
431 aea5f015 2018-12-24 stsp const struct got_error *got_privsep_send_obj_req(struct imsgbuf *, int);
432 59d1e4a0 2021-03-10 stsp const struct got_error *got_privsep_send_raw_obj_req(struct imsgbuf *, int);
433 59d1e4a0 2021-03-10 stsp const struct got_error *got_privsep_send_raw_obj_outfd(struct imsgbuf *, int);
434 1785f84a 2018-12-23 stsp const struct got_error *got_privsep_send_commit_req(struct imsgbuf *, int,
435 1785f84a 2018-12-23 stsp struct got_object_id *, int);
436 13c729f7 2018-12-24 stsp const struct got_error *got_privsep_send_tree_req(struct imsgbuf *, int,
437 13c729f7 2018-12-24 stsp struct got_object_id *, int);
438 268f7291 2018-12-24 stsp const struct got_error *got_privsep_send_tag_req(struct imsgbuf *, int,
439 268f7291 2018-12-24 stsp struct got_object_id *, int);
440 ebc55e2d 2018-12-24 stsp const struct got_error *got_privsep_send_blob_req(struct imsgbuf *, int,
441 ebc55e2d 2018-12-24 stsp struct got_object_id *, int);
442 55da3778 2018-09-10 stsp const struct got_error *got_privsep_send_blob_outfd(struct imsgbuf *, int);
443 3840f4c9 2018-09-12 stsp const struct got_error *got_privsep_send_tmpfd(struct imsgbuf *, int);
444 2178c42e 2018-04-22 stsp const struct got_error *got_privsep_send_obj(struct imsgbuf *,
445 876c234b 2018-09-10 stsp struct got_object *);
446 668a20f6 2020-03-18 stsp const struct got_error *got_privsep_send_index_pack_req(struct imsgbuf *,
447 668a20f6 2020-03-18 stsp uint8_t *, int);
448 73ab1060 2020-03-18 stsp const struct got_error *got_privsep_send_index_pack_outfd(struct imsgbuf *,
449 73ab1060 2020-03-18 stsp int);
450 baa9fea0 2020-03-18 stsp const struct got_error *got_privsep_recv_index_progress(int *, int *, int *,
451 668a20f6 2020-03-18 stsp int *, int *, struct imsgbuf *ibuf);
452 33501562 2020-03-18 stsp const struct got_error *got_privsep_send_fetch_req(struct imsgbuf *, int,
453 0e4002ca 2020-03-21 stsp struct got_pathlist_head *, int, struct got_pathlist_head *,
454 0e4002ca 2020-03-21 stsp struct got_pathlist_head *, int, int);
455 f826addf 2020-03-18 stsp const struct got_error *got_privsep_send_fetch_outfd(struct imsgbuf *, int);
456 8f2d01a6 2020-03-18 stsp const struct got_error *got_privsep_recv_fetch_progress(int *,
457 1d72a2a0 2020-03-24 stsp struct got_object_id **, char **, struct got_pathlist_head *, char **,
458 1d72a2a0 2020-03-24 stsp off_t *, uint8_t *, struct imsgbuf *);
459 cfd633c2 2018-09-10 stsp const struct got_error *got_privsep_get_imsg_obj(struct got_object **,
460 cfd633c2 2018-09-10 stsp struct imsg *, struct imsgbuf *);
461 2178c42e 2018-04-22 stsp const struct got_error *got_privsep_recv_obj(struct got_object **,
462 2178c42e 2018-04-22 stsp struct imsgbuf *);
463 59d1e4a0 2021-03-10 stsp const struct got_error *got_privsep_send_raw_obj(struct imsgbuf *, off_t,
464 59d1e4a0 2021-03-10 stsp size_t, uint8_t *);
465 59d1e4a0 2021-03-10 stsp const struct got_error *got_privsep_recv_raw_obj(uint8_t **, off_t *, size_t *,
466 59d1e4a0 2021-03-10 stsp struct imsgbuf *);
467 068fd2bf 2018-04-24 stsp const struct got_error *got_privsep_send_commit(struct imsgbuf *,
468 bff6ca00 2018-04-23 stsp struct got_commit_object *);
469 068fd2bf 2018-04-24 stsp const struct got_error *got_privsep_recv_commit(struct got_commit_object **,
470 bff6ca00 2018-04-23 stsp struct imsgbuf *);
471 068fd2bf 2018-04-24 stsp const struct got_error *got_privsep_recv_tree(struct got_tree_object **,
472 e033d803 2018-04-23 stsp struct imsgbuf *);
473 068fd2bf 2018-04-24 stsp const struct got_error *got_privsep_send_tree(struct imsgbuf *,
474 3022d272 2019-11-14 stsp struct got_pathlist_head *, int);
475 ac544f8c 2019-01-13 stsp const struct got_error *got_privsep_send_blob(struct imsgbuf *, size_t, size_t,
476 ac544f8c 2019-01-13 stsp const uint8_t *);
477 ac544f8c 2019-01-13 stsp const struct got_error *got_privsep_recv_blob(uint8_t **, size_t *, size_t *,
478 ebc55e2d 2018-12-24 stsp struct imsgbuf *);
479 f4a881ce 2018-11-17 stsp const struct got_error *got_privsep_send_tag(struct imsgbuf *,
480 f4a881ce 2018-11-17 stsp struct got_tag_object *);
481 f4a881ce 2018-11-17 stsp const struct got_error *got_privsep_recv_tag(struct got_tag_object **,
482 f4a881ce 2018-11-17 stsp struct imsgbuf *);
483 876c234b 2018-09-10 stsp const struct got_error *got_privsep_init_pack_child(struct imsgbuf *,
484 876c234b 2018-09-10 stsp struct got_pack *, struct got_packidx *);
485 106807b4 2018-09-15 stsp const struct got_error *got_privsep_send_packed_obj_req(struct imsgbuf *, int,
486 106807b4 2018-09-15 stsp struct got_object_id *);
487 59d1e4a0 2021-03-10 stsp const struct got_error *got_privsep_send_packed_raw_obj_req(struct imsgbuf *,
488 59d1e4a0 2021-03-10 stsp int, struct got_object_id *);
489 41fa1437 2018-11-05 stsp const struct got_error *got_privsep_send_pack_child_ready(struct imsgbuf *);
490 aba9c984 2019-09-08 stsp
491 aba9c984 2019-09-08 stsp const struct got_error *got_privsep_send_gitconfig_parse_req(struct imsgbuf *,
492 aba9c984 2019-09-08 stsp int);
493 aba9c984 2019-09-08 stsp const struct got_error *
494 aba9c984 2019-09-08 stsp got_privsep_send_gitconfig_repository_format_version_req(struct imsgbuf *);
495 20b7abb3 2020-10-22 stsp const struct got_error *got_privsep_send_gitconfig_repository_extensions_req(
496 20b7abb3 2020-10-22 stsp struct imsgbuf *);
497 aba9c984 2019-09-08 stsp const struct got_error *got_privsep_send_gitconfig_author_name_req(
498 aba9c984 2019-09-08 stsp struct imsgbuf *);
499 aba9c984 2019-09-08 stsp const struct got_error *got_privsep_send_gitconfig_author_email_req(
500 aba9c984 2019-09-08 stsp struct imsgbuf *);
501 cd95becd 2019-11-29 stsp const struct got_error *got_privsep_send_gitconfig_remotes_req(
502 cd95becd 2019-11-29 stsp struct imsgbuf *);
503 9a1cc63f 2020-02-03 stsp const struct got_error *got_privsep_send_gitconfig_owner_req(struct imsgbuf *);
504 aba9c984 2019-09-08 stsp const struct got_error *got_privsep_recv_gitconfig_str(char **,
505 aba9c984 2019-09-08 stsp struct imsgbuf *);
506 aba9c984 2019-09-08 stsp const struct got_error *got_privsep_recv_gitconfig_int(int *, struct imsgbuf *);
507 cd95becd 2019-11-29 stsp const struct got_error *got_privsep_recv_gitconfig_remotes(
508 257add31 2020-09-09 stsp struct got_remote_repo **, int *, struct imsgbuf *);
509 257add31 2020-09-09 stsp
510 257add31 2020-09-09 stsp const struct got_error *got_privsep_send_gotconfig_parse_req(struct imsgbuf *,
511 257add31 2020-09-09 stsp int);
512 257add31 2020-09-09 stsp const struct got_error *got_privsep_send_gotconfig_author_req(struct imsgbuf *);
513 257add31 2020-09-09 stsp const struct got_error *got_privsep_send_gotconfig_remotes_req(
514 257add31 2020-09-09 stsp struct imsgbuf *);
515 257add31 2020-09-09 stsp const struct got_error *got_privsep_recv_gotconfig_str(char **,
516 257add31 2020-09-09 stsp struct imsgbuf *);
517 257add31 2020-09-09 stsp const struct got_error *got_privsep_recv_gotconfig_remotes(
518 cd95becd 2019-11-29 stsp struct got_remote_repo **, int *, struct imsgbuf *);
519 aba9c984 2019-09-08 stsp
520 ca6e02ac 2020-01-07 stsp const struct got_error *got_privsep_send_commit_traversal_request(
521 ca6e02ac 2020-01-07 stsp struct imsgbuf *, struct got_object_id *, int, const char *);
522 ca6e02ac 2020-01-07 stsp const struct got_error *got_privsep_recv_traversed_commits(
523 ca6e02ac 2020-01-07 stsp struct got_commit_object **, struct got_object_id **,
524 ca6e02ac 2020-01-07 stsp struct got_object_id_queue *, struct imsgbuf *);
525 ca6e02ac 2020-01-07 stsp
526 aba9c984 2019-09-08 stsp void got_privsep_exec_child(int[2], const char *, const char *);