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_REFLIST. */
300 3efd8e31 2022-10-23 thomas struct gotd_imsg_reflist {
301 3efd8e31 2022-10-23 thomas size_t nrefs;
302 3efd8e31 2022-10-23 thomas
303 3efd8e31 2022-10-23 thomas /* Followed by nrefs times of gotd_imsg_ref/gotd_imsg_symref data. */
304 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
305 3efd8e31 2022-10-23 thomas
306 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REF data. */
307 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref {
308 3efd8e31 2022-10-23 thomas uint8_t id[SHA1_DIGEST_LENGTH];
309 3efd8e31 2022-10-23 thomas size_t name_len;
310 3efd8e31 2022-10-23 thomas /* Followed by name_len data bytes. */
311 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
312 3efd8e31 2022-10-23 thomas
313 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_SYMREF data. */
314 3efd8e31 2022-10-23 thomas struct gotd_imsg_symref {
315 3efd8e31 2022-10-23 thomas size_t name_len;
316 3efd8e31 2022-10-23 thomas size_t target_len;
317 3efd8e31 2022-10-23 thomas uint8_t target_id[SHA1_DIGEST_LENGTH];
318 3efd8e31 2022-10-23 thomas
319 3efd8e31 2022-10-23 thomas /*
320 3efd8e31 2022-10-23 thomas * Followed by name_len + target_len data bytes.
321 3efd8e31 2022-10-23 thomas */
322 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
323 3efd8e31 2022-10-23 thomas
324 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_CAPABILITIES data. */
325 3efd8e31 2022-10-23 thomas struct gotd_imsg_capabilities {
326 3efd8e31 2022-10-23 thomas size_t ncapabilities;
327 3efd8e31 2022-10-23 thomas
328 3efd8e31 2022-10-23 thomas /*
329 3efd8e31 2022-10-23 thomas * Followed by ncapabilities * GOTD_IMSG_CAPABILITY.
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_CAPABILITY data. */
334 3efd8e31 2022-10-23 thomas struct gotd_imsg_capability {
335 3efd8e31 2022-10-23 thomas size_t key_len;
336 3efd8e31 2022-10-23 thomas size_t value_len;
337 3efd8e31 2022-10-23 thomas
338 3efd8e31 2022-10-23 thomas /*
339 3efd8e31 2022-10-23 thomas * Followed by key_len + value_len data bytes.
340 3efd8e31 2022-10-23 thomas */
341 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
342 3efd8e31 2022-10-23 thomas
343 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_WANT data. */
344 3efd8e31 2022-10-23 thomas struct gotd_imsg_want {
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_HAVE data. */
349 3efd8e31 2022-10-23 thomas struct gotd_imsg_have {
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_ACK data. */
354 3efd8e31 2022-10-23 thomas struct gotd_imsg_ack {
355 3efd8e31 2022-10-23 thomas uint8_t object_id[SHA1_DIGEST_LENGTH];
356 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
357 3efd8e31 2022-10-23 thomas
358 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_NAK data. */
359 3efd8e31 2022-10-23 thomas struct gotd_imsg_nak {
360 3efd8e31 2022-10-23 thomas uint8_t object_id[SHA1_DIGEST_LENGTH];
361 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
362 3efd8e31 2022-10-23 thomas
363 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_PACKFILE_STATUS data. */
364 3efd8e31 2022-10-23 thomas struct gotd_imsg_packfile_status {
365 3efd8e31 2022-10-23 thomas size_t reason_len;
366 3efd8e31 2022-10-23 thomas
367 3efd8e31 2022-10-23 thomas /* Followed by reason_len data bytes. */
368 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
369 3efd8e31 2022-10-23 thomas
370 3efd8e31 2022-10-23 thomas
371 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REF_UPDATE data. */
372 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref_update {
373 3efd8e31 2022-10-23 thomas uint8_t old_id[SHA1_DIGEST_LENGTH];
374 3efd8e31 2022-10-23 thomas uint8_t new_id[SHA1_DIGEST_LENGTH];
375 3efd8e31 2022-10-23 thomas int ref_is_new;
376 49563dfb 2023-01-28 thomas int delete_ref;
377 3efd8e31 2022-10-23 thomas size_t name_len;
378 3efd8e31 2022-10-23 thomas
379 3efd8e31 2022-10-23 thomas /* Followed by name_len data bytes. */
380 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
381 3efd8e31 2022-10-23 thomas
382 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REF_UPDATES_START data. */
383 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref_updates_start {
384 3efd8e31 2022-10-23 thomas int nref_updates;
385 3efd8e31 2022-10-23 thomas
386 3efd8e31 2022-10-23 thomas /* Followed by nref_updates GOT_IMSG_REF_UPDATE_OK/NG messages. */
387 3efd8e31 2022-10-23 thomas };
388 3efd8e31 2022-10-23 thomas
389 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REF_UPDATE_OK data. */
390 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref_update_ok {
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 int ref_is_new;
394 3efd8e31 2022-10-23 thomas size_t name_len;
395 3efd8e31 2022-10-23 thomas
396 3efd8e31 2022-10-23 thomas /* Followed by name_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_REF_UPDATE_NG data. */
400 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref_update_ng {
401 3efd8e31 2022-10-23 thomas uint8_t old_id[SHA1_DIGEST_LENGTH];
402 3efd8e31 2022-10-23 thomas uint8_t new_id[SHA1_DIGEST_LENGTH];
403 3efd8e31 2022-10-23 thomas size_t name_len;
404 3efd8e31 2022-10-23 thomas size_t reason_len;
405 3efd8e31 2022-10-23 thomas
406 3efd8e31 2022-10-23 thomas /* Followed by name_len + reason_len data bytes. */
407 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
408 3efd8e31 2022-10-23 thomas
409 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_SEND_PACKFILE data. */
410 3efd8e31 2022-10-23 thomas struct gotd_imsg_send_packfile {
411 3efd8e31 2022-10-23 thomas int report_progress;
412 3efd8e31 2022-10-23 thomas
413 3efd8e31 2022-10-23 thomas /* delta cache file is sent as a file descriptor */
414 3efd8e31 2022-10-23 thomas
415 3efd8e31 2022-10-23 thomas /* followed by two GOTD_IMSG_PACKFILE_PIPE messages */
416 3efd8e31 2022-10-23 thomas };
417 3efd8e31 2022-10-23 thomas
418 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_RECV_PACKFILE data. */
419 3efd8e31 2022-10-23 thomas struct gotd_imsg_recv_packfile {
420 3efd8e31 2022-10-23 thomas int report_status;
421 3efd8e31 2022-10-23 thomas
422 3efd8e31 2022-10-23 thomas /* pack destination temp file is sent as a file descriptor */
423 3efd8e31 2022-10-23 thomas };
424 3efd8e31 2022-10-23 thomas
425 3efd8e31 2022-10-23 thomas /*
426 3efd8e31 2022-10-23 thomas * Structure for GOTD_IMSG_PACKFILE_PROGRESS and
427 3efd8e31 2022-10-23 thomas * GOTD_IMSG_PACKFILE_READY data.
428 3efd8e31 2022-10-23 thomas */
429 3efd8e31 2022-10-23 thomas struct gotd_imsg_packfile_progress {
430 3efd8e31 2022-10-23 thomas int ncolored;
431 3efd8e31 2022-10-23 thomas int nfound;
432 3efd8e31 2022-10-23 thomas int ntrees;
433 3efd8e31 2022-10-23 thomas off_t packfile_size;
434 3efd8e31 2022-10-23 thomas int ncommits;
435 3efd8e31 2022-10-23 thomas int nobj_total;
436 3efd8e31 2022-10-23 thomas int nobj_deltify;
437 3efd8e31 2022-10-23 thomas int nobj_written;
438 3efd8e31 2022-10-23 thomas };
439 3efd8e31 2022-10-23 thomas
440 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_PACKFILE_INSTALL. */
441 3efd8e31 2022-10-23 thomas struct gotd_imsg_packfile_install {
442 3efd8e31 2022-10-23 thomas uint8_t pack_sha1[SHA1_DIGEST_LENGTH];
443 3efd8e31 2022-10-23 thomas };
444 3efd8e31 2022-10-23 thomas
445 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_DISCONNECT data. */
446 3efd8e31 2022-10-23 thomas struct gotd_imsg_disconnect {
447 3efd8e31 2022-10-23 thomas uint32_t client_id;
448 3efd8e31 2022-10-23 thomas };
449 3efd8e31 2022-10-23 thomas
450 2b3d32a1 2022-12-30 thomas /* Structure for GOTD_IMSG_CONNECT. */
451 2b3d32a1 2022-12-30 thomas struct gotd_imsg_connect {
452 2b3d32a1 2022-12-30 thomas uint32_t client_id;
453 0bcde4c8 2022-12-30 thomas uid_t euid;
454 0bcde4c8 2022-12-30 thomas gid_t egid;
455 ce1bfad9 2024-03-30 thomas size_t username_len;
456 ce1bfad9 2024-03-30 thomas
457 ce1bfad9 2024-03-30 thomas /* Followed by username_len data bytes. */
458 2b3d32a1 2022-12-30 thomas };
459 2b3d32a1 2022-12-30 thomas
460 62ee7d94 2023-01-10 thomas /* Structure for GOTD_IMSG_CONNECT_REPO_CHILD. */
461 62ee7d94 2023-01-10 thomas struct gotd_imsg_connect_repo_child {
462 62ee7d94 2023-01-10 thomas enum gotd_procid proc_id;
463 62ee7d94 2023-01-10 thomas
464 62ee7d94 2023-01-10 thomas /* repo child imsg pipe is passed via imsg fd */
465 62ee7d94 2023-01-10 thomas };
466 62ee7d94 2023-01-10 thomas
467 c669c489 2022-12-30 thomas /* Structure for GOTD_IMSG_AUTHENTICATE. */
468 c669c489 2022-12-30 thomas struct gotd_imsg_auth {
469 c669c489 2022-12-30 thomas uid_t euid;
470 c669c489 2022-12-30 thomas gid_t egid;
471 c669c489 2022-12-30 thomas int required_auth;
472 c669c489 2022-12-30 thomas uint32_t client_id;
473 c669c489 2022-12-30 thomas };
474 c669c489 2022-12-30 thomas
475 ce1bfad9 2024-03-30 thomas /* Structures for GOTD_IMSG_NOTIFY. */
476 ce1bfad9 2024-03-30 thomas enum gotd_notification_action {
477 ce1bfad9 2024-03-30 thomas GOTD_NOTIF_ACTION_CREATED,
478 ce1bfad9 2024-03-30 thomas GOTD_NOTIF_ACTION_REMOVED,
479 ce1bfad9 2024-03-30 thomas GOTD_NOTIF_ACTION_CHANGED
480 ce1bfad9 2024-03-30 thomas };
481 ce1bfad9 2024-03-30 thomas /* IMSG_NOTIFY session <-> repo_write */
482 ce1bfad9 2024-03-30 thomas struct gotd_imsg_notification_content {
483 ce1bfad9 2024-03-30 thomas enum gotd_notification_action action;
484 ce1bfad9 2024-03-30 thomas uint8_t old_id[SHA1_DIGEST_LENGTH];
485 ce1bfad9 2024-03-30 thomas uint8_t new_id[SHA1_DIGEST_LENGTH];
486 ce1bfad9 2024-03-30 thomas size_t refname_len;
487 ce1bfad9 2024-03-30 thomas /* Followed by refname_len data bytes. */
488 ce1bfad9 2024-03-30 thomas };
489 ce1bfad9 2024-03-30 thomas /* IMSG_NOTIFY session -> notify*/
490 ce1bfad9 2024-03-30 thomas struct gotd_imsg_notify {
491 ce1bfad9 2024-03-30 thomas char repo_name[NAME_MAX];
492 ce1bfad9 2024-03-30 thomas char subject_line[64];
493 ce1bfad9 2024-03-30 thomas };
494 ce1bfad9 2024-03-30 thomas
495 b2ce1dae 2024-03-30 thomas int enter_chroot(const char *);
496 f3807fe5 2023-07-10 thomas int parse_config(const char *, enum gotd_procid, struct gotd *);
497 ce1bfad9 2024-03-30 thomas struct gotd_repo *gotd_find_repo_by_name(const char *, struct gotd_repolist *);
498 6d7eb4f7 2023-04-04 thomas struct gotd_repo *gotd_find_repo_by_path(const char *, struct gotd *);
499 65a36f17 2023-04-22 thomas struct gotd_uid_connection_limit *gotd_find_uid_connection_limit(
500 65a36f17 2023-04-22 thomas struct gotd_uid_connection_limit *limits, size_t nlimits, uid_t uid);
501 48488136 2023-04-22 thomas int gotd_parseuid(const char *s, uid_t *uid);
502 ce1bfad9 2024-03-30 thomas const struct got_error *gotd_parse_url(char **, char **, char **,
503 ce1bfad9 2024-03-30 thomas char **, const char *);
504 3efd8e31 2022-10-23 thomas
505 3efd8e31 2022-10-23 thomas /* imsg.c */
506 3efd8e31 2022-10-23 thomas const struct got_error *gotd_imsg_flush(struct imsgbuf *);
507 3efd8e31 2022-10-23 thomas const struct got_error *gotd_imsg_recv(struct imsg *, struct imsgbuf *, size_t);
508 3efd8e31 2022-10-23 thomas const struct got_error *gotd_imsg_poll_recv(struct imsg *, struct imsgbuf *,
509 3efd8e31 2022-10-23 thomas size_t);
510 3efd8e31 2022-10-23 thomas const struct got_error *gotd_imsg_recv_error(uint32_t *client_id,
511 3efd8e31 2022-10-23 thomas struct imsg *imsg);
512 3efd8e31 2022-10-23 thomas int gotd_imsg_send_error(struct imsgbuf *ibuf, uint32_t, uint32_t,
513 3efd8e31 2022-10-23 thomas const struct got_error *);
514 3efd8e31 2022-10-23 thomas int gotd_imsg_send_error_event(struct gotd_imsgev *, uint32_t, uint32_t,
515 3efd8e31 2022-10-23 thomas const struct got_error *);
516 3efd8e31 2022-10-23 thomas void gotd_imsg_event_add(struct gotd_imsgev *);
517 3efd8e31 2022-10-23 thomas int gotd_imsg_compose_event(struct gotd_imsgev *, uint16_t, uint32_t, int,
518 3efd8e31 2022-10-23 thomas void *, uint16_t);
519 3efd8e31 2022-10-23 thomas int gotd_imsg_forward(struct gotd_imsgev *, struct imsg *, int);
520 3efd8e31 2022-10-23 thomas
521 3efd8e31 2022-10-23 thomas void gotd_imsg_send_ack(struct got_object_id *, struct imsgbuf *,
522 3efd8e31 2022-10-23 thomas uint32_t, pid_t);
523 3efd8e31 2022-10-23 thomas void gotd_imsg_send_nak(struct got_object_id *, struct imsgbuf *,
524 3efd8e31 2022-10-23 thomas uint32_t, pid_t);