From e5f16b777a063c4d1dee88998b1a3cbca040dbee Mon Sep 17 00:00:00 2001 From: codemastr Date: Sun, 30 May 2004 00:59:05 +0000 Subject: [PATCH] Made the win32 version use a dynamically linked libc --- Changes | 6 ++++++ include/common.h | 1 - include/h.h | 5 +++++ include/inet.h | 2 +- include/sys.h | 2 +- include/win32/setup.h | 1 - makefile.win32 | 12 ++++++------ src/modules.c | 2 +- src/res.c | 2 +- src/s_bsd.c | 26 +++++++++++++------------- src/s_debug.c | 6 +----- src/send.c | 2 +- src/socket.c | 6 +----- src/ssl.c | 2 +- src/support.c | 34 +++++++++++++++++++--------------- src/url.c | 2 +- src/win32/unrealinst.iss | 33 +++++++++++++++++++++++++++------ wircd.def | 1 - 18 files changed, 85 insertions(+), 60 deletions(-) diff --git a/Changes b/Changes index 689ff7e52..eb5958689 100644 --- a/Changes +++ b/Changes @@ -3208,3 +3208,9 @@ This is the 3.2 fixes branch. - Imported TRE 0.6.8 for *nix - Added NICKIP to doc/technical/protoctl.txt - Imported TRE 0.6.8 for windows +- Redid the win32 version to use a dynamically linked libc. This solves memory issues + arising from the fact that dlls do not share the same heap as the exe. As a side effect, + however, there is now a dependency on msvcr70d.dll. This DLL does not come with any + versions of Windows except 2003. It also comes with any .NET application and the .NET + framework. Unreal will automatically download th DLL if it is needed. Reported by Bugz + (#0001833) diff --git a/include/common.h b/include/common.h index 2f5c4f2a7..fcd5857c2 100644 --- a/include/common.h +++ b/include/common.h @@ -331,7 +331,6 @@ extern struct SLink *find_user_link( /* struct SLink *, struct Client * */ ); * Windows' internal strerror() function doesn't work with socket errors. */ extern int DisplayString(HWND hWnd, char *InBuf, ...); -#undef strerror #else typedef int SOCKET; #define INVALID_SOCKET -1 diff --git a/include/h.h b/include/h.h index 971477ec5..19c7b6a52 100644 --- a/include/h.h +++ b/include/h.h @@ -25,6 +25,7 @@ * Most of the externs and prototypes thrown in here to 'cleanup' things. * -avalon */ +#include "setup.h" #ifndef NO_FDLIST #include "fdlist.h" #endif @@ -208,7 +209,11 @@ extern void reset_help(); extern MODVAR char *debugmode, *configfile, *sbrk0; extern char *getfield(char *); extern void get_sockhost(aClient *, char *); +#ifndef _WIN32 extern char *strerror(int); +#else +extern char *sock_strerror(int); +#endif extern int dgets(int, char *, int); extern char *inetntoa(char *); diff --git a/include/inet.h b/include/inet.h index 38f5cd9c8..21f593172 100644 --- a/include/inet.h +++ b/include/inet.h @@ -31,7 +31,7 @@ #endif extern int inet_pton(int af, const char *src, void *dst); -extern const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt); +extern const char *inet_ntop(int af, const void *src, char *dst, size_t cnt); #ifdef __STDC__ # ifndef _WIN32 diff --git a/include/sys.h b/include/sys.h index 86025bf3c..1ee43d5d1 100644 --- a/include/sys.h +++ b/include/sys.h @@ -234,7 +234,7 @@ static const struct in6_addr in6addr_any = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, #define CLOSE_SOCK(fd) closesocket(fd) #define IOCTL(x, y, z) ioctlsocket((x), (y), (z)) #define ERRNO WSAGetLastError() -#define STRERROR(x) nt_strerror(x) +#define STRERROR(x) sock_strerror(x) #define SET_ERRNO(x) WSASetLastError(x) /* Error constant portability */ #define P_EMFILE WSAEMFILE diff --git a/include/win32/setup.h b/include/win32/setup.h index 8360e5ad3..75b9e54db 100644 --- a/include/win32/setup.h +++ b/include/win32/setup.h @@ -30,7 +30,6 @@ #undef SYSSYSLOGH #define NOINDEX #define NOBCOPY -#define NEED_STRERROR #define NEED_STRTOKEN #undef NEED_STRTOK #undef NEED_INET_ADDR diff --git a/makefile.win32 b/makefile.win32 index ec23c62e3..bf5ad1d1e 100644 --- a/makefile.win32 +++ b/makefile.win32 @@ -101,21 +101,21 @@ OPENSSL_LIB=/LIBPATH:"$(OPENSSL_LIB_DIR)" !ENDIF !IFDEF DEBUG -DBGCFLAG=/MTd /Zi +DBGCFLAG=/MDd /Zi DBGLFLAG=/debug /debugtype:BOTH -MODDBGCFLAG=/LDd /Zi +MODDBGCFLAG=/LDd /MDd /Zi !ELSE -DBGCFLAG=/MT /O2 /G5 -MODDBGCFLAG=/LD +DBGCFLAG=/MD /O2 /G5 +MODDBGCFLAG=/LD /MD !ENDIF FD_SETSIZE=/D FD_SETSIZE=16384 CFLAGS=$(DBGCFLAG) $(LIBCURL_INC) $(ZLIB_INC) $(OPENSSL_INC) /I ./INCLUDE /Fosrc/ /nologo \ $(ZIPCFLAGS) $(CURLCFLAGS) $(FD_SETSIZE) $(SSLCFLAGS) $(NS_ADDRESS) /D NOSPOOF=1 /c LFLAGS=kernel32.lib user32.lib gdi32.lib shell32.lib ws2_32.lib advapi32.lib \ - dbghelp.lib oldnames.lib libcmt.lib comctl32.lib comdlg32.lib $(ZLIB_LIB) $(ZIPLIB) \ + dbghelp.lib oldnames.lib comctl32.lib comdlg32.lib $(ZLIB_LIB) $(ZIPLIB) \ $(OPENSSL_LIB) $(SSLLIBS) $(LIBCURL_LIB) $(CURLLIB) /def:wircd.def /implib:wircd.lib \ - /nodefaultlib /nologo $(DBGLFLAG) /out:WIRCD.EXE + /nologo $(DBGLFLAG) /out:WIRCD.EXE MODCFLAGS=$(MODDBGCFLAG) $(SSLCFLAGS) $(ZIPCFLAGS) $(CURLCFLAGS) /Fesrc/modules/ \ /Fosrc/modules/ /nologo $(LIBCURL_INC) $(ZLIB_INC) $(OPENSSL_INC) /I ./INCLUDE /D \ DYNAMIC_LINKING /D NOSPOOF /D MODULE_COMPILE diff --git a/src/modules.c b/src/modules.c index 110af2fa3..a99774bc2 100644 --- a/src/modules.c +++ b/src/modules.c @@ -93,7 +93,7 @@ void DeleteTempModules(void) if (!fd) /* Ouch.. this is NOT good!! */ { config_error("Unable to open 'tmp' directory: %s, please create one with the appropriate permissions", - strerror(ERRNO)); + strerror(errno)); if (!loop.ircd_booted) exit(7); return; diff --git a/src/res.c b/src/res.c index dad194c8b..ebc0cd576 100644 --- a/src/res.c +++ b/src/res.c @@ -374,7 +374,7 @@ static int send_res_msg(char *msg, int len, int rcount) #endif { - Debug((DEBUG_DNS, "send_res_msg, errno = %s",strerror(ERRNO))); + Debug((DEBUG_DNS, "send_res_msg, errno = %s",STRERROR(ERRNO))); reinfo.re_sent++; sent++; } diff --git a/src/s_bsd.c b/src/s_bsd.c index 1e6f4c8a3..df15d34d9 100644 --- a/src/s_bsd.c +++ b/src/s_bsd.c @@ -271,7 +271,7 @@ void report_error(char *text, aClient *cptr) host = (cptr) ? get_client_name(cptr, FALSE) : ""; - Debug((DEBUG_ERROR, text, host, strerror(errtmp))); + Debug((DEBUG_ERROR, text, host, STRERROR(errtmp))); /* * Get the *real* error from the socket (well try to anyway..). @@ -290,14 +290,14 @@ void report_error(char *text, aClient *cptr) * some tricks are needed because of 2x strerror() (or at least * according to the man page) -- Syzop. */ - snprintf(xbuf, 200, "[syserr='%s'", strerror(origerr)); + snprintf(xbuf, 200, "[syserr='%s'", STRERROR(origerr)); n = strlen(xbuf); - snprintf(xbuf+n, 256-n, ", sockerr='%s']", strerror(errtmp)); + snprintf(xbuf+n, 256-n, ", sockerr='%s']", STRERROR(errtmp)); sendto_snomask(SNO_JUNK, text, host, xbuf); ircd_log(LOG_ERROR, text, host, xbuf); } else { - sendto_snomask(SNO_JUNK, text, host, strerror(errtmp)); - ircd_log(LOG_ERROR, text,host,strerror(errtmp)); + sendto_snomask(SNO_JUNK, text, host, STRERROR(errtmp)); + ircd_log(LOG_ERROR, text,host,STRERROR(errtmp)); } return; } @@ -316,7 +316,7 @@ void report_baderror(char *text, aClient *cptr) /* fprintf(stderr, text, host, strerror(errtmp)); fputc('\n', stderr); */ - Debug((DEBUG_ERROR, text, host, strerror(errtmp))); + Debug((DEBUG_ERROR, text, host, STRERROR(errtmp))); /* * Get the *real* error from the socket (well try to anyway..). @@ -330,7 +330,7 @@ void report_baderror(char *text, aClient *cptr) if (err) errtmp = err; #endif - sendto_umode(UMODE_OPER, text, host, strerror(errtmp)); + sendto_umode(UMODE_OPER, text, host, STRERROR(errtmp)); return; } @@ -1918,7 +1918,7 @@ deadsocket: } (void)exit_client(cptr, cptr, &me, ((sockerr = get_sockerr(cptr)) - ? strerror(sockerr) : "Client exited")); + ? STRERROR(sockerr) : "Client exited")); continue; } } @@ -2005,7 +2005,7 @@ deadsocket: if (length != FLUSH_BUFFER) (void)exit_client(cptr, cptr, &me, ((sockerr = get_sockerr(cptr)) - ? strerror(sockerr) : "Client exited")); + ? STRERROR(sockerr) : "Client exited")); } return 0; } @@ -2290,7 +2290,7 @@ int read_message(time_t delay, fdlist *listp) (void)exit_client(cptr, cptr, &me, ((sockerr = - get_sockerr(cptr)) ? strerror(sockerr) : + get_sockerr(cptr)) ? STRERROR(sockerr) : "Client exited")); continue; } @@ -2312,7 +2312,7 @@ int read_message(time_t delay, fdlist *listp) if (IsDead(cptr)) { ircsprintf(errmsg, "Read/Dead Error: %s", - strerror(get_sockerr(cptr))); + STRERROR(get_sockerr(cptr))); exit_client(cptr, cptr, &me, errmsg); continue; } @@ -2341,7 +2341,7 @@ int read_message(time_t delay, fdlist *listp) if (length != FLUSH_BUFFER) (void)exit_client(cptr, cptr, &me, ((sockerr = get_sockerr(cptr)) - ? strerror(sockerr) : "Client exited")); + ? STRERROR(sockerr) : "Client exited")); } return 0; @@ -2624,7 +2624,7 @@ static void do_dns_async(void) sendto_realops("Hostname %s is unknown for server %s (!?).", aconf->hostname, aconf->servername); break; default: - sendto_realops("Connection to %s failed: %s", aconf->servername, strerror(n)); + sendto_realops("Connection to %s failed: %s", aconf->servername, STRERROR(n)); } } if (!hp) { diff --git a/src/s_debug.c b/src/s_debug.c index 8bcdc1574..dba4cfd83 100644 --- a/src/s_debug.c +++ b/src/s_debug.c @@ -317,11 +317,7 @@ void send_usage(aClient *cptr, char *nick) if (times(&tmsbuf) == -1) { sendto_one(cptr, ":%s %d %s :times(2) error: %s.", -# ifndef _WIN32 - me.name, RPL_STATSDEBUG, nick, strerror(errno)); -# else - me.name, RPL_STATSDEBUG, nick, strerror(WSAGetLastError())); -# endif + me.name, RPL_STATSDEBUG, nick, STRERROR(ERRNO)); return; } secs = tmsbuf.tms_utime + tmsbuf.tms_stime; diff --git a/src/send.c b/src/send.c index e1ae3dbeb..d78645d3d 100644 --- a/src/send.c +++ b/src/send.c @@ -196,7 +196,7 @@ int send_queued(aClient *to) if ((rlen = deliver_it(to, msg, len)) < 0) { char buf[256]; - snprintf(buf, 256, "Write error: %s", strerror(ERRNO)); + snprintf(buf, 256, "Write error: %s", STRERROR(ERRNO)); return dead_link(to, buf); } (void)dbuf_delete(&to->sendQ, rlen); diff --git a/src/socket.c b/src/socket.c index f8c188b13..8c1d69f1f 100644 --- a/src/socket.c +++ b/src/socket.c @@ -119,11 +119,7 @@ int deliver_it(aClient *cptr, char *str, int len) if (retval < 0) { writeb[0]++; -# ifndef _WIN32 - Debug((DEBUG_ERROR, "write error (%s) to %s", strerror(errno), cptr->name)); -# else - Debug((DEBUG_ERROR, "write error (%s) to %s", "", cptr->name)); -# endif + Debug((DEBUG_ERROR, "write error (%s) to %s", STRERROR(ERRNO), cptr->name)); } else if (retval == 0) diff --git a/src/ssl.c b/src/ssl.c index 9c6b0a76b..0d40b8775 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -103,7 +103,7 @@ static char ssl_errbuf[256]; ssl_errstr = "OpenSSL requested a X509 lookup which didn`t arrive"; break; case SSL_ERROR_SYSCALL: - snprintf(ssl_errbuf, sizeof(ssl_errbuf), "Underlying syscall error [%s]", strerror(ERRNO)); + snprintf(ssl_errbuf, sizeof(ssl_errbuf), "Underlying syscall error [%s]", STRERROR(ERRNO)); ssl_errstr = ssl_errbuf; break; case SSL_ERROR_ZERO_RETURN: diff --git a/src/support.c b/src/support.c index 0e628f8c2..4e493b10d 100644 --- a/src/support.c +++ b/src/support.c @@ -136,19 +136,8 @@ char *strerror(int err_no) if (errp == (char *)NULL) { errp = buff; -#ifndef _WIN32 (void)ircsprintf(errp, "Unknown Error %d", err_no); -#else - switch (err_no) - { - case WSAECONNRESET: - ircsprintf(errp, "Connection reset by peer"); - break; - default: - ircsprintf(errp, "Unknown Error %d", err_no); - break; - } -#endif + } return errp; } @@ -1704,7 +1693,7 @@ char *unreal_mktemp(char *dir, char *suffix) fclose(fd); } config_error("Unable to create temporary file in directory '%s': %s", - dir, strerror(ERRNO)); /* eg: permission denied :p */ + dir, strerror(errno)); /* eg: permission denied :p */ return NULL; } @@ -1758,7 +1747,7 @@ int unreal_copyfile(char *src, char *dest) #endif if (destfd < 0) { - config_error("Unable to create file '%s': %s", dest, strerror(ERRNO)); + config_error("Unable to create file '%s': %s", dest, strerror(errno)); return 0; } @@ -1772,7 +1761,7 @@ int unreal_copyfile(char *src, char *dest) if (len < 0) /* very unusual.. perhaps an I/O error */ { - config_error("Read error from file '%s': %s", src, strerror(ERRNO)); + config_error("Read error from file '%s': %s", src, strerror(errno)); goto fail; } @@ -2274,3 +2263,18 @@ inet_pton6(const char *src, unsigned char *dst) return (1); } #endif /* !HAVE_INET_PTON */ + +#ifdef _WIN32 +char *sock_strerror(int error) +{ + static char buf[1024]; + static HMODULE hSock = NULL; + if (!hSock) + hSock = LoadLibraryEx("wsock32.dll", NULL, LOAD_LIBRARY_AS_DATAFILE); + + FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_HMODULE, + hSock, error, 0, buf, 1024, NULL); + + return buf; +} +#endif diff --git a/src/url.c b/src/url.c index cfa43cee3..3381a0aaf 100644 --- a/src/url.c +++ b/src/url.c @@ -157,7 +157,7 @@ char *download_file(char *url, char **error) fd = fopen(tmp, "wb"); if (!fd) { - snprintf(errorbuf, CURL_ERROR_SIZE, "Cannot write to %s: %s", tmp, strerror(ERRNO)); + snprintf(errorbuf, CURL_ERROR_SIZE, "Cannot write to %s: %s", tmp, strerror(errno)); if (file) free(file); *error = errorbuf; diff --git a/src/win32/unrealinst.iss b/src/win32/unrealinst.iss index c1376aa88..2b4944ed7 100644 --- a/src/win32/unrealinst.iss +++ b/src/win32/unrealinst.iss @@ -91,12 +91,14 @@ function isxdl_Download(hWnd: Integer; URL, Filename: PChar): Integer; external 'isxdl_Download@files:isxdl.dll stdcall'; function isxdl_SetOption(Option, Value: PChar): Integer; external 'isxdl_SetOption@files:isxdl.dll stdcall'; -const url = 'http://www.unrealircd.com/downloads/DbgHelp.Dll'; -var didDl: Boolean; +const dbgurl = 'http://www.unrealircd.com/downloads/DbgHelp.Dll'; +const crturl = 'http://www.unrealircd.com/downloads/msvcr70d.dll'; +var didDbgDl,didCrtDl: Boolean; function NextButtonClick(CurPage: Integer): Boolean; var dbghelp,tmp,output: String; +msvcrt: String; m: String; hWnd,answer: Integer; begin @@ -104,7 +106,21 @@ begin if ((CurPage = wpReady)) then begin dbghelp := ExpandConstant('{sys}\DbgHelp.Dll'); output := ExpandConstant('{app}\DbgHelp.Dll'); + msvcrt := ExpandConstant('{sys}\msvcr70d.Dll'); GetVersionNumbersString(dbghelp,m); + if (NOT FileExists(msvcrt)) then begin + answer := MsgBox('Unreal requires the MS C Runtime 7.0 in order to run, do you wish to install it now?', mbConfirmation, MB_YESNO); + if answer = IDYES then begin + tmp := ExpandConstant('{tmp}\msvcr70d.Dll'); + isxdl_SetOption('title', 'Downloading msvcr70d.dll'); + hWnd := StrToInt(ExpandConstant('{wizardhwnd}')); + if isxdl_Download(hWnd, crturl, tmp) = 0 then begin + MsgBox('Download and installation of msvcr70d.dll failed, the file must be manually installed. The file can be downloaded at http://www.unrealircd.com/downloads/mscvr70.dll', mbInformation, MB_OK); + end else + didCrtDl := true; + end else + MsgBox('In order for Unreal to properly function, you must manually install msvcr70d.dll. The dll can be downloaded from http://www.unrealircd.com/downloads/msvcr70d.dll', mbInformation, MB_OK); + end; if (NOT FileExists(output)) then begin if (NOT FileExists(dbghelp)) then m := StringOfChar('0',1); @@ -114,12 +130,12 @@ begin tmp := ExpandConstant('{tmp}\dbghelp.dll'); isxdl_SetOption('title', 'Downloading DbgHelp.dll'); hWnd := StrToInt(ExpandConstant('{wizardhwnd}')); - if isxdl_Download(hWnd, url, tmp) = 0 then begin + if isxdl_Download(hWnd, dbgurl, tmp) = 0 then begin MsgBox('Download and installation of DbgHelp.Dll failed, the file must be manually installed. The file can be downloaded at http://www.unrealircd.com/downloads/DbgHelp.Dll', mbInformation, MB_OK); end else - didDl := true; + didDbgDl := true; end else - MsgBox('In order for Unreal to properly function you must manually install this dll. The dll can be downloaded from http://www.unrealircd.com/downloads/DbgHelp.Dll', mbInformation, MB_OK); + MsgBox('In order for Unreal to properly function you must manually install dbghelp.dll. The dll can be downloaded from http://www.unrealircd.com/downloads/DbgHelp.Dll', mbInformation, MB_OK); end; end; end; @@ -130,11 +146,16 @@ procedure DeInitializeSetup(); var input,output: String; begin - if (didDl) then begin + if (didDbgDl) then begin input := ExpandConstant('{tmp}\dbghelp.dll'); output := ExpandConstant('{app}\dbghelp.dll'); FileCopy(input, output, true); end; + if (didCrtDl) then begin + input := ExpandConstant('{tmp}\msvcr70d.dll'); + output := ExpandConstant('{sys}\msvcr70d.dll'); + FileCopy(input, output, true); + end; end; [Icons] diff --git a/wircd.def b/wircd.def index 7a2977231..24fba71ba 100644 --- a/wircd.def +++ b/wircd.def @@ -786,7 +786,6 @@ EXPORTS spamfilter_target_inttostring start_auth start_of_normal_client_handshake - strerror stripbadwords stripbadwords_channel stripbadwords_message