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>
43 #include <WINNT/afsreg.h>
45 HMODULE hVolStatus = NULL;
46 dll_VolStatus_Funcs_t dll_funcs;
47 cm_VolStatus_Funcs_t cm_funcs;
49 static char volstat_NetbiosName[64] = "";
52 cm_VolStatus_Active(void)
54 return (hVolStatus != NULL);
57 /* This function is used to load any Volume Status Handlers
58 * and their associated function pointers.
61 cm_VolStatus_Initialization(void)
63 long (__fastcall * dll_VolStatus_Initialization)(dll_VolStatus_Funcs_t * dll_funcs, cm_VolStatus_Funcs_t *cm_funcs) = NULL;
67 char wd[MAX_PATH+1] = "";
69 code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
70 0, KEY_QUERY_VALUE, &parmKey);
71 if (code == ERROR_SUCCESS) {
72 dummyLen = sizeof(wd);
73 code = RegQueryValueEx(parmKey, "VolStatusHandler", NULL, NULL,
74 (BYTE *) &wd, &dummyLen);
77 dummyLen = sizeof(volstat_NetbiosName);
78 code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
79 (BYTE *)volstat_NetbiosName, &dummyLen);
81 RegCloseKey (parmKey);
84 if (code == ERROR_SUCCESS && wd[0])
85 hVolStatus = LoadLibrary(wd);
87 (FARPROC) dll_VolStatus_Initialization = GetProcAddress(hVolStatus, "@VolStatus_Initialization@8");
88 if (dll_VolStatus_Initialization) {
89 cm_funcs.version = CM_VOLSTATUS_FUNCS_VERSION;
90 cm_funcs.cm_VolStatus_Path_To_ID = cm_VolStatus_Path_To_ID;
91 cm_funcs.cm_VolStatus_Path_To_DFSlink = cm_VolStatus_Path_To_DFSlink;
93 dll_funcs.version = DLL_VOLSTATUS_FUNCS_VERSION;
94 code = dll_VolStatus_Initialization(&dll_funcs, &cm_funcs);
97 if (dll_VolStatus_Initialization == NULL || code != 0 ||
98 dll_funcs.version != DLL_VOLSTATUS_FUNCS_VERSION) {
99 FreeLibrary(hVolStatus);
105 osi_Log1(afsd_logp,"cm_VolStatus_Initialization 0x%x", code);
110 /* This function is used to unload any Volume Status Handlers
111 * that were loaded during initialization.
114 cm_VolStatus_Finalize(void)
116 osi_Log1(afsd_logp,"cm_VolStatus_Finalize handle 0x%x", hVolStatus);
118 if (hVolStatus == NULL)
121 FreeLibrary(hVolStatus);
126 /* This function notifies the Volume Status Handlers that the
127 * AFS client service has started. If the network is started
128 * at this point we call cm_VolStatus_Network_Started().
131 cm_VolStatus_Service_Started(void)
135 osi_Log1(afsd_logp,"cm_VolStatus_Service_Started handle 0x%x", hVolStatus);
137 if (hVolStatus == NULL)
140 code = dll_funcs.dll_VolStatus_Service_Started();
141 if (code == 0 && smb_IsNetworkStarted())
142 code = dll_funcs.dll_VolStatus_Network_Started(cm_NetbiosName, cm_NetbiosName);
147 /* This function notifies the Volume Status Handlers that the
148 * AFS client service is stopping.
151 cm_VolStatus_Service_Stopped(void)
155 osi_Log1(afsd_logp,"cm_VolStatus_Service_Stopped handle 0x%x", hVolStatus);
157 if (hVolStatus == NULL)
160 code = dll_funcs.dll_VolStatus_Service_Stopped();
166 /* This function notifies the Volume Status Handlers that the
167 * AFS client service is accepting network requests using the
168 * specified netbios names.
172 cm_VolStatus_Network_Started(const char * netbios32, const char * netbios64)
174 cm_VolStatus_Network_Started(const char * netbios)
179 if (hVolStatus == NULL)
183 code = dll_funcs.dll_VolStatus_Network_Started(netbios32, netbios64);
185 code = dll_funcs.dll_VolStatus_Network_Started(netbios, netbios);
191 /* This function notifies the Volume Status Handlers that the
192 * AFS client service is no longer accepting network requests
193 * using the specified netbios names
197 cm_VolStatus_Network_Stopped(const char * netbios32, const char * netbios64)
199 cm_VolStatus_Network_Stopped(const char * netbios)
204 if (hVolStatus == NULL)
208 code = dll_funcs.dll_VolStatus_Network_Stopped(netbios32, netbios64);
210 code = dll_funcs.dll_VolStatus_Network_Stopped(netbios, netbios);
216 /* This function is called when the IP address list changes.
217 * Volume Status Handlers can use this notification as a hint
218 * that it might be possible to determine volume IDs for paths
219 * that previously were not accessible.
222 cm_VolStatus_Network_Addr_Change(void)
226 if (hVolStatus == NULL)
229 code = dll_funcs.dll_VolStatus_Network_Addr_Change();
234 /* This function notifies the Volume Status Handlers that the
235 * state of the specified cell.volume has changed.
238 cm_VolStatus_Change_Notification(afs_uint32 cellID, afs_uint32 volID, enum volstatus status)
242 if (hVolStatus == NULL)
245 code = dll_funcs.dll_VolStatus_Change_Notification(cellID, volID, status);
253 cm_VolStatus_Notify_DFS_Mapping(cm_scache_t *scp, char *tidPathp, char *pathp)
259 if (hVolStatus == NULL || dll_funcs.version < 2)
262 snprintf(src,sizeof(src), "\\\\%s%s", volstat_NetbiosName, tidPathp);
264 if ((src[len-1] == '\\' || src[len-1] == '/') &&
265 (pathp[0] == '\\' || pathp[0] == '/'))
266 strncat(src, &pathp[1], sizeof(src));
268 strncat(src, pathp, sizeof(src));
270 for ( p=src; *p; p++ ) {
275 code = dll_funcs.dll_VolStatus_Notify_DFS_Mapping(scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique,
276 src, scp->mountPointStringp);
282 cm_VolStatus_Invalidate_DFS_Mapping(cm_scache_t *scp)
286 if (hVolStatus == NULL || dll_funcs.version < 2)
289 code = dll_funcs.dll_VolStatus_Invalidate_DFS_Mapping(scp->fid.cell, scp->fid.volume, scp->fid.vnode, scp->fid.unique);
296 cm_VolStatus_Path_To_ID(const char * share, const char * path, afs_uint32 * cellID, afs_uint32 * volID, enum volstatus *pstatus)
303 if (cellID == NULL || volID == NULL)
304 return CM_ERROR_INVAL;
306 osi_Log2(afsd_logp,"cm_VolStatus_Path_To_ID share %s path %s",
307 osi_LogSaveString(afsd_logp, (char *)share), osi_LogSaveString(afsd_logp, (char *)path));
311 code = cm_NameI(cm_data.rootSCachep, (char *)path, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW, cm_rootUserp, (char *)share, &req, &scp);
315 lock_ObtainWrite(&scp->rw);
316 code = cm_SyncOp(scp, NULL,cm_rootUserp, &req, 0,
317 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
319 lock_ReleaseWrite(&scp->rw);
320 cm_ReleaseSCache(scp);
324 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
326 *cellID = scp->fid.cell;
327 *volID = scp->fid.volume;
328 volp = cm_GetVolumeByFID(&scp->fid);
330 *pstatus = cm_GetVolumeStatus(volp, scp->fid.volume);
333 *pstatus = vl_unknown;
335 lock_ReleaseWrite(&scp->rw);
336 cm_ReleaseSCache(scp);
339 osi_Log1(afsd_logp,"cm_VolStatus_Path_To_ID code 0x%x",code);
344 cm_VolStatus_Path_To_DFSlink(const char * share, const char * path, afs_uint32 *pBufSize, char *pBuffer)
351 if (pBufSize == NULL || (pBuffer == NULL && *pBufSize != 0))
352 return CM_ERROR_INVAL;
354 osi_Log2(afsd_logp,"cm_VolStatus_Path_To_DFSlink share %s path %s",
355 osi_LogSaveString(afsd_logp, (char *)share), osi_LogSaveString(afsd_logp, (char *)path));
359 code = cm_NameI(cm_data.rootSCachep, (char *)path, CM_FLAG_CASEFOLD | CM_FLAG_FOLLOW,
360 cm_rootUserp, (char *)share, &req, &scp);
364 lock_ObtainWrite(&scp->rw);
365 code = cm_SyncOp(scp, NULL, cm_rootUserp, &req, 0,
366 CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
368 lock_ReleaseWrite(&scp->rw);
369 cm_ReleaseSCache(scp);
373 cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_GETSTATUS);
375 if (scp->fileType != CM_SCACHETYPE_DFSLINK) {
376 code = CM_ERROR_NOT_A_DFSLINK;
380 len = strlen(scp->mountPointStringp) + 1;
383 else if (*pBufSize >= len) {
384 strcpy(pBuffer, scp->mountPointStringp);
387 code = CM_ERROR_TOOBIG;
391 lock_ReleaseWrite(&scp->rw);
392 cm_ReleaseSCache(scp);
395 osi_Log1(afsd_logp,"cm_VolStatus_Path_To_DFSlink code 0x%x",code);