]> git.saurik.com Git - apple/security.git/blob - SecurityTests/regressions/test/testcssm.c
Security-57740.1.18.tar.gz
[apple/security.git] / SecurityTests / regressions / test / testcssm.c
1 /*
2 * Copyright (c) 2005 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 * cssmlib.c
24 */
25
26 #include <stdlib.h>
27 #include <Security/cssmapi.h>
28 #include <Security/cssmapple.h>
29
30 #include "testcssm.h"
31 #include "testmore.h"
32
33 const CSSM_API_MEMORY_FUNCS gMemFuncs =
34 {
35 (CSSM_MALLOC)malloc,
36 (CSSM_FREE)free,
37 (CSSM_REALLOC)realloc,
38 (CSSM_CALLOC)calloc,
39 NULL /* context */
40 };
41
42 int
43 cssm_attach(const CSSM_GUID *guid, CSSM_HANDLE *handle)
44 {
45 setup("cssm_attach");
46
47 CSSM_VERSION version = {2, 0};
48 CSSM_PVC_MODE pvcPolicy = CSSM_PVC_NONE;
49 return (ok_status(CSSM_Init(&version, CSSM_PRIVILEGE_SCOPE_NONE,
50 &gGuidCssm, CSSM_KEY_HIERARCHY_NONE, &pvcPolicy,
51 NULL /* reserved */), "CSSM_Init") &&
52 ok_status(CSSM_ModuleLoad(guid, CSSM_KEY_HIERARCHY_NONE, NULL, NULL),
53 "CSSM_ModuleLoad") &&
54 ok_status(CSSM_ModuleAttach(guid, &version, &gMemFuncs,
55 0 /* SubserviceID */, CSSM_SERVICE_DL, 0 /* CSSM_ATTACH_FLAGS */,
56 CSSM_KEY_HIERARCHY_NONE, NULL, 0, NULL, handle),
57 "CSSM_ModuleAttach"));
58 }
59
60 int
61 cssm_detach(const CSSM_GUID *guid, CSSM_HANDLE handle)
62 {
63 setup("cssm_detach");
64
65 return ok_status(CSSM_ModuleDetach(handle), "CSSM_ModuleDetach") &&
66 ok_status(CSSM_ModuleUnload(guid, NULL, NULL), "CSSM_ModuleUnload") &&
67 ok_status(CSSM_Terminate(), "CSSM_Terminate");
68 }