]> git.saurik.com Git - apple/security.git/blame - securityd/src/process.h
Security-58286.270.3.0.1.tar.gz
[apple/security.git] / securityd / src / process.h
CommitLineData
d8f41ccd
A
1/*
2 * Copyright (c) 2000-2009 Apple 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
24
25//
26// process - track a single client process and its belongings
27//
28#ifndef _H_PROCESS
29#define _H_PROCESS
30
31#include "structure.h"
32#include "session.h"
d8f41ccd
A
33#include <security_utilities/refcount.h>
34#include <security_utilities/ccaudit.h>
35#include <security_utilities/vproc++.h>
36#include "clientid.h"
37#include "csproxy.h"
38#include "localkey.h"
39#include "notifications.h"
40#include <string>
41
42using MachPlusPlus::Port;
43using MachPlusPlus::TaskPort;
44
45class Session;
46class LocalDatabase;
47class AuthorizationToken;
48
49
50//
51// A Process object represents a UNIX process (and associated Mach Task) that has
52// had contact with us and may have some state associated with it. It primarily tracks
53// the process nature of the client. Individual threads in the client are tracked by
54// Connection objects.
55//
56// Code Signing-style Guest identities are managed in two of our mix-ins. The two play
57// distinct but related roles:
58// * CodeSigningHost manages the public identity of guests within the client.
59// In this relationship, securityd provides registry and proxy services to the client.
60// * ClientIdentification tracks the identity of guests in the client *as securityd clients*.
61// It is concerned with which guest is asking for securityd services, and whether this
62// should be granted.
63// Often, the two form a loop: ClientIdentification uses CodeSigningHost to determine
64// the guest client identity, but it does so through public (Mach IPC) interfaces, because
65// clients may implement their own proxy (though currently not registry) services.
66// We could short-circuit the IPC leg in those cases where securityd serves itself,
67// but there's no evidence (yet) that this is worth the trouble.
68//
69class Process : public PerProcess,
70 public CodeSigningHost,
71 public ClientIdentification,
72 private VProc::Transaction {
73public:
74 Process(TaskPort tPort, const ClientSetupInfo *info, const CommonCriteria::AuditToken &audit);
75 virtual ~Process();
76
77 void reset(TaskPort tPort, const ClientSetupInfo *info, const CommonCriteria::AuditToken &audit);
78
79 uid_t uid() const { return mUid; }
80 gid_t gid() const { return mGid; }
81 pid_t pid() const { return mPid; }
dbe77505 82 Security::CommonCriteria::AuditToken const &audit_token() const { return mAudit; }
d8f41ccd
A
83 TaskPort taskPort() const { return mTaskPort; }
84 bool byteFlipped() const { return mByteFlipped; }
85
d8f41ccd
A
86 using PerProcess::kill;
87 void kill();
88
89 void changeSession(Session::SessionId sessionId);
90
91 Session& session() const;
92 void checkSession(const audit_token_t &auditToken);
93
94 LocalDatabase &localStore();
95 Key *makeTemporaryKey(const CssmKey &key, CSSM_KEYATTR_FLAGS moreAttributes,
96 const AclEntryPrototype *owner);
97
98 // aclSequence is taken to serialize ACL validations to pick up mutual changes
99 Mutex aclSequence;
79b9da22
A
100
101 // Dumping is buggy and only hurts debugging. It's dead Jim.
102 //IFDUMP(void dumpNode());
d8f41ccd
A
103
104private:
105 void setup(const ClientSetupInfo *info);
106
107private:
108 // peer state: established during connection startup; fixed thereafter
109 TaskPort mTaskPort; // task port
110 bool mByteFlipped; // client's byte order is reverse of ours
111 pid_t mPid; // process id
112 uid_t mUid; // UNIX uid credential
113 gid_t mGid; // primary UNIX gid credential
dbe77505 114 Security::CommonCriteria::AuditToken const mAudit; // audit token
fa7225c8 115
d8f41ccd
A
116 // canonical local (transient) key store
117 RefPointer<LocalDatabase> mLocalStore;
118};
119
120
121//
122// Convenience comparison
123//
124inline bool operator == (const Process &p1, const Process &p2)
125{
126 return &p1 == &p2;
127}
128
129
130#endif //_H_PROCESS