2 * Copyright (c) 2007 Secure Endpoints Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Neither the name of the Secure Endpoints Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 /* This source file provides the declarations
30 * which specify the AFS Cache Manager Volume Status Event
34 #include <afs/param.h>
44 #include <WINNT/afsreg.h>
46 HMODULE hVolStatus = NULL;
47 dll_VolStatus_Funcs_t dll_funcs;
48 cm_VolStatus_Funcs_t cm_funcs;
50 static char volstat_NetbiosName[64] = "";
53 cm_VolStatus_Active(void)
55 return (hVolStatus != NULL);
58 /* This function is used to load any Volume Status Handlers
59 * and their associated function pointers.
62 cm_VolStatus_Initialization(void)
64 long (__fastcall * dll_VolStatus_Initialization)(dll_VolStatus_Funcs_t * dll_funcs, cm_VolStatus_Funcs_t *cm_funcs) = NULL;
68 char wd[MAX_PATH+1] = "";
70 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
71 0, KEY_QUERY_VALUE, &parmKey);
72 if (code == ERROR_SUCCESS) {
73 dummyLen = sizeof(wd);
74 code = RegQueryValueEx(parmKey, "VolStatusHandler", NULL, NULL,
75 (BYTE *) &wd, &dummyLen);
78 dummyLen = sizeof(volstat_NetbiosName);
79 code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
80 (BYTE *)volstat_NetbiosName, &dummyLen);
82 RegCloseKey (parmKey);
85 if (code == ERROR_SUCCESS && wd[0])
86 hVolStatus = LoadLibrary(wd);
88 (FARPROC) dll_VolStatus_Initialization = GetProcAddress(hVolStatus, "@VolStatus_Initialization@8");
89 if (dll_VolStatus_Initialization) {
90 cm_funcs.version = CM_VOLSTATUS_FUNCS_VERSION;
91 cm_funcs.cm_VolStatus_Path_To_ID = cm_VolStatus_Path_To_ID;
92 cm_funcs.cm_VolStatus_Path_To_DFSlink = cm_VolStatus_Path_To_DFSlink;
94 dll_funcs.version = DLL_VOLSTATUS_FUNCS_VERSION;
95 code = dll_VolStatus_Initialization(&dll_funcs, &cm_funcs);
98 if (dll_VolStatus_Initialization == NULL || code != 0 ||
99 dll_funcs.version != DLL_VOLSTATUS_FUNCS_VERSION) {
100 FreeLibrary(hVolStatus);
106 osi_Log1(afsd_logp,"cm_VolStatus_Initialization 0x%x", code);
111 /* This function is used to unload any Volume Status Handlers
112 * that were loaded during initialization.
115 cm_VolStatus_Finalize(void)
117 osi_Log1(afsd_logp,"cm_VolStatus_Finalize handle 0x%x", hVolStatus);
119 if (hVolStatus == NULL)
122 FreeLibrary(hVolStatus);
127 /* This function notifies the Volume Status Handlers that the
128 * AFS client service has started. If the network is started
129 * at this point we call cm_VolStatus_Network_Started().
132 cm_VolStatus_Service_Started(void)
136 osi_Log1(afsd_logp,"cm_VolStatus_Service_Started handle 0x%x", hVolStatus);
138 if (hVolStatus == NULL)
141 code = dll_funcs.dll_VolStatus_Service_Started();
142 if (code == 0 && smb_IsNetworkStarted())
143 code = dll_funcs.dll_VolStatus_Network_Started(cm_NetbiosName, cm_NetbiosName);
148 /* This function notifies the Volume Status Handlers that the
149 * AFS client service is stopping.
152 cm_VolStatus_Service_Stopped(void)
156 osi_Log1(afsd_logp,"cm_VolStatus_Service_Stopped handle 0x%x", hVolStatus);
158 if (hVolStatus == NULL)
161 code = dll_funcs.dll_VolStatus_Service_Stopped();
167 /* This function notifies the Volume Status Handlers that the
168 * AFS client service is accepting network requests using the
169 * specified netbios names.
173 cm_VolStatus_Network_Started(const char * netbios32, const char * netbios64)
175 cm_VolStatus_Network_Started(const char * netbios32)
180 if (hVolStatus == NULL)
184 code = dll_funcs.dll_VolStatus_Network_Started(netbios32, netbios64);
186 code = dll_funcs.dll_VolStatus_Network_Started(netbios32, netbios32);
192 /* This function notifies the Volume Status Handlers that the
193 * AFS client service is no longer accepting network requests
194 * using the specified netbios names
198 cm_VolStatus_Network_Stopped(const char * netbios32, const char * netbios64)
200 cm_VolStatus_Network_Stopped(const char * netbios32)
205 if (hVolStatus == NULL)
209 code = dll_funcs.dll_VolStatus_Network_Stopped(netbios32, netbios64);
211 code = dll_funcs.dll_VolStatus_Network_Stopped(netbios32, netbios32);
217 /* This function is called when the IP address list changes.
218 * Volume Status Handlers can use this notification as a hint
219 * that it might be possible to determine volume IDs for paths
220 * that previously were not accessible.
223 cm_VolStatus_Network_Addr_Change(void)
227 if (hVolStatus == NULL)
230 code = dll_funcs.dll_VolStatus_Network_Addr_Change();
235 /* This function notifies the Volume Status Handlers that the
236 * state of the specified cell.volume has changed.
239 cm_VolStatus_Change_Notification(afs_uint32 cellID, afs_uint32 volID, enum volstatus status)
243 if (hVolStatus == NULL)
246 code = dll_funcs.dll_VolStatus_Change_Notification(cellID, volID, status);
254 cm_VolStatus_Notify_DFS_Mapping(cm_scache_t *scp, const clientchar_t *ctidPathp,
255 const clientchar_t *cpathp)
260 char * tidPathp = NULL;
263 if (hVolStatus == NULL || dll_funcs.version < 2)
266 tidPathp = cm_ClientStringToUtf8Alloc(ctidPathp, -1, NULL);
267 pathp = cm_ClientStringToUtf8Alloc(cpathp, -1, NULL);
269 snprintf(src,sizeof(src), "\\\\%s%s", volstat_NetbiosName, tidPathp);
271 if ((src[len-1] == '\\' || src[len-1] == '/') &&
272 (pathp[0] == '\\' || pathp[0] == '/'))
273 strncat(src, &pathp[1], sizeof(src));
275 strncat(src, pathp, sizeof(src));
277 for ( p=src; *p; p++ ) {
282 code = dll_funcs.dll_VolStatus_Notify_DFS_Mapping(scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique,
283 src, scp->mountPointStringp);
294 cm_VolStatus_Invalidate_DFS_Mapping(cm_scache_t *scp)
298 if (hVolStatus == NULL || dll_funcs.version < 2)
301 code = dll_funcs.dll_VolStatus_Invalidate_DFS_Mapping(scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
308 cm_VolStatus_Path_To_ID(const char * share, const char * path, afs_uint32 * cellID, afs_uint32 * volID, enum volstatus *pstatus)
314 clientchar_t * cpath = NULL;
315 clientchar_t * cshare = NULL;
317 if (cellID == NULL || volID == NULL)
318 return CM_ERROR_INVAL;
320 osi_Log2(afsd_logp,"cm_VolStatus_Path_To_ID share %s path %s",
321 osi_LogSaveString(afsd_logp, (char *)share), osi_LogSaveString(afsd_logp, (char *)path));
325 cpath = cm_FsStringToClientStringAlloc(path, -1, NULL);
326 cshare = cm_FsStringToClientStringAlloc(share, -1, NULL);
328 code = cm_NameI(cm_data.rootSCachep, cpath,
329 CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
330 cm_rootUserp, cshare, &req, &scp);
334 lock_ObtainWrite(&scp->rw);
335 code = cm_SyncOp(scp, NULL,cm_rootUserp, &req, 0,
336 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
338 lock_ReleaseWrite(&scp->rw);
339 cm_ReleaseSCache(scp);
343 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
345 *cellID = scp->fid.cell;
346 *volID = scp->fid.volume;
347 volp = cm_GetVolumeByFID(&scp->fid);
349 *pstatus = cm_GetVolumeStatus(volp, scp->fid.volume);
352 *pstatus = vl_unknown;
354 lock_ReleaseWrite(&scp->rw);
355 cm_ReleaseSCache(scp);
363 osi_Log1(afsd_logp,"cm_VolStatus_Path_To_ID code 0x%x",code);
368 cm_VolStatus_Path_To_DFSlink(const char * share, const char * path, afs_uint32 *pBufSize, char *pBuffer)
374 clientchar_t *cpath = NULL;
375 clientchar_t *cshare = NULL;
377 if (pBufSize == NULL || (pBuffer == NULL && *pBufSize != 0))
378 return CM_ERROR_INVAL;
380 osi_Log2(afsd_logp,"cm_VolStatus_Path_To_DFSlink share %s path %s",
381 osi_LogSaveString(afsd_logp, (char *)share), osi_LogSaveString(afsd_logp, (char *)path));
385 cpath = cm_FsStringToClientStringAlloc(path, -1, NULL);
386 cshare = cm_FsStringToClientStringAlloc(share, -1, NULL);
388 code = cm_NameI(cm_data.rootSCachep, cpath, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
389 cm_rootUserp, cshare, &req, &scp);
393 lock_ObtainWrite(&scp->rw);
394 code = cm_SyncOp(scp, NULL, cm_rootUserp, &req, 0,
395 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
397 lock_ReleaseWrite(&scp->rw);
398 cm_ReleaseSCache(scp);
402 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
404 if (scp->fileType != CM_SCACHETYPE_DFSLINK) {
405 code = CM_ERROR_NOT_A_DFSLINK;
409 len = strlen(scp->mountPointStringp) + 1;
412 else if (*pBufSize >= len) {
413 strcpy(pBuffer, scp->mountPointStringp);
416 code = CM_ERROR_TOOBIG;
420 lock_ReleaseWrite(&scp->rw);
421 cm_ReleaseSCache(scp);
429 osi_Log1(afsd_logp,"cm_VolStatus_Path_To_DFSlink code 0x%x",code);