Blame


1 aba9c984 2019-09-08 stsp /*
2 aba9c984 2019-09-08 stsp * Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
3 aba9c984 2019-09-08 stsp *
4 aba9c984 2019-09-08 stsp * Permission to use, copy, modify, and distribute this software for any
5 aba9c984 2019-09-08 stsp * purpose with or without fee is hereby granted, provided that the above
6 aba9c984 2019-09-08 stsp * copyright notice and this permission notice appear in all copies.
7 aba9c984 2019-09-08 stsp *
8 aba9c984 2019-09-08 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 aba9c984 2019-09-08 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 aba9c984 2019-09-08 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 aba9c984 2019-09-08 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 aba9c984 2019-09-08 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 aba9c984 2019-09-08 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 aba9c984 2019-09-08 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 aba9c984 2019-09-08 stsp */
16 aba9c984 2019-09-08 stsp
17 aba9c984 2019-09-08 stsp #include <sys/types.h>
18 aba9c984 2019-09-08 stsp #include <sys/queue.h>
19 aba9c984 2019-09-08 stsp #include <sys/uio.h>
20 aba9c984 2019-09-08 stsp #include <sys/time.h>
21 aba9c984 2019-09-08 stsp #include <sys/syslimits.h>
22 aba9c984 2019-09-08 stsp
23 aba9c984 2019-09-08 stsp #include <stdint.h>
24 aba9c984 2019-09-08 stsp #include <imsg.h>
25 aba9c984 2019-09-08 stsp #include <limits.h>
26 aba9c984 2019-09-08 stsp #include <signal.h>
27 aba9c984 2019-09-08 stsp #include <stdio.h>
28 aba9c984 2019-09-08 stsp #include <stdlib.h>
29 aba9c984 2019-09-08 stsp #include <string.h>
30 aba9c984 2019-09-08 stsp #include <sha1.h>
31 81a12da5 2020-09-09 naddy #include <unistd.h>
32 aba9c984 2019-09-08 stsp #include <zlib.h>
33 aba9c984 2019-09-08 stsp
34 aba9c984 2019-09-08 stsp #include "got_error.h"
35 aba9c984 2019-09-08 stsp #include "got_object.h"
36 cd95becd 2019-11-29 stsp #include "got_repository.h"
37 aba9c984 2019-09-08 stsp
38 aba9c984 2019-09-08 stsp #include "got_lib_delta.h"
39 aba9c984 2019-09-08 stsp #include "got_lib_object.h"
40 aba9c984 2019-09-08 stsp #include "got_lib_privsep.h"
41 aba9c984 2019-09-08 stsp #include "got_lib_gitconfig.h"
42 aba9c984 2019-09-08 stsp
43 aba9c984 2019-09-08 stsp static volatile sig_atomic_t sigint_received;
44 aba9c984 2019-09-08 stsp
45 aba9c984 2019-09-08 stsp static void
46 aba9c984 2019-09-08 stsp catch_sigint(int signo)
47 aba9c984 2019-09-08 stsp {
48 aba9c984 2019-09-08 stsp sigint_received = 1;
49 aba9c984 2019-09-08 stsp }
50 aba9c984 2019-09-08 stsp
51 aba9c984 2019-09-08 stsp static const struct got_error *
52 e70bf110 2020-03-22 stsp send_gitconfig_int(struct imsgbuf *ibuf, int value)
53 e70bf110 2020-03-22 stsp {
54 e70bf110 2020-03-22 stsp if (imsg_compose(ibuf, GOT_IMSG_GITCONFIG_INT_VAL, 0, 0, -1,
55 e70bf110 2020-03-22 stsp &value, sizeof(value)) == -1)
56 e70bf110 2020-03-22 stsp return got_error_from_errno("imsg_compose GITCONFIG_INT_VAL");
57 e70bf110 2020-03-22 stsp
58 e70bf110 2020-03-22 stsp return got_privsep_flush_imsg(ibuf);
59 e70bf110 2020-03-22 stsp }
60 e70bf110 2020-03-22 stsp
61 e70bf110 2020-03-22 stsp static const struct got_error *
62 aba9c984 2019-09-08 stsp gitconfig_num_request(struct imsgbuf *ibuf, struct got_gitconfig *gitconfig,
63 aba9c984 2019-09-08 stsp char *section, char *tag, int def)
64 aba9c984 2019-09-08 stsp {
65 aba9c984 2019-09-08 stsp int value;
66 aba9c984 2019-09-08 stsp
67 aba9c984 2019-09-08 stsp if (gitconfig == NULL)
68 aba9c984 2019-09-08 stsp return got_error(GOT_ERR_PRIVSEP_MSG);
69 aba9c984 2019-09-08 stsp
70 aba9c984 2019-09-08 stsp value = got_gitconfig_get_num(gitconfig, section, tag, def);
71 e70bf110 2020-03-22 stsp return send_gitconfig_int(ibuf, value);
72 aba9c984 2019-09-08 stsp }
73 aba9c984 2019-09-08 stsp
74 aba9c984 2019-09-08 stsp static const struct got_error *
75 e70bf110 2020-03-22 stsp send_gitconfig_str(struct imsgbuf *ibuf, const char *value)
76 e70bf110 2020-03-22 stsp {
77 e70bf110 2020-03-22 stsp size_t len = value ? strlen(value) + 1 : 0;
78 e70bf110 2020-03-22 stsp
79 e70bf110 2020-03-22 stsp if (imsg_compose(ibuf, GOT_IMSG_GITCONFIG_STR_VAL, 0, 0, -1,
80 e70bf110 2020-03-22 stsp value, len) == -1)
81 e70bf110 2020-03-22 stsp return got_error_from_errno("imsg_compose GITCONFIG_STR_VAL");
82 e70bf110 2020-03-22 stsp
83 e70bf110 2020-03-22 stsp return got_privsep_flush_imsg(ibuf);
84 e70bf110 2020-03-22 stsp }
85 e70bf110 2020-03-22 stsp
86 e70bf110 2020-03-22 stsp static const struct got_error *
87 aba9c984 2019-09-08 stsp gitconfig_str_request(struct imsgbuf *ibuf, struct got_gitconfig *gitconfig,
88 aba9c984 2019-09-08 stsp char *section, char *tag)
89 aba9c984 2019-09-08 stsp {
90 aba9c984 2019-09-08 stsp char *value;
91 aba9c984 2019-09-08 stsp
92 aba9c984 2019-09-08 stsp if (gitconfig == NULL)
93 aba9c984 2019-09-08 stsp return got_error(GOT_ERR_PRIVSEP_MSG);
94 aba9c984 2019-09-08 stsp
95 aba9c984 2019-09-08 stsp value = got_gitconfig_get_str(gitconfig, section, tag);
96 e70bf110 2020-03-22 stsp return send_gitconfig_str(ibuf, value);
97 aba9c984 2019-09-08 stsp }
98 aba9c984 2019-09-08 stsp
99 cd95becd 2019-11-29 stsp static const struct got_error *
100 e70bf110 2020-03-22 stsp send_gitconfig_remotes(struct imsgbuf *ibuf, struct got_remote_repo *remotes,
101 e70bf110 2020-03-22 stsp int nremotes)
102 e70bf110 2020-03-22 stsp {
103 e70bf110 2020-03-22 stsp const struct got_error *err = NULL;
104 e70bf110 2020-03-22 stsp struct got_imsg_remotes iremotes;
105 e70bf110 2020-03-22 stsp int i;
106 e70bf110 2020-03-22 stsp
107 e70bf110 2020-03-22 stsp iremotes.nremotes = nremotes;
108 e70bf110 2020-03-22 stsp if (imsg_compose(ibuf, GOT_IMSG_GITCONFIG_REMOTES, 0, 0, -1,
109 e70bf110 2020-03-22 stsp &iremotes, sizeof(iremotes)) == -1)
110 e70bf110 2020-03-22 stsp return got_error_from_errno("imsg_compose GITCONFIG_REMOTES");
111 e70bf110 2020-03-22 stsp
112 e70bf110 2020-03-22 stsp err = got_privsep_flush_imsg(ibuf);
113 e70bf110 2020-03-22 stsp imsg_clear(ibuf);
114 e70bf110 2020-03-22 stsp if (err)
115 e70bf110 2020-03-22 stsp return err;
116 e70bf110 2020-03-22 stsp
117 e70bf110 2020-03-22 stsp for (i = 0; i < nremotes; i++) {
118 e70bf110 2020-03-22 stsp struct got_imsg_remote iremote;
119 e70bf110 2020-03-22 stsp size_t len = sizeof(iremote);
120 e70bf110 2020-03-22 stsp struct ibuf *wbuf;
121 e70bf110 2020-03-22 stsp
122 e70bf110 2020-03-22 stsp iremote.mirror_references = remotes[i].mirror_references;
123 e70bf110 2020-03-22 stsp iremote.name_len = strlen(remotes[i].name);
124 e70bf110 2020-03-22 stsp len += iremote.name_len;
125 e70bf110 2020-03-22 stsp iremote.url_len = strlen(remotes[i].url);
126 e70bf110 2020-03-22 stsp len += iremote.url_len;
127 e70bf110 2020-03-22 stsp
128 e70bf110 2020-03-22 stsp wbuf = imsg_create(ibuf, GOT_IMSG_GITCONFIG_REMOTE, 0, 0, len);
129 e70bf110 2020-03-22 stsp if (wbuf == NULL)
130 e70bf110 2020-03-22 stsp return got_error_from_errno(
131 e70bf110 2020-03-22 stsp "imsg_create GITCONFIG_REMOTE");
132 e70bf110 2020-03-22 stsp
133 e70bf110 2020-03-22 stsp if (imsg_add(wbuf, &iremote, sizeof(iremote)) == -1) {
134 e70bf110 2020-03-22 stsp err = got_error_from_errno(
135 e70bf110 2020-03-22 stsp "imsg_add GITCONFIG_REMOTE");
136 e70bf110 2020-03-22 stsp ibuf_free(wbuf);
137 e70bf110 2020-03-22 stsp return err;
138 e70bf110 2020-03-22 stsp }
139 e70bf110 2020-03-22 stsp
140 e70bf110 2020-03-22 stsp if (imsg_add(wbuf, remotes[i].name, iremote.name_len) == -1) {
141 e70bf110 2020-03-22 stsp err = got_error_from_errno(
142 e70bf110 2020-03-22 stsp "imsg_add GITCONFIG_REMOTE");
143 e70bf110 2020-03-22 stsp ibuf_free(wbuf);
144 e70bf110 2020-03-22 stsp return err;
145 e70bf110 2020-03-22 stsp }
146 e70bf110 2020-03-22 stsp if (imsg_add(wbuf, remotes[i].url, iremote.url_len) == -1) {
147 e70bf110 2020-03-22 stsp err = got_error_from_errno(
148 e70bf110 2020-03-22 stsp "imsg_add GITCONFIG_REMOTE");
149 e70bf110 2020-03-22 stsp ibuf_free(wbuf);
150 e70bf110 2020-03-22 stsp return err;
151 e70bf110 2020-03-22 stsp }
152 e70bf110 2020-03-22 stsp
153 e70bf110 2020-03-22 stsp wbuf->fd = -1;
154 e70bf110 2020-03-22 stsp imsg_close(ibuf, wbuf);
155 e70bf110 2020-03-22 stsp err = got_privsep_flush_imsg(ibuf);
156 e70bf110 2020-03-22 stsp if (err)
157 e70bf110 2020-03-22 stsp return err;
158 e70bf110 2020-03-22 stsp }
159 e70bf110 2020-03-22 stsp
160 e70bf110 2020-03-22 stsp return NULL;
161 e70bf110 2020-03-22 stsp }
162 e70bf110 2020-03-22 stsp
163 e70bf110 2020-03-22 stsp
164 e70bf110 2020-03-22 stsp static const struct got_error *
165 cd95becd 2019-11-29 stsp gitconfig_remotes_request(struct imsgbuf *ibuf, struct got_gitconfig *gitconfig)
166 cd95becd 2019-11-29 stsp {
167 cd95becd 2019-11-29 stsp const struct got_error *err = NULL;
168 cd95becd 2019-11-29 stsp struct got_gitconfig_list *sections;
169 cd95becd 2019-11-29 stsp struct got_gitconfig_list_node *node;
170 cd95becd 2019-11-29 stsp struct got_remote_repo *remotes = NULL;
171 cd95becd 2019-11-29 stsp int nremotes = 0, i;
172 cd95becd 2019-11-29 stsp
173 cd95becd 2019-11-29 stsp if (gitconfig == NULL)
174 cd95becd 2019-11-29 stsp return got_error(GOT_ERR_PRIVSEP_MSG);
175 cd95becd 2019-11-29 stsp
176 cd95becd 2019-11-29 stsp err = got_gitconfig_get_section_list(&sections, gitconfig);
177 cd95becd 2019-11-29 stsp if (err)
178 cd95becd 2019-11-29 stsp return err;
179 cd95becd 2019-11-29 stsp
180 cd95becd 2019-11-29 stsp TAILQ_FOREACH(node, &sections->fields, link) {
181 cd95becd 2019-11-29 stsp if (strncasecmp("remote \"", node->field, 8) != 0)
182 cd95becd 2019-11-29 stsp continue;
183 cd95becd 2019-11-29 stsp nremotes++;
184 cd95becd 2019-11-29 stsp }
185 cd95becd 2019-11-29 stsp
186 cd95becd 2019-11-29 stsp if (nremotes == 0) {
187 e70bf110 2020-03-22 stsp err = send_gitconfig_remotes(ibuf, NULL, 0);
188 cd95becd 2019-11-29 stsp goto done;
189 cd95becd 2019-11-29 stsp }
190 cd95becd 2019-11-29 stsp
191 cd95becd 2019-11-29 stsp remotes = recallocarray(NULL, 0, nremotes, sizeof(*remotes));
192 cd95becd 2019-11-29 stsp if (remotes == NULL) {
193 cd95becd 2019-11-29 stsp err = got_error_from_errno("recallocarray");
194 cd95becd 2019-11-29 stsp goto done;
195 cd95becd 2019-11-29 stsp }
196 cd95becd 2019-11-29 stsp
197 cd95becd 2019-11-29 stsp i = 0;
198 cd95becd 2019-11-29 stsp TAILQ_FOREACH(node, &sections->fields, link) {
199 469dd726 2020-03-20 stsp char *name, *end, *mirror;
200 cd95becd 2019-11-29 stsp
201 cd95becd 2019-11-29 stsp if (strncasecmp("remote \"", node->field, 8) != 0)
202 cd95becd 2019-11-29 stsp continue;
203 cd95becd 2019-11-29 stsp
204 cd95becd 2019-11-29 stsp name = strdup(node->field + 8);
205 cd95becd 2019-11-29 stsp if (name == NULL) {
206 cd95becd 2019-11-29 stsp err = got_error_from_errno("strdup");
207 cd95becd 2019-11-29 stsp goto done;
208 cd95becd 2019-11-29 stsp }
209 cd95becd 2019-11-29 stsp end = strrchr(name, '"');
210 cd95becd 2019-11-29 stsp if (end)
211 cd95becd 2019-11-29 stsp *end = '\0';
212 cd95becd 2019-11-29 stsp remotes[i].name = name;
213 cd95becd 2019-11-29 stsp
214 cd95becd 2019-11-29 stsp remotes[i].url = got_gitconfig_get_str(gitconfig,
215 cd95becd 2019-11-29 stsp node->field, "url");
216 cd95becd 2019-11-29 stsp if (remotes[i].url == NULL) {
217 cd95becd 2019-11-29 stsp err = got_error(GOT_ERR_GITCONFIG_SYNTAX);
218 cd95becd 2019-11-29 stsp goto done;
219 cd95becd 2019-11-29 stsp }
220 469dd726 2020-03-20 stsp
221 469dd726 2020-03-20 stsp remotes[i].mirror_references = 0;
222 469dd726 2020-03-20 stsp mirror = got_gitconfig_get_str(gitconfig, node->field,
223 469dd726 2020-03-20 stsp "mirror");
224 469dd726 2020-03-20 stsp if (mirror != NULL &&
225 469dd726 2020-03-20 stsp (strcasecmp(mirror, "true") == 0 ||
226 469dd726 2020-03-20 stsp strcasecmp(mirror, "on") == 0 ||
227 469dd726 2020-03-20 stsp strcasecmp(mirror, "yes") == 0 ||
228 469dd726 2020-03-20 stsp strcmp(mirror, "1") == 0))
229 469dd726 2020-03-20 stsp remotes[i].mirror_references = 1;
230 cd95becd 2019-11-29 stsp
231 cd95becd 2019-11-29 stsp i++;
232 cd95becd 2019-11-29 stsp }
233 cd95becd 2019-11-29 stsp
234 e70bf110 2020-03-22 stsp err = send_gitconfig_remotes(ibuf, remotes, nremotes);
235 cd95becd 2019-11-29 stsp done:
236 cd95becd 2019-11-29 stsp for (i = 0; i < nremotes; i++)
237 cd95becd 2019-11-29 stsp free(remotes[i].name);
238 cd95becd 2019-11-29 stsp free(remotes);
239 cd95becd 2019-11-29 stsp got_gitconfig_free_list(sections);
240 cd95becd 2019-11-29 stsp return err;
241 9a1cc63f 2020-02-03 stsp }
242 9a1cc63f 2020-02-03 stsp
243 9a1cc63f 2020-02-03 stsp static const struct got_error *
244 9a1cc63f 2020-02-03 stsp gitconfig_owner_request(struct imsgbuf *ibuf, struct got_gitconfig *gitconfig)
245 9a1cc63f 2020-02-03 stsp {
246 9a1cc63f 2020-02-03 stsp char *value;
247 9a1cc63f 2020-02-03 stsp
248 9a1cc63f 2020-02-03 stsp if (gitconfig == NULL)
249 9a1cc63f 2020-02-03 stsp return got_error(GOT_ERR_PRIVSEP_MSG);
250 9a1cc63f 2020-02-03 stsp
251 9a1cc63f 2020-02-03 stsp value = got_gitconfig_get_str(gitconfig, "gotweb", "owner");
252 9a1cc63f 2020-02-03 stsp if (value)
253 e70bf110 2020-03-22 stsp return send_gitconfig_str(ibuf, value);
254 9a1cc63f 2020-02-03 stsp value = got_gitconfig_get_str(gitconfig, "gitweb", "owner");
255 e70bf110 2020-03-22 stsp return send_gitconfig_str(ibuf, value);
256 cd95becd 2019-11-29 stsp }
257 cd95becd 2019-11-29 stsp
258 aba9c984 2019-09-08 stsp int
259 aba9c984 2019-09-08 stsp main(int argc, char *argv[])
260 aba9c984 2019-09-08 stsp {
261 aba9c984 2019-09-08 stsp const struct got_error *err = NULL;
262 aba9c984 2019-09-08 stsp struct imsgbuf ibuf;
263 aba9c984 2019-09-08 stsp size_t datalen;
264 aba9c984 2019-09-08 stsp struct got_gitconfig *gitconfig = NULL;
265 aba9c984 2019-09-08 stsp #if 0
266 aba9c984 2019-09-08 stsp static int attached;
267 aba9c984 2019-09-08 stsp
268 aba9c984 2019-09-08 stsp while (!attached)
269 aba9c984 2019-09-08 stsp sleep(1);
270 aba9c984 2019-09-08 stsp #endif
271 aba9c984 2019-09-08 stsp signal(SIGINT, catch_sigint);
272 aba9c984 2019-09-08 stsp
273 aba9c984 2019-09-08 stsp imsg_init(&ibuf, GOT_IMSG_FD_CHILD);
274 aba9c984 2019-09-08 stsp
275 aba9c984 2019-09-08 stsp #ifndef PROFILE
276 aba9c984 2019-09-08 stsp /* revoke access to most system calls */
277 aba9c984 2019-09-08 stsp if (pledge("stdio recvfd", NULL) == -1) {
278 aba9c984 2019-09-08 stsp err = got_error_from_errno("pledge");
279 aba9c984 2019-09-08 stsp got_privsep_send_error(&ibuf, err);
280 aba9c984 2019-09-08 stsp return 1;
281 aba9c984 2019-09-08 stsp }
282 aba9c984 2019-09-08 stsp #endif
283 aba9c984 2019-09-08 stsp
284 aba9c984 2019-09-08 stsp for (;;) {
285 aba9c984 2019-09-08 stsp struct imsg imsg;
286 aba9c984 2019-09-08 stsp
287 aba9c984 2019-09-08 stsp memset(&imsg, 0, sizeof(imsg));
288 aba9c984 2019-09-08 stsp imsg.fd = -1;
289 aba9c984 2019-09-08 stsp
290 aba9c984 2019-09-08 stsp if (sigint_received) {
291 aba9c984 2019-09-08 stsp err = got_error(GOT_ERR_CANCELLED);
292 aba9c984 2019-09-08 stsp break;
293 aba9c984 2019-09-08 stsp }
294 aba9c984 2019-09-08 stsp
295 aba9c984 2019-09-08 stsp err = got_privsep_recv_imsg(&imsg, &ibuf, 0);
296 aba9c984 2019-09-08 stsp if (err) {
297 aba9c984 2019-09-08 stsp if (err->code == GOT_ERR_PRIVSEP_PIPE)
298 aba9c984 2019-09-08 stsp err = NULL;
299 aba9c984 2019-09-08 stsp break;
300 aba9c984 2019-09-08 stsp }
301 aba9c984 2019-09-08 stsp
302 aba9c984 2019-09-08 stsp if (imsg.hdr.type == GOT_IMSG_STOP)
303 aba9c984 2019-09-08 stsp break;
304 aba9c984 2019-09-08 stsp
305 aba9c984 2019-09-08 stsp switch (imsg.hdr.type) {
306 aba9c984 2019-09-08 stsp case GOT_IMSG_GITCONFIG_PARSE_REQUEST:
307 aba9c984 2019-09-08 stsp datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
308 aba9c984 2019-09-08 stsp if (datalen != 0) {
309 aba9c984 2019-09-08 stsp err = got_error(GOT_ERR_PRIVSEP_LEN);
310 aba9c984 2019-09-08 stsp break;
311 aba9c984 2019-09-08 stsp }
312 aba9c984 2019-09-08 stsp if (imsg.fd == -1){
313 aba9c984 2019-09-08 stsp err = got_error(GOT_ERR_PRIVSEP_NO_FD);
314 aba9c984 2019-09-08 stsp break;
315 aba9c984 2019-09-08 stsp }
316 aba9c984 2019-09-08 stsp
317 aba9c984 2019-09-08 stsp if (gitconfig)
318 aba9c984 2019-09-08 stsp got_gitconfig_close(gitconfig);
319 aba9c984 2019-09-08 stsp err = got_gitconfig_open(&gitconfig, imsg.fd);
320 aba9c984 2019-09-08 stsp break;
321 aba9c984 2019-09-08 stsp case GOT_IMSG_GITCONFIG_REPOSITORY_FORMAT_VERSION_REQUEST:
322 aba9c984 2019-09-08 stsp err = gitconfig_num_request(&ibuf, gitconfig, "core",
323 aba9c984 2019-09-08 stsp "repositoryformatversion", 0);
324 aba9c984 2019-09-08 stsp break;
325 aba9c984 2019-09-08 stsp case GOT_IMSG_GITCONFIG_AUTHOR_NAME_REQUEST:
326 aba9c984 2019-09-08 stsp err = gitconfig_str_request(&ibuf, gitconfig, "user",
327 aba9c984 2019-09-08 stsp "name");
328 aba9c984 2019-09-08 stsp break;
329 aba9c984 2019-09-08 stsp case GOT_IMSG_GITCONFIG_AUTHOR_EMAIL_REQUEST:
330 aba9c984 2019-09-08 stsp err = gitconfig_str_request(&ibuf, gitconfig, "user",
331 aba9c984 2019-09-08 stsp "email");
332 aba9c984 2019-09-08 stsp break;
333 cd95becd 2019-11-29 stsp case GOT_IMSG_GITCONFIG_REMOTES_REQUEST:
334 cd95becd 2019-11-29 stsp err = gitconfig_remotes_request(&ibuf, gitconfig);
335 cd95becd 2019-11-29 stsp break;
336 9a1cc63f 2020-02-03 stsp case GOT_IMSG_GITCONFIG_OWNER_REQUEST:
337 9a1cc63f 2020-02-03 stsp err = gitconfig_owner_request(&ibuf, gitconfig);
338 9a1cc63f 2020-02-03 stsp break;
339 aba9c984 2019-09-08 stsp default:
340 aba9c984 2019-09-08 stsp err = got_error(GOT_ERR_PRIVSEP_MSG);
341 aba9c984 2019-09-08 stsp break;
342 aba9c984 2019-09-08 stsp }
343 aba9c984 2019-09-08 stsp
344 aba9c984 2019-09-08 stsp if (imsg.fd != -1) {
345 aba9c984 2019-09-08 stsp if (close(imsg.fd) == -1 && err == NULL)
346 aba9c984 2019-09-08 stsp err = got_error_from_errno("close");
347 aba9c984 2019-09-08 stsp }
348 aba9c984 2019-09-08 stsp
349 aba9c984 2019-09-08 stsp imsg_free(&imsg);
350 aba9c984 2019-09-08 stsp if (err)
351 aba9c984 2019-09-08 stsp break;
352 aba9c984 2019-09-08 stsp }
353 aba9c984 2019-09-08 stsp
354 aba9c984 2019-09-08 stsp imsg_clear(&ibuf);
355 aba9c984 2019-09-08 stsp if (err) {
356 aba9c984 2019-09-08 stsp if (!sigint_received && err->code != GOT_ERR_PRIVSEP_PIPE) {
357 aba9c984 2019-09-08 stsp fprintf(stderr, "%s: %s\n", getprogname(), err->msg);
358 aba9c984 2019-09-08 stsp got_privsep_send_error(&ibuf, err);
359 aba9c984 2019-09-08 stsp }
360 aba9c984 2019-09-08 stsp }
361 aba9c984 2019-09-08 stsp if (close(GOT_IMSG_FD_CHILD) != 0 && err == NULL)
362 aba9c984 2019-09-08 stsp err = got_error_from_errno("close");
363 aba9c984 2019-09-08 stsp return err ? 1 : 0;
364 aba9c984 2019-09-08 stsp }