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 3efd8e31 2022-10-23 thomas struct gotd_client_capability {
138 3efd8e31 2022-10-23 thomas char *key;
139 3efd8e31 2022-10-23 thomas char *value;
140 3efd8e31 2022-10-23 thomas };
141 3efd8e31 2022-10-23 thomas
142 3efd8e31 2022-10-23 thomas struct gotd_object_id_array {
143 3efd8e31 2022-10-23 thomas struct got_object_id **ids;
144 3efd8e31 2022-10-23 thomas size_t nalloc;
145 3efd8e31 2022-10-23 thomas size_t nids;
146 3efd8e31 2022-10-23 thomas };
147 3efd8e31 2022-10-23 thomas
148 0781db0e 2023-01-06 thomas struct gotd_uid_connection_limit {
149 0781db0e 2023-01-06 thomas uid_t uid;
150 0781db0e 2023-01-06 thomas int max_connections;
151 0781db0e 2023-01-06 thomas };
152 78943464 2023-06-22 thomas
153 78943464 2023-06-22 thomas struct gotd_child_proc;
154 0781db0e 2023-01-06 thomas
155 3efd8e31 2022-10-23 thomas struct gotd {
156 3efd8e31 2022-10-23 thomas pid_t pid;
157 3efd8e31 2022-10-23 thomas char unix_socket_path[PATH_MAX];
158 3efd8e31 2022-10-23 thomas char user_name[32];
159 3efd8e31 2022-10-23 thomas struct gotd_repolist repos;
160 3efd8e31 2022-10-23 thomas int nrepos;
161 78943464 2023-06-22 thomas struct gotd_child_proc *listen_proc;
162 ce1bfad9 2024-03-30 thomas struct gotd_child_proc *notify_proc;
163 ce1bfad9 2024-03-30 thomas int notifications_enabled;
164 0781db0e 2023-01-06 thomas struct timeval request_timeout;
165 0781db0e 2023-01-06 thomas struct timeval auth_timeout;
166 0781db0e 2023-01-06 thomas struct gotd_uid_connection_limit *connection_limits;
167 0781db0e 2023-01-06 thomas size_t nconnection_limits;
168 85b37c72 2022-12-30 thomas
169 85b37c72 2022-12-30 thomas char *argv0;
170 85b37c72 2022-12-30 thomas const char *confpath;
171 85b37c72 2022-12-30 thomas int daemonize;
172 3efd8e31 2022-10-23 thomas int verbosity;
173 3efd8e31 2022-10-23 thomas };
174 3efd8e31 2022-10-23 thomas
175 3efd8e31 2022-10-23 thomas enum gotd_imsg_type {
176 3efd8e31 2022-10-23 thomas /* An error occured while processing a request. */
177 3efd8e31 2022-10-23 thomas GOTD_IMSG_ERROR,
178 3efd8e31 2022-10-23 thomas
179 c902213d 2022-10-29 thomas /* Commands used by gotctl(8). */
180 c902213d 2022-10-29 thomas GOTD_IMSG_INFO,
181 c902213d 2022-10-29 thomas GOTD_IMSG_INFO_REPO,
182 c902213d 2022-10-29 thomas GOTD_IMSG_INFO_CLIENT,
183 c902213d 2022-10-29 thomas GOTD_IMSG_STOP,
184 c902213d 2022-10-29 thomas
185 3efd8e31 2022-10-23 thomas /* Request a list of references. */
186 3efd8e31 2022-10-23 thomas GOTD_IMSG_LIST_REFS,
187 3efd8e31 2022-10-23 thomas GOTD_IMSG_LIST_REFS_INTERNAL,
188 3efd8e31 2022-10-23 thomas
189 3efd8e31 2022-10-23 thomas /* References. */
190 3efd8e31 2022-10-23 thomas GOTD_IMSG_REFLIST,
191 3efd8e31 2022-10-23 thomas GOTD_IMSG_REF,
192 3efd8e31 2022-10-23 thomas GOTD_IMSG_SYMREF,
193 3efd8e31 2022-10-23 thomas
194 3efd8e31 2022-10-23 thomas /* Git protocol capabilities. */
195 3efd8e31 2022-10-23 thomas GOTD_IMSG_CAPABILITIES,
196 3efd8e31 2022-10-23 thomas GOTD_IMSG_CAPABILITY,
197 3efd8e31 2022-10-23 thomas
198 3efd8e31 2022-10-23 thomas /* Git protocol chatter. */
199 3efd8e31 2022-10-23 thomas GOTD_IMSG_WANT, /* The client wants an object. */
200 3efd8e31 2022-10-23 thomas GOTD_IMSG_HAVE, /* The client has an object. */
201 3efd8e31 2022-10-23 thomas GOTD_IMSG_ACK, /* The server has an object or a reference. */
202 3efd8e31 2022-10-23 thomas GOTD_IMSG_NAK, /* The server does not have an object/ref. */
203 3efd8e31 2022-10-23 thomas GOTD_IMSG_REF_UPDATE, /* The client wants to update a reference. */
204 3efd8e31 2022-10-23 thomas GOTD_IMSG_REF_DELETE, /* The client wants to delete a reference. */
205 3efd8e31 2022-10-23 thomas GOTD_IMSG_FLUSH, /* The client sent a flush packet. */
206 3efd8e31 2022-10-23 thomas GOTD_IMSG_DONE, /* The client is done chatting. */
207 3efd8e31 2022-10-23 thomas
208 3efd8e31 2022-10-23 thomas /* Sending or receiving a pack file. */
209 3efd8e31 2022-10-23 thomas GOTD_IMSG_SEND_PACKFILE, /* The server is sending a pack file. */
210 3efd8e31 2022-10-23 thomas GOTD_IMSG_RECV_PACKFILE, /* The server is receiving a pack file. */
211 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKIDX_FILE, /* Temporary file handle for new pack index. */
212 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKFILE_PIPE, /* Pipe to send/receive a pack file stream. */
213 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKFILE_PROGRESS, /* Progress reporting. */
214 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKFILE_READY, /* Pack file is ready to be sent. */
215 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKFILE_STATUS, /* Received pack success/failure status. */
216 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKFILE_INSTALL, /* Received pack file can be installed. */
217 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKFILE_DONE, /* Pack file has been sent/received. */
218 3efd8e31 2022-10-23 thomas
219 3efd8e31 2022-10-23 thomas /* Reference updates. */
220 3efd8e31 2022-10-23 thomas GOTD_IMSG_REF_UPDATES_START, /* Ref updates starting. */
221 3efd8e31 2022-10-23 thomas GOTD_IMSG_REF_UPDATE_OK, /* Update went OK. */
222 3efd8e31 2022-10-23 thomas GOTD_IMSG_REF_UPDATE_NG, /* Update was not good. */
223 3efd8e31 2022-10-23 thomas GOTD_IMSG_REFS_UPDATED, /* The server proccessed all ref updates. */
224 3efd8e31 2022-10-23 thomas
225 2b3d32a1 2022-12-30 thomas /* Client connections. */
226 3efd8e31 2022-10-23 thomas GOTD_IMSG_DISCONNECT,
227 2b3d32a1 2022-12-30 thomas GOTD_IMSG_CONNECT,
228 85b37c72 2022-12-30 thomas
229 85b37c72 2022-12-30 thomas /* Child process management. */
230 62ee7d94 2023-01-10 thomas GOTD_IMSG_CLIENT_SESSION_READY,
231 85b37c72 2022-12-30 thomas GOTD_IMSG_REPO_CHILD_READY,
232 62ee7d94 2023-01-10 thomas GOTD_IMSG_CONNECT_REPO_CHILD,
233 c669c489 2022-12-30 thomas
234 c669c489 2022-12-30 thomas /* Auth child process. */
235 c669c489 2022-12-30 thomas GOTD_IMSG_AUTHENTICATE,
236 c669c489 2022-12-30 thomas GOTD_IMSG_ACCESS_GRANTED,
237 ce1bfad9 2024-03-30 thomas
238 ce1bfad9 2024-03-30 thomas /* Notify child process. */
239 ce1bfad9 2024-03-30 thomas GOTD_IMSG_CONNECT_NOTIFIER,
240 ce1bfad9 2024-03-30 thomas GOTD_IMSG_CONNECT_SESSION,
241 ce1bfad9 2024-03-30 thomas GOTD_IMSG_NOTIFY,
242 ce1bfad9 2024-03-30 thomas GOTD_IMSG_NOTIFICATION_SENT
243 3efd8e31 2022-10-23 thomas };
244 3efd8e31 2022-10-23 thomas
245 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_ERROR. */
246 3efd8e31 2022-10-23 thomas struct gotd_imsg_error {
247 3efd8e31 2022-10-23 thomas int code; /* an error code from got_error.h */
248 3efd8e31 2022-10-23 thomas int errno_code; /* in case code equals GOT_ERR_ERRNO */
249 3efd8e31 2022-10-23 thomas uint32_t client_id;
250 3efd8e31 2022-10-23 thomas char msg[GOT_ERR_MAX_MSG_SIZE];
251 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
252 3efd8e31 2022-10-23 thomas
253 c902213d 2022-10-29 thomas /* Structure for GOTD_IMSG_INFO. */
254 c902213d 2022-10-29 thomas struct gotd_imsg_info {
255 c902213d 2022-10-29 thomas pid_t pid;
256 c902213d 2022-10-29 thomas int verbosity;
257 c902213d 2022-10-29 thomas int nrepos;
258 c902213d 2022-10-29 thomas int nclients;
259 c902213d 2022-10-29 thomas
260 c902213d 2022-10-29 thomas /* Followed by nrepos GOTD_IMSG_INFO_REPO messages. */
261 c902213d 2022-10-29 thomas /* Followed by nclients GOTD_IMSG_INFO_CLIENT messages. */
262 c902213d 2022-10-29 thomas };
263 c902213d 2022-10-29 thomas
264 c902213d 2022-10-29 thomas /* Structure for GOTD_IMSG_INFO_REPO. */
265 c902213d 2022-10-29 thomas struct gotd_imsg_info_repo {
266 c902213d 2022-10-29 thomas char repo_name[NAME_MAX];
267 c902213d 2022-10-29 thomas char repo_path[PATH_MAX];
268 c902213d 2022-10-29 thomas };
269 c902213d 2022-10-29 thomas
270 c902213d 2022-10-29 thomas /* Structure for GOTD_IMSG_INFO_CLIENT */
271 c902213d 2022-10-29 thomas struct gotd_imsg_info_client {
272 c902213d 2022-10-29 thomas uid_t euid;
273 c902213d 2022-10-29 thomas gid_t egid;
274 c902213d 2022-10-29 thomas char repo_name[NAME_MAX];
275 c902213d 2022-10-29 thomas int is_writing;
276 62ee7d94 2023-01-10 thomas pid_t session_child_pid;
277 62ee7d94 2023-01-10 thomas pid_t repo_child_pid;
278 c902213d 2022-10-29 thomas };
279 c902213d 2022-10-29 thomas
280 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_LIST_REFS. */
281 3efd8e31 2022-10-23 thomas struct gotd_imsg_list_refs {
282 3efd8e31 2022-10-23 thomas char repo_name[NAME_MAX];
283 3efd8e31 2022-10-23 thomas int client_is_reading; /* 1 if reading, 0 if writing */
284 3efd8e31 2022-10-23 thomas };
285 3efd8e31 2022-10-23 thomas
286 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REFLIST. */
287 3efd8e31 2022-10-23 thomas struct gotd_imsg_reflist {
288 3efd8e31 2022-10-23 thomas size_t nrefs;
289 3efd8e31 2022-10-23 thomas
290 3efd8e31 2022-10-23 thomas /* Followed by nrefs times of gotd_imsg_ref/gotd_imsg_symref data. */
291 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
292 3efd8e31 2022-10-23 thomas
293 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REF data. */
294 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref {
295 3efd8e31 2022-10-23 thomas uint8_t id[SHA1_DIGEST_LENGTH];
296 3efd8e31 2022-10-23 thomas size_t name_len;
297 3efd8e31 2022-10-23 thomas /* Followed by name_len data bytes. */
298 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
299 3efd8e31 2022-10-23 thomas
300 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_SYMREF data. */
301 3efd8e31 2022-10-23 thomas struct gotd_imsg_symref {
302 3efd8e31 2022-10-23 thomas size_t name_len;
303 3efd8e31 2022-10-23 thomas size_t target_len;
304 3efd8e31 2022-10-23 thomas uint8_t target_id[SHA1_DIGEST_LENGTH];
305 3efd8e31 2022-10-23 thomas
306 3efd8e31 2022-10-23 thomas /*
307 3efd8e31 2022-10-23 thomas * Followed by name_len + target_len data bytes.
308 3efd8e31 2022-10-23 thomas */
309 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
310 3efd8e31 2022-10-23 thomas
311 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_CAPABILITIES data. */
312 3efd8e31 2022-10-23 thomas struct gotd_imsg_capabilities {
313 3efd8e31 2022-10-23 thomas size_t ncapabilities;
314 3efd8e31 2022-10-23 thomas
315 3efd8e31 2022-10-23 thomas /*
316 3efd8e31 2022-10-23 thomas * Followed by ncapabilities * GOTD_IMSG_CAPABILITY.
317 3efd8e31 2022-10-23 thomas */
318 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
319 3efd8e31 2022-10-23 thomas
320 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_CAPABILITY data. */
321 3efd8e31 2022-10-23 thomas struct gotd_imsg_capability {
322 3efd8e31 2022-10-23 thomas size_t key_len;
323 3efd8e31 2022-10-23 thomas size_t value_len;
324 3efd8e31 2022-10-23 thomas
325 3efd8e31 2022-10-23 thomas /*
326 3efd8e31 2022-10-23 thomas * Followed by key_len + value_len data bytes.
327 3efd8e31 2022-10-23 thomas */
328 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
329 3efd8e31 2022-10-23 thomas
330 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_WANT data. */
331 3efd8e31 2022-10-23 thomas struct gotd_imsg_want {
332 3efd8e31 2022-10-23 thomas uint8_t object_id[SHA1_DIGEST_LENGTH];
333 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
334 3efd8e31 2022-10-23 thomas
335 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_HAVE data. */
336 3efd8e31 2022-10-23 thomas struct gotd_imsg_have {
337 3efd8e31 2022-10-23 thomas uint8_t object_id[SHA1_DIGEST_LENGTH];
338 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
339 3efd8e31 2022-10-23 thomas
340 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_ACK data. */
341 3efd8e31 2022-10-23 thomas struct gotd_imsg_ack {
342 3efd8e31 2022-10-23 thomas uint8_t object_id[SHA1_DIGEST_LENGTH];
343 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
344 3efd8e31 2022-10-23 thomas
345 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_NAK data. */
346 3efd8e31 2022-10-23 thomas struct gotd_imsg_nak {
347 3efd8e31 2022-10-23 thomas uint8_t object_id[SHA1_DIGEST_LENGTH];
348 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
349 3efd8e31 2022-10-23 thomas
350 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_PACKFILE_STATUS data. */
351 3efd8e31 2022-10-23 thomas struct gotd_imsg_packfile_status {
352 3efd8e31 2022-10-23 thomas size_t reason_len;
353 3efd8e31 2022-10-23 thomas
354 3efd8e31 2022-10-23 thomas /* Followed by reason_len data bytes. */
355 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
356 3efd8e31 2022-10-23 thomas
357 3efd8e31 2022-10-23 thomas
358 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REF_UPDATE data. */
359 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref_update {
360 3efd8e31 2022-10-23 thomas uint8_t old_id[SHA1_DIGEST_LENGTH];
361 3efd8e31 2022-10-23 thomas uint8_t new_id[SHA1_DIGEST_LENGTH];
362 3efd8e31 2022-10-23 thomas int ref_is_new;
363 49563dfb 2023-01-28 thomas int delete_ref;
364 3efd8e31 2022-10-23 thomas size_t name_len;
365 3efd8e31 2022-10-23 thomas
366 3efd8e31 2022-10-23 thomas /* Followed by name_len data bytes. */
367 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
368 3efd8e31 2022-10-23 thomas
369 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REF_UPDATES_START data. */
370 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref_updates_start {
371 3efd8e31 2022-10-23 thomas int nref_updates;
372 3efd8e31 2022-10-23 thomas
373 3efd8e31 2022-10-23 thomas /* Followed by nref_updates GOT_IMSG_REF_UPDATE_OK/NG messages. */
374 3efd8e31 2022-10-23 thomas };
375 3efd8e31 2022-10-23 thomas
376 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REF_UPDATE_OK data. */
377 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref_update_ok {
378 3efd8e31 2022-10-23 thomas uint8_t old_id[SHA1_DIGEST_LENGTH];
379 3efd8e31 2022-10-23 thomas uint8_t new_id[SHA1_DIGEST_LENGTH];
380 3efd8e31 2022-10-23 thomas int ref_is_new;
381 3efd8e31 2022-10-23 thomas size_t name_len;
382 3efd8e31 2022-10-23 thomas
383 3efd8e31 2022-10-23 thomas /* Followed by name_len data bytes. */
384 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
385 3efd8e31 2022-10-23 thomas
386 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REF_UPDATE_NG data. */
387 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref_update_ng {
388 3efd8e31 2022-10-23 thomas uint8_t old_id[SHA1_DIGEST_LENGTH];
389 3efd8e31 2022-10-23 thomas uint8_t new_id[SHA1_DIGEST_LENGTH];
390 3efd8e31 2022-10-23 thomas size_t name_len;
391 3efd8e31 2022-10-23 thomas size_t reason_len;
392 3efd8e31 2022-10-23 thomas
393 3efd8e31 2022-10-23 thomas /* Followed by name_len + reason_len data bytes. */
394 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
395 3efd8e31 2022-10-23 thomas
396 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_SEND_PACKFILE data. */
397 3efd8e31 2022-10-23 thomas struct gotd_imsg_send_packfile {
398 3efd8e31 2022-10-23 thomas int report_progress;
399 3efd8e31 2022-10-23 thomas
400 3efd8e31 2022-10-23 thomas /* delta cache file is sent as a file descriptor */
401 3efd8e31 2022-10-23 thomas
402 3efd8e31 2022-10-23 thomas /* followed by two GOTD_IMSG_PACKFILE_PIPE messages */
403 3efd8e31 2022-10-23 thomas };
404 3efd8e31 2022-10-23 thomas
405 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_RECV_PACKFILE data. */
406 3efd8e31 2022-10-23 thomas struct gotd_imsg_recv_packfile {
407 3efd8e31 2022-10-23 thomas int report_status;
408 3efd8e31 2022-10-23 thomas
409 3efd8e31 2022-10-23 thomas /* pack destination temp file is sent as a file descriptor */
410 3efd8e31 2022-10-23 thomas };
411 3efd8e31 2022-10-23 thomas
412 3efd8e31 2022-10-23 thomas /*
413 3efd8e31 2022-10-23 thomas * Structure for GOTD_IMSG_PACKFILE_PROGRESS and
414 3efd8e31 2022-10-23 thomas * GOTD_IMSG_PACKFILE_READY data.
415 3efd8e31 2022-10-23 thomas */
416 3efd8e31 2022-10-23 thomas struct gotd_imsg_packfile_progress {
417 3efd8e31 2022-10-23 thomas int ncolored;
418 3efd8e31 2022-10-23 thomas int nfound;
419 3efd8e31 2022-10-23 thomas int ntrees;
420 3efd8e31 2022-10-23 thomas off_t packfile_size;
421 3efd8e31 2022-10-23 thomas int ncommits;
422 3efd8e31 2022-10-23 thomas int nobj_total;
423 3efd8e31 2022-10-23 thomas int nobj_deltify;
424 3efd8e31 2022-10-23 thomas int nobj_written;
425 3efd8e31 2022-10-23 thomas };
426 3efd8e31 2022-10-23 thomas
427 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_PACKFILE_INSTALL. */
428 3efd8e31 2022-10-23 thomas struct gotd_imsg_packfile_install {
429 3efd8e31 2022-10-23 thomas uint8_t pack_sha1[SHA1_DIGEST_LENGTH];
430 3efd8e31 2022-10-23 thomas };
431 3efd8e31 2022-10-23 thomas
432 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_DISCONNECT data. */
433 3efd8e31 2022-10-23 thomas struct gotd_imsg_disconnect {
434 3efd8e31 2022-10-23 thomas uint32_t client_id;
435 3efd8e31 2022-10-23 thomas };
436 3efd8e31 2022-10-23 thomas
437 2b3d32a1 2022-12-30 thomas /* Structure for GOTD_IMSG_CONNECT. */
438 2b3d32a1 2022-12-30 thomas struct gotd_imsg_connect {
439 2b3d32a1 2022-12-30 thomas uint32_t client_id;
440 0bcde4c8 2022-12-30 thomas uid_t euid;
441 0bcde4c8 2022-12-30 thomas gid_t egid;
442 ce1bfad9 2024-03-30 thomas size_t username_len;
443 ce1bfad9 2024-03-30 thomas
444 ce1bfad9 2024-03-30 thomas /* Followed by username_len data bytes. */
445 2b3d32a1 2022-12-30 thomas };
446 2b3d32a1 2022-12-30 thomas
447 62ee7d94 2023-01-10 thomas /* Structure for GOTD_IMSG_CONNECT_REPO_CHILD. */
448 62ee7d94 2023-01-10 thomas struct gotd_imsg_connect_repo_child {
449 62ee7d94 2023-01-10 thomas enum gotd_procid proc_id;
450 62ee7d94 2023-01-10 thomas
451 62ee7d94 2023-01-10 thomas /* repo child imsg pipe is passed via imsg fd */
452 62ee7d94 2023-01-10 thomas };
453 62ee7d94 2023-01-10 thomas
454 c669c489 2022-12-30 thomas /* Structure for GOTD_IMSG_AUTHENTICATE. */
455 c669c489 2022-12-30 thomas struct gotd_imsg_auth {
456 c669c489 2022-12-30 thomas uid_t euid;
457 c669c489 2022-12-30 thomas gid_t egid;
458 c669c489 2022-12-30 thomas int required_auth;
459 c669c489 2022-12-30 thomas uint32_t client_id;
460 c669c489 2022-12-30 thomas };
461 c669c489 2022-12-30 thomas
462 ce1bfad9 2024-03-30 thomas /* Structures for GOTD_IMSG_NOTIFY. */
463 ce1bfad9 2024-03-30 thomas enum gotd_notification_action {
464 ce1bfad9 2024-03-30 thomas GOTD_NOTIF_ACTION_CREATED,
465 ce1bfad9 2024-03-30 thomas GOTD_NOTIF_ACTION_REMOVED,
466 ce1bfad9 2024-03-30 thomas GOTD_NOTIF_ACTION_CHANGED
467 ce1bfad9 2024-03-30 thomas };
468 ce1bfad9 2024-03-30 thomas /* IMSG_NOTIFY session <-> repo_write */
469 ce1bfad9 2024-03-30 thomas struct gotd_imsg_notification_content {
470 ce1bfad9 2024-03-30 thomas enum gotd_notification_action action;
471 ce1bfad9 2024-03-30 thomas uint8_t old_id[SHA1_DIGEST_LENGTH];
472 ce1bfad9 2024-03-30 thomas uint8_t new_id[SHA1_DIGEST_LENGTH];
473 ce1bfad9 2024-03-30 thomas size_t refname_len;
474 ce1bfad9 2024-03-30 thomas /* Followed by refname_len data bytes. */
475 ce1bfad9 2024-03-30 thomas };
476 ce1bfad9 2024-03-30 thomas /* IMSG_NOTIFY session -> notify*/
477 ce1bfad9 2024-03-30 thomas struct gotd_imsg_notify {
478 ce1bfad9 2024-03-30 thomas char repo_name[NAME_MAX];
479 ce1bfad9 2024-03-30 thomas char subject_line[64];
480 ce1bfad9 2024-03-30 thomas };
481 ce1bfad9 2024-03-30 thomas
482 b2ce1dae 2024-03-30 thomas int enter_chroot(const char *);
483 f3807fe5 2023-07-10 thomas int parse_config(const char *, enum gotd_procid, struct gotd *);
484 ce1bfad9 2024-03-30 thomas struct gotd_repo *gotd_find_repo_by_name(const char *, struct gotd_repolist *);
485 6d7eb4f7 2023-04-04 thomas struct gotd_repo *gotd_find_repo_by_path(const char *, struct gotd *);
486 65a36f17 2023-04-22 thomas struct gotd_uid_connection_limit *gotd_find_uid_connection_limit(
487 65a36f17 2023-04-22 thomas struct gotd_uid_connection_limit *limits, size_t nlimits, uid_t uid);
488 48488136 2023-04-22 thomas int gotd_parseuid(const char *s, uid_t *uid);
489 ce1bfad9 2024-03-30 thomas const struct got_error *gotd_parse_url(char **, char **, char **,
490 ce1bfad9 2024-03-30 thomas char **, const char *);
491 3efd8e31 2022-10-23 thomas
492 3efd8e31 2022-10-23 thomas /* imsg.c */
493 3efd8e31 2022-10-23 thomas const struct got_error *gotd_imsg_flush(struct imsgbuf *);
494 3efd8e31 2022-10-23 thomas const struct got_error *gotd_imsg_recv(struct imsg *, struct imsgbuf *, size_t);
495 3efd8e31 2022-10-23 thomas const struct got_error *gotd_imsg_poll_recv(struct imsg *, struct imsgbuf *,
496 3efd8e31 2022-10-23 thomas size_t);
497 3efd8e31 2022-10-23 thomas const struct got_error *gotd_imsg_recv_error(uint32_t *client_id,
498 3efd8e31 2022-10-23 thomas struct imsg *imsg);
499 3efd8e31 2022-10-23 thomas int gotd_imsg_send_error(struct imsgbuf *ibuf, uint32_t, uint32_t,
500 3efd8e31 2022-10-23 thomas const struct got_error *);
501 3efd8e31 2022-10-23 thomas int gotd_imsg_send_error_event(struct gotd_imsgev *, uint32_t, uint32_t,
502 3efd8e31 2022-10-23 thomas const struct got_error *);
503 3efd8e31 2022-10-23 thomas void gotd_imsg_event_add(struct gotd_imsgev *);
504 3efd8e31 2022-10-23 thomas int gotd_imsg_compose_event(struct gotd_imsgev *, uint16_t, uint32_t, int,
505 3efd8e31 2022-10-23 thomas void *, uint16_t);
506 3efd8e31 2022-10-23 thomas int gotd_imsg_forward(struct gotd_imsgev *, struct imsg *, int);
507 3efd8e31 2022-10-23 thomas
508 3efd8e31 2022-10-23 thomas void gotd_imsg_send_ack(struct got_object_id *, struct imsgbuf *,
509 3efd8e31 2022-10-23 thomas uint32_t, pid_t);
510 3efd8e31 2022-10-23 thomas void gotd_imsg_send_nak(struct got_object_id *, struct imsgbuf *,
511 3efd8e31 2022-10-23 thomas uint32_t, pid_t);