]>
git.saurik.com Git - apple/security.git/blob - securityd/src/tokenaccess.h
2 * Copyright (c) 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 // tokenaccess - access management to a TokenDatabase's Token's TokenDaemon's tokend
28 #ifndef _H_TOKENACCESS
29 #define _H_TOKENACCESS
31 #include "tokendatabase.h"
37 // Turn a Key into a TokenKey, when we know that it's that
39 inline TokenKey
&myKey(Key
&key
)
41 return safer_cast
<TokenKey
&>(key
);
46 // The common access/retry/management framework for calls that go to the actual daemon.
48 class Access
: public Token::Access
{
50 Access(Token
&token
) : Token::Access(token
), mIteration(0)
51 { Server::active().longTermActivity(); }
52 template <class Whatever
>
53 Access(Token
&token
, Whatever
&it
) : Token::Access(token
)
54 { add(it
); Server::active().longTermActivity(); }
56 void operator () (const CssmError
&err
);
57 using Token::Access::operator ();
59 void add(TokenAcl
&acl
) { mAcls
.insert(&acl
); }
60 void add(TokenAcl
*acl
) { if (acl
) mAcls
.insert(acl
); }
61 void add(AclSource
&src
) { add(dynamic_cast<TokenAcl
&>(src
.acl())); }
62 void add(AclSource
*src
) { if (src
) add(*src
); }
63 void add(Key
&key
) { mAcls
.insert(&myKey(key
)); }
66 set
<TokenAcl
*> mAcls
; // TokenAcl subclasses to clear on retry
67 unsigned int mIteration
; // iteration count (try, retry, give up)
72 // A nice little macro bracket to apply it.
73 // You must declare an Access called 'access' before doing
76 // GUARD(a call to tokend)
79 #define TRY for (;;) {
81 #define DONE return; \
82 } catch (const CssmError &error) { \
87 #endif //_H_TOKENACCESS