Path: blob/main/crypto/krb5/src/tests/gssapi/t_iakerb.c
34914 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* tests/gssapi/t_iakerb.c - IAKERB tests */2/*3* Copyright (C) 2024, 2025 by the Massachusetts Institute of Technology.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9*10* * Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12*13* * Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in15* the documentation and/or other materials provided with the16* distribution.17*18* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS19* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT20* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS21* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE22* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,23* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES24* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR25* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,27* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)28* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED29* OF THE POSSIBILITY OF SUCH DAMAGE.30*/3132#include <stdio.h>33#include <string.h>34#include "common.h"3536int37main(int argc, char **argv)38{39OM_uint32 major, minor;40const char *password;41gss_name_t iname, tname, aname;42gss_cred_id_t icred, acred;43gss_ctx_id_t ictx, actx;44gss_buffer_desc pwbuf;4546if (argc != 5) {47fprintf(stderr, "Usage: %s initiatorname password|- targetname "48"acceptorname\n", argv[0]);49return 1;50}5152iname = import_name(argv[1]);53password = argv[2];54tname = import_name(argv[3]);55aname = import_name(argv[4]);5657if (strcmp(password, "-") != 0) {58pwbuf.value = (void *)password;59pwbuf.length = strlen(password);60major = gss_acquire_cred_with_password(&minor, iname, &pwbuf, 0,61&mechset_iakerb, GSS_C_INITIATE,62&icred, NULL, NULL);63check_gsserr("gss_acquire_cred_with_password", major, minor);64} else {65major = gss_acquire_cred(&minor, iname, GSS_C_INDEFINITE,66&mechset_iakerb, GSS_C_INITIATE, &icred, NULL,67NULL);68check_gsserr("gss_acquire_cred(iname)", major, minor);69}7071major = gss_acquire_cred(&minor, aname, GSS_C_INDEFINITE, &mechset_iakerb,72GSS_C_ACCEPT, &acred, NULL, NULL);73check_gsserr("gss_acquire_cred(aname)", major, minor);7475establish_contexts(&mech_iakerb, icred, acred, tname, 0, &ictx, &actx,76NULL, NULL, NULL);7778(void)gss_release_name(&minor, &iname);79(void)gss_release_name(&minor, &tname);80(void)gss_release_name(&minor, &aname);81(void)gss_release_cred(&minor, &icred);82(void)gss_release_cred(&minor, &acred);83(void)gss_delete_sec_context(&minor, &ictx, NULL);84(void)gss_delete_sec_context(&minor, &actx, NULL);85return 0;86}878889