2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 // cssmmds - MDS interface for CSSM & friends
29 ModuleNexus
<MdsComponent::MDS
> MdsComponent::mds
;
32 MdsComponent::MdsComponent(const Guid
&guid
) : mMyGuid(guid
)
37 MdsComponent::~MdsComponent()
42 void MdsComponent::getInfo() const
46 while (fgets(buffer
, sizeof(buffer
), mds().config
)) {
47 static const char space
[] = " \t\f";
48 char *p
= buffer
+ strspn(buffer
, space
);
49 if (*p
== '#' || *p
== '\0' || *p
== '\n')
50 continue; // comment or blank line
53 const char *guid
= p
; p
+= strcspn(p
, space
);
54 if (!*p
) CssmError::throwMe(CSSM_ERRCODE_MDS_ERROR
);
57 if (Guid(guid
) != mMyGuid
)
58 continue; // no match this line
59 } catch (const CssmCommonError
&error
) {
60 if (error
.cssmError() == CSSM_ERRCODE_INVALID_GUID
)
61 CssmError::throwMe(CSSM_ERRCODE_MDS_ERROR
); // invalid file guid => MDS error
62 throw; // pass all other errors
65 // field 2: flags/options
66 p
+= strspn(p
, space
);
68 mIsThreadSafe
= false;
69 while (*p
&& !isspace(*p
)) {
71 case 'a': mServices
|= CSSM_SERVICE_AC
; break;
72 case 'c': mServices
|= CSSM_SERVICE_CSP
; break;
73 case 'd': mServices
|= CSSM_SERVICE_DL
; break;
74 case 'C': mServices
|= CSSM_SERVICE_CL
; break;
75 case 't': mServices
|= CSSM_SERVICE_TP
; break;
76 case 'm': mIsThreadSafe
= true; break;
78 CssmError::throwMe(CSSM_ERRCODE_MDS_ERROR
);
82 if (!*p
) CssmError::throwMe(CSSM_ERRCODE_MDS_ERROR
);
83 p
+= strspn(p
, space
); // skip space
84 p
[strlen(p
)-1] = '\0'; // remove trailing newline
85 mPath
= p
; // rest of line is pathname, uninterpreted
90 CssmError::throwMe(CSSM_ERRCODE_INVALID_GUID
); // @@@ should have "guid not found" error
94 #if !defined(_MDS_PATH)
95 # define _MDS_PATH "/System/Library/Frameworks/Security.framework/Resources/MDS"
98 MdsComponent::MDS::MDS()
100 const char *path
= getenv("MDSPATH");
102 path
= getenv("MDSFILE");
105 if (!(config
= fopen(path
, "r")))
106 CssmError::throwMe(CSSM_ERRCODE_MDS_ERROR
);
109 MdsComponent::MDS::~MDS()