Path: blob/main/crypto/krb5/src/tests/gssapi/t_ccselect.c
34907 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* tests/gssapi/t_ccselect.c - Test program for GSSAPI cred selection */2/*3* Copyright 2011 by the Massachusetts Institute of Technology.4* All Rights Reserved.5*6* Export of this software from the United States of America may7* require a specific license from the United States Government.8* It is the responsibility of any person or organization contemplating9* export to obtain such a license before exporting.10*11* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and12* distribute this software and its documentation for any purpose and13* without fee is hereby granted, provided that the above copyright14* notice appear in all copies and that both that copyright notice and15* this permission notice appear in supporting documentation, and that16* the name of M.I.T. not be used in advertising or publicity pertaining17* to distribution of the software without specific, written prior18* permission. Furthermore if you modify this software you must label19* your software as modified software and not distribute it in such a20* fashion that it might be confused with the original M.I.T. software.21* M.I.T. makes no representations about the suitability of22* this software for any purpose. It is provided "as is" without express23* or implied warranty.24*/2526#include <stdio.h>27#include <stdlib.h>28#include <string.h>2930#include "common.h"3132/*33* Test program for client credential selection, intended to be run from a34* Python test script. Establishes contexts with an optionally specified35* initiator name, a specified target name, and the default acceptor cred. If36* the exchange is successful, prints the initiator name as seen by the37* acceptor. If any call is unsuccessful, displays an error message. Exits38* with status 0 if all operations are successful, or 1 if not.39*40* Usage: ./t_ccselect targetname [initiatorname|-]41*/4243int44main(int argc, char *argv[])45{46OM_uint32 minor, major, flags;47gss_cred_id_t initiator_cred = GSS_C_NO_CREDENTIAL;48gss_name_t target_name, initiator_name = GSS_C_NO_NAME;49gss_name_t real_initiator_name;50gss_buffer_desc namebuf;51gss_ctx_id_t initiator_context, acceptor_context;5253if (argc < 2 || argc > 3) {54fprintf(stderr, "Usage: %s targetname [initiatorname|-]\n", argv[0]);55return 1;56}5758target_name = import_name(argv[1]);5960if (argc >= 3) {61/* Get initiator cred. */62if (strcmp(argv[2], "-") != 0)63initiator_name = import_name(argv[2]);64major = gss_acquire_cred(&minor, initiator_name, GSS_C_INDEFINITE,65GSS_C_NO_OID_SET, GSS_C_INITIATE,66&initiator_cred, NULL, NULL);67check_gsserr("gss_acquire_cred", major, minor);68}6970flags = GSS_C_REPLAY_FLAG | GSS_C_SEQUENCE_FLAG;71establish_contexts(&mech_krb5, initiator_cred, GSS_C_NO_CREDENTIAL,72target_name, flags, &initiator_context,73&acceptor_context, &real_initiator_name, NULL, NULL);7475namebuf.value = NULL;76namebuf.length = 0;77major = gss_display_name(&minor, real_initiator_name, &namebuf, NULL);78check_gsserr("gss_display_name(initiator)", major, minor);79printf("%.*s\n", (int)namebuf.length, (char *)namebuf.value);8081(void)gss_release_name(&minor, &target_name);82(void)gss_release_name(&minor, &initiator_name);83(void)gss_release_name(&minor, &real_initiator_name);84(void)gss_release_cred(&minor, &initiator_cred);85(void)gss_delete_sec_context(&minor, &initiator_context, NULL);86(void)gss_delete_sec_context(&minor, &acceptor_context, NULL);87(void)gss_release_buffer(&minor, &namebuf);88return 0;89}909192