diff options
author | Simo Sorce <simo@redhat.com> | 2014-08-14 17:48:02 -0400 |
---|---|---|
committer | Günther Deschner <gdeschner@redhat.com> | 2014-09-15 13:09:56 +0200 |
commit | 57a9447610eb29c72f606a59d10c211c8d7f41e6 (patch) | |
tree | faf961eb52b6a18dcfa9b5e94b64f81b6d415221 /proxy/tests/t_utils.c | |
parent | 38a158446d1f9ce495715aa83265fe35a29f8a2b (diff) | |
download | gss-proxy-57a9447610eb29c72f606a59d10c211c8d7f41e6.tar.gz gss-proxy-57a9447610eb29c72f606a59d10c211c8d7f41e6.tar.xz gss-proxy-57a9447610eb29c72f606a59d10c211c8d7f41e6.zip |
Add a test framework for gss-proxy
This sets up a kdc using socket_wrapper and nss_wrapper from the cwrap
project, and uses a dirty hack to force gssapi to load the current
proxymech interposer library.
It provisions a service and a user key then runs the interpostest binary
in this artifical environment.
Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Guenther Deschner <gdeschner@redhat.com>
Diffstat (limited to 'proxy/tests/t_utils.c')
-rw-r--r-- | proxy/tests/t_utils.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/proxy/tests/t_utils.c b/proxy/tests/t_utils.c new file mode 100644 index 0000000..f4446fa --- /dev/null +++ b/proxy/tests/t_utils.c @@ -0,0 +1,109 @@ +/* Copyright (C) 2014 the GSS-PROXY contributors, see COPYING for license */ + +#include "t_utils.h" +#include <arpa/inet.h> +#include <unistd.h> +#include <errno.h> + +int t_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 t_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; +} + +void t_log_failure(gss_OID mech, uint32_t maj, uint32_t min) +{ + uint32_t msgctx; + uint32_t discard; + gss_buffer_desc tmp; + + fprintf(stderr, "Failed with:"); + + if (mech != GSS_C_NO_OID) { + gss_oid_to_str(&discard, mech, &tmp); + fprintf(stderr, " (OID: %s)", (char *)tmp.value); + gss_release_buffer(&discard, &tmp); + } + + msgctx = 0; + gss_display_status(&discard, maj, GSS_C_GSS_CODE, mech, &msgctx, &tmp); + fprintf(stderr, " %s,", (char *)tmp.value); + gss_release_buffer(&discard, &tmp); + + msgctx = 0; + gss_display_status(&discard, min, GSS_C_MECH_CODE, mech, &msgctx, &tmp); + fprintf(stderr, " %s\n", (char *)tmp.value); + gss_release_buffer(&discard, &tmp); +} + +int t_string_to_name(const char *string, gss_name_t *name) +{ + gss_buffer_desc target_buf; + uint32_t ret_maj; + uint32_t ret_min; + + target_buf.value = strdup(string); + target_buf.length = strlen(string) + 1; + + ret_maj = gss_import_name(&ret_min, &target_buf, + GSS_C_NT_HOSTBASED_SERVICE, name); + free(target_buf.value); + return ret_maj; +} |