mirror of
https://git.savannah.gnu.org/git/gnulib.git
synced 2025-08-08 17:22:05 +03:00
root-uid: new module
This is for portability to Tandem's NonStop Kernel. * lib/root-uid.h, modules/root-uid: New files. * lib/euidaccess.c, lib/pt_chown.c, lib/unlinkdir.c: * lib/write-any-file.c, tests/test-sethostname2.c: Include "root-uid.h". * lib/euidaccess.c (euidaccess): * lib/pt_chown.c (main): * lib/unlinkdir.c (cannot_unlink_dir): * lib/write-any-file.c (can_write_any_file): * m4/mknod.m4 (gl_FUNC_MKNOD): * tests/test-sethostname2.c (geteuid, main): Don't assume ROOT_UID == 0. * modules/euidaccess (Depends-on): * modules/pt_chown (Depends-on): * modules/sethostname-tests (Depends-on): * modules/unlinkdir (Depends-on): * modules/write-any-file (Depends-on): Add root-uid.
This commit is contained in:
20
ChangeLog
20
ChangeLog
@@ -1,5 +1,25 @@
|
|||||||
2012-06-26 Paul Eggert <eggert@cs.ucla.edu>
|
2012-06-26 Paul Eggert <eggert@cs.ucla.edu>
|
||||||
|
|
||||||
|
root-uid: new module
|
||||||
|
This is for portability to Tandem's NonStop Kernel.
|
||||||
|
* lib/root-uid.h, modules/root-uid: New files.
|
||||||
|
* lib/euidaccess.c, lib/pt_chown.c, lib/unlinkdir.c:
|
||||||
|
* lib/write-any-file.c, tests/test-sethostname2.c:
|
||||||
|
Include "root-uid.h".
|
||||||
|
* lib/euidaccess.c (euidaccess):
|
||||||
|
* lib/pt_chown.c (main):
|
||||||
|
* lib/unlinkdir.c (cannot_unlink_dir):
|
||||||
|
* lib/write-any-file.c (can_write_any_file):
|
||||||
|
* m4/mknod.m4 (gl_FUNC_MKNOD):
|
||||||
|
* tests/test-sethostname2.c (geteuid, main):
|
||||||
|
Don't assume ROOT_UID == 0.
|
||||||
|
* modules/euidaccess (Depends-on):
|
||||||
|
* modules/pt_chown (Depends-on):
|
||||||
|
* modules/sethostname-tests (Depends-on):
|
||||||
|
* modules/unlinkdir (Depends-on):
|
||||||
|
* modules/write-any-file (Depends-on):
|
||||||
|
Add root-uid.
|
||||||
|
|
||||||
regex: use locale-independent comparison for codeset name
|
regex: use locale-independent comparison for codeset name
|
||||||
See Bruno Haible's comment in <http://bugs.gnu.org/10305#120>.
|
See Bruno Haible's comment in <http://bugs.gnu.org/10305#120>.
|
||||||
* lib/regcomp.c (init_dfa): Use just ASCII case comparison
|
* lib/regcomp.c (init_dfa): Use just ASCII case comparison
|
||||||
|
@@ -30,6 +30,8 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "root-uid.h"
|
||||||
|
|
||||||
#if HAVE_LIBGEN_H
|
#if HAVE_LIBGEN_H
|
||||||
# include <libgen.h>
|
# include <libgen.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -140,8 +142,9 @@ euidaccess (const char *file, int mode)
|
|||||||
|
|
||||||
/* The super-user can read and write any file, and execute any file
|
/* The super-user can read and write any file, and execute any file
|
||||||
that anyone can execute. */
|
that anyone can execute. */
|
||||||
if (euid == 0 && ((mode & X_OK) == 0
|
if (euid == ROOT_UID
|
||||||
|| (stats.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))))
|
&& ((mode & X_OK) == 0
|
||||||
|
|| (stats.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Convert the mode to traditional form, clearing any bogus bits. */
|
/* Convert the mode to traditional form, clearing any bogus bits. */
|
||||||
|
@@ -25,6 +25,8 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "root-uid.h"
|
||||||
|
|
||||||
#include "pty-private.h"
|
#include "pty-private.h"
|
||||||
|
|
||||||
/* For security reasons, we try to minimize the dependencies on libraries
|
/* For security reasons, we try to minimize the dependencies on libraries
|
||||||
@@ -75,7 +77,7 @@ main (int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
uid_t euid = geteuid ();
|
uid_t euid = geteuid ();
|
||||||
|
|
||||||
if (argc == 1 && euid == 0)
|
if (argc == 1 && euid == ROOT_UID)
|
||||||
{
|
{
|
||||||
/* Normal invocation of this program is with no arguments and
|
/* Normal invocation of this program is with no arguments and
|
||||||
with privileges. */
|
with privileges. */
|
||||||
@@ -152,7 +154,7 @@ main (int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check if we are properly installed. */
|
/* Check if we are properly installed. */
|
||||||
if (euid != 0)
|
if (euid != ROOT_UID)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "pt_chown: needs to be installed setuid 'root'\n");
|
fprintf (stderr, "pt_chown: needs to be installed setuid 'root'\n");
|
||||||
return FAIL_EXEC;
|
return FAIL_EXEC;
|
||||||
|
30
lib/root-uid.h
Normal file
30
lib/root-uid.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/* The user ID that always has appropriate privileges in the POSIX sense.
|
||||||
|
|
||||||
|
Copyright 2012 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 3 of the License, 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Written by Paul Eggert. */
|
||||||
|
|
||||||
|
#ifndef ROOT_UID_H_
|
||||||
|
#define ROOT_UID_H_
|
||||||
|
|
||||||
|
/* The user ID that always has appropriate privileges in the POSIX sense. */
|
||||||
|
#ifdef __TANDEM
|
||||||
|
# define ROOT_UID 65535
|
||||||
|
#else
|
||||||
|
# define ROOT_UID 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "unlinkdir.h"
|
#include "unlinkdir.h"
|
||||||
#include "priv-set.h"
|
#include "priv-set.h"
|
||||||
|
#include "root-uid.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#if ! UNLINK_CANNOT_UNLINK_DIR
|
#if ! UNLINK_CANNOT_UNLINK_DIR
|
||||||
@@ -43,7 +44,7 @@ cannot_unlink_dir (void)
|
|||||||
cannot = (priv_set_ismember (PRIV_SYS_LINKDIR) == 0);
|
cannot = (priv_set_ismember (PRIV_SYS_LINKDIR) == 0);
|
||||||
# else
|
# else
|
||||||
/* In traditional Unix, only root can unlink directories. */
|
/* In traditional Unix, only root can unlink directories. */
|
||||||
cannot = (geteuid () != 0);
|
cannot = (geteuid () != ROOT_UID);
|
||||||
# endif
|
# endif
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "write-any-file.h"
|
#include "write-any-file.h"
|
||||||
#include "priv-set.h"
|
#include "priv-set.h"
|
||||||
|
#include "root-uid.h"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ can_write_any_file (void)
|
|||||||
can = (priv_set_ismember (PRIV_FILE_DAC_WRITE) == 1);
|
can = (priv_set_ismember (PRIV_FILE_DAC_WRITE) == 1);
|
||||||
#else
|
#else
|
||||||
/* In traditional Unix, only root can unlink directories. */
|
/* In traditional Unix, only root can unlink directories. */
|
||||||
can = (geteuid () == 0);
|
can = (geteuid () == ROOT_UID);
|
||||||
#endif
|
#endif
|
||||||
can_write = can;
|
can_write = can;
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
@@ -25,9 +25,16 @@ AC_DEFUN([gl_FUNC_MKNOD],
|
|||||||
[AC_LANG_PROGRAM(
|
[AC_LANG_PROGRAM(
|
||||||
[[#include <sys/stat.h>
|
[[#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/* Copied from root-uid.h. FIXME: Just use root-uid.h. */
|
||||||
|
#ifdef __TANDEM
|
||||||
|
# define ROOT_UID 65535
|
||||||
|
#else
|
||||||
|
# define ROOT_UID 0
|
||||||
|
#endif
|
||||||
]], [[/* Indeterminate for super-user, assume no. Why are you running
|
]], [[/* Indeterminate for super-user, assume no. Why are you running
|
||||||
configure as root, anyway? */
|
configure as root, anyway? */
|
||||||
if (!geteuid ()) return 99;
|
if (geteuid () == ROOT_UID) return 99;
|
||||||
if (mknod ("conftest.fifo", S_IFIFO | 0600, 0)) return 2;]])],
|
if (mknod ("conftest.fifo", S_IFIFO | 0600, 0)) return 2;]])],
|
||||||
[gl_cv_func_mknod_works=yes],
|
[gl_cv_func_mknod_works=yes],
|
||||||
[if test $? = 99 && test x"$FORCE_UNSAFE_CONFIGURE" = x; then
|
[if test $? = 99 && test x"$FORCE_UNSAFE_CONFIGURE" = x; then
|
||||||
|
@@ -8,6 +8,7 @@ m4/euidaccess.m4
|
|||||||
Depends-on:
|
Depends-on:
|
||||||
unistd
|
unistd
|
||||||
extensions
|
extensions
|
||||||
|
root-uid
|
||||||
group-member [test $HAVE_EUIDACCESS = 0]
|
group-member [test $HAVE_EUIDACCESS = 0]
|
||||||
stat [test $HAVE_EUIDACCESS = 0]
|
stat [test $HAVE_EUIDACCESS = 0]
|
||||||
sys_stat [test $HAVE_EUIDACCESS = 0]
|
sys_stat [test $HAVE_EUIDACCESS = 0]
|
||||||
|
@@ -7,6 +7,7 @@ lib/pty-private.h
|
|||||||
|
|
||||||
Depends-on:
|
Depends-on:
|
||||||
ptsname
|
ptsname
|
||||||
|
root-uid
|
||||||
stdlib
|
stdlib
|
||||||
configmake
|
configmake
|
||||||
|
|
||||||
|
20
modules/root-uid
Normal file
20
modules/root-uid
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
Description:
|
||||||
|
ROOT_UID macro: superuser's user ID
|
||||||
|
|
||||||
|
Files:
|
||||||
|
lib/root-uid.h
|
||||||
|
|
||||||
|
Depends-on:
|
||||||
|
|
||||||
|
configure.ac:
|
||||||
|
|
||||||
|
Makefile.am:
|
||||||
|
|
||||||
|
Include:
|
||||||
|
"root-uid.h"
|
||||||
|
|
||||||
|
License:
|
||||||
|
LGPLv2+
|
||||||
|
|
||||||
|
Maintainer:
|
||||||
|
all
|
@@ -6,6 +6,7 @@ tests/macros.h
|
|||||||
|
|
||||||
Depends-on:
|
Depends-on:
|
||||||
gethostname
|
gethostname
|
||||||
|
root-uid
|
||||||
|
|
||||||
configure.ac:
|
configure.ac:
|
||||||
AC_CHECK_FUNCS_ONCE([geteuid])
|
AC_CHECK_FUNCS_ONCE([geteuid])
|
||||||
|
@@ -9,6 +9,7 @@ m4/unlinkdir.m4
|
|||||||
Depends-on:
|
Depends-on:
|
||||||
stdbool
|
stdbool
|
||||||
priv-set
|
priv-set
|
||||||
|
root-uid
|
||||||
|
|
||||||
configure.ac:
|
configure.ac:
|
||||||
gl_UNLINKDIR
|
gl_UNLINKDIR
|
||||||
|
@@ -9,6 +9,7 @@ m4/write-any-file.m4
|
|||||||
Depends-on:
|
Depends-on:
|
||||||
stdbool
|
stdbool
|
||||||
priv-set
|
priv-set
|
||||||
|
root-uid
|
||||||
|
|
||||||
configure.ac:
|
configure.ac:
|
||||||
gl_WRITE_ANY_FILE
|
gl_WRITE_ANY_FILE
|
||||||
|
@@ -27,6 +27,8 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "root-uid.h"
|
||||||
|
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
|
|
||||||
#define TESTHOSTNAME "gnulib-hostname"
|
#define TESTHOSTNAME "gnulib-hostname"
|
||||||
@@ -35,7 +37,7 @@
|
|||||||
On Cygwin, geteuid() may return non-zero even for user accounts with
|
On Cygwin, geteuid() may return non-zero even for user accounts with
|
||||||
administrator privileges, so use a dummy value as well. */
|
administrator privileges, so use a dummy value as well. */
|
||||||
#if !HAVE_GETEUID || defined __CYGWIN__
|
#if !HAVE_GETEUID || defined __CYGWIN__
|
||||||
# define geteuid() 0
|
# define geteuid() ROOT_UID
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -50,7 +52,7 @@ main (int argc, char *argv[] _GL_UNUSED)
|
|||||||
consider things like CAP_SYS_ADMIN (linux) or PRIV_SYS_ADMIN
|
consider things like CAP_SYS_ADMIN (linux) or PRIV_SYS_ADMIN
|
||||||
(solaris), etc. systems without a working geteuid (mingw, MSVC
|
(solaris), etc. systems without a working geteuid (mingw, MSVC
|
||||||
9) will always skip this test. */
|
9) will always skip this test. */
|
||||||
if (geteuid () != 0)
|
if (geteuid () != ROOT_UID)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "Skipping test: insufficient permissions.\n");
|
fprintf (stderr, "Skipping test: insufficient permissions.\n");
|
||||||
return 77;
|
return 77;
|
||||||
|
Reference in New Issue
Block a user