Seulement dans patch2: bin Seulement dans patch2: obj diff -cr orig/src/client.c patch2/src/client.c *** orig/src/client.c 2014-04-12 20:55:57.000000000 +0200 --- patch2/src/client.c 2014-06-10 09:23:03.812500000 +0200 *************** *** 929,934 **** --- 929,935 ---- default: sockerror(text); longjmp(c->err, 1); + return 1; /* 20140610 pdelaage to avoid warning on W32/WCE */ } } diff -cr orig/src/common.h patch2/src/common.h *** orig/src/common.h 2014-04-14 13:40:40.000000000 +0200 --- patch2/src/common.h 2014-06-10 08:49:06.406250000 +0200 *************** *** 222,228 **** --- 222,230 ---- #include #include /* _beginthread */ + #ifndef _WIN32_WCE /* pdelaage 20140520 : this file does not exist in WCE; if needed, a replacement for SHGetFolderPath will be provided for WCE */ #include /* SHGetFolderPath */ + #endif #include #include "resources.h" diff -cr orig/src/evc.mak patch2/src/evc.mak *** orig/src/evc.mak 2013-05-20 07:23:11.000000000 +0200 --- patch2/src/evc.mak 2014-06-21 20:57:18.828125000 +0200 *************** *** 1,8 **** # wce.mak for stunnel.exe by Michal Trojnara 2006-2012 # with help of Pierre Delaage # # DEFAULTLIB management: only 2 are necessary ! # defaultlibS as given for CLxxx in the MS doc ARE WRONG # !!!!!!!!!!!!!! # CUSTOMIZE THIS according to your wcecompat and openssl directories --- 1,25 ---- # wce.mak for stunnel.exe by Michal Trojnara 2006-2012 # with help of Pierre Delaage + # pdelaage 20140610 : added UNICODE optional FLAG, always ACTIVE on WCE because of poor ANSI support + # pdelaage 20140610 : added _WIN32_WCE flag for RC compilation, to preprocess out "HELP" unsupported menu flag on WCE + # pdelaage 20140610 : added new source mywcedefs.c for more WCE equivalent to some W32 services + # pdelaage 20140610 : ws2 lib is required to get WSAGetLastError routine (absent from winsock lib) + # pdelaage 20140610 : /Dx86 flag required for X86/Emulator targets, to get proper definition for InterlockedExchange + # pdelaage 20140610 : /MT flag is NON-SENSE for X86-WCE platforms, it is only meaningful for X86-W32-Desktop. + # for X86-WCE targets, although compiler "cl.exe" is REALLY the same as desktop W32 VS6 C++ compiler, + # the MT flags relating to LIBCMT is useless BECAUSE LIBCMT does NOT exist on WCE. No msvcrt on WCE either... + + # pdelaage 20140610 : Note on /MC flag + # For other targets than X86/Emulator, /MC flag is redundant with "/nodefaultlib coredll.lib corelibc.lib" LD lib list. + # For << X86 / Emulator >> target, as the cl.exe compiler IS the SAME as the standard VS6.0 C++ compiler for Desktop Pentium processor, + # /MC flag is in fact NOT existing, thus requiring an explicit linking with core libs by using : + # /NODEFAULTLIB coredll.lib corelibc.lib, + # something that is correct for any WCE target, X86 and other, and leading /MC flag to be useless ALSO for other target than X86. + + # # DEFAULTLIB management: only 2 are necessary ! # defaultlibS, as given for CLxxx in the MS doc, ARE WRONG # !!!!!!!!!!!!!! # CUSTOMIZE THIS according to your wcecompat and openssl directories *************** *** 10,19 **** # Modify this to point to your actual openssl compile directory # (You did already compile openssl, didn't you???) ! SSLDIR=C:\Users\standard\Documents\Dvts\Contrib\openssl\v1.0.0a\patched3 # Note that we currently use a multi-target customized version of legacy Essemer/wcecompat lib ! COMPATDIR=C:\Users\standard\Documents\Dvts\Contrib\wcecompat\v12\patchedX86 WCEVER=420 --- 27,36 ---- # Modify this to point to your actual openssl compile directory # (You did already compile openssl, didn't you???) ! SSLDIR=C:\Users\pdelaage\Dvts\Contrib\openssl\v1.0.2-stable-SNAP-20121213\patch3 # Note that we currently use a multi-target customized version of legacy Essemer/wcecompat lib ! COMPATDIR=C:\Users\pdelaage\Dvts\Contrib\wcecompat\v12\patched3emu WCEVER=420 *************** *** 24,30 **** !IF "$(TARGETCPU)"=="X86" WCETARGETCPU=_X86_ LDTARGETCPU=X86 ! MORECFLAGS=/MT # TODO: continue list for other targets : see wcecompat/wcedefs.mak for a good ref. # see also openssl/util/pl/vc-32.pl, also link /? --- 41,48 ---- !IF "$(TARGETCPU)"=="X86" WCETARGETCPU=_X86_ LDTARGETCPU=X86 ! #pdelaage 20140621 /Dx86 for inline defs of InterlockedExchange inline in winbase.h; no more /MT ! MORECFLAGS=/Dx86 # TODO: continue list for other targets : see wcecompat/wcedefs.mak for a good ref. # see also openssl/util/pl/vc-32.pl, also link /? *************** *** 34,50 **** !ELSEIF "$(TARGETCPU)"=="emulator" WCETARGETCPU=_X86_ LDTARGETCPU=X86 ! MORECFLAGS=/MT !ELSEIF "$(TARGETCPU)"=="MIPS16" || "$(TARGETCPU)"=="MIPSII" || "$(TARGETCPU)"=="MIPSII_FP" || "$(TARGETCPU)"=="MIPSIV" || "$(TARGETCPU)"=="MIPSIV_FP" WCETARGETCPU=_MIPS_ LDTARGETCPU=MIPS ! MORECFLAGS=/DMIPS /MC !ELSEIF "$(TARGETCPU)"=="SH3" || "$(TARGETCPU)"=="SH4" WCETARGETCPU=SHx LDTARGETCPU=$(TARGETCPU) ! MORECFLAGS=/MC !ELSE # default is ARM ! --- 52,71 ---- !ELSEIF "$(TARGETCPU)"=="emulator" WCETARGETCPU=_X86_ LDTARGETCPU=X86 ! #pdelaage 20140621 /Dx86 for inline defs of InterlockedExchange inline in winbase.h; no more /MT ! MORECFLAGS=/Dx86 !ELSEIF "$(TARGETCPU)"=="MIPS16" || "$(TARGETCPU)"=="MIPSII" || "$(TARGETCPU)"=="MIPSII_FP" || "$(TARGETCPU)"=="MIPSIV" || "$(TARGETCPU)"=="MIPSIV_FP" WCETARGETCPU=_MIPS_ LDTARGETCPU=MIPS ! #pdelaage 20140621 no more /MC required ! MORECFLAGS=/DMIPS !ELSEIF "$(TARGETCPU)"=="SH3" || "$(TARGETCPU)"=="SH4" WCETARGETCPU=SHx LDTARGETCPU=$(TARGETCPU) ! #pdelaage 20140621 no more /MC required ! MORECFLAGS= !ELSE # default is ARM ! *************** *** 52,59 **** # the following flag is required by (eg) winnt.h, and is different from targetcpu (armV4) WCETARGETCPU=ARM LDTARGETCPU=ARM ! MORECFLAGS=/MC ! !ENDIF # ceutilsdir probably useless (nb : were tools from essemer; but ms delivers a cecopy anyway, see ms dld site) --- 73,80 ---- # the following flag is required by (eg) winnt.h, and is different from targetcpu (armV4) WCETARGETCPU=ARM LDTARGETCPU=ARM ! #pdelaage 20140621 no more /MC required ! MORECFLAGS= !ENDIF # ceutilsdir probably useless (nb : were tools from essemer; but ms delivers a cecopy anyway, see ms dld site) *************** *** 65,76 **** INCLUDES=-I$(SSLDIR)\inc32 -I$(COMPATDIR)\include -I"$(SDKDIR)\include\$(TARGETCPU)" # for X86 and other it appears that /MC or /ML flags are absurd, # we always have to override runtime lib list to coredll and corelibc ! LIBS=/NODEFAULTLIB winsock.lib wcecompatex.lib libeay32.lib ssleay32.lib coredll.lib corelibc.lib DEFINES=/DHOST=\"$(TARGETCPU)-WCE-eVC-$(WCEVER)\" # /O1 /Oi more correct vs MS doc ! CFLAGS=/nologo $(MORECFLAGS) /O1 /Oi /W3 /WX /GF /Gy $(DEFINES) /D$(WCETARGETCPU) /D$(TARGETCPU) /DUNDER_CE=$(WCEVER) /D_WIN32_WCE=$(WCEVER) /DUNICODE -D_UNICODE $(INCLUDES) ! RFLAGS=$(DEFINES) $(INCLUDES) # LDFLAGS: since openssl >> 098a (eg 098h) out32dll is out32dll_targetCPU for WCE # delaage added $(TARGETCPU) in legacy Essemer/wcecompat libpath # to ease multitarget compilation without recompiling everything --- 86,102 ---- INCLUDES=-I$(SSLDIR)\inc32 -I$(COMPATDIR)\include -I"$(SDKDIR)\include\$(TARGETCPU)" # for X86 and other it appears that /MC or /ML flags are absurd, # we always have to override runtime lib list to coredll and corelibc ! #LIBS=/NODEFAULTLIB winsock.lib wcecompatex.lib libeay32.lib ssleay32.lib coredll.lib corelibc.lib ! LIBS=/NODEFAULTLIB ws2.lib wcecompatex.lib libeay32.lib ssleay32.lib coredll.lib corelibc.lib DEFINES=/DHOST=\"$(TARGETCPU)-WCE-eVC-$(WCEVER)\" + # pdelaage 20140610 added unicode flag : ALWAYS ACTIVE on WCE, because of poor ANSI support by the MS SDK + UNICODEFLAGS=/DUNICODE -D_UNICODE # /O1 /Oi more correct vs MS doc ! CFLAGS=/nologo $(MORECFLAGS) /O1 /Oi /W3 /WX /GF /Gy $(DEFINES) /D$(WCETARGETCPU) /D$(TARGETCPU) /DUNDER_CE=$(WCEVER) /D_WIN32_WCE=$(WCEVER) $(UNICODEFLAGS) $(INCLUDES) ! # pdelaage 20140610 : RC compilation requires D_WIN32_WCE flag to comment out unsupported "HELP" flag in menu definition, in resources.rc file ! RFLAGS=$(DEFINES) /D_WIN32_WCE=$(WCEVER) $(INCLUDES) ! # LDFLAGS: since openssl >> 098a (eg 098h) out32dll is out32dll_targetCPU for WCE # delaage added $(TARGETCPU) in legacy Essemer/wcecompat libpath # to ease multitarget compilation without recompiling everything *************** *** 90,96 **** OBJS=$(OBJ)\stunnel.obj $(OBJ)\ssl.obj $(OBJ)\ctx.obj $(OBJ)\verify.obj \ $(OBJ)\file.obj $(OBJ)\client.obj $(OBJ)\protocol.obj $(OBJ)\sthreads.obj \ $(OBJ)\log.obj $(OBJ)\options.obj $(OBJ)\network.obj \ ! $(OBJ)\resolver.obj $(OBJ)\str.obj $(OBJ)\fd.obj GUIOBJS=$(OBJ)\ui_win_gui.obj $(OBJ)\resources.res NOGUIOBJS=$(OBJ)\ui_win_cli.obj --- 116,122 ---- OBJS=$(OBJ)\stunnel.obj $(OBJ)\ssl.obj $(OBJ)\ctx.obj $(OBJ)\verify.obj \ $(OBJ)\file.obj $(OBJ)\client.obj $(OBJ)\protocol.obj $(OBJ)\sthreads.obj \ $(OBJ)\log.obj $(OBJ)\options.obj $(OBJ)\network.obj \ ! $(OBJ)\resolver.obj $(OBJ)\str.obj $(OBJ)\fd.obj $(OBJ)\mywcedefs.obj GUIOBJS=$(OBJ)\ui_win_gui.obj $(OBJ)\resources.res NOGUIOBJS=$(OBJ)\ui_win_cli.obj diff -cr orig/src/file.c patch2/src/file.c *** orig/src/file.c 2014-03-06 00:25:33.000000000 +0100 --- patch2/src/file.c 2014-06-12 09:21:45.875000000 +0200 *************** *** 49,65 **** /* open file */ switch(mode) { case FILE_MODE_READ: ! desired_access=FILE_READ_DATA; creation_disposition=OPEN_EXISTING; break; case FILE_MODE_APPEND: ! desired_access=FILE_APPEND_DATA; ! creation_disposition=OPEN_ALWAYS; break; case FILE_MODE_OVERWRITE: ! desired_access=FILE_WRITE_DATA; creation_disposition=CREATE_ALWAYS; ! break; default: /* invalid mode */ return NULL; } --- 49,66 ---- /* open file */ switch(mode) { case FILE_MODE_READ: ! desired_access=GENERIC_READ;/* pdelaage 20140610 WCE: good old flags supported on w32/WCE, while FILE_READ_DATA is FAILING on WCE; ! this FILE_READ_DATA flag PREVENTS read from various folders on WCE phones such as \stunnel\ or \Storage card\, or on WCE emulator \stunnel\.... where we find stunnel.conf file sometimes...*/ creation_disposition=OPEN_EXISTING; break; case FILE_MODE_APPEND: ! desired_access=GENERIC_WRITE; /* pdelaage 20140610: FILE_APPEND_DATA; back to old code W32/WCE compatible */ ! creation_disposition=OPEN_ALWAYS;/* pdelaage 20140610 : I disagree with OPEN_ALWAYS that creates the file if not existing. I suggest : OPEN_EXISTING */ break; case FILE_MODE_OVERWRITE: ! desired_access=GENERIC_WRITE; /* pdelaage 20140610:FILE_WRITE_DATA; back to old code W32/WCE compatible */ creation_disposition=CREATE_ALWAYS; ! break; default: /* invalid mode */ return NULL; } diff -cr orig/src/makew32.bat patch2/src/makew32.bat *** orig/src/makew32.bat 2010-11-17 21:20:14.000000000 +0100 --- patch2/src/makew32.bat 2014-06-09 15:49:25.546875000 +0200 *************** *** 2,7 **** --- 2,8 ---- TITLE W32 STUNNEL ::pdelaage 20101026: for use with MS VCexpress 2008 (v9) ::some trick to avoid re-pollution of env vars as much as possible + ::pdelaage 20140609: makew32 "UNICODESUPPORT=" to compile a UNICODE version :: In multitarget compilation environment, it is better to open a new cmd.exe window :: to avoid pollution of PATH from, eg, some previous WCE compilation attempts. Seulement dans patch2/src: mywcedefs.c Seulement dans patch2/src: mywcedefs.h diff -cr orig/src/protocol.c patch2/src/protocol.c *** orig/src/protocol.c 2014-04-13 13:15:21.000000000 +0200 --- patch2/src/protocol.c 2014-06-10 09:29:17.406250000 +0200 *************** *** 535,540 **** --- 535,542 ---- } str_free(line); longjmp(c->err, 2); /* don't reset */ + + return NULL; /* pdelaage 20140610 : just to avoid compilation warning on W32/WCE */ } /**************************************** nntp */ diff -cr orig/src/resolver.c patch2/src/resolver.c *** orig/src/resolver.c 2014-04-11 09:44:10.000000000 +0200 --- patch2/src/resolver.c 2014-06-09 15:57:21.406250000 +0200 *************** *** 92,98 **** #if defined(USE_WIN32) && !defined(_WIN32_WCE) HINSTANCE handle; ! handle=LoadLibrary("ws2_32.dll"); /* IPv6 in Windows XP or higher */ if(handle) { s_getaddrinfo=(GETADDRINFO)GetProcAddress(handle, "getaddrinfo"); s_freeaddrinfo=(FREEADDRINFO)GetProcAddress(handle, "freeaddrinfo"); --- 92,98 ---- #if defined(USE_WIN32) && !defined(_WIN32_WCE) HINSTANCE handle; ! handle=LoadLibrary(TEXT("ws2_32.dll")); /* IPv6 in Windows XP or higher *//* pdelaage 20140529...unicode ! */ if(handle) { s_getaddrinfo=(GETADDRINFO)GetProcAddress(handle, "getaddrinfo"); s_freeaddrinfo=(FREEADDRINFO)GetProcAddress(handle, "freeaddrinfo"); *************** *** 101,107 **** return; /* IPv6 detected -> OK */ FreeLibrary(handle); } ! handle=LoadLibrary("wship6.dll"); /* experimental IPv6 for Windows 2000 */ if(handle) { s_getaddrinfo=(GETADDRINFO)GetProcAddress(handle, "getaddrinfo"); s_freeaddrinfo=(FREEADDRINFO)GetProcAddress(handle, "freeaddrinfo"); --- 101,107 ---- return; /* IPv6 detected -> OK */ FreeLibrary(handle); } ! handle=LoadLibrary(TEXT("wship6.dll")); /* experimental IPv6 for Windows 2000 *//* pdelaage 20140609...unicode ! */ if(handle) { s_getaddrinfo=(GETADDRINFO)GetProcAddress(handle, "getaddrinfo"); s_freeaddrinfo=(FREEADDRINFO)GetProcAddress(handle, "freeaddrinfo"); diff -cr orig/src/resources.h patch2/src/resources.h *** orig/src/resources.h 2014-01-02 09:13:37.000000000 +0100 --- patch2/src/resources.h 2014-06-23 16:37:20.562500000 +0200 *************** *** 31,33 **** --- 31,35 ---- #define IDM_HOMEPAGE 52 #define IDM_PEER_MENU 60 + + #define IDS_SERVICE_DESC 70 /* pdelaage 20140623 : added description for Win32 Service Manager */ diff -cr orig/src/resources.rc patch2/src/resources.rc *** orig/src/resources.rc 2014-03-06 00:27:52.000000000 +0100 --- patch2/src/resources.rc 2014-06-23 16:39:47.156250000 +0200 *************** *** 45,60 **** MENUITEM SEPARATOR MENUITEM "&Close", IDM_CLOSE END POPUP "&Configuration" BEGIN MENUITEM "&Edit Configuration", IDM_EDIT_CONFIG MENUITEM "&Reload Configuration", IDM_RELOAD_CONFIG END POPUP "&Save Peer Certificate" BEGIN MENUITEM "dummy", 0, GRAYED END ! POPUP "&Help", HELP BEGIN MENUITEM "&About", IDM_ABOUT MENUITEM SEPARATOR --- 45,73 ---- MENUITEM SEPARATOR MENUITEM "&Close", IDM_CLOSE END + /* pdelaage 20140610: in WCE, this menu is too large for smart phones */ + #ifdef _WIN32_WCE + POPUP "&Config." + #else POPUP "&Configuration" + #endif BEGIN MENUITEM "&Edit Configuration", IDM_EDIT_CONFIG MENUITEM "&Reload Configuration", IDM_RELOAD_CONFIG END + /* pdelaage 20140610: in WCE, this menu is too large for smart phones */ + #ifdef _WIN32_WCE + POPUP "&Save Peer Certs." + #else POPUP "&Save Peer Certificate" + #endif + BEGIN MENUITEM "dummy", 0, GRAYED END ! /* pdelaage 20140610: in WCE, the HELP flag, although documented, is NOT SUPPORTED, use addornements instead ? */ ! /* pdelaage 20140610: in W32, the HELP flag is nowadays useless : with wide screens, it is painful to go the right end to get help */ ! POPUP "&?" /* pdelaage 20140610: both to fit space on WCE phones, and for "standard" look and feel on W32, ? replaces "Help" */ BEGIN MENUITEM "&About", IDM_ABOUT MENUITEM SEPARATOR *************** *** 89,94 **** --- 102,109 ---- ABOUTBOX DIALOG DISCARDABLE 0, 0, 140, 68 STYLE DS_MODALFRAME|DS_CENTER|WS_POPUP|WS_CAPTION|WS_SYSMENU CAPTION "About stunnel" + /* pdelaage 20140609 : no more ugly font a la windows 3.1...stunnel deserves to look more "smart" */ + FONT 8, "MS Sans Serif" BEGIN ICON IDI_STUNNEL_MAIN, -1, 9, 8, 18, 20 LTEXT "stunnel version", -1, 30, 4, 52, 8 *************** *** 103,108 **** --- 118,125 ---- PASSBOX DIALOG DISCARDABLE 0, 0, 158, 51 STYLE DS_MODALFRAME|DS_CENTER|WS_POPUP|WS_CAPTION|WS_SYSMENU CAPTION "" + /* pdelaage 20140609 : no more ugly font a la windows 3.1...stunnel deserves to look more "smart" */ + FONT 8, "MS Sans Serif" BEGIN ICON IDI_STUNNEL_MAIN, -1, 8, 6, 18, 20 LTEXT "Pass phrase:", -1, 33, 9, 50, 8 *************** *** 122,124 **** --- 139,145 ---- PUSHBUTTON "Cancel",IDCANCEL, 101, 30, 50, 14 END + STRINGTABLE + { + IDS_SERVICE_DESC "SSL encryption wrapper between local/remote clients and local/remote servers" + } diff -cr orig/src/ui_win_cli.c patch2/src/ui_win_cli.c *** orig/src/ui_win_cli.c 2014-03-26 18:13:01.000000000 +0100 --- patch2/src/ui_win_cli.c 2014-06-11 00:22:46.343750000 +0200 *************** *** 37,59 **** #include "common.h" #include "prototypes.h" int main(int argc, char *argv[]) { static struct WSAData wsa_state; ! char *c, stunnel_exe_path[MAX_PATH]; /* set current working directory and engine path */ GetModuleFileName(0, stunnel_exe_path, MAX_PATH); ! c=strrchr(stunnel_exe_path, '\\'); /* last backslash */ if(c) /* found */ ! c[1]='\0'; /* truncate program name */ #ifndef _WIN32_WCE if(!SetCurrentDirectory(stunnel_exe_path)) { ! fprintf(stderr, "Cannot set directory to %s", stunnel_exe_path); return 1; } #endif ! _putenv_s("OPENSSL_ENGINES", stunnel_exe_path); str_init(); /* initialize per-thread string management */ if(WSAStartup(MAKEWORD(1, 1), &wsa_state)) --- 37,67 ---- #include "common.h" #include "prototypes.h" + #ifdef _WIN32_WCE + #include "mywcedefs.h" /* pdelaage 20140610 for _tputenv_s */ + #endif int main(int argc, char *argv[]) { static struct WSAData wsa_state; ! TCHAR *c, stunnel_exe_path[MAX_PATH];/* pdelaage 20140609 UNICODE : TCHAR for both vars, because of GetModuleFileName */ /* set current working directory and engine path */ GetModuleFileName(0, stunnel_exe_path, MAX_PATH); ! c=_tcsrchr(stunnel_exe_path, TEXT('\\')); /* last backslash *//* pdelaage 20140526 UNICODE : strrchr replaced by _tcsrchr */ if(c) /* found */ ! c[1]=TEXT('\0'); /* truncate program name *//* pdelaage 20140526 UNICODE : strrchr replaced by _tcsrchr, because of SetCurrentDirectory and stunnel_exe_path */ #ifndef _WIN32_WCE if(!SetCurrentDirectory(stunnel_exe_path)) { ! #ifdef UNICODE /* pdelaage 20140526 QUESTION : shoud'nt we use s_log instead of fprintf ?? */ ! fprintf(stderr, "Cannot set directory to %ls", stunnel_exe_path);/* pdelaage 20140526 UNICODE format spec support */ ! #else ! fprintf(stderr, "Cannot set directory to %hs", stunnel_exe_path); ! #endif ! return 1; } #endif ! _tputenv_s(TEXT("OPENSSL_ENGINES"), stunnel_exe_path);/* pdelaage 20140526 UNICODE *//* pdelaage 20140610 : WCE implementation in mywcedefs.c */ str_init(); /* initialize per-thread string management */ if(WSAStartup(MAKEWORD(1, 1), &wsa_state)) *************** *** 107,114 **** /* log to Windows CE debug output stream */ LPTSTR tstr; ! tstr=str2tstr(line); ! RETAILMSG(TRUE, (TEXT("%s\r\n"), tstr)); str_free(tstr); #else fputs(line, stderr); --- 115,122 ---- /* log to Windows CE debug output stream */ LPTSTR tstr; ! tstr=str2tstr((LPSTR) line);/* pdelaage 20140610 : str2tstr strictly expects a "const LPSTR" */ ! RETAILMSG(TRUE, (TEXT("%s\r\n"), tstr)); str_free(tstr); #else fputs(line, stderr); diff -cr orig/src/ui_win_gui.c patch2/src/ui_win_gui.c *** orig/src/ui_win_gui.c 2014-05-12 08:31:13.000000000 +0200 --- patch2/src/ui_win_gui.c 2014-06-23 18:02:39.828125000 +0200 *************** *** 44,49 **** --- 44,61 ---- #endif #include "resources.h" + #ifdef _WIN32_WCE /* pdelaage 20140610 : some ports of win32 services to WCE, or some specific WCE services */ + #include "mywcedefs.h" + #endif + + #ifdef UNICODE /* pdelaage 20140623 : TSTR and TCAR ansi-printf format specs : YES ansi-printf can print Wchar strings ...*/ + #define TCAR_PRINTF_FORMAT "%lc" + #define TSTR_PRINTF_FORMAT "%ls" + #else + #define TCAR_PRINTF_FORMAT "%hc" + #define TSTR_PRINTF_FORMAT "%hs" + #endif + #define LOG_LINES 1000 #ifdef _WIN32_WCE *************** *** 54,60 **** #else /* MSDN claims that _WIN32 is always defined */ #define STUNNEL_PLATFORM "Win32" #endif ! #define SERVICE_NAME "stunnel" #endif /* mingw-Patches-1825044 is missing in Debian Squeeze */ --- 66,74 ---- #else /* MSDN claims that _WIN32 is always defined */ #define STUNNEL_PLATFORM "Win32" #endif ! ! #define SERVICE_NAME TEXT("stunnel") /* pdelaage 20140609 UNICODE */ ! #define SERVICE_DISPLAY_NAME TEXT("Stunnel SSL wrapper") /* pdelaage 20140623: Nicer name to be displayed in Service Control Manager */ #endif /* mingw-Patches-1825044 is missing in Debian Squeeze */ *************** *** 89,95 **** /* NT Service related function */ #ifndef _WIN32_WCE NOEXPORT int service_initialize(void); ! NOEXPORT int service_install(LPTSTR); NOEXPORT int service_uninstall(void); NOEXPORT int service_start(void); NOEXPORT int service_stop(void); --- 103,110 ---- /* NT Service related function */ #ifndef _WIN32_WCE NOEXPORT int service_initialize(void); ! /* pdelaage 20140609 : wrong prototype, the DEFINITION code further in that file is with LPSTR only, not lpTstr...static int service_install(LPTSTR); */ ! NOEXPORT int service_install(LPSTR); NOEXPORT int service_uninstall(void); NOEXPORT int service_start(void); NOEXPORT int service_stop(void); *************** *** 126,132 **** static SERVICE_STATUS_HANDLE serviceStatusHandle=0; #endif ! static volatile int visible=0; static volatile int error_mode=1; /* no valid configuration was ever loaded */ static HANDLE config_ready=NULL; /* reload without a valid configuration */ static LONG new_logs=0; --- 141,148 ---- static SERVICE_STATUS_HANDLE serviceStatusHandle=0; #endif ! /* pdelaage 20140610: now visible is more appropriately a BOOL, as stated by MSDN */ ! static volatile BOOL visible = FALSE;/* int visible=0; */ static volatile int error_mode=1; /* no valid configuration was ever loaded */ static HANDLE config_ready=NULL; /* reload without a valid configuration */ static LONG new_logs=0; *************** *** 149,155 **** #endif int nCmdShow) { LPSTR command_line; ! char *c, stunnel_exe_path[MAX_PATH]; #ifndef _WIN32_WCE char *errmsg; #endif --- 165,172 ---- #endif int nCmdShow) { LPSTR command_line; ! /* 20140609 pdelaage char *c, stunnel_exe_path[MAX_PATH]; */ ! TCHAR *c, stunnel_exe_path[MAX_PATH];/* 20140609 pdelaage : UNICODE support for GetModuleFileName on W32/WCE */ #ifndef _WIN32_WCE char *errmsg; #endif *************** *** 160,197 **** str_init(); /* initialize per-thread string management */ ghInst=this_instance; #ifdef _WIN32_WCE ! command_line=tstr2str(lpCmdLine); #else ! command_line=lpCmdLine; #endif parse_cmdline(command_line); /* setup global cmdline structure */ ! GetModuleFileName(0, stunnel_exe_path, MAX_PATH); #ifndef _WIN32_WCE /* find previous instances of the same executable */ if(!cmdline.service && !cmdline.install && !cmdline.uninstall && !cmdline.start && !cmdline.stop) { ! EnumWindows(enum_windows, (LPARAM)stunnel_exe_path); if(cmdline.exit) return 0; /* in case EnumWindows didn't find a previous instance */ } #endif /* set current working directory and engine path */ ! c=strrchr(stunnel_exe_path, '\\'); /* last backslash */ if(c) /* found */ ! c[1]='\0'; /* truncate program name */ #ifndef _WIN32_WCE if(!SetCurrentDirectory(stunnel_exe_path)) { ! errmsg=str_printf("Cannot set directory to %s", stunnel_exe_path); message_box(errmsg, MB_ICONERROR); str_free(errmsg); return 1; } #endif ! _putenv_s("OPENSSL_ENGINES", stunnel_exe_path); if(initialize_winsock()) return 1; --- 177,215 ---- str_init(); /* initialize per-thread string management */ ghInst=this_instance; #ifdef _WIN32_WCE ! command_line=wstr2str(lpCmdLine);/* pdelaage 20140610 : on WCE, even in <> compilation mode that is ALSO possible on WCE, lpCmdline is ALWAYS WCHAR, so that WCE ALWAYS need a WCHAR to STR conversion, but in ANSI mode tstr2str INAPPROPRIATELY here expects a char* so that we need another conversion function : see extra source in mywcedefs.c */ #else ! command_line=lpCmdLine; /* pdelaage 20140610, on win32 lpcmdline is always ANSI string...for the moment.*/ #endif parse_cmdline(command_line); /* setup global cmdline structure */ ! GetModuleFileName(0, stunnel_exe_path, MAX_PATH);/* 20140609 pdelaage : requires UNICODE strings */ #ifndef _WIN32_WCE /* find previous instances of the same executable */ if(!cmdline.service && !cmdline.install && !cmdline.uninstall && !cmdline.start && !cmdline.stop) { ! EnumWindows(enum_windows, (LPARAM)stunnel_exe_path);/* 20140609 pdelaage : BE CAREFUL that enum_windows will CORRECTLY CAST to UNICODE ! done by my contribution there ...*/ if(cmdline.exit) return 0; /* in case EnumWindows didn't find a previous instance */ } #endif /* set current working directory and engine path */ ! c=_tcsrchr(stunnel_exe_path, TEXT('\\')); /* last backslash *//* pdelaage 20140609 unicode */ if(c) /* found */ ! c[1]=TEXT('\0'); /* truncate program name */ #ifndef _WIN32_WCE if(!SetCurrentDirectory(stunnel_exe_path)) { ! /* pdelaage 20140609 : UNICODE in printf format spec */ ! errmsg=str_printf("Cannot set directory to "TSTR_PRINTF_FORMAT, stunnel_exe_path); message_box(errmsg, MB_ICONERROR); str_free(errmsg); return 1; } #endif ! _tputenv_s(TEXT("OPENSSL_ENGINES"), stunnel_exe_path);/* pdelaage 20140609 : UNICODE */ if(initialize_winsock()) return 1; *************** *** 216,224 **** NOEXPORT BOOL CALLBACK enum_windows(HWND other_window_handle, LPARAM lParam) { DWORD pid; HINSTANCE hInstance; ! char window_exe_path[MAX_PATH]; HANDLE process_handle; ! char *stunnel_exe_path=(char *)lParam; if(!other_window_handle) return TRUE; --- 234,242 ---- NOEXPORT BOOL CALLBACK enum_windows(HWND other_window_handle, LPARAM lParam) { DWORD pid; HINSTANCE hInstance; ! TCHAR window_exe_path[MAX_PATH];/* pdelaage 20140609 UNICODE */ HANDLE process_handle; ! TCHAR *stunnel_exe_path=(TCHAR *)lParam;/* pdelaage 20140529 UNICODE */ if(!other_window_handle) return TRUE; *************** *** 235,241 **** CloseHandle(process_handle); return TRUE; } ! if(strcmp(stunnel_exe_path, window_exe_path)) { CloseHandle(process_handle); return TRUE; } --- 253,259 ---- CloseHandle(process_handle); return TRUE; } ! if(_tcscmp(stunnel_exe_path, window_exe_path)) { /* pdelaage 20140529 UNICODE */ CloseHandle(process_handle); return TRUE; } *************** *** 315,320 **** --- 333,341 ---- MSG msg; LPTSTR classname=TEXT("stunnel_main_window_class"); + /* Ensure commctrl.dll is loaded *//* pdelaage 20140621 addition, needed -eg- for WCE commandbars ... */ + InitCommonControls(); /* pdelaage 20140621 : Good practice before using common controls, both for WCE and W32 */ + /* register the class */ #ifndef _WIN32_WCE wc.cbSize=sizeof wc; *************** *** 383,389 **** s_log(LOG_DEBUG, "Window message: %d", message); #endif switch(message) { ! case WM_CREATE: #ifdef _WIN32_WCE /* create command bar */ command_bar_handle=CommandBar_Create(ghInst, main_window_handle, 1); --- 404,410 ---- s_log(LOG_DEBUG, "Window message: %d", message); #endif switch(message) { ! case WM_CREATE: #ifdef _WIN32_WCE /* create command bar */ command_bar_handle=CommandBar_Create(ghInst, main_window_handle, 1); *************** *** 396,404 **** #endif /* create child edit window */ ! edit_handle=CreateWindow(TEXT("EDIT"), NULL, ! WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|ES_MULTILINE|ES_READONLY, ! 0, 0, 0, 0, main_window_handle, (HMENU)IDE_EDIT, ghInst, NULL); #ifndef _WIN32_WCE SendMessage(edit_handle, WM_SETFONT, (WPARAM)CreateFont(-12, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, --- 417,426 ---- #endif /* create child edit window */ ! edit_handle=CreateWindowEx(WS_EX_STATICEDGE, /* pdelaage 20140610 : for better look and feel, 3D edges to separate from menubar...over Win31 flat style */ ! TEXT("EDIT"), NULL, ! WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|ES_MULTILINE|ES_READONLY, ! 0, 0, 0, 0, main_window_handle, (HMENU)IDE_EDIT, ghInst, NULL); #ifndef _WIN32_WCE SendMessage(edit_handle, WM_SETFONT, (WPARAM)CreateFont(-12, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, *************** *** 413,424 **** #ifdef _WIN32_WCE MoveWindow(edit_handle, 0, CommandBar_Height(command_bar_handle), rect.right, rect.bottom-CommandBar_Height(command_bar_handle), TRUE); #else MoveWindow(edit_handle, 0, 0, rect.right, rect.bottom, TRUE); #endif UpdateWindow(edit_handle); /* CommandBar_Show(command_bar_handle, TRUE); */ ! return TRUE; case WM_SETFOCUS: SetFocus(edit_handle); --- 435,451 ---- #ifdef _WIN32_WCE MoveWindow(edit_handle, 0, CommandBar_Height(command_bar_handle), rect.right, rect.bottom-CommandBar_Height(command_bar_handle), TRUE); + + /* pdelaage 20140610 WCE : dixit MSDN, and indeed, commandbars do not resize automatically unless providing this code, necessary on "sliding-keyboard" OR "auto-rotating screen orientation" smart phones when switching from portrait to landscape display and vice/versa */ + SendMessage(command_bar_handle, TB_AUTOSIZE, 0L, 0L); + CommandBar_AlignAdornments(command_bar_handle);/* pdelaage 20140610 WCE: MSDN says we have to repeat this for auto-repositioning of Help btn */ + #else MoveWindow(edit_handle, 0, 0, rect.right, rect.bottom, TRUE); #endif UpdateWindow(edit_handle); /* CommandBar_Show(command_bar_handle, TRUE); */ ! return TRUE;/* pdelaage 20140621, TODO: both for W32 and WCE, this should be "return 0", not "TRUE"... dixit MSDN. Same remark for most of the msg processing here */ case WM_SETFOCUS: SetFocus(edit_handle); *************** *** 433,446 **** ShowWindow(main_window_handle, SW_HIDE); return TRUE; ! case WM_SHOWWINDOW: ! visible=wParam; /* setup global variable */ if(tray_menu_handle) CheckMenuItem(tray_menu_handle, IDM_SHOW_LOG, visible ? MF_CHECKED : MF_UNCHECKED); if(visible) ! update_logs(); ! return TRUE; case WM_DESTROY: #ifdef _WIN32_WCE --- 460,478 ---- ShowWindow(main_window_handle, SW_HIDE); return TRUE; ! /* pdelaage 20140610: I made "visible" a real BOOL, as defined by MSDN doc on WM_SHOWWINDOW...instead of an int between 0 and 1...*/ ! /* case WM_SHOWWINDOW: ! visible= (BOOL) wParam; *//* setup global variable ! */ ! /* pdelaage 20140610: WM_SHOWWINDOW does NOT exist on WCE, so replaced by WM_WINDOWPOSCHANGED W32/WCE compatible */ ! case WM_WINDOWPOSCHANGED : ! visible = IsWindowVisible(main_window_handle);/* setup global variable *//* pdelaage 20140610: more reliable than msg content */ if(tray_menu_handle) CheckMenuItem(tray_menu_handle, IDM_SHOW_LOG, visible ? MF_CHECKED : MF_UNCHECKED); if(visible) ! update_logs(); ! break;/* return TRUE;*//* pdelaage 20140610: WM_WINDOWPOSCHANGED MUST go to DefProc to properly refresh window appearance (WM_SIZE/WM_MOVE)*/ case WM_DESTROY: #ifdef _WIN32_WCE *************** *** 895,901 **** HMENU tray_peer_list=NULL; char *str; unsigned int section_number; ! MENUITEMINFO mii; /* purge menu peer lists */ #ifndef _WIN32_WCE --- 927,934 ---- HMENU tray_peer_list=NULL; char *str; unsigned int section_number; ! ! /* 20140610 pdelaage unsupported on WCE, useless with common code in W32 (and thus generates a compilation warning) : MENUITEMINFO mii; */ /* purge menu peer lists */ #ifndef _WIN32_WCE *************** *** 908,915 **** if(tray_menu_handle) tray_peer_list=GetSubMenu(GetSubMenu(tray_menu_handle, 0), 2); if(tray_peer_list) ! while(GetMenuItemCount(tray_peer_list)) /* purge old menu */ ! DeleteMenu(tray_peer_list, 0, MF_BYPOSITION); /* initialize data structures */ number_of_sections=0; --- 941,948 ---- if(tray_menu_handle) tray_peer_list=GetSubMenu(GetSubMenu(tray_menu_handle, 0), 2); if(tray_peer_list) ! /* pdelaage 20140610 : W32/WCE trick because GetMenuItemCount does not exist on WCE */ ! while (DeleteMenu(tray_peer_list, 0, MF_BYPOSITION) == TRUE) {;}; /* purge old menu */ /* initialize data structures */ number_of_sections=0; *************** *** 942,947 **** --- 975,981 ---- section->chain=NULL; /* insert new menu item */ + /* pdelaage 20140610 : this code is not supported by WCE, and the same can be achieved by a SHORTER common code for W32/WCE mii.cbSize=sizeof mii; mii.fMask=MIIM_STRING|MIIM_DATA|MIIM_ID|MIIM_STATE; mii.fType=MFT_STRING; *************** *** 957,962 **** --- 991,1007 ---- if(tray_peer_list) if(!InsertMenuItem(tray_peer_list, section_number, TRUE, &mii)) ioerror("InsertMenuItem"); + */ + /* pdelaage 20140610, W32/WCE short COMMON code to create menuitems */ + #ifndef _WIN32_WCE + if(main_peer_list) + if(InsertMenu(main_peer_list, section_number, MF_BYPOSITION | MF_STRING | MF_GRAYED, IDM_PEER_MENU+section_number, section->file) == 0) + ioerror("InsertMenu"); + #endif + if(tray_peer_list) + if(InsertMenu(tray_peer_list, section_number, MF_BYPOSITION | MF_STRING | MF_GRAYED, IDM_PEER_MENU+section_number, section->file) == 0) + ioerror("InsertMenu"); + ++section_number; } if(hwnd) *************** *** 986,995 **** ICON_IMAGE load_icon_file(const char *name) { LPTSTR tname; ICON_IMAGE icon; ! tname=str2tstr((LPSTR)name); icon=LoadImage(NULL, tname, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_LOADFROMFILE); str_free(tname); return icon; } --- 1031,1044 ---- ICON_IMAGE load_icon_file(const char *name) { LPTSTR tname; ICON_IMAGE icon; ! tname=str2tstr((LPSTR)name); + #ifdef _WIN32_WCE /* pdelaage 20140610 : LR_LOADFROMFILE unsupported in WCE, cannot be replaced by SHLoadDIBitmap in this context, but... */ + icon=wceLoadIconFromFile(tname);/* pdelaage 20140610 : ...with some standard W32 coding, an equivalent to loadimage for BMP files (not ICO) is possible, for WCE...working also for W32 if needed */ + #else icon=LoadImage(NULL, tname, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_LOADFROMFILE); + #endif str_free(tname); return icon; } *************** *** 998,1003 **** --- 1047,1054 ---- NOTIFYICONDATA nid; static ICON_TYPE previous_icon=ICON_NONE; ICON_TYPE current_icon; + HICON prevIcon_l = (HICON) NULL; /* pdelaage 20140610 WCE */ + BOOL retval_l = FALSE; /* pdelaage 20140610 WCE */ if(!global_options.option.taskbar) { /* save menu resources */ if(tray_menu_handle) { /* disabled in the new configuration */ *************** *** 1018,1024 **** nid.uCallbackMessage=WM_SYSTRAY; /* notification message */ nid.hWnd=hwnd; /* window to receive notifications */ if(num<0) { ! _stprintf(nid.szTip, TEXT("Server is down")); current_icon=ICON_ERROR; } else if(num>0) { _stprintf(nid.szTip, TEXT("%d active session(s)"), num); --- 1069,1075 ---- nid.uCallbackMessage=WM_SYSTRAY; /* notification message */ nid.hWnd=hwnd; /* window to receive notifications */ if(num<0) { ! _stprintf(nid.szTip, TEXT("Server is down"));/* pdelaage 20140621 : Be careful that on WCE, szTip is ALWAYS WCHAR. Anyway ANSI version of stunnel for WCE, although possible with some port effort, is of no practical interest since UNICODE covers ANSI... */ current_icon=ICON_ERROR; } else if(num>0) { _stprintf(nid.szTip, TEXT("%d active session(s)"), num); *************** *** 1029,1038 **** } nid.hIcon=global_options.icon[current_icon]; if(current_icon!=previous_icon) { ! nid.uFlags|=NIF_ICON; ! previous_icon=current_icon; ! } ! if(Shell_NotifyIcon(NIM_MODIFY, &nid)) /* modify tooltip */ return; /* OK: taskbar icon exists */ /* tooltip update failed - try to create the icon */ nid.uFlags|=NIF_ICON; --- 1080,1097 ---- } nid.hIcon=global_options.icon[current_icon]; if(current_icon!=previous_icon) { ! #ifdef _WIN32_WCE /* pdelaage 20140610 : on WCE, the replaced Icon will be DELETED and LOST from the system resources, so that we have to duplicate it before losing it, and in the objective to restore it later. */ ! if (previous_icon != ICON_NONE) ! { ! prevIcon_l = global_options.icon[previous_icon]; ! global_options.icon[previous_icon] = DuplicateIcon((HINSTANCE) NULL, prevIcon_l); ! DestroyIcon(prevIcon_l);/* pdelaage 20140610: ok, the WCE system will do that, but it is better to do it explicitely, either if one day WCE doesn't do it anymore AND/OR if this code is reused in W32: something absolutely possible ...*/ ! } ! #endif ! nid.uFlags|=NIF_ICON; ! previous_icon=current_icon; ! } ! if(Shell_NotifyIcon(NIM_MODIFY, &nid)) /* modify tooltip */ return; /* OK: taskbar icon exists */ /* tooltip update failed - try to create the icon */ nid.uFlags|=NIF_ICON; *************** *** 1083,1110 **** } NOEXPORT void edit_config(HWND main_window_handle) { ! char cwd[MAX_PATH], *conf_path; ! /* TODO: port it to WCE */ if(is_admin()) { ! ShellExecute(main_window_handle, TEXT("open"), ! TEXT("notepad.exe"), configuration_file, NULL, SW_SHOWNORMAL); } else { /* UAC workaround */ if(strchr(configuration_file, '\\')) { conf_path=str_dup(configuration_file); } else { ! GetCurrentDirectory(MAX_PATH, cwd); ! conf_path=str_printf("%s\\%s", cwd, configuration_file); } ShellExecute(main_window_handle, TEXT("runas"), ! TEXT("notepad.exe"), conf_path, ! NULL, SW_SHOWNORMAL); str_free(conf_path); } } NOEXPORT BOOL is_admin(void) { SID_IDENTIFIER_AUTHORITY NtAuthority={SECURITY_NT_AUTHORITY}; PSID admin_group; BOOL retval; --- 1142,1186 ---- } NOEXPORT void edit_config(HWND main_window_handle) { ! TCHAR cwd[MAX_PATH];/* pdelaage 20140609 : unicode because of GetCurrentDirectory */ ! char *conf_path; ! TCHAR *conf_string; /* pdelaage 20140609 : needed for UNICODE ShellExecute, because "configuration_file" is JUST ASCII !! */ ! /* TODO: port it to WCE */ + /* pdelaage 20140610 : DONE ! for ShellExecute in mywcedefs.c */ if(is_admin()) { ! conf_string = str2tstr(configuration_file); ! ! ShellExecute(main_window_handle, TEXT("open"), /* pdelaage 20140610 : reimplemenred for WCE, see mywcedefs.c */ ! TEXT("notepad.exe"), conf_string,/* pdelaage 20140609 : now UNICODE correct */ ! /* pdelaage 20140610 : TODO : notepad is NOT available on CE, we have to find/suggest a free replacement: some exist. */ NULL, SW_SHOWNORMAL); + + str_free(conf_string); + } else { /* UAC workaround */ if(strchr(configuration_file, '\\')) { conf_path=str_dup(configuration_file); } else { ! GetCurrentDirectory(MAX_PATH, cwd);/* pdelaage 20140610 : reimplemenred for WCE, see mywcedefs.c */ ! /* pdelaage 20140621 : UNICODE in printf format spec */ ! conf_path=str_printf(TSTR_PRINTF_FORMAT"\\%s", cwd, configuration_file); } + + conf_string = str2tstr(conf_path); + ShellExecute(main_window_handle, TEXT("runas"), ! TEXT("notepad.exe"), conf_string, /* pdelaage 20140609 : now UNICODE correct */ ! /* pdelaage 20140610 : TODO : notepad is NOT available on CE, we have to find/suggest a free replacement: some exist. */ ! NULL, SW_SHOWNORMAL); ! ! str_free(conf_string); str_free(conf_path); } } NOEXPORT BOOL is_admin(void) { + #ifndef _WIN32_WCE SID_IDENTIFIER_AUTHORITY NtAuthority={SECURITY_NT_AUTHORITY}; PSID admin_group; BOOL retval; *************** *** 1118,1123 **** --- 1194,1202 ---- FreeSid(admin_group); } return retval; + #else + return TRUE; /* pdelaage 20140610 :on WCE, user is always admin */ + #endif } /**************************************** windows service */ *************** *** 1127,1133 **** NOEXPORT int service_initialize(void) { SERVICE_TABLE_ENTRY serviceTable[]={{0, 0}, {0, 0}}; ! serviceTable[0].lpServiceName=SERVICE_NAME; serviceTable[0].lpServiceProc=service_main; global_options.option.taskbar=0; /* disable taskbar for security */ if(!StartServiceCtrlDispatcher(serviceTable)) { --- 1206,1212 ---- NOEXPORT int service_initialize(void) { SERVICE_TABLE_ENTRY serviceTable[]={{0, 0}, {0, 0}}; ! serviceTable[0].lpServiceName=SERVICE_NAME;/* pdelaage 20140525 : UNICODE */ serviceTable[0].lpServiceProc=service_main; global_options.option.taskbar=0; /* disable taskbar for security */ if(!StartServiceCtrlDispatcher(serviceTable)) { *************** *** 1139,1163 **** NOEXPORT int service_install(LPSTR command_line) { SC_HANDLE scm, service; ! char stunnel_exe_path[MAX_PATH], *service_path; ! scm=OpenSCManager(0, 0, SC_MANAGER_CREATE_SERVICE); if(!scm) { error_box("OpenSCManager"); return 1; } GetModuleFileName(0, stunnel_exe_path, MAX_PATH); ! service_path=str_printf("\"%s\" -service %s", stunnel_exe_path, command_line); ! service=CreateService(scm, SERVICE_NAME, SERVICE_NAME, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS|SERVICE_INTERACTIVE_PROCESS, ! SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, service_path, NULL, NULL, NULL, NULL, NULL); str_free(service_path); if(!service) { error_box("CreateService"); CloseServiceHandle(scm); return 1; } message_box("Service installed", MB_ICONINFORMATION); CloseServiceHandle(service); CloseServiceHandle(scm); --- 1218,1260 ---- NOEXPORT int service_install(LPSTR command_line) { SC_HANDLE scm, service; ! TCHAR stunnel_exe_path[MAX_PATH], *tservice_path;/* pdelaage 20140609: UNICODE for GetModuleFileName, CreateService */ ! char *service_path; ! ! TCHAR service_description_string[256];/* pdelaage 20140621: Added service description for Services Manager */ ! SERVICE_DESCRIPTION service_description; ! scm=OpenSCManager(0, 0, SC_MANAGER_CREATE_SERVICE); if(!scm) { error_box("OpenSCManager"); return 1; } GetModuleFileName(0, stunnel_exe_path, MAX_PATH); ! /* pdelaage 20140609 : we CAN mix TCHAR* and char* in printf...provided we use the proper h or l FORMAT SPEC */ ! service_path=str_printf("\""TSTR_PRINTF_FORMAT"\" -service %hs", stunnel_exe_path, command_line); ! ! tservice_path = str2tstr(service_path); ! ! service=CreateService(scm, SERVICE_NAME, SERVICE_DISPLAY_NAME, /* pdelaage 20140623: Added service display-name for Service Manager */ ! SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS|SERVICE_INTERACTIVE_PROCESS, ! SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, tservice_path, NULL, NULL, NULL, NULL, NULL); + str_free(tservice_path); str_free(service_path); if(!service) { error_box("CreateService"); CloseServiceHandle(scm); return 1; } + + /* pdelaage 20140623 : set more explicit description for the service, in Windows Service Control Manager */ + if (LoadString(ghInst, IDS_SERVICE_DESC, service_description_string, sizeof(service_description_string))) + { + service_description.lpDescription = service_description_string; + ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &service_description); + } + message_box("Service installed", MB_ICONINFORMATION); CloseServiceHandle(service); CloseServiceHandle(scm); diff -cr orig/src/vc.mak patch2/src/vc.mak *** orig/src/vc.mak 2014-06-09 01:15:37.000000000 +0200 --- patch2/src/vc.mak 2014-06-21 17:54:40.734375000 +0200 *************** *** 1,6 **** --- 1,12 ---- # vc.mak by Michal Trojnara 1998-2014 # with help of David Gillingham # with help of Pierre Delaage + # pdelaage 20140609 : added UNICODE optional FLAG + # pdelaage 20140609 : added WX (fails on warning) flag to detect subtle error prone cast + # pdelaage 20140609 : added _CRT_NON_CONFORMING_SWPRINTFS to explicitely support old fashioned stprintf in ui_win_gui.c + # pdelaage 20140610 : BUG FIX : no clean working because of a typo in GUIOBJS and NOGUIOBJS names in clean rule + # pdelaage 20140610 : BUG FIX : no clean working because of a typo in SHAREOBJS list ($(OBJ)/fd.obj instead of xx\xx) + # pdelaage 20140610 : Explicit link to comctl32.lib for InitCommonControls call # the compilation requires: # - Visual C++ 2005 Express Edition with Platform SDK *************** *** 8,13 **** --- 14,21 ---- # - Visual C++ 2005 Professional Edition # - Visual C++ 2008 Express Edition + + !IF [ml64.exe /help >NUL 2>&1] TARGET=win32 !ELSE *************** *** 24,30 **** #FIPSDIR=$(SSLDIR)\include #LIBDIR=$(SSLDIR)\lib # or compile one yourself ! SSLDIR=..\..\openssl-1.0.1h-$(TARGET) INCDIR=$(SSLDIR)\inc32 FIPSDIR=$(SSLDIR)\inc32 LIBDIR=$(SSLDIR)\out32dll --- 32,39 ---- #FIPSDIR=$(SSLDIR)\include #LIBDIR=$(SSLDIR)\lib # or compile one yourself ! # pdelaage 20140609 SSLDIR=..\..\openssl-1.0.1h-$(TARGET) ! SSLDIR=C:\Users\pdelaage\Dvts\Contrib\openssl\v1.0.2-stable-SNAP-20121213\patch1 INCDIR=$(SSLDIR)\inc32 FIPSDIR=$(SSLDIR)\inc32 LIBDIR=$(SSLDIR)\out32dll *************** *** 44,61 **** $(OBJ)\verify.obj $(OBJ)\file.obj $(OBJ)\client.obj \ $(OBJ)\protocol.obj $(OBJ)\sthreads.obj $(OBJ)\log.obj \ $(OBJ)\options.obj $(OBJ)\network.obj $(OBJ)\resolver.obj \ ! $(OBJ)\str.obj $(OBJ)/fd.obj GUIOBJS=$(OBJ)\ui_win_gui.obj $(OBJ)\resources.res NOGUIOBJS=$(OBJ)\ui_win_cli.obj CC=cl LINK=link ! CFLAGS=/MD /W3 /O2 /nologo /I"$(INCDIR)" /I"$(FIPSDIR)" LDFLAGS=/NOLOGO SHAREDLIBS=ws2_32.lib user32.lib shell32.lib ! GUILIBS=advapi32.lib comdlg32.lib crypt32.lib gdi32.lib psapi.lib NOGUILIBS= SSLLIBS=/LIBPATH:"$(LIBDIR)" libeay32.lib ssleay32.lib # static linking: --- 53,79 ---- $(OBJ)\verify.obj $(OBJ)\file.obj $(OBJ)\client.obj \ $(OBJ)\protocol.obj $(OBJ)\sthreads.obj $(OBJ)\log.obj \ $(OBJ)\options.obj $(OBJ)\network.obj $(OBJ)\resolver.obj \ ! $(OBJ)\str.obj $(OBJ)\fd.obj GUIOBJS=$(OBJ)\ui_win_gui.obj $(OBJ)\resources.res NOGUIOBJS=$(OBJ)\ui_win_cli.obj CC=cl LINK=link ! # pdelaage 20140529 added unicode flag : because w32 unicode version helps to debug...W32/WCE ansi/unicode version... ! !ifdef UNICODESUPPORT ! UNICODEFLAGS=/DUNICODE -D_UNICODE ! !else ! UNICODEFLAGS= ! !endif ! ! # pdelaage 20140609 WX warning as error to detect subtle cast problems in ansi/unicode management. ! MORECFLAGS=/WX $(UNICODEFLAGS) /D_CRT_NON_CONFORMING_SWPRINTFS ! CFLAGS=/MD /W3 /O2 /nologo $(MORECFLAGS) /I"$(INCDIR)" /I"$(FIPSDIR)" LDFLAGS=/NOLOGO SHAREDLIBS=ws2_32.lib user32.lib shell32.lib ! GUILIBS=advapi32.lib comctl32.lib comdlg32.lib crypt32.lib gdi32.lib psapi.lib NOGUILIBS= SSLLIBS=/LIBPATH:"$(LIBDIR)" libeay32.lib ssleay32.lib # static linking: *************** *** 73,80 **** clean: -@ del $(SHAREDOBJS) >NUL 2>&1 ! -@ del $(GUIBJS) >NUL 2>&1 ! -@ del $(NOGUIBJS) >NUL 2>&1 # -@ del *.manifest >NUL 2>&1 -@ del $(BIN)\stunnel.exe >NUL 2>&1 -@ del $(BIN)\stunnel.exe.manifest >NUL 2>&1 --- 91,98 ---- clean: -@ del $(SHAREDOBJS) >NUL 2>&1 ! -@ del $(GUIOBJS) >NUL 2>&1 ! -@ del $(NOGUIOBJS) >NUL 2>&1 # -@ del *.manifest >NUL 2>&1 -@ del $(BIN)\stunnel.exe >NUL 2>&1 -@ del $(BIN)\stunnel.exe.manifest >NUL 2>&1