Various zlib related fixes and enhancements.
authorDr. Stephen Henson <steve@openssl.org>
Mon, 5 Dec 2005 13:34:56 +0000 (13:34 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Mon, 5 Dec 2005 13:34:56 +0000 (13:34 +0000)
CHANGES
Configure
Makefile.org
crypto/comp/c_zlib.c
util/mk1mf.pl
util/pl/VC-32.pl

diff --git a/CHANGES b/CHANGES
index 19ffb2bbdb3eff9774b7f785a89ef77254973e70..4a314be6a99b97745ebc614a0c5c466ad9d2894c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,16 @@
 
  Changes between 0.9.8a and 0.9.8b  [XX xxx XXXX]
 
+  *) Fixes and enhancements to zlib compression code. We now only use
+     "zlib1.dll" and use the default __cdecl calling convention on Win32
+     to conform with the standards mentioned here:
+           http://www.zlib.net/DLL_FAQ.txt
+     Static zlib linking now works on Windows and the new --with-zlib-include
+     --with-zlib-lib options to Configure can be used to supply the location
+     of the headers and library. Gracefully handle case where zlib library
+     can't be loaded.
+     [Steve Henson]
+
   *) Several fixes and enhancements to the OID generation code. The old code
      sometimes allowed invalid OIDs (1.X for X >= 40 for example), couldn't
      handle numbers larger than ULONG_MAX, truncated printing and had a
index 855ad1522ddd40505e435f69f5d54c6c5289ee06..6b4727cffaa9889f5a25ac500f6313a236713271 100755 (executable)
--- a/Configure
+++ b/Configure
@@ -748,6 +748,10 @@ PROCESS_ARGS:
                                {
                                $withargs{"krb5-".$1}=$2;
                                }
