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
28 ModuleNexus
<MdsComponent::MDS
> MdsComponent::mds
;
31 MdsComponent::MdsComponent(const Guid
&guid
) : mMyGuid(guid
)
36 MdsComponent::~MdsComponent()
41 void MdsComponent::getInfo() const
45 while (fgets(buffer
, sizeof(buffer
), mds().config
)) {
46 static const char space
[] = " \t\f";
47 char *p
= buffer
+ strspn(buffer
, space
);
48 if (*p
== '#' || *p
== '\0' || *p
== '\n')
49 continue; // comment or blank line
52 const char *guid
= p
; p
+= strcspn(p
, space
);
53 if (!*p
) CssmError::throwMe(CSSM_ERRCODE_MDS_ERROR
);
56 if (Guid(guid
) != mMyGuid
)
57 continue; // no match this line
58 } catch (CssmCommonError
&error
) {
59 if (error
.cssmError() == CSSM_ERRCODE_INVALID_GUID
)
60 CssmError::throwMe(CSSM_ERRCODE_MDS_ERROR
); // invalid file guid => MDS error
61 throw; // pass all other errors
64 // field 2: flags/options
65 p
+= strspn(p
, space
);
67 mIsThreadSafe
= false;
68 while (*p
&& !isspace(*p
)) {
70 case 'a': mServices
|= CSSM_SERVICE_AC
; break;
71 case 'c': mServices
|= CSSM_SERVICE_CSP
; break;
72 case 'd': mServices
|= CSSM_SERVICE_DL
; break;
73 case 'C': mServices
|= CSSM_SERVICE_CL
; break;
74 case 't': mServices
|= CSSM_SERVICE_TP
; break;
75 case 'm': mIsThreadSafe
= true; break;
77 CssmError::throwMe(CSSM_ERRCODE_MDS_ERROR
);
81 if (!*p
) CssmError::throwMe(CSSM_ERRCODE_MDS_ERROR
);
82 p
+= strspn(p
, space
); // skip space
83 p
[strlen(p
)-1] = '\0'; // remove trailing newline
84 mPath
= p
; // rest of line is pathname, uninterpreted
89 CssmError::throwMe(CSSM_ERRCODE_INVALID_GUID
); // @@@ should have "guid not found" error
93 #if !defined(_MDS_PATH)
94 # define _MDS_PATH "/System/Library/Frameworks/Security.framework/Resources/MDS"
97 MdsComponent::MDS::MDS()
99 const char *path
= getenv("MDSPATH");
101 path
= getenv("MDSFILE");
104 if (!(config
= fopen(path
, "r")))
105 CssmError::throwMe(CSSM_ERRCODE_MDS_ERROR
);
108 MdsComponent::MDS::~MDS()