From: Miro Jurisic Date: Sat, 20 Feb 1999 00:26:13 +0000 (+0000) Subject: Added Krb5GlobalsLib and Krb5GlobalsDataLib sources X-Git-Tag: krb5-1.1-beta1~345 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=64d464b3bbf2adcff13d1522b1e26c11803f6e24;p=krb5.git Added Krb5GlobalsLib and Krb5GlobalsDataLib sources git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11194 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/mac/libraries/Kerberos v5 Globals/Krb5Globals.CFM.c b/src/mac/libraries/Kerberos v5 Globals/Krb5Globals.CFM.c new file mode 100644 index 000000000..c56f295dd --- /dev/null +++ b/src/mac/libraries/Kerberos v5 Globals/Krb5Globals.CFM.c @@ -0,0 +1,122 @@ +/* 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 +#include +#include +#include + + +#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 diff --git a/src/mac/libraries/Kerberos v5 Globals/Krb5Globals.CFM.h b/src/mac/libraries/Kerberos v5 Globals/Krb5Globals.CFM.h new file mode 100644 index 000000000..dde7b3f14 --- /dev/null +++ b/src/mac/libraries/Kerberos v5 Globals/Krb5Globals.CFM.h @@ -0,0 +1,10 @@ +/* + * 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 diff --git a/src/mac/libraries/Kerberos v5 Globals/Krb5Globals.c b/src/mac/libraries/Kerberos v5 Globals/Krb5Globals.c new file mode 100644 index 000000000..acf48493f --- /dev/null +++ b/src/mac/libraries/Kerberos v5 Globals/Krb5Globals.c @@ -0,0 +1,98 @@ +/* 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 + +#include + +#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 diff --git a/src/mac/libraries/Kerberos v5 Globals/Krb5Globals.exp b/src/mac/libraries/Kerberos v5 Globals/Krb5Globals.exp new file mode 100644 index 000000000..846352e26 --- /dev/null +++ b/src/mac/libraries/Kerberos v5 Globals/Krb5Globals.exp @@ -0,0 +1,9 @@ +# +# Exports for accessors for globally shared data used by Kerberos v5 library +# +# $Header$ +# + +Krb5GlobalsSetDefaultCacheName +Krb5GlobalsGetDefaultCacheName +Krb5GlobalsSetUniqueDefaultCacheName diff --git a/src/mac/libraries/Kerberos v5 Globals/Krb5Globals.h b/src/mac/libraries/Kerberos v5 Globals/Krb5Globals.h new file mode 100644 index 000000000..5f881626f --- /dev/null +++ b/src/mac/libraries/Kerberos v5 Globals/Krb5Globals.h @@ -0,0 +1,62 @@ +/* + * 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 diff --git a/src/mac/libraries/Kerberos v5 Globals/Krb5GlobalsData.c b/src/mac/libraries/Kerberos v5 Globals/Krb5GlobalsData.c new file mode 100644 index 000000000..440b8b75c --- /dev/null +++ b/src/mac/libraries/Kerberos v5 Globals/Krb5GlobalsData.c @@ -0,0 +1,11 @@ +/* + * Definitions for globally shared data used by the Kerberos v5 library + * + * $Header$ + */ + +#include "Krb5GlobalsData.h" + +UInt32 gKerberos5GlobalsRefCount = 0; +char* gKerberos5SystemDefaultCacheName = nil; + diff --git a/src/mac/libraries/Kerberos v5 Globals/Krb5GlobalsData.exp b/src/mac/libraries/Kerberos v5 Globals/Krb5GlobalsData.exp new file mode 100644 index 000000000..51eed7269 --- /dev/null +++ b/src/mac/libraries/Kerberos v5 Globals/Krb5GlobalsData.exp @@ -0,0 +1,8 @@ +# +# Exports for globally shared data used by Kerberos v5 library +# +# $Header$ +# + +gKerberos5GlobalsRefCount +gKerberos5SystemDefaultCacheName diff --git a/src/mac/libraries/Kerberos v5 Globals/Krb5GlobalsData.h b/src/mac/libraries/Kerberos v5 Globals/Krb5GlobalsData.h new file mode 100644 index 000000000..0779ba294 --- /dev/null +++ b/src/mac/libraries/Kerberos v5 Globals/Krb5GlobalsData.h @@ -0,0 +1,15 @@ +/* + * Declarations for globally shared data used by Kerberos v5 library + * + * $Header$ + */ + +#ifndef __Krb5GlobalsData_h__ +#define __Krb5GlobalsData_h__ + +#include + +extern UInt32 gKerberos5GlobalsRefCount; +extern char* gKerberos5SystemDefaultCacheName; + +#endif /* __Krb5GlobalsData_h__ */ \ No newline at end of file