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
|
/* Copyright 1998 by the Massachusetts Institute of Technology.
*
* 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.
*/
/*
* Definitions for globally shared data used by the Kerberos v5 library
*
* $Header$
*/
#include <Errors.h>
#include <CCache.h>
#include <string.h>
#include <stdio.h>
#include "Krb5Globals.h"
#include "Krb5GlobalsData.h"
#include "Krb5Globals.CFM.h"
/*
* Set the default cache name
*/
OSStatus
Krb5GlobalsSetDefaultCacheName (
char* inName)
{
char* newName;
newName = NewPtrSys (strlen (inName) + 1);
if (newName == nil)
return MemError();
BlockMoveData (inName, newName, strlen (inName) + 1);
if (gKerberos5SystemDefaultCacheName != nil)
DisposePtr (gKerberos5SystemDefaultCacheName);
gKerberos5SystemDefaultCacheName = newName;
gKerberos5SystemDefaultCacheNameModification++;
return noErr;
}
/*
* Get the default cache name
*/
UInt32
Krb5GlobalsGetDefaultCacheName (
char* inName,
UInt32 inLength)
{
if (inName != nil) {
BlockMoveData (gKerberos5SystemDefaultCacheName, inName, inLength);
inName [inLength] = '\0';
}
return strlen (gKerberos5SystemDefaultCacheName) + 1;
}
/*
* Set the default cache name to something unique
* (i.e. not a name of an existing ccache)
*/
OSStatus
Krb5GlobalsSetUniqueDefaultCacheName ()
{
OSStatus err = noErr;
UInt32 i;
char name [16];
cc_uint32 ccErr;
ccache_p* ccache;
/* Infinite loop! I presume you won't have 2^32 ccaches... */
for (i = 0; ;i++) {
sprintf (name, "%d", i);
ccErr = cc_open (gCCContext, name, CC_CRED_V5, 0L, &ccache);
if (ccErr == CC_NO_EXIST) {
err = Krb5GlobalsSetDefaultCacheName (name);
break;
} else if (ccErr == CC_NOERROR) {
cc_close (gCCContext, &ccache);
} else {
err = memFullErr;
break;
}
}
return err;
}
/*
* Return the modification number
*/
UInt32
Krb5GlobalsGetDefaultCacheNameModification ()
{
return gKerberos5SystemDefaultCacheNameModification;
}
|