]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_sd_cspdl/lib/SDCSPDLPlugin.cpp
Security-57740.1.18.tar.gz
[apple/security.git] / OSX / libsecurity_sd_cspdl / lib / SDCSPDLPlugin.cpp
1 /*
2 * Copyright (c) 2004,2011-2012,2014 Apple 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 // SDCSPDLPlugin.cpp - Securityd-based CSP/DL plug-in module.
27 //
28 #include "SDCSPDLPlugin.h"
29
30 #include "SDCSPSession.h"
31 #include "SDDLSession.h"
32 #include <securityd_client/dictionary.h>
33
34 using namespace SecurityServer;
35
36
37 //
38 // Make and break the plugin object
39 //
40 SDCSPDLPlugin::SDCSPDLPlugin()
41 : EventListener(kNotificationDomainCDSA, kNotificationAllEvents),
42 mRawCsp(gGuidAppleCSP)
43 {
44 EventListener::FinishedInitialization(this);
45 }
46
47 SDCSPDLPlugin::~SDCSPDLPlugin()
48 {
49 }
50
51
52 //
53 // Create a new plugin session, our way
54 //
55 PluginSession *
56 SDCSPDLPlugin::makeSession(CSSM_MODULE_HANDLE handle,
57 const CSSM_VERSION &version,
58 uint32 subserviceId,
59 CSSM_SERVICE_TYPE subserviceType,
60 CSSM_ATTACH_FLAGS attachFlags,
61 const CSSM_UPCALLS &upcalls)
62 {
63 switch (subserviceType)
64 {
65 case CSSM_SERVICE_CSP:
66 return new SDCSPSession(handle,
67 *this,
68 version,
69 subserviceId,
70 subserviceType,
71 attachFlags,
72 upcalls,
73 mSDCSPDLSession,
74 mRawCsp);
75 case CSSM_SERVICE_DL:
76 return new SDDLSession(handle,
77 *this,
78 version,
79 subserviceId,
80 subserviceType,
81 attachFlags,
82 upcalls,
83 mDatabaseManager,
84 mSDCSPDLSession);
85 default:
86 CssmError::throwMe(CSSMERR_CSSM_INVALID_SERVICE_MASK);
87 // return 0; // placebo
88 }
89 }
90
91
92 //
93 // Accept callback notifications from securityd and dispatch them
94 // upstream through CSSM.
95 //
96 void SDCSPDLPlugin::consume(NotificationDomain domain, NotificationEvent event,
97 const CssmData &data)
98 {
99 NameValueDictionary nvd(data);
100 assert(domain == kNotificationDomainCDSA);
101 if (const NameValuePair *uidp = nvd.FindByName(SSUID_KEY)) {
102 CssmSubserviceUid *uid = (CssmSubserviceUid *)uidp->Value().data();
103 assert(uid);
104 secinfo("sdcspdl", "sending callback %d upstream", event);
105 sendCallback(event, n2h (uid->subserviceId()), CSSM_SERVICE_DL | CSSM_SERVICE_CSP);
106 } else
107 secinfo("sdcspdl", "callback event %d has no SSUID data", event);
108 }