bug-gnulib
[Top][All Lists]
Advanced

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

[Bug-gnulib] Re: new modules: getdomainname and xgetdomainname


From: Simon Josefsson
Subject: [Bug-gnulib] Re: new modules: getdomainname and xgetdomainname
Date: Thu, 25 Sep 2003 01:19:30 +0200
User-agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux)

Bruno Haible <address@hidden> writes:

> Simon Josefsson wrote:
>
>> +/* Put up to LEN chars of the domain name into NAME.
>> +   Null terminate it if the name is shorter than LEN.
>> +   Return 0 if ok, -1 if error.  */
>> +extern int getdomainname(char *name, size_t len);
>
> This is insufficient documentation. There are three notions of "domain name",
> each serving a different purpose:
>
>   - The NIS (new word for YP) domain name. This used by tools for
>     administration of NIS, NIS+. Applications shouldn't call this
>     directly; instead they should use the usual <pwd.h>, <grp.h> API
>     for this stuff.
>
>   - The difference between the fully qualified host name and the
>     short host name. What is this useful for?
>
>   - The difference between the HOST part of email addresses address@hidden
>     and the short host name of the machine. This is not generally
>     useful, because nowadays many email addresses don't carry the
>     machine's name in them. (My machine's name is neither 'clisp' nor
>     'ilog'.)
>
> getdomainname(). according to the glibc sources, is the NIS domain
> name.

Yup, this is the intention, the module description said:

getdomainname() function: Return machine's NIS/YP domain name.

But it is good to mention NIS/YP everywhere the term "domain name" is
mentioned.  Updated patch below.

>> What do you think?  I noticed that I had been using getdomainname()
>> for a while
>
> What have you been using it for? Are you maintaining the 'ypcat' program?

No, I'm using it to guess the Kerberos realm for the local host, when
the user didn't supplied one.  I can imagine people running NIS and
Kerberos realm named the same, and for people not running NIS, it will
return NULL (or the string "(none)" (sic!) as it does on my Debian
box).  If the NIS domain isn't set, I'm using the hostname.

Index: MODULES.html.sh
===================================================================
RCS file: /cvsroot/gnulib/gnulib/MODULES.html.sh,v
retrieving revision 1.38
diff -u -p -r1.38 MODULES.html.sh
--- MODULES.html.sh     17 Sep 2003 10:10:55 -0000      1.38
+++ MODULES.html.sh     24 Sep 2003 23:12:39 -0000
@@ -1822,6 +1822,8 @@ func_all_modules ()
   func_begin_table
   func_module gethostname
   func_module xgethostname
+  func_module getdomainname
+  func_module xgetdomainname
   func_module canon-host
   func_end_table
 
