commit - 0e762e67cef9321f74d4fcec9f27811c9a7fbd9d
commit + c115f13dfefb091ce3bfb4f72a9fe2082ca1c4f7
blob - 447c95850f26e58bc93149f6531707c99bf1691b
blob + dbb09cd4673bf340a19e12a3607758538bfefff2
--- gotctl/gotctl.c
+++ gotctl/gotctl.c
}
static const struct got_error *
-show_capability(struct imsg *imsg)
-{
- struct gotd_imsg_capability icapa;
- size_t datalen;
- char *key, *value = NULL;
-
- memset(&icapa, 0, sizeof(icapa));
-
- datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
- if (datalen < sizeof(icapa))
- return got_error(GOT_ERR_PRIVSEP_LEN);
- memcpy(&icapa, imsg->data, sizeof(icapa));
-
- if (datalen != sizeof(icapa) + icapa.key_len + icapa.value_len)
- return got_error(GOT_ERR_PRIVSEP_LEN);
-
- key = malloc(icapa.key_len + 1);
- if (key == NULL)
- return got_error_from_errno("malloc");
- if (icapa.value_len > 0) {
- value = malloc(icapa.value_len + 1);
- if (value == NULL) {
- free(key);
- return got_error_from_errno("malloc");
- }
- }
-
- memcpy(key, imsg->data + sizeof(icapa), icapa.key_len);
- key[icapa.key_len] = '\0';
- if (value) {
- memcpy(value, imsg->data + sizeof(icapa) + icapa.key_len,
- icapa.value_len);
- value[icapa.value_len] = '\0';
- }
-
- if (strcmp(key, GOT_CAPA_AGENT) == 0)
- printf(" client user agent: %s\n", value);
- else if (value)
- printf(" client supports %s=%s\n", key, value);
- else
- printf(" client supports %s\n", key);
-
- free(key);
- free(value);
- return NULL;
-}
-
-static const struct got_error *
cmd_info(int argc, char *argv[], int gotd_sock)
{
const struct got_error *err;
case GOTD_IMSG_INFO_CLIENT:
err = show_client_info(&imsg);
break;
- case GOTD_IMSG_CAPABILITY:
- err = show_capability(&imsg);
- break;
default:
err = got_error(GOT_ERR_PRIVSEP_MSG);
break;
blob - 5859cd2493349eb8310f838afc2f0b11cdbc6f14
blob + 56c227fb60619b289a5e2680330bf0651400bac8
--- gotd/gotd.c
+++ gotd/gotd.c
struct gotd_client {
STAILQ_ENTRY(gotd_client) entry;
enum gotd_client_state state;
- struct gotd_client_capability *capabilities;
- size_t ncapa_alloc;
- size_t ncapabilities;
uint32_t id;
int fd;
struct gotd_imsgev iev;
close(client->fd);
else if (client->iev.ibuf.fd != -1)
close(client->iev.ibuf.fd);
- free(client->capabilities);
free(client);
client_cnt--;
}
err = got_error_from_errno("imsg compose INFO_REPO");
if (err)
return err;
- }
-
- return NULL;
-}
-
-static const struct got_error *
-send_capability(struct gotd_client_capability *capa, struct gotd_imsgev* iev)
-{
- const struct got_error *err = NULL;
- struct gotd_imsg_capability icapa;
- size_t len;
- struct ibuf *wbuf;
-
- memset(&icapa, 0, sizeof(icapa));
-
- icapa.key_len = strlen(capa->key);
- len = sizeof(icapa) + icapa.key_len;
- if (capa->value) {
- icapa.value_len = strlen(capa->value);
- len += icapa.value_len;
- }
-
- wbuf = imsg_create(&iev->ibuf, GOTD_IMSG_CAPABILITY, 0, 0, len);
- if (wbuf == NULL) {
- err = got_error_from_errno("imsg_create CAPABILITY");
- return err;
}
-
- if (imsg_add(wbuf, &icapa, sizeof(icapa)) == -1)
- return got_error_from_errno("imsg_add CAPABILITY");
- if (imsg_add(wbuf, capa->key, icapa.key_len) == -1)
- return got_error_from_errno("imsg_add CAPABILITY");
- if (capa->value) {
- if (imsg_add(wbuf, capa->value, icapa.value_len) == -1)
- return got_error_from_errno("imsg_add CAPABILITY");
- }
-
- wbuf->fd = -1;
- imsg_close(&iev->ibuf, wbuf);
- gotd_imsg_event_add(iev);
-
return NULL;
}
const struct got_error *err = NULL;
struct gotd_imsg_info_client iclient;
struct gotd_child_proc *proc;
- size_t i;
memset(&iclient, 0, sizeof(iclient));
iclient.euid = client->euid;
iclient.state = client->state;
if (client->session)
iclient.session_child_pid = client->session->pid;
- iclient.ncapabilities = client->ncapabilities;
if (gotd_imsg_compose_event(iev, GOTD_IMSG_INFO_CLIENT, PROC_GOTD, -1,
&iclient, sizeof(iclient)) == -1) {
err = got_error_from_errno("imsg compose INFO_CLIENT");
- if (err)
- return err;
- }
-
- for (i = 0; i < client->ncapabilities; i++) {
- struct gotd_client_capability *capa;
- capa = &client->capabilities[i];
- err = send_capability(capa, iev);
if (err)
return err;
}
blob - 3f6ddfc81056dd0933a199322c90fe6b5e8296b0
blob + 3c7194f856798d1eab7423b732b4dad29644e13e
--- gotd/gotd.h
+++ gotd/gotd.h
enum gotd_client_state state;
pid_t session_child_pid;
pid_t repo_child_pid;
- size_t ncapabilities;
-
- /* Followed by ncapabilities GOTD_IMSG_CAPABILITY. */
};
/* Structure for GOTD_IMSG_LIST_REFS. */