]> git.saurik.com Git - apple/securityd.git/blob - src/connection.h
securityd-32596.tar.gz
[apple/securityd.git] / src / connection.h
1 /*
2 * Copyright (c) 2000-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
24
25 //
26 // connection - manage connections to clients
27 //
28 #ifndef _H_CONNECTION
29 #define _H_CONNECTION
30
31 #include <security_agent_client/agentclient.h>
32 #include <security_utilities/osxcode.h>
33 #include "process.h"
34 #include "session.h"
35 #include "key.h"
36 #include <string>
37
38 using MachPlusPlus::Port;
39 using MachPlusPlus::TaskPort;
40
41 class Session;
42
43
44 //
45 // A Connection object represents an established connection between a client
46 // and securityd. Note that in principle, a client process can have
47 // multiple Connections (each represented by an IPC channel), though there will
48 // usually be only one.
49 //
50 class Connection : public PerConnection {
51 typedef Key::Handle KeyHandle;
52 public:
53 Connection(Process &proc, Port rPort);
54 virtual ~Connection();
55 void terminate(); // normal termination
56 void abort(bool keepReplyPort = false); // abnormal termination
57
58 Port clientPort() const { return mClientPort; }
59
60 // work framing - called as work threads pick up connection work
61 void beginWork(); // I've got it
62 void checkWork(); // everything still okay?
63 void endWork(); // Done with this
64
65 // notify that a SecurityAgent call may hang the active worker thread for a while
66 void useAgent(SecurityAgent::Client *client)
67 { StLock<Mutex> _(*this); agentWait = client; }
68
69 // special UI convenience - set a don't-ask-again trigger for Keychain-style ACLs
70 void setAclUpdateTrigger(const SecurityServerAcl &object)
71 { aclUpdateTrigger = &object; aclUpdateTriggerCount = aclUpdateTriggerLimit + 1; }
72 bool aclWasSetForUpdateTrigger(const SecurityServerAcl &object) const
73 { return aclUpdateTriggerCount > 0 && aclUpdateTrigger == &object; }
74
75 Process &process() const { return parent<Process>(); }
76 Session &session() const { return process().session(); }
77
78 private:
79 // peer state: established during connection startup; fixed thereafter
80 Port mClientPort;
81
82 // transient state (altered as we go)
83 enum State {
84 idle, // no thread services us
85 busy, // a thread is busy servicing us
86 dying // busy and scheduled to die as soon as possible
87 } state;
88 SecurityAgent::Client *agentWait; // SA client session we may be waiting on
89
90 // see KeychainPromptAclSubject in acl_keychain.cpp for more information on this
91 const SecurityServerAcl *aclUpdateTrigger; // update trigger set for this (NULL if none)
92 uint8 aclUpdateTriggerCount; // number of back-to-back requests honored
93 static const uint8 aclUpdateTriggerLimit = 3; // 3 calls (getAcl+getOwner+changeAcl)
94 };
95
96
97 #endif //_H_CONNECTION