]> git.saurik.com Git - apple/security.git/blob - SecurityTests/clxutils/dotMacArchive/dotMacTpAttach.cpp
Security-57031.30.12.tar.gz
[apple/security.git] / SecurityTests / clxutils / dotMacArchive / dotMacTpAttach.cpp
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 * dotMacTpAttach.cpp - attach/detach to/from loadable .mac TP
26 */
27
28 #include "dotMacTpAttach.h"
29 #include <Security/Security.h>
30
31 /* SPI; the framework actually contains a static lib we link against */
32 #include <security_cdsa_utils/cuCdsaUtils.h>
33
34 static CSSM_VERSION vers = {2, 0};
35 static const CSSM_GUID dummyGuid = { 0xFADE, 0, 0, { 1,2,3,4,5,6,7,0 }};
36
37 static CSSM_API_MEMORY_FUNCS memFuncs = {
38 cuAppMalloc,
39 cuAppFree,
40 cuAppRealloc,
41 cuAppCalloc,
42 NULL
43 };
44
45 /* load & attach; returns 0 on error */
46 CSSM_TP_HANDLE dotMacTpAttach()
47 {
48 CSSM_TP_HANDLE tpHand;
49 CSSM_RETURN crtn;
50
51 if(cuCssmStartup() == CSSM_FALSE) {
52 return 0;
53 }
54 crtn = CSSM_ModuleLoad(&gGuidAppleDotMacTP,
55 CSSM_KEY_HIERARCHY_NONE,
56 NULL, // eventHandler
57 NULL); // AppNotifyCallbackCtx
58 if(crtn) {
59 cuPrintError("CSSM_ModuleLoad(AppleTP)", crtn);
60 return 0;
61 }
62 crtn = CSSM_ModuleAttach (&gGuidAppleDotMacTP,
63 &vers,
64 &memFuncs, // memFuncs
65 0, // SubserviceID
66 CSSM_SERVICE_TP, // SubserviceFlags
67 0, // AttachFlags
68 CSSM_KEY_HIERARCHY_NONE,
69 NULL, // FunctionTable
70 0, // NumFuncTable
71 NULL, // reserved
72 &tpHand);
73 if(crtn) {
74 cuPrintError("CSSM_ModuleAttach(AppleTP)", crtn);
75 return 0;
76 }
77 else {
78 return tpHand;
79 }
80 }
81
82 /* detach & unload */
83 void dotMacTpDetach(CSSM_TP_HANDLE tpHand)
84 {
85 CSSM_RETURN crtn = CSSM_ModuleDetach(tpHand);
86 if(crtn) {
87 return;
88 }
89 CSSM_ModuleUnload(&gGuidAppleDotMacTP, NULL, NULL);
90 }
91