Imported Upstream version 1.10.2
[platform/upstream/krb5.git] / src / ccapi / common / win / OldCC / init.hxx
1 /*
2  * $Header$
3  *
4  * Copyright 2008 Massachusetts Institute of Technology.
5  * All Rights Reserved.
6  *
7  * Export of this software from the United States of America may
8  * require a specific license from the United States Government.
9  * It is the responsibility of any person or organization contemplating
10  * export to obtain such a license before exporting.
11  *
12  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13  * distribute this software and its documentation for any purpose and
14  * without fee is hereby granted, provided that the above copyright
15  * notice appear in all copies and that both that copyright notice and
16  * this permission notice appear in supporting documentation, and that
17  * the name of M.I.T. not be used in advertising or publicity pertaining
18  * to distribution of the software without specific, written prior
19  * permission.  Furthermore if you modify this software you must label
20  * your software as modified software and not distribute it in such a
21  * fashion that it might be confused with the original M.I.T. software.
22  * M.I.T. makes no representations about the suitability of
23  * this software for any purpose.  It is provided "as is" without express
24  * or implied warranty.
25  */
26
27 #pragma once
28 #include "autolock.hxx"
29 #include <rpc.h>
30
31 typedef RPC_STATUS (RPC_ENTRY *FP_RpcBindingSetAuthInfoExA)(
32     IN RPC_BINDING_HANDLE Binding,
33     IN unsigned char __RPC_FAR * ServerPrincName,
34     IN unsigned long AuthnLevel,
35     IN unsigned long AuthnSvc,
36     IN RPC_AUTH_IDENTITY_HANDLE AuthIdentity, OPTIONAL
37     IN unsigned long AuthzSvc,
38     IN RPC_SECURITY_QOS *SecurityQos OPTIONAL
39     );
40
41 typedef RPC_STATUS (RPC_ENTRY *FP_RpcBindingSetAuthInfoExW)(
42     IN RPC_BINDING_HANDLE Binding,
43     IN unsigned short __RPC_FAR * ServerPrincName,
44     IN unsigned long AuthnLevel,
45     IN unsigned long AuthnSvc,
46     IN RPC_AUTH_IDENTITY_HANDLE AuthIdentity, OPTIONAL
47     IN unsigned long AuthzSvc, OPTIONAL
48     IN RPC_SECURITY_QOS *SecurityQOS
49     );
50
51 typedef RPC_STATUS (RPC_ENTRY *FP_RpcServerRegisterIfEx)(
52     IN RPC_IF_HANDLE IfSpec,
53     IN UUID __RPC_FAR * MgrTypeUuid,
54     IN RPC_MGR_EPV __RPC_FAR * MgrEpv,
55     IN unsigned int Flags,
56     IN unsigned int MaxCalls,
57     IN RPC_IF_CALLBACK_FN __RPC_FAR *IfCallback
58     );
59
60 #ifdef UNICODE
61 #define FP_RpcBindingSetAuthInfoEx FP_RpcBindingSetAuthInfoExW
62 #define FN_RpcBindingSetAuthInfoEx "RpcBindingSetAuthInfoExW"
63 #else
64 #define FP_RpcBindingSetAuthInfoEx FP_RpcBindingSetAuthInfoExA
65 #define FN_RpcBindingSetAuthInfoEx "RpcBindingSetAuthInfoExA"
66 #endif
67
68 #define FN_RpcServerRegisterIfEx   "RpcServerRegisterIfEx"
69
70 class Init
71 {
72 public:
73     struct InitInfo {
74         BOOL isNT;
75         FP_RpcBindingSetAuthInfoEx fRpcBindingSetAuthInfoEx;
76         FP_RpcServerRegisterIfEx fRpcServerRegisterIfEx;
77     };
78
79     static DWORD Initialize();
80     static DWORD Cleanup();
81     static DWORD Info(InitInfo& info);
82
83     static bool Initialized() { return s_init; }
84
85 private:
86     static CcOsLock s_lock;
87     static DWORD s_refcount;
88     static DWORD s_error;
89     static bool s_init;
90     static InitInfo s_info;
91     static HINSTANCE s_hRpcDll;
92 };
93
94 #define INIT_INIT_EX(trap, error) \
95 do \
96 { \
97     if (!Init::Initialized()) \
98     { \
99         DWORD rc = Init::Initialize(); \
100         if (rc) return (trap) ? (error) : rc; \
101     } \
102 } while(0)