winnt-dont-display-ibm-legal-message-20040326
[openafs.git] / src / WINNT / afsapplib / al_dynlink.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
13 }
14
15 #include <WINNT/afsapplib.h>
16 #include "al_dynlink.h"
17
18
19 /*
20  * LIBRARIES __________________________________________________________________
21  *
22  */
23
24 #define cszLIBRARY_UTIL        TEXT("AfsAdminUtil.dll")
25 #define cszLIBRARY_KAS         TEXT("AfsKasAdmin.dll")
26 #define cszLIBRARY_CLIENT      TEXT("AfsClientAdmin.dll")
27
28
29 /*
30  * ADMIN ______________________________________________________________________
31  *
32  */
33
34 static size_t g_cReqUtilLibrary = 0;
35 static HINSTANCE g_hiUtilLibrary = NULL;
36
37 util_AdminErrorCodeTranslate_t util_AdminErrorCodeTranslateP = NULL;
38
39
40 BOOL OpenUtilLibrary (ULONG *pStatus)
41 {
42    BOOL rc = FALSE;
43    ULONG status = ERROR_DLL_NOT_FOUND;
44
45    if ((++g_cReqUtilLibrary) == 1)
46       {
47       if ( ((g_hiUtilLibrary = LoadLibrary (cszLIBRARY_UTIL)) == NULL) ||
48            ((util_AdminErrorCodeTranslateP = (util_AdminErrorCodeTranslate_t)GetProcAddress (g_hiUtilLibrary, "util_AdminErrorCodeTranslate")) == NULL) )
49          {
50          status = GetLastError();
51          CloseUtilLibrary();
52          }
53       }
54    if (g_hiUtilLibrary)
55       {
56       rc = TRUE;
57       }
58
59    if (pStatus)
60       *pStatus = status;
61    return rc;
62 }
63
64
65 void CloseUtilLibrary (void)
66 {
67    if ((--g_cReqUtilLibrary) == 0)
68       {
69       if (g_hiUtilLibrary)
70          FreeLibrary (g_hiUtilLibrary);
71       g_hiUtilLibrary = NULL;
72       }
73 }
74
75
76 /*
77  * KAS ________________________________________________________________________
78  *
79  */
80
81 static size_t g_cReqKasLibrary = 0;
82 static HINSTANCE g_hiKasLibrary = NULL;
83
84 kas_PrincipalGetBegin_t kas_PrincipalGetBeginP = NULL;
85 kas_PrincipalGetNext_t kas_PrincipalGetNextP = NULL;
86 kas_PrincipalGetDone_t kas_PrincipalGetDoneP = NULL;
87 kas_PrincipalGet_t kas_PrincipalGetP = NULL;
88
89
90 BOOL OpenKasLibrary (ULONG *pStatus)
91 {
92    BOOL rc = FALSE;
93    ULONG status = ERROR_DLL_NOT_FOUND;
94
95    if ((++g_cReqKasLibrary) == 1)
96       {
97       if ( ((g_hiKasLibrary = LoadLibrary (cszLIBRARY_KAS)) == NULL) ||
98            ((kas_PrincipalGetBeginP = (kas_PrincipalGetBegin_t)GetProcAddress (g_hiKasLibrary, "kas_PrincipalGetBegin")) == NULL) ||
99            ((kas_PrincipalGetNextP = (kas_PrincipalGetNext_t)GetProcAddress (g_hiKasLibrary, "kas_PrincipalGetNext")) == NULL) ||
100            ((kas_PrincipalGetDoneP = (kas_PrincipalGetDone_t)GetProcAddress (g_hiKasLibrary, "kas_PrincipalGetDone")) == NULL) ||
101            ((kas_PrincipalGetP = (kas_PrincipalGet_t)GetProcAddress (g_hiKasLibrary, "kas_PrincipalGet")) == NULL) )
102          {
103          status = GetLastError();
104          CloseKasLibrary();
105          }
106       }
107    if (g_hiKasLibrary)
108       {
109       rc = TRUE;
110       }
111
112    if (pStatus)
113       *pStatus = status;
114    return rc;
115 }
116
117
118 void CloseKasLibrary (void)
119 {
120    if ((--g_cReqKasLibrary) == 0)
121       {
122       if (g_hiKasLibrary)
123          FreeLibrary (g_hiKasLibrary);
124       g_hiKasLibrary = NULL;
125       }
126 }
127
128
129 /*
130  * CLIENT _____________________________________________________________________
131  *
132  */
133
134 static size_t g_cReqClientLibrary = 0;
135 static HINSTANCE g_hiClientLibrary = NULL;
136
137 typedef int (ADMINAPI *afsclient_Init_t)(afs_status_p st);
138
139 afsclient_TokenGetExisting_t afsclient_TokenGetExistingP = NULL;
140 afsclient_TokenGetNew_t afsclient_TokenGetNewP = NULL;
141 afsclient_TokenClose_t afsclient_TokenCloseP = NULL;
142 afsclient_TokenQuery_t afsclient_TokenQueryP = NULL;
143 afsclient_CellOpen_t afsclient_CellOpenP = NULL;
144 afsclient_CellClose_t afsclient_CellCloseP = NULL;
145 afsclient_LocalCellGet_t afsclient_LocalCellGetP = NULL;
146 afsclient_Init_t afsclient_InitP = NULL;
147
148
149 BOOL OpenClientLibrary (ULONG *pStatus)
150 {
151    BOOL rc = FALSE;
152    ULONG status = ERROR_DLL_NOT_FOUND;
153
154    if ((++g_cReqClientLibrary) == 1)
155       {
156       if ( ((g_hiClientLibrary = LoadLibrary (cszLIBRARY_CLIENT)) == NULL) ||
157            ((afsclient_TokenGetExistingP = (afsclient_TokenGetExisting_t)GetProcAddress (g_hiClientLibrary, "afsclient_TokenGetExisting")) == NULL) ||
158            ((afsclient_TokenGetNewP = (afsclient_TokenGetNew_t)GetProcAddress (g_hiClientLibrary, "afsclient_TokenGetNew")) == NULL) ||
159            ((afsclient_TokenCloseP = (afsclient_TokenClose_t)GetProcAddress (g_hiClientLibrary, "afsclient_TokenClose")) == NULL) ||
160            ((afsclient_TokenQueryP = (afsclient_TokenQuery_t)GetProcAddress (g_hiClientLibrary, "afsclient_TokenQuery")) == NULL) ||
161            ((afsclient_CellOpenP = (afsclient_CellOpen_t)GetProcAddress (g_hiClientLibrary, "afsclient_CellOpen")) == NULL) ||
162            ((afsclient_CellCloseP = (afsclient_CellClose_t)GetProcAddress (g_hiClientLibrary, "afsclient_CellClose")) == NULL) ||
163            ((afsclient_LocalCellGetP = (afsclient_LocalCellGet_t)GetProcAddress (g_hiClientLibrary, "afsclient_LocalCellGet")) == NULL) ||
164            ((afsclient_InitP = (afsclient_Init_t)GetProcAddress (g_hiClientLibrary, "afsclient_Init")) == NULL) )
165          {
166          status = GetLastError();
167          CloseClientLibrary();
168          }
169       else if (!(*afsclient_InitP)((afs_status_p)&status))
170          {
171          CloseClientLibrary();
172          }
173       }
174    if (g_hiClientLibrary)
175       {
176       rc = TRUE;
177       }
178
179    if (pStatus)
180       *pStatus = status;
181    return rc;
182 }
183
184
185 void CloseClientLibrary (void)
186 {
187    if ((--g_cReqClientLibrary) == 0)
188       {
189       if (g_hiClientLibrary)
190          FreeLibrary (g_hiClientLibrary);
191       g_hiClientLibrary = NULL;
192       }
193 }
194