]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_sd_cspdl/lib/SDCSPDLPlugin.cpp
Security-59306.101.1.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 mInitialized = true;
45 EventListener::FinishedInitialization(this);
46 }
47
48 SDCSPDLPlugin::~SDCSPDLPlugin()
49 {
50 }
51
52
53 //
54 // Create a new plugin session, our way
55 //
56 PluginSession *
57 SDCSPDLPlugin::makeSession(CSSM_MODULE_HANDLE handle,
58 const CSSM_VERSION &version,
59 uint32 subserviceId,
60 CSSM_SERVICE_TYPE subserviceType,
61 CSSM_ATTACH_FLAGS attachFlags,
62 const CSSM_UPCALLS &upcalls)
63 {
64 switch (subserviceType)
65 {
66 case CSSM_SERVICE_CSP:
67 return new SDCSPSession(handle,
68 *this,
69 version,
70 subserviceId,
71 subserviceType,
72 attachFlags,
73 upcalls,
74 mSDCSPDLSession,
75 mRawCsp);
76 case CSSM_SERVICE_DL:
77 return new SDDLSession(handle,
78 *this,
79 version,
80 subserviceId,
81 subserviceType,
82 attachFlags,
83 upcalls,
84 mDatabaseManager,
85 mSDCSPDLSession);
86 default:
87 CssmError::throwMe(CSSMERR_CSSM_INVALID_SERVICE_MASK);
88 // return 0; // placebo
89 }
90 }
91
92
93 //
94 // Accept callback notifications from securityd and dispatch them
95 // upstream through CSSM.
96 //
97 void SDCSPDLPlugin::consume(NotificationDomain domain, NotificationEvent event,
98 const CssmData &data)
99 {
100 NameValueDictionary nvd(data);
101 assert(domain == kNotificationDomainCDSA);
102 if (const NameValuePair *uidp = nvd.FindByName(SSUID_KEY)) {
103 CssmSubserviceUid *uid = (CssmSubserviceUid *)uidp->Value().data();
104 assert(uid);
105 secinfo("sdcspdl", "sending callback %d upstream", event);
106 sendCallback(event, n2h (uid->subserviceId()), CSSM_SERVICE_DL | CSSM_SERVICE_CSP);
107 } else
108 secinfo("sdcspdl", "callback event %d has no SSUID data", event);
109 }