From 3d8634f17142fd4b12440c79ed4226ba6199f7dc Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 19 Aug 2018 14:14:17 +0200 Subject: [PATCH] getpass: Move declaration to . * lib/unistd.in.h (getpass): New declaration. * lib/getpass.h: Replace with a stub that just includes . * 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 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 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. --- ChangeLog | 25 ++++++++++++++++++ NEWS | 3 +++ doc/glibc-functions/getpass.texi | 2 +- lib/getpass.h | 30 ++------------------- lib/unistd.in.h | 30 +++++++++++++++++++++ m4/getpass.m4 | 45 ++++++++++++++++++-------------- m4/unistd_h.m4 | 7 +++-- modules/getpass | 6 +++-- modules/getpass-gnu | 9 +++---- modules/unistd | 3 +++ tests/test-unistd-c++.cc | 4 +++ 11 files changed, 107 insertions(+), 57 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0799bd31d0..7d20b21ce9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,28 @@ +2018-08-19 Bruno Haible + + getpass: Move declaration to . + * lib/unistd.in.h (getpass): New declaration. + * lib/getpass.h: Replace with a stub that just includes . + * 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 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 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. + 2018-08-19 Bruno Haible glob: Fix over-optimization due to attribute __nonnull__. diff --git a/NEWS b/NEWS index 1328e73246..e763c91a8a 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 . + 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 202cf95b2d..932fab7ea4 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 e07e73bcab..3daa1b63ff 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 , 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 . */ - -#ifndef GETPASS_H -# define GETPASS_H +/* Obsolete; consider using unistd.h instead. */ /* Get getpass declaration, if available. */ -# include - -# 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 diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 8098291ae1..7a145514c6 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 !@HAVE_GETPASS@ +_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 7f3fc88c7e..b0b427816f 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 and 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 and 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 +#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 159c48aeef..3ba64da8a0 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 c1cbc25574..29918b9755 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" + License: LGPLv2+ diff --git a/modules/getpass-gnu b/modules/getpass-gnu index cd83015ee6..2c9f76e3ff 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" + License: LGPL diff --git a/modules/unistd b/modules/unistd index 25bf9fa6ab..fc1a27fe12 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 d7fee3a47f..e4461588c4 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 -- 2.39.5