Blame


1 3efd8e31 2022-10-23 thomas /*
2 3efd8e31 2022-10-23 thomas * Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
3 3efd8e31 2022-10-23 thomas *
4 3efd8e31 2022-10-23 thomas * Permission to use, copy, modify, and distribute this software for any
5 3efd8e31 2022-10-23 thomas * purpose with or without fee is hereby granted, provided that the above
6 3efd8e31 2022-10-23 thomas * copyright notice and this permission notice appear in all copies.
7 3efd8e31 2022-10-23 thomas *
8 3efd8e31 2022-10-23 thomas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 3efd8e31 2022-10-23 thomas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 3efd8e31 2022-10-23 thomas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 3efd8e31 2022-10-23 thomas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 3efd8e31 2022-10-23 thomas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 3efd8e31 2022-10-23 thomas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 3efd8e31 2022-10-23 thomas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 3efd8e31 2022-10-23 thomas */
16 3efd8e31 2022-10-23 thomas
17 3efd8e31 2022-10-23 thomas
18 3efd8e31 2022-10-23 thomas #define GOTD_UNIX_SOCKET "/var/run/gotd.sock"
19 3efd8e31 2022-10-23 thomas #define GOTD_UNIX_SOCKET_BACKLOG 10
20 3efd8e31 2022-10-23 thomas #define GOTD_UNIX_GROUP "_gotsh"
21 3efd8e31 2022-10-23 thomas #define GOTD_USER "_gotd"
22 3efd8e31 2022-10-23 thomas #define GOTD_CONF_PATH "/etc/gotd.conf"
23 2b3d32a1 2022-12-30 thomas #define GOTD_EMPTY_PATH "/var/empty"
24 3efd8e31 2022-10-23 thomas
25 3efd8e31 2022-10-23 thomas #define GOTD_MAXCLIENTS 1024
26 3efd8e31 2022-10-23 thomas #define GOTD_FD_RESERVE 5
27 3efd8e31 2022-10-23 thomas #define GOTD_FD_NEEDED 6
28 bb3a6ce9 2022-11-17 thomas #define GOTD_FILENO_MSG_PIPE 3
29 3efd8e31 2022-10-23 thomas
30 3efd8e31 2022-10-23 thomas /* Client hash tables need some extra room. */
31 3efd8e31 2022-10-23 thomas #define GOTD_CLIENT_TABLE_SIZE (GOTD_MAXCLIENTS * 4)
32 3efd8e31 2022-10-23 thomas
33 3efd8e31 2022-10-23 thomas enum gotd_procid {
34 3efd8e31 2022-10-23 thomas PROC_GOTD = 0,
35 2b3d32a1 2022-12-30 thomas PROC_LISTEN,
36 c669c489 2022-12-30 thomas PROC_AUTH,
37 3efd8e31 2022-10-23 thomas PROC_REPO_READ,
38 3efd8e31 2022-10-23 thomas PROC_REPO_WRITE,
39 3efd8e31 2022-10-23 thomas PROC_MAX,
40 3efd8e31 2022-10-23 thomas };
41 3efd8e31 2022-10-23 thomas
42 3efd8e31 2022-10-23 thomas struct gotd_imsgev {
43 3efd8e31 2022-10-23 thomas struct imsgbuf ibuf;
44 3efd8e31 2022-10-23 thomas void (*handler)(int, short, void *);
45 3efd8e31 2022-10-23 thomas void *handler_arg;
46 3efd8e31 2022-10-23 thomas struct event ev;
47 3efd8e31 2022-10-23 thomas short events;
48 3efd8e31 2022-10-23 thomas };
49 3efd8e31 2022-10-23 thomas
50 3efd8e31 2022-10-23 thomas struct gotd_child_proc {
51 3efd8e31 2022-10-23 thomas pid_t pid;
52 3efd8e31 2022-10-23 thomas enum gotd_procid type;
53 3efd8e31 2022-10-23 thomas char repo_name[NAME_MAX];
54 414e37cb 2022-12-30 thomas char repo_path[PATH_MAX];
55 3efd8e31 2022-10-23 thomas int pipe[2];
56 3efd8e31 2022-10-23 thomas struct gotd_imsgev iev;
57 3efd8e31 2022-10-23 thomas size_t nhelpers;
58 729a7e24 2022-11-17 thomas };
59 729a7e24 2022-11-17 thomas
60 729a7e24 2022-11-17 thomas enum gotd_access {
61 729a7e24 2022-11-17 thomas GOTD_ACCESS_PERMITTED = 1,
62 729a7e24 2022-11-17 thomas GOTD_ACCESS_DENIED
63 729a7e24 2022-11-17 thomas };
64 729a7e24 2022-11-17 thomas
65 729a7e24 2022-11-17 thomas struct gotd_access_rule {
66 729a7e24 2022-11-17 thomas STAILQ_ENTRY(gotd_access_rule) entry;
67 729a7e24 2022-11-17 thomas
68 729a7e24 2022-11-17 thomas enum gotd_access access;
69 729a7e24 2022-11-17 thomas
70 729a7e24 2022-11-17 thomas int authorization;
71 729a7e24 2022-11-17 thomas #define GOTD_AUTH_READ 0x1
72 729a7e24 2022-11-17 thomas #define GOTD_AUTH_WRITE 0x2
73 729a7e24 2022-11-17 thomas
74 729a7e24 2022-11-17 thomas char *identifier;
75 3efd8e31 2022-10-23 thomas };
76 729a7e24 2022-11-17 thomas STAILQ_HEAD(gotd_access_rule_list, gotd_access_rule);
77 3efd8e31 2022-10-23 thomas
78 3efd8e31 2022-10-23 thomas struct gotd_repo {
79 3efd8e31 2022-10-23 thomas TAILQ_ENTRY(gotd_repo) entry;
80 3efd8e31 2022-10-23 thomas
81 3efd8e31 2022-10-23 thomas char name[NAME_MAX];
82 3efd8e31 2022-10-23 thomas char path[PATH_MAX];
83 729a7e24 2022-11-17 thomas
84 729a7e24 2022-11-17 thomas struct gotd_access_rule_list rules;
85 3efd8e31 2022-10-23 thomas };
86 3efd8e31 2022-10-23 thomas TAILQ_HEAD(gotd_repolist, gotd_repo);
87 3efd8e31 2022-10-23 thomas
88 3efd8e31 2022-10-23 thomas enum gotd_client_state {
89 3efd8e31 2022-10-23 thomas GOTD_STATE_EXPECT_LIST_REFS,
90 3efd8e31 2022-10-23 thomas GOTD_STATE_EXPECT_CAPABILITIES,
91 3efd8e31 2022-10-23 thomas GOTD_STATE_EXPECT_WANT,
92 3efd8e31 2022-10-23 thomas GOTD_STATE_EXPECT_REF_UPDATE,
93 3efd8e31 2022-10-23 thomas GOTD_STATE_EXPECT_MORE_REF_UPDATES,
94 3efd8e31 2022-10-23 thomas GOTD_STATE_EXPECT_HAVE,
95 3efd8e31 2022-10-23 thomas GOTD_STATE_EXPECT_PACKFILE,
96 3efd8e31 2022-10-23 thomas GOTD_STATE_EXPECT_DONE,
97 3efd8e31 2022-10-23 thomas GOTD_STATE_DONE,
98 3efd8e31 2022-10-23 thomas };
99 3efd8e31 2022-10-23 thomas
100 3efd8e31 2022-10-23 thomas struct gotd_client_capability {
101 3efd8e31 2022-10-23 thomas char *key;
102 3efd8e31 2022-10-23 thomas char *value;
103 3efd8e31 2022-10-23 thomas };
104 3efd8e31 2022-10-23 thomas
105 3efd8e31 2022-10-23 thomas struct gotd_object_id_array {
106 3efd8e31 2022-10-23 thomas struct got_object_id **ids;
107 3efd8e31 2022-10-23 thomas size_t nalloc;
108 3efd8e31 2022-10-23 thomas size_t nids;
109 3efd8e31 2022-10-23 thomas };
110 3efd8e31 2022-10-23 thomas
111 3efd8e31 2022-10-23 thomas struct gotd {
112 3efd8e31 2022-10-23 thomas pid_t pid;
113 3efd8e31 2022-10-23 thomas char unix_socket_path[PATH_MAX];
114 3efd8e31 2022-10-23 thomas char unix_group_name[32];
115 3efd8e31 2022-10-23 thomas char user_name[32];
116 3efd8e31 2022-10-23 thomas struct gotd_repolist repos;
117 3efd8e31 2022-10-23 thomas int nrepos;
118 85b37c72 2022-12-30 thomas struct gotd_child_proc listen_proc;
119 85b37c72 2022-12-30 thomas
120 85b37c72 2022-12-30 thomas char *argv0;
121 85b37c72 2022-12-30 thomas const char *confpath;
122 85b37c72 2022-12-30 thomas int daemonize;
123 3efd8e31 2022-10-23 thomas int verbosity;
124 3efd8e31 2022-10-23 thomas };
125 3efd8e31 2022-10-23 thomas
126 3efd8e31 2022-10-23 thomas enum gotd_imsg_type {
127 3efd8e31 2022-10-23 thomas /* An error occured while processing a request. */
128 3efd8e31 2022-10-23 thomas GOTD_IMSG_ERROR,
129 3efd8e31 2022-10-23 thomas
130 c902213d 2022-10-29 thomas /* Commands used by gotctl(8). */
131 c902213d 2022-10-29 thomas GOTD_IMSG_INFO,
132 c902213d 2022-10-29 thomas GOTD_IMSG_INFO_REPO,
133 c902213d 2022-10-29 thomas GOTD_IMSG_INFO_CLIENT,
134 c902213d 2022-10-29 thomas GOTD_IMSG_STOP,
135 c902213d 2022-10-29 thomas
136 3efd8e31 2022-10-23 thomas /* Request a list of references. */
137 3efd8e31 2022-10-23 thomas GOTD_IMSG_LIST_REFS,
138 3efd8e31 2022-10-23 thomas GOTD_IMSG_LIST_REFS_INTERNAL,
139 3efd8e31 2022-10-23 thomas
140 3efd8e31 2022-10-23 thomas /* References. */
141 3efd8e31 2022-10-23 thomas GOTD_IMSG_REFLIST,
142 3efd8e31 2022-10-23 thomas GOTD_IMSG_REF,
143 3efd8e31 2022-10-23 thomas GOTD_IMSG_SYMREF,
144 3efd8e31 2022-10-23 thomas
145 3efd8e31 2022-10-23 thomas /* Git protocol capabilities. */
146 3efd8e31 2022-10-23 thomas GOTD_IMSG_CAPABILITIES,
147 3efd8e31 2022-10-23 thomas GOTD_IMSG_CAPABILITY,
148 3efd8e31 2022-10-23 thomas
149 3efd8e31 2022-10-23 thomas /* Git protocol chatter. */
150 3efd8e31 2022-10-23 thomas GOTD_IMSG_WANT, /* The client wants an object. */
151 3efd8e31 2022-10-23 thomas GOTD_IMSG_HAVE, /* The client has an object. */
152 3efd8e31 2022-10-23 thomas GOTD_IMSG_ACK, /* The server has an object or a reference. */
153 3efd8e31 2022-10-23 thomas GOTD_IMSG_NAK, /* The server does not have an object/ref. */
154 3efd8e31 2022-10-23 thomas GOTD_IMSG_REF_UPDATE, /* The client wants to update a reference. */
155 3efd8e31 2022-10-23 thomas GOTD_IMSG_REF_DELETE, /* The client wants to delete a reference. */
156 3efd8e31 2022-10-23 thomas GOTD_IMSG_FLUSH, /* The client sent a flush packet. */
157 3efd8e31 2022-10-23 thomas GOTD_IMSG_DONE, /* The client is done chatting. */
158 3efd8e31 2022-10-23 thomas
159 3efd8e31 2022-10-23 thomas /* Sending or receiving a pack file. */
160 3efd8e31 2022-10-23 thomas GOTD_IMSG_SEND_PACKFILE, /* The server is sending a pack file. */
161 3efd8e31 2022-10-23 thomas GOTD_IMSG_RECV_PACKFILE, /* The server is receiving a pack file. */
162 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKIDX_FILE, /* Temporary file handle for new pack index. */
163 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKFILE_PIPE, /* Pipe to send/receive a pack file stream. */
164 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKFILE_PROGRESS, /* Progress reporting. */
165 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKFILE_READY, /* Pack file is ready to be sent. */
166 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKFILE_STATUS, /* Received pack success/failure status. */
167 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKFILE_INSTALL, /* Received pack file can be installed. */
168 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKFILE_DONE, /* Pack file has been sent/received. */
169 3efd8e31 2022-10-23 thomas
170 3efd8e31 2022-10-23 thomas /* Reference updates. */
171 3efd8e31 2022-10-23 thomas GOTD_IMSG_REF_UPDATES_START, /* Ref updates starting. */
172 3efd8e31 2022-10-23 thomas GOTD_IMSG_REF_UPDATE_OK, /* Update went OK. */
173 3efd8e31 2022-10-23 thomas GOTD_IMSG_REF_UPDATE_NG, /* Update was not good. */
174 3efd8e31 2022-10-23 thomas GOTD_IMSG_REFS_UPDATED, /* The server proccessed all ref updates. */
175 3efd8e31 2022-10-23 thomas
176 2b3d32a1 2022-12-30 thomas /* Client connections. */
177 3efd8e31 2022-10-23 thomas GOTD_IMSG_DISCONNECT,
178 2b3d32a1 2022-12-30 thomas GOTD_IMSG_CONNECT,
179 85b37c72 2022-12-30 thomas
180 85b37c72 2022-12-30 thomas /* Child process management. */
181 85b37c72 2022-12-30 thomas GOTD_IMSG_REPO_CHILD_READY,
182 c669c489 2022-12-30 thomas
183 c669c489 2022-12-30 thomas /* Auth child process. */
184 c669c489 2022-12-30 thomas GOTD_IMSG_AUTHENTICATE,
185 c669c489 2022-12-30 thomas GOTD_IMSG_ACCESS_GRANTED,
186 3efd8e31 2022-10-23 thomas };
187 3efd8e31 2022-10-23 thomas
188 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_ERROR. */
189 3efd8e31 2022-10-23 thomas struct gotd_imsg_error {
190 3efd8e31 2022-10-23 thomas int code; /* an error code from got_error.h */
191 3efd8e31 2022-10-23 thomas int errno_code; /* in case code equals GOT_ERR_ERRNO */
192 3efd8e31 2022-10-23 thomas uint32_t client_id;
193 3efd8e31 2022-10-23 thomas char msg[GOT_ERR_MAX_MSG_SIZE];
194 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
195 3efd8e31 2022-10-23 thomas
196 c902213d 2022-10-29 thomas /* Structure for GOTD_IMSG_INFO. */
197 c902213d 2022-10-29 thomas struct gotd_imsg_info {
198 c902213d 2022-10-29 thomas pid_t pid;
199 c902213d 2022-10-29 thomas int verbosity;
200 c902213d 2022-10-29 thomas int nrepos;
201 c902213d 2022-10-29 thomas int nclients;
202 c902213d 2022-10-29 thomas
203 c902213d 2022-10-29 thomas /* Followed by nrepos GOTD_IMSG_INFO_REPO messages. */
204 c902213d 2022-10-29 thomas /* Followed by nclients GOTD_IMSG_INFO_CLIENT messages. */
205 c902213d 2022-10-29 thomas };
206 c902213d 2022-10-29 thomas
207 c902213d 2022-10-29 thomas /* Structure for GOTD_IMSG_INFO_REPO. */
208 c902213d 2022-10-29 thomas struct gotd_imsg_info_repo {
209 c902213d 2022-10-29 thomas char repo_name[NAME_MAX];
210 c902213d 2022-10-29 thomas char repo_path[PATH_MAX];
211 c902213d 2022-10-29 thomas };
212 c902213d 2022-10-29 thomas
213 c902213d 2022-10-29 thomas /* Structure for GOTD_IMSG_INFO_CLIENT */
214 c902213d 2022-10-29 thomas struct gotd_imsg_info_client {
215 c902213d 2022-10-29 thomas uid_t euid;
216 c902213d 2022-10-29 thomas gid_t egid;
217 c902213d 2022-10-29 thomas char repo_name[NAME_MAX];
218 c902213d 2022-10-29 thomas int is_writing;
219 c902213d 2022-10-29 thomas enum gotd_client_state state;
220 c902213d 2022-10-29 thomas size_t ncapabilities;
221 c902213d 2022-10-29 thomas
222 c902213d 2022-10-29 thomas /* Followed by ncapabilities GOTD_IMSG_CAPABILITY. */
223 c902213d 2022-10-29 thomas };
224 c902213d 2022-10-29 thomas
225 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_LIST_REFS. */
226 3efd8e31 2022-10-23 thomas struct gotd_imsg_list_refs {
227 3efd8e31 2022-10-23 thomas char repo_name[NAME_MAX];
228 3efd8e31 2022-10-23 thomas int client_is_reading; /* 1 if reading, 0 if writing */
229 3efd8e31 2022-10-23 thomas };
230 3efd8e31 2022-10-23 thomas
231 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_LIST_REFS_INTERNAL. */
232 3efd8e31 2022-10-23 thomas struct gotd_imsg_list_refs_internal {
233 3efd8e31 2022-10-23 thomas uint32_t client_id;
234 3efd8e31 2022-10-23 thomas };
235 3efd8e31 2022-10-23 thomas
236 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REFLIST. */
237 3efd8e31 2022-10-23 thomas struct gotd_imsg_reflist {
238 3efd8e31 2022-10-23 thomas size_t nrefs;
239 3efd8e31 2022-10-23 thomas
240 3efd8e31 2022-10-23 thomas /* Followed by nrefs times of gotd_imsg_ref/gotd_imsg_symref data. */
241 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
242 3efd8e31 2022-10-23 thomas
243 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REF data. */
244 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref {
245 3efd8e31 2022-10-23 thomas uint8_t id[SHA1_DIGEST_LENGTH];
246 3efd8e31 2022-10-23 thomas size_t name_len;
247 3efd8e31 2022-10-23 thomas /* Followed by name_len data bytes. */
248 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
249 3efd8e31 2022-10-23 thomas
250 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_SYMREF data. */
251 3efd8e31 2022-10-23 thomas struct gotd_imsg_symref {
252 3efd8e31 2022-10-23 thomas size_t name_len;
253 3efd8e31 2022-10-23 thomas size_t target_len;
254 3efd8e31 2022-10-23 thomas uint8_t target_id[SHA1_DIGEST_LENGTH];
255 3efd8e31 2022-10-23 thomas
256 3efd8e31 2022-10-23 thomas /*
257 3efd8e31 2022-10-23 thomas * Followed by name_len + target_len data bytes.
258 3efd8e31 2022-10-23 thomas */
259 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
260 3efd8e31 2022-10-23 thomas
261 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_CAPABILITIES data. */
262 3efd8e31 2022-10-23 thomas struct gotd_imsg_capabilities {
263 3efd8e31 2022-10-23 thomas size_t ncapabilities;
264 3efd8e31 2022-10-23 thomas
265 3efd8e31 2022-10-23 thomas /*
266 3efd8e31 2022-10-23 thomas * Followed by ncapabilities * GOTD_IMSG_CAPABILITY.
267 3efd8e31 2022-10-23 thomas */
268 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
269 3efd8e31 2022-10-23 thomas
270 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_CAPABILITY data. */
271 3efd8e31 2022-10-23 thomas struct gotd_imsg_capability {
272 3efd8e31 2022-10-23 thomas size_t key_len;
273 3efd8e31 2022-10-23 thomas size_t value_len;
274 3efd8e31 2022-10-23 thomas
275 3efd8e31 2022-10-23 thomas /*
276 3efd8e31 2022-10-23 thomas * Followed by key_len + value_len data bytes.
277 3efd8e31 2022-10-23 thomas */
278 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
279 3efd8e31 2022-10-23 thomas
280 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_WANT data. */
281 3efd8e31 2022-10-23 thomas struct gotd_imsg_want {
282 3efd8e31 2022-10-23 thomas uint8_t object_id[SHA1_DIGEST_LENGTH];
283 3efd8e31 2022-10-23 thomas uint32_t client_id;
284 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
285 3efd8e31 2022-10-23 thomas
286 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_HAVE data. */
287 3efd8e31 2022-10-23 thomas struct gotd_imsg_have {
288 3efd8e31 2022-10-23 thomas uint8_t object_id[SHA1_DIGEST_LENGTH];
289 3efd8e31 2022-10-23 thomas uint32_t client_id;
290 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
291 3efd8e31 2022-10-23 thomas
292 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_ACK data. */
293 3efd8e31 2022-10-23 thomas struct gotd_imsg_ack {
294 3efd8e31 2022-10-23 thomas uint8_t object_id[SHA1_DIGEST_LENGTH];
295 3efd8e31 2022-10-23 thomas uint32_t client_id;
296 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
297 3efd8e31 2022-10-23 thomas
298 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_NAK data. */
299 3efd8e31 2022-10-23 thomas struct gotd_imsg_nak {
300 3efd8e31 2022-10-23 thomas uint8_t object_id[SHA1_DIGEST_LENGTH];
301 3efd8e31 2022-10-23 thomas uint32_t client_id;
302 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
303 3efd8e31 2022-10-23 thomas
304 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_PACKFILE_STATUS data. */
305 3efd8e31 2022-10-23 thomas struct gotd_imsg_packfile_status {
306 3efd8e31 2022-10-23 thomas size_t reason_len;
307 3efd8e31 2022-10-23 thomas
308 3efd8e31 2022-10-23 thomas /* Followed by reason_len data bytes. */
309 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
310 3efd8e31 2022-10-23 thomas
311 3efd8e31 2022-10-23 thomas
312 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REF_UPDATE data. */
313 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref_update {
314 3efd8e31 2022-10-23 thomas uint8_t old_id[SHA1_DIGEST_LENGTH];
315 3efd8e31 2022-10-23 thomas uint8_t new_id[SHA1_DIGEST_LENGTH];
316 3efd8e31 2022-10-23 thomas int ref_is_new;
317 3efd8e31 2022-10-23 thomas uint32_t client_id;
318 3efd8e31 2022-10-23 thomas size_t name_len;
319 3efd8e31 2022-10-23 thomas
320 3efd8e31 2022-10-23 thomas /* Followed by name_len data bytes. */
321 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
322 3efd8e31 2022-10-23 thomas
323 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REF_UPDATES_START data. */
324 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref_updates_start {
325 3efd8e31 2022-10-23 thomas int nref_updates;
326 3efd8e31 2022-10-23 thomas uint32_t client_id;
327 3efd8e31 2022-10-23 thomas
328 3efd8e31 2022-10-23 thomas /* Followed by nref_updates GOT_IMSG_REF_UPDATE_OK/NG messages. */
329 3efd8e31 2022-10-23 thomas };
330 3efd8e31 2022-10-23 thomas
331 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REF_UPDATE_OK data. */
332 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref_update_ok {
333 3efd8e31 2022-10-23 thomas uint8_t old_id[SHA1_DIGEST_LENGTH];
334 3efd8e31 2022-10-23 thomas uint8_t new_id[SHA1_DIGEST_LENGTH];
335 3efd8e31 2022-10-23 thomas int ref_is_new;
336 3efd8e31 2022-10-23 thomas uint32_t client_id;
337 3efd8e31 2022-10-23 thomas size_t name_len;
338 3efd8e31 2022-10-23 thomas
339 3efd8e31 2022-10-23 thomas /* Followed by name_len data bytes. */
340 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
341 3efd8e31 2022-10-23 thomas
342 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REF_UPDATE_NG data. */
343 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref_update_ng {
344 3efd8e31 2022-10-23 thomas uint8_t old_id[SHA1_DIGEST_LENGTH];
345 3efd8e31 2022-10-23 thomas uint8_t new_id[SHA1_DIGEST_LENGTH];
346 3efd8e31 2022-10-23 thomas uint32_t client_id;
347 3efd8e31 2022-10-23 thomas size_t name_len;
348 3efd8e31 2022-10-23 thomas size_t reason_len;
349 3efd8e31 2022-10-23 thomas
350 3efd8e31 2022-10-23 thomas /* Followed by name_len + reason_len data bytes. */
351 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
352 3efd8e31 2022-10-23 thomas
353 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_SEND_PACKFILE data. */
354 3efd8e31 2022-10-23 thomas struct gotd_imsg_send_packfile {
355 3efd8e31 2022-10-23 thomas uint32_t client_id;
356 3efd8e31 2022-10-23 thomas int report_progress;
357 3efd8e31 2022-10-23 thomas
358 3efd8e31 2022-10-23 thomas /* delta cache file is sent as a file descriptor */
359 3efd8e31 2022-10-23 thomas
360 3efd8e31 2022-10-23 thomas /* followed by two GOTD_IMSG_PACKFILE_PIPE messages */
361 3efd8e31 2022-10-23 thomas };
362 3efd8e31 2022-10-23 thomas
363 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_RECV_PACKFILE data. */
364 3efd8e31 2022-10-23 thomas struct gotd_imsg_recv_packfile {
365 3efd8e31 2022-10-23 thomas uint32_t client_id;
366 3efd8e31 2022-10-23 thomas int report_status;
367 3efd8e31 2022-10-23 thomas
368 3efd8e31 2022-10-23 thomas /* pack destination temp file is sent as a file descriptor */
369 3efd8e31 2022-10-23 thomas };
370 3efd8e31 2022-10-23 thomas
371 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_PACKFILE_PIPE data. */
372 3efd8e31 2022-10-23 thomas struct gotd_imsg_packfile_pipe {
373 3efd8e31 2022-10-23 thomas uint32_t client_id;
374 3efd8e31 2022-10-23 thomas };
375 3efd8e31 2022-10-23 thomas
376 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_PACKIDX_FILE data. */
377 3efd8e31 2022-10-23 thomas struct gotd_imsg_packidx_file {
378 3efd8e31 2022-10-23 thomas uint32_t client_id;
379 3efd8e31 2022-10-23 thomas };
380 3efd8e31 2022-10-23 thomas
381 3efd8e31 2022-10-23 thomas
382 3efd8e31 2022-10-23 thomas /*
383 3efd8e31 2022-10-23 thomas * Structure for GOTD_IMSG_PACKFILE_PROGRESS and
384 3efd8e31 2022-10-23 thomas * GOTD_IMSG_PACKFILE_READY data.
385 3efd8e31 2022-10-23 thomas */
386 3efd8e31 2022-10-23 thomas struct gotd_imsg_packfile_progress {
387 3efd8e31 2022-10-23 thomas uint32_t client_id;
388 3efd8e31 2022-10-23 thomas int ncolored;
389 3efd8e31 2022-10-23 thomas int nfound;
390 3efd8e31 2022-10-23 thomas int ntrees;
391 3efd8e31 2022-10-23 thomas off_t packfile_size;
392 3efd8e31 2022-10-23 thomas int ncommits;
393 3efd8e31 2022-10-23 thomas int nobj_total;
394 3efd8e31 2022-10-23 thomas int nobj_deltify;
395 3efd8e31 2022-10-23 thomas int nobj_written;
396 3efd8e31 2022-10-23 thomas };
397 3efd8e31 2022-10-23 thomas
398 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_PACKFILE_INSTALL. */
399 3efd8e31 2022-10-23 thomas struct gotd_imsg_packfile_install {
400 3efd8e31 2022-10-23 thomas uint32_t client_id;
401 3efd8e31 2022-10-23 thomas uint8_t pack_sha1[SHA1_DIGEST_LENGTH];
402 3efd8e31 2022-10-23 thomas };
403 3efd8e31 2022-10-23 thomas
404 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_PACKFILE_DONE data. */
405 3efd8e31 2022-10-23 thomas struct gotd_imsg_packfile_done {
406 3efd8e31 2022-10-23 thomas uint32_t client_id;
407 3efd8e31 2022-10-23 thomas };
408 3efd8e31 2022-10-23 thomas
409 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_DISCONNECT data. */
410 3efd8e31 2022-10-23 thomas struct gotd_imsg_disconnect {
411 3efd8e31 2022-10-23 thomas uint32_t client_id;
412 3efd8e31 2022-10-23 thomas };
413 3efd8e31 2022-10-23 thomas
414 2b3d32a1 2022-12-30 thomas /* Structure for GOTD_IMSG_CONNECT. */
415 2b3d32a1 2022-12-30 thomas struct gotd_imsg_connect {
416 2b3d32a1 2022-12-30 thomas uint32_t client_id;
417 2b3d32a1 2022-12-30 thomas };
418 2b3d32a1 2022-12-30 thomas
419 c669c489 2022-12-30 thomas /* Structure for GOTD_IMSG_AUTHENTICATE. */
420 c669c489 2022-12-30 thomas struct gotd_imsg_auth {
421 c669c489 2022-12-30 thomas uid_t euid;
422 c669c489 2022-12-30 thomas gid_t egid;
423 c669c489 2022-12-30 thomas int required_auth;
424 c669c489 2022-12-30 thomas uint32_t client_id;
425 c669c489 2022-12-30 thomas };
426 c669c489 2022-12-30 thomas
427 3efd8e31 2022-10-23 thomas int parse_config(const char *, enum gotd_procid, struct gotd *);
428 3efd8e31 2022-10-23 thomas
429 3efd8e31 2022-10-23 thomas /* imsg.c */
430 3efd8e31 2022-10-23 thomas const struct got_error *gotd_imsg_flush(struct imsgbuf *);
431 3efd8e31 2022-10-23 thomas const struct got_error *gotd_imsg_recv(struct imsg *, struct imsgbuf *, size_t);
432 3efd8e31 2022-10-23 thomas const struct got_error *gotd_imsg_poll_recv(struct imsg *, struct imsgbuf *,
433 3efd8e31 2022-10-23 thomas size_t);
434 3efd8e31 2022-10-23 thomas const struct got_error *gotd_imsg_recv_error(uint32_t *client_id,
435 3efd8e31 2022-10-23 thomas struct imsg *imsg);
436 3efd8e31 2022-10-23 thomas int gotd_imsg_send_error(struct imsgbuf *ibuf, uint32_t, uint32_t,
437 3efd8e31 2022-10-23 thomas const struct got_error *);
438 3efd8e31 2022-10-23 thomas int gotd_imsg_send_error_event(struct gotd_imsgev *, uint32_t, uint32_t,
439 3efd8e31 2022-10-23 thomas const struct got_error *);
440 3efd8e31 2022-10-23 thomas void gotd_imsg_event_add(struct gotd_imsgev *);
441 3efd8e31 2022-10-23 thomas int gotd_imsg_compose_event(struct gotd_imsgev *, uint16_t, uint32_t, int,
442 3efd8e31 2022-10-23 thomas void *, uint16_t);
443 3efd8e31 2022-10-23 thomas int gotd_imsg_forward(struct gotd_imsgev *, struct imsg *, int);
444 3efd8e31 2022-10-23 thomas
445 3efd8e31 2022-10-23 thomas void gotd_imsg_send_ack(struct got_object_id *, struct imsgbuf *,
446 3efd8e31 2022-10-23 thomas uint32_t, pid_t);
447 3efd8e31 2022-10-23 thomas void gotd_imsg_send_nak(struct got_object_id *, struct imsgbuf *,
448 3efd8e31 2022-10-23 thomas uint32_t, pid_t);