Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afsapplib / al_dynlink.cpp
blob8bea2b0d9f492879222c2656b98d7bcd24d8afb7
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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 */
10 #include <winsock2.h>
11 #include <ws2tcpip.h>
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
18 #include <WINNT/afsapplib.h>
19 #include "al_dynlink.h"
23 * LIBRARIES __________________________________________________________________
27 #define cszLIBRARY_UTIL TEXT("AfsAdminUtil.dll")
28 #define cszLIBRARY_KAS TEXT("AfsKasAdmin.dll")
29 #define cszLIBRARY_CLIENT TEXT("AfsClientAdmin.dll")
33 * ADMIN ______________________________________________________________________
37 static size_t g_cReqUtilLibrary = 0;
38 static HINSTANCE g_hiUtilLibrary = NULL;
40 util_AdminErrorCodeTranslate_t util_AdminErrorCodeTranslateP = NULL;
43 BOOL OpenUtilLibrary (ULONG *pStatus)
45 BOOL rc = FALSE;
46 ULONG status = ERROR_DLL_NOT_FOUND;
48 if ((++g_cReqUtilLibrary) == 1)
50 if ( ((g_hiUtilLibrary = LoadLibrary (cszLIBRARY_UTIL)) == NULL) ||
51 ((util_AdminErrorCodeTranslateP = (util_AdminErrorCodeTranslate_t)GetProcAddress (g_hiUtilLibrary, "util_AdminErrorCodeTranslate")) == NULL) )
53 status = GetLastError();
54 CloseUtilLibrary();
57 if (g_hiUtilLibrary)
59 rc = TRUE;
62 if (pStatus)
63 *pStatus = status;
64 return rc;
68 void CloseUtilLibrary (void)
70 if ((--g_cReqUtilLibrary) == 0)
72 if (g_hiUtilLibrary)
73 FreeLibrary (g_hiUtilLibrary);
74 g_hiUtilLibrary = NULL;
80 * KAS ________________________________________________________________________
84 static size_t g_cReqKasLibrary = 0;
85 static HINSTANCE g_hiKasLibrary = NULL;
87 kas_PrincipalGetBegin_t kas_PrincipalGetBeginP = NULL;
88 kas_PrincipalGetNext_t kas_PrincipalGetNextP = NULL;
89 kas_PrincipalGetDone_t kas_PrincipalGetDoneP = NULL;
90 kas_PrincipalGet_t kas_PrincipalGetP = NULL;
93 BOOL OpenKasLibrary (ULONG *pStatus)
95 BOOL rc = FALSE;
96 ULONG status = ERROR_DLL_NOT_FOUND;
98 if ((++g_cReqKasLibrary) == 1)
100 if ( ((g_hiKasLibrary = LoadLibrary (cszLIBRARY_KAS)) == NULL) ||
101 ((kas_PrincipalGetBeginP = (kas_PrincipalGetBegin_t)GetProcAddress (g_hiKasLibrary, "kas_PrincipalGetBegin")) == NULL) ||
102 ((kas_PrincipalGetNextP = (kas_PrincipalGetNext_t)GetProcAddress (g_hiKasLibrary, "kas_PrincipalGetNext")) == NULL) ||
103 ((kas_PrincipalGetDoneP = (kas_PrincipalGetDone_t)GetProcAddress (g_hiKasLibrary, "kas_PrincipalGetDone")) == NULL) ||
104 ((kas_PrincipalGetP = (kas_PrincipalGet_t)GetProcAddress (g_hiKasLibrary, "kas_PrincipalGet")) == NULL) )
106 status = GetLastError();
107 CloseKasLibrary();
110 if (g_hiKasLibrary)
112 rc = TRUE;
115 if (pStatus)
116 *pStatus = status;
117 return rc;
121 void CloseKasLibrary (void)
123 if ((--g_cReqKasLibrary) == 0)
125 if (g_hiKasLibrary)
126 FreeLibrary (g_hiKasLibrary);
127 g_hiKasLibrary = NULL;
133 * CLIENT _____________________________________________________________________
137 static size_t g_cReqClientLibrary = 0;
138 static HINSTANCE g_hiClientLibrary = NULL;
140 typedef int (ADMINAPI *afsclient_Init_t)(afs_status_p st);
142 afsclient_TokenGetExisting_t afsclient_TokenGetExistingP = NULL;
143 afsclient_TokenGetNew_t afsclient_TokenGetNewP = NULL;
144 afsclient_TokenClose_t afsclient_TokenCloseP = NULL;
145 afsclient_TokenQuery_t afsclient_TokenQueryP = NULL;
146 afsclient_CellOpen_t afsclient_CellOpenP = NULL;
147 afsclient_CellClose_t afsclient_CellCloseP = NULL;
148 afsclient_LocalCellGet_t afsclient_LocalCellGetP = NULL;
149 afsclient_Init_t afsclient_InitP = NULL;
152 BOOL OpenClientLibrary (ULONG *pStatus)
154 BOOL rc = FALSE;
155 ULONG status = ERROR_DLL_NOT_FOUND;
157 if ((++g_cReqClientLibrary) == 1)
159 if ( ((g_hiClientLibrary = LoadLibrary (cszLIBRARY_CLIENT)) == NULL) ||
160 ((afsclient_TokenGetExistingP = (afsclient_TokenGetExisting_t)GetProcAddress (g_hiClientLibrary, "afsclient_TokenGetExisting")) == NULL) ||
161 ((afsclient_TokenGetNewP = (afsclient_TokenGetNew_t)GetProcAddress (g_hiClientLibrary, "afsclient_TokenGetNew")) == NULL) ||
162 ((afsclient_TokenCloseP = (afsclient_TokenClose_t)GetProcAddress (g_hiClientLibrary, "afsclient_TokenClose")) == NULL) ||
163 ((afsclient_TokenQueryP = (afsclient_TokenQuery_t)GetProcAddress (g_hiClientLibrary, "afsclient_TokenQuery")) == NULL) ||
164 ((afsclient_CellOpenP = (afsclient_CellOpen_t)GetProcAddress (g_hiClientLibrary, "afsclient_CellOpen")) == NULL) ||
165 ((afsclient_CellCloseP = (afsclient_CellClose_t)GetProcAddress (g_hiClientLibrary, "afsclient_CellClose")) == NULL) ||
166 ((afsclient_LocalCellGetP = (afsclient_LocalCellGet_t)GetProcAddress (g_hiClientLibrary, "afsclient_LocalCellGet")) == NULL) ||
167 ((afsclient_InitP = (afsclient_Init_t)GetProcAddress (g_hiClientLibrary, "afsclient_Init")) == NULL) )
169 status = GetLastError();
170 CloseClientLibrary();
172 else if (!(*afsclient_InitP)((afs_status_p)&status))
174 CloseClientLibrary();
177 if (g_hiClientLibrary)
179 rc = TRUE;
182 if (pStatus)
183 *pStatus = status;
184 return rc;
188 void CloseClientLibrary (void)
190 if ((--g_cReqClientLibrary) == 0)
192 if (g_hiClientLibrary)
193 FreeLibrary (g_hiClientLibrary);
194 g_hiClientLibrary = NULL;