diff options
author | Simo Sorce <simo@redhat.com> | 2015-11-12 17:37:57 -0500 |
---|---|---|
committer | Robbie Harwood <rharwood@redhat.com> | 2015-12-01 17:54:02 -0500 |
commit | e5d0a2d58044042bd18103c934b98954d66653f9 (patch) | |
tree | b3efa2006836728e226b78d4a93b3b89af6becf3 /proxy/tests/interposetest.c | |
parent | ed62abc6def520fdc36798dbed4e26be7470ca39 (diff) | |
download | gss-proxy-e5d0a2d58044042bd18103c934b98954d66653f9.tar.gz gss-proxy-e5d0a2d58044042bd18103c934b98954d66653f9.tar.xz gss-proxy-e5d0a2d58044042bd18103c934b98954d66653f9.zip |
Use t_utils.h in all tests.
Avoid duplicating the same helper functions everywhere.
Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Robbie Harwoood <rharwood@redhat.com>
Diffstat (limited to 'proxy/tests/interposetest.c')
-rw-r--r-- | proxy/tests/interposetest.c | 109 |
1 files changed, 21 insertions, 88 deletions
diff --git a/proxy/tests/interposetest.c b/proxy/tests/interposetest.c index 678bee7..d904002 100644 --- a/proxy/tests/interposetest.c +++ b/proxy/tests/interposetest.c @@ -17,81 +17,12 @@ #include "src/gp_log.h" #include "popt.h" #include <libintl.h> +#include "t_utils.h" -#define MAX_RPC_SIZE 1024*1024 #define _(STRING) gettext(STRING) static const char *actor = "<not set>"; - -#define DEBUG(...) do { \ - char msg[4096]; \ - snprintf(msg, 4096, __VA_ARGS__); \ - fprintf(stderr, "%s line %d: %s", actor, __LINE__, msg); \ - fflush(stderr); \ -} while(0); - -static 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; -} - -static 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; -} +const char **argv; static int gptest_inq_context(gss_ctx_id_t ctx) { @@ -252,7 +183,7 @@ void run_client(struct aproc *data) } 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) { DEBUG("Failed to send data to server!\n"); @@ -269,7 +200,7 @@ void run_client(struct aproc *data) 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) { DEBUG("Failed to receive data from server!\n"); goto done; @@ -312,7 +243,7 @@ void run_client(struct aproc *data) goto done; } - ret = gp_send_buffer(data->srv_pipe[1], out_token.value, out_token.length); + ret = t_send_buffer(data->srv_pipe[1], out_token.value, out_token.length); if (ret) { DEBUG("Failed to send data to server!\n"); goto done; @@ -320,7 +251,7 @@ void run_client(struct aproc *data) gss_release_buffer(&ret_min, &out_token); - ret = gp_recv_buffer(data->cli_pipe[0], buffer, &buflen); + ret = t_recv_buffer(data->cli_pipe[0], buffer, &buflen); if (ret) { DEBUG("Failed to receive data from server!\n"); goto done; @@ -330,7 +261,7 @@ void run_client(struct aproc *data) buffer[buflen] = '\0'; in_token.value = (void *)&buffer[buflen + 1]; - ret = gp_recv_buffer(data->cli_pipe[0], in_token.value, &buflen); + ret = t_recv_buffer(data->cli_pipe[0], in_token.value, &buflen); if (ret) { DEBUG("Failed to receive data from server!\n"); goto done; @@ -397,13 +328,13 @@ void run_client(struct aproc *data) goto done; } - ret = gp_send_buffer(data->srv_pipe[1], iov[0].buffer.value, iov[0].buffer.length); + ret = t_send_buffer(data->srv_pipe[1], iov[0].buffer.value, iov[0].buffer.length); if (ret) { DEBUG("Failed to send data to server!\n"); goto done; } - ret = gp_send_buffer(data->srv_pipe[1], iov[1].buffer.value, iov[1].buffer.length); + ret = t_send_buffer(data->srv_pipe[1], iov[1].buffer.value, iov[1].buffer.length); if (ret) { DEBUG("Failed to send data to server!\n"); goto done; @@ -416,7 +347,7 @@ void run_client(struct aproc *data) goto done; } - ret = gp_send_buffer(data->srv_pipe[1], out_token.value, out_token.length); + ret = t_send_buffer(data->srv_pipe[1], out_token.value, out_token.length); if (ret) { DEBUG("Failed to send data to server!\n"); goto done; @@ -598,7 +529,7 @@ void run_server(struct aproc *data) 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; @@ -625,7 +556,7 @@ void run_server(struct aproc *data) } 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"); @@ -641,7 +572,7 @@ void run_server(struct aproc *data) 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; @@ -671,12 +602,12 @@ void run_server(struct aproc *data) goto done; } - ret = gp_send_buffer(data->cli_pipe[1], in_token.value, in_token.length); + ret = t_send_buffer(data->cli_pipe[1], in_token.value, in_token.length); if (ret) { DEBUG("Failed to send data to client!\n"); goto done; } - ret = gp_send_buffer(data->cli_pipe[1], out_token.value, out_token.length); + ret = t_send_buffer(data->cli_pipe[1], out_token.value, out_token.length); if (ret) { DEBUG("Failed to send data to client!\n"); goto done; @@ -686,7 +617,7 @@ void run_server(struct aproc *data) /* test gss_unwrap_iov */ - 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; @@ -696,7 +627,7 @@ void run_server(struct aproc *data) iov[0].buffer.value = buffer; iov[0].buffer.length = buflen; - ret = gp_recv_buffer(data->srv_pipe[0], buffer+buflen, &buflen); + ret = t_recv_buffer(data->srv_pipe[0], buffer+buflen, &buflen); if (ret) { DEBUG("Failed to get data from client!\n"); goto done; @@ -718,7 +649,7 @@ void run_server(struct aproc *data) 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; @@ -870,7 +801,7 @@ done: return ret; } -int main(int argc, const char *argv[]) +int main(int argc, const char *main_argv[]) { int opt; poptContext pc; @@ -890,6 +821,8 @@ int main(int argc, const char *argv[]) POPT_TABLEEND }; + argv = main_argv; + pc = poptGetContext(argv[0], argc, argv, long_options, 0); while((opt = poptGetNextOpt(pc)) != -1) { switch(opt) { |