+                       elsif (/^--with-zlib-(lib|include)=(.*)$/)
+                               {
+                               $withargs{"zlib-".$1}=$2;
+                               }
                        else
                                {
                                print STDERR $usage;
@@ -1302,6 +1306,8 @@ while (<IN>)
        s/^PERL=.*/PERL= $perl/;
        s/^KRB5_INCLUDES=.*/KRB5_INCLUDES=$withargs{"krb5-include"}/;
        s/^LIBKRB5=.*/LIBKRB5=$withargs{"krb5-lib"}/;
+       s/^LIBZLIB=.*/LIBZLIB=$withargs{"zlib-lib"}/;
+       s/^ZLIB_INCLUDE=.*/ZLIB_INCLUDE=$withargs{"zlib-include"}/;
        s/^SHLIB_TARGET=.*/SHLIB_TARGET=$shared_target/;
        s/^SHLIB_MARK=.*/SHLIB_MARK=$shared_mark/;
        s/^SHARED_LIBS=.*/SHARED_LIBS=\$(SHARED_CRYPTO) \$(SHARED_SSL)/ if (!$no_shared);
index a28b469eaaaf7bd0a81487f8597ce2ee7c5c497f..e65779cdd20f28d4fe0ec916f4ef3a270fa5d8ad 100644 (file)
@@ -100,6 +100,10 @@ RMD160_ASM_OBJ=
 KRB5_INCLUDES=
 LIBKRB5=
 
+# Zlib stuff
+ZLIB_INCLUDE=
+LIBZLIB=
+
 DIRS=   crypto ssl engines apps test tools
 SHLIBDIRS= crypto ssl
 
index 1cd1a296af6bc2d324058523f1d53fb8b28aedfd..941b807eb39149f2d1e3fae2378676f6c8734407 100644 (file)
@@ -67,46 +67,25 @@ static COMP_METHOD zlib_stateful_method={
  * When OpenSSL is built on Windows, we do not want to require that
  * the ZLIB.DLL be available in order for the OpenSSL DLLs to
  * work.  Therefore, all ZLIB routines are loaded at run time
- * and we do not link to a .LIB file.
+ * and we do not link to a .LIB file when ZLIB_SHARED is set.
  */
 #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
 # include <windows.h>
-
-# define Z_CALLCONV _stdcall
-# ifndef ZLIB_SHARED
-#  define ZLIB_SHARED
-# endif
-#else
-# define Z_CALLCONV
 #endif /* !(OPENSSL_SYS_WINDOWS || OPENSSL_SYS_WIN32) */
 
 #ifdef ZLIB_SHARED
 #include <openssl/dso.h>
 
-/* Prototypes for built in stubs */
-#if 0
-static int stub_compress(Bytef *dest,uLongf *destLen,
-       const Bytef *source, uLong sourceLen);
-#endif
-static int stub_inflateEnd(z_streamp strm);
-static int stub_inflate(z_streamp strm, int flush);
-static int stub_inflateInit_(z_streamp strm, const char * version,
-       int stream_size);
-static int stub_deflateEnd(z_streamp strm);
-static int stub_deflate(z_streamp strm, int flush);
-static int stub_deflateInit_(z_streamp strm, int level,
-       const char * version, int stream_size);
-
 /* Function pointers */
-typedef int (Z_CALLCONV *compress_ft)(Bytef *dest,uLongf *destLen,
+typedef int (*compress_ft)(Bytef *dest,uLongf *destLen,
        const Bytef *source, uLong sourceLen);
-typedef int (Z_CALLCONV *inflateEnd_ft)(z_streamp strm);
-typedef int (Z_CALLCONV *inflate_ft)(z_streamp strm, int flush);
-typedef int (Z_CALLCONV *inflateInit__ft)(z_streamp strm,
+typedef int (*inflateEnd_ft)(z_streamp strm);
+typedef int (*inflate_ft)(z_streamp strm, int flush);
+typedef int (*inflateInit__ft)(z_streamp strm,
        const char * version, int stream_size);
-typedef int (Z_CALLCONV *deflateEnd_ft)(z_streamp strm);
-typedef int (Z_CALLCONV *deflate_ft)(z_streamp strm, int flush);
-typedef int (Z_CALLCONV *deflateInit__ft)(z_streamp strm, int level,
+typedef int (*deflateEnd_ft)(z_streamp strm);
+typedef int (*deflate_ft)(z_streamp strm, int flush);
+typedef int (*deflateInit__ft)(z_streamp strm, int level,
        const char * version, int stream_size);
 static compress_ft     p_compress=NULL;
 static inflateEnd_ft   p_inflateEnd=NULL;
@@ -119,13 +98,13 @@ static deflateInit__ft     p_deflateInit_=NULL;
 static int zlib_loaded = 0;     /* only attempt to init func pts once */
 static DSO *zlib_dso = NULL;
 
-#define compress                stub_compress
-#define inflateEnd              stub_inflateEnd
-#define inflate                 stub_inflate
-#define inflateInit_            stub_inflateInit_
-#define deflateEnd              stub_deflateEnd
-#define deflate                 stub_deflate
-#define deflateInit_            stub_deflateInit_
+#define compress                p_compress
+#define inflateEnd              p_inflateEnd
+#define inflate                 p_inflate
+#define inflateInit_            p_inflateInit_
+#define deflateEnd              p_deflateEnd
+#define deflate                 p_deflate
+#define deflateInit_            p_deflateInit_
 #endif /* ZLIB_SHARED */
 
 struct zlib_state
@@ -361,16 +340,6 @@ COMP_METHOD *COMP_zlib(void)
                {
 #if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
                zlib_dso = DSO_load(NULL, "ZLIB1", NULL, 0);
-               if (!zlib_dso)
-                       {
-                       zlib_dso = DSO_load(NULL, "ZLIB", NULL, 0);
-                       if (zlib_dso)
-                               {
-                               /* Clear the errors from the first failed
-                                  DSO_load() */
-                               ERR_clear_error();
-                               }
-                       }
 #else
                zlib_dso = DSO_load(NULL, "z", NULL, 0);
 #endif
@@ -416,72 +385,3 @@ COMP_METHOD *COMP_zlib(void)
        return(meth);
        }
 
-#ifdef ZLIB_SHARED
-#if 0
-/* Stubs for each function to be dynamicly loaded */
-static int 
-stub_compress(Bytef *dest,uLongf *destLen,const Bytef *source, uLong sourceLen)
-       {
-       if (p_compress)
-               return(p_compress(dest,destLen,source,sourceLen));
-       else
-               return(Z_MEM_ERROR);
-       }
-#endif
-
-static int
-stub_inflateEnd(z_streamp strm)
-       {
-       if ( p_inflateEnd )
-               return(p_inflateEnd(strm));
-       else
-               return(Z_MEM_ERROR);
-       }
-
-static int
-stub_inflate(z_streamp strm, int flush)
-       {
-       if ( p_inflate )
-               return(p_inflate(strm,flush));
-       else
-               return(Z_MEM_ERROR);
-       }
-
-static int
-stub_inflateInit_(z_streamp strm, const char * version, int stream_size)
-       {
-       if ( p_inflateInit_ )
-               return(p_inflateInit_(strm,version,stream_size));
-       else
-               return(Z_MEM_ERROR);
-       }
-
-static int
-stub_deflateEnd(z_streamp strm)
-       {
-       if ( p_deflateEnd )
-               return(p_deflateEnd(strm));
-       else
-               return(Z_MEM_ERROR);
-       }
-
-static int
-stub_deflate(z_streamp strm, int flush)
-       {
-       if ( p_deflate )
-               return(p_deflate(strm,flush));
-       else
-               return(Z_MEM_ERROR);
-       }
-
-static int
-stub_deflateInit_(z_streamp strm, int level,
-       const char * version, int stream_size)
-       {
-       if ( p_deflateInit_ )
-               return(p_deflateInit_(strm,level,version,stream_size));
-       else
-               return(Z_MEM_ERROR);
-       }
-
-#endif /* ZLIB_SHARED */
index 2404aee29927503995981b1efa961113e370948d..bf4f89f48c3da0b511a8ceb8814db9c38ca3ffe5 100755 (executable)
@@ -12,6 +12,8 @@ $banner="\t\@echo Building OpenSSL";
 
 my $no_static_engine = 0;
 my $engines = "";
+local $zlib_opt = 0;   # 0 = no zlib, 1 = static, 2 = dynamic
+local $zlib_lib = "";
 
 
 open(IN,"<Makefile") || die "unable to open Makefile!\n";
@@ -222,6 +224,9 @@ $cflags.=" -DOPENSSL_NO_ECDH" if $no_ecdh;
 $cflags.=" -DOPENSSL_NO_ENGINE"   if $no_engine;
 $cflags.=" -DOPENSSL_NO_HW"   if $no_hw;
 
+$cflags.= " -DZLIB" if $zlib_opt;
+$cflags.= " -DZLIB_SHARED" if $zlib_opt == 2;
+
 if ($no_static_engine)
        {
        $cflags .= " -DOPENSSL_NO_STATIC_ENGINE";
@@ -240,6 +245,7 @@ else
 
 $ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
 
+
 %shlib_ex_cflags=("SSL" => " -DOPENSSL_BUILD_SHLIBSSL",
                  "CRYPTO" => " -DOPENSSL_BUILD_SHLIBCRYPTO");
 
@@ -284,8 +290,14 @@ for (;;)
        if ($key eq "KRB5_INCLUDES")
                { $cflags .= " $val";}
 
+       if ($key eq "ZLIB_INCLUDE")
+               { $cflags .= " -I$val";}
+
+       if ($key eq "LIBZLIB")
+               { $zlib_lib = "$val" if $val ne "";}
+
        if ($key eq "LIBKRB5")
-               { $ex_libs .= " $val";}
+               { $ex_libs .= " $val" if $val ne "";}
 
        if ($key eq "TEST")
                { $test.=&var_add($dir,$val, 0); }
@@ -337,6 +349,7 @@ else
        \$(CP) \$(O_SSL) \$(INSTALLTOP)${o}lib
        \$(CP) \$(O_CRYPTO) \$(INSTALLTOP)${o}lib
 EOF
+       $ex_libs .= " $zlib_lib" if $zlib_opt == 1;
        }
 
 $defs= <<"EOF";
@@ -831,7 +844,7 @@ sub do_defs
                $ret.=$t;
                }
        # hack to add version info on MSVC
-       if ($shlib && ($platform eq "VC-WIN32") || ($platform eq "VC-NT"))
+       if ($shlib && (($platform eq "VC-WIN32") || ($platform eq "VC-NT")))
                {
                if ($var eq "CRYPTOOBJ")
                        { $ret.="\$(OBJ_D)\\\$(CRYPTO).res "; }
@@ -1016,10 +1029,10 @@ sub read_options
                        }
                }
        elsif (/^no-comp$/) { $xcflags = "-DOPENSSL_NO_COMP $xcflags"; }
-       elsif (/^enable-zlib$/) { $xcflags = "-DZLIB $xcflags"; }
+       elsif (/^enable-zlib$/) { $zlib_opt = 1 if $zlib_opt == 0 }
        elsif (/^enable-zlib-dynamic$/)
                {
-               $xcflags = "-DZLIB_SHARED -DZLIB $xcflags";
+               $zlib_opt = 2;
                }
        elsif (/^no-static-engine/)
                {
index 90bcd4207ca0c0648d1c10f23f4f7a841123933c..d946ce4a3ac4d23b33eee6474028fb92e6e0b905 100644 (file)
@@ -11,6 +11,8 @@ $cp='$(PERL) util/copy.pl';
 $mkdir='$(PERL) util/mkdir-p.pl';
 $rm='del';
 
+$zlib_lib="zlib1.lib";
+
 # C compiler stuff
 $cc='cl';
 if ($FLAVOR =~ /WIN64/)
@@ -143,7 +145,6 @@ if ($FLAVOR =~ /NT/)
        $cflags.=" -DOPENSSL_SYSNAME_WINNT -DUNICODE -D_UNICODE";
        $ex_libs="unicows.lib $ex_libs";
        }
-
 # static library stuff
 $mklib='lib';
 $ranlib='';
@@ -272,6 +273,7 @@ sub do_lib_rule
                        $ex.=' wsock32.lib gdi32.lib advapi32.lib user32.lib';
                        $ex.=' bufferoverflowu.lib' if ($FLAVOR =~ /WIN64/);
                        }
+               $ex.=" $zlib_lib" if $zlib_opt == 1 && $target =~ /O_CRYPTO/;
                $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target $name @<<\n  \$(SHLIB_EX_OBJ) $objs $ex\n<<\n";
                }
        $ret.="\n";