2 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
7 * lib/krb5/os/ccdefname.c
9 * Copyright 1990 by the Massachusetts Institute of Technology.
10 * All Rights Reserved.
12 * Export of this software from the United States of America may
13 * require a specific license from the United States Government.
14 * It is the responsibility of any person or organization contemplating
15 * export to obtain such a license before exporting.
17 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
18 * distribute this software and its documentation for any purpose and
19 * without fee is hereby granted, provided that the above copyright
20 * notice appear in all copies and that both that copyright notice and
21 * this permission notice appear in supporting documentation, and that
22 * the name of M.I.T. not be used in advertising or publicity pertaining
23 * to distribution of the software without specific, written prior
24 * permission. Furthermore if you modify this software you must label
25 * your software as modified software and not distribute it in such a
26 * fashion that it might be confused with the original M.I.T. software.
27 * M.I.T. makes no representations about the suitability of
28 * this software for any purpose. It is provided "as is" without express
29 * or implied warranty.
32 * Return default cred. cache name.
36 * SUNW14resync - because of changes specific to Solaris, future
37 * resyncs should leave this file "as is" if possible.
44 * Solaris kerberos: use dirent.h to get maximum filename length MAXNAMLEN
48 static krb5_error_code
get_from_os(
52 krb5_error_code retval
;
56 * Use krb5_getuid() to select the mechanism to obtain the uid.
58 retval
= snprintf(name_buf
, name_size
, "FILE:/tmp/krb5cc_%d",
60 KRB5_LOG(KRB5_INFO
, "get_from_os() FILE=%s\n", name_buf
);
68 krb5_error_code KRB5_CALLCONV
69 krb5_cc_set_default_name(
73 char name_buf
[MAXNAMLEN
];
74 char *new_name
= getenv(KRB5_ENV_CCNAME
);
76 krb5_error_code retval
;
77 krb5_os_context os_ctx
;
79 if (!context
|| context
->magic
!= KV5M_CONTEXT
)
82 os_ctx
= context
->os_context
;
86 * Use the following in this order
88 * 2) name from environment variable
89 * 3) name from os based on UID
90 * resulting string is pointed to by name
94 /* use environment variable or default */
95 if (new_name
!= 0) { /* so that it is in env variable */
98 retval
= get_from_os(name_buf
, sizeof(name_buf
));
105 name_length
= strlen(name
);
106 if (name_length
>= MAXNAMLEN
|| name_length
<=0) {
107 KRB5_LOG(KRB5_ERR
, "krb5_cc_set_default_name() "
108 "bad file size %d\n", name_length
);
111 new_name
= malloc(name_length
+1);
114 strcpy(new_name
, name
);
116 free(os_ctx
->default_ccname
);
118 os_ctx
->default_ccname
= new_name
;
123 const char * KRB5_CALLCONV
124 krb5_cc_default_name(krb5_context context
)
126 krb5_os_context os_ctx
;
128 if (!context
|| context
->magic
!= KV5M_CONTEXT
)
131 os_ctx
= context
->os_context
;
134 * Solaris kerberos: this is a bug fix for service principals.
135 * We need to always fetch the ccache name.
137 krb5_cc_set_default_name(context
, NULL
);
139 KRB5_LOG(KRB5_INFO
, "krb5_cc_default_name() FILE=%s\n",
140 os_ctx
->default_ccname
);
142 return(os_ctx
->default_ccname
);