2 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 #pragma ident "%Z%%M% %I% %E% SMI"
9 * lib/krb5/os/ccdefname.c
11 * Copyright 1990 by the Massachusetts Institute of Technology.
12 * All Rights Reserved.
14 * Export of this software from the United States of America may
15 * require a specific license from the United States Government.
16 * It is the responsibility of any person or organization contemplating
17 * export to obtain such a license before exporting.
19 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
20 * distribute this software and its documentation for any purpose and
21 * without fee is hereby granted, provided that the above copyright
22 * notice appear in all copies and that both that copyright notice and
23 * this permission notice appear in supporting documentation, and that
24 * the name of M.I.T. not be used in advertising or publicity pertaining
25 * to distribution of the software without specific, written prior
26 * permission. Furthermore if you modify this software you must label
27 * your software as modified software and not distribute it in such a
28 * fashion that it might be confused with the original M.I.T. software.
29 * M.I.T. makes no representations about the suitability of
30 * this software for any purpose. It is provided "as is" without express
31 * or implied warranty.
34 * Return default cred. cache name.
38 * SUNW14resync - because of changes specific to Solaris, future
39 * resyncs should leave this file "as is" if possible.
46 * Solaris kerberos: use dirent.h to get maximum filename length MAXNAMLEN
50 static krb5_error_code
get_from_os(
54 krb5_error_code retval
;
58 * Use krb5_getuid() to select the mechanism to obtain the uid.
60 retval
= snprintf(name_buf
, name_size
, "FILE:/tmp/krb5cc_%d",
62 KRB5_LOG(KRB5_INFO
, "get_from_os() FILE=%s\n", name_buf
);
70 krb5_error_code KRB5_CALLCONV
71 krb5_cc_set_default_name(
75 char name_buf
[MAXNAMLEN
];
76 char *new_name
= getenv(KRB5_ENV_CCNAME
);
78 krb5_error_code retval
;
79 krb5_os_context os_ctx
;
81 if (!context
|| context
->magic
!= KV5M_CONTEXT
)
84 os_ctx
= context
->os_context
;
88 * Use the following in this order
90 * 2) name from environment variable
91 * 3) name from os based on UID
92 * resulting string is pointed to by name
96 /* use environment variable or default */
97 if (new_name
!= 0) { /* so that it is in env variable */
100 retval
= get_from_os(name_buf
, sizeof(name_buf
));
107 name_length
= strlen(name
);
108 if (name_length
>= MAXNAMLEN
|| name_length
<=0) {
109 KRB5_LOG(KRB5_ERR
, "krb5_cc_set_default_name() "
110 "bad file size %d\n", name_length
);
113 new_name
= malloc(name_length
+1);
116 strcpy(new_name
, name
);
118 if (os_ctx
->default_ccname
)
119 free(os_ctx
->default_ccname
);
121 os_ctx
->default_ccname
= new_name
;
126 const char * KRB5_CALLCONV
127 krb5_cc_default_name(krb5_context context
)
129 krb5_os_context os_ctx
;
131 if (!context
|| context
->magic
!= KV5M_CONTEXT
)
134 os_ctx
= context
->os_context
;
137 * Solaris kerberos: this is a bug fix for service principals.
138 * We need to always fetch the ccache name.
140 krb5_cc_set_default_name(context
, NULL
);
142 KRB5_LOG(KRB5_INFO
, "krb5_cc_default_name() FILE=%s\n",
143 os_ctx
->default_ccname
);
145 return(os_ctx
->default_ccname
);