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