/* * Function: Called during blocking operations. Implement a timeout * if nothing occurs within the specified time, cancel the blocking * operation. Also permit the user to press escape in order to * cancel the blocking operation. * * Returns: TRUE if we got and dispatched a message, FALSE otherwise. */ BOOL CALLBACK blocking_hook_proc(void) { MSG msg; BOOL rc; if (GetTickCount() > blocking_end_time) { WSACancelBlockingCall(); return FALSE; } rc = (BOOL)PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); if (!rc) return FALSE; if (msg.message == WM_KEYDOWN && msg.wParam == VK_ESCAPE) { WSACancelBlockingCall(); blocking_end_time = msg.time - 1; return FALSE; } TranslateMessage(&msg); DispatchMessage(&msg); return TRUE; }
int MSLogUnInit() { unInitLock(&g_MSLog.lock); if(g_MSLog.logfd) fclose(g_MSLog.logfd); if(g_MSLog.pMemBuffer) free(g_MSLog.pMemBuffer); #if defined(WIN32) ::closesocket(g_sock); #else ::close(g_sock); #endif g_sock = -1; memset(&g_MSLog,0,sizeof(MSLOGMGR)); #ifdef WIN32 if(WSACleanup() == SOCKET_ERROR) { if(WSAGetLastError() == WSAEINPROGRESS) { WSACancelBlockingCall(); WSACleanup(); } } #else #endif return 0; }
BOOL PASCAL FAR BlockingHook(void) { #ifdef ID_PC MSG msg; BOOL ret; if ((Sys_FloatTime() - blocktime) > 2.0) { WSACancelBlockingCall(); return FALSE; } /* get the next message, if any */ ret = (BOOL) PeekMessage(&msg, NULL, 0, 0, PM_REMOVE); /* if we got one, process it */ if (ret) { TranslateMessage(&msg); DispatchMessage(&msg); } /* TRUE if we got a message */ return ret; #endif return false; }
void SDLNet_Quit() { if ( SDLNet_started == 0 ) { return; } if ( --SDLNet_started == 0 ) { #ifdef __USE_W32_SOCKETS /* Clean up windows networking */ if ( WSACleanup() == SOCKET_ERROR ) { if ( WSAGetLastError() == WSAEINPROGRESS ) { #ifndef _WIN32_WCE WSACancelBlockingCall(); #endif WSACleanup(); } } #else /* Restore the SIGPIPE handler */ void (*handler)(int); handler = signal(SIGPIPE, SIG_DFL); if ( handler != SIG_IGN ) { signal(SIGPIPE, handler); } #endif } }
void SDLNet_Quit(void) { if ( SDLNet_started == 0 ) { return; } if ( --SDLNet_started == 0 ) { #ifdef __USE_W32_SOCKETS /* Clean up windows networking */ if ( WSACleanup() == SOCKET_ERROR ) { if ( WSAGetLastError() == WSAEINPROGRESS ) { WSACancelBlockingCall(); WSACleanup(); } } #else #ifdef __CELLOS_LV2__ /* kill the stack */ sys_net_finalize_network(); cellSysmoduleUnloadModule(CELL_SYSMODULE_NET); #endif #ifndef __CELLOS_LV2__ /* No signals on cell */ /* Restore the SIGPIPE handler */ void (*handler)(int); handler = signal(SIGPIPE, SIG_DFL); if ( handler != SIG_IGN ) { signal(SIGPIPE, handler); } #endif #endif } }
BOOL WINAPI SocketsBlockingHook() { PGPEventHandlerProcPtr eventHandler = NULL; PGPUserValue userValue; PGPError pgpError; PGPRMWOLockStartReading(&sIdleEventHandlerLock); (void) PGPThreadGetSpecific(sIdleEventHandlerIndex, (void**)&eventHandler); (void) PGPThreadGetSpecific(sIdleEventHandlerDataIndex, &userValue); PGPRMWOLockStopReading(&sIdleEventHandlerLock); if (eventHandler != NULL) { PGPEvent theEvent; pgpClearMemory(&theEvent, sizeof(theEvent)); theEvent.type = kPGPEvent_SocketsIdleEvent; pgpError = eventHandler(NULL, &theEvent, userValue); if (IsPGPError(pgpError)) { WSACancelBlockingCall(); } } return FALSE; }
/** ** Hardware dependend network exit. */ void NetExit() { // Clean up windows networking if (WSACleanup() == SOCKET_ERROR) { if (WSAGetLastError() == WSAEINPROGRESS) { WSACancelBlockingCall(); WSACleanup(); } } }
static void ssl_sock_cleanup(void) { if (wsa_init_done) { wsa_init_done = 0; # ifndef OPENSSL_SYS_WINCE WSACancelBlockingCall(); # endif WSACleanup(); } }
static void Destroy(void) { if (WSACleanup() == SOCKET_ERROR && WSAGetLastError() == WSAEINPROGRESS) { #ifndef _WIN32_WCE WSACancelBlockingCall(); #endif WSACleanup(); } AG_MutexDestroy(&agNetWin32Lock); }
static BOOLEAN AreLegacyFunctionsSupported(VOID) { int Error; Error = WSACancelBlockingCall(); ok(Error == SOCKET_ERROR, "Error = %d\n", Error); ok(WSAGetLastError() == WSAEOPNOTSUPP || WSAGetLastError() == WSAEINVAL, "WSAGetLastError = %d\n", WSAGetLastError()); return WSAGetLastError() != WSAEOPNOTSUPP; }
BOOL WINAPI WsAsyncThreadBlockingHook(VOID) { /* Check if this task is being cancelled */ if (WsAsyncCurrentTaskHandle == WsAsyncCancelledTaskHandle) { /* Cancel the blocking call so we can get back */ WSACancelBlockingCall(); } /* Return to system */ return FALSE; }
int net_cleanup(void) { #if defined(__WIN32__) || defined(WIN32) if ( WSACleanup() == SOCKET_ERROR ) { if ( WSAGetLastError() == WSAEINPROGRESS ) { WSACancelBlockingCall(); WSACleanup(); return 0; } } return 0; #else return 0; #endif }
void BIO_sock_cleanup(void) { #ifdef OPENSSL_SYS_WINDOWS if (wsa_init_done) { wsa_init_done=0; #ifndef OPENSSL_SYS_WINCE WSACancelBlockingCall(); #endif WSACleanup(); } #elif defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK) if (wsa_init_done) { wsa_init_done=0; WSACleanup(); } #endif }
void TcpClient::close() const { if (client_ != 0) { ::shutdown(client_, 1); #ifdef _WIN32 closesocket(client_); if (WSACleanup() == SOCKET_ERROR) { if (WSAGetLastError() == WSAEINPROGRESS) { #ifndef _WIN32_WCE WSACancelBlockingCall(); #endif WSACleanup(); } } #else ::close(client_); #endif } }
void BIO_sock_cleanup(void) { #ifdef OPENSSL_SYS_WINDOWS if (wsa_init_done) { wsa_init_done=0; #if 0 /* this call is claimed to be non-present in Winsock2 */ WSACancelBlockingCall(); #endif WSACleanup(); } #elif defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK) if (wsa_init_done) { wsa_init_done=0; WSACleanup(); } #endif }
void net_Quit(void) { if ( net_started == 0 ) return; if ( net_started-- == 0 ) { #ifdef __USE_W32_SOCKETS /* Clean up windows networking */ if ( WSACleanup() == SOCKET_ERROR ) { if ( WSAGetLastError() == WSAEINPROGRESS ) { WSACancelBlockingCall(); WSACleanup(); } } #else ; #endif } }
/* ------------------------------------------------------------------ */ int Skt4uCleanup (void) { int Ark; if (bInitDone) { /* blocking call ? */ if (WSAIsBlocking()) { WSACancelBlockingCall (); return TCP4U_ERROR; } else { /* TcpClose (&s) force s a -1 -> pas besoin de UnrcdSkt */ for (Ark=0 ; Ark<SizeOfTab(HistoSocket) ; Ark++) if ( HistoSocket[Ark].hTask == GetCurrentTask () && HistoSocket[Ark].skt != INVALID_SOCKET ) TcpClose (& HistoSocket[Ark].skt); WSACleanup (); } /* requete non bloquante */ } /* bInitDone */ return TCP4U_SUCCESS; } /* Skt4wCleanup */
/* * try to send out and receive message. * return 1 on success, 0 on failure */ static send_recv(KTEXT pkt, KTEXT rpkt, SOCKET f, struct sockaddr_in *_to, struct hostent *addrs) { fd_set readfds; register struct hostent *hp; struct sockaddr_in from; int sin_size; int numsent; int ret = SOCKET_ERROR; if (krb_debug) { if (_to->sin_family == AF_INET) kdebug("Sending message to %s...", inet_ntoa(_to->sin_addr)); else kdebug("Sending message..."); } if ((numsent = sendto(f,(char *)(pkt->dat), pkt->length, 0, (struct sockaddr *)_to, S_AD_SZ)) != pkt->length) { if (krb_debug) kdebug("sent only %d/%d\n", numsent, pkt->length); return 0; } if (krb_debug) { kdebug("Sent\nWaiting for reply..."); } FD_ZERO(&readfds); FD_SET(f, &readfds); WSASetLastError(0); /* select - either recv is ready, or timeout */ /* see if timeout or error or wrong descriptor */ ret = select(0, &readfds, (fd_set *)0, (fd_set *)0, &timeout); if (ret != 1 || !FD_ISSET(f, &readfds)) { /* I don't think the WinSock blocking stuff is needed... */ if (WSAIsBlocking()) { WSACancelBlockingCall(); } if (krb_debug) { kdebug("select failed: ret=%d, readfds=%x, errno=%d", ret, readfds, WSAGetLastError()); } return 0; } sin_size = sizeof(from); if ((numsent = (recvfrom(f, (char *)(rpkt->dat), sizeof(rpkt->dat), 0, (struct sockaddr *)&from, &sin_size))) != rpkt->length) { if (numsent < 0) { if (krb_debug) kdebug("recvfrom : Error %d\n", WSAGetLastError()); return 0; } } if (krb_debug) { kdebug("received packet from %s\n", inet_ntoa(from.sin_addr)); } for (hp = addrs; hp->h_name != 0; hp++) { if (!memcmp(hp->h_addr, &from.sin_addr.s_addr, hp->h_length)) { if (krb_debug) { kdebug("Received it\n"); } return 1; } if (krb_debug) kdebug("packet not from %x\n", hp->h_addr); } if (krb_debug) kdebug("%s: received packet from wrong host! (%x)\n", "send_to_kdc(send_rcv)", from.sin_addr.s_addr); return 0; }
/*************************************************** StartShutdown purpose Tells the thread that it should shutdown immediatly, also sets a shutdown flag that the rest of the class must monitor params None return UTE_SUCCESS if successful - this does not mean the thread has shutdown, but that the process has started ****************************************************/ int CUT_WSThread::StartShutdown(){ WSACancelBlockingCall(); m_nShutDownFlag = TRUE; return OnError(UTE_SUCCESS); }
/* * Function: Process WM_COMMAND messages */ static void kwin_command(HWND hwnd, int cid, HWND hwndCtl, UINT codeNotify) { char name[ANAME_SZ]; char realm[REALM_SZ]; char password[MAX_KPW_LEN]; HCURSOR hcursor; BOOL blogin; HMENU hmenu; char menuitem[MAX_K_NAME_SZ + 3]; char copyright[128]; int id; #ifdef KRB4 char instance[INST_SZ]; int lifetime; int krc; #endif #ifdef KRB5 long lifetime; krb5_error_code code; krb5_principal principal; krb5_creds creds; krb5_get_init_creds_opt opts; gic_data gd; #endif #ifdef KRB4 EnableWindow(GetDlgItem(hwnd, IDD_TICKET_DELETE), krb_get_num_cred() > 0); #endif #ifdef KRB5 EnableWindow(GetDlgItem(hwnd, IDD_TICKET_DELETE), k5_get_num_cred(1) > 0); #endif GetDlgItemText(hwnd, IDD_LOGIN_NAME, name, sizeof(name)); trim(name); blogin = strlen(name) > 0; if (blogin) { GetDlgItemText(hwnd, IDD_LOGIN_REALM, realm, sizeof(realm)); trim(realm); blogin = strlen(realm) > 0; } if (blogin) { GetDlgItemText(hwnd, IDD_LOGIN_PASSWORD, password, sizeof(password)); blogin = strlen(password) > 0; } EnableWindow(GetDlgItem(hwnd, IDD_LOGIN), blogin); id = (blogin) ? IDD_LOGIN : IDD_PASSWORD_CR2; SendMessage(hwnd, DM_SETDEFID, id, 0); if (codeNotify != BN_CLICKED && codeNotify != 0 && codeNotify != 1) return; /* FALSE */ /* * Check to see if this item is in a list of the ``recent hosts'' sort * of list, under the FILE menu. */ if (cid >= IDM_FIRST_LOGIN && cid < IDM_FIRST_LOGIN + FILE_MENU_MAX_LOGINS) { hmenu = GetMenu(hwnd); assert(hmenu != NULL); hmenu = GetSubMenu(hmenu, 0); assert(hmenu != NULL); if (!GetMenuString(hmenu, cid, menuitem, sizeof(menuitem), MF_BYCOMMAND)) return; /* TRUE */ if (menuitem[0]) kwin_init_name(hwnd, &menuitem[3]); return; /* TRUE */ } switch (cid) { case IDM_EXIT: if (isblocking) WSACancelBlockingCall(); WinHelp(hwnd, KERBEROS_HLP, HELP_QUIT, 0); PostQuitMessage(0); return; /* TRUE */ case IDD_PASSWORD_CR2: /* Make CR == TAB */ id = GetDlgCtrlID(GetFocus()); assert(id != 0); if (id == IDD_MAX_EDIT) PostMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwnd, IDD_MIN_EDIT), MAKELONG(1, 0)); else PostMessage(hwnd, WM_NEXTDLGCTL, 0, 0); return; /* TRUE */ case IDD_LOGIN: if (isblocking) return; /* TRUE */ GetDlgItemText(hwnd, IDD_LOGIN_NAME, name, sizeof(name)); trim(name); GetDlgItemText(hwnd, IDD_LOGIN_REALM, realm, sizeof(realm)); trim(realm); GetDlgItemText(hwnd, IDD_LOGIN_PASSWORD, password, sizeof(password)); SetDlgItemText(hwnd, IDD_LOGIN_PASSWORD, ""); /* nuke the password */ trim(password); #ifdef KRB4 GetDlgItemText(hwnd, IDD_LOGIN_INSTANCE, instance, sizeof(instance)); trim(instance); #endif hcursor = SetCursor(LoadCursor(NULL, IDC_WAIT)); lifetime = cns_res.lifetime; start_blocking_hook(BLOCK_MAX_SEC); #ifdef KRB4 lifetime = (lifetime + 4) / 5; krc = krb_get_pw_in_tkt(name, instance, realm, "krbtgt", realm, lifetime, password); #endif #ifdef KRB5 principal = NULL; /* * convert the name + realm into a krb5 principal string and parse it into a principal */ sprintf(menuitem, "%s@%s", name, realm); code = krb5_parse_name(k5_context, menuitem, &principal); if (code) goto errorpoint; /* * set the various ticket options. First, initialize the structure, then set the ticket * to be forwardable if desired, and set the lifetime. */ krb5_get_init_creds_opt_init(&opts); krb5_get_init_creds_opt_set_forwardable(&opts, forwardable); krb5_get_init_creds_opt_set_tkt_life(&opts, lifetime * 60); if (noaddresses) { krb5_get_init_creds_opt_set_address_list(&opts, NULL); } /* * get the initial creds using the password and the options we set above */ gd.hinstance = hinstance; gd.hwnd = hwnd; gd.id = ID_VARDLG; code = krb5_get_init_creds_password(k5_context, &creds, principal, password, gic_prompter, &gd, 0, NULL, &opts); if (code) goto errorpoint; /* * initialize the credential cache */ code = krb5_cc_initialize(k5_context, k5_ccache, principal); if (code) goto errorpoint; /* * insert the principal into the cache */ code = krb5_cc_store_cred(k5_context, k5_ccache, &creds); errorpoint: if (principal) krb5_free_principal(k5_context, principal); end_blocking_hook(); SetCursor(hcursor); kwin_set_default_focus(hwnd); if (code) { if (code == KRB5KRB_AP_ERR_BAD_INTEGRITY) MessageBox(hwnd, "Password incorrect", NULL, MB_OK | MB_ICONEXCLAMATION); else com_err(NULL, code, "while logging in"); } #endif /* KRB5 */ #ifdef KRB4 if (krc != KSUCCESS) { MessageBox(hwnd, krb_get_err_text(krc), "", MB_OK | MB_ICONEXCLAMATION); return; /* TRUE */ } #endif kwin_save_name(hwnd); alerted = FALSE; switch (action) { case LOGIN_AND_EXIT: SendMessage(hwnd, WM_COMMAND, GET_WM_COMMAND_MPS(IDM_EXIT, 0, 0)); break; case LOGIN_AND_MINIMIZE: ShowWindow(hwnd, SW_MINIMIZE); break; } return; /* TRUE */ case IDD_TICKET_DELETE: if (isblocking) return; /* TRUE */ #ifdef KRB4 krc = dest_tkt(); if (krc != KSUCCESS) MessageBox(hwnd, krb_get_err_text(krc), "", MB_OK | MB_ICONEXCLAMATION); #endif #ifdef KRB5 code = k5_dest_tkt(); #endif kwin_set_default_focus(hwnd); alerted = FALSE; return; /* TRUE */ case IDD_CHANGE_PASSWORD: if (isblocking) return; /* TRUE */ password_dialog(hwnd); kwin_set_default_focus(hwnd); return; /* TRUE */ case IDM_OPTIONS: if (isblocking) return; /* TRUE */ opts_dialog(hwnd); return; /* TRUE */ case IDM_HELP_INDEX: WinHelp(hwnd, KERBEROS_HLP, HELP_INDEX, 0); return; /* TRUE */ case IDM_ABOUT: ticket_init_list(GetDlgItem(hwnd, IDD_TICKET_LIST)); if (isblocking) return; /* TRUE */ #ifdef KRB4 strcpy(copyright, " Kerberos 4 for Windows "); #endif #ifdef KRB5 strcpy(copyright, " Kerberos V5 for Windows "); #endif #ifdef _WIN32 strncat(copyright, "32-bit\n", sizeof(copyright) - 1 - strlen(copyright)); #else strncat(copyright, "16-bit\n", sizeof(copyright) - 1 - strlen(copyright)); #endif strncat(copyright, "\n Version 1.12\n\n", sizeof(copyright) - 1 - strlen(copyright)); #ifdef ORGANIZATION strncat(copyright, " For information, contact:\n", sizeof(copyright) - 1 - strlen(copyright)); strncat(copyright, ORGANIZATION, sizeof(copyright) - 1 - strlen(copyright)); #endif MessageBox(hwnd, copyright, KWIN_DIALOG_NAME, MB_OK); return; /* TRUE */ } return; /* FALSE */ }