test_acquire_cred.c revision 120945
1120945Snectar/* 2120945Snectar * Copyright (c) 2003 Kungliga Tekniska H�gskolan 3120945Snectar * (Royal Institute of Technology, Stockholm, Sweden). 4120945Snectar * All rights reserved. 5120945Snectar * 6120945Snectar * Redistribution and use in source and binary forms, with or without 7120945Snectar * modification, are permitted provided that the following conditions 8120945Snectar * are met: 9120945Snectar * 10120945Snectar * 1. Redistributions of source code must retain the above copyright 11120945Snectar * notice, this list of conditions and the following disclaimer. 12120945Snectar * 13120945Snectar * 2. Redistributions in binary form must reproduce the above copyright 14120945Snectar * notice, this list of conditions and the following disclaimer in the 15120945Snectar * documentation and/or other materials provided with the distribution. 16120945Snectar * 17120945Snectar * 3. Neither the name of KTH nor the names of its contributors may be 18120945Snectar * used to endorse or promote products derived from this software without 19120945Snectar * specific prior written permission. 20120945Snectar * 21120945Snectar * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY 22120945Snectar * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23120945Snectar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24120945Snectar * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE 25120945Snectar * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26120945Snectar * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27120945Snectar * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 28120945Snectar * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29120945Snectar * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30120945Snectar * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 31120945Snectar * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 32120945Snectar 33120945Snectar#include "gssapi_locl.h" 34120945Snectar#include <err.h> 35120945Snectar 36120945SnectarRCSID("$Id: test_acquire_cred.c,v 1.2 2003/04/06 00:20:37 lha Exp $"); 37120945Snectar 38120945Snectarstatic void 39120945Snectarprint_time(OM_uint32 time_rec) 40120945Snectar{ 41120945Snectar if (time_rec == GSS_C_INDEFINITE) { 42120945Snectar printf("cred never expire\n"); 43120945Snectar } else { 44120945Snectar time_t t = time_rec; 45120945Snectar printf("expiration time: %s", ctime(&t)); 46120945Snectar } 47120945Snectar} 48120945Snectar 49120945Snectarint 50120945Snectarmain(int argc, char **argv) 51120945Snectar{ 52120945Snectar OM_uint32 major_status, minor_status; 53120945Snectar gss_cred_id_t cred_handle, copy_cred; 54120945Snectar OM_uint32 time_rec; 55120945Snectar 56120945Snectar major_status = gss_acquire_cred(&minor_status, 57120945Snectar GSS_C_NO_NAME, 58120945Snectar 0, 59120945Snectar NULL, 60120945Snectar GSS_C_INITIATE, 61120945Snectar &cred_handle, 62120945Snectar NULL, 63120945Snectar &time_rec); 64120945Snectar if (GSS_ERROR(major_status)) 65120945Snectar errx(1, "acquire_cred failed"); 66120945Snectar 67120945Snectar 68120945Snectar print_time(time_rec); 69120945Snectar 70120945Snectar major_status = gss_add_cred (&minor_status, 71120945Snectar cred_handle, 72120945Snectar GSS_C_NO_NAME, 73120945Snectar GSS_KRB5_MECHANISM, 74120945Snectar GSS_C_INITIATE, 75120945Snectar 0, 76120945Snectar 0, 77120945Snectar ©_cred, 78120945Snectar NULL, 79120945Snectar &time_rec, 80120945Snectar NULL); 81120945Snectar 82120945Snectar if (GSS_ERROR(major_status)) 83120945Snectar errx(1, "add_cred failed"); 84120945Snectar 85120945Snectar print_time(time_rec); 86120945Snectar 87120945Snectar major_status = gss_release_cred(&minor_status, 88120945Snectar &cred_handle); 89120945Snectar if (GSS_ERROR(major_status)) 90120945Snectar errx(1, "release_cred failed"); 91120945Snectar 92120945Snectar major_status = gss_release_cred(&minor_status, 93120945Snectar ©_cred); 94120945Snectar if (GSS_ERROR(major_status)) 95120945Snectar errx(1, "release_cred failed"); 96120945Snectar 97120945Snectar return 0; 98120945Snectar} 99