commit - eac23c306591c21ddaa23930159d302f668ae34c
commit + f7a854cff3b036707a2322ebff8540f29561a8a5
blob - 390d403cdcb5e59c2799c5ebfea7918257bbfa92
blob + 717b4729fac0259057de6bd02cadff694a709e40
--- gotd/gotd.c
+++ gotd/gotd.c
struct event tmo;
uid_t euid;
gid_t egid;
- struct gotd_child_proc *repo_read;
- struct gotd_child_proc *repo_write;
+ struct gotd_child_proc *repo;
struct gotd_child_proc *auth;
struct gotd_child_proc *session;
int required_auth;
return NULL;
}
-static struct gotd_child_proc *
-get_client_repo_proc(struct gotd_client *client)
-{
- if (client->repo_read && client->repo_write) {
- fatalx("uid %d is reading and writing in the same session",
- client->euid);
- /* NOTREACHED */
- }
-
- if (client->repo_read)
- return client->repo_read;
- else if (client->repo_write)
- return client->repo_write;
-
- return NULL;
-}
-
static struct gotd_client *
find_client_by_proc_fd(int fd)
{
struct gotd_client *c;
STAILQ_FOREACH(c, &gotd_clients[slot], entry) {
- struct gotd_child_proc *proc = get_client_repo_proc(c);
- if (proc && proc->iev.ibuf.fd == fd)
+ if (c->repo && c->repo->iev.ibuf.fd == fd)
return c;
if (c->auth && c->auth->iev.ibuf.fd == fd)
return c;
static int
client_is_reading(struct gotd_client *client)
{
- return client->repo_read != NULL;
+ return (client->required_auth &
+ (GOTD_AUTH_READ | GOTD_AUTH_WRITE)) == GOTD_AUTH_READ;
}
static int
client_is_writing(struct gotd_client *client)
{
- return client->repo_write != NULL;
+ return (client->required_auth &
+ (GOTD_AUTH_READ | GOTD_AUTH_WRITE)) ==
+ (GOTD_AUTH_READ | GOTD_AUTH_WRITE);
}
static const struct got_error *
disconnect(struct gotd_client *client)
{
struct gotd_imsg_disconnect idisconnect;
- struct gotd_child_proc *proc = get_client_repo_proc(client);
+ struct gotd_child_proc *proc = client->repo;
struct gotd_child_proc *listen_proc = &gotd.listen_proc;
uint64_t slot;
iclient.euid = client->euid;
iclient.egid = client->egid;
- proc = get_client_repo_proc(client);
+ proc = client->repo;
if (proc) {
if (strlcpy(iclient.repo_name, proc->repo_path,
sizeof(iclient.repo_name)) >= sizeof(iclient.repo_name)) {
struct imsg *imsg)
{
const struct got_error *err;
- struct gotd_child_proc *client_proc;
int ret = 0;
if (proc->type == PROC_REPO_READ || proc->type == PROC_REPO_WRITE) {
- client_proc = get_client_repo_proc(client);
- if (client_proc == NULL)
+ if (client->repo == NULL)
fatalx("no process found for uid %d", client->euid);
- if (proc->pid != client_proc->pid) {
+ if (proc->pid != client->repo->pid) {
kill_proc(proc, 1);
log_warnx("received message from PID %d for uid %d, "
"while PID %d is the process serving this user",
- proc->pid, client->euid, client_proc->pid);
+ proc->pid, client->euid, client->repo->pid);
return 0;
}
}
}
}
- proc = get_client_repo_proc(client);
+ proc = client->repo;
if (proc == NULL)
fatalx("cannot find child process for fd %d", fd);
gotd_dispatch_repo_child, &proc->iev);
gotd_imsg_event_add(&proc->iev);
- if (proc->type == PROC_REPO_READ)
- client->repo_read = proc;
- else
- client->repo_write = proc;
-
+ client->repo = proc;
return NULL;
}