2N/A/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2N/A/*
2N/A * lib/krb5/os/ktdefname.c
2N/A *
2N/A * Copyright 1990 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 * Return default keytab file name.
2N/A */
2N/A
2N/A#define NEED_WINDOWS
2N/A
2N/A#include "k5-int.h"
2N/A
2N/Aextern char *krb5_defkeyname;
2N/A
2N/A/* this is a an exceedinly gross thing. */
2N/Achar *krb5_overridekeyname = NULL;
2N/A
2N/Akrb5_error_code KRB5_CALLCONV
2N/Akrb5_kt_default_name(krb5_context context, char *name, int name_size)
2N/A{
2N/A char *cp = 0;
2N/A char *retval;
2N/A unsigned int namesize = (name_size < 0 ? 0 : name_size);
2N/A
2N/A if (krb5_overridekeyname) {
2N/A if (strlcpy(name, krb5_overridekeyname, namesize) >= namesize)
2N/A return KRB5_CONFIG_NOTENUFSPACE;
2N/A } else if ((context->profile_secure == FALSE) &&
2N/A (cp = getenv("KRB5_KTNAME"))) {
2N/A if (strlcpy(name, cp, namesize) >= namesize)
2N/A return KRB5_CONFIG_NOTENUFSPACE;
2N/A } else if ((profile_get_string(context->profile,
2N/A KRB5_CONF_LIBDEFAULTS,
2N/A KRB5_CONF_DEFAULT_KEYTAB_NAME, NULL,
2N/A NULL, &retval) == 0) &&
2N/A retval) {
2N/A if (strlcpy(name, retval, namesize) >= namesize)
2N/A return KRB5_CONFIG_NOTENUFSPACE;
2N/A profile_release_string(retval);
2N/A } else {
2N/A#if defined(_WIN32)
2N/A {
2N/A char defname[160];
2N/A int len;
2N/A
2N/A len= GetWindowsDirectory( defname, sizeof(defname)-2 );
2N/A defname[len]= '\0';
2N/A if ( (len + strlen(krb5_defkeyname) + 1) > namesize )
2N/A return KRB5_CONFIG_NOTENUFSPACE;
2N/A snprintf(name, namesize, krb5_defkeyname, defname);
2N/A }
2N/A#else
2N/A if (strlcpy(name, krb5_defkeyname, namesize) >= namesize)
2N/A return KRB5_CONFIG_NOTENUFSPACE;
2N/A#endif
2N/A }
2N/A return 0;
2N/A}