2 * Copyright (c) 2000-2004 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
26 // acls - securityd ACL implementation
29 #include "connection.h"
31 #include "agentquery.h"
32 #include "tokendatabase.h"
34 // ACL subjects whose Environments we implement
35 #include <security_cdsa_utilities/acl_any.h>
36 #include <security_cdsa_utilities/acl_password.h>
37 #include <security_cdsa_utilities/acl_threshold.h>
41 // SecurityServerAcl is virtual
43 SecurityServerAcl::~SecurityServerAcl()
48 // The default implementation of the ACL interface simply uses the local ObjectAcl
49 // data. You can customize this by implementing instantiateAcl() [from ObjectAcl]
50 // or by overriding these methods as desired.
51 // Note: While you can completely ignore the ObjectAcl personality if you wish, it's
52 // usually smarter to adapt it.
54 void SecurityServerAcl::getOwner(AclOwnerPrototype
&owner
)
56 ObjectAcl::cssmGetOwner(owner
);
59 void SecurityServerAcl::getAcl(const char *tag
, uint32
&count
, AclEntryInfo
*&acls
)
61 ObjectAcl::cssmGetAcl(tag
, count
, acls
);
64 void SecurityServerAcl::changeAcl(const AclEdit
&edit
, const AccessCredentials
*cred
,
67 SecurityServerEnvironment
env(*this, db
);
68 ObjectAcl::cssmChangeAcl(edit
, cred
, &env
);
71 void SecurityServerAcl::changeOwner(const AclOwnerPrototype
&newOwner
,
72 const AccessCredentials
*cred
, Database
*db
)
74 SecurityServerEnvironment
env(*this, db
);
75 ObjectAcl::cssmChangeOwner(newOwner
, cred
, &env
);
80 // Modified validate() methods to connect all the conduits...
82 void SecurityServerAcl::validate(AclAuthorization auth
, const AccessCredentials
*cred
, Database
*db
)
84 SecurityServerEnvironment
env(*this, db
);
85 StLock
<Mutex
> objectSequence(aclSequence
);
86 StLock
<Mutex
> processSequence(Server::process().aclSequence
);
87 ObjectAcl::validate(auth
, cred
, &env
);
90 void SecurityServerAcl::validate(AclAuthorization auth
, const Context
&context
, Database
*db
)
93 context
.get
<AccessCredentials
>(CSSM_ATTRIBUTE_ACCESS_CREDENTIALS
), db
);
98 // External storage interface
100 Adornable
&SecurityServerEnvironment::store(const AclSubject
*subject
)
102 switch (subject
->type()) {
103 case CSSM_ACL_SUBJECT_TYPE_PREAUTH
:
105 if (TokenDatabase
*tokenDb
= dynamic_cast<TokenDatabase
*>(database
))
106 return tokenDb
->common().store();
112 CssmError::throwMe(CSSM_ERRCODE_ACL_SUBJECT_TYPE_NOT_SUPPORTED
);
117 // ProcessAclSubject personality: uid/gid/pid come from the active Process object
119 uid_t
SecurityServerEnvironment::getuid() const
121 return Server::process().uid();
124 gid_t
SecurityServerEnvironment::getgid() const
126 return Server::process().gid();
129 pid_t
SecurityServerEnvironment::getpid() const
131 return Server::process().pid();
136 // CodeSignatureAclSubject personality: take code signature from active Process object
138 bool SecurityServerEnvironment::verifyCodeSignature(const CodeSigning::Signature
*signature
,
139 const CssmData
*comment
)
141 return Server::codeSignatures().verify(Server::process(), signature
, comment
);
146 // PromptedAclSubject personality: Get a secret by prompting through SecurityAgent
148 bool SecurityServerEnvironment::getSecret(CssmOwnedData
&secret
, const CssmData
&prompt
) const
150 //@@@ ignoring prompt - not used right now
152 QueryPIN
query(*database
);
153 query
.inferHints(Server::process());
154 if (!query()) { // success
155 secret
= query
.pin();
164 // SecretAclSubject personality: externally validate a secret (passphrase etc.)
165 // Right now, this always goes to the (Token)Database object, because that's where
166 // the PIN ACL entries are. We could direct this at the ObjectAcl (database or key)
167 // instead and rely on tokend to perform the PIN mapping, but the generic tokend
168 // wrappers do not (currently) perform any ACL validation, so every tokend would have
169 // to re-implement that. Perhaps in the next ACL revamp cycle...
171 bool SecurityServerEnvironment::validateSecret(const SecretAclSubject
*me
,
172 const AccessCredentials
*cred
)
174 return database
&& database
->validateSecret(me
, cred
);
179 // PreAuthenticationAclSubject personality - refer to database (ObjectAcl)
181 ObjectAcl
*SecurityServerEnvironment::preAuthSource()
183 return database
? &database
->acl() : NULL
;
188 // The default AclSource denies having an ACL at all
190 SecurityServerAcl
&AclSource::acl()
192 CssmError::throwMe(CSSM_ERRCODE_OBJECT_ACL_NOT_SUPPORTED
);
195 Database
*AclSource::relatedDatabase()