]> git.saurik.com Git - apple/securityd.git/blob - src/authority.h
4b2200cfc15d8b072336b93b90eeb2eb0a165a98
[apple/securityd.git] / src / authority.h
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25
26
27 //
28 // authority - authorization manager
29 //
30 #ifndef _H_AUTHORITY
31 #define _H_AUTHORITY
32
33 #include "securityserver.h"
34 #include <security_cdsa_utilities/AuthorizationData.h>
35 #include <security_cdsa_client/osxsigning.h>
36 #include "database.h"
37
38 using Authorization::Credential;
39 using Authorization::CredentialSet;
40 using Authorization::AuthItemSet;
41
42 class Process;
43 class Session;
44
45 class AuthorizationToken : public PerSession {
46 public:
47 AuthorizationToken(Session &ssn, const CredentialSet &base, const security_token_t &securityToken);
48 ~AuthorizationToken();
49
50 Session &session() const;
51
52 const AuthorizationBlob &handle() const { return mHandle; }
53 const CredentialSet &baseCreds() const { return mBaseCreds; }
54 CredentialSet effectiveCreds() const;
55
56 typedef CredentialSet::iterator iterator;
57 iterator begin() { return mBaseCreds.begin(); }
58 iterator end() { return mBaseCreds.end(); }
59
60 // add more credential dependencies
61 void mergeCredentials(const CredentialSet &more);
62
63 // maintain process-owning links
64 void addProcess(Process &proc);
65 bool endProcess(Process &proc);
66
67 // access control for external representations
68 bool mayExternalize(Process &proc) const;
69 bool mayInternalize(Process &proc, bool countIt = true);
70
71 uid_t creatorUid() const { return mCreatorUid; }
72 CodeSigning::OSXCode *creatorCode() const { return mCreatorCode; }
73 pid_t creatorPid() const { return mCreatorPid; }
74
75 AuthItemSet infoSet(AuthorizationString tag = NULL);
76 void setInfoSet(AuthItemSet &newInfoSet);
77 void setCredentialInfo(const Credential &inCred);
78 void clearInfoSet();
79
80 public:
81 static AuthorizationToken &find(const AuthorizationBlob &blob);
82
83 class Deleter {
84 public:
85 Deleter(const AuthorizationBlob &blob);
86
87 void remove();
88 operator AuthorizationToken &() const { return *mAuth; }
89
90 private:
91 AuthorizationToken *mAuth;
92 StLock<Mutex> lock;
93 };
94
95 private:
96 Mutex mLock; // object lock
97 AuthorizationBlob mHandle; // official randomized blob marker
98 CredentialSet mBaseCreds; // credentials we're based on
99
100 unsigned int mTransferCount; // number of internalizations remaining
101
102 typedef set<Process *> ProcessSet;
103 ProcessSet mUsingProcesses; // set of process objects using this token
104
105 uid_t mCreatorUid; // Uid of proccess that created this authorization
106 RefPointer<CodeSigning::OSXCode> mCreatorCode; // code id of creator
107 pid_t mCreatorPid; // Pid of processs that created this authorization
108
109 AuthItemSet mInfoSet; // Side band info gathered from evaluations in this session
110
111 private:
112 typedef map<AuthorizationBlob, RefPointer<AuthorizationToken> > AuthMap;
113 static AuthMap authMap; // set of extant authorizations
114 static Mutex authMapLock; // lock for mAuthorizations (only)
115 };
116
117
118
119
120 #endif //_H_AUTHORITY