2 * Copyright (c) 2003-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@
28 #ifndef _H_AUTHORIZATIONRULE
29 #define _H_AUTHORIZATIONRULE 1
31 #include <CoreFoundation/CoreFoundation.h>
32 #include <security_cdsa_utilities/AuthorizationData.h>
33 #include "authority.h"
35 namespace Authorization
40 class RuleImpl
: public RefCount
44 RuleImpl(const string
&inRightName
, CFDictionaryRef cfRight
, CFDictionaryRef cfRules
);
46 OSStatus
evaluate(const AuthItemRef
&inRight
, const Rule
&inRule
, AuthItemSet
&environmentToClient
,
47 AuthorizationFlags flags
, CFAbsoluteTime now
,
48 const CredentialSet
*inCredentials
, CredentialSet
&credentials
,
49 AuthorizationToken
&auth
) const;
51 string
name() const { return mRightName
; }
56 // evaluate credential for right
57 OSStatus
evaluateCredentialForRight(const AuthorizationToken
&auth
, const AuthItemRef
&inRight
, const Rule
&inRule
,
58 const AuthItemSet
&environment
, CFAbsoluteTime now
, const Credential
&credential
, bool ignoreShared
) const;
59 // evaluate user credential (authentication) for right
60 OSStatus
evaluateUserCredentialForRight(const AuthorizationToken
&auth
, const AuthItemRef
&inRight
, const Rule
&inRule
, const AuthItemSet
&environment
, CFAbsoluteTime now
, const Credential
&credential
, bool ignoreShared
) const;
62 OSStatus
evaluateRules(const AuthItemRef
&inRight
, const Rule
&inRule
,
63 AuthItemSet
&environmentToClient
, AuthorizationFlags flags
,
64 CFAbsoluteTime now
, const CredentialSet
*inCredentials
, CredentialSet
&credentials
,
65 AuthorizationToken
&auth
) const;
67 void setAgentHints(const AuthItemRef
&inRight
, const Rule
&inTopLevelRule
, AuthItemSet
&environmentToClient
, AuthorizationToken
&auth
) const;
69 // perform authorization based on running specified mechanisms (see evaluateMechanism)
70 OSStatus
evaluateAuthentication(const AuthItemRef
&inRight
, const Rule
&inRule
, AuthItemSet
&environmentToClient
, AuthorizationFlags flags
, CFAbsoluteTime now
, const CredentialSet
*inCredentials
, CredentialSet
&credentials
, AuthorizationToken
&auth
) const;
72 OSStatus
evaluateUser(const AuthItemRef
&inRight
, const Rule
&inRule
,
73 AuthItemSet
&environmentToClient
, AuthorizationFlags flags
,
74 CFAbsoluteTime now
, const CredentialSet
*inCredentials
, CredentialSet
&credentials
,
75 AuthorizationToken
&auth
) const;
77 OSStatus
evaluateMechanismOnly(const AuthItemRef
&inRight
, const Rule
&inRule
, AuthItemSet
&environmentToClient
, AuthorizationToken
&auth
, CredentialSet
&outCredentials
) const;
79 // find username hint based on session owner
80 OSStatus
evaluateSessionOwner(const AuthItemRef
&inRight
, const Rule
&inRule
, const AuthItemSet
&environment
, const CFAbsoluteTime now
, const AuthorizationToken
&auth
, Credential
&credential
) const;
82 CredentialSet
makeCredentials(const AuthorizationToken
&auth
) const;
84 map
<string
,string
> localizedPrompts() const { return mLocalizedPrompts
; }
101 CFTimeInterval mMaxCredentialAge
;
104 vector
<string
> mEvalDef
;
106 vector
<Rule
> mRuleDef
;
108 mutable uint32_t mTries
;
109 bool mAuthenticateUser
;
110 map
<string
,string
> mLocalizedPrompts
;
117 static bool getBool(CFDictionaryRef config
, CFStringRef key
, bool required
, bool defaultValue
);
118 static double getDouble(CFDictionaryRef config
, CFStringRef key
, bool required
, double defaultValue
);
119 static string
getString(CFDictionaryRef config
, CFStringRef key
, bool required
, char *defaultValue
);
120 static vector
<string
> getVector(CFDictionaryRef config
, CFStringRef key
, bool required
);
121 static bool getLocalizedPrompts(CFDictionaryRef config
, map
<string
,string
> &localizedPrompts
);
126 static CFStringRef kUserGroupID
;
127 static CFStringRef kTimeoutID
;
128 static CFStringRef kSharedID
;
129 static CFStringRef kAllowRootID
;
130 static CFStringRef kMechanismsID
;
131 static CFStringRef kSessionOwnerID
;
132 static CFStringRef kKofNID
;
133 static CFStringRef kPromptID
;
134 static CFStringRef kTriesID
;
136 static CFStringRef kRuleClassID
;
137 static CFStringRef kRuleAllowID
;
138 static CFStringRef kRuleDenyID
;
139 static CFStringRef kRuleUserID
;
140 static CFStringRef kRuleDelegateID
;
141 static CFStringRef kRuleMechanismsID
;
142 static CFStringRef kRuleAuthenticateUserID
;
145 class Rule
: public RefPointer
<RuleImpl
>
149 Rule(const string
&inRightName
, CFDictionaryRef cfRight
, CFDictionaryRef cfRules
);
152 }; /* namespace Authorization */
154 #endif /* ! _H_AUTHORIZATIONRULE */