Index: lib/getdomainname.c
===================================================================
RCS file: lib/getdomainname.c
diff -N lib/getdomainname.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/getdomainname.c 24 Sep 2003 23:12:39 -0000
@@ -0,0 +1,38 @@
+/* getdomainname emulation for systems that doesn't have it.
+   Copyright (C) 2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+/* written by Simon Josefsson */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/* Get specification. */
+#include "getdomainname.h"
+
+/* Get strcpy. */
+#include <string.h>
+
+/* Put up to LEN chars of the NIS/YP domain name into NAME.
+   Null terminate it if the name is shorter than LEN.
+   Return 0 if ok, -1 if error.  */
+int
+getdomainname (char *name, size_t len)
+{
+  strcpy (name, "");           /* Hardcode your domain name if you want.  */
+  return 0;
+}
Index: lib/getdomainname.h
===================================================================
RCS file: lib/getdomainname.h
diff -N lib/getdomainname.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/getdomainname.h 24 Sep 2003 23:12:39 -0000
@@ -0,0 +1,35 @@
+/* getdomainname emulation for systems that doesn't have it.
+   Copyright (C) 2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#ifndef _GETDOMAINNAME_H
+#define _GETDOMAINNAME_H
+
+#if HAVE_GETDOMAINNAME
+
+/* Get getdomainname() declarations.  */
+# include <unistd.h>
+
+#else
+
+/* Put up to LEN chars of the NIS/YP domain name into NAME.
+   Null terminate it if the name is shorter than LEN.
+   Return 0 if ok, -1 if error.  */
+extern int getdomainname(char *name, size_t len);
+
+#endif /* HAVE_GETDOMAINNAME */
+
+#endif /* _GETDOMAINNAME_H */
Index: lib/xgetdomainname.c
===================================================================
RCS file: lib/xgetdomainname.c
diff -N lib/xgetdomainname.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/xgetdomainname.c        24 Sep 2003 23:12:39 -0000
@@ -0,0 +1,72 @@
+/* xgetdomainname.c -- return current NIS/YP domain name with unlimited length
+   Copyright (C) 1992, 1996, 2000, 2001, 2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+/* based on xgethostname.c written by Jim Meyering */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/* Specification.  */
+#include "xgetdomainname.h"
+
+/* Get getdomainname.  */
+#include "getdomainname.h"
+
+/* Get errno.  */
+#include <errno.h>
+
+#include "xalloc.h"
+
+#ifndef INITIAL_DOMAINNAME_LENGTH
+# define INITIAL_DOMAINNAME_LENGTH 34
+#endif
+
+/* Return the current NIS/YP domain name in malloc'd storage.
+   If malloc fails, exit.
+   Upon any other failure, return NULL.  */
+char *
+xgetdomainname (void)
+{
+  char *domainname;
+  size_t size;
+
+  size = INITIAL_DOMAINNAME_LENGTH;
+  domainname = xmalloc (size);
+  while (1)
+    {
+      int k = size - 1;
+      int err;
+
+      errno = 0;
+      domainname[k] = '\0';
+      err = getdomainname (domainname, size);
+      if (err >= 0 && domainname[k] == '\0')
+       break;
+      else if (err < 0 && errno != EINVAL)
+       {
+         int saved_errno = errno;
+         free (domainname);
+         errno = saved_errno;
+         return NULL;
+       }
+      size *= 2;
+      domainname = xrealloc (domainname, size);
+    }
+
+  return domainname;
+}
Index: lib/xgetdomainname.h
===================================================================
RCS file: lib/xgetdomainname.h
diff -N lib/xgetdomainname.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/xgetdomainname.h        24 Sep 2003 23:12:39 -0000
@@ -0,0 +1,26 @@
+/* xgetdomainname.h -- return current NIS/YP domain name with unlimited length
+   Copyright (C) 1992, 1996, 2000, 2001, 2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#ifndef _XGETDOMAINNAME_H
+#define _XGETDOMAINNAME_H
+
+/* Return the current NIS/YP domain name in malloc'd storage.
+   If malloc fails, exit.
+   Upon any other failure, return NULL.  */
+extern char *xgetdomainname (void);
+
+#endif /* _XGETDOMAINNAME_H */
Index: m4/getdomainname.m4
===================================================================
RCS file: m4/getdomainname.m4
diff -N m4/getdomainname.m4
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ m4/getdomainname.m4 24 Sep 2003 23:12:39 -0000
@@ -0,0 +1,23 @@
+# getdomainname.m4 serial 1
+dnl Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License.  As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+AC_DEFUN([gl_FUNC_GETDOMAINNAME],
+[
+  dnl Persuade glibc <unistd.h> to declare getdomainname().
+  AC_REQUIRE([AC_GNU_SOURCE])
+
+  AC_REPLACE_FUNCS(getdomainname)
+  if test $ac_cv_func_getdomainname = no; then
+    gl_PREREQ_GETDOMAINNAME
+  fi
+])
+
+# Prerequisites of lib/getdomainname.c.
+AC_DEFUN([gl_PREREQ_GETDOMAINNAME], [
+  :
+])
Index: modules/getdomainname
===================================================================
RCS file: modules/getdomainname
diff -N modules/getdomainname
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ modules/getdomainname       24 Sep 2003 23:12:41 -0000
@@ -0,0 +1,21 @@
+Description:
+getdomainname() function: Return machine's NIS/YP domain name.
+
+Files:
+lib/getdomainname.h
+lib/getdomainname.c
+m4/getdomainname.m4
+
+Depends-on:
+
+configure.ac:
+gl_FUNC_GETDOMAINNAME
+
+Makefile.am:
+libfoo_la_SOURCES += getdomainname.h
+
+Include:
+
+Maintainer:
+all
+
Index: modules/xgetdomainname
===================================================================
RCS file: modules/xgetdomainname
diff -N modules/xgetdomainname
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ modules/xgetdomainname      24 Sep 2003 23:12:41 -0000
@@ -0,0 +1,20 @@
+Description:
+Return machine's domainname, without size limitations.
+
+Files:
+lib/xgetdomainname.h
+lib/xgetdomainname.c
+
+Depends-on:
+getdomainname
+xalloc
+
+configure.ac:
+
+Makefile.am:
+lib_SOURCES += xgetdomainname.h xgetdomainname.c
+
+Include:
+
+Maintainer:
+Simon Josefsson





reply via email to

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