Path: blob/main/crypto/krb5/src/tests/gssapi/t_accname.c
34914 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/*2* Copyright 2011 by the Massachusetts Institute of Technology.3* All Rights Reserved.4*5* Export of this software from the United States of America may6* require a specific license from the United States Government.7* It is the responsibility of any person or organization contemplating8* export to obtain such a license before exporting.9*10* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and11* distribute this software and its documentation for any purpose and12* without fee is hereby granted, provided that the above copyright13* notice appear in all copies and that both that copyright notice and14* this permission notice appear in supporting documentation, and that15* the name of M.I.T. not be used in advertising or publicity pertaining16* to distribution of the software without specific, written prior17* permission. Furthermore if you modify this software you must label18* your software as modified software and not distribute it in such a19* fashion that it might be confused with the original M.I.T. software.20* M.I.T. makes no representations about the suitability of21* this software for any purpose. It is provided "as is" without express22* or implied warranty.23*/2425#include <stdio.h>26#include <stdlib.h>2728#include "common.h"2930/*31* Test program for acceptor names, intended to be run from a Python test32* script. Establishes contexts with the default initiator name, a specified33* principal name as target name, and a specified host-based name as acceptor34* name (or GSS_C_NO_NAME if no acceptor name is given). If the exchange is35* successful, queries the context for the acceptor name and prints it. If any36* call is unsuccessful, displays an error message. Exits with status 0 if all37* operations are successful, or 1 if not.38*39* Usage: ./t_accname targetname [acceptorname]40*/4142int43main(int argc, char *argv[])44{45OM_uint32 minor, major, flags;46gss_cred_id_t acceptor_cred;47gss_name_t target_name, acceptor_name = GSS_C_NO_NAME, real_acceptor_name;48gss_buffer_desc namebuf;49gss_ctx_id_t initiator_context, acceptor_context;5051if (argc < 2 || argc > 3) {52fprintf(stderr, "Usage: %s targetname [acceptorname]\n", argv[0]);53return 1;54}5556/* Import target and acceptor names. */57target_name = import_name(argv[1]);58if (argc >= 3)59acceptor_name = import_name(argv[2]);6061/* Get acceptor cred. */62major = gss_acquire_cred(&minor, acceptor_name, GSS_C_INDEFINITE,63GSS_C_NO_OID_SET, GSS_C_ACCEPT,64&acceptor_cred, NULL, NULL);65check_gsserr("gss_acquire_cred", major, minor);6667flags = GSS_C_REPLAY_FLAG | GSS_C_SEQUENCE_FLAG;68establish_contexts(&mech_krb5, GSS_C_NO_CREDENTIAL, acceptor_cred,69target_name, flags, &initiator_context,70&acceptor_context, NULL, NULL, NULL);7172major = gss_inquire_context(&minor, acceptor_context, NULL,73&real_acceptor_name, NULL, NULL, NULL, NULL,74NULL);75check_gsserr("gss_inquire_context", major, minor);7677namebuf.value = NULL;78namebuf.length = 0;79major = gss_display_name(&minor, real_acceptor_name, &namebuf, NULL);80check_gsserr("gss_display_name", major, minor);8182printf("%.*s\n", (int)namebuf.length, (char *)namebuf.value);8384(void)gss_release_name(&minor, &target_name);85(void)gss_release_name(&minor, &acceptor_name);86(void)gss_release_name(&minor, &real_acceptor_name);87(void)gss_release_cred(&minor, &acceptor_cred);88(void)gss_delete_sec_context(&minor, &initiator_context, NULL);89(void)gss_delete_sec_context(&minor, &acceptor_context, NULL);90(void)gss_release_buffer(&minor, &namebuf);91return 0;92}939495