Path: blob/main/crypto/krb5/src/plugins/kdcpolicy/test/main.c
34914 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* include/krb5/kdcpolicy_plugin.h - KDC policy plugin interface */2/*3* Copyright (C) 2017 by Red Hat, Inc.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#include "k5-int.h"33#include "kdb.h"34#include <krb5/kdcpolicy_plugin.h>3536static krb5_error_code37output_from_indicator(const char *const *auth_indicators, int divisor,38krb5_deltat *lifetime_out,39krb5_deltat *renew_lifetime_out,40const char **status)41{42if (auth_indicators[0] == NULL) {43*status = NULL;44return 0;45}4647if (strcmp(auth_indicators[0], "ONE_HOUR") == 0) {48*lifetime_out = 3600 / divisor;49*renew_lifetime_out = *lifetime_out * 2;50return 0;51} else if (strcmp(auth_indicators[0], "SEVEN_HOURS") == 0) {52*lifetime_out = 7 * 3600 / divisor;53*renew_lifetime_out = *lifetime_out * 2;54return 0;55}5657*status = "LOCAL_POLICY";58return KRB5KDC_ERR_POLICY;59}6061static krb5_error_code62test_check_as(krb5_context context, krb5_kdcpolicy_moddata moddata,63const krb5_kdc_req *request, const krb5_db_entry *client,64const krb5_db_entry *server, const char *const *auth_indicators,65const char **status, krb5_deltat *lifetime_out,66krb5_deltat *renew_lifetime_out)67{68if (request->client != NULL && request->client->length >= 1 &&69data_eq_string(request->client->data[0], "fail")) {70*status = "LOCAL_POLICY";71return KRB5KDC_ERR_POLICY;72}73return output_from_indicator(auth_indicators, 1, lifetime_out,74renew_lifetime_out, status);75}7677static krb5_error_code78test_check_tgs(krb5_context context, krb5_kdcpolicy_moddata moddata,79const krb5_kdc_req *request, const krb5_db_entry *server,80const krb5_ticket *ticket, const char *const *auth_indicators,81const char **status, krb5_deltat *lifetime_out,82krb5_deltat *renew_lifetime_out)83{84if (request->server != NULL && request->server->length >= 1 &&85data_eq_string(request->server->data[0], "fail")) {86*status = "LOCAL_POLICY";87return KRB5KDC_ERR_POLICY;88}89return output_from_indicator(auth_indicators, 2, lifetime_out,90renew_lifetime_out, status);91}9293krb5_error_code94kdcpolicy_test_initvt(krb5_context context, int maj_ver, int min_ver,95krb5_plugin_vtable vtable);96krb5_error_code97kdcpolicy_test_initvt(krb5_context context, int maj_ver, int min_ver,98krb5_plugin_vtable vtable)99{100krb5_kdcpolicy_vtable vt;101102if (maj_ver != 1)103return KRB5_PLUGIN_VER_NOTSUPP;104105vt = (krb5_kdcpolicy_vtable)vtable;106vt->name = "test";107vt->check_as = test_check_as;108vt->check_tgs = test_check_tgs;109return 0;110}111112113