bug-gnulib
[Top][All Lists]
Advanced

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

getpass: move declaration to <unistd.h>


From: Bruno Haible
Subject: getpass: move declaration to <unistd.h>
Date: Sun, 19 Aug 2018 14:19:24 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-130-generic; KDE/5.18.0; x86_64; ; )

The 'getpass' module provides a replacement for a glibc function.
In glibc the header file for this function is <unistd.h>. In gnulib,
so far, the user has to include "getpass.h" instead - simply because
this module predates the 'unistd' module.

This patch moves the declaration into <unistd.h>, to match glibc.


2018-08-19  Bruno Haible  <address@hidden>

        getpass: Move declaration to <unistd.h>.
        * lib/unistd.in.h (getpass): New declaration.
        * lib/getpass.h: Replace with a stub that just includes <unistd.h>.
        * m4/getpass.m4 (gl_FUNC_GETPASS): Declare through AC_DEFUN_ONCE.
        Require gl_UNISTD_H_DEFAULTS. Don't test whether getpass is declared.
        (gl_FUNC_GETPASS_GNU): Require gl_UNISTD_H_DEFAULTS and gl_FUNC_GETPASS.
        On glibc systems, don't set REPLACE_GETPASS to 1.
        * modules/getpass (Depends-on): Add 'unistd'.
        (configure.ac): Test also REPLACE_GETPASS. Define a module indicator.
        (Include): Specify <unistd.h> instead of "getpass.h".
        * modules/getpass-gnu (Depends-on): Merely depend on 'getpass'.
        (configure.ac): Sync with the configure.ac section of modules/getpass.
        (Include): Specify <unistd.h> instead of "getpass.h".
        * m4/unistd_h.m4 (gl_UNISTD_H): Test whether getpass is declared.
        (gl_UNISTD_H_DEFAULTS): Initialize GNULIB_GETPASS, HAVE_GETPASS,
        REPLACE_GETPASS.
        * modules/unistd (Makefile.am): Substitute GNULIB_GETPASS, HAVE_GETPASS,
        REPLACE_GETPASS.
        * tests/test-unistd-c++.cc: Test also the declaration of 'getpass'.
        * doc/glibc-functions/getpass.texi: A length limit exists also on uClibc
        and musl.
        * NEWS: Mention the change.

diff --git a/NEWS b/NEWS
index 1328e73..e763c91 100644
--- a/NEWS
+++ b/NEWS
@@ -42,6 +42,9 @@ User visible incompatible changes
 
 Date        Modules         Changes
 
+2018-08-18  getpass         The include file is changed from "getpass.h" to
+            getpass-gnu     <unistd.h>.
+
 2018-07-17  hard-locale     m4/hard-locale.m4 and gl_HARD_LOCALE are removed.
 
 2018-07-05  renameat2       This module is renamed to 'renameatu' and all
diff --git a/doc/glibc-functions/getpass.texi b/doc/glibc-functions/getpass.texi
index 202cf95..932fab7 100644
--- a/doc/glibc-functions/getpass.texi
+++ b/doc/glibc-functions/getpass.texi
@@ -15,7 +15,7 @@ Portability problems fixed by Gnulib module 
@code{getpass-gnu}:
 @itemize
 @item
 The returned password is truncated to PASS_MAX characters on some platforms:
-Mac OS X 10.5 (128), FreeBSD 6.2 (128), NetBSD 3.0 (128), OpenBSD 4.0 (128), 
AIX 5.1 (32), HP-UX 11 (8), IRIX 6.5 (32), OSF/1 5.1 (80), Solaris 11 2010-11 
(8, even less than PASS_MAX), Cygwin (128).
+uClibc (256), musl (128), Mac OS X 10.5 (128), FreeBSD 6.2 (128), NetBSD 3.0 
(128), OpenBSD 4.0 (128), AIX 5.1 (32), HP-UX 11 (8), IRIX 6.5 (32), OSF/1 5.1 
(80), Solaris 11 2010-11 (8, even less than PASS_MAX), Cygwin (128).
 The gnulib implementation returns the password untruncated.
 @end itemize
 
