--- /dev/null
+/* 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.
+ * 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 <Types.h>
+#include <Errors.h>
+#include <CCache.h>
+#include <CodeFragments.h>
+
+
+#include "Krb5GlobalsData.h"
+#include "Krb5Globals.CFM.h"
+
+apiCB* gCCContext = nil;
+
+/* $Header$ */
+
+/* Include MITAthenaCore for:
+ - prototypes for __initialize and __terminate
+ - resource-fork access utilities for shared libraries
+ */
+
+#if defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__)
+# pragma import on
+#endif
+
+ pascal OSErr __initialize (const CFragInitBlock* theInitBlock);
+ pascal void __terminate (void);
+
+/* Standard CFM initializion function prototype */
+pascal OSErr
+__initialize_Kerberos5GlobalsLib (
+ CFragInitBlockPtr inInitBlock);
+
+/* Standard CFM termination function prototype */
+pascal void
+__terminate_Kerberos5GlobalsLib (
+ void);
+
+/* CFM magic again */
+#if defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__)
+# pragma import reset
+#endif
+
+/* This is the initialization function.
+ This function is guaranteed to be called every time the library is prepared -- which
+ is whenever an application is launched that uses the library
+ In order for this to happen, the function name must be entered in the "Initialization function"
+ field in PPC and CFM-68K linker preferences.
+
+ If this function returns an error code, preparation of the library fails. When preparation fails,
+ either the Finder displays an error message (in the case of strong linking) or library is not loaded
+ (in the case of weak linking).
+*/
+pascal OSErr
+__initialize_Kerberos5GlobalsLib (
+ CFragInitBlockPtr inInitBlock)
+{
+ OSErr err = noErr;
+ cc_uint32 ccErr;
+
+ /* Always do this first in your own initialization function -- this calls runtime
+ library to initialize your globals and your exceptions table */
+ err = __initialize (inInitBlock);
+ if (err != noErr)
+ return err;
+
+ ccErr = cc_initialize (&gCCContext, 2, NULL, NULL);
+ if (ccErr != CC_NOERROR)
+ return memFullErr;
+
+ gKerberos5GlobalsRefCount++;
+ err = Krb5GlobalsSetUniqueDefaultCacheName ();
+ return err;
+}
+
+/* This is the shared library termination function.
+ Here you need to undo, in the reverse order, everything you did in
+ the initialization function.
+
+ This function can't fail.
+*/
+
+pascal void
+__terminate_Kerberos5GlobalsLib (
+ void)
+{
+ /* First, clean up your library-specific structures.
+ ErrorLib does nothing here, since it doesn't take ownership
+ of error tables */
+
+ cc_shutdown (&gCCContext);
+
+ gKerberos5GlobalsRefCount--;
+
+ /* Dispose ccache name if we are last instance */
+ if ((gKerberos5GlobalsRefCount == 0) && (gKerberos5SystemDefaultCacheName != nil)) {
+ DisposePtr (gKerberos5SystemDefaultCacheName);
+ gKerberos5SystemDefaultCacheName = nil;
+ }
+
+ /* Finally, cleanup exception tables and global chain */
+ __terminate ();
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Global CCache context for Kerberos v5 globals library
+ */
+
+#ifndef __Krb5Globlas_CFM_h__
+#define __Krb5Globlas_CFM_h__
+
+extern apiCB* gCCContext;
+
+#endif /* __Krb5Globlas_CFM_h__ */
\ No newline at end of file
--- /dev/null
+/* 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.
+ * 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 "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;
+ 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);
+}
+
+/*
+ * 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 ("%d", i, name);
+ ccErr = cc_open (gCCContext, name, CC_CRED_V5, 0L, &ccache);
+ if (ccErr == CC_NO_EXIST) {
+ err = Krb5GlobalsSetDefaultCacheName (name);
+ } else if (ccErr == CC_NOERROR) {
+ cc_close (gCCContext, &ccache);
+ } else {
+ err = memFullErr;
+ break;
+ }
+ }
+
+ return err;
+}
\ No newline at end of file
--- /dev/null
+#
+# Exports for accessors for globally shared data used by Kerberos v5 library
+#
+# $Header$
+#
+
+Krb5GlobalsSetDefaultCacheName
+Krb5GlobalsGetDefaultCacheName
+Krb5GlobalsSetUniqueDefaultCacheName
--- /dev/null
+/*
+ * Decalrations for Kerberos v5 systemwide globals
+ *
+ * $Header$
+ */
+
+#ifndef __Krb5Globals_h__
+#define __Krb5Globals_h__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#if defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__)
+# pragma import on
+#endif
+
+/*
+ * Set the default cache name
+ *
+ * inName is a C string with the name of the new cache
+ *
+ * returns: noErr, memFullErr
+ */
+
+OSStatus
+Krb5GlobalsSetDefaultCacheName (
+ char* inName);
+
+/*
+ * Retrieve the default cache name
+ *
+ * inName should point to at least inLength bytes of storage
+ * if inName is nil, just returns the length
+ *
+ * returns: length of default cache name
+ */
+
+void
+Krb5GlobalsGetDefaultCacheName (
+ char* inName,
+ UInt32 inLength);
+
+/*
+ * Set the default cache name to a unique string
+ *
+ * Sets the default cache name to a string that is not the name
+ * of an existing cache
+ */
+
+OSStatus
+Krb5GlobalsSetUniqueDefaultCacheName ();
+
+#if defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__)
+# pragma import reset
+#endif
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __Krb5Globals_h__ */
\ No newline at end of file
--- /dev/null
+/*
+ * Definitions for globally shared data used by the Kerberos v5 library
+ *
+ * $Header$
+ */
+
+#include "Krb5GlobalsData.h"
+
+UInt32 gKerberos5GlobalsRefCount = 0;
+char* gKerberos5SystemDefaultCacheName = nil;
+
--- /dev/null
+#
+# Exports for globally shared data used by Kerberos v5 library
+#
+# $Header$
+#
+
+gKerberos5GlobalsRefCount
+gKerberos5SystemDefaultCacheName
--- /dev/null
+/*
+ * Declarations for globally shared data used by Kerberos v5 library
+ *
+ * $Header$
+ */
+
+#ifndef __Krb5GlobalsData_h__
+#define __Krb5GlobalsData_h__
+
+#include <Types.h>
+
+extern UInt32 gKerberos5GlobalsRefCount;
+extern char* gKerberos5SystemDefaultCacheName;
+
+#endif /* __Krb5GlobalsData_h__ */
\ No newline at end of file