1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* lib/krb5/os/ccdefname.c
*
* Copyright 1990 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation, and that
* the name of M.I.T. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. Furthermore if you modify this software you must label
* your software as modified software and not distribute it in such a
* fashion that it might be confused with the original M.I.T. software.
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*
*
* Return default cred. cache name.
*/
/*
* SUNW14resync - because of changes specific to Solaris, future
* resyncs should leave this file "as is" if possible.
*/
#include <k5-int.h>
#include <stdio.h>
/*
* Solaris kerberos: use dirent.h to get maximum filename length MAXNAMLEN
*/
#include <dirent.h>
static krb5_error_code get_from_os(
char *name_buf,
int name_size)
{
krb5_error_code retval;
/*
* Solaris Kerberos
* Use krb5_getuid() to select the mechanism to obtain the uid.
*/
retval = snprintf(name_buf, name_size, "FILE:/tmp/krb5cc_%d",
krb5_getuid());
KRB5_LOG(KRB5_INFO, "get_from_os() FILE=%s\n", name_buf);
if (retval < 0)
return retval;
else
return 0;
}
/*ARGSUSED*/
krb5_error_code KRB5_CALLCONV
krb5_cc_set_default_name(
krb5_context context,
const char *name)
{
char name_buf[MAXNAMLEN];
char *new_name = getenv(KRB5_ENV_CCNAME);
int name_length;
krb5_error_code retval;
krb5_os_context os_ctx;
if (!context || context->magic != KV5M_CONTEXT)
return KV5M_CONTEXT;
os_ctx = context->os_context;
/*
* Solaris kerberos:
* Use the following in this order
* 1) name from arg
* 2) name from environment variable
* 3) name from os based on UID
* resulting string is pointed to by name
*/
if (!name) {
/* use environment variable or default */
if (new_name != 0) { /* so that it is in env variable */
name = new_name;
} else {
retval = get_from_os(name_buf, sizeof(name_buf));
if (retval)
return retval;
name = name_buf;
}
}
name_length = strlen(name);
if (name_length >= MAXNAMLEN || name_length <=0) {
KRB5_LOG(KRB5_ERR, "krb5_cc_set_default_name() "
"bad file size %d\n", name_length);
return -1;
}
new_name = malloc(name_length+1);
if (!new_name)
return ENOMEM;
strcpy(new_name, name);
if (os_ctx->default_ccname)
free(os_ctx->default_ccname);
os_ctx->default_ccname = new_name;
return 0;
}
const char * KRB5_CALLCONV
krb5_cc_default_name(krb5_context context)
{
krb5_os_context os_ctx;
if (!context || context->magic != KV5M_CONTEXT)
return NULL;
os_ctx = context->os_context;
/*
* Solaris kerberos: this is a bug fix for service principals.
* We need to always fetch the ccache name.
*/
krb5_cc_set_default_name(context, NULL);
KRB5_LOG(KRB5_INFO, "krb5_cc_default_name() FILE=%s\n",
os_ctx->default_ccname);
return(os_ctx->default_ccname);
}
|