PageRenderTime 26ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/opensource.apple.com/source/libsecurity_agent/libsecurity_agent-36399/lib/agentclient.h

#
C Header | 235 lines | 191 code | 39 blank | 5 comment | 0 complexity | 743f2ae6563c7bfd199244f8a6ae7b53 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-2.0, BSD-3-Clause, GPL-3.0, MPL-2.0, LGPL-2.0, LGPL-2.1, CC-BY-SA-3.0, IPL-1.0, ISC, AGPL-1.0, AGPL-3.0, JSON, Apache-2.0, 0BSD
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>agentclient.h</title>
  6. <style type="text/css">
  7. .enscript-comment { font-style: italic; color: rgb(178,34,34); }
  8. .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
  9. .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
  10. .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
  11. .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
  12. .enscript-string { font-weight: bold; color: rgb(188,143,143); }
  13. .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
  14. .enscript-type { font-weight: bold; color: rgb(34,139,34); }
  15. .enscript-highlight { text-decoration: underline; color: 0; }
  16. </style>
  17. </head>
  18. <body id="top">
  19. <h1 style="margin:8px;" id="f1">agentclient.h&nbsp;&nbsp;&nbsp;<span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
  20. <hr/>
  21. <div></div>
  22. <pre>
  23. <span class="enscript-comment">/*
  24. * agentclient.h
  25. * SecurityAgent
  26. *
  27. * Copyright (c) 2002,2008 Apple Inc.. All rights reserved.
  28. *
  29. */</span>
  30. #<span class="enscript-reference">ifndef</span> <span class="enscript-variable-name">_H_AGENTCLIENT</span>
  31. #<span class="enscript-reference">define</span> <span class="enscript-variable-name">_H_AGENTCLIENT</span>
  32. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;Security/Authorization.h&gt;</span>
  33. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;Security/AuthorizationPlugin.h&gt;</span>
  34. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;Security/AuthorizationTags.h&gt;</span>
  35. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;Security/AuthorizationTagsPriv.h&gt;</span>
  36. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;security_agent_client/sa_types.h&gt;</span>
  37. #<span class="enscript-reference">if</span> <span class="enscript-reference">defined</span>(<span class="enscript-variable-name">__cplusplus</span>)
  38. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;string&gt;</span>
  39. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;security_utilities/mach++.h&gt;</span>
  40. #<span class="enscript-reference">include</span> <span class="enscript-string">&lt;security_cdsa_utilities/AuthorizationData.h&gt;</span>
  41. namespace SecurityAgent {
  42. #<span class="enscript-reference">endif</span> <span class="enscript-comment">/* __cplusplus__ */</span>
  43. <span class="enscript-comment">// Manimum number of failed authentications before
  44. </span><span class="enscript-comment">// SecurityAgent dialog is killed.
  45. </span>#<span class="enscript-reference">define</span> <span class="enscript-variable-name">kMaximumAuthorizationTries</span> 10000
  46. <span class="enscript-comment">// Number of failed authentications before a password
  47. </span><span class="enscript-comment">// hint is displayed.
  48. </span>#<span class="enscript-reference">define</span> <span class="enscript-variable-name">kAuthorizationTriesBeforeHint</span> 3
  49. #<span class="enscript-reference">define</span> <span class="enscript-variable-name">maxPassphraseLength</span> 1024
  50. <span class="enscript-comment">//
  51. </span><span class="enscript-comment">// Unified reason codes transmitted to SecurityAgent (and internationalized there)
  52. </span><span class="enscript-comment">//
  53. </span><span class="enscript-type">enum</span> Reason {
  54. noReason = 0, <span class="enscript-comment">// no reason (not used, used as a NULL)
  55. </span> unknownReason, <span class="enscript-comment">// something else (catch-all internal error)
  56. </span>
  57. <span class="enscript-comment">// reasons for asking for a new passphrase
  58. </span> newDatabase = 11, <span class="enscript-comment">// need passphrase for a new database
  59. </span> changePassphrase, <span class="enscript-comment">// changing passphrase for existing database
  60. </span>
  61. <span class="enscript-comment">// reasons for retrying an unlock query
  62. </span> invalidPassphrase = 21, <span class="enscript-comment">// passphrase was wrong
  63. </span>
  64. <span class="enscript-comment">// reasons for retrying a new passphrase query
  65. </span> passphraseIsNull = 31, <span class="enscript-comment">// empty passphrase
  66. </span> passphraseTooSimple, <span class="enscript-comment">// passphrase is not complex enough
  67. </span> passphraseRepeated, <span class="enscript-comment">// passphrase was used before (must use new one)
  68. </span> passphraseUnacceptable, <span class="enscript-comment">// passphrase unacceptable for some other reason
  69. </span> oldPassphraseWrong, <span class="enscript-comment">// the old passphrase given is wrong
  70. </span>
  71. <span class="enscript-comment">// reasons for retrying an authorization query
  72. </span> userNotInGroup = 41, <span class="enscript-comment">// authenticated user not in needed group
  73. </span> unacceptableUser, <span class="enscript-comment">// authenticated user unacceptable for some other reason
  74. </span>
  75. <span class="enscript-comment">// reasons for canceling a staged query
  76. </span> tooManyTries = 61, <span class="enscript-comment">// too many failed attempts to get it right
  77. </span> noLongerNeeded, <span class="enscript-comment">// the queried item is no longer needed
  78. </span> keychainAddFailed, <span class="enscript-comment">// the requested itemed couldn't be added to the keychain
  79. </span> generalErrorCancel, <span class="enscript-comment">// something went wrong so we have to give up now
  80. </span>
  81. worldChanged = 101
  82. };
  83. <span class="enscript-type">typedef</span> <span class="enscript-type">enum</span> {
  84. tool = 'TOOL',
  85. bundle = 'BNDL',
  86. unknown = 'UNKN'
  87. } RequestorType;
  88. #<span class="enscript-reference">if</span> <span class="enscript-reference">defined</span>(<span class="enscript-variable-name">__cplusplus</span>)
  89. using MachPlusPlus::Port;
  90. using MachPlusPlus::PortSet;
  91. using MachPlusPlus::Bootstrap;
  92. using MachPlusPlus::ReceivePort;
  93. using MachPlusPlus::Message;
  94. using Authorization::AuthItemSet;
  95. using Authorization::AuthValueVector;
  96. class Clients;
  97. class Client
  98. {
  99. friend class Clients;
  100. <span class="enscript-type">enum</span> MessageType { requestInterruptMessage, didDeactivateMessage, reportErrorMessage };
  101. <span class="enscript-reference">public</span>:
  102. Client();
  103. virtual ~Client();
  104. <span class="enscript-type">static</span> AuthItemSet clientHints(SecurityAgent::RequestorType type, std::string &amp;path, pid_t clientPid, uid_t clientUid);
  105. <span class="enscript-type">static</span> OSStatus startTransaction(Port serverPort);
  106. <span class="enscript-type">static</span> OSStatus endTransaction(Port serverPort);
  107. <span class="enscript-reference">protected</span>:
  108. <span class="enscript-type">void</span> establishServer();
  109. <span class="enscript-reference">public</span>:
  110. <span class="enscript-type">void</span> activate(Port serverPort);
  111. OSStatus create(<span class="enscript-type">const</span> <span class="enscript-type">char</span> *pluginId, <span class="enscript-type">const</span> <span class="enscript-type">char</span> *mechanismId, <span class="enscript-type">const</span> SessionId inSessionId);
  112. <span class="enscript-type">void</span> setArguments(<span class="enscript-type">const</span> Authorization::AuthValueVector&amp; inArguments) { mArguments = inArguments; }
  113. <span class="enscript-type">void</span> setInput(<span class="enscript-type">const</span> Authorization::AuthItemSet&amp; inHints, <span class="enscript-type">const</span> Authorization::AuthItemSet&amp; inContext) { mInHints = inHints; mInContext = inContext; }
  114. OSStatus invoke();
  115. OSStatus deactivate();
  116. OSStatus destroy();
  117. OSStatus terminate();
  118. <span class="enscript-type">void</span> receive();
  119. <span class="enscript-type">void</span> didCreate(<span class="enscript-type">const</span> mach_port_t inStagePort);
  120. <span class="enscript-type">void</span> setResult(<span class="enscript-type">const</span> AuthorizationResult inResult, <span class="enscript-type">const</span> AuthorizationItemSet *inHints, <span class="enscript-type">const</span> AuthorizationItemSet *inContext);
  121. <span class="enscript-type">void</span> requestInterrupt(); <span class="enscript-comment">// setMessageType(requestInterrupt);
  122. </span> <span class="enscript-type">void</span> didDeactivate(); <span class="enscript-comment">// setMessageType(didDeactivate);
  123. </span>
  124. <span class="enscript-type">void</span> setError(<span class="enscript-type">const</span> OSStatus inMechanismError); <span class="enscript-comment">// setMessageType(reportError); setError(mechanismError);
  125. </span> OSStatus getError();
  126. AuthorizationResult result() { <span class="enscript-keyword">return</span> mResult; }
  127. <span class="enscript-type">typedef</span> <span class="enscript-type">enum</span> _PluginState {
  128. init,
  129. created,
  130. current,
  131. deactivating,
  132. active,
  133. interrupting,
  134. dead
  135. } PluginState;
  136. PluginState state() { <span class="enscript-keyword">return</span> mState; }
  137. <span class="enscript-reference">protected</span>:
  138. <span class="enscript-type">void</span> setMessageType(<span class="enscript-type">const</span> MessageType inMessageType);
  139. <span class="enscript-comment">// allow didCreate to set stagePort
  140. </span> <span class="enscript-type">void</span> setStagePort(<span class="enscript-type">const</span> mach_port_t inStagePort);
  141. <span class="enscript-comment">// allow server routines to use request port to find instance
  142. </span>
  143. <span class="enscript-comment">// @@@ implement lessThan operator for set in terms of instance
  144. </span>
  145. <span class="enscript-reference">protected</span>:
  146. <span class="enscript-type">void</span> setup();
  147. <span class="enscript-type">void</span> teardown() throw();
  148. Port mServerPort;
  149. Port mStagePort;
  150. Port mClientPort;
  151. MessageType mMessageType;
  152. OSStatus mErrorState;
  153. AuthorizationResult mResult;
  154. AuthValueVector mArguments;
  155. AuthItemSet mInHints;
  156. AuthItemSet mInContext;
  157. AuthItemSet mOutHints;
  158. AuthItemSet mOutContext;
  159. PluginState mState;
  160. <span class="enscript-type">void</span> setState(PluginState mState);
  161. <span class="enscript-reference">public</span>:
  162. mach_port_t instance() <span class="enscript-type">const</span> { <span class="enscript-keyword">return</span> mClientPort; }
  163. <span class="enscript-comment">// bool operator == (const Client &amp;other) const { return this-&gt;instance() == other.instance(); }
  164. </span> bool operator &lt; (<span class="enscript-type">const</span> Client &amp;other) <span class="enscript-type">const</span> { <span class="enscript-keyword">return</span> this-&gt;instance() &lt; other.instance(); }
  165. AuthItemSet &amp;inHints() { <span class="enscript-keyword">return</span> mInHints; }
  166. AuthItemSet &amp;inContext() { <span class="enscript-keyword">return</span> mInContext; }
  167. AuthItemSet &amp;outHints() { <span class="enscript-keyword">return</span> mOutHints; }
  168. AuthItemSet &amp;outContext() { <span class="enscript-keyword">return</span> mOutContext; }
  169. <span class="enscript-reference">public</span>:
  170. <span class="enscript-type">void</span> check(mach_msg_return_t returnCode);
  171. <span class="enscript-type">void</span> checkResult();
  172. };
  173. class Clients
  174. {
  175. friend class Client;
  176. <span class="enscript-reference">protected</span>:
  177. set&lt;Client*&gt; mClients;
  178. PortSet mClientPortSet;
  179. <span class="enscript-reference">public</span>:
  180. Clients() {}
  181. <span class="enscript-type">void</span> create(); <span class="enscript-comment">// create an agentclient
  182. </span> <span class="enscript-type">void</span> insert(Client *agent) { StLock&lt;Mutex&gt; _(mLock); mClients.insert(agent); mClientPortSet += agent-&gt;instance(); }
  183. <span class="enscript-type">void</span> remove(Client *agent) { StLock&lt;Mutex&gt; _(mLock); mClientPortSet -= agent-&gt;instance(); mClients.erase(agent); }
  184. Client &amp;find(<span class="enscript-type">const</span> mach_port_t instance) <span class="enscript-type">const</span>;
  185. bool receive();
  186. bool compare(<span class="enscript-type">const</span> Client * client, mach_port_t instance);
  187. mutable Mutex mLock;
  188. <span class="enscript-type">static</span> ThreadNexus&lt;Clients&gt; gClients;
  189. };
  190. } <span class="enscript-comment">// end namespace Authorization
  191. </span>
  192. #<span class="enscript-reference">endif</span> <span class="enscript-comment">/* __cplusplus__ */</span>
  193. #<span class="enscript-reference">endif</span> <span class="enscript-comment">/* _H_AGENTCLIENT */</span>
  194. </pre>
  195. <hr />
  196. </body></html>