2 * Copyright (c) 2003-2010,2012 Apple 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@
23 * AuthorizationRule.cpp
28 #include "AuthorizationRule.h"
29 #include <Security/AuthorizationTags.h>
30 #include <Security/AuthorizationTagsPriv.h>
31 #include <Security/AuthorizationDB.h>
32 #include <Security/AuthorizationPriv.h>
33 #include <security_utilities/logging.h>
34 #include <bsm/audit_uevents.h>
35 #include "ccaudit_extensions.h"
36 #include "authority.h"
39 #include "agentquery.h"
40 #include "AuthorizationMechEval.h"
46 #include <membership.h>
49 #include <membershipPriv.h>
52 using namespace CommonCriteria::Securityd
;
57 namespace Authorization
{
59 CFStringRef
RuleImpl::kUserGroupID
= CFSTR(kAuthorizationRuleParameterGroup
);
60 CFStringRef
RuleImpl::kTimeoutID
= CFSTR(kAuthorizationRuleParameterCredentialTimeout
);
61 CFStringRef
RuleImpl::kSharedID
= CFSTR(kAuthorizationRuleParameterCredentialShared
);
62 CFStringRef
RuleImpl::kAllowRootID
= CFSTR(kAuthorizationRuleParameterAllowRoot
);
63 CFStringRef
RuleImpl::kMechanismsID
= CFSTR(kAuthorizationRuleParameterMechanisms
);
64 CFStringRef
RuleImpl::kSessionOwnerID
= CFSTR(kAuthorizationRuleParameterCredentialSessionOwner
);
65 CFStringRef
RuleImpl::kKofNID
= CFSTR(kAuthorizationRuleParameterKofN
);
66 CFStringRef
RuleImpl::kPromptID
= CFSTR(kAuthorizationRuleParameterDefaultPrompt
);
67 CFStringRef
RuleImpl::kButtonID
= CFSTR(kAuthorizationRuleParameterDefaultButton
);
68 CFStringRef
RuleImpl::kTriesID
= CFSTR("tries"); // XXX/cs move to AuthorizationTagsPriv.h
69 CFStringRef
RuleImpl::kExtractPasswordID
= CFSTR(kAuthorizationRuleParameterExtractPassword
);
71 CFStringRef
RuleImpl::kRuleClassID
= CFSTR(kAuthorizationRuleClass
);
72 CFStringRef
RuleImpl::kRuleAllowID
= CFSTR(kAuthorizationRuleClassAllow
);
73 CFStringRef
RuleImpl::kRuleDenyID
= CFSTR(kAuthorizationRuleClassDeny
);
74 CFStringRef
RuleImpl::kRuleUserID
= CFSTR(kAuthorizationRuleClassUser
);
75 CFStringRef
RuleImpl::kRuleDelegateID
= CFSTR(kAuthorizationRightRule
);
76 CFStringRef
RuleImpl::kRuleMechanismsID
= CFSTR(kAuthorizationRuleClassMechanisms
);
77 CFStringRef
RuleImpl::kRuleAuthenticateUserID
= CFSTR(kAuthorizationRuleParameterAuthenticateUser
);
81 RuleImpl::Attribute::getString(CFDictionaryRef config
, CFStringRef key
, bool required
= false, const char *defaultValue
= "")
83 Syslog::alert("Authorization via securityd no longer supported");
84 MacOSError::throwMe(errAuthorizationInternal
);
88 RuleImpl::Attribute::getDouble(CFDictionaryRef config
, CFStringRef key
, bool required
= false, double defaultValue
= 0.0)
90 Syslog::alert("Authorization via securityd no longer supported");
91 MacOSError::throwMe(errAuthorizationInternal
);
95 RuleImpl::Attribute::getBool(CFDictionaryRef config
, CFStringRef key
, bool required
= false, bool defaultValue
= false)
97 Syslog::alert("Authorization via securityd no longer supported");
98 MacOSError::throwMe(errAuthorizationInternal
);
102 RuleImpl::Attribute::getVector(CFDictionaryRef config
, CFStringRef key
, bool required
= false)
104 Syslog::alert("Authorization via securityd no longer supported");
105 MacOSError::throwMe(errAuthorizationInternal
);
109 bool RuleImpl::Attribute::getLocalizedText(CFDictionaryRef config
, map
<string
,string
> &localizedPrompts
, CFStringRef dictKey
, const char *descriptionKey
)
111 Syslog::alert("Authorization via securityd no longer supported");
112 MacOSError::throwMe(errAuthorizationInternal
);
117 RuleImpl::RuleImpl() :
118 mType(kUser
), mGroupName("admin"), mMaxCredentialAge(300.0), mShared(true), mAllowRoot(false), mSessionOwner(false), mTries(0), mAuthenticateUser(true), mExtractPassword(false)
120 // XXX/cs read default descriptions from somewhere
121 // @@@ Default rule is shared admin group with 5 minute timeout
124 // return rule built from rule definition; throw if invalid.
125 RuleImpl::RuleImpl(const string
&inRightName
, CFDictionaryRef cfRight
, CFDictionaryRef cfRules
) : mRightName(inRightName
), mExtractPassword(false)
127 Syslog::alert("Authorization via securityd no longer supported");
128 MacOSError::throwMe(errAuthorizationInternal
);
138 RuleImpl::setAgentHints(const AuthItemRef
&inRight
, const Rule
&inTopLevelRule
, AuthItemSet
&environmentToClient
, AuthorizationToken
&auth
) const
140 Syslog::alert("Authorization via securityd no longer supported");
141 MacOSError::throwMe(errAuthorizationInternal
);
144 // If a different evaluation for getting a credential is prescribed,
145 // we'll run that and validate the credentials from there.
146 // we fall back on a default configuration from the authenticate rule
148 RuleImpl::evaluateAuthentication(const AuthItemRef
&inRight
, const Rule
&inRule
,AuthItemSet
&environmentToClient
, AuthorizationFlags flags
, CFAbsoluteTime now
, const CredentialSet
*inCredentials
, CredentialSet
&credentials
, AuthorizationToken
&auth
, SecurityAgent::Reason
&reason
, bool savePassword
) const
150 Syslog::alert("Authorization via securityd no longer supported");
151 MacOSError::throwMe(errAuthorizationInternal
);
154 // create externally verified credentials on the basis of
155 // mechanism-provided information
157 RuleImpl::makeCredentials(const AuthorizationToken
&auth
) const
159 Syslog::alert("Authorization via securityd no longer supported");
160 MacOSError::throwMe(errAuthorizationInternal
);
163 // evaluate whether a good credential of the current session owner would authorize a right
165 RuleImpl::evaluateSessionOwner(const AuthItemRef
&inRight
, const Rule
&inRule
, const AuthItemSet
&environment
, const CFAbsoluteTime now
, const AuthorizationToken
&auth
, Credential
&credential
, SecurityAgent::Reason
&reason
) const
167 Syslog::alert("Authorization via securityd no longer supported");
168 MacOSError::throwMe(errAuthorizationInternal
);
173 RuleImpl::evaluateCredentialForRight(const AuthorizationToken
&auth
, const AuthItemRef
&inRight
, const Rule
&inRule
, const AuthItemSet
&environment
, CFAbsoluteTime now
, const Credential
&credential
, bool ignoreShared
, SecurityAgent::Reason
&reason
) const
175 Syslog::alert("Authorization via securityd no longer supported");
176 MacOSError::throwMe(errAuthorizationInternal
);
179 // Return errAuthorizationSuccess if this rule allows access based on the specified credential,
180 // return errAuthorizationDenied otherwise.
182 RuleImpl::evaluateUserCredentialForRight(const AuthorizationToken
&auth
, const AuthItemRef
&inRight
, const Rule
&inRule
, const AuthItemSet
&environment
, CFAbsoluteTime now
, const Credential
&credential
, bool ignoreShared
, SecurityAgent::Reason
&reason
) const
184 Syslog::alert("Authorization via securityd no longer supported");
185 MacOSError::throwMe(errAuthorizationInternal
);
191 RuleImpl::evaluateUser(const AuthItemRef
&inRight
, const Rule
&inRule
, AuthItemSet
&environmentToClient
, AuthorizationFlags flags
, CFAbsoluteTime now
, const CredentialSet
*inCredentials
, CredentialSet
&credentials
, AuthorizationToken
&auth
, SecurityAgent::Reason
&reason
, bool savePassword
) const
193 Syslog::alert("Authorization via securityd no longer supported");
194 MacOSError::throwMe(errAuthorizationInternal
);
198 RuleImpl::evaluateMechanismOnly(const AuthItemRef
&inRight
, const Rule
&inRule
, AuthItemSet
&environmentToClient
, AuthorizationToken
&auth
, CredentialSet
&outCredentials
, bool savePassword
) const
200 Syslog::alert("Authorization via securityd no longer supported");
201 MacOSError::throwMe(errAuthorizationInternal
);
205 RuleImpl::evaluateRules(const AuthItemRef
&inRight
, const Rule
&inRule
, AuthItemSet
&environmentToClient
, AuthorizationFlags flags
, CFAbsoluteTime now
, const CredentialSet
*inCredentials
, CredentialSet
&credentials
, AuthorizationToken
&auth
, SecurityAgent::Reason
&reason
, bool savePassword
) const
207 Syslog::alert("Authorization via securityd no longer supported");
208 MacOSError::throwMe(errAuthorizationInternal
);
213 RuleImpl::evaluate(const AuthItemRef
&inRight
, const Rule
&inRule
, AuthItemSet
&environmentToClient
, AuthorizationFlags flags
, CFAbsoluteTime now
, const CredentialSet
*inCredentials
, CredentialSet
&credentials
, AuthorizationToken
&auth
, SecurityAgent::Reason
&reason
, bool savePassword
) const
215 Syslog::alert("Authorization via securityd no longer supported");
216 MacOSError::throwMe(errAuthorizationInternal
);
219 Rule::Rule() : RefPointer
<RuleImpl
>(new RuleImpl()) {}
220 Rule::Rule(const string
&inRightName
, CFDictionaryRef cfRight
, CFDictionaryRef cfRules
) : RefPointer
<RuleImpl
>(new RuleImpl(inRightName
, cfRight
, cfRules
)) {}
224 } // end namespace Authorization