1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Copyright 2002 Sun Microsystems, Inc. All rights reserved. 3*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 4*7c478bd9Sstevel@tonic-gate */ 5*7c478bd9Sstevel@tonic-gate 6*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 7*7c478bd9Sstevel@tonic-gate 8*7c478bd9Sstevel@tonic-gate /* 9*7c478bd9Sstevel@tonic-gate * lib/krb5/os/ktdefname.c 10*7c478bd9Sstevel@tonic-gate * 11*7c478bd9Sstevel@tonic-gate * Copyright 1990 by the Massachusetts Institute of Technology. 12*7c478bd9Sstevel@tonic-gate * All Rights Reserved. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * Export of this software from the United States of America may 15*7c478bd9Sstevel@tonic-gate * require a specific license from the United States Government. 16*7c478bd9Sstevel@tonic-gate * It is the responsibility of any person or organization contemplating 17*7c478bd9Sstevel@tonic-gate * export to obtain such a license before exporting. 18*7c478bd9Sstevel@tonic-gate * 19*7c478bd9Sstevel@tonic-gate * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 20*7c478bd9Sstevel@tonic-gate * distribute this software and its documentation for any purpose and 21*7c478bd9Sstevel@tonic-gate * without fee is hereby granted, provided that the above copyright 22*7c478bd9Sstevel@tonic-gate * notice appear in all copies and that both that copyright notice and 23*7c478bd9Sstevel@tonic-gate * this permission notice appear in supporting documentation, and that 24*7c478bd9Sstevel@tonic-gate * the name of M.I.T. not be used in advertising or publicity pertaining 25*7c478bd9Sstevel@tonic-gate * to distribution of the software without specific, written prior 26*7c478bd9Sstevel@tonic-gate * permission. Furthermore if you modify this software you must label 27*7c478bd9Sstevel@tonic-gate * your software as modified software and not distribute it in such a 28*7c478bd9Sstevel@tonic-gate * fashion that it might be confused with the original M.I.T. software. 29*7c478bd9Sstevel@tonic-gate * M.I.T. makes no representations about the suitability of 30*7c478bd9Sstevel@tonic-gate * this software for any purpose. It is provided "as is" without express 31*7c478bd9Sstevel@tonic-gate * or implied warranty. 32*7c478bd9Sstevel@tonic-gate * 33*7c478bd9Sstevel@tonic-gate * 34*7c478bd9Sstevel@tonic-gate * Return default keytab file name. 35*7c478bd9Sstevel@tonic-gate */ 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #define NEED_WINDOWS 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate #include <k5-int.h> 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate extern char *krb5_defkeyname; 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate /* this is a an exceedinly gross thing. */ 44*7c478bd9Sstevel@tonic-gate char *krb5_overridekeyname = NULL; 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate KRB5_DLLIMP krb5_error_code KRB5_CALLCONV 47*7c478bd9Sstevel@tonic-gate krb5_kt_default_name(context, name, namesize) 48*7c478bd9Sstevel@tonic-gate krb5_context context; 49*7c478bd9Sstevel@tonic-gate char FAR *name; 50*7c478bd9Sstevel@tonic-gate int namesize; 51*7c478bd9Sstevel@tonic-gate { 52*7c478bd9Sstevel@tonic-gate char *cp = 0; 53*7c478bd9Sstevel@tonic-gate char *retval; 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate if (krb5_overridekeyname) { 56*7c478bd9Sstevel@tonic-gate if ((size_t) namesize < (strlen(krb5_overridekeyname)+1)) 57*7c478bd9Sstevel@tonic-gate return KRB5_CONFIG_NOTENUFSPACE; 58*7c478bd9Sstevel@tonic-gate strncpy(name, krb5_overridekeyname, namesize); 59*7c478bd9Sstevel@tonic-gate } else if ((context->profile_secure == FALSE) && 60*7c478bd9Sstevel@tonic-gate (cp = getenv("KRB5_KTNAME"))) { 61*7c478bd9Sstevel@tonic-gate if ((size_t) namesize < (strlen(cp)+1)) 62*7c478bd9Sstevel@tonic-gate return KRB5_CONFIG_NOTENUFSPACE; 63*7c478bd9Sstevel@tonic-gate strncpy(name, cp, namesize); 64*7c478bd9Sstevel@tonic-gate } else if ((profile_get_string(context->profile, 65*7c478bd9Sstevel@tonic-gate "libdefaults", 66*7c478bd9Sstevel@tonic-gate "default_keytab_name", NULL, 67*7c478bd9Sstevel@tonic-gate NULL, &retval) == 0) && 68*7c478bd9Sstevel@tonic-gate retval) { 69*7c478bd9Sstevel@tonic-gate if ((size_t) namesize < (strlen(retval)+1)) 70*7c478bd9Sstevel@tonic-gate return KRB5_CONFIG_NOTENUFSPACE; 71*7c478bd9Sstevel@tonic-gate strncpy(name, retval, namesize); 72*7c478bd9Sstevel@tonic-gate profile_release_string(retval); 73*7c478bd9Sstevel@tonic-gate } else { 74*7c478bd9Sstevel@tonic-gate #if defined (_MSDOS) || defined(_WIN32) 75*7c478bd9Sstevel@tonic-gate { 76*7c478bd9Sstevel@tonic-gate char defname[160]; 77*7c478bd9Sstevel@tonic-gate int len; 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate len= GetWindowsDirectory( defname, sizeof(defname)-2 ); 80*7c478bd9Sstevel@tonic-gate defname[len]= '\0'; 81*7c478bd9Sstevel@tonic-gate if ( (len + strlen(krb5_defkeyname) + 1) > namesize ) 82*7c478bd9Sstevel@tonic-gate return KRB5_CONFIG_NOTENUFSPACE; 83*7c478bd9Sstevel@tonic-gate sprintf(name, krb5_defkeyname, defname); 84*7c478bd9Sstevel@tonic-gate } 85*7c478bd9Sstevel@tonic-gate #else 86*7c478bd9Sstevel@tonic-gate if ((size_t) namesize < (strlen(krb5_defkeyname)+1)) 87*7c478bd9Sstevel@tonic-gate return KRB5_CONFIG_NOTENUFSPACE; 88*7c478bd9Sstevel@tonic-gate strncpy(name, krb5_defkeyname, namesize); 89*7c478bd9Sstevel@tonic-gate #endif 90*7c478bd9Sstevel@tonic-gate } 91*7c478bd9Sstevel@tonic-gate return 0; 92*7c478bd9Sstevel@tonic-gate } 93