From 57a9447610eb29c72f606a59d10c211c8d7f41e6 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Thu, 14 Aug 2014 17:48:02 -0400 Subject: 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 Reviewed-by: Guenther Deschner --- proxy/tests/t_utils.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 proxy/tests/t_utils.c (limited to 'proxy/tests/t_utils.c') 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 +#include +#include + +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; +} -- cgit