summaryrefslogtreecommitdiffstats
path: root/proxy/tests/cli_srv_comm.c
diff options
context:
space:
mode:
Diffstat (limited to 'proxy/tests/cli_srv_comm.c')
-rw-r--r--proxy/tests/cli_srv_comm.c103
1 files changed, 20 insertions, 83 deletions
diff --git a/proxy/tests/cli_srv_comm.c b/proxy/tests/cli_srv_comm.c
index 77fe338..45f77e5 100644
--- a/proxy/tests/cli_srv_comm.c
+++ b/proxy/tests/cli_srv_comm.c
@@ -19,77 +19,7 @@
#include "src/gp_debug.h"
#include "src/client/gssapi_gpm.h"
#include "popt.h"
-
-#define DEBUG(...) do { \
- char msg[4096]; \
- snprintf(msg, 4096, __VA_ARGS__); \
- fprintf(stderr, "%s:%d: %s", __FUNCTION__, __LINE__, msg); \
- fflush(stderr); \
-} while(0);
-
-
-int gp_send_buffer(int fd, char *buf, uint32_t len)
-{
- uint32_t size;
- size_t wn;
- size_t pos;
-
- size = htonl(len);
-
- wn = write(fd, &size, sizeof(uint32_t));
- if (wn != 4) {
- return EIO;
- }
-
- pos = 0;
- while (len > pos) {
- wn = write(fd, buf + pos, len - pos);
- if (wn == -1) {
- if (errno == EINTR) {
- continue;
- }
- return errno;
- }
- pos += wn;
- }
-
- return 0;
-}
-
-int gp_recv_buffer(int fd, char *buf, uint32_t *len)
-{
- uint32_t size;
- size_t rn;
- size_t pos;
-
- rn = read(fd, &size, sizeof(uint32_t));
- if (rn != 4) {
- return EIO;
- }
-
- *len = ntohl(size);
-
- if (*len > MAX_RPC_SIZE) {
- return EINVAL;
- }
-
- pos = 0;
- while (*len > pos) {
- rn = read(fd, buf + pos, *len - pos);
- if (rn == -1) {
- if (errno == EINTR) {
- continue;
- }
- return errno;
- }
- if (rn == 0) {
- return EIO;
- }
- pos += rn;
- }
-
- return 0;
-}
+#include "t_utils.h"
int gp_send_accept_sec_context(int fd,
gssx_arg_accept_sec_context *arg,
@@ -134,13 +64,13 @@ int gp_send_accept_sec_context(int fd,
}
/* send to proxy */
- ret = gp_send_buffer(fd, buffer, xdr_getpos(&xdr_call_ctx));
+ ret = t_send_buffer(fd, buffer, xdr_getpos(&xdr_call_ctx));
if (ret) {
return EIO;
}
/* receive answer */
- ret = gp_recv_buffer(fd, buffer, &length);
+ ret = t_recv_buffer(fd, buffer, &length);
if (ret) {
return EIO;
}
@@ -171,6 +101,7 @@ int gp_send_accept_sec_context(int fd,
}
struct athread {
+ const char **argv;
pthread_t tid;
int *cli_pipe;
int *srv_pipe;
@@ -181,6 +112,7 @@ struct athread {
void *client_thread(void *pvt)
{
+ const char **argv;
struct athread *data;
uint32_t ret_maj;
uint32_t ret_min;
@@ -198,6 +130,7 @@ void *client_thread(void *pvt)
uint32_t max_size;
data = (struct athread *)pvt;
+ argv = data->argv;
target_buf.value = (void *)data->target;
target_buf.length = strlen(data->target) + 1;
@@ -229,7 +162,7 @@ void *client_thread(void *pvt)
}
if (out_token.length != 0) {
/* send to server */
- ret = gp_send_buffer(data->srv_pipe[1],
+ ret = t_send_buffer(data->srv_pipe[1],
out_token.value, out_token.length);
if (ret) {
goto done;
@@ -244,7 +177,7 @@ void *client_thread(void *pvt)
if (ret_maj == GSS_S_CONTINUE_NEEDED) {
/* and wait for reply */
- ret = gp_recv_buffer(data->cli_pipe[0], buffer, &buflen);
+ ret = t_recv_buffer(data->cli_pipe[0], buffer, &buflen);
if (ret) {
goto done;
}
@@ -269,14 +202,14 @@ void *client_thread(void *pvt)
}
/* send msg to server */
- ret = gp_send_buffer(data->srv_pipe[1],
+ ret = t_send_buffer(data->srv_pipe[1],
msg_buf.value, msg_buf.length);
if (ret) {
goto done;
}
/* send signature to server */
- ret = gp_send_buffer(data->srv_pipe[1],
+ ret = t_send_buffer(data->srv_pipe[1],
out_token.value, out_token.length);
if (ret) {
goto done;
@@ -301,7 +234,7 @@ void *client_thread(void *pvt)
}
/* send to server */
- ret = gp_send_buffer(data->srv_pipe[1],
+ ret = t_send_buffer(data->srv_pipe[1],
out_token.value,
out_token.length);
if (ret) {
@@ -332,6 +265,7 @@ done:
void *server_thread(void *pvt)
{
+ const char **argv;
struct athread *data;
char buffer[MAX_RPC_SIZE];
uint32_t buflen;
@@ -368,6 +302,7 @@ void *server_thread(void *pvt)
int conf_state;
data = (struct athread *)pvt;
+ argv = data->argv;
target_buf.value = (void *)data->target;
target_buf.length = strlen(data->target) + 1;
@@ -471,7 +406,7 @@ void *server_thread(void *pvt)
goto done;
}
- ret = gp_recv_buffer(data->srv_pipe[0], buffer, &buflen);
+ ret = t_recv_buffer(data->srv_pipe[0], buffer, &buflen);
if (ret) {
DEBUG("Failed to get data from client!\n");
goto done;
@@ -498,7 +433,7 @@ void *server_thread(void *pvt)
}
if (out_token.length) {
- ret = gp_send_buffer(data->cli_pipe[1],
+ ret = t_send_buffer(data->cli_pipe[1],
out_token.value, out_token.length);
if (ret) {
DEBUG("Failed to send data to client!\n");
@@ -507,7 +442,7 @@ void *server_thread(void *pvt)
}
/* receive message from client */
- ret = gp_recv_buffer(data->srv_pipe[0], buffer, &buflen);
+ ret = t_recv_buffer(data->srv_pipe[0], buffer, &buflen);
if (ret) {
DEBUG("Failed to get data from client!\n");
goto done;
@@ -516,7 +451,7 @@ void *server_thread(void *pvt)
in_token.length = buflen;
/* receive signature from client */
- ret = gp_recv_buffer(data->srv_pipe[0],
+ ret = t_recv_buffer(data->srv_pipe[0],
&buffer[in_token.length], &buflen);
if (ret) {
DEBUG("Failed to get data from client!\n");
@@ -535,7 +470,7 @@ void *server_thread(void *pvt)
DEBUG("Received valid msg from client: [%s]\n", buffer);
- ret = gp_recv_buffer(data->srv_pipe[0], buffer, &buflen);
+ ret = t_recv_buffer(data->srv_pipe[0], buffer, &buflen);
if (ret) {
DEBUG("Failed to get data from client!\n");
goto done;
@@ -644,6 +579,7 @@ int main(int argc, const char *argv[])
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+ server.argv = argv;
server.srv_pipe = srv_pipe;
server.cli_pipe = cli_pipe;
server.target = opt_target;
@@ -653,6 +589,7 @@ int main(int argc, const char *argv[])
return -1;
}
+ client.argv = argv;
client.srv_pipe = srv_pipe;
client.cli_pipe = cli_pipe;
client.target = opt_target;