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 // acls - SecurityServer ACL implementation
23 #include "connection.h"
25 #include "SecurityAgentClient.h"
26 #include <Security/acl_any.h>
27 #include <Security/acl_password.h>
28 #include <Security/acl_threshold.h>
32 // SecurityServerAcl is virtual
34 SecurityServerAcl::~SecurityServerAcl()
39 // Each SecurityServerAcl type must provide some indication of a database
40 // it is associated with. The default, naturally, is "none".
42 const Database
*SecurityServerAcl::relatedDatabase() const
47 // Provide environmental information to get/change-ACL calls.
48 // Also make them virtual so our children can override them.
50 void SecurityServerAcl::cssmGetAcl(const char *tag
, uint32
&count
, AclEntryInfo
* &acls
)
53 return ObjectAcl::cssmGetAcl(tag
, count
, acls
);
56 void SecurityServerAcl::cssmGetOwner(AclOwnerPrototype
&owner
)
59 return ObjectAcl::cssmGetOwner(owner
);
62 void SecurityServerAcl::cssmChangeAcl(const AclEdit
&edit
, const AccessCredentials
*cred
)
65 SecurityServerEnvironment
env(*this);
66 ObjectAcl::cssmChangeAcl(edit
, cred
, &env
);
70 void SecurityServerAcl::cssmChangeOwner(const AclOwnerPrototype
&newOwner
,
71 const AccessCredentials
*cred
)
74 SecurityServerEnvironment
env(*this);
75 ObjectAcl::cssmChangeOwner(newOwner
, cred
, &env
);
81 // Modified validate() methods to connect all the conduits...
83 void SecurityServerAcl::validate(AclAuthorization auth
, const AccessCredentials
*cred
) const
86 SecurityServerEnvironment
env(*this);
87 ObjectAcl::validate(auth
, cred
, &env
);
90 void SecurityServerAcl::validate(AclAuthorization auth
, const Context
&context
) const
93 context
.get
<AccessCredentials
>(CSSM_ATTRIBUTE_ACCESS_CREDENTIALS
));
98 // This function decodes the "special passphrase samples" that provide passphrases
99 // to the SecurityServer through ACL sample blocks. Essentially, it trolls a credentials
100 // structure's samples for the special markers, resolves anything that contains
101 // passphrases outright (and returns true), or returns false if the normal interactive
102 // procedures are to be followed.
103 // (This doesn't strongly belong to the SecurityServerAcl class, but doesn't really have
104 // a better home elsewhere.)
106 bool SecurityServerAcl::getBatchPassphrase(const AccessCredentials
*cred
,
107 CSSM_SAMPLE_TYPE neededSampleType
, CssmOwnedData
&passphrase
)
110 // check all top-level samples
111 const SampleGroup
&samples
= cred
->samples();
112 for (uint32 n
= 0; n
< samples
.length(); n
++) {
113 TypedList sample
= samples
[n
];
114 if (!sample
.isProper())
115 CssmError::throwMe(CSSM_ERRCODE_INVALID_SAMPLE_VALUE
);
116 if (sample
.type() == neededSampleType
) {
118 if (!sample
.isProper())
119 CssmError::throwMe(CSSM_ERRCODE_INVALID_SAMPLE_VALUE
);
120 switch (sample
.type()) {
121 case CSSM_SAMPLE_TYPE_KEYCHAIN_PROMPT
:
123 case CSSM_SAMPLE_TYPE_PASSWORD
:
124 if (sample
.length() != 2)
125 CssmError::throwMe(CSSM_ERRCODE_INVALID_SAMPLE_VALUE
);
126 passphrase
= sample
[1];
129 CssmError::throwMe(CSSM_ERRCODE_INVALID_SAMPLE_VALUE
);
139 // Implement our environment object
141 uid_t
SecurityServerEnvironment::getuid() const
143 return Server::connection().process
.uid();
146 gid_t
SecurityServerEnvironment::getgid() const
148 return Server::connection().process
.gid();
151 pid_t
SecurityServerEnvironment::getpid() const
153 return Server::connection().process
.pid();
156 bool SecurityServerEnvironment::verifyCodeSignature(const CodeSigning::Signature
*signature
)
158 return Server::connection().process
.verifyCodeSignature(signature
);