dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / gss_mechs / mech_krb5 / krb5 / os / ccdefname.c
blob6f0fe768d758b7cfee29ce2c8feb94767c1c7808
1 /*
2 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
6 /*
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.
40 #include <k5-int.h>
41 #include <stdio.h>
44 * Solaris kerberos: use dirent.h to get maximum filename length MAXNAMLEN
46 #include <dirent.h>
48 static krb5_error_code get_from_os(
49 char *name_buf,
50 int name_size)
52 krb5_error_code retval;
55 * Solaris Kerberos
56 * Use krb5_getuid() to select the mechanism to obtain the uid.
58 retval = snprintf(name_buf, name_size, "FILE:/tmp/krb5cc_%d",
59 krb5_getuid());
60 KRB5_LOG(KRB5_INFO, "get_from_os() FILE=%s\n", name_buf);
61 if (retval < 0)
62 return retval;
63 else
64 return 0;
67 /*ARGSUSED*/
68 krb5_error_code KRB5_CALLCONV
69 krb5_cc_set_default_name(
70 krb5_context context,
71 const char *name)
73 char name_buf[MAXNAMLEN];
74 char *new_name = getenv(KRB5_ENV_CCNAME);
75 int name_length;
76 krb5_error_code retval;
77 krb5_os_context os_ctx;
79 if (!context || context->magic != KV5M_CONTEXT)
80 return KV5M_CONTEXT;
82 os_ctx = context->os_context;
85 * Solaris kerberos:
86 * Use the following in this order
87 * 1) name from arg
88 * 2) name from environment variable
89 * 3) name from os based on UID
90 * resulting string is pointed to by name
93 if (!name) {
94 /* use environment variable or default */
95 if (new_name != 0) { /* so that it is in env variable */
96 name = new_name;
97 } else {
98 retval = get_from_os(name_buf, sizeof(name_buf));
99 if (retval)
100 return retval;
101 name = 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);
109 return -1;
111 new_name = malloc(name_length+1);
112 if (!new_name)
113 return ENOMEM;
114 strcpy(new_name, name);
116 free(os_ctx->default_ccname);
118 os_ctx->default_ccname = new_name;
119 return 0;
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)
129 return NULL;
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);