Blame


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