-/* $OpenBSD: connection.c,v 1.14 2014/04/20 16:49:56 claudio Exp $ */
+/* $OpenBSD: connection.c,v 1.15 2014/04/20 18:17:12 claudio Exp $ */
/*
* Copyright (c) 2009 Claudio Jeker <claudio@openbsd.org>
if (kvp && i < *nkvp) {
kvp[i].key = strdup("MaxConnections");
if (kvp[i].key == NULL)
- return (-1);
+ return -1;
if (asprintf(&kvp[i].value, "%hu",
s->mine.MaxConnections) == -1) {
kvp[i].value = NULL;
- return (-1);
+ return -1;
}
}
i++;
if (kvp && i < *nkvp) {
kvp[i].key = strdup("MaxRecvDataSegmentLength");
if (kvp[i].key == NULL)
- return (-1);
+ return -1;
if (asprintf(&kvp[i].value, "%u",
c->mine.MaxRecvDataSegmentLength) == -1) {
kvp[i].value = NULL;
- return (-1);
+ return -1;
}
}
i++;
}
*nkvp = i;
- return (0);
+ return 0;
}
void
log_warnx("connect(%s), lost socket",
log_sockaddr(&c->config.TargetAddr));
session_fsm(c->session, SESS_EV_CONN_FAIL, c);
- return (CONN_FREE);
+ return CONN_FREE;
}
if (connect(c->fd, (struct sockaddr *)&c->config.TargetAddr,
c->config.TargetAddr.ss_len) == -1) {
if (errno == EINPROGRESS) {
event_add(&c->wev, NULL);
- return (CONN_XPT_WAIT);
+ return CONN_XPT_WAIT;
} else {
log_warn("connect(%s)",
log_sockaddr(&c->config.TargetAddr));
session_fsm(c->session, SESS_EV_CONN_FAIL, c);
- return (CONN_FREE);
+ return CONN_FREE;
}
}
/* move forward */
- return (c_do_login(c, CONN_EV_CONNECTED));
+ return c_do_login(c, CONN_EV_CONNECTED);
}
int
{
/* start a login session and hope for the best ... */
initiator_login(c);
- return (CONN_IN_LOGIN);
+ return CONN_IN_LOGIN;
}
int
{
session_fsm(c->session, SESS_EV_CONN_LOGGED_IN, c);
- return (CONN_LOGGED_IN);
+ return CONN_LOGGED_IN;
}
int
c_do_logout(struct connection *c, enum c_event ev)
{
/* logout is in progress ... */
- return (CONN_IN_LOGOUT);
+ return CONN_IN_LOGOUT;
}
int
close(c->fd);
/* session is informed by the logout handler */
- return (CONN_FREE);
+ return CONN_FREE;
}
int
session_fsm(c->session, SESS_EV_CONN_FAIL, c);
if (ev == CONN_EV_FREE || c->state & CONN_NEVER_LOGGED_IN)
- return (CONN_FREE);
- return (CONN_CLEANUP_WAIT);
+ return CONN_FREE;
+ return CONN_CLEANUP_WAIT;
}
const char *
-/* $OpenBSD: control.c,v 1.6 2014/04/19 18:31:33 claudio Exp $ */
+/* $OpenBSD: control.c,v 1.7 2014/04/20 18:17:12 claudio Exp $ */
/*
* Copyright (c) 2010 Claudio Jeker <claudio@openbsd.org>
if ((control_state = calloc(1, sizeof(*control_state))) == NULL) {
log_warn("control_init: calloc");
- return (-1);
+ return -1;
}
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
log_warn("control_init: socket");
- return (-1);
+ return -1;
}
bzero(&sun, sizeof(sun));
sun.sun_family = AF_UNIX;
- strlcpy(sun.sun_path, path, sizeof(sun.sun_path));
+ if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
+ sizeof(sun.sun_path)) {
+ log_warnx("control_init: path %s too long", path);
+ return -1;
+ }
if (unlink(path) == -1)
if (errno != ENOENT) {
log_warn("control_init: unlink %s", path);
close(fd);
- return (-1);
+ return -1;
}
old_umask = umask(S_IXUSR|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH);
log_warn("control_init: bind: %s", path);
close(fd);
umask(old_umask);
- return (-1);
+ return -1;
}
umask(old_umask);
log_warn("control_init: chmod");
close(fd);
(void)unlink(path);
- return (-1);
+ return -1;
}
if (listen(fd, CONTROL_BACKLOG) == -1) {
log_warn("control_init: listen");
close(fd);
(void)unlink(path);
- return (-1);
+ return -1;
}
socket_setblockmode(fd, 1);
control_state->fd = fd;
TAILQ_INIT(&controls);
- return (0);
+ return 0;
}
void
-/* $OpenBSD: pdu.c,v 1.7 2014/04/19 18:31:33 claudio Exp $ */
+/* $OpenBSD: pdu.c,v 1.8 2014/04/20 18:17:12 claudio Exp $ */
/*
* Copyright (c) 2009 Claudio Jeker <claudio@openbsd.org>
int n, nk;
if (k == NULL)
- return (0);
+ return 0;
nk = 0;
while(k[nk].key) {
if (error)
ull = 0;
- return (ull);
+ return ull;
#undef INVALID
#undef TOOSMALL
#undef TOOLARGE
else
*errstrp = "invalid";
}
- return (val);
+ return val;
}
if (c->prbuf.wpos >= c->prbuf.size)
c->prbuf.wpos -= c->prbuf.size;
- return (n);
+ return n;
}
ssize_t
size_t l;
if (rb->rpos == rb->wpos) {
- return (0);
+ return 0;
} else if (rb->rpos < rb->wpos) {
l = PDU_MIN(rb->wpos - rb->rpos, len);
memcpy(ptr, rb->buf + rb->rpos, l);