bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getdomainname: fix several problems


From: Bruno Haible
Subject: Re: getdomainname: fix several problems
Date: Sun, 28 Nov 2010 21:24:32 +0100
User-agent: KMail/1.9.9

Hi Paul,

> who needs getdomainname and why?  If the caller wants the DNS domain,
> they could well be barking up the wrong tree here.

It's a glibc function, and some programs use it. There's a big warning
in our unistd.in.h that this function is not related to the DNS domain.

> <http://www.sun.com/software/solaris/programs/abi/appcert_faq.xml#q18>
> says that libnsl's getdomainname is a private interface, which (presumably)
> means that gnulib should not use it.  It says that for the NIS domain
> (which is what the code currently says it wants) the code should use
> sysinfo(SI_SRPC_DOMAIN).

Thanks for this info. In this light, I find it best to follow this advice
on Solaris. But continue to use getdomainname() on IRIX and OSF/1 - on these
platforms getdomainname() and SI_SRPC_DOMAIN both exist.

Here's an additional proposed patch:


--- NEWS.orig   Sun Nov 28 21:17:39 2010
+++ NEWS        Sun Nov 28 20:39:57 2010
@@ -12,9 +12,6 @@
 
 Date        Modules         Changes
 
-2010-11-28  getdomainname   The use of this module now requires linking with
-                            $(GETDOMAINNAME_LIB).
-
 2010-10-05  getdate         This module is deprecated. Please use the new
                             parse-datetime module for the replacement
                             function parse_datetime(), or help us write
--- doc/glibc-functions/getdomainname.texi.orig Sun Nov 28 21:17:40 2010
+++ doc/glibc-functions/getdomainname.texi      Sun Nov 28 20:58:42 2010
@@ -8,10 +8,7 @@
 @itemize
 @item
 This function is missing on some platforms:
-mingw, Interix 3.5, BeOS.
address@hidden
-This function is not declared on some platforms:
-Solaris 11 2010-11.
+Solaris 11 2010-11, mingw, Interix 3.5, BeOS.
 @item
 This function is declared in @code{netdb.h}, not in @code{unistd.h}, on
 some platforms:
@@ -22,7 +19,7 @@
 OSF/1 5.1.
 @item
 The second argument is of type @code{int}, not @code{size_t}, on some 
platforms:
-AIX 7.1, MacOS X 10.5, FreeBSD 6.4, IRIX 6.5, Solaris 11 2010-11.
+MacOS X 10.5, FreeBSD 6.4, AIX 7.1, IRIX 6.5.
 @end itemize
 
 Portability problems not fixed by Gnulib:
--- lib/getdomainname.c.orig    Sun Nov 28 21:17:40 2010
+++ lib/getdomainname.c Sun Nov 28 21:14:00 2010
@@ -26,6 +26,10 @@
 #include <string.h>
 #include <errno.h>
 
+#if HAVE_SYSINFO && HAVE_SYS_SYSTEMINFO_H /* IRIX, OSF/1, Solaris */
+# include <sys/systeminfo.h>
+#endif
+
 /* Return the NIS domain name of the machine.
    WARNING! The NIS domain name is unrelated to the fully qualified host name
             of the machine.  It is also unrelated to email addresses.
@@ -40,13 +44,29 @@
 getdomainname (char *name, size_t len)
 #undef getdomainname
 {
-#if HAVE_GETDOMAINNAME
+#if HAVE_GETDOMAINNAME                 /* MacOS X, FreeBSD, AIX, IRIX, OSF/1 */
   extern int getdomainname (char *, int);
 
   if (len > INT_MAX)
     len = INT_MAX;
   return getdomainname (name, (int) len);
-#else
+#elif HAVE_SYSINFO && HAVE_SYS_SYSTEMINFO_H && defined SI_SRPC_DOMAIN
+                                       /* Solaris */
+  int ret;
+
+  if (len > INT_MAX)
+    len = INT_MAX;
+  ret = sysinfo (SI_SRPC_DOMAIN, name, len);
+  if (ret < 0)
+    /* errno is set here.  */
+    return -1;
+  if (ret > len)
+    {
+      errno = EINVAL;
+      return -1;
+    }
+  return 0;
+#else                                  /* HP-UX, Cygwin, mingw */
   const char *result = "";      /* Hardcode your domain name if you want.  */
   size_t result_len = strlen (result);
 
