1/*
2 * Copyright (c) 2004 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25
26#include <Security/Security.h>
27#include "DataStorageLibrary.h"
28
29
30
31/*
32	stubs for CSSM SPI's -- these simply call the next level
33*/
34
35
36
37extern "C" CSSM_RETURN CSSM_SPI_ModuleUnload (const CSSM_GUID *CssmGuid,
38											  const CSSM_GUID *ModuleGuid,
39											  CSSM_SPI_ModuleEventHandler CssmNotifyCallback,
40											  void* CssmNotifyCallbackCtx)
41{
42	try
43	{
44		StaticMutex _mutex (*DataStorageLibrary::gGlobalLock);
45		MutexLocker _lock (_mutex);
46
47		if (DataStorageLibrary::gDL != NULL)
48		{
49			// delete our instance
50			delete DataStorageLibrary::gDL;
51			DataStorageLibrary::gDL = NULL;
52		}
53		return 0;
54	}
55	catch (...)
56	{
57		return CSSMERR_CSSM_INTERNAL_ERROR;
58	}
59}
60
61
62
63extern "C" CSSM_RETURN CSSM_SPI_ModuleAttach (const CSSM_GUID *ModuleGuid,
64											  const CSSM_VERSION *Version,
65											  uint32 SubserviceID,
66											  CSSM_SERVICE_TYPE SubserviceType,
67											  CSSM_ATTACH_FLAGS AttachFlags,
68											  CSSM_MODULE_HANDLE ModuleHandle,
69											  CSSM_KEY_HIERARCHY KeyHierarchy,
70											  const CSSM_GUID *CssmGuid,
71											  const CSSM_GUID *ModuleManagerGuid,
72											  const CSSM_GUID *CallerGuid,
73											  const CSSM_UPCALLS *Upcalls,
74											  CSSM_MODULE_FUNCS_PTR *FuncTbl)
75{
76	try
77	{
78		if (DataStorageLibrary::gDL == NULL)
79		{
80			return CSSMERR_CSSM_MODULE_NOT_LOADED;
81		}
82
83		DataStorageLibrary::gDL->Attach (ModuleGuid, Version, SubserviceID, SubserviceType, AttachFlags, ModuleHandle, KeyHierarchy,
84										 CssmGuid, ModuleManagerGuid, CallerGuid, Upcalls, FuncTbl);
85		return 0;
86	}
87	catch (...)
88	{
89		return CSSMERR_CSSM_INTERNAL_ERROR;
90	}
91}
92
93
94
95extern "C" CSSM_RETURN CSSM_SPI_ModuleDetach (CSSM_MODULE_HANDLE ModuleHandle)
96{
97	try
98	{
99		if (DataStorageLibrary::gDL == NULL)
100		{
101			return CSSMERR_CSSM_MODULE_NOT_LOADED;
102		}
103
104		DataStorageLibrary::gDL->Detach (ModuleHandle);
105		return 0;
106	}
107	catch (...)
108	{
109		return CSSMERR_CSSM_INTERNAL_ERROR;
110	}
111}
112