]> git.saurik.com Git - apple/securityd.git/blob - src/AuthorizationRule.h
securityd-40120.tar.gz
[apple/securityd.git] / src / AuthorizationRule.h
1 /*
2 * Copyright (c) 2003-2004 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 *
23 * AuthorizationRule.h
24 * Security
25 *
26 */
27
28 #ifndef _H_AUTHORIZATIONRULE
29 #define _H_AUTHORIZATIONRULE 1
30
31 #include <CoreFoundation/CoreFoundation.h>
32 #include <security_cdsa_utilities/AuthorizationData.h>
33 #include "authority.h"
34
35 namespace Authorization
36 {
37
38 class Rule;
39
40 class RuleImpl : public RefCount
41 {
42 public:
43 RuleImpl();
44 RuleImpl(const string &inRightName, CFDictionaryRef cfRight, CFDictionaryRef cfRules);
45
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, SecurityAgent::Reason &reason) const;
50
51 string name() const { return mRightName; }
52
53 private:
54 // internal machinery
55
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, SecurityAgent::Reason &reason) 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, SecurityAgent::Reason &reason) const;
61
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, SecurityAgent::Reason &reason) const;
66
67 void setAgentHints(const AuthItemRef &inRight, const Rule &inTopLevelRule, AuthItemSet &environmentToClient, AuthorizationToken &auth) const;
68
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, SecurityAgent::Reason &reason) const;
71
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, SecurityAgent::Reason &reason) const;
76
77 OSStatus evaluateMechanismOnly(const AuthItemRef &inRight, const Rule &inRule, AuthItemSet &environmentToClient, AuthorizationToken &auth, CredentialSet &outCredentials) const;
78
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, SecurityAgent::Reason &reason) const;
81
82 CredentialSet makeCredentials(const AuthorizationToken &auth) const;
83
84 map<string,string> localizedPrompts() const { return mLocalizedPrompts; }
85
86
87 // parsed attributes
88 private:
89 enum Type
90 {
91 kDeny,
92 kAllow,
93 kUser,
94 kRuleDelegation,
95 kKofN,
96 kEvaluateMechanisms,
97 } mType;
98
99 string mRightName;
100 string mGroupName;
101 CFTimeInterval mMaxCredentialAge;
102 bool mShared;
103 bool mAllowRoot;
104 vector<string> mEvalDef;
105 bool mSessionOwner;
106 vector<Rule> mRuleDef;
107 uint32_t mKofN;
108 mutable uint32_t mTries;
109 bool mAuthenticateUser;
110 map<string,string> mLocalizedPrompts;
111
112 private:
113
114 class Attribute
115 {
116 public:
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, const char *defaultValue);
120 static vector<string> getVector(CFDictionaryRef config, CFStringRef key, bool required);
121 static bool getLocalizedPrompts(CFDictionaryRef config, map<string,string> &localizedPrompts);
122 };
123
124
125 // keys
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;
135
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;
143 };
144
145 class Rule : public RefPointer<RuleImpl>
146 {
147 public:
148 Rule();
149 Rule(const string &inRightName, CFDictionaryRef cfRight, CFDictionaryRef cfRules);
150 };
151
152 }; /* namespace Authorization */
153
154 #endif /* ! _H_AUTHORIZATIONRULE */