diff --git a/lib/getpass.h b/lib/getpass.h
index e07e73b..3daa1b6 100644
--- a/lib/getpass.h
+++ b/lib/getpass.h
@@ -1,30 +1,4 @@
-/* getpass.h -- Read a password of arbitrary length from /dev/tty or stdin.
-   Copyright (C) 2004, 2009-2018 Free Software Foundation, Inc.
-   Contributed by Simon Josefsson <address@hidden>, 2004.
-
-   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, see <https://www.gnu.org/licenses/>.  */
-
-#ifndef GETPASS_H
-# define GETPASS_H
+/* Obsolete; consider using unistd.h instead.  */
 
 /* Get getpass declaration, if available.  */
-# include <unistd.h>
-
-# if !HAVE_DECL_GETPASS
-/* Read a password of arbitrary length from /dev/tty or stdin.  */
-char *getpass (const char *prompt);
-
-# endif
-
-#endif /* GETPASS_H */
+#include <unistd.h>
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index 8098291..7a14551 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -935,6 +935,36 @@ _GL_WARN_ON_USE (getpagesize, "getpagesize is unportable - 
"
 #endif
 
 
+#if @GNULIB_GETPASS@
+/* Function getpass() from module 'getpass':
+     Read a password from /dev/tty or stdin.
+   Function getpass() from module 'getpass-gnu':
+     Read a password of arbitrary length from /dev/tty or stdin.  */
+# if @REPLACE_GETPASS@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef getpass
+#   define getpass rpl_getpass
+#  endif
+_GL_FUNCDECL_RPL (getpass, char *, (const char *prompt)
+                                   _GL_ARG_NONNULL ((1)));
+_GL_CXXALIAS_RPL (getpass, char *, (const char *prompt));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (getpass, char *, (const char *prompt)
+                                   _GL_ARG_NONNULL ((1)));
+#  endif
+_GL_CXXALIAS_SYS (getpass, char *, (const char *prompt));
+# endif
+_GL_CXXALIASWARN (getpass);
+#elif defined GNULIB_POSIXCHECK
+# undef getpass
+# if HAVE_RAW_DECL_GETPASS
+_GL_WARN_ON_USE (getpass, "getpass is unportable - "
+                 "use gnulib module getpass or getpass-gnu for portability");
+# endif
+#endif
+
+
 #if @GNULIB_GETUSERSHELL@
 /* Return the next valid login shell on the system, or NULL when the end of
    the list has been reached.  */
diff --git a/m4/getpass.m4 b/m4/getpass.m4
index 7f3fc88..b0b4278 100644
--- a/m4/getpass.m4
+++ b/m4/getpass.m4
@@ -1,4 +1,4 @@
-# getpass.m4 serial 15
+# getpass.m4 serial 16
 dnl Copyright (C) 2002-2003, 2005-2006, 2009-2018 Free Software Foundation,
 dnl Inc.
 dnl This file is free software; the Free Software Foundation
@@ -6,16 +6,15 @@ dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
 
 # Provide a getpass() function if the system doesn't have it.
-AC_DEFUN([gl_FUNC_GETPASS],
+AC_DEFUN_ONCE([gl_FUNC_GETPASS],
 [
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+
   dnl Persuade Solaris <unistd.h> and <stdlib.h> to declare getpass().
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
 
-  AC_CHECK_FUNCS([getpass])
-  AC_CHECK_DECLS_ONCE([getpass])
-  if test $ac_cv_func_getpass = yes; then
-    HAVE_GETPASS=1
-  else
+  AC_CHECK_FUNCS_ONCE([getpass])
+  if test $ac_cv_func_getpass = no; then
     HAVE_GETPASS=0
   fi
 ])
@@ -24,19 +23,27 @@ AC_DEFUN([gl_FUNC_GETPASS],
 # arbitrary length (not just 8 bytes as on HP-UX).
 AC_DEFUN([gl_FUNC_GETPASS_GNU],
 [
-  dnl Persuade Solaris <unistd.h> and <stdlib.h> to declare getpass().
-  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
-
-  AC_CHECK_DECLS_ONCE([getpass])
-  dnl TODO: Detect when GNU getpass() is already found in glibc.
-  REPLACE_GETPASS=1
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_REQUIRE([gl_FUNC_GETPASS])
 
-  if test $REPLACE_GETPASS = 1; then
-    dnl We must choose a different name for our function, since on ELF systems
-    dnl an unusable getpass() in libc.so would override our getpass() if it is
-    dnl compiled into a shared library.
-    AC_DEFINE([getpass], [gnu_getpass],
-      [Define to a replacement function name for getpass().])
+  if test $ac_cv_func_getpass = yes; then
+    AC_CACHE_CHECK([for getpass without length limitations],
+      [gl_cv_func_getpass_good],
+      [AC_EGREP_CPP([Lucky GNU user],
+         [
+#include <features.h>
+#ifdef __GNU_LIBRARY__
+ #if (__GLIBC__ >= 2) && !defined __UCLIBC__
+  Lucky GNU user
+ #endif
+#endif
+         ],
+         [gl_cv_func_getpass_good=yes],
+         [gl_cv_func_getpass_good=no])
+      ])
+    if test $gl_cv_func_getpass_good != yes; then
+      REPLACE_GETPASS=1
+    fi
   fi
 ])
 
diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4
index 159c48a..3ba64da 100644
--- a/m4/unistd_h.m4
+++ b/m4/unistd_h.m4
@@ -1,4 +1,4 @@
-# unistd_h.m4 serial 73
+# unistd_h.m4 serial 74
 dnl Copyright (C) 2006-2018 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -43,7 +43,7 @@ AC_DEFUN([gl_UNISTD_H],
 #endif
     ]], [chdir chown dup dup2 dup3 environ euidaccess faccessat fchdir fchownat
     fdatasync fsync ftruncate getcwd getdomainname getdtablesize getgroups
-    gethostname getlogin getlogin_r getpagesize
+    gethostname getlogin getlogin_r getpagesize getpass
     getusershell setusershell endusershell
     group_member isatty lchown link linkat lseek pipe pipe2 pread pwrite
     readlink readlinkat rmdir sethostname sleep symlink symlinkat
@@ -83,6 +83,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   GNULIB_GETLOGIN=0;             AC_SUBST([GNULIB_GETLOGIN])
   GNULIB_GETLOGIN_R=0;           AC_SUBST([GNULIB_GETLOGIN_R])
   GNULIB_GETPAGESIZE=0;          AC_SUBST([GNULIB_GETPAGESIZE])
+  GNULIB_GETPASS=0;              AC_SUBST([GNULIB_GETPASS])
   GNULIB_GETUSERSHELL=0;         AC_SUBST([GNULIB_GETUSERSHELL])
   GNULIB_GROUP_MEMBER=0;         AC_SUBST([GNULIB_GROUP_MEMBER])
   GNULIB_ISATTY=0;               AC_SUBST([GNULIB_ISATTY])
@@ -126,6 +127,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   HAVE_GETHOSTNAME=1;     AC_SUBST([HAVE_GETHOSTNAME])
   HAVE_GETLOGIN=1;        AC_SUBST([HAVE_GETLOGIN])
   HAVE_GETPAGESIZE=1;     AC_SUBST([HAVE_GETPAGESIZE])
+  HAVE_GETPASS=1;         AC_SUBST([HAVE_GETPASS])
   HAVE_GROUP_MEMBER=1;    AC_SUBST([HAVE_GROUP_MEMBER])
   HAVE_LCHOWN=1;          AC_SUBST([HAVE_LCHOWN])
   HAVE_LINK=1;            AC_SUBST([HAVE_LINK])
@@ -168,6 +170,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   REPLACE_GETLOGIN_R=0;   AC_SUBST([REPLACE_GETLOGIN_R])
   REPLACE_GETGROUPS=0;    AC_SUBST([REPLACE_GETGROUPS])
   REPLACE_GETPAGESIZE=0;  AC_SUBST([REPLACE_GETPAGESIZE])
+  REPLACE_GETPASS=0;      AC_SUBST([REPLACE_GETPASS])
   REPLACE_ISATTY=0;       AC_SUBST([REPLACE_ISATTY])
   REPLACE_LCHOWN=0;       AC_SUBST([REPLACE_LCHOWN])
   REPLACE_LINK=0;         AC_SUBST([REPLACE_LINK])
diff --git a/modules/getpass b/modules/getpass
index c1cbc25..29918b9 100644
--- a/modules/getpass
+++ b/modules/getpass
@@ -7,6 +7,7 @@ lib/getpass.c
 m4/getpass.m4
 
 Depends-on:
+unistd
 extensions
 fseeko
 getline
@@ -15,15 +16,16 @@ strdup-posix
 
 configure.ac:
 gl_FUNC_GETPASS
-if test $HAVE_GETPASS = 0; then
+if test $HAVE_GETPASS = 0 || test $REPLACE_GETPASS = 1; then
   AC_LIBOBJ([getpass])
   gl_PREREQ_GETPASS
 fi
+gl_UNISTD_MODULE_INDICATOR([getpass])
 
 Makefile.am:
 
 Include:
-"getpass.h"
+<unistd,h>
 
 License:
 LGPLv2+
diff --git a/modules/getpass-gnu b/modules/getpass-gnu
index cd83015..2c9f76e 100644
--- a/modules/getpass-gnu
+++ b/modules/getpass-gnu
@@ -7,21 +7,20 @@ lib/getpass.c
 m4/getpass.m4
 
 Depends-on:
-fseeko
-getline
-stdbool
+getpass
 
 configure.ac:
 gl_FUNC_GETPASS_GNU
-if test $REPLACE_GETPASS = 1; then
+if test $HAVE_GETPASS = 0 || test $REPLACE_GETPASS = 1; then
   AC_LIBOBJ([getpass])
   gl_PREREQ_GETPASS
 fi
+gl_UNISTD_MODULE_INDICATOR([getpass])
 
 Makefile.am:
 
 Include:
-"getpass.h"
+<unistd.h>
 
 License:
 LGPL
diff --git a/modules/unistd b/modules/unistd
index 25bf9fa..fc1a27f 100644
--- a/modules/unistd
+++ b/modules/unistd
@@ -58,6 +58,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H
              -e 's/@''GNULIB_GETLOGIN''@/$(GNULIB_GETLOGIN)/g' \
              -e 's/@''GNULIB_GETLOGIN_R''@/$(GNULIB_GETLOGIN_R)/g' \
              -e 's/@''GNULIB_GETPAGESIZE''@/$(GNULIB_GETPAGESIZE)/g' \
+             -e 's/@''GNULIB_GETPASS''@/$(GNULIB_GETPASS)/g' \
              -e 's/@''GNULIB_GETUSERSHELL''@/$(GNULIB_GETUSERSHELL)/g' \
              -e 's/@''GNULIB_GROUP_MEMBER''@/$(GNULIB_GROUP_MEMBER)/g' \
              -e 's/@''GNULIB_ISATTY''@/$(GNULIB_ISATTY)/g' \
@@ -101,6 +102,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H
              -e 's|@''HAVE_GETGROUPS''@|$(HAVE_GETGROUPS)|g' \
              -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \
              -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \
+             -e 's|@''HAVE_GETPASS''@|$(HAVE_GETPASS)|g' \
              -e 's|@''HAVE_GROUP_MEMBER''@|$(HAVE_GROUP_MEMBER)|g' \
              -e 's|@''HAVE_LCHOWN''@|$(HAVE_LCHOWN)|g' \
              -e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \
@@ -144,6 +146,7 @@ unistd.h: unistd.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H
              -e 's|@''REPLACE_GETLOGIN_R''@|$(REPLACE_GETLOGIN_R)|g' \
              -e 's|@''REPLACE_GETGROUPS''@|$(REPLACE_GETGROUPS)|g' \
              -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \
+             -e 's|@''REPLACE_GETPASS''@|$(REPLACE_GETPASS)|g' \
              -e 's|@''REPLACE_ISATTY''@|$(REPLACE_ISATTY)|g' \
              -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \
              -e 's|@''REPLACE_LINK''@|$(REPLACE_LINK)|g' \
diff --git a/tests/test-unistd-c++.cc b/tests/test-unistd-c++.cc
index d7fee3a..e446158 100644
--- a/tests/test-unistd-c++.cc
+++ b/tests/test-unistd-c++.cc
@@ -110,6 +110,10 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::getlogin_r, int, (char 
*, size_t));
 SIGNATURE_CHECK (GNULIB_NAMESPACE::getpagesize, int, (void));
 #endif
 
+#if GNULIB_TEST_GETPASS
+SIGNATURE_CHECK (GNULIB_NAMESPACE::getpass, char *, (const char *));
+#endif
+
 #if GNULIB_TEST_GETUSERSHELL
 SIGNATURE_CHECK (GNULIB_NAMESPACE::getusershell, char *, (void));
 #endif




reply via email to

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