xref: /onnv-gate/usr/src/lib/gss_mechs/mech_krb5/krb5/os/ktdefname.c (revision 7934:6aeeafc994de)
10Sstevel@tonic-gate /*
2*7934SMark.Phalan@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
30Sstevel@tonic-gate  * Use is subject to license terms.
40Sstevel@tonic-gate  */
50Sstevel@tonic-gate 
60Sstevel@tonic-gate 
70Sstevel@tonic-gate /*
80Sstevel@tonic-gate  * lib/krb5/os/ktdefname.c
90Sstevel@tonic-gate  *
100Sstevel@tonic-gate  * Copyright 1990 by the Massachusetts Institute of Technology.
110Sstevel@tonic-gate  * All Rights Reserved.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * Export of this software from the United States of America may
140Sstevel@tonic-gate  *   require a specific license from the United States Government.
150Sstevel@tonic-gate  *   It is the responsibility of any person or organization contemplating
160Sstevel@tonic-gate  *   export to obtain such a license before exporting.
17*7934SMark.Phalan@Sun.COM  *
180Sstevel@tonic-gate  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
190Sstevel@tonic-gate  * distribute this software and its documentation for any purpose and
200Sstevel@tonic-gate  * without fee is hereby granted, provided that the above copyright
210Sstevel@tonic-gate  * notice appear in all copies and that both that copyright notice and
220Sstevel@tonic-gate  * this permission notice appear in supporting documentation, and that
230Sstevel@tonic-gate  * the name of M.I.T. not be used in advertising or publicity pertaining
240Sstevel@tonic-gate  * to distribution of the software without specific, written prior
250Sstevel@tonic-gate  * permission.  Furthermore if you modify this software you must label
260Sstevel@tonic-gate  * your software as modified software and not distribute it in such a
270Sstevel@tonic-gate  * fashion that it might be confused with the original M.I.T. software.
280Sstevel@tonic-gate  * M.I.T. makes no representations about the suitability of
290Sstevel@tonic-gate  * this software for any purpose.  It is provided "as is" without express
300Sstevel@tonic-gate  * or implied warranty.
31*7934SMark.Phalan@Sun.COM  *
320Sstevel@tonic-gate  *
330Sstevel@tonic-gate  * Return default keytab file name.
340Sstevel@tonic-gate  */
350Sstevel@tonic-gate 
360Sstevel@tonic-gate #define NEED_WINDOWS
370Sstevel@tonic-gate 
38*7934SMark.Phalan@Sun.COM #include "k5-int.h"
390Sstevel@tonic-gate 
400Sstevel@tonic-gate extern char *krb5_defkeyname;
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /* this is a an exceedinly gross thing. */
430Sstevel@tonic-gate char *krb5_overridekeyname = NULL;
440Sstevel@tonic-gate 
45781Sgtb krb5_error_code KRB5_CALLCONV
krb5_kt_default_name(krb5_context context,char * name,int namesize)46781Sgtb krb5_kt_default_name(krb5_context context, char *name, int namesize)
470Sstevel@tonic-gate {
480Sstevel@tonic-gate     char *cp = 0;
490Sstevel@tonic-gate     char *retval;
500Sstevel@tonic-gate 
510Sstevel@tonic-gate     if (krb5_overridekeyname) {
520Sstevel@tonic-gate 	if ((size_t) namesize < (strlen(krb5_overridekeyname)+1))
530Sstevel@tonic-gate 	    return KRB5_CONFIG_NOTENUFSPACE;
54*7934SMark.Phalan@Sun.COM 	/* Solaris Kerberos */
550Sstevel@tonic-gate 	strncpy(name, krb5_overridekeyname, namesize);
560Sstevel@tonic-gate     } else if ((context->profile_secure == FALSE) &&
570Sstevel@tonic-gate 	(cp = getenv("KRB5_KTNAME"))) {
580Sstevel@tonic-gate 	if ((size_t) namesize < (strlen(cp)+1))
590Sstevel@tonic-gate 	    return KRB5_CONFIG_NOTENUFSPACE;
60*7934SMark.Phalan@Sun.COM 	/* Solaris Kerberos */
610Sstevel@tonic-gate 	strncpy(name, cp, namesize);
620Sstevel@tonic-gate     } else if ((profile_get_string(context->profile,
63*7934SMark.Phalan@Sun.COM 				   "libdefaults",
64*7934SMark.Phalan@Sun.COM 				   "default_keytab_name", NULL,
65*7934SMark.Phalan@Sun.COM 				   NULL, &retval) == 0) &&
660Sstevel@tonic-gate 	       retval) {
670Sstevel@tonic-gate 	if ((size_t) namesize < (strlen(retval)+1))
680Sstevel@tonic-gate 	    return KRB5_CONFIG_NOTENUFSPACE;
69*7934SMark.Phalan@Sun.COM 	/* Solaris Kerberos */
700Sstevel@tonic-gate 	strncpy(name, retval, namesize);
710Sstevel@tonic-gate 	profile_release_string(retval);
720Sstevel@tonic-gate     } else {
73781Sgtb #if defined(_WIN32)
740Sstevel@tonic-gate 	{
750Sstevel@tonic-gate 	    char    defname[160];
760Sstevel@tonic-gate 	    int     len;
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 	    len= GetWindowsDirectory( defname, sizeof(defname)-2 );
790Sstevel@tonic-gate 	    defname[len]= '\0';
800Sstevel@tonic-gate 	    if ( (len + strlen(krb5_defkeyname) + 1) > namesize )
810Sstevel@tonic-gate 		return KRB5_CONFIG_NOTENUFSPACE;
820Sstevel@tonic-gate 	    sprintf(name, krb5_defkeyname, defname);
830Sstevel@tonic-gate 	}
840Sstevel@tonic-gate #else
850Sstevel@tonic-gate 	if ((size_t) namesize < (strlen(krb5_defkeyname)+1))
860Sstevel@tonic-gate 	    return KRB5_CONFIG_NOTENUFSPACE;
87*7934SMark.Phalan@Sun.COM 	/* Solaris Kerberos */
880Sstevel@tonic-gate 	strncpy(name, krb5_defkeyname, namesize);
890Sstevel@tonic-gate #endif
900Sstevel@tonic-gate     }
910Sstevel@tonic-gate     return 0;
920Sstevel@tonic-gate }
93*7934SMark.Phalan@Sun.COM 
94