NSS compat support

Miroslav Lichvar <[email protected]>
Newsgroups gmane.network.slrn.user
Message-ID <20080606140057.GA1127@localhost>
Hi,

attached are three patches for slrn. The first patch adds a support
for NSS compat library, second fixes a problem with autoconf-2.62 and
the third one adds getaddrinfo support to get_hostname() function.

-- 
Miroslav Lichvar

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
slrn-nss.patch (text/plain, 3.3 KB)
Index: src/config.hin
===================================================================
--- src/config.hin	(revision 272)
+++ src/config.hin	(working copy)
@@ -16,6 +16,9 @@
 /* define if you want SSL support */
 #undef USE_SSL
 
+/* define if you want to use NSS compat library instead of OpenSSL */
+#undef USE_NSS_COMPAT
+
 /* define if you have stdlib.h */
 #undef HAVE_STDLIB_H
 
@@ -162,6 +165,9 @@
 #define SLTCP_HAS_GNUTLS_SUPPORT SLRN_HAS_GNUTLS_SUPPORT
 #define SLTCP_HAS_SSL_SUPPORT SLRN_HAS_SSL_SUPPORT
 
+#ifdef USE_NSS_COMPAT
+# define SLTCP_HAS_NSS_COMPAT 1
+#endif
 
 #define SLRN_SERVER_ID_NNTP 1
 #define SLRN_SERVER_ID_SPOOL 2
Index: src/sltcp.c
===================================================================
--- src/sltcp.c	(revision 272)
+++ src/sltcp.c	(working copy)
@@ -114,9 +114,13 @@
 # include <gnutls/openssl.h>
 #else
 # if SLTCP_HAS_SSL_SUPPORT
-#  include <openssl/ssl.h>
-#  include <openssl/err.h>
-#  include <openssl/rand.h>
+#  if SLTCP_HAS_NSS_COMPAT
+#   include <nss_compat_ossl.h>
+#  else
+#   include <openssl/ssl.h>
+#   include <openssl/err.h>
+#   include <openssl/rand.h>
+#  endif
 # endif
 #endif
 
@@ -509,14 +513,17 @@
      print_error ("%s\n", ERR_error_string(err, 0));
 }
 
+#if !SLTCP_HAS_NSS_COMPAT
 unsigned long Fast_Random;
 static unsigned long fast_random (void)
 {
    return (Fast_Random = Fast_Random * 69069U + 1013904243U);
 }
+#endif
 
 static int init_ssl_random (void)
 {
+#if !SLTCP_HAS_NSS_COMPAT
    time_t t;
    pid_t pid;
    unsigned int count;
@@ -538,6 +545,7 @@
 	unsigned long r = fast_random ();
 	RAND_seed (&r, sizeof (unsigned long));
      }
+#endif
    if (RAND_status ())
      return 0;
    
Index: autoconf/configure.ac
===================================================================
--- autoconf/configure.ac	(revision 272)
+++ autoconf/configure.ac	(working copy)
@@ -200,6 +200,9 @@
 #---------------------------------------------------------------------------
 # SSL stuff
 #---------------------------------------------------------------------------
+AC_ARG_WITH(nss-compat,
+    [  --with-nss-compat       Use NSS compat library instead of OpenSSL],
+    [use_nss_compat=$withval], [use_nss_compat=no])
 AC_CACHE_CHECK(if you want SSL support,jd_use_ssl,
 [
   AC_ARG_WITH(ssl, 
@@ -212,17 +215,30 @@
    SSLLIB=
   ;;
 x|xyes)
-   SSLINC="-I/usr/local/ssl/include"
-   SSLLIB="-L/usr/local/ssl/lib -lssl -lcrypto"
+   if test "x$use_nss_compat" != xno; then
+     SSLINC="-I/usr/local/include/nss_compat_ossl -I/usr/local/include/nss3 -I/usr/local/include/nspr4"
+     SSLLIB="-L/usr/local/lib -lnss_compat_ossl"
+   else
+     SSLINC="-I/usr/local/ssl/include"
+     SSLLIB="-L/usr/local/ssl/lib -lssl -lcrypto"
+   fi
 ;;
 *)
-   SSLINC="-I$jd_use_ssl/include"
-   SSLLIB="-L$jd_use_ssl/lib -lssl -lcrypto"
+   if test "x$use_nss_compat" != xno; then
+     SSLINC="-I$jd_use_ssl/include/nss_compat_ossl -I$jd_use_ssl/include/nss3 -I$jd_use_ssl/include/nspr4"
+     SSLLIB="-L$jd_use_ssl/lib -lnss_compat_ossl"
+   else
+     SSLINC="-I$jd_use_ssl/include"
+     SSLLIB="-L$jd_use_ssl/lib -lssl -lcrypto"
+   fi
 esac
 AC_SUBST(SSLINC)
 AC_SUBST(SSLLIB)
 if test "x$SSLINC" != x; then
  AC_DEFINE(USE_SSL)
+ if test "x$use_nss_compat" != xno; then
+   AC_DEFINE(USE_NSS_COMPAT)
+ fi
 fi
 
 #---------------------------------------------------------------------------
slrn-cc.patch (text/plain, 365 B)
Index: autoconf/aclocal.m4
===================================================================
--- autoconf/aclocal.m4	(revision 272)
+++ autoconf/aclocal.m4	(working copy)
@@ -501,11 +501,11 @@
 
 AC_DEFUN(JD_ANSI_CC, dnl#{{{
 [
+AC_AIX
 AC_PROG_CC
 AC_PROG_CPP
 AC_PROG_GCC_TRADITIONAL
 AC_ISC_POSIX
-AC_AIX
 
 dnl #This stuff came from Yorick config script
 dnl
slrn-getaddrinfo.patch (text/plain, 1.3 KB)
Index: src/misc.c
===================================================================
--- src/misc.c	(revision 272)
+++ src/misc.c	(working copy)
@@ -2543,10 +2543,14 @@
 /* Try to get a fully qualified domain name. */
 static char *get_hostname (void)
 {
+#ifdef HAVE_GETADDRINFO
+   struct addrinfo hint, *res;
+   int r;
+#else
    struct hostent *host_entry;
+#endif
    char buf[MAX_HOST_NAME_LEN + 1];
 
-   host_entry = NULL;
    if ((-1 == gethostname (buf, MAX_HOST_NAME_LEN))
        || (*buf == 0))
      return NULL;
@@ -2555,6 +2559,24 @@
     * to get more information.  Why isn't there a simplified interface to
     * get the FQDN!!!!
     */
+#ifdef HAVE_GETADDRINFO
+   memset(&hint, 0, sizeof (hint));
+   hint.ai_flags = AI_CANONNAME;
+
+   r = getaddrinfo(buf, NULL, &hint, &res);
+   if (r == EAI_AGAIN)
+     {
+	slrn_sleep (2);
+	r = getaddrinfo(buf, NULL, &hint, &res);
+     }
+
+   if (r == 0 && res && res->ai_canonname)
+     {
+	char *ret = slrn_safe_strmalloc (res->ai_canonname);
+	freeaddrinfo(res);
+	return ret;
+     }
+#else
    host_entry = gethostbyname (buf);
 
 #if defined(TRY_AGAIN) && !defined(MULTINET)
@@ -2585,6 +2607,7 @@
 	return slrn_safe_strmalloc ((char *)host_entry->h_name);
      }
    
+#endif 
    return slrn_safe_strmalloc (buf);
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.