]> git.saurik.com Git - apple/security.git/blob - SecurityServer/process.h
Security-28.tar.gz
[apple/security.git] / SecurityServer / process.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 //
20 // process - track a single client process and its belongings
21 //
22 #ifndef _H_PROCESS
23 #define _H_PROCESS
24
25 #include "securityserver.h"
26 #include "SecurityAgentClient.h"
27 #include <Security/osxsigning.h>
28 #include "key.h"
29 #include <string>
30
31 using MachPlusPlus::Port;
32 using MachPlusPlus::TaskPort;
33
34 class Session;
35 class AuthorizationToken;
36
37
38 //
39 // A Process object represents a UNIX process (and associated Mach Task) that has
40 // had contact with us and may have some state associated with it.
41 //
42 class Process {
43 public:
44 Process(TaskPort tPort, const char *identity, uid_t uid, gid_t gid);
45 Process(Process &prior); // specialized reclone facility
46 virtual ~Process();
47
48 uid_t uid() const { return mUid; }
49 gid_t gid() const { return mGid; }
50 pid_t pid() const { return mPid; }
51 TaskPort taskPort() const { return mTaskPort; }
52
53 const CodeSigning::OSXCode *clientCode() const { return mClientCode; }
54 bool verifyCodeSignature(const CodeSigning::Signature *signature);
55
56 void addAuthorization(AuthorizationToken *auth);
57 bool removeAuthorization(AuthorizationToken *auth);
58
59 void beginConnection(Connection &);
60 bool endConnection(Connection &);
61 bool kill();
62
63 void addDatabase(Database *database);
64 void removeDatabase(Database *database);
65
66 Session &session;
67
68 protected:
69 static Session &sessionForPort(TaskPort taskPort);
70
71 private:
72 Mutex mLock; // object lock
73 uint32 mBusyCount; // number of Connection references
74 bool mDying; // process is dead; waiting for Connections to drain
75
76 // peer state: established during connection startup; fixed thereafter
77 TaskPort mTaskPort; // task port
78 pid_t mPid; // process id
79 uid_t mUid; // UNIX uid credential
80 gid_t mGid; // primary UNIX gid credential
81
82 CodeSigning::OSXCode *mClientCode; // code object for client
83
84 // authorization dictionary
85 typedef multiset<AuthorizationToken *> AuthorizationSet;
86 AuthorizationSet mAuthorizations; // set of valid authorizations for process
87
88 // database dictionary
89 typedef set<Database *> DatabaseSet;
90 DatabaseSet mDatabases; // set of valid database handles
91 };
92
93
94 #endif //_H_PROCESS