--- m4/getdomainname.m4.orig    Sun Nov 28 21:17:40 2010
+++ m4/getdomainname.m4 Sun Nov 28 21:03:38 2010
@@ -14,9 +14,11 @@
   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
 
   dnl Where is getdomainname() defined?
-  dnl - On Solaris, it is in libnsl.
+  dnl - On Solaris, it is in libnsl. But this function is not declared and
+  dnl   is deprecated, see
+  dnl   <http://www.sun.com/software/solaris/programs/abi/appcert_faq.xml#q18>.
+  dnl   We need to avoid a collision with this function.
   dnl - Otherwise is is in libc.
-  GETDOMAINNAME_LIB=
   AC_CHECK_FUNCS([getdomainname], , [
     AC_CACHE_CHECK([for getdomainname in -lnsl],
       [gl_cv_func_getdomainname_in_libnsl],
@@ -32,18 +34,11 @@
          [gl_cv_func_getdomainname_in_libnsl=yes])
        LIBS="$gl_save_LIBS"
       ])
-    if test $gl_cv_func_getdomainname_in_libnsl = yes; then
-      GETDOMAINNAME_LIB="-lnsl"
-    fi
   ])
-  AC_SUBST([GETDOMAINNAME_LIB])
 
   dnl What about the declaration?
   dnl - It's  int getdomainname(char *, size_t)  on glibc, NetBSD, OpenBSD.
-  dnl - It's  int getdomainname(char *, int)  on MacOS X, FreeBSD, IRIX.
-  dnl - It's missing, but the function is defined as
-  dnl         int getdomainname(char *, int)
-  dnl   on Solaris.
+  dnl - It's  int getdomainname(char *, int)  on MacOS X, FreeBSD, AIX, IRIX, 
OSF/1.
   AC_CHECK_DECLS([getdomainname], , ,
     [#include <sys/types.h>
      #ifdef HAVE_SYS_SOCKET_H
@@ -80,12 +75,11 @@
     HAVE_DECL_GETDOMAINNAME=0
   fi
 
-  if test $ac_cv_func_getdomainname = yes \
-     || test $gl_cv_func_getdomainname_in_libnsl = yes; then
-    dnl The function getdomainname() exists.
-    if test $gl_cv_decl_getdomainname_argtype2 != size_t; then
-      REPLACE_GETDOMAINNAME=1
-    fi
+  if { test $ac_cv_func_getdomainname = yes \
+       && test $gl_cv_decl_getdomainname_argtype2 != size_t; \
+     } \
+     || test "$gl_cv_func_getdomainname_in_libnsl" = yes; then
+    REPLACE_GETDOMAINNAME=1
   fi
 
   if test $HAVE_DECL_GETDOMAINNAME = 0 || test $REPLACE_GETDOMAINNAME = 1; then
@@ -96,6 +90,10 @@
 
 # Prerequisites of lib/getdomainname.c.
 AC_DEFUN([gl_PREREQ_GETDOMAINNAME], [
-  AC_DEFINE_UNQUOTED([HAVE_GETDOMAINNAME], [$REPLACE_GETDOMAINNAME],
-    [Define if the getdomainname() function is present in some library.])
+  if test $ac_cv_func_getdomainname = yes; then
+    AC_DEFINE([HAVE_GETDOMAINNAME], [1],
+      [Define if the getdomainname() function is present and can be used.])
+  fi
+  AC_CHECK_HEADERS([sys/systeminfo.h])
+  AC_CHECK_FUNCS([sysinfo])
 ])
--- modules/getdomainname.orig  Sun Nov 28 21:17:40 2010
+++ modules/getdomainname       Sun Nov 28 20:40:12 2010
@@ -20,9 +20,6 @@
 Include:
 <unistd.h>
 
-Link:
-$(GETDOMAINNAME_LIB)
-
 License:
 GPL
 
--- modules/getdomainname-tests.orig    Sun Nov 28 21:17:40 2010
+++ modules/getdomainname-tests Sun Nov 28 20:40:18 2010
@@ -9,4 +9,3 @@
 Makefile.am:
 TESTS += test-getdomainname
 check_PROGRAMS += test-getdomainname
-test_getdomainname_LDADD = $(LDADD) @GETDOMAINNAME_LIB@



reply via email to

[Prev in Thread] Current Thread [Next in Thread]