mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-03-11 07:17:02 +08:00
Use 32-bit length variable for transferring between occtl and ocserv
This allows to handle the transfer of long data between ocserv and occtl. Reported by Liviu. Resolves #29
This commit is contained in:
@@ -95,26 +95,27 @@ int send_cmd(struct unix_ctx *ctx, unsigned cmd, const void *data,
|
||||
struct iovec iov[2];
|
||||
unsigned iov_len = 1;
|
||||
int e, ret;
|
||||
uint16_t length = 0;
|
||||
uint16_t rlength = 0;
|
||||
uint32_t length32 = 0;
|
||||
void *packed = NULL;
|
||||
|
||||
if (get_size)
|
||||
length = get_size(data);
|
||||
rlength = get_size(data);
|
||||
|
||||
header[0] = cmd;
|
||||
memcpy(&header[1], &length, 2);
|
||||
memcpy(&header[1], &rlength, 2);
|
||||
|
||||
iov[0].iov_base = header;
|
||||
iov[0].iov_len = 3;
|
||||
|
||||
if (data != NULL) {
|
||||
packed = talloc_size(ctx, length);
|
||||
packed = talloc_size(ctx, rlength);
|
||||
if (packed == NULL) {
|
||||
fprintf(stderr, "memory error\n");
|
||||
return -1;
|
||||
}
|
||||
iov[1].iov_base = packed;
|
||||
iov[1].iov_len = length;
|
||||
iov[1].iov_len = rlength;
|
||||
|
||||
ret = pack(data, packed);
|
||||
if (ret == 0) {
|
||||
@@ -134,7 +135,7 @@ int send_cmd(struct unix_ctx *ctx, unsigned cmd, const void *data,
|
||||
}
|
||||
|
||||
if (rep != NULL) {
|
||||
ret = force_read_timeout(ctx->fd, header, 3, DEFAULT_TIMEOUT);
|
||||
ret = force_read_timeout(ctx->fd, header, 1+sizeof(length32), DEFAULT_TIMEOUT);
|
||||
if (ret == -1) {
|
||||
/*e = errno;
|
||||
fprintf(stderr, "read: %s\n", strerror(e));*/
|
||||
@@ -142,7 +143,7 @@ int send_cmd(struct unix_ctx *ctx, unsigned cmd, const void *data,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (ret != 3) {
|
||||
if (ret != 1+sizeof(length32)) {
|
||||
fprintf(stderr, "short read %d\n", ret);
|
||||
ret = -1;
|
||||
goto fail;
|
||||
@@ -156,17 +157,17 @@ int send_cmd(struct unix_ctx *ctx, unsigned cmd, const void *data,
|
||||
goto fail;
|
||||
}
|
||||
|
||||
memcpy(&length, &header[1], 2);
|
||||
memcpy(&length32, &header[1], 4);
|
||||
|
||||
rep->data_size = length;
|
||||
rep->data = talloc_size(ctx, length);
|
||||
rep->data_size = length32;
|
||||
rep->data = talloc_size(ctx, length32);
|
||||
if (rep->data == NULL) {
|
||||
fprintf(stderr, "memory error\n");
|
||||
ret = -1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = force_read_timeout(ctx->fd, rep->data, length, DEFAULT_TIMEOUT);
|
||||
ret = force_read_timeout(ctx->fd, rep->data, length32, DEFAULT_TIMEOUT);
|
||||
if (ret == -1) {
|
||||
e = errno;
|
||||
talloc_free(rep->data);
|
||||
@@ -1063,7 +1064,7 @@ int handle_events_cmd(struct unix_ctx *ctx, const char *arg, cmd_params_st *para
|
||||
struct cmd_reply_st raw;
|
||||
UserListRep *rep1 = NULL;
|
||||
TopUpdateRep *rep2 = NULL;
|
||||
uint16_t length;
|
||||
uint32_t slength;
|
||||
unsigned data_size;
|
||||
uint8_t *data = NULL;
|
||||
char *groupname;
|
||||
@@ -1113,7 +1114,7 @@ int handle_events_cmd(struct unix_ctx *ctx, const char *arg, cmd_params_st *para
|
||||
|
||||
if (ret == -1) {
|
||||
int e = errno;
|
||||
fprintf(stderr, "top: select: %s\n", strerror(e));
|
||||
fprintf(stderr, "events: select: %s\n", strerror(e));
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
@@ -1129,46 +1130,46 @@ int handle_events_cmd(struct unix_ctx *ctx, const char *arg, cmd_params_st *para
|
||||
if (!FD_ISSET(ctx->fd, &rfds))
|
||||
continue;
|
||||
|
||||
ret = read(ctx->fd, header, 3);
|
||||
ret = force_read_timeout(ctx->fd, header, 1+sizeof(slength), DEFAULT_TIMEOUT);
|
||||
if (ret == -1) {
|
||||
int e = errno;
|
||||
fprintf(stderr, "top: read1: %s\n", strerror(e));
|
||||
fprintf(stderr, "events: read1: %s\n", strerror(e));
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
fprintf(stderr, "top: server closed the connection\n");
|
||||
fprintf(stderr, "events: server closed the connection\n");
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret != 3) {
|
||||
fprintf(stderr, "top: short read %d\n", ret);
|
||||
if (ret != 1+sizeof(slength)) {
|
||||
fprintf(stderr, "events: short read %d\n", ret);
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (header[0] != CTL_CMD_TOP_UPDATE_REP) {
|
||||
fprintf(stderr, "top: Unexpected message '%d', expected '%d'\n", (int)header[0], (int)CTL_CMD_TOP_UPDATE_REP);
|
||||
fprintf(stderr, "events: Unexpected message '%d', expected '%d'\n", (int)header[0], (int)CTL_CMD_TOP_UPDATE_REP);
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
memcpy(&length, &header[1], 2);
|
||||
memcpy(&slength, &header[1], sizeof(slength));
|
||||
|
||||
data_size = length;
|
||||
data = talloc_size(ctx, length);
|
||||
data_size = slength;
|
||||
data = talloc_size(ctx, slength);
|
||||
if (data == NULL) {
|
||||
fprintf(stderr, "top: memory error\n");
|
||||
fprintf(stderr, "events: memory error\n");
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
ret = read(ctx->fd, data, data_size);
|
||||
ret = force_read(ctx->fd, data, data_size);
|
||||
if (ret == -1) {
|
||||
int e = errno;
|
||||
fprintf(stderr, "top: read: %s\n", strerror(e));
|
||||
fprintf(stderr, "events: read: %s\n", strerror(e));
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user