2 * Copyright (c) 2003,2011,2014 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@
25 * AuthorizationDB.h -- APIs for managing the authorization policy database
29 #ifndef _SECURITY_AUTHORIZATIONDB_H_
30 #define _SECURITY_AUTHORIZATIONDB_H_
32 #include <Security/Authorization.h>
33 #include <CoreFoundation/CoreFoundation.h>
35 #if defined(__cplusplus)
39 CF_ASSUME_NONNULL_BEGIN
42 @header AuthorizationDB
45 This API allows for any programs to get, modify, delete and add new right definitions to the policy database. Meta-rights specify whether and what authorization is required to make these modifications.
47 AuthorizationRightSet(authRef, "com.ifoo.ifax.send", CFSTR(kRuleIsAdmin), CFSTR("You must authenticate to send a fax."), NULL, NULL)
49 add a rule for letting admins send faxes using a canned rule, delegating to a pre-specified rule that authorizes everyone who is an admin.
51 AuthorizationRightSet(authRef, "com.ifoo.ifax.send", [[CFSTR(kRightRule), CFSTR(kRuleIsAdmin)], [CFSTR(kRightComment), CFSTR("authorizes sending of 1 fax message")]], CFSTR("Authorize sending of a fax"), NULL, NULL)
53 add identical rule, but specify additional attributes this time.
55 Keep in mind while specifying a comment to be specific about what you need to authorize for (1 fax), in terms of a general message for user. The means of proof required for kRuleIsAdmin (enter username/password for example) should not be included here, since it could be configured differently. Also note that the "authRef" variable used in each of the above examples must be a vaild AuthorizationRef obtained from AuthorizationCreate().
59 /*! @define kRightRule
60 rule delegation key. Instead of specifying exact behavior some canned rules
61 are shipped that may be switched by configurable security.
63 #define kAuthorizationRightRule "rule"
65 /*! @defined kRuleIsAdmin
66 canned rule values for use with rule delegation definitions: require user to be an admin.
68 #define kAuthorizationRuleIsAdmin "is-admin"
70 /*! @defined kRuleAuthenticateAsSessionUser
71 canned rule value for use with rule delegation definitions: require user to authenticate as the session owner (logged-in user).
73 #define kAuthorizationRuleAuthenticateAsSessionUser "authenticate-session-owner"
75 /*! @defined kRuleAuthenticateAsAdmin
76 Canned rule value for use with rule delegation definitions: require user to authenticate as admin.
78 #define kAuthorizationRuleAuthenticateAsAdmin "authenticate-admin"
80 /*! @defined kAuthorizationRuleClassAllow
81 Class that allows anything.
83 #define kAuthorizationRuleClassAllow "allow"
85 /*! @defined kAuthorizationRuleClassDeny
86 Class that denies anything.
88 #define kAuthorizationRuleClassDeny "deny"
90 /*! @defined kAuthorizationComment
91 comments for the administrator on what is being customized here;
92 as opposed to (localized) descriptions presented to the user.
94 #define kAuthorizationComment "comment"
99 @function AuthorizationRightGet
101 Retrieves a right definition as a dictionary. There are no restrictions to keep anyone from retrieving these definitions.
103 @param rightName (input) the rightname (ASCII). Wildcard rightname definitions are okay.
104 @param rightDefinition (output/optional) the dictionary with all keys defining the right. See documented keys. Passing in NULL will just check if there is a definition. The caller is responsible for releasing the returned dictionary.
106 @result errAuthorizationSuccess 0 No error.
108 errAuthorizationDenied -60005 No definition found.
111 OSStatus
AuthorizationRightGet(const char *rightName
,
112 CFDictionaryRef
* __nullable CF_RETURNS_RETAINED rightDefinition
);
115 @function AuthorizationRightSet
117 Create or update a right entry. Only normal rights can be registered (wildcard rights are denied); wildcard rights are considered to be put in by an administrator putting together a site configuration.
119 @param authRef (input) authRef to authorize modifications.
120 @param rightName (input) the rightname (ASCII). Wildcard rightnames are not okay.
121 @param rightDefinition (input) a CFString of the name of a rule to use (delegate) or CFDictionary containing keys defining one.
122 @param descriptionKey (input/optional) a CFString to use as a key for looking up localized descriptions. If no localization is found this will be the description itself.
123 @param bundle (input/optional) a bundle to get localizations from if not the main bundle.
124 @param localeTableName (input/optional) stringtable name to get localizations from.
126 @result errAuthorizationSuccess 0 added right definition successfully.
128 errAuthorizationDenied -60005 Unable to create or update right definition.
130 errAuthorizationCanceled -60006 Authorization was canceled by user.
132 errAuthorizationInteractionNotAllowed -60007 Interaction was required but not possible.
135 OSStatus
AuthorizationRightSet(AuthorizationRef authRef
,
136 const char *rightName
,
137 CFTypeRef rightDefinition
,
138 CFStringRef __nullable descriptionKey
,
139 CFBundleRef __nullable bundle
,
140 CFStringRef __nullable localeTableName
);
145 @function AuthorizationRightRemove
147 Request to remove a right from the policy database.
149 @param authRef (input) authRef, to be used to authorize this action.
150 @param rightName (input) the rightname (ASCII). Wildcard rightnames are not okay.
153 OSStatus
AuthorizationRightRemove(AuthorizationRef authRef
,
154 const char *rightName
);
156 CF_ASSUME_NONNULL_END
158 #if defined(__cplusplus)
162 #endif /* !_SECURITY_AUTHORIZATIONDB_H_ */