diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/cryptlib.c | 229 | ||||
| -rw-r--r-- | src/lib/libssl/src/crypto/cryptlib.c | 229 |
2 files changed, 0 insertions, 458 deletions
diff --git a/src/lib/libcrypto/cryptlib.c b/src/lib/libcrypto/cryptlib.c index 89667d175a..2bf5def17d 100644 --- a/src/lib/libcrypto/cryptlib.c +++ b/src/lib/libcrypto/cryptlib.c | |||
| @@ -201,14 +201,6 @@ CRYPTO_get_new_lockid(char *name) | |||
| 201 | char *str; | 201 | char *str; |
| 202 | int i; | 202 | int i; |
| 203 | 203 | ||
| 204 | #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16) | ||
| 205 | /* A hack to make Visual C++ 5.0 work correctly when linking as | ||
| 206 | * a DLL using /MT. Without this, the application cannot use | ||
| 207 | * any floating point printf's. | ||
| 208 | * It also seems to be needed for Visual C 1.5 (win16) */ | ||
| 209 | SSLeay_MSVC5_hack = (double)name[0]*(double)name[1]; | ||
| 210 | #endif | ||
| 211 | |||
| 212 | if ((app_locks == NULL) && ((app_locks = sk_OPENSSL_STRING_new_null()) == NULL)) { | 204 | if ((app_locks == NULL) && ((app_locks = sk_OPENSSL_STRING_new_null()) == NULL)) { |
| 213 | CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID, ERR_R_MALLOC_FAILURE); | 205 | CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID, ERR_R_MALLOC_FAILURE); |
| 214 | return (0); | 206 | return (0); |
| @@ -488,16 +480,8 @@ CRYPTO_THREADID_current(CRYPTO_THREADID *id) | |||
| 488 | } | 480 | } |
| 489 | #endif | 481 | #endif |
| 490 | /* Else pick a backup */ | 482 | /* Else pick a backup */ |
| 491 | #ifdef OPENSSL_SYS_WIN16 | ||
| 492 | CRYPTO_THREADID_set_numeric(id, (unsigned long)GetCurrentTask()); | ||
| 493 | #elif defined(OPENSSL_SYS_WIN32) | ||
| 494 | CRYPTO_THREADID_set_numeric(id, (unsigned long)GetCurrentThreadId()); | ||
| 495 | #elif defined(OPENSSL_SYS_BEOS) | ||
| 496 | CRYPTO_THREADID_set_numeric(id, (unsigned long)find_thread(NULL)); | ||
| 497 | #else | ||
| 498 | /* For everything else, default to using the address of 'errno' */ | 483 | /* For everything else, default to using the address of 'errno' */ |
| 499 | CRYPTO_THREADID_set_pointer(id, (void*)&errno); | 484 | CRYPTO_THREADID_set_pointer(id, (void*)&errno); |
| 500 | #endif | ||
| 501 | } | 485 | } |
| 502 | 486 | ||
| 503 | int | 487 | int |
| @@ -536,17 +520,7 @@ CRYPTO_thread_id(void) | |||
| 536 | unsigned long ret = 0; | 520 | unsigned long ret = 0; |
| 537 | 521 | ||
| 538 | if (id_callback == NULL) { | 522 | if (id_callback == NULL) { |
| 539 | #ifdef OPENSSL_SYS_WIN16 | ||
| 540 | ret = (unsigned long)GetCurrentTask(); | ||
| 541 | #elif defined(OPENSSL_SYS_WIN32) | ||
| 542 | ret = (unsigned long)GetCurrentThreadId(); | ||
| 543 | #elif defined(GETPID_IS_MEANINGLESS) | ||
| 544 | ret = 1L; | ||
| 545 | #elif defined(OPENSSL_SYS_BEOS) | ||
| 546 | ret = (unsigned long)find_thread(NULL); | ||
| 547 | #else | ||
| 548 | ret = (unsigned long)getpid(); | 523 | ret = (unsigned long)getpid(); |
| 549 | #endif | ||
| 550 | } else | 524 | } else |
| 551 | ret = id_callback(); | 525 | ret = id_callback(); |
| 552 | return (ret); | 526 | return (ret); |
| @@ -721,203 +695,7 @@ void | |||
| 721 | OPENSSL_cpuid_setup(void) {} | 695 | OPENSSL_cpuid_setup(void) {} |
| 722 | #endif | 696 | #endif |
| 723 | 697 | ||
| 724 | #if (defined(_WIN32) || defined(__CYGWIN__)) && defined(_WINDLL) | ||
| 725 | #ifdef __CYGWIN__ | ||
| 726 | /* pick DLL_[PROCESS|THREAD]_[ATTACH|DETACH] definitions */ | ||
| 727 | #include <windows.h> | ||
| 728 | /* this has side-effect of _WIN32 getting defined, which otherwise | ||
| 729 | * is mutually exclusive with __CYGWIN__... */ | ||
| 730 | #endif | ||
| 731 | |||
| 732 | /* All we really need to do is remove the 'error' state when a thread | ||
| 733 | * detaches */ | ||
| 734 | |||
| 735 | BOOL WINAPI | ||
| 736 | DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) | ||
| 737 | { | ||
| 738 | switch (fdwReason) { | ||
| 739 | case DLL_PROCESS_ATTACH: | ||
| 740 | OPENSSL_cpuid_setup(); | ||
| 741 | #if defined(_WIN32_WINNT) | ||
| 742 | { | ||
| 743 | IMAGE_DOS_HEADER *dos_header = (IMAGE_DOS_HEADER *)hinstDLL; | ||
| 744 | IMAGE_NT_HEADERS *nt_headers; | ||
| 745 | |||
| 746 | if (dos_header->e_magic == IMAGE_DOS_SIGNATURE) { | ||
| 747 | nt_headers = (IMAGE_NT_HEADERS *)((char *)dos_header | ||
| 748 | + dos_header->e_lfanew); | ||
| 749 | if (nt_headers->Signature == IMAGE_NT_SIGNATURE && | ||
| 750 | hinstDLL != (HINSTANCE)(nt_headers->OptionalHeader.ImageBase)) | ||
| 751 | OPENSSL_NONPIC_relocated = 1; | ||
| 752 | } | ||
| 753 | } | ||
| 754 | #endif | ||
| 755 | break; | ||
| 756 | case DLL_THREAD_ATTACH: | ||
| 757 | break; | ||
| 758 | case DLL_THREAD_DETACH: | ||
| 759 | break; | ||
| 760 | case DLL_PROCESS_DETACH: | ||
| 761 | break; | ||
| 762 | } | ||
| 763 | return (TRUE); | ||
| 764 | } | ||
| 765 | #endif | ||
| 766 | |||
| 767 | #if defined(_WIN32) && !defined(__CYGWIN__) | ||
| 768 | #include <tchar.h> | ||
| 769 | #include <signal.h> | ||
| 770 | #ifdef __WATCOMC__ | ||
| 771 | #if defined(_UNICODE) || defined(__UNICODE__) | ||
| 772 | #define _vsntprintf _vsnwprintf | ||
| 773 | #else | ||
| 774 | #define _vsntprintf _vsnprintf | ||
| 775 | #endif | ||
| 776 | #endif | ||
| 777 | #ifdef _MSC_VER | ||
| 778 | #define alloca _alloca | ||
| 779 | #endif | ||
| 780 | |||
| 781 | #if defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0333 | ||
| 782 | int | ||
| 783 | OPENSSL_isservice(void) | ||
| 784 | { HWINSTA h; | ||
| 785 | DWORD len; | ||
| 786 | WCHAR *name; | ||
| 787 | static union { void *p; | ||
| 788 | int (*f)(void); | ||
| 789 | } _OPENSSL_isservice = { NULL }; | ||
| 790 | |||
| 791 | if (_OPENSSL_isservice.p == NULL) { | ||
| 792 | HANDLE h = GetModuleHandle(NULL); | ||
| 793 | if (h != NULL) | ||
| 794 | _OPENSSL_isservice.p = GetProcAddress(h, "_OPENSSL_isservice"); | ||
| 795 | if (_OPENSSL_isservice.p == NULL) | ||
| 796 | _OPENSSL_isservice.p = (void *) - 1; | ||
| 797 | } | ||
| 798 | 698 | ||
| 799 | if (_OPENSSL_isservice.p != (void *) - 1) | ||
| 800 | return (*_OPENSSL_isservice.f)(); | ||
| 801 | |||
| 802 | (void)GetDesktopWindow(); /* return value is ignored */ | ||
| 803 | |||
| 804 | h = GetProcessWindowStation(); | ||
| 805 | if (h == NULL) | ||
| 806 | return -1; | ||
| 807 | |||
| 808 | if (GetUserObjectInformationW (h, UOI_NAME, NULL, 0, &len) || | ||
| 809 | GetLastError() != ERROR_INSUFFICIENT_BUFFER) | ||
| 810 | return -1; | ||
| 811 | |||
| 812 | if (len > 512) | ||
| 813 | return -1; | ||
| 814 | /* paranoia */ | ||
| 815 | len++, len&=~1; | ||
| 816 | /* paranoia */ | ||
| 817 | name = (WCHAR *)alloca(len + sizeof(WCHAR)); | ||
| 818 | if (!GetUserObjectInformationW (h, UOI_NAME, name, len, &len)) | ||
| 819 | return -1; | ||
| 820 | |||
| 821 | len++, len&=~1; | ||
| 822 | /* paranoia */ | ||
| 823 | name[len/sizeof(WCHAR)]=L'\0'; /* paranoia */ | ||
| 824 | #if 1 | ||
| 825 | /* This doesn't cover "interactive" services [working with real | ||
| 826 | * WinSta0's] nor programs started non-interactively by Task | ||
| 827 | * Scheduler [those are working with SAWinSta]. */ | ||
| 828 | if (wcsstr(name, L"Service-0x")) return 1; | ||
| 829 | #else | ||
| 830 | /* This covers all non-interactive programs such as services. */ | ||
| 831 | if (!wcsstr(name, L"WinSta0")) return 1; | ||
| 832 | #endif | ||
| 833 | else return 0; | ||
| 834 | } | ||
| 835 | #else | ||
| 836 | int OPENSSL_isservice(void) { return 0; | ||
| 837 | } | ||
| 838 | #endif | ||
| 839 | |||
| 840 | void OPENSSL_showfatal (const char *fmta,...) | ||
| 841 | { va_list ap; | ||
| 842 | TCHAR buf[256]; | ||
| 843 | const TCHAR *fmt; | ||
| 844 | #ifdef STD_ERROR_HANDLE /* what a dirty trick! */ | ||
| 845 | HANDLE h; | ||
| 846 | |||
| 847 | if ((h = GetStdHandle(STD_ERROR_HANDLE)) != NULL && | ||
| 848 | GetFileType(h) != FILE_TYPE_UNKNOWN) | ||
| 849 | { /* must be console application */ | ||
| 850 | va_start (ap, fmta); | ||
| 851 | vfprintf (stderr, fmta, ap); | ||
| 852 | va_end (ap); | ||
| 853 | return; | ||
| 854 | } | ||
| 855 | #endif | ||
| 856 | |||
| 857 | if (sizeof(TCHAR) == sizeof(char)) | ||
| 858 | fmt = (const TCHAR *)fmta; | ||
| 859 | else do | ||
| 860 | { int keepgoing; | ||
| 861 | size_t len_0 = strlen(fmta) + 1, i; | ||
| 862 | WCHAR *fmtw; | ||
| 863 | |||
| 864 | fmtw = (WCHAR *)alloca(len_0*sizeof(WCHAR)); | ||
| 865 | if (fmtw == NULL) { | ||
| 866 | fmt = (const TCHAR *)L"no stack?"; | ||
| 867 | break; | ||
| 868 | } | ||
| 869 | |||
| 870 | #ifndef OPENSSL_NO_MULTIBYTE | ||
| 871 | if (!MultiByteToWideChar(CP_ACP, 0, fmta, len_0, fmtw, len_0)) | ||
| 872 | #endif | ||
| 873 | for (i = 0;i < len_0;i++) fmtw[i] = (WCHAR)fmta[i]; | ||
| 874 | |||
| 875 | for (i = 0; i < len_0; i++) | ||
| 876 | { if (fmtw[i]==L'%') do | ||
| 877 | { keepgoing = 0; | ||
| 878 | switch (fmtw[i + 1]) | ||
| 879 | { case L'0': case L'1': case L'2': case L'3': case L'4': | ||
| 880 | case L'5': case L'6': case L'7': case L'8': case L'9': | ||
| 881 | case L'.': case L'*': | ||
| 882 | case L'-': | ||
| 883 | i++; | ||
| 884 | keepgoing = 1; | ||
| 885 | break; | ||
| 886 | case L's': | ||
| 887 | fmtw[i + 1] = L'S'; | ||
| 888 | break; | ||
| 889 | case L'S': | ||
| 890 | fmtw[i + 1] = L's'; | ||
| 891 | break; | ||
| 892 | case L'c': | ||
| 893 | fmtw[i + 1] = L'C'; | ||
| 894 | break; | ||
| 895 | case L'C': | ||
| 896 | fmtw[i + 1] = L'c'; | ||
| 897 | break; | ||
| 898 | } | ||
| 899 | } while (keepgoing); | ||
| 900 | } | ||
| 901 | fmt = (const TCHAR *)fmtw; | ||
| 902 | } while (0); | ||
| 903 | |||
| 904 | va_start (ap, fmta); | ||
| 905 | _vsntprintf (buf, sizeof(buf)/sizeof(TCHAR) - 1, fmt, ap); | ||
| 906 | buf [sizeof(buf)/sizeof(TCHAR) - 1] = _T('\0'); | ||
| 907 | va_end (ap); | ||
| 908 | |||
| 909 | #if defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0333 | ||
| 910 | /* this -------------v--- guards NT-specific calls */ | ||
| 911 | if (check_winnt() && OPENSSL_isservice() > 0) | ||
| 912 | { HANDLE h = RegisterEventSource(0, _T("OPENSSL")); | ||
| 913 | const TCHAR *pmsg = buf; | ||
| 914 | ReportEvent(h, EVENTLOG_ERROR_TYPE, 0, 0, 0, 1, 0, &pmsg, 0); | ||
| 915 | DeregisterEventSource(h); | ||
| 916 | } else | ||
| 917 | #endif | ||
| 918 | MessageBox (NULL, buf, _T("OpenSSL: FATAL"), MB_OK|MB_ICONSTOP); | ||
| 919 | } | ||
| 920 | #else | ||
| 921 | void OPENSSL_showfatal(const char *fmta, ...) | 699 | void OPENSSL_showfatal(const char *fmta, ...) |
| 922 | { | 700 | { |
| 923 | va_list ap; | 701 | va_list ap; |
| @@ -931,7 +709,6 @@ int OPENSSL_isservice(void) | |||
| 931 | { | 709 | { |
| 932 | return 0; | 710 | return 0; |
| 933 | } | 711 | } |
| 934 | #endif | ||
| 935 | 712 | ||
| 936 | void | 713 | void |
| 937 | OpenSSLDie(const char *file, int line, const char *assertion) | 714 | OpenSSLDie(const char *file, int line, const char *assertion) |
| @@ -939,13 +716,7 @@ OpenSSLDie(const char *file, int line, const char *assertion) | |||
| 939 | OPENSSL_showfatal( | 716 | OPENSSL_showfatal( |
| 940 | "%s(%d): OpenSSL internal error, assertion failed: %s\n", | 717 | "%s(%d): OpenSSL internal error, assertion failed: %s\n", |
| 941 | file, line, assertion); | 718 | file, line, assertion); |
| 942 | #if !defined(_WIN32) || defined(__CYGWIN__) | ||
| 943 | abort(); | 719 | abort(); |
| 944 | #else | ||
| 945 | /* Win32 abort() customarily shows a dialog, but we just did that... */ | ||
| 946 | raise(SIGABRT); | ||
| 947 | _exit(3); | ||
| 948 | #endif | ||
| 949 | } | 720 | } |
| 950 | 721 | ||
| 951 | void *OPENSSL_stderr(void) | 722 | void *OPENSSL_stderr(void) |
diff --git a/src/lib/libssl/src/crypto/cryptlib.c b/src/lib/libssl/src/crypto/cryptlib.c index 89667d175a..2bf5def17d 100644 --- a/src/lib/libssl/src/crypto/cryptlib.c +++ b/src/lib/libssl/src/crypto/cryptlib.c | |||
| @@ -201,14 +201,6 @@ CRYPTO_get_new_lockid(char *name) | |||
| 201 | char *str; | 201 | char *str; |
| 202 | int i; | 202 | int i; |
| 203 | 203 | ||
| 204 | #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16) | ||
| 205 | /* A hack to make Visual C++ 5.0 work correctly when linking as | ||
| 206 | * a DLL using /MT. Without this, the application cannot use | ||
| 207 | * any floating point printf's. | ||
| 208 | * It also seems to be needed for Visual C 1.5 (win16) */ | ||
| 209 | SSLeay_MSVC5_hack = (double)name[0]*(double)name[1]; | ||
| 210 | #endif | ||
| 211 | |||
| 212 | if ((app_locks == NULL) && ((app_locks = sk_OPENSSL_STRING_new_null()) == NULL)) { | 204 | if ((app_locks == NULL) && ((app_locks = sk_OPENSSL_STRING_new_null()) == NULL)) { |
| 213 | CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID, ERR_R_MALLOC_FAILURE); | 205 | CRYPTOerr(CRYPTO_F_CRYPTO_GET_NEW_LOCKID, ERR_R_MALLOC_FAILURE); |
| 214 | return (0); | 206 | return (0); |
| @@ -488,16 +480,8 @@ CRYPTO_THREADID_current(CRYPTO_THREADID *id) | |||
| 488 | } | 480 | } |
| 489 | #endif | 481 | #endif |
| 490 | /* Else pick a backup */ | 482 | /* Else pick a backup */ |
| 491 | #ifdef OPENSSL_SYS_WIN16 | ||
| 492 | CRYPTO_THREADID_set_numeric(id, (unsigned long)GetCurrentTask()); | ||
| 493 | #elif defined(OPENSSL_SYS_WIN32) | ||
| 494 | CRYPTO_THREADID_set_numeric(id, (unsigned long)GetCurrentThreadId()); | ||
| 495 | #elif defined(OPENSSL_SYS_BEOS) | ||
| 496 | CRYPTO_THREADID_set_numeric(id, (unsigned long)find_thread(NULL)); | ||
| 497 | #else | ||
| 498 | /* For everything else, default to using the address of 'errno' */ | 483 | /* For everything else, default to using the address of 'errno' */ |
| 499 | CRYPTO_THREADID_set_pointer(id, (void*)&errno); | 484 | CRYPTO_THREADID_set_pointer(id, (void*)&errno); |
| 500 | #endif | ||
| 501 | } | 485 | } |
| 502 | 486 | ||
| 503 | int | 487 | int |
| @@ -536,17 +520,7 @@ CRYPTO_thread_id(void) | |||
| 536 | unsigned long ret = 0; | 520 | unsigned long ret = 0; |
| 537 | 521 | ||
| 538 | if (id_callback == NULL) { | 522 | if (id_callback == NULL) { |
| 539 | #ifdef OPENSSL_SYS_WIN16 | ||
| 540 | ret = (unsigned long)GetCurrentTask(); | ||
| 541 | #elif defined(OPENSSL_SYS_WIN32) | ||
| 542 | ret = (unsigned long)GetCurrentThreadId(); | ||
| 543 | #elif defined(GETPID_IS_MEANINGLESS) | ||
| 544 | ret = 1L; | ||
| 545 | #elif defined(OPENSSL_SYS_BEOS) | ||
| 546 | ret = (unsigned long)find_thread(NULL); | ||
| 547 | #else | ||
| 548 | ret = (unsigned long)getpid(); | 523 | ret = (unsigned long)getpid(); |
| 549 | #endif | ||
| 550 | } else | 524 | } else |
| 551 | ret = id_callback(); | 525 | ret = id_callback(); |
| 552 | return (ret); | 526 | return (ret); |
| @@ -721,203 +695,7 @@ void | |||
| 721 | OPENSSL_cpuid_setup(void) {} | 695 | OPENSSL_cpuid_setup(void) {} |
| 722 | #endif | 696 | #endif |
| 723 | 697 | ||
| 724 | #if (defined(_WIN32) || defined(__CYGWIN__)) && defined(_WINDLL) | ||
| 725 | #ifdef __CYGWIN__ | ||
| 726 | /* pick DLL_[PROCESS|THREAD]_[ATTACH|DETACH] definitions */ | ||
| 727 | #include <windows.h> | ||
| 728 | /* this has side-effect of _WIN32 getting defined, which otherwise | ||
| 729 | * is mutually exclusive with __CYGWIN__... */ | ||
| 730 | #endif | ||
| 731 | |||
| 732 | /* All we really need to do is remove the 'error' state when a thread | ||
| 733 | * detaches */ | ||
| 734 | |||
| 735 | BOOL WINAPI | ||
| 736 | DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) | ||
| 737 | { | ||
| 738 | switch (fdwReason) { | ||
| 739 | case DLL_PROCESS_ATTACH: | ||
| 740 | OPENSSL_cpuid_setup(); | ||
| 741 | #if defined(_WIN32_WINNT) | ||
| 742 | { | ||
| 743 | IMAGE_DOS_HEADER *dos_header = (IMAGE_DOS_HEADER *)hinstDLL; | ||
| 744 | IMAGE_NT_HEADERS *nt_headers; | ||
| 745 | |||
| 746 | if (dos_header->e_magic == IMAGE_DOS_SIGNATURE) { | ||
| 747 | nt_headers = (IMAGE_NT_HEADERS *)((char *)dos_header | ||
| 748 | + dos_header->e_lfanew); | ||
| 749 | if (nt_headers->Signature == IMAGE_NT_SIGNATURE && | ||
| 750 | hinstDLL != (HINSTANCE)(nt_headers->OptionalHeader.ImageBase)) | ||
| 751 | OPENSSL_NONPIC_relocated = 1; | ||
| 752 | } | ||
| 753 | } | ||
| 754 | #endif | ||
| 755 | break; | ||
| 756 | case DLL_THREAD_ATTACH: | ||
| 757 | break; | ||
| 758 | case DLL_THREAD_DETACH: | ||
| 759 | break; | ||
| 760 | case DLL_PROCESS_DETACH: | ||
| 761 | break; | ||
| 762 | } | ||
| 763 | return (TRUE); | ||
| 764 | } | ||
| 765 | #endif | ||
| 766 | |||
| 767 | #if defined(_WIN32) && !defined(__CYGWIN__) | ||
| 768 | #include <tchar.h> | ||
| 769 | #include <signal.h> | ||
| 770 | #ifdef __WATCOMC__ | ||
| 771 | #if defined(_UNICODE) || defined(__UNICODE__) | ||
| 772 | #define _vsntprintf _vsnwprintf | ||
| 773 | #else | ||
| 774 | #define _vsntprintf _vsnprintf | ||
| 775 | #endif | ||
| 776 | #endif | ||
| 777 | #ifdef _MSC_VER | ||
| 778 | #define alloca _alloca | ||
| 779 | #endif | ||
| 780 | |||
| 781 | #if defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0333 | ||
| 782 | int | ||
| 783 | OPENSSL_isservice(void) | ||
| 784 | { HWINSTA h; | ||
| 785 | DWORD len; | ||
| 786 | WCHAR *name; | ||
| 787 | static union { void *p; | ||
| 788 | int (*f)(void); | ||
| 789 | } _OPENSSL_isservice = { NULL }; | ||
| 790 | |||
| 791 | if (_OPENSSL_isservice.p == NULL) { | ||
| 792 | HANDLE h = GetModuleHandle(NULL); | ||
| 793 | if (h != NULL) | ||
| 794 | _OPENSSL_isservice.p = GetProcAddress(h, "_OPENSSL_isservice"); | ||
| 795 | if (_OPENSSL_isservice.p == NULL) | ||
| 796 | _OPENSSL_isservice.p = (void *) - 1; | ||
| 797 | } | ||
| 798 | 698 | ||
| 799 | if (_OPENSSL_isservice.p != (void *) - 1) | ||
| 800 | return (*_OPENSSL_isservice.f)(); | ||
| 801 | |||
| 802 | (void)GetDesktopWindow(); /* return value is ignored */ | ||
| 803 | |||
| 804 | h = GetProcessWindowStation(); | ||
| 805 | if (h == NULL) | ||
| 806 | return -1; | ||
| 807 | |||
| 808 | if (GetUserObjectInformationW (h, UOI_NAME, NULL, 0, &len) || | ||
| 809 | GetLastError() != ERROR_INSUFFICIENT_BUFFER) | ||
| 810 | return -1; | ||
| 811 | |||
| 812 | if (len > 512) | ||
| 813 | return -1; | ||
| 814 | /* paranoia */ | ||
| 815 | len++, len&=~1; | ||
| 816 | /* paranoia */ | ||
| 817 | name = (WCHAR *)alloca(len + sizeof(WCHAR)); | ||
| 818 | if (!GetUserObjectInformationW (h, UOI_NAME, name, len, &len)) | ||
| 819 | return -1; | ||
| 820 | |||
| 821 | len++, len&=~1; | ||
| 822 | /* paranoia */ | ||
| 823 | name[len/sizeof(WCHAR)]=L'\0'; /* paranoia */ | ||
| 824 | #if 1 | ||
| 825 | /* This doesn't cover "interactive" services [working with real | ||
| 826 | * WinSta0's] nor programs started non-interactively by Task | ||
| 827 | * Scheduler [those are working with SAWinSta]. */ | ||
| 828 | if (wcsstr(name, L"Service-0x")) return 1; | ||
| 829 | #else | ||
| 830 | /* This covers all non-interactive programs such as services. */ | ||
| 831 | if (!wcsstr(name, L"WinSta0")) return 1; | ||
| 832 | #endif | ||
| 833 | else return 0; | ||
| 834 | } | ||
| 835 | #else | ||
| 836 | int OPENSSL_isservice(void) { return 0; | ||
| 837 | } | ||
| 838 | #endif | ||
| 839 | |||
| 840 | void OPENSSL_showfatal (const char *fmta,...) | ||
| 841 | { va_list ap; | ||
| 842 | TCHAR buf[256]; | ||
| 843 | const TCHAR *fmt; | ||
| 844 | #ifdef STD_ERROR_HANDLE /* what a dirty trick! */ | ||
| 845 | HANDLE h; | ||
| 846 | |||
| 847 | if ((h = GetStdHandle(STD_ERROR_HANDLE)) != NULL && | ||
| 848 | GetFileType(h) != FILE_TYPE_UNKNOWN) | ||
| 849 | { /* must be console application */ | ||
| 850 | va_start (ap, fmta); | ||
| 851 | vfprintf (stderr, fmta, ap); | ||
| 852 | va_end (ap); | ||
| 853 | return; | ||
| 854 | } | ||
| 855 | #endif | ||
| 856 | |||
| 857 | if (sizeof(TCHAR) == sizeof(char)) | ||
| 858 | fmt = (const TCHAR *)fmta; | ||
| 859 | else do | ||
| 860 | { int keepgoing; | ||
| 861 | size_t len_0 = strlen(fmta) + 1, i; | ||
| 862 | WCHAR *fmtw; | ||
| 863 | |||
| 864 | fmtw = (WCHAR *)alloca(len_0*sizeof(WCHAR)); | ||
| 865 | if (fmtw == NULL) { | ||
| 866 | fmt = (const TCHAR *)L"no stack?"; | ||
| 867 | break; | ||
| 868 | } | ||
| 869 | |||
| 870 | #ifndef OPENSSL_NO_MULTIBYTE | ||
| 871 | if (!MultiByteToWideChar(CP_ACP, 0, fmta, len_0, fmtw, len_0)) | ||
| 872 | #endif | ||
| 873 | for (i = 0;i < len_0;i++) fmtw[i] = (WCHAR)fmta[i]; | ||
| 874 | |||
| 875 | for (i = 0; i < len_0; i++) | ||
| 876 | { if (fmtw[i]==L'%') do | ||
| 877 | { keepgoing = 0; | ||
| 878 | switch (fmtw[i + 1]) | ||
| 879 | { case L'0': case L'1': case L'2': case L'3': case L'4': | ||
| 880 | case L'5': case L'6': case L'7': case L'8': case L'9': | ||
| 881 | case L'.': case L'*': | ||
| 882 | case L'-': | ||
| 883 | i++; | ||
| 884 | keepgoing = 1; | ||
| 885 | break; | ||
| 886 | case L's': | ||
| 887 | fmtw[i + 1] = L'S'; | ||
| 888 | break; | ||
| 889 | case L'S': | ||
| 890 | fmtw[i + 1] = L's'; | ||
| 891 | break; | ||
| 892 | case L'c': | ||
| 893 | fmtw[i + 1] = L'C'; | ||
| 894 | break; | ||
| 895 | case L'C': | ||
| 896 | fmtw[i + 1] = L'c'; | ||
| 897 | break; | ||
| 898 | } | ||
| 899 | } while (keepgoing); | ||
| 900 | } | ||
| 901 | fmt = (const TCHAR *)fmtw; | ||
| 902 | } while (0); | ||
| 903 | |||
| 904 | va_start (ap, fmta); | ||
| 905 | _vsntprintf (buf, sizeof(buf)/sizeof(TCHAR) - 1, fmt, ap); | ||
| 906 | buf [sizeof(buf)/sizeof(TCHAR) - 1] = _T('\0'); | ||
| 907 | va_end (ap); | ||
| 908 | |||
| 909 | #if defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0333 | ||
| 910 | /* this -------------v--- guards NT-specific calls */ | ||
| 911 | if (check_winnt() && OPENSSL_isservice() > 0) | ||
| 912 | { HANDLE h = RegisterEventSource(0, _T("OPENSSL")); | ||
| 913 | const TCHAR *pmsg = buf; | ||
| 914 | ReportEvent(h, EVENTLOG_ERROR_TYPE, 0, 0, 0, 1, 0, &pmsg, 0); | ||
| 915 | DeregisterEventSource(h); | ||
| 916 | } else | ||
| 917 | #endif | ||
| 918 | MessageBox (NULL, buf, _T("OpenSSL: FATAL"), MB_OK|MB_ICONSTOP); | ||
| 919 | } | ||
| 920 | #else | ||
| 921 | void OPENSSL_showfatal(const char *fmta, ...) | 699 | void OPENSSL_showfatal(const char *fmta, ...) |
| 922 | { | 700 | { |
| 923 | va_list ap; | 701 | va_list ap; |
| @@ -931,7 +709,6 @@ int OPENSSL_isservice(void) | |||
| 931 | { | 709 | { |
| 932 | return 0; | 710 | return 0; |
| 933 | } | 711 | } |
| 934 | #endif | ||
| 935 | 712 | ||
| 936 | void | 713 | void |
| 937 | OpenSSLDie(const char *file, int line, const char *assertion) | 714 | OpenSSLDie(const char *file, int line, const char *assertion) |
| @@ -939,13 +716,7 @@ OpenSSLDie(const char *file, int line, const char *assertion) | |||
| 939 | OPENSSL_showfatal( | 716 | OPENSSL_showfatal( |
| 940 | "%s(%d): OpenSSL internal error, assertion failed: %s\n", | 717 | "%s(%d): OpenSSL internal error, assertion failed: %s\n", |
| 941 | file, line, assertion); | 718 | file, line, assertion); |
| 942 | #if !defined(_WIN32) || defined(__CYGWIN__) | ||
| 943 | abort(); | 719 | abort(); |
| 944 | #else | ||
| 945 | /* Win32 abort() customarily shows a dialog, but we just did that... */ | ||
| 946 | raise(SIGABRT); | ||
| 947 | _exit(3); | ||
| 948 | #endif | ||
| 949 | } | 720 | } |
| 950 | 721 | ||
| 951 | void *OPENSSL_stderr(void) | 722 | void *OPENSSL_stderr(void) |
