File mozilla-shared-nss-db.patch of Package mozilla-xulrunner190

From: Hans Petter Jansson <hpj@copyleft.no>
      Wolfgang Rosenauer <wr@rosenauer.org>
Subject: use libnsssharedhelper if available at compile time
         (can be disabled by exporting MOZ_XRE_NO_NSSHELPER=1)
References:


Index: configure
===================================================================
RCS file: /cvsroot/mozilla/configure,v
retrieving revision 1.2036
diff -u -p -6 -r1.2036 configure
--- configure	21 Oct 2008 02:11:02 -0000	1.2036
+++ configure	19 Nov 2008 10:12:42 -0000
@@ -20374,12 +20374,115 @@ echo "configure:20346: checking LCMS_LIB
 fi
 
 
 
 
 
+
+  succeeded=no
+
+  if test -z "$PKG_CONFIG"; then
+    # Extract the first word of "pkg-config", so it can be a program name with args.
+set dummy pkg-config; ac_word=$2
+echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
+echo "configure:20388: checking for $ac_word" >&5
+if eval "test \"`echo '$''{'ac_cv_path_PKG_CONFIG'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  case "$PKG_CONFIG" in
+  /*)
+  ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path.
+  ;;
+  ?:/*)			 
+  ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a dos path.
+  ;;
+  *)
+  IFS="${IFS= 	}"; ac_save_ifs="$IFS"; IFS=":"
+  ac_dummy="$PATH"
+  for ac_dir in $ac_dummy; do 
+    test -z "$ac_dir" && ac_dir=.
+    if test -f $ac_dir/$ac_word; then
+      ac_cv_path_PKG_CONFIG="$ac_dir/$ac_word"
+      break
+    fi
+  done
+  IFS="$ac_save_ifs"
+  test -z "$ac_cv_path_PKG_CONFIG" && ac_cv_path_PKG_CONFIG="no"
+  ;;
+esac
+fi
+PKG_CONFIG="$ac_cv_path_PKG_CONFIG"
+if test -n "$PKG_CONFIG"; then
+  echo "$ac_t""$PKG_CONFIG" 1>&6
+else
+  echo "$ac_t""no" 1>&6
+fi
+
+  fi
+
+  if test "$PKG_CONFIG" = "no" ; then
+     echo "*** The pkg-config script could not be found. Make sure it is"
+     echo "*** in your path, or set the PKG_CONFIG environment variable"
+     echo "*** to the full path to pkg-config."
+     echo "*** Or see http://www.freedesktop.org/software/pkgconfig to get pkg-config."
+  else
+     PKG_CONFIG_MIN_VERSION=0.9.0
+     if $PKG_CONFIG --atleast-pkgconfig-version $PKG_CONFIG_MIN_VERSION; then
+        echo $ac_n "checking for nss-shared-helper""... $ac_c" 1>&6
+echo "configure:20432: checking for nss-shared-helper" >&5
+
+        if $PKG_CONFIG --exists "nss-shared-helper" ; then
+            echo "$ac_t""yes" 1>&6
+            succeeded=yes
+
+            echo $ac_n "checking NSSHELPER_CFLAGS""... $ac_c" 1>&6
+echo "configure:20439: checking NSSHELPER_CFLAGS" >&5
+            NSSHELPER_CFLAGS=`$PKG_CONFIG --cflags "nss-shared-helper"`
+            echo "$ac_t""$NSSHELPER_CFLAGS" 1>&6
+
+            echo $ac_n "checking NSSHELPER_LIBS""... $ac_c" 1>&6
+echo "configure:20444: checking NSSHELPER_LIBS" >&5
+            ## Remove evil flags like -Wl,--export-dynamic
+            NSSHELPER_LIBS="`$PKG_CONFIG --libs \"nss-shared-helper\" |sed s/-Wl,--export-dynamic//g`"
+            echo "$ac_t""$NSSHELPER_LIBS" 1>&6
+        else
+            NSSHELPER_CFLAGS=""
+            NSSHELPER_LIBS=""
+            ## If we have a custom action on failure, don't print errors, but 
+            ## do set a variable so people can do so.
+            NSSHELPER_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "nss-shared-helper"`
+            
+        fi
+
+        
+        
+     else
+        echo "*** Your version of pkg-config is too old. You need version $PKG_CONFIG_MIN_VERSION or newer."
+        echo "*** See http://www.freedesktop.org/software/pkgconfig"
+     fi
+  fi
+
+  if test $succeeded = yes; then
+     MOZ_ENABLE_NSSHELPER=1
+  else
+     if test "$COMPILE_ENVIRONMENT"; then 
+       MOZ_ENABLE_NSSHELPER=
+     fi
+  fi
+
+
+if test "$MOZ_ENABLE_NSSHELPER"; then
+  cat >> confdefs.h <<\EOF
+#define MOZ_ENABLE_NSSHELPER 1
+EOF
+
+fi
+
+
+
+
 # Check whether --enable-xul or --disable-xul was given.
 if test "${enable_xul+set}" = set; then
   enableval="$enable_xul"
   if test "$enableval" = "no"; then
     MOZ_XUL= 
   elif test "$enableval" = "yes"; then
@@ -20687,20 +20790,20 @@ if test "$SUNCTL"; then
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5'
 ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5'
 cross_compiling=$ac_cv_prog_cc_cross
 
     cat > conftest.$ac_ext <<EOF
-#line 20694 "configure"
+#line 20797 "configure"
 #include "confdefs.h"
 #include <gmodule.h>
 int main() {
  int x = 1; x++; 
 ; return 0; }
 EOF
-if { (eval echo configure:20701: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:20804: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   :
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
   { echo "configure: error: Cannot build ctl without gmodule support in glib." 1>&2; exit 1; }
@@ -21008,13 +21111,13 @@ fi
 
 if test "$COMPILE_ENVIRONMENT"; then
 if test "$MOZ_X11"; then
                 _SAVE_CFLAGS=$CFLAGS
     CFLAGS="$CFLAGS $XCFLAGS"
     cat > conftest.$ac_ext <<EOF
-#line 21015 "configure"
+#line 21118 "configure"
 #include "confdefs.h"
 
         #include <stdio.h>
         #include <stdlib.h>
         #include <X11/Xlib.h>
         #include <X11/Intrinsic.h>
@@ -21026,13 +21129,13 @@ int main() {
             fprintf(stderr, ": can't open %s\n", XDisplayName(NULL));
             exit(1);
         }
     
 ; return 0; }
 EOF
-if { (eval echo configure:21033: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:21136: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   :
 else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
    { echo "configure: error: Could not compile basic X program." 1>&2; exit 1; } 
@@ -21679,12 +21782,15 @@ s%@CAIRO_XRENDER_LIBS@%$CAIRO_XRENDER_LI
 s%@MOZ_TREE_CAIRO@%$MOZ_TREE_CAIRO%g
 s%@MOZ_CAIRO_CFLAGS@%$MOZ_CAIRO_CFLAGS%g
 s%@MOZ_CAIRO_LIBS@%$MOZ_CAIRO_LIBS%g
 s%@LCMS_CFLAGS@%$LCMS_CFLAGS%g
 s%@LCMS_LIBS@%$LCMS_LIBS%g
 s%@MOZ_NATIVE_LCMS@%$MOZ_NATIVE_LCMS%g
+s%@NSSHELPER_CFLAGS@%$NSSHELPER_CFLAGS%g
+s%@NSSHELPER_LIBS@%$NSSHELPER_LIBS%g
+s%@MOZ_ENABLE_NSSHELPER@%$MOZ_ENABLE_NSSHELPER%g
 s%@MOZ_XUL@%$MOZ_XUL%g
 s%@MOZ_PYTHON_EXTENSIONS@%$MOZ_PYTHON_EXTENSIONS%g
 s%@MOZ_PYTHON@%$MOZ_PYTHON%g
 s%@MOZ_PYTHON_PREFIX@%$MOZ_PYTHON_PREFIX%g
 s%@MOZ_PYTHON_INCLUDES@%$MOZ_PYTHON_INCLUDES%g
 s%@MOZ_PYTHON_LIBS@%$MOZ_PYTHON_LIBS%g
Index: configure.in
===================================================================
RCS file: /cvsroot/mozilla/configure.in,v
retrieving revision 1.1999
diff -u -p -6 -r1.1999 configure.in
--- configure.in	21 Oct 2008 02:09:09 -0000	1.1999
+++ configure.in	19 Nov 2008 10:12:45 -0000
@@ -7453,12 +7453,27 @@ fi
 
 AC_SUBST(MOZ_NATIVE_LCMS)
 AC_SUBST(LCMS_CFLAGS)
 AC_SUBST(LCMS_LIBS)
 
 dnl ========================================================
+dnl Check for nss-shared-helper
+dnl ========================================================
+
+  PKG_CHECK_MODULES(NSSHELPER, nss-shared-helper, 
+   [MOZ_ENABLE_NSSHELPER=1],
+   [MOZ_ENABLE_NSSHELPER=])
+
+if test "$MOZ_ENABLE_NSSHELPER"; then
+  AC_DEFINE(MOZ_ENABLE_NSSHELPER)
+fi
+AC_SUBST(MOZ_ENABLE_NSSHELPER)
+AC_SUBST(NSSHELPER_CFLAGS)
+AC_SUBST(NSSHELPER_LIBS)
+
+dnl ========================================================
 dnl disable xul
 dnl ========================================================
 MOZ_ARG_DISABLE_BOOL(xul,
 [  --disable-xul           Disable XUL],
     MOZ_XUL= )
 if test "$MOZ_XUL"; then
Index: config/autoconf.mk.in
===================================================================
RCS file: /cvsroot/mozilla/config/autoconf.mk.in,v
retrieving revision 3.464
diff -u -p -6 -r3.464 autoconf.mk.in
--- config/autoconf.mk.in	18 Sep 2008 22:00:51 -0000	3.464
+++ config/autoconf.mk.in	19 Nov 2008 10:12:46 -0000
@@ -532,12 +532,16 @@ GLIB_CFLAGS	= @GLIB_CFLAGS@
 GLIB_LIBS	= @GLIB_LIBS@
 GLIB_GMODULE_LIBS	= @GLIB_GMODULE_LIBS@
 LIBIDL_CFLAGS = @LIBIDL_CFLAGS@
 LIBIDL_LIBS = @LIBIDL_LIBS@
 STATIC_LIBIDL = @STATIC_LIBIDL@
 
+MOZ_ENABLE_NSSHELPER = @MOZ_ENABLE_NSSHELPER@
+NSSHELPER_CFLAGS = @NSSHELPER_CFLAGS@
+NSSHELPER_LIBS = @NSSHELPER_LIBS@
+
 MOZ_NATIVE_MAKEDEPEND	= @SYSTEM_MAKEDEPEND@
 
 # Used for LD_LIBRARY_PATH
 LIBS_PATH       = @LIBS_PATH@
 
 MOZ_AUTO_DEPS	= @MOZ_AUTO_DEPS@
Index: security/manager/ssl/src/Makefile.in
===================================================================
RCS file: /cvsroot/mozilla/security/manager/ssl/src/Makefile.in,v
retrieving revision 1.93
diff -u -p -6 -r1.93 Makefile.in
--- security/manager/ssl/src/Makefile.in	16 Sep 2008 20:44:53 -0000	1.93
+++ security/manager/ssl/src/Makefile.in	19 Nov 2008 10:13:03 -0000
@@ -136,17 +136,18 @@ REQUIRES	= nspr \
 EXTRA_DEPS = $(NSS_DEP_LIBS)
 
 DEFINES += -DNSS_ENABLE_ECC
 
 # Use local includes because they are inserted before INCLUDES
 # so that Mozilla's nss.h is used, not glibc's
-LOCAL_INCLUDES += $(NSS_CFLAGS)
+LOCAL_INCLUDES += $(NSS_CFLAGS) $(NSSHELPER_CFLAGS)
 
 EXTRA_DSO_LDOPTS += \
 		$(MOZ_UNICHARUTIL_LIBS) \
 		$(MOZ_COMPONENT_LIBS) \
 		$(MOZ_JS_LIBS) \
+		$(NSSHELPER_LIBS) \
 		$(NSS_LIBS) \
 		$(NULL)
 
 include $(topsrcdir)/config/rules.mk
 
Index: toolkit/library/Makefile.in
===================================================================
RCS file: /cvsroot/mozilla/toolkit/library/Makefile.in,v
retrieving revision 1.69
diff -u -p -6 -r1.69 Makefile.in
--- toolkit/library/Makefile.in	8 May 2008 09:20:45 -0000	1.69
+++ toolkit/library/Makefile.in	19 Nov 2008 10:13:07 -0000
@@ -198,13 +198,13 @@ EXTRA_DSO_LDOPTS += \
 	$(MOZ_JS_LIBS) \
 	$(NULL)
 endif
 
 DEFINES += -DIMPL_XREAPI
 
-EXTRA_DSO_LDOPTS += $(NSPR_LIBS)
+EXTRA_DSO_LDOPTS += $(NSPR_LIBS) $(NSSHELPER_LIBS)
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
 CXXFLAGS	+= $(TK_CFLAGS)
 EXTRA_DSO_LDOPTS += \
 	-framework QuickTime \
 	-framework IOKit \
Index: security/manager/ssl/src/nsNSSComponent.cpp
===================================================================
RCS file: /cvsroot/mozilla/security/manager/ssl/src/nsNSSComponent.cpp,v
retrieving revision 1.167
diff -u -p -6 -r1.167 nsNSSComponent.cpp
--- security/manager/ssl/src/nsNSSComponent.cpp	16 Sep 2008 20:44:53 -0000	1.167
+++ security/manager/ssl/src/nsNSSComponent.cpp	3 Jan 2009 09:12:33 -0000
@@ -41,12 +41,20 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#ifdef MOZ_ENABLE_NSSHELPER
+#pragma GCC visibility push(default)
+#include <nss-shared-helper.h>
+#pragma GCC visibility pop
+#include "prenv.h"
+#include "nsIXULAppInfo.h"
+#endif
+
 #include "nsNSSComponent.h"
 #include "nsNSSCallbacks.h"
 #include "nsNSSIOLayer.h"
 #include "nsSSLThread.h"
 #include "nsCertVerificationThread.h"
 
@@ -1542,13 +1550,32 @@ nsNSSComponent::InitializeNSS(PRBool sho
     // If we could assume i18n will not change between profiles, one call per application
     // run were sufficient. As I can't predict what happens in the future, let's repeat
     // this call for every re-init of NSS.
 
     ConfigureInternalPKCS11Token();
 
-    SECStatus init_rv = ::NSS_InitReadWrite(profileStr.get());
+    SECStatus init_rv = SECFailure;
+#ifdef MOZ_ENABLE_NSSHELPER
+    if (PR_GetEnv("MOZ_XRE_NO_NSSHELPER")) {
+      init_rv = ::NSS_InitReadWrite(profileStr.get());
+    } else {
+      nsCOMPtr<nsIXULAppInfo> appInfo = do_GetService("@mozilla.org/xre/app-info;1");
+      if (appInfo) {
+        nsXPIDLCString appName;
+        appInfo->GetName(appName);
+        init_rv = ::nsshelp_open_db (appName.get(), profileStr.get(), 0);
+      }
+
+      if (init_rv != SECSuccess) {
+        PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("can not init NSS using nsshelp_open_db in %s\n", profileStr.get()));
+        init_rv = ::NSS_InitReadWrite(profileStr.get());
+      }
+    }
+#else
+    init_rv = ::NSS_InitReadWrite(profileStr.get());
+#endif
 
     if (init_rv != SECSuccess) {
       PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("can not init NSS r/w in %s\n", profileStr.get()));
 
       if (supress_warning_preference) {
         which_nss_problem = problem_none;