Path: blob/main/crypto/krb5/src/tests/gssapi/ccrefresh.c
34907 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* tests/gssapi/ccrefresh.c - Get or set refresh time on a ccache */2/*3* Copyright (C) 2012 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* This program sets the refresh time of an existing ccache to 1, forcing a34* refresh.35*/3637#include "k5-int.h"3839static void40check(krb5_error_code code)41{42if (code != 0) {43com_err("ccrefresh", code, NULL);44abort();45}46}4748int49main(int argc, char **argv)50{51const char *ccname, *value = NULL;52krb5_context context;53krb5_ccache ccache;54krb5_data d;5556if (argc != 2 && argc != 3) {57fprintf(stderr, "Usage: %s ccname [value]\n", argv[0]);58return 1;59}60ccname = argv[1];61if (argc == 3)62value = argv[2];6364check(krb5_init_context(&context));65check(krb5_cc_resolve(context, ccname, &ccache));66if (value != NULL) {67d = string2data((char *)value);68check(krb5_cc_set_config(context, ccache, NULL,69KRB5_CC_CONF_REFRESH_TIME, &d));70} else {71check(krb5_cc_get_config(context, ccache, NULL,72KRB5_CC_CONF_REFRESH_TIME, &d));73printf("%.*s\n", (int)d.length, d.data);74krb5_free_data_contents(context, &d);75}76krb5_cc_close(context, ccache);77krb5_free_context(context);78return 0;79}808182