Blame src/tests/gssapi/t_accname.c

Packit fd8b60
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
Packit fd8b60
/*
Packit fd8b60
 * Copyright 2011 by the Massachusetts Institute of Technology.
Packit fd8b60
 * All Rights Reserved.
Packit fd8b60
 *
Packit fd8b60
 * Export of this software from the United States of America may
Packit fd8b60
 *   require a specific license from the United States Government.
Packit fd8b60
 *   It is the responsibility of any person or organization contemplating
Packit fd8b60
 *   export to obtain such a license before exporting.
Packit fd8b60
 *
Packit fd8b60
 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
Packit fd8b60
 * distribute this software and its documentation for any purpose and
Packit fd8b60
 * without fee is hereby granted, provided that the above copyright
Packit fd8b60
 * notice appear in all copies and that both that copyright notice and
Packit fd8b60
 * this permission notice appear in supporting documentation, and that
Packit fd8b60
 * the name of M.I.T. not be used in advertising or publicity pertaining
Packit fd8b60
 * to distribution of the software without specific, written prior
Packit fd8b60
 * permission.  Furthermore if you modify this software you must label
Packit fd8b60
 * your software as modified software and not distribute it in such a
Packit fd8b60
 * fashion that it might be confused with the original M.I.T. software.
Packit fd8b60
 * M.I.T. makes no representations about the suitability of
Packit fd8b60
 * this software for any purpose.  It is provided "as is" without express
Packit fd8b60
 * or implied warranty.
Packit fd8b60
 */
Packit fd8b60
Packit fd8b60
#include <stdio.h>
Packit fd8b60
#include <stdlib.h>
Packit fd8b60
Packit fd8b60
#include "common.h"
Packit fd8b60
Packit fd8b60
/*
Packit fd8b60
 * Test program for acceptor names, intended to be run from a Python test
Packit fd8b60
 * script.  Establishes contexts with the default initiator name, a specified
Packit fd8b60
 * principal name as target name, and a specified host-based name as acceptor
Packit fd8b60
 * name (or GSS_C_NO_NAME if no acceptor name is given).  If the exchange is
Packit fd8b60
 * successful, queries the context for the acceptor name and prints it.  If any
Packit fd8b60
 * call is unsuccessful, displays an error message.  Exits with status 0 if all
Packit fd8b60
 * operations are successful, or 1 if not.
Packit fd8b60
 *
Packit fd8b60
 * Usage: ./t_accname targetname [acceptorname]
Packit fd8b60
 */
Packit fd8b60
Packit fd8b60
int
Packit fd8b60
main(int argc, char *argv[])
Packit fd8b60
{
Packit fd8b60
    OM_uint32 minor, major, flags;
Packit fd8b60
    gss_cred_id_t acceptor_cred;
Packit fd8b60
    gss_name_t target_name, acceptor_name = GSS_C_NO_NAME, real_acceptor_name;
Packit fd8b60
    gss_buffer_desc namebuf;
Packit fd8b60
    gss_ctx_id_t initiator_context, acceptor_context;
Packit fd8b60
Packit fd8b60
    if (argc < 2 || argc > 3) {
Packit fd8b60
        fprintf(stderr, "Usage: %s targetname [acceptorname]\n", argv[0]);
Packit fd8b60
        return 1;
Packit fd8b60
    }
Packit fd8b60
Packit fd8b60
    /* Import target and acceptor names. */
Packit fd8b60
    target_name = import_name(argv[1]);
Packit fd8b60
    if (argc >= 3)
Packit fd8b60
        acceptor_name = import_name(argv[2]);
Packit fd8b60
Packit fd8b60
    /* Get acceptor cred. */
Packit fd8b60
    major = gss_acquire_cred(&minor, acceptor_name, GSS_C_INDEFINITE,
Packit fd8b60
                             GSS_C_NO_OID_SET, GSS_C_ACCEPT,
Packit fd8b60
                             &acceptor_cred, NULL, NULL);
Packit fd8b60
    check_gsserr("gss_acquire_cred", major, minor);
Packit fd8b60
Packit fd8b60
    flags = GSS_C_REPLAY_FLAG | GSS_C_SEQUENCE_FLAG;
Packit fd8b60
    establish_contexts(&mech_krb5, GSS_C_NO_CREDENTIAL, acceptor_cred,
Packit fd8b60
                       target_name, flags, &initiator_context,
Packit fd8b60
                       &acceptor_context, NULL, NULL, NULL);
Packit fd8b60
Packit fd8b60
    major = gss_inquire_context(&minor, acceptor_context, NULL,
Packit fd8b60
                                &real_acceptor_name, NULL, NULL, NULL, NULL,
Packit fd8b60
                                NULL);
Packit fd8b60
    check_gsserr("gss_inquire_context", major, minor);
Packit fd8b60
Packit fd8b60
    namebuf.value = NULL;
Packit fd8b60
    namebuf.length = 0;
Packit fd8b60
    major = gss_display_name(&minor, real_acceptor_name, &namebuf, NULL);
Packit fd8b60
    check_gsserr("gss_display_name", major, minor);
Packit fd8b60
Packit fd8b60
    printf("%.*s\n", (int)namebuf.length, (char *)namebuf.value);
Packit fd8b60
Packit fd8b60
    (void)gss_release_name(&minor, &target_name);
Packit fd8b60
    (void)gss_release_name(&minor, &acceptor_name);
Packit fd8b60
    (void)gss_release_name(&minor, &real_acceptor_name);
Packit fd8b60
    (void)gss_release_cred(&minor, &acceptor_cred);
Packit fd8b60
    (void)gss_delete_sec_context(&minor, &initiator_context, NULL);
Packit fd8b60
    (void)gss_delete_sec_context(&minor, &acceptor_context, NULL);
Packit fd8b60
    (void)gss_release_buffer(&minor, &namebuf);
Packit fd8b60
    return 0;
Packit fd8b60
}