void cm_RankUpServers() { cm_server_t * tsp; lock_ObtainRead(&cm_serverLock); for (tsp = cm_serversAllFirstp; tsp; tsp = (cm_server_t *)osi_QNext(&tsp->allq)) { cm_GetServerNoLock(tsp); lock_ReleaseRead(&cm_serverLock); lock_ObtainMutex(&tsp->mx); /* if the server is not down, rank the server */ if(!(tsp->flags & CM_SERVERFLAG_DOWN)) cm_RankServer(tsp); lock_ReleaseMutex(&tsp->mx); lock_ObtainRead(&cm_serverLock); cm_PutServerNoLock(tsp); } lock_ReleaseRead(&cm_serverLock); }
/** Handle a SMB_COM_READ for an RPC fid Called from smb_ReceiveCoreRead when we receive a read on the RPC fid */ afs_int32 smb_RPCRead(smb_fid_t *fidp, smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) { smb_rpc_t *rpcp; long count; char *op; afs_int32 code; cm_user_t *userp; count = smb_GetSMBParm(inp, 1); userp = smb_GetUserFromVCP(vcp, inp); osi_Log3(smb_logp, "smb_RPCRead for user[0x%p] fid[0x%p (%d)]", userp, fidp, fidp->fid); lock_ObtainMutex(&fidp->mx); rpcp = fidp->rpcp; code = smb_RPC_BeginOp(rpcp); lock_ReleaseMutex(&fidp->mx); if (code) { cm_ReleaseUser(userp); return code; } code = smb_RPC_PrepareRead(rpcp); if (code) { cm_ReleaseUser(userp); smb_RPC_EndOp(rpcp); return code; } count = smb_RPC_ReadPacketLength(rpcp, count); /* now set the parms for a read of count bytes */ smb_SetSMBParm(outp, 0, count); smb_SetSMBParm(outp, 1, 0); smb_SetSMBParm(outp, 2, 0); smb_SetSMBParm(outp, 3, 0); smb_SetSMBParm(outp, 4, 0); smb_SetSMBDataLength(outp, count+3); op = smb_GetSMBData(outp, NULL); *op++ = 1; *op++ = (char)(count & 0xff); *op++ = (char)((count >> 8) & 0xff); smb_RPC_ReadPacket(rpcp, op, count); smb_RPC_EndOp(rpcp); cm_ReleaseUser(userp); return 0; }
void cm_InitCell(int newFile, long maxCells) { static osi_once_t once; if (osi_Once(&once)) { cm_cell_t * cellp; lock_InitializeRWLock(&cm_cellLock, "cell global lock", LOCK_HIERARCHY_CELL_GLOBAL); if ( newFile ) { cm_data.allCellsp = NULL; cm_data.currentCells = 0; cm_data.maxCells = maxCells; memset(cm_data.cellNameHashTablep, 0, sizeof(cm_cell_t *) * cm_data.cellHashTableSize); memset(cm_data.cellIDHashTablep, 0, sizeof(cm_cell_t *) * cm_data.cellHashTableSize); #ifdef AFS_FREELANCE_CLIENT /* Generate a dummy entry for the Freelance cell whether or not * freelance mode is being used in this session */ cellp = &cm_data.cellBaseAddress[cm_data.currentCells++]; memset(cellp, 0, sizeof(cm_cell_t)); cellp->magic = CM_CELL_MAGIC; lock_InitializeMutex(&cellp->mx, "cm_cell_t mutex", LOCK_HIERARCHY_CELL); lock_ObtainMutex(&cellp->mx); lock_ObtainWrite(&cm_cellLock); /* copy in name */ strncpy(cellp->name, "Freelance.Local.Cell", CELL_MAXNAMELEN); /*safe*/ cellp->name[CELL_MAXNAMELEN-1] = '\0'; /* thread on global list */ cellp->allNextp = cm_data.allCellsp; cm_data.allCellsp = cellp; cellp->cellID = AFS_FAKE_ROOT_CELL_ID; cellp->vlServersp = NULL; cellp->flags = CM_CELLFLAG_FREELANCE; cm_AddCellToNameHashTable(cellp); cm_AddCellToIDHashTable(cellp); lock_ReleaseWrite(&cm_cellLock); lock_ReleaseMutex(&cellp->mx); #endif } else { lock_ObtainRead(&cm_cellLock); for (cellp = cm_data.allCellsp; cellp; cellp=cellp->allNextp) { lock_InitializeMutex(&cellp->mx, "cm_cell_t mutex", LOCK_HIERARCHY_CELL); cellp->vlServersp = NULL; cellp->flags |= CM_CELLFLAG_VLSERVER_INVALID; } lock_ReleaseRead(&cm_cellLock); } osi_EndOnce(&once); } }
unsigned long main_Mod2(void *parm) { long i; for(i=0; i<OSI_MOD2LOOPS; i++) { osi_Log0(main_logp, "mod2"); lock_ObtainMutex(&main_aMutex); lock_ObtainWrite(&main_bRWLock); a += 3; Sleep(0); b -= 3; osi_assert(a+b == 100); Sleep(0); lock_ReleaseWrite(&main_bRWLock); Sleep(0); lock_ReleaseMutex(&main_aMutex); Sleep(0); m2Loops = i; osi_Log4(main_logp, "mod2 done, %d %d %d %d", m2Loops, 2, 3, 4); } lock_ObtainWrite(&main_doneRWLock); done++; Sleep(0); lock_ReleaseWrite(&main_doneRWLock); return 0; }
unsigned long main_Mod1(void *parm) { long i; for(i=0; i<OSI_MOD1LOOPS; i++) { lock_ObtainMutex(&main_aMutex); osi_Log0(main_logp, "mod1"); lock_ObtainWrite(&main_bRWLock); a -= 52; Sleep(0); b += 52; osi_assert(a+b == 100); Sleep(0); lock_ReleaseWrite(&main_bRWLock); Sleep(0); lock_ReleaseMutex(&main_aMutex); Sleep(0); m1Loops = i; osi_Log1(main_logp, "mod1 done, %d", m1Loops); } lock_ObtainWrite(&main_doneRWLock); done++; Sleep(0); lock_ReleaseWrite(&main_doneRWLock); return 0; }
void ChangeTrayIcon (int nim) { static BOOL fAdded = FALSE; static BOOL fDeleted = FALSE; if ((nim == NIM_MODIFY) && (!fAdded)) nim = NIM_ADD; if ((nim == NIM_MODIFY) && (fDeleted)) return; if ((nim != NIM_DELETE) || (IsWindow (g.hMain))) { static HICON ICON_CREDS_YES = TaLocale_LoadIcon (IDI_CREDS_YES); static HICON ICON_CREDS_NO = TaLocale_LoadIcon (IDI_CREDS_NO); size_t iExpired = Main_FindExpiredCreds(); NOTIFYICONDATA nid; memset (&nid, 0x00, sizeof(NOTIFYICONDATA)); nid.cbSize = sizeof(NOTIFYICONDATA); nid.hWnd = g.hMain; nid.uID = 0; nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; nid.uCallbackMessage = WM_TRAYICON; lock_ObtainMutex(&g.credsLock); nid.hIcon = ((g.cCreds != 0) && (iExpired == (size_t)-1)) ? ICON_CREDS_YES : ICON_CREDS_NO; lock_ReleaseMutex(&g.credsLock); GetString (nid.szTip, (g.fIsWinNT) ? IDS_TOOLTIP : IDS_TOOLTIP_95); Shell_NotifyIcon (nim, &nid); } if (nim == NIM_ADD) fAdded = TRUE; if (nim == NIM_DELETE) fDeleted = TRUE; }
static void cm_CheckServersSingular(afs_uint32 flags, cm_cell_t *cellp) { /* ping all file servers, up or down, with unauthenticated connection, * to find out whether we have all our callbacks from the server still. * Also, ping down VLDBs. */ cm_server_t *tsp; int doPing; int isDown; int isFS; int isVLDB; lock_ObtainRead(&cm_serverLock); for (tsp = cm_serversAllFirstp; tsp; tsp = (cm_server_t *)osi_QNext(&tsp->allq)) { cm_GetServerNoLock(tsp); lock_ReleaseRead(&cm_serverLock); /* now process the server */ lock_ObtainMutex(&tsp->mx); doPing = 0; isDown = tsp->flags & CM_SERVERFLAG_DOWN; isFS = tsp->type == CM_SERVER_FILE; isVLDB = tsp->type == CM_SERVER_VLDB; /* only do the ping if the cell matches the requested cell, or we're * matching all cells (cellp == NULL), and if we've requested to ping * this type of {up, down} servers. */ if ((cellp == NULL || cellp == tsp->cellp) && ((isDown && (flags & CM_FLAG_CHECKDOWNSERVERS)) || (!isDown && (flags & CM_FLAG_CHECKUPSERVERS))) && ((!(flags & CM_FLAG_CHECKVLDBSERVERS) || isVLDB && (flags & CM_FLAG_CHECKVLDBSERVERS)) && (!(flags & CM_FLAG_CHECKFILESERVERS) || isFS && (flags & CM_FLAG_CHECKFILESERVERS)))) { doPing = 1; } /* we're supposed to check this up/down server */ lock_ReleaseMutex(&tsp->mx); /* at this point, we've adjusted the server state, so do the ping and * adjust things. */ if (doPing) cm_PingServer(tsp); /* also, run the GC function for connections on all of the * server's connections. */ cm_GCConnections(tsp); lock_ObtainRead(&cm_serverLock); cm_PutServerNoLock(tsp); } lock_ReleaseRead(&cm_serverLock); }
static void cm_MarkServerDown(cm_server_t *tsp, afs_int32 code, int wasDown) { /* mark server as down */ if (!(tsp->flags & CM_SERVERFLAG_DOWN)) { _InterlockedOr(&tsp->flags, CM_SERVERFLAG_DOWN); tsp->downTime = time(NULL); } if (code != VRESTARTING) { lock_ReleaseMutex(&tsp->mx); cm_ForceNewConnections(tsp); lock_ObtainMutex(&tsp->mx); } /* Now update the volume status if necessary */ if (!wasDown) { if (tsp->type == CM_SERVER_FILE) { cm_server_vols_t * tsrvp; cm_volume_t * volp; int i; cm_req_t req; for (tsrvp = tsp->vols; tsrvp; tsrvp = tsrvp->nextp) { for (i=0; i<NUM_SERVER_VOLS; i++) { if (tsrvp->ids[i] != 0) { cm_InitReq(&req); lock_ReleaseMutex(&tsp->mx); code = cm_FindVolumeByID(tsp->cellp, tsrvp->ids[i], cm_rootUserp, &req, CM_GETVOL_FLAG_NO_LRU_UPDATE, &volp); lock_ObtainMutex(&tsp->mx); if (code == 0) { cm_UpdateVolumeStatus(volp, tsrvp->ids[i]); cm_PutVolume(volp); } } } } } cm_RankServer(tsp); } }
/*! \brief End an RPC operation \see smb_RPC_BeginOp() */ afs_int32 smb_RPC_EndOp(smb_rpc_t * rpcp) { lock_ObtainMutex(&rpcp->fidp->mx); osi_assertx(rpcp->fidp->flags & SMB_FID_RPC_INCALL, "RPC_EndOp() call without RPC_BeginOp()"); rpcp->fidp->flags &= ~SMB_FID_RPC_INCALL; lock_ReleaseMutex(&rpcp->fidp->mx); osi_Wakeup((LONG_PTR) rpcp); return 0; }
/* * Add a new uuid and session key to the list. */ void cm_RegisterNewTokenEvent( afs_uuid_t uuid, char sessionKey[8]) { tokenEvent_t *te = malloc(sizeof(tokenEvent_t)); te->uuid = uuid; memcpy(te->sessionKey, sessionKey, sizeof(te->sessionKey)); lock_ObtainMutex(&tokenEventLock); te->next = tokenEvents; tokenEvents = te; lock_ReleaseMutex(&tokenEventLock); }
/** Handle SMB_COM_WRITE_ANDX for an RPC fid Called from smb_ReceiveV3WriteX when we receive a write call on the RPC file descriptor. */ afs_int32 smb_RPCV3Write(smb_fid_t *fidp, smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) { smb_rpc_t *rpcp; long count; afs_int32 code; char *op; cm_user_t *userp = NULL; code = 0; count = smb_GetSMBParm(inp, 10); userp = smb_GetUserFromVCP(vcp, inp); osi_Log3(smb_logp, "smb_RPCV3Write for user[0x%p] fid[0x%p (%d)]", userp, fidp, fidp->fid); if (userp == NULL) { code = CM_ERROR_BADSMB; goto done; } lock_ObtainMutex(&fidp->mx); rpcp = fidp->rpcp; code = smb_RPC_BeginOp(rpcp); lock_ReleaseMutex(&fidp->mx); if (code) goto done; smb_RPC_PrepareWrite(rpcp); op = inp->data + smb_GetSMBParm(inp, 11); code = smb_RPC_WritePacket(rpcp, op, count, userp); smb_RPC_EndOp(rpcp); done: /* return # of bytes written */ if (code == 0) { smb_SetSMBParm(outp, 2, count); smb_SetSMBParm(outp, 3, 0); /* reserved */ smb_SetSMBParm(outp, 4, 0); /* reserved */ smb_SetSMBParm(outp, 5, 0); /* reserved */ smb_SetSMBDataLength(outp, 0); } if (userp) cm_ReleaseUser(userp); return code; }
time_t cm_TGTLifeTime(cm_user_t *userp, afs_uint32 cellID) { cm_cell_t *cellp = NULL; cm_ucell_t * ucp = NULL; time_t expirationTime = 0; lock_ObtainMutex(&userp->mx); cellp = cm_FindCellByID(cellID, CM_FLAG_NOPROBE); ucp = cm_GetUCell(userp, cellp); if (ucp->ticketp) expirationTime = ucp->expirationTime; lock_ReleaseMutex(&userp->mx); return expirationTime; }
void NewCreds_OnInitDialog (HWND hDlg) { LPTSTR pszCell = (LPTSTR)GetWindowLongPtr (hDlg, DWLP_USER); if (!pszCell) pszCell = TEXT(""); if (GetDlgItem (hDlg, IDC_NEWCREDS_TITLE)) { TCHAR szText[ cchRESOURCE ]; GetDlgItemText (hDlg, IDC_NEWCREDS_TITLE, szText, cchRESOURCE); LPTSTR pszText = FormatString (szText, TEXT("%s"), pszCell); SetDlgItemText (hDlg, IDC_NEWCREDS_TITLE, pszText); FreeString (pszText); } if (pszCell && *pszCell) { SetDlgItemText (hDlg, IDC_NEWCREDS_CELL, pszCell); } else { TCHAR szCell[ cchRESOURCE ] = TEXT(""); (void)GetDefaultCell (szCell); SetDlgItemText (hDlg, IDC_NEWCREDS_CELL, szCell); } lock_ObtainMutex(&g.credsLock); size_t iCreds; for (iCreds = 0; iCreds < g.cCreds; ++iCreds) { if (*pszCell && !lstrcmpi (g.aCreds[ iCreds ].szCell, pszCell)) break; } if ((iCreds == g.cCreds) || (!g.aCreds[ iCreds ].szUser[0])) { PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem (hDlg, IDC_NEWCREDS_USER), TRUE); } else // (we have a valid username already) { SetDlgItemText (hDlg, IDC_NEWCREDS_USER, g.aCreds[ iCreds ].szUser); PostMessage (hDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem (hDlg, IDC_NEWCREDS_PASSWORD), TRUE); } lock_ReleaseMutex(&g.credsLock); NewCreds_OnEnable (hDlg); SetForegroundWindow(hDlg); KillTimer (g.hMain, ID_SERVICE_TIMER); }
void cm_ChangeRankCellVLServer(cm_server_t *tsp) { cm_cell_t *cp; int code; cp = tsp->cellp; /* cell that this vlserver belongs to */ if (cp) { lock_ObtainMutex(&cp->mx); code = cm_ChangeRankServer(&cp->vlServersp, tsp); if ( !code ) /* if the server list was rearranged */ cm_RandomizeServer(&cp->vlServersp); lock_ReleaseMutex(&cp->mx); } }
/*! \brief Begin an RPC operation While generally we receive RPC requests one at a time, we have to protect against receiving multiple requests in parallel since there's nothing really preventing that from happening. This should be called before calling any of the smb_RPC_*() functions. If the return value is non-zero, it should be considered unsafe to call any smb_RPC_*() function. Each successful call to smb_RPC_BeginOp() should be coupled with a call to smb_RPC_EndOp(). \note Should be called with rpcp->fidp->mx locked. */ afs_int32 smb_RPC_BeginOp(smb_rpc_t * rpcp) { if (rpcp == NULL) return CM_ERROR_INVAL; osi_assertx(rpcp->fidp, "No fidp assigned to smb_rpc_t"); lock_AssertMutex(&rpcp->fidp->mx); while (rpcp->fidp->flags & SMB_FID_RPC_INCALL) { osi_SleepM((LONG_PTR) rpcp, &rpcp->fidp->mx); lock_ObtainMutex(&rpcp->fidp->mx); } rpcp->fidp->flags |= SMB_FID_RPC_INCALL; return 0; }
void Creds_OnCheckRemind (HWND hDlg) { LPTSTR pszCell = (LPTSTR)GetWindowLongPtr (hDlg, DWLP_USER); lock_ObtainMutex(&g.credsLock); size_t iCreds; for (iCreds = 0; iCreds < g.cCreds; ++iCreds) { if (!lstrcmpi (g.aCreds[ iCreds ].szCell, pszCell)) break; } if (iCreds != g.cCreds) { g.aCreds[ iCreds ].fRemind = IsDlgButtonChecked (hDlg, IDC_CREDS_REMIND); SaveRemind (iCreds); } lock_ReleaseMutex(&g.credsLock); }
void NewCreds_OnCancel (HWND hDlg) { TCHAR szText[ cchRESOURCE ] = ""; LPTSTR pszCell = NULL; if (GetDlgItem (hDlg, IDC_NEWCREDS_CELL)) { GetDlgItemText (hDlg, IDC_NEWCREDS_CELL, szText, cchRESOURCE); if ( szText[0] ) pszCell = szText; } if ( !pszCell ) pszCell = (LPTSTR)GetWindowLongPtr (hDlg, DWLP_USER); if (pszCell) { HWND hTab = GetDlgItem (g.hMain, IDC_TABS); LPTSTR pszTab = (LPTSTR)GetTabParam (hTab, TabCtrl_GetCurSel(hTab)); HWND hChildDlg = NULL; lock_ObtainMutex(&g.credsLock); for (size_t iCreds = 0; iCreds < g.cCreds; ++iCreds) { if (!lstrcmpi (g.aCreds[ iCreds ].szCell, pszCell)) { g.aCreds[ iCreds ].fRemind = FALSE; SaveRemind (iCreds); // Check the active tab, and fix its checkbox if necessary // if (pszTab && HIWORD(pszTab) && (!lstrcmpi (pszTab, pszCell))) { hChildDlg = GetTabChild (hTab); } } } lock_ReleaseMutex(&g.credsLock); if (hChildDlg) CheckDlgButton (hChildDlg, IDC_CREDS_REMIND, FALSE); } }
/** Setup a smb_fid:: structure for RPC \note Obtains fidp->mx */ afs_int32 smb_SetupRPCFid(smb_fid_t * fidp, const clientchar_t * _epnamep, unsigned short * file_type, unsigned short * device_state) { smb_rpc_t *rpcp; afs_int32 code = 0; const clientchar_t * epnamep; epnamep = cm_ClientStrChr(_epnamep, _C('\\')); if (epnamep == NULL) epnamep = _epnamep; else epnamep = cm_ClientCharNext(epnamep); lock_ObtainMutex(&fidp->mx); fidp->flags |= SMB_FID_RPC; fidp->scp = &cm_data.fakeSCache; cm_HoldSCache(fidp->scp); if (fidp->rpcp == NULL) { rpcp = malloc(sizeof(*rpcp)); memset(rpcp, 0, sizeof(*rpcp)); fidp->rpcp = rpcp; rpcp->fidp = fidp; } else { rpcp = fidp->rpcp; } code = smb_RPC_SetupEndpointByname(rpcp, epnamep); lock_ReleaseMutex(&fidp->mx); if (code == 0) { *file_type = SMB_FILETYPE_MESSAGE_MODE_PIPE; *device_state =((0xff) | /* instance count */ SMB_DEVICESTATE_READMSGFROMPIPE | SMB_DEVICESTATE_MESSAGEMODEPIPE | SMB_DEVICESTATE_PIPECLIENTEND); } return code; }
unsigned long main_Scan1(unsigned long parm) { while (1) { osi_Log0(main_logp, "scan1"); /* check to see if we're done */ lock_ObtainRead(&main_doneRWLock); lock_AssertRead(&main_doneRWLock); if (done >= 2) break; lock_ReleaseRead(&main_doneRWLock); /* check state for consistency */ lock_ObtainMutex(&main_aMutex); lock_AssertMutex(&main_aMutex); Sleep(0); lock_ObtainRead(&main_bRWLock); Sleep(0); osi_assert(a+b == 100); lock_ReleaseRead(&main_bRWLock); Sleep(0); lock_ReleaseMutex(&main_aMutex); /* get a read lock here to test people getting stuck on RW lock alone */ lock_ObtainRead(&main_bRWLock); Sleep(0); lock_ReleaseRead(&main_bRWLock); s1Loops++; osi_Log2(main_logp, "scan1 done %d %d", s1Loops, 2); } lock_ReleaseRead(&main_doneRWLock); lock_ObtainWrite(&main_doneRWLock); lock_AssertWrite(&main_doneRWLock); done++; lock_ReleaseWrite(&main_doneRWLock); return 0; }
void Main_OnCheckMenuRemind (void) { BOOL fRemind = FALSE; lock_ObtainMutex(&g.credsLock); size_t iCreds; for (iCreds = 0; iCreds < g.cCreds; ++iCreds) { if (g.aCreds[ iCreds ].fRemind) fRemind = TRUE; } fRemind = !fRemind; for (iCreds = 0; iCreds < g.cCreds; ++iCreds) { if (g.aCreds[ iCreds ].fRemind != fRemind) { g.aCreds[ iCreds ].fRemind = fRemind; SaveRemind (iCreds); } } lock_ReleaseMutex(&g.credsLock); // Check the active tab, and fix its checkbox if necessary // HWND hTab = GetDlgItem (g.hMain, IDC_TABS); LPTSTR pszTab = (LPTSTR)GetTabParam (hTab, TabCtrl_GetCurSel(hTab)); if (ISCELLTAB(pszTab) && (*pszTab)) { HWND hDlg = GetTabChild (hTab); if (hDlg) CheckDlgButton (hDlg, IDC_CREDS_REMIND, fRemind); } // Make sure the reminder timer is going // Main_EnableRemindTimer (fRemind); }
/* * Find a uuid on the list. If it is there, copy the session key and * destroy the entry, since it is only used once. * * Return TRUE if found, FALSE if not found */ BOOL cm_FindTokenEvent(afs_uuid_t uuid, char sessionKey[8]) { RPC_STATUS status; tokenEvent_t *te; tokenEvent_t **ltep; lock_ObtainMutex(&tokenEventLock); te = tokenEvents; ltep = &tokenEvents; while (te) { if (UuidEqual((UUID *)&uuid, (UUID *)&te->uuid, &status)) { *ltep = te->next; lock_ReleaseMutex(&tokenEventLock); memcpy(sessionKey, te->sessionKey, sizeof(te->sessionKey)); free(te); return TRUE; } ltep = &te->next; te = te->next; } lock_ReleaseMutex(&tokenEventLock); return FALSE; }
void Creds_OnUpdate (HWND hDlg) { LPTSTR pszCell = (LPTSTR)GetWindowLongPtr (hDlg, DWLP_USER); if (!pszCell || !*pszCell) { BOOL fRunning = IsServiceRunning(); ShowWindow (GetDlgItem (hDlg, IDC_RUNNING), fRunning); ShowWindow (GetDlgItem (hDlg, IDC_STOPPED), !fRunning); ShowWindow (GetDlgItem (hDlg, IDC_CREDS_OBTAIN), fRunning); return; } lock_ObtainMutex(&g.credsLock); size_t iCreds; for (iCreds = 0; iCreds < g.cCreds; ++iCreds) { if (!lstrcmpi (g.aCreds[ iCreds ].szCell, pszCell)) break; } TCHAR szGateway[cchRESOURCE] = TEXT(""); if (!g.fIsWinNT) GetGatewayName (szGateway); if (!szGateway[0]) { SetDlgItemText (hDlg, IDC_CREDS_CELL, pszCell); } else { TCHAR szCell[ cchRESOURCE ]; TCHAR szFormat[ cchRESOURCE ]; GetString (szFormat, IDS_CELL_GATEWAY); wsprintf (szCell, szFormat, pszCell, szGateway); SetDlgItemText (hDlg, IDC_CREDS_CELL, szCell); } if (iCreds == g.cCreds) { TCHAR szText[cchRESOURCE]; GetString (szText, IDS_NO_CREDS); SetDlgItemText (hDlg, IDC_CREDS_INFO, szText); } else { // FormatString(%t) expects a date in GMT, not the local time zone... // FILETIME ftLocal; SystemTimeToFileTime (&g.aCreds[ iCreds ].stExpires, &ftLocal); FILETIME ftGMT; LocalFileTimeToFileTime (&ftLocal, &ftGMT); SYSTEMTIME stGMT; FileTimeToSystemTime (&ftGMT, &stGMT); SYSTEMTIME stNow; GetLocalTime (&stNow); FILETIME ftNow; SystemTimeToFileTime (&stNow, &ftNow); LONGLONG llNow = (((LONGLONG)ftNow.dwHighDateTime) << 32) + (LONGLONG)(ftNow.dwLowDateTime); LONGLONG llExpires = (((LONGLONG)ftLocal.dwHighDateTime) << 32) + (LONGLONG)(ftLocal.dwLowDateTime); llNow /= c100ns1SECOND; llExpires /= c100ns1SECOND; LPTSTR pszCreds = NULL; if (llExpires <= (llNow + (LONGLONG)cminREMIND_WARN * csec1MINUTE)) pszCreds = FormatString (IDS_CREDS_EXPIRED, TEXT("%s"), g.aCreds[ iCreds ].szUser); if (!pszCreds || !pszCreds[0]) pszCreds = FormatString (IDS_CREDS, TEXT("%s%t"), g.aCreds[ iCreds ].szUser, &stGMT); SetDlgItemText (hDlg, IDC_CREDS_INFO, pszCreds); FreeString (pszCreds); } lock_ReleaseMutex(&g.credsLock); CheckDlgButton (hDlg, IDC_CREDS_REMIND, (iCreds == g.cCreds) ? FALSE : g.aCreds[iCreds].fRemind); EnableWindow (GetDlgItem (hDlg, IDC_CREDS_OBTAIN), IsServiceRunning()); EnableWindow (GetDlgItem (hDlg, IDC_CREDS_REMIND), (iCreds != g.cCreds)); EnableWindow (GetDlgItem (hDlg, IDC_CREDS_DESTROY), (iCreds != g.cCreds)); }
/* if it's from DNS, see if it has expired * and check to make sure we have a valid set of volume servers * this function must not be called with a lock on cm_cellLock */ cm_cell_t *cm_UpdateCell(cm_cell_t * cp, afs_uint32 flags) { long code = 0; cm_cell_rock_t rock; afs_uint32 mxheld = 0; if (cp == NULL) return NULL; lock_ObtainMutex(&cp->mx); mxheld = 1; #ifdef AFS_FREELANCE_CLIENT if (cp->flags & CM_CELLFLAG_FREELANCE) { lock_ReleaseMutex(&cp->mx); return cp; } #endif if (cm_IsServerListEmpty(cp->vlServersp) || (time(0) > cp->timeout) || (cm_dnsEnabled && (cp->flags & CM_CELLFLAG_DNS) && ((cp->flags & CM_CELLFLAG_VLSERVER_INVALID)))) { lock_ReleaseMutex(&cp->mx); mxheld = 0; /* must empty cp->vlServersp */ if (cp->vlServersp) cm_FreeServerList(&cp->vlServersp, CM_FREESERVERLIST_DELETE); rock.cellp = cp; rock.flags = flags; code = cm_SearchCellRegistry(1, cp->name, NULL, cp->linkedName, cm_AddCellProc, &rock); if (code && code != CM_ERROR_FORCE_DNS_LOOKUP) code = cm_SearchCellFileEx(cp->name, NULL, cp->linkedName, cm_AddCellProc, &rock); if (code == 0) { lock_ObtainMutex(&cp->mx); mxheld = 1; cp->timeout = time(0) + 7200; } else { if (cm_dnsEnabled) { int ttl; code = cm_SearchCellByDNS(cp->name, NULL, &ttl, cm_AddCellProc, &rock); if (code == 0) { /* got cell from DNS */ lock_ObtainMutex(&cp->mx); mxheld = 1; _InterlockedOr(&cp->flags, CM_CELLFLAG_DNS); _InterlockedAnd(&cp->flags, ~CM_CELLFLAG_VLSERVER_INVALID); cp->timeout = time(0) + ttl; #ifdef DEBUG fprintf(stderr, "cell %s: ttl=%d\n", cp->name, ttl); #endif } else { /* if we fail to find it this time, we'll just do nothing and leave the * current entry alone */ lock_ObtainMutex(&cp->mx); mxheld = 1; _InterlockedOr(&cp->flags, CM_CELLFLAG_VLSERVER_INVALID); } } } } if (code == 0) cm_RandomizeServer(&cp->vlServersp); if (mxheld) lock_ReleaseMutex(&cp->mx); return code ? NULL : cp; }
long cm_CreateCellWithInfo( char * cellname, char * linked_cellname, unsigned short vlport, afs_uint32 host_count, char *hostname[], afs_uint32 flags) { afs_uint32 code = 0; cm_cell_rock_t rock; struct hostent *thp; struct sockaddr_in vlSockAddr; afs_uint32 i, j; rock.cellp = cm_GetCell(cellname, CM_FLAG_CREATE | CM_FLAG_NOPROBE); rock.flags = 0; cm_FreeServerList(&rock.cellp->vlServersp, CM_FREESERVERLIST_DELETE); if (!(flags & CM_CELLFLAG_DNS)) { for (i = 0; i < host_count; i++) { thp = gethostbyname(hostname[i]); if (thp) { int foundAddr = 0; for (j=0 ; thp->h_addr_list[j]; j++) { if (thp->h_addrtype != AF_INET) continue; memcpy(&vlSockAddr.sin_addr.s_addr, thp->h_addr_list[j], sizeof(long)); vlSockAddr.sin_port = htons(vlport ? vlport : 7003); vlSockAddr.sin_family = AF_INET; cm_AddCellProc(&rock, &vlSockAddr, hostname[i], CM_FLAG_NOPROBE); } } } lock_ObtainMutex(&rock.cellp->mx); _InterlockedAnd(&rock.cellp->flags, ~CM_CELLFLAG_DNS); } else if (cm_dnsEnabled) { int ttl; code = cm_SearchCellByDNS(rock.cellp->name, NULL, &ttl, cm_AddCellProc, &rock); lock_ObtainMutex(&rock.cellp->mx); if (code == 0) { /* got cell from DNS */ _InterlockedOr(&rock.cellp->flags, CM_CELLFLAG_DNS); rock.cellp->timeout = time(0) + ttl; #ifdef DEBUG fprintf(stderr, "cell %s: ttl=%d\n", rock.cellp->name, ttl); #endif } } else { lock_ObtainMutex(&rock.cellp->mx); rock.cellp->flags &= ~CM_CELLFLAG_DNS; } _InterlockedOr(&rock.cellp->flags, CM_CELLFLAG_VLSERVER_INVALID); StringCbCopy(rock.cellp->linkedName, CELL_MAXNAMELEN, linked_cellname); lock_ReleaseMutex(&rock.cellp->mx); if (rock.cellp->vlServersp) cm_RandomizeServer(&rock.cellp->vlServersp); return code; }
cm_cell_t *cm_GetCell_Gen(char *namep, char *newnamep, afs_uint32 flags) { cm_cell_t *cp, *cp2; long code; char fullname[CELL_MAXNAMELEN]=""; char linkedName[CELL_MAXNAMELEN]=""; char name[CELL_MAXNAMELEN]=""; int hasWriteLock = 0; int hasMutex = 0; afs_uint32 hash; cm_cell_rock_t rock; size_t len; if (namep == NULL || !namep[0] || !strcmp(namep,CM_IOCTL_FILENAME_NOSLASH)) return NULL; /* * Strip off any trailing dots at the end of the cell name. * Failure to do so results in an undesireable alias as the * result of DNS AFSDB record lookups where a trailing dot * has special meaning. */ strncpy(name, namep, CELL_MAXNAMELEN); for (len = strlen(namep); len > 0 && namep[len-1] == '.'; len--) { name[len-1] = '\0'; } if (len == 0) return NULL; namep = name; hash = CM_CELL_NAME_HASH(namep); lock_ObtainRead(&cm_cellLock); for (cp = cm_data.cellNameHashTablep[hash]; cp; cp=cp->nameNextp) { if (cm_stricmp_utf8(namep, cp->name) == 0) { strncpy(fullname, cp->name, CELL_MAXNAMELEN); fullname[CELL_MAXNAMELEN-1] = '\0'; break; } } if (!cp) { for (cp = cm_data.allCellsp; cp; cp=cp->allNextp) { if (strnicmp(namep, cp->name, strlen(namep)) == 0) { strncpy(fullname, cp->name, CELL_MAXNAMELEN); fullname[CELL_MAXNAMELEN-1] = '\0'; break; } } } if (cp) { lock_ReleaseRead(&cm_cellLock); cm_UpdateCell(cp, flags); } else if (flags & CM_FLAG_CREATE) { lock_ConvertRToW(&cm_cellLock); hasWriteLock = 1; /* when we dropped the lock the cell could have been added * to the list so check again while holding the write lock */ for (cp = cm_data.cellNameHashTablep[hash]; cp; cp=cp->nameNextp) { if (cm_stricmp_utf8(namep, cp->name) == 0) { strncpy(fullname, cp->name, CELL_MAXNAMELEN); fullname[CELL_MAXNAMELEN-1] = '\0'; break; } } if (cp) goto done; for (cp = cm_data.allCellsp; cp; cp=cp->allNextp) { if (strnicmp(namep, cp->name, strlen(namep)) == 0) { strncpy(fullname, cp->name, CELL_MAXNAMELEN); fullname[CELL_MAXNAMELEN-1] = '\0'; break; } } if (cp) { lock_ReleaseWrite(&cm_cellLock); lock_ObtainMutex(&cp->mx); lock_ObtainWrite(&cm_cellLock); cm_AddCellToNameHashTable(cp); cm_AddCellToIDHashTable(cp); lock_ReleaseMutex(&cp->mx); goto done; } if ( cm_data.freeCellsp != NULL ) { cp = cm_data.freeCellsp; cm_data.freeCellsp = cp->freeNextp; /* * The magic, cellID, and mx fields are already set. */ } else { if ( cm_data.currentCells >= cm_data.maxCells ) osi_panic("Exceeded Max Cells", __FILE__, __LINE__); /* don't increment currentCells until we know that we * are going to keep this entry */ cp = &cm_data.cellBaseAddress[cm_data.currentCells]; memset(cp, 0, sizeof(cm_cell_t)); cp->magic = CM_CELL_MAGIC; /* the cellID cannot be 0 */ cp->cellID = ++cm_data.currentCells; /* otherwise we found the cell, and so we're nearly done */ lock_InitializeMutex(&cp->mx, "cm_cell_t mutex", LOCK_HIERARCHY_CELL); } lock_ReleaseWrite(&cm_cellLock); hasWriteLock = 0; rock.cellp = cp; rock.flags = flags; code = cm_SearchCellRegistry(1, namep, fullname, linkedName, cm_AddCellProc, &rock); if (code && code != CM_ERROR_FORCE_DNS_LOOKUP) code = cm_SearchCellFileEx(namep, fullname, linkedName, cm_AddCellProc, &rock); if (code) { osi_Log4(afsd_logp,"in cm_GetCell_gen cm_SearchCellFileEx(%s) returns code= %d fullname= %s linkedName= %s", osi_LogSaveString(afsd_logp,namep), code, osi_LogSaveString(afsd_logp,fullname), osi_LogSaveString(afsd_logp,linkedName)); if (cm_dnsEnabled) { int ttl; code = cm_SearchCellByDNS(namep, fullname, &ttl, cm_AddCellProc, &rock); if ( code ) { osi_Log3(afsd_logp,"in cm_GetCell_gen cm_SearchCellByDNS(%s) returns code= %d fullname= %s", osi_LogSaveString(afsd_logp,namep), code, osi_LogSaveString(afsd_logp,fullname)); lock_ObtainMutex(&cp->mx); lock_ObtainWrite(&cm_cellLock); hasWriteLock = 1; cm_RemoveCellFromIDHashTable(cp); cm_RemoveCellFromNameHashTable(cp); lock_ReleaseMutex(&cp->mx); cm_FreeCell(cp); cp = NULL; goto done; } else { /* got cell from DNS */ lock_ObtainMutex(&cp->mx); hasMutex = 1; _InterlockedOr(&cp->flags, CM_CELLFLAG_DNS); _InterlockedAnd(&cp->flags, ~CM_CELLFLAG_VLSERVER_INVALID); cp->timeout = time(0) + ttl; } } else { lock_ObtainMutex(&cp->mx); lock_ObtainWrite(&cm_cellLock); hasWriteLock = 1; cm_RemoveCellFromIDHashTable(cp); cm_RemoveCellFromNameHashTable(cp); lock_ReleaseMutex(&cp->mx); cm_FreeCell(cp); cp = NULL; goto done; } } else { lock_ObtainMutex(&cp->mx); hasMutex = 1; cp->timeout = time(0) + 7200; /* two hour timeout */ } /* we have now been given the fullname of the cell. It may * be that we already have a cell with that name. If so, * we should use it instead of completing the allocation * of a new cm_cell_t */ lock_ObtainRead(&cm_cellLock); hash = CM_CELL_NAME_HASH(fullname); for (cp2 = cm_data.cellNameHashTablep[hash]; cp2; cp2=cp2->nameNextp) { if (cm_stricmp_utf8(fullname, cp2->name) == 0) { break; } } if (cp2) { if (!hasMutex) { lock_ObtainMutex(&cp->mx); hasMutex = 1; } lock_ConvertRToW(&cm_cellLock); hasWriteLock = 1; cm_RemoveCellFromIDHashTable(cp); cm_RemoveCellFromNameHashTable(cp); lock_ReleaseMutex(&cp->mx); hasMutex = 0; cm_FreeCell(cp); cp = cp2; goto done; } lock_ReleaseRead(&cm_cellLock); /* randomise among those vlservers having the same rank*/ cm_RandomizeServer(&cp->vlServersp); if (!hasMutex) lock_ObtainMutex(&cp->mx); /* copy in name */ strncpy(cp->name, fullname, CELL_MAXNAMELEN); cp->name[CELL_MAXNAMELEN-1] = '\0'; strncpy(cp->linkedName, linkedName, CELL_MAXNAMELEN); cp->linkedName[CELL_MAXNAMELEN-1] = '\0'; lock_ObtainWrite(&cm_cellLock); hasWriteLock = 1; cm_AddCellToNameHashTable(cp); cm_AddCellToIDHashTable(cp); lock_ReleaseMutex(&cp->mx); hasMutex = 0; /* append cell to global list */ if (cm_data.allCellsp == NULL) { cm_data.allCellsp = cp; } else { for (cp2 = cm_data.allCellsp; cp2->allNextp; cp2=cp2->allNextp) ; cp2->allNextp = cp; } cp->allNextp = NULL; } else { lock_ReleaseRead(&cm_cellLock); } done: if (hasMutex && cp) lock_ReleaseMutex(&cp->mx); if (hasWriteLock) lock_ReleaseWrite(&cm_cellLock); /* fullname is not valid if cp == NULL */ if (newnamep) { if (cp) { strncpy(newnamep, fullname, CELL_MAXNAMELEN); newnamep[CELL_MAXNAMELEN-1]='\0'; } else { newnamep[0] = '\0'; } } if (cp && cp->linkedName[0]) { cm_cell_t * linkedCellp = NULL; if (!strcmp(cp->name, cp->linkedName)) { cp->linkedName[0] = '\0'; } else if (!(flags & CM_FLAG_NOMOUNTCHASE)) { linkedCellp = cm_GetCell(cp->linkedName, CM_FLAG_CREATE|CM_FLAG_NOPROBE|CM_FLAG_NOMOUNTCHASE); lock_ObtainWrite(&cm_cellLock); if (!linkedCellp || (linkedCellp->linkedName[0] && strcmp(cp->name, linkedCellp->linkedName))) { cp->linkedName[0] = '\0'; } else { strncpy(linkedCellp->linkedName, cp->name, CELL_MAXNAMELEN); linkedCellp->linkedName[CELL_MAXNAMELEN-1]='\0'; } lock_ReleaseWrite(&cm_cellLock); } } return cp; }
afs_int32 smb_RPCNmpipeTransact(smb_fid_t *fidp, smb_vc_t *vcp, smb_tran2Packet_t *p, smb_packet_t *op) { smb_tran2Packet_t *outp = NULL; struct smb_rpc *rpcp; afs_int32 code = 0; cm_user_t * userp = NULL; smb_user_t * uidp = NULL; int len; osi_Log0(smb_logp, "smb_RPCNmpipeTransact() begin"); uidp = smb_FindUID(vcp, p->uid, 0); if (!uidp) return CM_ERROR_BADSMB; userp = smb_GetUserFromUID(uidp); osi_assertx(userp != NULL, "null cm_user_t"); if (uidp && uidp->unp) { osi_Log3(afsd_logp, "RPC Transact uid %d user %x name %S", uidp->userID, userp, osi_LogSaveClientString(afsd_logp, uidp->unp->name)); } else { if (uidp) osi_Log2(afsd_logp, "RPC Transact uid %d user %x no name", uidp->userID, userp); else osi_Log1(afsd_logp, "RPC Transact no uid user %x no name", userp); } lock_ObtainMutex(&fidp->mx); rpcp = fidp->rpcp; code = smb_RPC_BeginOp(rpcp); if (code) { osi_Log0(smb_logp, "Can't begin RPC op. Aborting"); lock_ReleaseMutex(&fidp->mx); smb_ReleaseUID(uidp); cm_ReleaseUser(userp); return code; } osi_assertx((fidp->flags & SMB_FID_RPC), "FID wasn't setup for RPC"); osi_assertx(fidp->rpcp, "smb_rpc_t not associated with RPC FID"); lock_ReleaseMutex(&fidp->mx); code = smb_RPC_PrepareWrite(rpcp); if (code) goto done; code = smb_RPC_WritePacket(rpcp, p->datap, p->totalData, userp); if (code) goto done; code = smb_RPC_PrepareRead(rpcp); if (code) goto done; len = smb_RPC_ReadPacketLength(rpcp, p->maxReturnData); outp = smb_GetTran2ResponsePacket(vcp, p, op, 0, len); if (len > 0) { code = smb_RPC_ReadPacket(rpcp, outp->datap, len); if (code == CM_ERROR_RPC_MOREDATA) { outp->error_code = CM_ERROR_RPC_MOREDATA; } } if (code == 0 || code == CM_ERROR_RPC_MOREDATA) smb_SendTran2Packet(vcp, outp, op); smb_FreeTran2Packet(outp); done: smb_RPC_EndOp(rpcp); osi_Log1(smb_logp, "smb_RPCNmpipeTransact() end code=%d", code); if (uidp) smb_ReleaseUID(uidp); if (userp) cm_ReleaseUser(userp); return code; }
/** Handle SMB_COM_READ_ANDX for an RPC fid Called from smb_ReceiveV3ReadX to handle RPC descriptor reads */ afs_int32 smb_RPCV3Read(smb_fid_t *fidp, smb_vc_t *vcp, smb_packet_t *inp, smb_packet_t *outp) { smb_rpc_t *rpcp; long count; afs_int32 code; char *op; cm_user_t *userp; smb_user_t *uidp; count = smb_GetSMBParm(inp, 5); uidp = smb_FindUID(vcp, ((smb_t *)inp)->uid, 0); if (!uidp) return CM_ERROR_BADSMB; userp = smb_GetUserFromUID(uidp); osi_assertx(userp != NULL, "null cm_user_t"); osi_Log3(smb_logp, "smb_RPCV3Read for user[0x%p] fid[0x%p (%d)]", userp, fidp, fidp->fid); if (uidp && uidp->unp) { osi_Log3(afsd_logp, "RPC uid %d user %x name %S", uidp->userID, userp, osi_LogSaveClientString(afsd_logp, uidp->unp->name)); } else { if (uidp) osi_Log2(afsd_logp, "RPC uid %d user %x no name", uidp->userID, userp); else osi_Log1(afsd_logp, "RPC no uid user %x no name", userp); } lock_ObtainMutex(&fidp->mx); rpcp = fidp->rpcp; code = smb_RPC_BeginOp(rpcp); lock_ReleaseMutex(&fidp->mx); if (code) { if (uidp) smb_ReleaseUID(uidp); cm_ReleaseUser(userp); return code; } code = smb_RPC_PrepareRead(rpcp); if (uidp) { smb_ReleaseUID(uidp); } if (code) { cm_ReleaseUser(userp); smb_RPC_EndOp(rpcp); return code; } count = smb_RPC_ReadPacketLength(rpcp, count); /* 0 and 1 are reserved for request chaining, were setup by our caller, * and will be further filled in after we return. */ smb_SetSMBParm(outp, 2, 0); /* remaining bytes, for pipes */ smb_SetSMBParm(outp, 3, 0); /* resvd */ smb_SetSMBParm(outp, 4, 0); /* resvd */ smb_SetSMBParm(outp, 5, count); /* # of bytes we're going to read */ /* fill in #6 when we have all the parameters' space reserved */ smb_SetSMBParm(outp, 7, 0); /* resv'd */ smb_SetSMBParm(outp, 8, 0); /* resv'd */ smb_SetSMBParm(outp, 9, 0); /* resv'd */ smb_SetSMBParm(outp, 10, 0); /* resv'd */ smb_SetSMBParm(outp, 11, 0); /* reserved */ /* get op ptr after putting in the last parm, since otherwise we don't * know where the data really is. */ op = smb_GetSMBData(outp, NULL); /* now fill in offset from start of SMB header to first data byte (to op) */ smb_SetSMBParm(outp, 6, ((int) (op - outp->data))); /* set the packet data length the count of the # of bytes */ smb_SetSMBDataLength(outp, count); smb_RPC_ReadPacket(rpcp, op, count); smb_RPC_EndOp(rpcp); /* and cleanup things */ cm_ReleaseUser(userp); return 0; }
void Main_RepopulateTabs (BOOL fDestroyInvalid) { static BOOL fInHere = FALSE; if (!fInHere) { fInHere = TRUE; if (IsWindowVisible (g.hMain)) fDestroyInvalid = FALSE; // First we'll have to look around and see what credentials we currently // have. This call just updates g.aCreds[]; it doesn't do anything else. // (void)GetCurrentCredentials(); // We want one tab on the main dialog for each g.aCredentials entry, // and one tab for Advanced. // HWND hTab = GetDlgItem (g.hMain, IDC_TABS); // Generate a list of the lParams we'll be giving tabs... // LPTSTR *aTabs = NULL; size_t cTabs = 0; size_t iTabOut = 0; size_t nCreds = 0; lock_ObtainMutex(&g.credsLock); size_t iCreds; for (iCreds = 0; iCreds < g.cCreds; ++iCreds) { if (g.aCreds[ iCreds ].szCell[0]) ++nCreds; } if (!nCreds) { fDestroyInvalid = TRUE; } if (!fDestroyInvalid) { int nTabs = TabCtrl_GetItemCount(hTab); for (int iTab = 0; iTab < nTabs; ++iTab) { LPTSTR pszTab = (LPTSTR)GetTabParam (hTab, iTab); if (ISCELLTAB(pszTab) && (*pszTab)) { if (REALLOC (aTabs, cTabs, 1+iTabOut, cREALLOC_TABS)) aTabs[ iTabOut++ ] = CloneString(pszTab); } } } if (nCreds == 0) { if (REALLOC (aTabs, cTabs, 1+iTabOut, cREALLOC_TABS)) aTabs[ iTabOut++ ] = CloneString (TEXT("")); } else for (iCreds = 0; iCreds < g.cCreds; ++iCreds) { if (g.aCreds[ iCreds ].szCell[0]) { size_t ii; for (ii = 0; ii < iTabOut; ++ii) { if (!ISCELLTAB (aTabs[ii])) continue; if (!lstrcmpi (g.aCreds[ iCreds ].szCell, aTabs[ ii ])) break; } if (ii == iTabOut) { if (REALLOC (aTabs, cTabs, 1+iTabOut, cREALLOC_TABS)) aTabs[ iTabOut++ ] = CloneString (g.aCreds[ iCreds ].szCell); } } } lock_ReleaseMutex(&g.credsLock); if (Main_ShowMountTab()) { if (REALLOC (aTabs, cTabs, 1+iTabOut, cREALLOC_TABS)) aTabs[ iTabOut++ ] = dwTABPARAM_MOUNT; } #ifndef UAC_COMPATIBLE if (g.fIsWinNT) { if (REALLOC (aTabs, cTabs, 1+iTabOut, cREALLOC_TABS)) aTabs[ iTabOut++ ] = dwTABPARAM_ADVANCED; } #endif // Now erase the current tabs, and re-add new ones. Remember which tab is // currently selected, so we can try to go back to it later. // int iTabSel = 0; if (TabCtrl_GetItemCount(hTab)) { LPTSTR pszTabSel = (LPTSTR)GetTabParam (hTab, TabCtrl_GetCurSel(hTab)); for (size_t iSel = 0; iSel < iTabOut; ++iSel) { if ((!ISCELLTAB(pszTabSel)) && (!ISCELLTAB(aTabs[iSel])) && (pszTabSel == aTabs[iSel])) iTabSel = iSel; else if (ISCELLTAB(pszTabSel) && ISCELLTAB(aTabs[iSel]) && !lstrcmpi (pszTabSel, aTabs[iSel])) iTabSel = iSel; } } int nTabs = TabCtrl_GetItemCount(hTab); for (int iTab = 0; iTab < nTabs; ++iTab) { LPTSTR pszTab = (LPTSTR)GetTabParam (hTab, iTab); if (ISCELLTAB(pszTab)) FreeString (pszTab); } TabCtrl_DeleteAllItems (hTab); for (size_t ii = 0; ii < iTabOut; ++ii) { TCHAR szTitle[cchRESOURCE]; if (aTabs[ii] == dwTABPARAM_ADVANCED) GetString (szTitle, IDS_ADVANCED); else if (aTabs[ii] == dwTABPARAM_MOUNT) GetString (szTitle, IDS_MOUNT); else if ((nCreds <= 1) || (aTabs[ii][0] == TEXT('\0'))) GetString (szTitle, IDS_CREDENTIALS); else lstrcpy (szTitle, aTabs[ii]); TC_ITEM Item; memset (&Item, 0x00, sizeof(Item)); Item.mask = TCIF_PARAM | TCIF_TEXT; Item.pszText = szTitle; Item.cchTextMax = cchRESOURCE; Item.lParam = (LPARAM)(aTabs[ii]); TabCtrl_InsertItem (hTab, ii, &Item); } if (aTabs != NULL) Free (aTabs); TabCtrl_SetCurSel (hTab, iTabSel); Main_OnSelectTab (); fInHere = FALSE; } }
afs_uint32 raw_WriteData( cm_scache_t *scp, osi_hyper_t *offsetp, afs_uint32 length, char *bufferp, cm_user_t *userp, cm_req_t *reqp, afs_uint32 *writtenp) { long code = 0; long written = 0; osi_hyper_t fileLength; /* file's length at start of write */ osi_hyper_t minLength; /* don't read past this */ afs_uint32 nbytes; /* # of bytes to transfer this iteration */ cm_buf_t *bufp = NULL; osi_hyper_t thyper; /* hyper tmp variable */ osi_hyper_t bufferOffset; afs_uint32 bufIndex; /* index in buffer where our data is */ int doWriteBack = 0; osi_hyper_t writeBackOffset;/* offset of region to write back when I/O is done */ afs_uint32 writeBackLength; DWORD filter = 0; /* start by looking up the file's end */ code = cm_SyncOp(scp, NULL, userp, reqp, 0, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_SETSTATUS | CM_SCACHESYNC_GETSTATUS); if (code) goto done; cm_SyncOpDone(scp, NULL, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_SETSTATUS | CM_SCACHESYNC_GETSTATUS); /* now we have the entry locked, look up the length */ fileLength = scp->length; minLength = fileLength; if (LargeIntegerGreaterThan(minLength, scp->serverLength)) minLength = scp->serverLength; /* adjust file length if we extend past EOF */ thyper.LowPart = length; thyper.HighPart = 0; thyper = LargeIntegerAdd(*offsetp, thyper); /* where write should end */ if (LargeIntegerGreaterThan(thyper, fileLength)) { /* we'd write past EOF, so extend the file */ scp->mask |= CM_SCACHEMASK_LENGTH; scp->length = thyper; filter |= (FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_SIZE); } else filter |= FILE_NOTIFY_CHANGE_LAST_WRITE; doWriteBack = 1; writeBackOffset = *offsetp; writeBackLength = length; /* now, copy the data one buffer at a time, until we've filled the * request packet */ while (1) { /* if we've copied all the data requested, we're done */ if (length <= 0) break; /* otherwise, load up a buffer of data */ thyper.HighPart = offsetp->HighPart; thyper.LowPart = offsetp->LowPart & ~(cm_data.blockSize-1); if (!bufp || !LargeIntegerEqualTo(thyper, bufferOffset)) { /* wrong buffer */ if (bufp) { lock_ReleaseMutex(&bufp->mx); buf_Release(bufp); bufp = NULL; } lock_ReleaseWrite(&scp->rw); code = buf_Get(scp, &thyper, reqp, 0, &bufp); if (bufp) lock_ObtainMutex(&bufp->mx); lock_ObtainWrite(&scp->rw); if (code) goto done; bufferOffset = thyper; /* now get the data in the cache */ while (1) { code = cm_SyncOp(scp, bufp, userp, reqp, 0, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_WRITE | CM_SCACHESYNC_BUFLOCKED); if (code) goto done; cm_SyncOpDone(scp, bufp, CM_SCACHESYNC_NEEDCALLBACK | CM_SCACHESYNC_WRITE | CM_SCACHESYNC_BUFLOCKED); /* If we're overwriting the entire buffer, or * if we're writing at or past EOF, mark the * buffer as current so we don't call * cm_GetBuffer. This skips the fetch from the * server in those cases where we're going to * obliterate all the data in the buffer anyway, * or in those cases where there is no useful * data at the server to start with. * * Use minLength instead of scp->length, since * the latter has already been updated by this * call. */ if (LargeIntegerGreaterThanOrEqualTo(bufp->offset, minLength) || LargeIntegerEqualTo(*offsetp, bufp->offset) && (length >= cm_data.blockSize || LargeIntegerGreaterThanOrEqualTo(LargeIntegerAdd(*offsetp, ConvertLongToLargeInteger(length)), minLength))) { if (length < cm_data.blockSize && bufp->dataVersion == CM_BUF_VERSION_BAD) memset(bufp->datap, 0, cm_data.blockSize); bufp->dataVersion = scp->dataVersion; } if (cm_HaveBuffer(scp, bufp, 1)) break; /* otherwise, load the buffer and try again */ lock_ReleaseMutex(&bufp->mx); code = cm_GetBuffer(scp, bufp, NULL, userp, reqp); lock_ReleaseWrite(&scp->rw); lock_ObtainMutex(&bufp->mx); lock_ObtainWrite(&scp->rw); if (code) break; } if (code) { lock_ReleaseMutex(&bufp->mx); buf_Release(bufp); bufp = NULL; goto done; } } /* if (wrong buffer) ... */ /* now we have the right buffer loaded. Copy out the * data from here to the user's buffer. */ bufIndex = offsetp->LowPart & (cm_data.blockSize - 1); /* and figure out how many bytes we want from this buffer */ nbytes = cm_data.blockSize - bufIndex; /* what remains in buffer */ if (nbytes > length) nbytes = length; /* don't go past end of request */ /* now copy the data */ memcpy(bufp->datap + bufIndex, bufferp, nbytes); buf_SetDirty(bufp, reqp, bufIndex, nbytes, userp); /* adjust lengthers, pointers, etc. */ bufferp += nbytes; length -= nbytes; written += nbytes; thyper.LowPart = nbytes; thyper.HighPart = 0; *offsetp = LargeIntegerAdd(thyper, *offsetp); } /* while 1 */ done: if (writtenp) *writtenp = written; if (bufp) { lock_ReleaseMutex(&bufp->mx); buf_Release(bufp); } if (code == 0 && doWriteBack) { rock_BkgStore_t *rockp = malloc(sizeof(*rockp)); if (rockp) { code = cm_SyncOp(scp, NULL, userp, reqp, 0, CM_SCACHESYNC_ASYNCSTORE); if (code == 0) { rockp->length = writeBackLength; rockp->offset = writeBackOffset; lock_ReleaseWrite(&scp->rw); cm_QueueBKGRequest(scp, cm_BkgStore, rockp, userp, reqp); lock_ObtainWrite(&scp->rw); /* rock is freed by cm_BkgDaemon */ } else { free(rockp); } } } /* cm_SyncOpDone is called when cm_BkgStore completes */ return code; }
BOOL CALLBACK Main_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp) { static UINT msgCheckTerminate = 0; if (msgCheckTerminate == 0) msgCheckTerminate = RegisterWindowMessage (TEXT("AfsCredsCheckTerminate")); if (msg == msgCheckTerminate) { Main_OnCheckTerminate(); } else switch (msg) { case WM_INITDIALOG: g.hMain = hDlg; Main_OnInitDialog (hDlg); break; case WM_DESTROY: Creds_CloseLibraries(); ChangeTrayIcon (NIM_DELETE); break; case WM_ACTIVATEAPP: if (wp) { Main_RepopulateTabs (FALSE); } break; case WM_COMMAND: switch (LOWORD(wp)) { case IDOK: case IDCANCEL: Main_Show (FALSE); break; case M_ACTIVATE: if (g.fIsWinNT || IsServiceRunning()) { if (!lp) // Got here from "/show" parameter? switch tabs. { HWND hTab = GetDlgItem (g.hMain, IDC_TABS); TabCtrl_SetCurSel (hTab, 0); Main_OnSelectTab(); } Main_Show (TRUE); } else { Message (MB_ICONHAND, IDS_UNCONFIG_TITLE_95, IDS_UNCONFIG_DESC_95); } break; case M_TERMINATE: #ifndef UAC_COMPATIBLE if (g.fIsWinNT && IsServiceRunning()) ModalDialog (IDD_TERMINATE, NULL, (DLGPROC)Terminate_DlgProc); else #endif if (g.fIsWinNT) ModalDialog (IDD_TERMINATE_SMALL, NULL, (DLGPROC)Terminate_DlgProc); else // (!g.fIsWinNT) ModalDialog (IDD_TERMINATE_SMALL_95, NULL, (DLGPROC)Terminate_DlgProc); break; case M_TERMINATE_NOW: Quit(); break; case M_REMIND: Main_OnCheckMenuRemind(); break; } break; case WM_TIMER: Main_OnRemindTimer(); break; case WM_NOTIFY: switch (((NMHDR*)lp)->code) { case TCN_SELCHANGE: Main_OnSelectTab(); break; } break; case WM_TRAYICON: switch (lp) { case WM_LBUTTONDOWN: if (IsServiceRunning() || !IsServiceConfigured()) Main_Show (TRUE); else if (!g.fIsWinNT) Message (MB_ICONHAND, IDS_UNCONFIG_TITLE_95, IDS_UNCONFIG_DESC_95); else ShowStartupWizard(); break; case WM_RBUTTONDOWN: HMENU hm; if ((hm = TaLocale_LoadMenu (MENU_TRAYICON)) != 0) { POINT pt; GetCursorPos(&pt); HMENU hmDummy = CreateMenu(); InsertMenu (hmDummy, 0, MF_POPUP, (UINT)hm, NULL); BOOL fRemind = FALSE; lock_ObtainMutex(&g.credsLock); for (size_t iCreds = 0; iCreds < g.cCreds; ++iCreds) { if (g.aCreds[ iCreds ].fRemind) fRemind = TRUE; } lock_ReleaseMutex(&g.credsLock); CheckMenuItem (hm, M_REMIND, MF_BYCOMMAND | ((fRemind) ? MF_CHECKED : MF_UNCHECKED)); SetForegroundWindow(hDlg); TrackPopupMenu (GetSubMenu (hmDummy, 0), TPM_RIGHTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, NULL, hDlg, NULL); PostMessage(hDlg, WM_NULL, 0, 0); DestroyMenu (hmDummy); } break; case WM_MOUSEMOVE: Main_OnMouseOver(); break; } break; case WM_OBTAIN_TOKENS: if ( InterlockedIncrement (&g.fShowingMessage) != 1 ) InterlockedDecrement (&g.fShowingMessage); else ShowObtainCreds (wp, (char *)lp); GlobalFree((void *)lp); break; case WM_START_SERVICE: { SC_HANDLE hManager; if ((hManager = OpenSCManager ( NULL, NULL, SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE | SC_MANAGER_QUERY_LOCK_STATUS)) != NULL) { SC_HANDLE hService; if ((hService = OpenService ( hManager, TEXT("TransarcAFSDaemon"), SERVICE_QUERY_STATUS | SERVICE_START)) != NULL) { if (StartService (hService, 0, 0)) TestAndDoMapShare(SERVICE_START_PENDING); if ( KFW_is_available() && KFW_AFS_wait_for_service_start() ) { #ifdef USE_MS2MIT KFW_import_windows_lsa(); #endif /* USE_MS2MIT */ KFW_AFS_renew_tokens_for_all_cells(); } CloseServiceHandle (hService); } CloseServiceHandle (hManager); } if (KFW_AFS_wait_for_service_start()) ObtainTokensFromUserIfNeeded(g.hMain); } break; } return FALSE; }