Blame src/tests/gssapi/t_bindings.c

rpm-build c2b31c
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
rpm-build c2b31c
/*
rpm-build c2b31c
 * Copyright (C) 2020 by Red Hat, Inc.
rpm-build c2b31c
 * All rights reserved.
rpm-build c2b31c
 *
rpm-build c2b31c
 * Redistribution and use in source and binary forms, with or without
rpm-build c2b31c
 * modification, are permitted provided that the following conditions
rpm-build c2b31c
 * are met:
rpm-build c2b31c
 *
rpm-build c2b31c
 * * Redistributions of source code must retain the above copyright
rpm-build c2b31c
 *   notice, this list of conditions and the following disclaimer.
rpm-build c2b31c
 *
rpm-build c2b31c
 * * Redistributions in binary form must reproduce the above copyright
rpm-build c2b31c
 *   notice, this list of conditions and the following disclaimer in
rpm-build c2b31c
 *   the documentation and/or other materials provided with the
rpm-build c2b31c
 *   distribution.
rpm-build c2b31c
 *
rpm-build c2b31c
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
rpm-build c2b31c
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
rpm-build c2b31c
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
rpm-build c2b31c
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
rpm-build c2b31c
 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
rpm-build c2b31c
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
rpm-build c2b31c
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
rpm-build c2b31c
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
rpm-build c2b31c
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
rpm-build c2b31c
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
rpm-build c2b31c
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
rpm-build c2b31c
 * OF THE POSSIBILITY OF SUCH DAMAGE.
rpm-build c2b31c
 */
rpm-build c2b31c
rpm-build c2b31c
#include <stdio.h>
rpm-build c2b31c
#include <string.h>
rpm-build c2b31c
#include <assert.h>
rpm-build c2b31c
rpm-build c2b31c
#include "common.h"
rpm-build c2b31c
rpm-build c2b31c
/*
rpm-build c2b31c
 * Establish contexts (without and with GSS_C_DCE_STYLE) with the default
rpm-build c2b31c
 * initiator name, a specified principal name as target name, initiator
rpm-build c2b31c
 * bindings, and acceptor bindings.  If any call is unsuccessful, display an
rpm-build c2b31c
 * error message.  Output "yes" or "no" to indicate whether the contexts were
rpm-build c2b31c
 * reported as channel-bound on the acceptor.  Exit with status 0 if all
rpm-build c2b31c
 * operations are successful, or 1 if not.
rpm-build c2b31c
 *
rpm-build c2b31c
 * Usage: ./t_bindings [-s] targetname icb acb
rpm-build c2b31c
 *
rpm-build c2b31c
 * An icb or abc value of "-" will not specify channel bindings.
rpm-build c2b31c
 */
rpm-build c2b31c
rpm-build c2b31c
int
rpm-build c2b31c
main(int argc, char *argv[])
rpm-build c2b31c
{
rpm-build c2b31c
    OM_uint32 minor, flags1, flags2;
rpm-build c2b31c
    gss_name_t target_name;
rpm-build c2b31c
    gss_ctx_id_t ictx, actx;
rpm-build c2b31c
    struct gss_channel_bindings_struct icb_data = {0}, acb_data = {0};
rpm-build c2b31c
    gss_channel_bindings_t icb = GSS_C_NO_CHANNEL_BINDINGS;
rpm-build c2b31c
    gss_channel_bindings_t acb = GSS_C_NO_CHANNEL_BINDINGS;
rpm-build c2b31c
    gss_OID_desc *mech;
rpm-build c2b31c
rpm-build c2b31c
    argv++;
rpm-build c2b31c
    argc--;
rpm-build c2b31c
    if (*argv != NULL && strcmp(*argv, "-s") == 0) {
rpm-build c2b31c
        mech = &mech_spnego;
rpm-build c2b31c
        argv++;
rpm-build c2b31c
        argc--;
rpm-build c2b31c
    } else {
rpm-build c2b31c
        mech = &mech_krb5;
rpm-build c2b31c
    }
rpm-build c2b31c
rpm-build c2b31c
    if (argc != 3) {
rpm-build c2b31c
        fprintf(stderr, "Usage: t_bindings [-s] targetname icb acb\n");
rpm-build c2b31c
        return 1;
rpm-build c2b31c
    }
rpm-build c2b31c
rpm-build c2b31c
    target_name = import_name(argv[0]);
rpm-build c2b31c
rpm-build c2b31c
    if (strcmp(argv[1], "-") != 0) {
rpm-build c2b31c
        icb_data.application_data.length = strlen(argv[1]);
rpm-build c2b31c
        icb_data.application_data.value = argv[1];
rpm-build c2b31c
        icb = &icb_data;
rpm-build c2b31c
    }
rpm-build c2b31c
rpm-build c2b31c
    if (strcmp(argv[2], "-") != 0) {
rpm-build c2b31c
        acb_data.application_data.length = strlen(argv[2]);
rpm-build c2b31c
        acb_data.application_data.value = argv[2];
rpm-build c2b31c
        acb = &acb_data;
rpm-build c2b31c
    }
rpm-build c2b31c
rpm-build c2b31c
    establish_contexts_ex(mech, GSS_C_NO_CREDENTIAL, GSS_C_NO_CREDENTIAL,
rpm-build c2b31c
                          target_name, 0, &ictx, &actx, icb, acb, &flags1,
rpm-build c2b31c
                          NULL, NULL, NULL);
rpm-build c2b31c
rpm-build c2b31c
    /* Try again with GSS_C_DCE_STYLE */
rpm-build c2b31c
    (void)gss_delete_sec_context(&minor, &ictx, NULL);
rpm-build c2b31c
    (void)gss_delete_sec_context(&minor, &actx, NULL);
rpm-build c2b31c
rpm-build c2b31c
    establish_contexts_ex(mech, GSS_C_NO_CREDENTIAL, GSS_C_NO_CREDENTIAL,
rpm-build c2b31c
                          target_name, GSS_C_DCE_STYLE, &ictx, &actx, icb, acb,
rpm-build c2b31c
                          &flags2, NULL, NULL, NULL);
rpm-build c2b31c
    assert((flags1 & GSS_C_CHANNEL_BOUND_FLAG) ==
rpm-build c2b31c
           (flags2 & GSS_C_CHANNEL_BOUND_FLAG));
rpm-build c2b31c
    printf("%s\n", (flags1 & GSS_C_CHANNEL_BOUND_FLAG) ? "yes" : "no");
rpm-build c2b31c
rpm-build c2b31c
    (void)gss_delete_sec_context(&minor, &ictx, NULL);
rpm-build c2b31c
    (void)gss_delete_sec_context(&minor, &actx, NULL);
rpm-build c2b31c
    (void)gss_release_name(&minor, &target_name);
rpm-build c2b31c
rpm-build c2b31c
    return 0;
rpm-build c2b31c
}