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