Path: blob/main/crypto/krb5/src/tests/gssapi/t_store_cred.c
34914 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* tests/gssapi/t_store_cred.c - gss_store_cred() test harness */2/*3* Copyright (C) 2021 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/*33* Usage: t_store_cred [-d] [-i] [-o] src_ccname [dest_ccname]34*35* Acquires creds from src_ccname using gss_acquire_cred_from() and then stores36* them, using gss_store_cred_into() if -i is specified or gss_store_cred()37* otherwise. If dest_ccname is specified with -i, it is included in the cred38* store for the store operation; if it is specified without -i, it is set with39* gss_krb5_ccache_name() before the store operation. If -d and/or -o are40* specified they set the default_cred and overwrite_cred flags to true41* respectively.42*/4344#include "k5-platform.h"45#include <gssapi/gssapi_ext.h>46#include "common.h"4748int49main(int argc, char *argv[])50{51OM_uint32 major, minor;52gss_key_value_set_desc store;53gss_key_value_element_desc elem;54gss_cred_id_t cred;55krb5_boolean def = FALSE, into = FALSE, overwrite = FALSE;56const char *src_ccname, *dest_ccname;57int c;5859/* Parse arguments. */60while ((c = getopt(argc, argv, "dio")) != -1) {61switch (c) {62case 'd':63def = TRUE;64break;65case 'i':66into = TRUE;67break;68case 'o':69overwrite = TRUE;70break;71default:72abort();73}74}75argc -= optind;76argv += optind;77assert(argc == 1 || argc == 2);78src_ccname = argv[0];79dest_ccname = argv[1];8081elem.key = "ccache";82elem.value = src_ccname;83store.count = 1;84store.elements = &elem;85major = gss_acquire_cred_from(&minor, GSS_C_NO_NAME, GSS_C_INDEFINITE,86&mechset_krb5, GSS_C_INITIATE, &store, &cred,87NULL, NULL);88check_gsserr("acquire_cred", major, minor);8990if (into) {91if (dest_ccname != NULL) {92elem.key = "ccache";93elem.value = dest_ccname;94store.count = 1;95} else {96store.count = 0;97}98major = gss_store_cred_into(&minor, cred, GSS_C_INITIATE, &mech_krb5,99overwrite, def, &store, NULL, NULL);100check_gsserr("store_cred_into", major, minor);101} else {102if (dest_ccname != NULL) {103major = gss_krb5_ccache_name(&minor, dest_ccname, NULL);104check_gsserr("ccache_name", major, minor);105}106major = gss_store_cred(&minor, cred, GSS_C_INITIATE, &mech_krb5,107overwrite, def, NULL, NULL);108check_gsserr("store_cred", major, minor);109}110111gss_release_cred(&minor, &cred);112return 0;113}114115116