Blame


1 8a35f56c 2022-07-16 thomas /*
2 8a35f56c 2022-07-16 thomas * Copyright (c) 2016, 2019, 2020-2022 Tracey Emery <tracey@traceyemery.net>
3 8a35f56c 2022-07-16 thomas * Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
4 8a35f56c 2022-07-16 thomas * Copyright (c) 2013 David Gwynne <dlg@openbsd.org>
5 8a35f56c 2022-07-16 thomas * Copyright (c) 2013 Florian Obser <florian@openbsd.org>
6 8a35f56c 2022-07-16 thomas *
7 8a35f56c 2022-07-16 thomas * Permission to use, copy, modify, and distribute this software for any
8 8a35f56c 2022-07-16 thomas * purpose with or without fee is hereby granted, provided that the above
9 8a35f56c 2022-07-16 thomas * copyright notice and this permission notice appear in all copies.
10 8a35f56c 2022-07-16 thomas *
11 8a35f56c 2022-07-16 thomas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 8a35f56c 2022-07-16 thomas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 8a35f56c 2022-07-16 thomas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 8a35f56c 2022-07-16 thomas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 8a35f56c 2022-07-16 thomas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 8a35f56c 2022-07-16 thomas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 8a35f56c 2022-07-16 thomas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 8a35f56c 2022-07-16 thomas */
19 8a35f56c 2022-07-16 thomas
20 8a35f56c 2022-07-16 thomas #include <netinet/in.h>
21 8a35f56c 2022-07-16 thomas #include <net/if.h>
22 8a35f56c 2022-07-16 thomas #include <sys/queue.h>
23 8a35f56c 2022-07-16 thomas
24 8a35f56c 2022-07-16 thomas #include <limits.h>
25 8a35f56c 2022-07-16 thomas #include <stdio.h>
26 cb11302c 2022-12-30 thomas
27 cb11302c 2022-12-30 thomas #include "tmpl.h"
28 8a35f56c 2022-07-16 thomas
29 8a35f56c 2022-07-16 thomas #ifdef DEBUG
30 8a35f56c 2022-07-16 thomas #define dprintf(x...) do { log_debug(x); } while(0)
31 8a35f56c 2022-07-16 thomas #else
32 8a35f56c 2022-07-16 thomas #define dprintf(x...)
33 8a35f56c 2022-07-16 thomas #endif /* DEBUG */
34 8a35f56c 2022-07-16 thomas
35 8a35f56c 2022-07-16 thomas #ifndef nitems
36 8a35f56c 2022-07-16 thomas #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
37 8a35f56c 2022-07-16 thomas #endif
38 8a35f56c 2022-07-16 thomas
39 8a35f56c 2022-07-16 thomas /* GOTWEBD DEFAULTS */
40 8a35f56c 2022-07-16 thomas #define GOTWEBD_CONF "/etc/gotwebd.conf"
41 8a35f56c 2022-07-16 thomas
42 8a35f56c 2022-07-16 thomas #define GOTWEBD_USER "www"
43 8a35f56c 2022-07-16 thomas
44 3e9a56b5 2022-12-01 thomas #define GOTWEBD_MAXDESCRSZ 1024
45 3e9a56b5 2022-12-01 thomas #define GOTWEBD_MAXCLONEURLSZ 1024
46 e5539f76 2022-08-10 thomas #define GOTWEBD_CACHESIZE 1024
47 8a35f56c 2022-07-16 thomas #define GOTWEBD_MAXCLIENTS 1024
48 8a35f56c 2022-07-16 thomas #define GOTWEBD_MAXTEXT 511
49 8a35f56c 2022-07-16 thomas #define GOTWEBD_MAXNAME 64
50 8a35f56c 2022-07-16 thomas #define GOTWEBD_MAXPORT 6
51 8a35f56c 2022-07-16 thomas #define GOTWEBD_NUMPROC 3
52 8a35f56c 2022-07-16 thomas #define GOTWEBD_MAXIFACE 16
53 55e6cffd 2022-09-01 thomas #define GOTWEBD_REPO_CACHESIZE 4
54 8a35f56c 2022-07-16 thomas
55 8a35f56c 2022-07-16 thomas /* GOTWEB DEFAULTS */
56 8a35f56c 2022-07-16 thomas #define MAX_QUERYSTRING 2048
57 3191e256 2022-12-30 thomas #define MAX_DOCUMENT_URI 255
58 8a35f56c 2022-07-16 thomas #define MAX_SERVER_NAME 255
59 8a35f56c 2022-07-16 thomas
60 8a35f56c 2022-07-16 thomas #define GOTWEB_GIT_DIR ".git"
61 8a35f56c 2022-07-16 thomas
62 8a35f56c 2022-07-16 thomas #define D_HTTPD_CHROOT "/var/www"
63 8a35f56c 2022-07-16 thomas #define D_UNIX_SOCKET "/run/gotweb.sock"
64 8a35f56c 2022-07-16 thomas #define D_FCGI_PORT "9000"
65 8a35f56c 2022-07-16 thomas #define D_GOTPATH "/got/public"
66 8a35f56c 2022-07-16 thomas #define D_SITENAME "Gotweb"
67 8a35f56c 2022-07-16 thomas #define D_SITEOWNER "Got Owner"
68 8a35f56c 2022-07-16 thomas #define D_SITELINK "Repos"
69 8a35f56c 2022-07-16 thomas #define D_GOTLOGO "got.png"
70 8a35f56c 2022-07-16 thomas #define D_GOTURL "https://gameoftrees.org"
71 8a35f56c 2022-07-16 thomas #define D_GOTWEBCSS "gotweb.css"
72 8a35f56c 2022-07-16 thomas
73 8a35f56c 2022-07-16 thomas #define D_SHOWROWNER 1
74 8a35f56c 2022-07-16 thomas #define D_SHOWSOWNER 1
75 8a35f56c 2022-07-16 thomas #define D_SHOWAGE 1
76 8a35f56c 2022-07-16 thomas #define D_SHOWDESC 1
77 8a35f56c 2022-07-16 thomas #define D_SHOWURL 1
78 3991b2a5 2022-10-31 thomas #define D_RESPECTEXPORTOK 0
79 8a35f56c 2022-07-16 thomas #define D_MAXREPO 0
80 8a35f56c 2022-07-16 thomas #define D_MAXREPODISP 25
81 8a35f56c 2022-07-16 thomas #define D_MAXSLCOMMDISP 10
82 8a35f56c 2022-07-16 thomas #define D_MAXCOMMITDISP 25
83 8a35f56c 2022-07-16 thomas
84 8a35f56c 2022-07-16 thomas #define BUF 8192
85 8a35f56c 2022-07-16 thomas
86 8a35f56c 2022-07-16 thomas #define TIMEOUT_DEFAULT 120
87 8a35f56c 2022-07-16 thomas
88 8a35f56c 2022-07-16 thomas #define FCGI_CONTENT_SIZE 65535
89 8a35f56c 2022-07-16 thomas #define FCGI_PADDING_SIZE 255
90 8a35f56c 2022-07-16 thomas #define FCGI_RECORD_SIZE \
91 8a35f56c 2022-07-16 thomas (sizeof(struct fcgi_record_header) + FCGI_CONTENT_SIZE + FCGI_PADDING_SIZE)
92 8a35f56c 2022-07-16 thomas
93 8a35f56c 2022-07-16 thomas #define FCGI_ALIGNMENT 8
94 8a35f56c 2022-07-16 thomas #define FCGI_ALIGN(n) \
95 8a35f56c 2022-07-16 thomas (((n) + (FCGI_ALIGNMENT - 1)) & ~(FCGI_ALIGNMENT - 1))
96 8a35f56c 2022-07-16 thomas
97 8a35f56c 2022-07-16 thomas #define FD_RESERVE 5
98 8a35f56c 2022-07-16 thomas #define FD_NEEDED 6
99 8a35f56c 2022-07-16 thomas
100 8a35f56c 2022-07-16 thomas #define FCGI_BEGIN_REQUEST 1
101 8a35f56c 2022-07-16 thomas #define FCGI_ABORT_REQUEST 2
102 8a35f56c 2022-07-16 thomas #define FCGI_END_REQUEST 3
103 8a35f56c 2022-07-16 thomas #define FCGI_PARAMS 4
104 8a35f56c 2022-07-16 thomas #define FCGI_STDIN 5
105 8a35f56c 2022-07-16 thomas #define FCGI_STDOUT 6
106 8a35f56c 2022-07-16 thomas #define FCGI_STDERR 7
107 8a35f56c 2022-07-16 thomas #define FCGI_DATA 8
108 8a35f56c 2022-07-16 thomas #define FCGI_GET_VALUES 9
109 8a35f56c 2022-07-16 thomas #define FCGI_GET_VALUES_RESULT 10
110 8a35f56c 2022-07-16 thomas #define FCGI_UNKNOWN_TYPE 11
111 8a35f56c 2022-07-16 thomas #define FCGI_MAXTYPE (FCGI_UNKNOWN_TYPE)
112 8a35f56c 2022-07-16 thomas
113 8a35f56c 2022-07-16 thomas #define FCGI_REQUEST_COMPLETE 0
114 8a35f56c 2022-07-16 thomas #define FCGI_CANT_MPX_CONN 1
115 8a35f56c 2022-07-16 thomas #define FCGI_OVERLOADED 2
116 8a35f56c 2022-07-16 thomas #define FCGI_UNKNOWN_ROLE 3
117 8a35f56c 2022-07-16 thomas
118 61f9965e 2023-05-25 thomas #define GOTWEB_PACK_NUM_TEMPFILES (32 * 2)
119 8a35f56c 2022-07-16 thomas
120 b82440e1 2023-01-06 thomas /* Forward declaration */
121 b82440e1 2023-01-06 thomas struct got_blob_object;
122 3c14c1f2 2023-01-06 thomas struct got_tree_entry;
123 00abe30b 2023-01-14 thomas struct got_reflist_head;
124 b82440e1 2023-01-06 thomas
125 8a35f56c 2022-07-16 thomas enum imsg_type {
126 8a35f56c 2022-07-16 thomas IMSG_CFG_SRV = IMSG_PROC_MAX,
127 8a35f56c 2022-07-16 thomas IMSG_CFG_SOCK,
128 8a35f56c 2022-07-16 thomas IMSG_CFG_FD,
129 8a35f56c 2022-07-16 thomas IMSG_CFG_DONE,
130 8a35f56c 2022-07-16 thomas IMSG_CTL_START,
131 8a35f56c 2022-07-16 thomas };
132 8a35f56c 2022-07-16 thomas
133 8a35f56c 2022-07-16 thomas struct env_val {
134 8a35f56c 2022-07-16 thomas SLIST_ENTRY(env_val) entry;
135 8a35f56c 2022-07-16 thomas char *val;
136 8a35f56c 2022-07-16 thomas };
137 8a35f56c 2022-07-16 thomas SLIST_HEAD(env_head, env_val);
138 8a35f56c 2022-07-16 thomas
139 8a35f56c 2022-07-16 thomas struct fcgi_record_header {
140 8a35f56c 2022-07-16 thomas uint8_t version;
141 8a35f56c 2022-07-16 thomas uint8_t type;
142 8a35f56c 2022-07-16 thomas uint16_t id;
143 8a35f56c 2022-07-16 thomas uint16_t content_len;
144 8a35f56c 2022-07-16 thomas uint8_t padding_len;
145 8a35f56c 2022-07-16 thomas uint8_t reserved;
146 0740b40a 2022-07-16 thomas }__attribute__((__packed__));
147 1cd5d437 2023-01-15 thomas
148 1cd5d437 2023-01-15 thomas struct blame_line {
149 1cd5d437 2023-01-15 thomas int annotated;
150 1cd5d437 2023-01-15 thomas char *id_str;
151 1cd5d437 2023-01-15 thomas char *committer;
152 1cd5d437 2023-01-15 thomas char datebuf[11]; /* YYYY-MM-DD + NUL */
153 1cd5d437 2023-01-15 thomas };
154 8a35f56c 2022-07-16 thomas
155 8a35f56c 2022-07-16 thomas struct repo_dir {
156 8a35f56c 2022-07-16 thomas char *name;
157 8a35f56c 2022-07-16 thomas char *owner;
158 8a35f56c 2022-07-16 thomas char *description;
159 8a35f56c 2022-07-16 thomas char *url;
160 53bf32b8 2023-01-23 thomas time_t age;
161 8a35f56c 2022-07-16 thomas char *path;
162 8a35f56c 2022-07-16 thomas };
163 8a35f56c 2022-07-16 thomas
164 8a35f56c 2022-07-16 thomas struct repo_tag {
165 8a35f56c 2022-07-16 thomas TAILQ_ENTRY(repo_tag) entry;
166 8a35f56c 2022-07-16 thomas char *commit_id;
167 8a35f56c 2022-07-16 thomas char *tag_name;
168 8a35f56c 2022-07-16 thomas char *tag_commit;
169 8a35f56c 2022-07-16 thomas char *commit_msg;
170 8a35f56c 2022-07-16 thomas char *tagger;
171 8a35f56c 2022-07-16 thomas time_t tagger_time;
172 8a35f56c 2022-07-16 thomas };
173 8a35f56c 2022-07-16 thomas
174 8a35f56c 2022-07-16 thomas struct repo_commit {
175 8a35f56c 2022-07-16 thomas TAILQ_ENTRY(repo_commit) entry;
176 8a35f56c 2022-07-16 thomas char *path;
177 8a35f56c 2022-07-16 thomas char *refs_str;
178 8a35f56c 2022-07-16 thomas char *commit_id; /* id_str1 */
179 8a35f56c 2022-07-16 thomas char *parent_id; /* id_str2 */
180 8a35f56c 2022-07-16 thomas char *tree_id;
181 8a35f56c 2022-07-16 thomas char *author;
182 8a35f56c 2022-07-16 thomas char *committer;
183 8a35f56c 2022-07-16 thomas char *commit_msg;
184 8a35f56c 2022-07-16 thomas time_t committer_time;
185 8a35f56c 2022-07-16 thomas };
186 8a35f56c 2022-07-16 thomas
187 8a35f56c 2022-07-16 thomas struct got_repository;
188 8a35f56c 2022-07-16 thomas struct transport {
189 8a35f56c 2022-07-16 thomas TAILQ_HEAD(repo_commits_head, repo_commit) repo_commits;
190 8a35f56c 2022-07-16 thomas TAILQ_HEAD(repo_tags_head, repo_tag) repo_tags;
191 161663e7 2023-03-11 thomas struct got_reflist_head refs;
192 8a35f56c 2022-07-16 thomas struct got_repository *repo;
193 8a35f56c 2022-07-16 thomas struct repo_dir *repo_dir;
194 8a35f56c 2022-07-16 thomas struct querystring *qs;
195 20bab626 2023-02-03 thomas char *more_id;
196 8a35f56c 2022-07-16 thomas char *next_id;
197 8a35f56c 2022-07-16 thomas char *prev_id;
198 8a35f56c 2022-07-16 thomas unsigned int repos_total;
199 8a35f56c 2022-07-16 thomas unsigned int next_disp;
200 8a35f56c 2022-07-16 thomas unsigned int prev_disp;
201 8a35f56c 2022-07-16 thomas unsigned int tag_count;
202 164b5ddc 2023-03-11 thomas const struct got_error *error;
203 161663e7 2023-03-11 thomas struct got_blob_object *blob;
204 161663e7 2023-03-11 thomas int fd;
205 161663e7 2023-03-11 thomas FILE *fp;
206 161663e7 2023-03-11 thomas struct dirent **repos;
207 161663e7 2023-03-11 thomas int nrepos;
208 8a35f56c 2022-07-16 thomas };
209 8a35f56c 2022-07-16 thomas
210 8a35f56c 2022-07-16 thomas enum socket_priv_fds {
211 8a35f56c 2022-07-16 thomas DIFF_FD_1,
212 8a35f56c 2022-07-16 thomas DIFF_FD_2,
213 8a35f56c 2022-07-16 thomas DIFF_FD_3,
214 8a35f56c 2022-07-16 thomas DIFF_FD_4,
215 8a35f56c 2022-07-16 thomas DIFF_FD_5,
216 8a35f56c 2022-07-16 thomas BLAME_FD_1,
217 8a35f56c 2022-07-16 thomas BLAME_FD_2,
218 8a35f56c 2022-07-16 thomas BLAME_FD_3,
219 8a35f56c 2022-07-16 thomas BLAME_FD_4,
220 8a35f56c 2022-07-16 thomas BLAME_FD_5,
221 8a35f56c 2022-07-16 thomas BLAME_FD_6,
222 8a35f56c 2022-07-16 thomas BLOB_FD_1,
223 8a35f56c 2022-07-16 thomas BLOB_FD_2,
224 8a35f56c 2022-07-16 thomas PRIV_FDS__MAX,
225 8a35f56c 2022-07-16 thomas };
226 8a35f56c 2022-07-16 thomas
227 e7e5fa49 2022-12-30 thomas struct template;
228 8a35f56c 2022-07-16 thomas struct request {
229 8a35f56c 2022-07-16 thomas struct socket *sock;
230 8a35f56c 2022-07-16 thomas struct server *srv;
231 8a35f56c 2022-07-16 thomas struct transport *t;
232 e7e5fa49 2022-12-30 thomas struct template *tp;
233 8a35f56c 2022-07-16 thomas struct event ev;
234 8a35f56c 2022-07-16 thomas struct event tmo;
235 8a35f56c 2022-07-16 thomas
236 8a35f56c 2022-07-16 thomas uint16_t id;
237 8a35f56c 2022-07-16 thomas int fd;
238 8a35f56c 2022-07-16 thomas int priv_fd[PRIV_FDS__MAX];
239 8a35f56c 2022-07-16 thomas
240 8a35f56c 2022-07-16 thomas uint8_t buf[FCGI_RECORD_SIZE];
241 8a35f56c 2022-07-16 thomas size_t buf_pos;
242 8a35f56c 2022-07-16 thomas size_t buf_len;
243 e5539f76 2022-08-10 thomas
244 e5539f76 2022-08-10 thomas uint8_t outbuf[GOTWEBD_CACHESIZE];
245 e5539f76 2022-08-10 thomas size_t outbuf_len;
246 8a35f56c 2022-07-16 thomas
247 8a35f56c 2022-07-16 thomas char querystring[MAX_QUERYSTRING];
248 3191e256 2022-12-30 thomas char document_uri[MAX_DOCUMENT_URI];
249 8a35f56c 2022-07-16 thomas char server_name[MAX_SERVER_NAME];
250 d6795e9f 2022-12-30 thomas int https;
251 8a35f56c 2022-07-16 thomas
252 8a35f56c 2022-07-16 thomas uint8_t request_started;
253 8a35f56c 2022-07-16 thomas };
254 8a35f56c 2022-07-16 thomas
255 8a35f56c 2022-07-16 thomas struct fcgi_begin_request_body {
256 8a35f56c 2022-07-16 thomas uint16_t role;
257 8a35f56c 2022-07-16 thomas uint8_t flags;
258 8a35f56c 2022-07-16 thomas uint8_t reserved[5];
259 0740b40a 2022-07-16 thomas }__attribute__((__packed__));
260 8a35f56c 2022-07-16 thomas
261 8a35f56c 2022-07-16 thomas struct fcgi_end_request_body {
262 8a35f56c 2022-07-16 thomas uint32_t app_status;
263 8a35f56c 2022-07-16 thomas uint8_t protocol_status;
264 8a35f56c 2022-07-16 thomas uint8_t reserved[3];
265 755d897e 2022-08-06 thomas }__attribute__((__packed__));
266 8a35f56c 2022-07-16 thomas
267 8a35f56c 2022-07-16 thomas struct address {
268 8a35f56c 2022-07-16 thomas TAILQ_ENTRY(address) entry;
269 8a35f56c 2022-07-16 thomas struct sockaddr_storage ss;
270 8a35f56c 2022-07-16 thomas int ipproto;
271 8a35f56c 2022-07-16 thomas in_port_t port;
272 8a35f56c 2022-07-16 thomas char ifname[IFNAMSIZ];
273 8a35f56c 2022-07-16 thomas };
274 8a35f56c 2022-07-16 thomas TAILQ_HEAD(addresslist, address);
275 8a35f56c 2022-07-16 thomas
276 55e6cffd 2022-09-01 thomas struct cached_repo {
277 55e6cffd 2022-09-01 thomas char path[PATH_MAX];
278 55e6cffd 2022-09-01 thomas struct got_repository *repo;
279 55e6cffd 2022-09-01 thomas };
280 55e6cffd 2022-09-01 thomas
281 8a35f56c 2022-07-16 thomas struct server {
282 8a35f56c 2022-07-16 thomas TAILQ_ENTRY(server) entry;
283 62f85214 2022-08-16 thomas struct addresslist al;
284 8a35f56c 2022-07-16 thomas
285 a004b24a 2022-09-06 thomas struct cached_repo *cached_repos;
286 55e6cffd 2022-09-01 thomas int ncached_repos;
287 55e6cffd 2022-09-01 thomas
288 8a35f56c 2022-07-16 thomas char name[GOTWEBD_MAXTEXT];
289 8a35f56c 2022-07-16 thomas
290 8a35f56c 2022-07-16 thomas char repos_path[PATH_MAX];
291 8a35f56c 2022-07-16 thomas char site_name[GOTWEBD_MAXNAME];
292 8a35f56c 2022-07-16 thomas char site_owner[GOTWEBD_MAXNAME];
293 8a35f56c 2022-07-16 thomas char site_link[GOTWEBD_MAXTEXT];
294 8a35f56c 2022-07-16 thomas char logo[GOTWEBD_MAXTEXT];
295 8a35f56c 2022-07-16 thomas char logo_url[GOTWEBD_MAXTEXT];
296 8a35f56c 2022-07-16 thomas char custom_css[PATH_MAX];
297 8a35f56c 2022-07-16 thomas
298 8a35f56c 2022-07-16 thomas size_t max_repos;
299 8a35f56c 2022-07-16 thomas size_t max_repos_display;
300 8a35f56c 2022-07-16 thomas size_t max_commits_display;
301 8a35f56c 2022-07-16 thomas
302 8a35f56c 2022-07-16 thomas int show_site_owner;
303 8a35f56c 2022-07-16 thomas int show_repo_owner;
304 8a35f56c 2022-07-16 thomas int show_repo_age;
305 8a35f56c 2022-07-16 thomas int show_repo_description;
306 8a35f56c 2022-07-16 thomas int show_repo_cloneurl;
307 3991b2a5 2022-10-31 thomas int respect_exportok;
308 8a35f56c 2022-07-16 thomas
309 8a35f56c 2022-07-16 thomas int unix_socket;
310 8a35f56c 2022-07-16 thomas char unix_socket_name[PATH_MAX];
311 8a35f56c 2022-07-16 thomas
312 8a35f56c 2022-07-16 thomas int fcgi_socket;
313 8a35f56c 2022-07-16 thomas };
314 8a35f56c 2022-07-16 thomas TAILQ_HEAD(serverlist, server);
315 8a35f56c 2022-07-16 thomas
316 8a35f56c 2022-07-16 thomas enum client_action {
317 8a35f56c 2022-07-16 thomas CLIENT_CONNECT,
318 8a35f56c 2022-07-16 thomas CLIENT_DISCONNECT,
319 8a35f56c 2022-07-16 thomas };
320 8a35f56c 2022-07-16 thomas
321 8a35f56c 2022-07-16 thomas struct socket_conf {
322 9d7714e3 2022-08-27 thomas struct address addr;
323 8a35f56c 2022-07-16 thomas
324 8a35f56c 2022-07-16 thomas char name[GOTWEBD_MAXTEXT];
325 8a35f56c 2022-07-16 thomas char srv_name[GOTWEBD_MAXTEXT];
326 8a35f56c 2022-07-16 thomas
327 8a35f56c 2022-07-16 thomas int id;
328 720c2b05 2022-08-16 thomas int af_type;
329 8a35f56c 2022-07-16 thomas char unix_socket_name[PATH_MAX];
330 8a35f56c 2022-07-16 thomas in_port_t fcgi_socket_port;
331 8a35f56c 2022-07-16 thomas };
332 8a35f56c 2022-07-16 thomas
333 8a35f56c 2022-07-16 thomas struct socket {
334 8a35f56c 2022-07-16 thomas TAILQ_ENTRY(socket) entry;
335 8a35f56c 2022-07-16 thomas struct socket_conf conf;
336 8a35f56c 2022-07-16 thomas
337 8a35f56c 2022-07-16 thomas int fd;
338 e80b37ed 2022-07-22 thomas int pack_fds[GOTWEB_PACK_NUM_TEMPFILES];
339 8a35f56c 2022-07-16 thomas int priv_fd[PRIV_FDS__MAX];
340 8a35f56c 2022-07-16 thomas
341 8a35f56c 2022-07-16 thomas struct event evt;
342 8a35f56c 2022-07-16 thomas struct event ev;
343 8a35f56c 2022-07-16 thomas struct event pause;
344 8a35f56c 2022-07-16 thomas
345 8a35f56c 2022-07-16 thomas int client_status;
346 8a35f56c 2022-07-16 thomas };
347 8a35f56c 2022-07-16 thomas TAILQ_HEAD(socketlist, socket);
348 8a35f56c 2022-07-16 thomas
349 8a35f56c 2022-07-16 thomas struct gotwebd {
350 90d63d47 2022-08-16 thomas struct serverlist servers;
351 90d63d47 2022-08-16 thomas struct socketlist sockets;
352 8a35f56c 2022-07-16 thomas
353 8a35f56c 2022-07-16 thomas struct privsep *gotwebd_ps;
354 8a35f56c 2022-07-16 thomas const char *gotwebd_conffile;
355 8a35f56c 2022-07-16 thomas
356 8a35f56c 2022-07-16 thomas int gotwebd_debug;
357 8a35f56c 2022-07-16 thomas int gotwebd_verbose;
358 8a35f56c 2022-07-16 thomas int gotwebd_noaction;
359 8a35f56c 2022-07-16 thomas
360 8a35f56c 2022-07-16 thomas uint16_t prefork_gotwebd;
361 8a35f56c 2022-07-16 thomas int gotwebd_reload;
362 8a35f56c 2022-07-16 thomas
363 8a35f56c 2022-07-16 thomas int server_cnt;
364 8a35f56c 2022-07-16 thomas
365 8a35f56c 2022-07-16 thomas char httpd_chroot[PATH_MAX];
366 8a35f56c 2022-07-16 thomas
367 8a35f56c 2022-07-16 thomas int unix_socket;
368 8a35f56c 2022-07-16 thomas char unix_socket_name[PATH_MAX];
369 8a35f56c 2022-07-16 thomas };
370 8a35f56c 2022-07-16 thomas
371 55144267 2022-09-07 thomas /*
372 11490987 2023-01-15 thomas * URL parameter for gotweb_render_url. NULL values and int set to -1
373 11490987 2023-01-15 thomas * are implicitly ignored, and string are properly escaped.
374 55144267 2022-09-07 thomas */
375 55144267 2022-09-07 thomas struct gotweb_url {
376 55144267 2022-09-07 thomas int action;
377 55144267 2022-09-07 thomas int index_page;
378 55144267 2022-09-07 thomas int page;
379 55144267 2022-09-07 thomas const char *commit;
380 55144267 2022-09-07 thomas const char *previd;
381 55144267 2022-09-07 thomas const char *prevset;
382 55144267 2022-09-07 thomas const char *file;
383 55144267 2022-09-07 thomas const char *folder;
384 55144267 2022-09-07 thomas const char *headref;
385 55144267 2022-09-07 thomas const char *path;
386 55144267 2022-09-07 thomas };
387 55144267 2022-09-07 thomas
388 8a35f56c 2022-07-16 thomas struct querystring {
389 8a35f56c 2022-07-16 thomas uint8_t action;
390 8a35f56c 2022-07-16 thomas char *commit;
391 8a35f56c 2022-07-16 thomas char *previd;
392 8a35f56c 2022-07-16 thomas char *prevset;
393 8a35f56c 2022-07-16 thomas char *file;
394 8a35f56c 2022-07-16 thomas char *folder;
395 8a35f56c 2022-07-16 thomas char *headref;
396 8a35f56c 2022-07-16 thomas int index_page;
397 8a35f56c 2022-07-16 thomas char *path;
398 8a35f56c 2022-07-16 thomas int page;
399 8a35f56c 2022-07-16 thomas };
400 8a35f56c 2022-07-16 thomas
401 8a35f56c 2022-07-16 thomas struct querystring_keys {
402 8a35f56c 2022-07-16 thomas const char *name;
403 8a35f56c 2022-07-16 thomas int element;
404 8a35f56c 2022-07-16 thomas };
405 8a35f56c 2022-07-16 thomas
406 8a35f56c 2022-07-16 thomas struct action_keys {
407 8a35f56c 2022-07-16 thomas const char *name;
408 8a35f56c 2022-07-16 thomas int action;
409 8a35f56c 2022-07-16 thomas };
410 8a35f56c 2022-07-16 thomas
411 8a35f56c 2022-07-16 thomas enum querystring_elements {
412 8a35f56c 2022-07-16 thomas ACTION,
413 8a35f56c 2022-07-16 thomas COMMIT,
414 8a35f56c 2022-07-16 thomas RFILE,
415 8a35f56c 2022-07-16 thomas FOLDER,
416 8a35f56c 2022-07-16 thomas HEADREF,
417 8a35f56c 2022-07-16 thomas INDEX_PAGE,
418 8a35f56c 2022-07-16 thomas PATH,
419 8a35f56c 2022-07-16 thomas PAGE,
420 8a35f56c 2022-07-16 thomas PREVID,
421 8a35f56c 2022-07-16 thomas QSELEM__MAX,
422 8a35f56c 2022-07-16 thomas };
423 8a35f56c 2022-07-16 thomas
424 8a35f56c 2022-07-16 thomas enum query_actions {
425 8a35f56c 2022-07-16 thomas BLAME,
426 8a35f56c 2022-07-16 thomas BLOB,
427 b82440e1 2023-01-06 thomas BLOBRAW,
428 8a35f56c 2022-07-16 thomas BRIEFS,
429 8a35f56c 2022-07-16 thomas COMMITS,
430 8a35f56c 2022-07-16 thomas DIFF,
431 8a35f56c 2022-07-16 thomas ERR,
432 8a35f56c 2022-07-16 thomas INDEX,
433 8a35f56c 2022-07-16 thomas SUMMARY,
434 8a35f56c 2022-07-16 thomas TAG,
435 8a35f56c 2022-07-16 thomas TAGS,
436 8a35f56c 2022-07-16 thomas TREE,
437 d6795e9f 2022-12-30 thomas RSS,
438 8a35f56c 2022-07-16 thomas ACTIONS__MAX,
439 8a35f56c 2022-07-16 thomas };
440 8a35f56c 2022-07-16 thomas
441 e7e5fa49 2022-12-30 thomas enum gotweb_ref_tm {
442 e7e5fa49 2022-12-30 thomas TM_DIFF,
443 e7e5fa49 2022-12-30 thomas TM_LONG,
444 d6795e9f 2022-12-30 thomas TM_RFC822,
445 e7e5fa49 2022-12-30 thomas };
446 e7e5fa49 2022-12-30 thomas
447 8a35f56c 2022-07-16 thomas extern struct gotwebd *gotwebd_env;
448 8a35f56c 2022-07-16 thomas
449 1cd5d437 2023-01-15 thomas typedef int (*got_render_blame_line_cb)(struct template *, const char *,
450 1cd5d437 2023-01-15 thomas struct blame_line *, int, int);
451 1cd5d437 2023-01-15 thomas
452 8a35f56c 2022-07-16 thomas /* sockets.c */
453 8a35f56c 2022-07-16 thomas void sockets(struct privsep *, struct privsep_proc *);
454 8a35f56c 2022-07-16 thomas void sockets_shutdown(void);
455 8a35f56c 2022-07-16 thomas void sockets_parse_sockets(struct gotwebd *);
456 8a35f56c 2022-07-16 thomas void sockets_socket_accept(int, short, void *);
457 8a35f56c 2022-07-16 thomas int sockets_privinit(struct gotwebd *, struct socket *);
458 8a35f56c 2022-07-16 thomas
459 8a35f56c 2022-07-16 thomas /* gotweb.c */
460 2f4f0731 2022-12-30 thomas void gotweb_get_navs(struct request *, struct gotweb_url *, int *,
461 2f4f0731 2022-12-30 thomas struct gotweb_url *, int *);
462 53bf32b8 2023-01-23 thomas int gotweb_render_age(struct template *, time_t, int);
463 8a35f56c 2022-07-16 thomas const struct got_error *gotweb_init_transport(struct transport **);
464 e7e5fa49 2022-12-30 thomas const char *gotweb_action_name(int);
465 e7e5fa49 2022-12-30 thomas int gotweb_render_url(struct request *, struct gotweb_url *);
466 d6795e9f 2022-12-30 thomas int gotweb_render_absolute_url(struct request *, struct gotweb_url *);
467 8a35f56c 2022-07-16 thomas void gotweb_free_repo_commit(struct repo_commit *);
468 8a35f56c 2022-07-16 thomas void gotweb_free_repo_tag(struct repo_tag *);
469 8a35f56c 2022-07-16 thomas void gotweb_process_request(struct request *);
470 8a35f56c 2022-07-16 thomas void gotweb_free_transport(struct transport *);
471 8a35f56c 2022-07-16 thomas
472 e7e5fa49 2022-12-30 thomas /* pages.tmpl */
473 161663e7 2023-03-11 thomas int gotweb_render_page(struct template *, int (*)(struct template *));
474 164b5ddc 2023-03-11 thomas int gotweb_render_error(struct template *);
475 e7e5fa49 2022-12-30 thomas int gotweb_render_repo_table_hdr(struct template *);
476 e7e5fa49 2022-12-30 thomas int gotweb_render_repo_fragment(struct template *, struct repo_dir *);
477 e7e5fa49 2022-12-30 thomas int gotweb_render_briefs(struct template *);
478 2f4f0731 2022-12-30 thomas int gotweb_render_navs(struct template *);
479 7ade8b27 2022-12-30 thomas int gotweb_render_commits(struct template *);
480 161663e7 2023-03-11 thomas int gotweb_render_blob(struct template *);
481 3c14c1f2 2023-01-06 thomas int gotweb_render_tree(struct template *);
482 b3ba36c3 2023-01-14 thomas int gotweb_render_tags(struct template *);
483 145ca42a 2023-01-09 thomas int gotweb_render_tag(struct template *);
484 161663e7 2023-03-11 thomas int gotweb_render_diff(struct template *);
485 00abe30b 2023-01-14 thomas int gotweb_render_branches(struct template *, struct got_reflist_head *);
486 161663e7 2023-03-11 thomas int gotweb_render_summary(struct template *);
487 1cd5d437 2023-01-15 thomas int gotweb_render_blame(struct template *);
488 d6795e9f 2022-12-30 thomas int gotweb_render_rss(struct template *);
489 e7e5fa49 2022-12-30 thomas
490 8a35f56c 2022-07-16 thomas /* parse.y */
491 8a35f56c 2022-07-16 thomas int parse_config(const char *, struct gotwebd *);
492 8a35f56c 2022-07-16 thomas int cmdline_symset(char *);
493 8a35f56c 2022-07-16 thomas
494 8a35f56c 2022-07-16 thomas /* fcgi.c */
495 8a35f56c 2022-07-16 thomas void fcgi_request(int, short, void *);
496 8a35f56c 2022-07-16 thomas void fcgi_timeout(int, short, void *);
497 8a35f56c 2022-07-16 thomas void fcgi_cleanup_request(struct request *);
498 8a35f56c 2022-07-16 thomas void fcgi_create_end_record(struct request *);
499 8a35f56c 2022-07-16 thomas void dump_fcgi_record(const char *, struct fcgi_record_header *);
500 e7e5fa49 2022-12-30 thomas int fcgi_puts(struct template *, const char *);
501 e7e5fa49 2022-12-30 thomas int fcgi_putc(struct template *, int);
502 55144267 2022-09-07 thomas int fcgi_vprintf(struct request *, const char *, va_list);
503 79393471 2022-08-27 thomas int fcgi_printf(struct request *, const char *, ...)
504 79393471 2022-08-27 thomas __attribute__((__format__(printf, 2, 3)))
505 79393471 2022-08-27 thomas __attribute__((__nonnull__(2)));
506 8a35f56c 2022-07-16 thomas int fcgi_gen_binary_response(struct request *, const uint8_t *, int);
507 8a35f56c 2022-07-16 thomas
508 8a35f56c 2022-07-16 thomas /* got_operations.c */
509 d00235d8 2023-05-17 thomas const struct got_error *got_gotweb_closefile(FILE *);
510 6c7f10f7 2022-11-23 thomas const struct got_error *got_get_repo_owner(char **, struct request *);
511 53bf32b8 2023-01-23 thomas const struct got_error *got_get_repo_age(time_t *, struct request *,
512 53bf32b8 2023-01-23 thomas const char *);
513 087cc2fc 2023-06-15 thomas const struct got_error *got_get_repo_commits(struct request *, size_t);
514 6c24d194 2023-06-15 thomas const struct got_error *got_get_repo_tags(struct request *, size_t);
515 8a35f56c 2022-07-16 thomas const struct got_error *got_get_repo_heads(struct request *);
516 04b2c111 2023-05-16 thomas const struct got_error *got_open_diff_for_output(FILE **, struct request *);
517 3c14c1f2 2023-01-06 thomas int got_output_repo_tree(struct request *,
518 3c14c1f2 2023-01-06 thomas int (*)(struct template *, struct got_tree_entry *));
519 b82440e1 2023-01-06 thomas const struct got_error *got_open_blob_for_output(struct got_blob_object **,
520 b82440e1 2023-01-06 thomas int *, int *, struct request *);
521 b82440e1 2023-01-06 thomas int got_output_blob_by_lines(struct template *, struct got_blob_object *,
522 b82440e1 2023-01-06 thomas int (*)(struct template *, const char *, size_t));
523 1cd5d437 2023-01-15 thomas const struct got_error *got_output_file_blame(struct request *,
524 1cd5d437 2023-01-15 thomas got_render_blame_line_cb);
525 8a35f56c 2022-07-16 thomas
526 8a35f56c 2022-07-16 thomas /* config.c */
527 8a35f56c 2022-07-16 thomas int config_setserver(struct gotwebd *, struct server *);
528 8a35f56c 2022-07-16 thomas int config_getserver(struct gotwebd *, struct imsg *);
529 8a35f56c 2022-07-16 thomas int config_setsock(struct gotwebd *, struct socket *);
530 8a35f56c 2022-07-16 thomas int config_getsock(struct gotwebd *, struct imsg *);
531 8a35f56c 2022-07-16 thomas int config_setfd(struct gotwebd *, struct socket *);
532 8a35f56c 2022-07-16 thomas int config_getfd(struct gotwebd *, struct imsg *);
533 8a35f56c 2022-07-16 thomas int config_getcfg(struct gotwebd *, struct imsg *);
534 8a35f56c 2022-07-16 thomas int config_init(struct gotwebd *);