2 * Copyright (c) 2000-2004 Apple Computer, 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@
26 // connection - manage connections to clients
31 #include <security_agent_client/agentclient.h>
32 #include <security_utilities/osxcode.h>
38 using MachPlusPlus::Port
;
39 using MachPlusPlus::TaskPort
;
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.
50 class Connection
: public PerConnection
{
51 typedef Key::Handle KeyHandle
;
53 Connection(Process
&proc
, Port rPort
);
54 virtual ~Connection();
55 void terminate(); // normal termination
56 void abort(bool keepReplyPort
= false); // abnormal termination
58 Port
clientPort() const { return mClientPort
; }
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
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
; }
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
; }
75 Process
&process() const { return parent
<Process
>(); }
76 Session
&session() const { return process().session(); }
79 // peer state: established during connection startup; fixed thereafter
82 // transient state (altered as we go)
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
88 SecurityAgent::Client
*agentWait
; // SA client session we may be waiting on
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)
97 #endif //_H_CONNECTION