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