[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCHv2 2/2] pt_chown: break gnulib link dependency
From: |
Eric Blake |
Subject: |
[PATCHv2 2/2] pt_chown: break gnulib link dependency |
Date: |
Wed, 19 Oct 2011 18:01:40 -0600 |
If pt_chown calls ptsname(), then it must pull in gnulib; but then
we must decide whether libtool is in use (libgnu.a vs. libgnu.la).
Simpler is just shifting the burden to the sole caller. Even though
this breaks compatibility with glibc pt_chown, we already document
that our helper app is only conditionally built; and since it lives
in pkglibexecdir, no one else should be calling it, anyways.
* lib/pt_chown.c (main, do_pt_chown): Require pty name as argument.
* lib/grantpt.c (grantpt): Update caller.
* modules/grantpt (Makefile.am): Simplify LDADD accordingly.
* NEWS: Document the call convention change.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 8 ++++++++
NEWS | 3 ++-
lib/grantpt.c | 7 ++++++-
lib/pt_chown.c | 26 +++++++++++---------------
modules/grantpt | 1 -
5 files changed, 27 insertions(+), 18 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 611ff0f..bcb9a75 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2011-10-19 Eric Blake <address@hidden>
+ pt_chown: break gnulib link dependency
+ * lib/pt_chown.c (main, do_pt_chown): Require pty name as argument.
+ * lib/grantpt.c (grantpt): Update caller.
+ * modules/grantpt (Makefile.am): Simplify LDADD accordingly.
+ * NEWS: Document the call convention change.
+
grantpt: only build pt_chown when needed
* modules/pt_chown: Delete, merging into...
* modules/grantpt: ...its sole user. Make building of pt_chown
diff --git a/NEWS b/NEWS
index 493a25b..0bff6a7 100644
--- a/NEWS
+++ b/NEWS
@@ -15,7 +15,8 @@ Date Modules Changes
2011-10-19 pt_chown This module no longer exists. The helper
application pt_chown is now only built if needed
for the 'grantpt' module, since it has no use
- as a stand-alone application.
+ as a stand-alone application; also, it
+ intentionally differs from glibc's pt_chown.
2011-10-03 poll The link requirements of this module are changed
from empty to $(LIB_POLL).
diff --git a/lib/grantpt.c b/lib/grantpt.c
index 985e31d..1398026 100644
--- a/lib/grantpt.c
+++ b/lib/grantpt.c
@@ -55,6 +55,10 @@ grantpt (int fd)
else if (pid == 0)
{
/* This is executed in the child process. */
+ char *pty;
+ pty = ptsname (PTY_FILENO);
+ if (pty == NULL)
+ _exit (errno == EBADF ? FAIL_EBADF : FAIL_EINVAL);
#if HAVE_SETRLIMIT && defined RLIMIT_CORE
/* Disable core dumps. */
@@ -71,7 +75,8 @@ grantpt (int fd)
CLOSE_ALL_FDS ();
#endif
- execle (_PATH_PT_CHOWN, strrchr (_PATH_PT_CHOWN, '/') + 1, NULL, NULL);
+ execle (_PATH_PT_CHOWN, strrchr (_PATH_PT_CHOWN, '/') + 1, pty, NULL,
+ NULL);
_exit (FAIL_EXEC);
}
else
diff --git a/lib/pt_chown.c b/lib/pt_chown.c
index ccc04fd..f654b2d 100644
--- a/lib/pt_chown.c
+++ b/lib/pt_chown.c
@@ -30,22 +30,18 @@
/* For security reasons, we try to minimize the dependencies on libraries
outside libc. This means, in particular:
- No use of gettext(), since it's usually implemented in libintl.
- - No use of error() or argp, since they rely on gettext by default. */
+ - No use of error() or argp, since they rely on gettext by default.
+ - No use of ptsname(), since this implementation is only compiled
+ by gnulib, which implies ptsname is also implemented by gnulib. */
static int
-do_pt_chown (void)
+do_pt_chown (char *pty)
{
- char *pty;
struct stat st;
struct group *p;
gid_t gid;
- /* Check that PTY_FILENO is a valid master pseudo terminal. */
- pty = ptsname (PTY_FILENO);
- if (pty == NULL)
- return errno == EBADF ? FAIL_EBADF : FAIL_EINVAL;
-
/* Check that the returned slave pseudo terminal is a
character device. */
if (stat (pty, &st) < 0 || !S_ISCHR (st.st_mode))
@@ -75,11 +71,11 @@ main (int argc, char *argv[])
{
uid_t euid = geteuid ();
- if (argc == 1 && euid == 0)
+ if (argc == 2 && argv[1][0] != '-' && euid == 0)
{
/* Normal invocation of this program is with no arguments and
with privileges. */
- return do_pt_chown ();
+ return do_pt_chown (argv[1]);
}
/* It would be possible to drop setuid/setgid privileges here. But it is not
@@ -123,11 +119,11 @@ main (int argc, char *argv[])
if (do_help)
{
- printf ("Usage: pt_chown [OPTION...]\n");
+ printf ("Usage: pt_chown [OPTION...] PTSNAME\n");
printf ("Set the owner, group and access permission of the slave
pseudo terminal\n"
- "corresponding to the master pseudo terminal passed on file
descriptor %d.\n"
- "This is the helper program for the 'grantpt' function. It is
not intended\n"
- "to be run directly from the command line.\n",
+ "PTSNAME corresponding to the master pseudo terminal passed on
file\n"
+ "descriptor %d. This is the helper program for the 'grantpt'
function.\n"
+ "It is not intended to be run directly from the command
line.\n",
PTY_FILENO);
printf ("\n");
printf (" --help Give this help list\n");
@@ -146,7 +142,7 @@ main (int argc, char *argv[])
printf ("Copyright (C) %s Free Software Foundation, Inc.\n"
"This is free software; see the source for copying conditions.
There is NO\n"
"warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.\n",
- "1999");
+ "2011");
return EXIT_SUCCESS;
}
}
diff --git a/modules/grantpt b/modules/grantpt
index c8b41ac..3dec876 100644
--- a/modules/grantpt
+++ b/modules/grantpt
@@ -27,7 +27,6 @@ Makefile.am:
if GL_GENERATE_PT_CHOWN
# TODO: Add rules for installing as setuid root (chown root, chmod a=rx,u+s).
pkglibexec_PROGRAMS = pt_chown
-pt_chown_LDADD = libgnu.a
else
EXTRA_DIST += pt_chown.c
endif
--
1.7.4.4
- license relaxation request, Eric Blake, 2011/10/17
- Re: license relaxation request, Bruno Haible, 2011/10/17
- Re: pt_chown build failure, Bruno Haible, 2011/10/19
- Re: pt_chown build failure, Eric Blake, 2011/10/19
- [PATCHv2 1/2] grantpt: only build pt_chown when needed, Eric Blake, 2011/10/19
- [PATCHv2 2/2] pt_chown: break gnulib link dependency,
Eric Blake <=
- Re: [PATCHv2 2/2] pt_chown: break gnulib link dependency, Bruno Haible, 2011/10/20
- Re: [PATCHv2 1/2] grantpt: only build pt_chown when needed, Bruno Haible, 2011/10/20
- Re: license relaxation request, Bruno Haible, 2011/10/19
- Re: license relaxation request, Eric Blake, 2011/10/19
- Re: license relaxation request, Simon Josefsson, 2011/10/20