2N/A/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2N/A/*
2N/A * lib/krb5/keytab/ktfns.c
2N/A *
2N/A * Copyright 2001,2008 by the Massachusetts Institute of Technology.
2N/A * All Rights Reserved.
2N/A *
2N/A * Export of this software from the United States of America may
2N/A * require a specific license from the United States Government.
2N/A * It is the responsibility of any person or organization contemplating
2N/A * export to obtain such a license before exporting.
2N/A *
2N/A * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
2N/A * distribute this software and its documentation for any purpose and
2N/A * without fee is hereby granted, provided that the above copyright
2N/A * notice appear in all copies and that both that copyright notice and
2N/A * this permission notice appear in supporting documentation, and that
2N/A * the name of M.I.T. not be used in advertising or publicity pertaining
2N/A * to distribution of the software without specific, written prior
2N/A * permission. Furthermore if you modify this software you must label
2N/A * your software as modified software and not distribute it in such a
2N/A * fashion that it might be confused with the original M.I.T. software.
2N/A * M.I.T. makes no representations about the suitability of
2N/A * this software for any purpose. It is provided "as is" without express
2N/A * or implied warranty.
2N/A */
2N/A
2N/A/*
2N/A * Dispatch methods for keytab code.
2N/A */
2N/A
2N/A#ifndef LEAN_CLIENT
2N/A
2N/A#include "k5-int.h"
2N/A
2N/Aconst char * KRB5_CALLCONV
2N/Akrb5_kt_get_type (krb5_context context, krb5_keytab keytab)
2N/A{
2N/A return keytab->ops->prefix;
2N/A}
2N/A
2N/Akrb5_error_code KRB5_CALLCONV
2N/Akrb5_kt_get_name(krb5_context context, krb5_keytab keytab, char *name,
2N/A unsigned int namelen)
2N/A{
2N/A return krb5_x((keytab)->ops->get_name,(context, keytab,name,namelen));
2N/A}
2N/A
2N/Akrb5_error_code KRB5_CALLCONV
2N/Akrb5_kt_close(krb5_context context, krb5_keytab keytab)
2N/A{
2N/A return krb5_x((keytab)->ops->close,(context, keytab));
2N/A}
2N/A
2N/Akrb5_error_code KRB5_CALLCONV
2N/Akrb5_kt_get_entry(krb5_context context, krb5_keytab keytab,
2N/A krb5_const_principal principal, krb5_kvno vno,
2N/A krb5_enctype enctype, krb5_keytab_entry *entry)
2N/A{
2N/A krb5_error_code err;
2N/A krb5_principal_data princ_data;
2N/A
2N/A if (krb5_is_referral_realm(&principal->realm)) {
2N/A char *realm;
2N/A princ_data = *principal;
2N/A principal = &princ_data;
2N/A err = krb5_get_default_realm(context, &realm);
2N/A if (err)
2N/A return err;
2N/A princ_data.realm.data = realm;
2N/A princ_data.realm.length = strlen(realm);
2N/A }
2N/A err = krb5_x((keytab)->ops->get,(context, keytab, principal, vno, enctype,
2N/A entry));
2N/A if (principal == &princ_data)
2N/A krb5_free_default_realm(context, princ_data.realm.data);
2N/A return err;
2N/A}
2N/A
2N/Akrb5_error_code KRB5_CALLCONV
2N/Akrb5_kt_start_seq_get(krb5_context context, krb5_keytab keytab,
2N/A krb5_kt_cursor *cursor)
2N/A{
2N/A return krb5_x((keytab)->ops->start_seq_get,(context, keytab, cursor));
2N/A}
2N/A
2N/Akrb5_error_code KRB5_CALLCONV
2N/Akrb5_kt_next_entry(krb5_context context, krb5_keytab keytab,
2N/A krb5_keytab_entry *entry, krb5_kt_cursor *cursor)
2N/A{
2N/A return krb5_x((keytab)->ops->get_next,(context, keytab, entry, cursor));
2N/A}
2N/A
2N/Akrb5_error_code KRB5_CALLCONV
2N/Akrb5_kt_end_seq_get(krb5_context context, krb5_keytab keytab,
2N/A krb5_kt_cursor *cursor)
2N/A{
2N/A return krb5_x((keytab)->ops->end_get,(context, keytab, cursor));
2N/A}
2N/A
2N/A/*
2N/A * Solaris Kerberos: this is a hack until a keytab method is provided that
2N/A * will tell us if the keytab exists or not.
2N/A */
2N/Akrb5_error_code KRB5_CALLCONV
2N/Akrb5_kt_file_exists(krb5_context context, krb5_keytab keytab, krb5_boolean *is_file_type,
2N/A size_t *size)
2N/A{
2N/A krb5_error_code ret;
2N/A char kt_name[MAXPATHLEN], *cp;
2N/A struct stat statbuf;
2N/A
2N/A ret = krb5_kt_get_name(context, keytab, kt_name, sizeof (kt_name));
2N/A if (ret)
2N/A return ret;
2N/A if (!strncmp(kt_name, "FILE:", 5) || !strncmp(kt_name, "WRFILE:", 7)) {
2N/A *is_file_type = TRUE;
2N/A cp = strchr(kt_name, ':');
2N/A /* ++cp to skip the ':' */
2N/A ret = stat(++cp, &statbuf);
2N/A if (ret)
2N/A return errno;
2N/A else
2N/A *size = statbuf.st_size;
2N/A } else {
2N/A *is_file_type = FALSE;
2N/A }
2N/A return ret;
2N/A}
2N/A#endif /* LEAN_CLIENT */