2001-06-17 21:09:28 +00:00
|
|
|
/* hairy bits of Hurd file name lookup
|
2022-01-01 18:54:23 +00:00
|
|
|
Copyright (C) 1992-2022 Free Software Foundation, Inc.
|
2001-06-17 21:09:28 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2001-06-17 21:09:28 +00:00
|
|
|
|
|
|
|
The GNU C Library 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
|
2001-07-06 04:58:11 +00:00
|
|
|
Lesser General Public License for more details.
|
2001-06-17 21:09:28 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2001-06-17 21:09:28 +00:00
|
|
|
|
|
|
|
#include <hurd.h>
|
|
|
|
#include <hurd/lookup.h>
|
|
|
|
#include <hurd/term.h>
|
|
|
|
#include <hurd/paths.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
2012-03-20 23:00:23 +00:00
|
|
|
#include <_itoa.h>
|
2012-08-01 17:33:11 +00:00
|
|
|
#include <eloop-threshold.h>
|
2018-12-28 21:31:01 +00:00
|
|
|
#include <unistd.h>
|
2001-06-17 21:09:28 +00:00
|
|
|
|
|
|
|
/* Translate the error from dir_lookup into the error the user sees. */
|
|
|
|
static inline error_t
|
|
|
|
lookup_error (error_t error)
|
|
|
|
{
|
|
|
|
switch (error)
|
|
|
|
{
|
|
|
|
case EOPNOTSUPP:
|
|
|
|
case MIG_BAD_ID:
|
|
|
|
/* These indicate that the server does not understand dir_lookup
|
|
|
|
at all. If it were a directory, it would, by definition. */
|
|
|
|
return ENOTDIR;
|
|
|
|
default:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
error_t
|
|
|
|
__hurd_file_name_lookup_retry (error_t (*use_init_port)
|
2012-05-10 22:37:23 +00:00
|
|
|
(int which, error_t (*operate) (file_t)),
|
2001-06-17 21:09:28 +00:00
|
|
|
file_t (*get_dtable_port) (int fd),
|
|
|
|
error_t (*lookup)
|
hurd: Fix warnings
* hurd/hurd/lookup.h (__hurd_file_name_lookup, hurd_file_name_lookup,
__hurd_file_name_split, hurd_file_name_split,
__hurd_directory_name_split, hurd_directory_name_split,
__hurd_file_name_lookup_retry, hurd_file_name_lookup_retry,
hurd_file_name_path_lookup): Make lookup function parameter take a
const char *name instead of char *name.
* hurd/hurdlookup.c (__hurd_file_name_lookup, __hurd_file_name_split,
__hurd_directory_name_split): Likewise.
* hurd/lookup-retry.c (__hurd_file_name_lookup_retry): Likewise.
* hurd/path-lookup.c (hurd_file_name_path_lookup): Likewise.
2018-01-28 15:23:59 +00:00
|
|
|
(file_t dir, const char *name,
|
2001-06-17 21:09:28 +00:00
|
|
|
int flags, mode_t mode,
|
|
|
|
retry_type *do_retry, string_t retry_name,
|
|
|
|
mach_port_t *result),
|
|
|
|
enum retry_type doretry,
|
|
|
|
char retryname[1024],
|
|
|
|
int flags, mode_t mode,
|
|
|
|
file_t *result)
|
|
|
|
{
|
|
|
|
error_t err;
|
|
|
|
char *file_name;
|
|
|
|
int nloops;
|
2018-12-28 21:31:01 +00:00
|
|
|
file_t lastdir = MACH_PORT_NULL;
|
2001-06-17 21:09:28 +00:00
|
|
|
|
|
|
|
error_t lookup_op (file_t startdir)
|
|
|
|
{
|
2016-01-12 23:48:30 +00:00
|
|
|
if (file_name[0] == '/' && file_name[1] != '\0')
|
|
|
|
{
|
|
|
|
while (file_name[1] == '/')
|
|
|
|
/* Remove double leading slash. */
|
|
|
|
file_name++;
|
|
|
|
if (file_name[1] != '\0')
|
|
|
|
/* Remove leading slash when we have more than the slash. */
|
|
|
|
file_name++;
|
|
|
|
}
|
2001-06-17 21:09:28 +00:00
|
|
|
|
|
|
|
return lookup_error ((*lookup) (startdir, file_name, flags, mode,
|
|
|
|
&doretry, retryname, result));
|
|
|
|
}
|
|
|
|
error_t reauthenticate (file_t unauth)
|
|
|
|
{
|
|
|
|
error_t err;
|
|
|
|
mach_port_t ref = __mach_reply_port ();
|
|
|
|
error_t reauth (auth_t auth)
|
|
|
|
{
|
|
|
|
return __auth_user_authenticate (auth, ref,
|
|
|
|
MACH_MSG_TYPE_MAKE_SEND,
|
|
|
|
result);
|
|
|
|
}
|
|
|
|
err = __io_reauthenticate (unauth, ref, MACH_MSG_TYPE_MAKE_SEND);
|
|
|
|
if (! err)
|
|
|
|
err = (*use_init_port) (INIT_PORT_AUTH, &reauth);
|
|
|
|
__mach_port_destroy (__mach_task_self (), ref);
|
|
|
|
__mach_port_deallocate (__mach_task_self (), unauth);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! lookup)
|
|
|
|
lookup = __dir_lookup;
|
|
|
|
|
|
|
|
nloops = 0;
|
|
|
|
err = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
file_t startdir = MACH_PORT_NULL;
|
|
|
|
int dirport = INIT_PORT_CWDIR;
|
|
|
|
|
|
|
|
switch (doretry)
|
|
|
|
{
|
|
|
|
case FS_RETRY_REAUTH:
|
|
|
|
if (err = reauthenticate (*result))
|
2018-12-28 21:31:01 +00:00
|
|
|
goto out;
|
2001-06-17 21:09:28 +00:00
|
|
|
/* Fall through. */
|
|
|
|
|
|
|
|
case FS_RETRY_NORMAL:
|
2012-08-01 17:33:11 +00:00
|
|
|
if (nloops++ >= __eloop_threshold ())
|
2001-06-17 21:09:28 +00:00
|
|
|
{
|
|
|
|
__mach_port_deallocate (__mach_task_self (), *result);
|
2018-12-28 21:31:01 +00:00
|
|
|
err = ELOOP;
|
|
|
|
goto out;
|
2001-06-17 21:09:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* An empty RETRYNAME indicates we have the final port. */
|
Break some lines before not after operators.
The GNU Coding Standards specify that line breaks in expressions
should go before an operator, not after one. This patch fixes various
code to do this. It only changes code that appears to be mostly
following GNU style anyway, not files and directories with
substantially different formatting. It is not exhaustive even for
files using GNU style (for example, changes to sysdeps files are
deferred for subsequent cleanups). Some files changed are shared with
gnulib, but most are specific to glibc. Changes were made manually,
with places to change found by grep (so some cases, e.g. where the
operator was followed by a comment at end of line, are particularly
liable to have been missed by grep, but I did include cases where the
operator was followed by backslash-newline).
This patch generally does not attempt to address other coding style
issues in the expressions changed (for example, missing spaces before
'(', or lack of parentheses to ensure indentation of continuation
lines properly reflects operator precedence).
Tested for x86_64, and with build-many-glibcs.py.
* benchtests/bench-memmem.c (simple_memmem): Break lines before
rather than after operators.
* benchtests/bench-skeleton.c (TIMESPEC_AFTER): Likewise.
* crypt/md5.c (md5_finish_ctx): Likewise.
* crypt/sha256.c (__sha256_finish_ctx): Likewise.
* crypt/sha512.c (__sha512_finish_ctx): Likewise.
* elf/cache.c (load_aux_cache): Likewise.
* elf/dl-load.c (open_verify): Likewise.
* elf/get-dynamic-info.h (elf_get_dynamic_info): Likewise.
* elf/readelflib.c (process_elf_file): Likewise.
* elf/rtld.c (dl_main): Likewise.
* elf/sprof.c (generate_call_graph): Likewise.
* hurd/ctty-input.c (_hurd_ctty_input): Likewise.
* hurd/ctty-output.c (_hurd_ctty_output): Likewise.
* hurd/dtable.c (reauth_dtable): Likewise.
* hurd/getdport.c (__getdport): Likewise.
* hurd/hurd/signal.h (_hurd_interrupted_rpc_timeout): Likewise.
* hurd/hurd/sigpreempt.h (HURD_PREEMPT_SIGNAL_P): Likewise.
* hurd/hurdfault.c (_hurdsig_fault_catch_exception_raise):
Likewise.
* hurd/hurdioctl.c (fioctl): Likewise.
* hurd/hurdselect.c (_hurd_select): Likewise.
* hurd/hurdsig.c (_hurdsig_abort_rpcs): Likewise.
(STOPSIGS): Likewise.
* hurd/hurdstartup.c (_hurd_startup): Likewise.
* hurd/intr-msg.c (_hurd_intr_rpc_mach_msg): Likewise.
* hurd/lookup-retry.c (__hurd_file_name_lookup_retry): Likewise.
* hurd/msgportdemux.c (msgport_server): Likewise.
* hurd/setauth.c (_hurd_setauth): Likewise.
* include/features.h (__GLIBC_USE_DEPRECATED_SCANF): Likewise.
* libio/libioP.h [IO_DEBUG] (CHECK_FILE): Likewise.
* locale/programs/ld-ctype.c (set_class_defaults): Likewise.
* localedata/tests-mbwc/tst_swscanf.c (tst_swscanf): Likewise.
* login/tst-utmp.c (do_check): Likewise.
(simulate_login): Likewise.
* mach/lowlevellock.h (lll_lock): Likewise.
(lll_trylock): Likewise.
* math/test-fenv.c (ALL_EXC): Likewise.
* math/test-fenvinline.c (ALL_EXC): Likewise.
* misc/sys/cdefs.h (__attribute_deprecated_msg__): Likewise.
* nis/nis_call.c (__do_niscall3): Likewise.
* nis/nis_callback.c (cb_prog_1): Likewise.
* nis/nis_defaults.c (searchaccess): Likewise.
* nis/nis_findserv.c (__nis_findfastest_with_timeout): Likewise.
* nis/nis_ismember.c (internal_ismember): Likewise.
* nis/nis_local_names.c (nis_local_principal): Likewise.
* nis/nss_nis/nis-rpc.c (_nss_nis_getrpcbyname_r): Likewise.
* nis/nss_nisplus/nisplus-netgrp.c (_nss_nisplus_getnetgrent_r):
Likewise.
* nis/ypclnt.c (yp_match): Likewise.
(yp_first): Likewise.
(yp_next): Likewise.
(yp_master): Likewise.
(yp_order): Likewise.
* nscd/hstcache.c (cache_addhst): Likewise.
* nscd/initgrcache.c (addinitgroupsX): Likewise.
* nss/nss_compat/compat-pwd.c (copy_pwd_changes): Likewise.
(internal_getpwuid_r): Likewise.
* nss/nss_compat/compat-spwd.c (copy_spwd_changes): Likewise.
* posix/glob.h (__GLOB_FLAGS): Likewise.
* posix/regcomp.c (peek_token): Likewise.
(peek_token_bracket): Likewise.
(parse_expression): Likewise.
* posix/regexec.c (sift_states_iter_mb): Likewise.
(check_node_accept_bytes): Likewise.
* posix/tst-spawn3.c (do_test): Likewise.
* posix/wordexp-test.c (testit): Likewise.
* posix/wordexp.c (parse_tilde): Likewise.
(exec_comm): Likewise.
* posix/wordexp.h (__WRDE_FLAGS): Likewise.
* resource/vtimes.c (TIMEVAL_TO_VTIMES): Likewise.
* setjmp/sigjmp.c (__sigjmp_save): Likewise.
* stdio-common/printf_fp.c (__printf_fp_l): Likewise.
* stdio-common/tst-fileno.c (do_test): Likewise.
* stdio-common/vfprintf-internal.c (vfprintf): Likewise.
* stdlib/strfmon_l.c (__vstrfmon_l_internal): Likewise.
* stdlib/strtod_l.c (round_and_return): Likewise.
(____STRTOF_INTERNAL): Likewise.
* stdlib/tst-strfrom.h (TEST_STRFROM): Likewise.
* string/strcspn.c (STRCSPN): Likewise.
* string/test-memmem.c (simple_memmem): Likewise.
* termios/tcsetattr.c (tcsetattr): Likewise.
* time/alt_digit.c (_nl_parse_alt_digit): Likewise.
* time/asctime.c (asctime_internal): Likewise.
* time/strptime_l.c (__strptime_internal): Likewise.
* time/sys/time.h (timercmp): Likewise.
* time/tzfile.c (__tzfile_compute): Likewise.
2019-02-22 01:32:36 +00:00
|
|
|
if (retryname[0] == '\0'
|
2001-06-17 21:09:28 +00:00
|
|
|
/* If reauth'd, we must do one more retry on "" to give the new
|
|
|
|
translator a chance to make a new port for us. */
|
Break some lines before not after operators.
The GNU Coding Standards specify that line breaks in expressions
should go before an operator, not after one. This patch fixes various
code to do this. It only changes code that appears to be mostly
following GNU style anyway, not files and directories with
substantially different formatting. It is not exhaustive even for
files using GNU style (for example, changes to sysdeps files are
deferred for subsequent cleanups). Some files changed are shared with
gnulib, but most are specific to glibc. Changes were made manually,
with places to change found by grep (so some cases, e.g. where the
operator was followed by a comment at end of line, are particularly
liable to have been missed by grep, but I did include cases where the
operator was followed by backslash-newline).
This patch generally does not attempt to address other coding style
issues in the expressions changed (for example, missing spaces before
'(', or lack of parentheses to ensure indentation of continuation
lines properly reflects operator precedence).
Tested for x86_64, and with build-many-glibcs.py.
* benchtests/bench-memmem.c (simple_memmem): Break lines before
rather than after operators.
* benchtests/bench-skeleton.c (TIMESPEC_AFTER): Likewise.
* crypt/md5.c (md5_finish_ctx): Likewise.
* crypt/sha256.c (__sha256_finish_ctx): Likewise.
* crypt/sha512.c (__sha512_finish_ctx): Likewise.
* elf/cache.c (load_aux_cache): Likewise.
* elf/dl-load.c (open_verify): Likewise.
* elf/get-dynamic-info.h (elf_get_dynamic_info): Likewise.
* elf/readelflib.c (process_elf_file): Likewise.
* elf/rtld.c (dl_main): Likewise.
* elf/sprof.c (generate_call_graph): Likewise.
* hurd/ctty-input.c (_hurd_ctty_input): Likewise.
* hurd/ctty-output.c (_hurd_ctty_output): Likewise.
* hurd/dtable.c (reauth_dtable): Likewise.
* hurd/getdport.c (__getdport): Likewise.
* hurd/hurd/signal.h (_hurd_interrupted_rpc_timeout): Likewise.
* hurd/hurd/sigpreempt.h (HURD_PREEMPT_SIGNAL_P): Likewise.
* hurd/hurdfault.c (_hurdsig_fault_catch_exception_raise):
Likewise.
* hurd/hurdioctl.c (fioctl): Likewise.
* hurd/hurdselect.c (_hurd_select): Likewise.
* hurd/hurdsig.c (_hurdsig_abort_rpcs): Likewise.
(STOPSIGS): Likewise.
* hurd/hurdstartup.c (_hurd_startup): Likewise.
* hurd/intr-msg.c (_hurd_intr_rpc_mach_msg): Likewise.
* hurd/lookup-retry.c (__hurd_file_name_lookup_retry): Likewise.
* hurd/msgportdemux.c (msgport_server): Likewise.
* hurd/setauth.c (_hurd_setauth): Likewise.
* include/features.h (__GLIBC_USE_DEPRECATED_SCANF): Likewise.
* libio/libioP.h [IO_DEBUG] (CHECK_FILE): Likewise.
* locale/programs/ld-ctype.c (set_class_defaults): Likewise.
* localedata/tests-mbwc/tst_swscanf.c (tst_swscanf): Likewise.
* login/tst-utmp.c (do_check): Likewise.
(simulate_login): Likewise.
* mach/lowlevellock.h (lll_lock): Likewise.
(lll_trylock): Likewise.
* math/test-fenv.c (ALL_EXC): Likewise.
* math/test-fenvinline.c (ALL_EXC): Likewise.
* misc/sys/cdefs.h (__attribute_deprecated_msg__): Likewise.
* nis/nis_call.c (__do_niscall3): Likewise.
* nis/nis_callback.c (cb_prog_1): Likewise.
* nis/nis_defaults.c (searchaccess): Likewise.
* nis/nis_findserv.c (__nis_findfastest_with_timeout): Likewise.
* nis/nis_ismember.c (internal_ismember): Likewise.
* nis/nis_local_names.c (nis_local_principal): Likewise.
* nis/nss_nis/nis-rpc.c (_nss_nis_getrpcbyname_r): Likewise.
* nis/nss_nisplus/nisplus-netgrp.c (_nss_nisplus_getnetgrent_r):
Likewise.
* nis/ypclnt.c (yp_match): Likewise.
(yp_first): Likewise.
(yp_next): Likewise.
(yp_master): Likewise.
(yp_order): Likewise.
* nscd/hstcache.c (cache_addhst): Likewise.
* nscd/initgrcache.c (addinitgroupsX): Likewise.
* nss/nss_compat/compat-pwd.c (copy_pwd_changes): Likewise.
(internal_getpwuid_r): Likewise.
* nss/nss_compat/compat-spwd.c (copy_spwd_changes): Likewise.
* posix/glob.h (__GLOB_FLAGS): Likewise.
* posix/regcomp.c (peek_token): Likewise.
(peek_token_bracket): Likewise.
(parse_expression): Likewise.
* posix/regexec.c (sift_states_iter_mb): Likewise.
(check_node_accept_bytes): Likewise.
* posix/tst-spawn3.c (do_test): Likewise.
* posix/wordexp-test.c (testit): Likewise.
* posix/wordexp.c (parse_tilde): Likewise.
(exec_comm): Likewise.
* posix/wordexp.h (__WRDE_FLAGS): Likewise.
* resource/vtimes.c (TIMEVAL_TO_VTIMES): Likewise.
* setjmp/sigjmp.c (__sigjmp_save): Likewise.
* stdio-common/printf_fp.c (__printf_fp_l): Likewise.
* stdio-common/tst-fileno.c (do_test): Likewise.
* stdio-common/vfprintf-internal.c (vfprintf): Likewise.
* stdlib/strfmon_l.c (__vstrfmon_l_internal): Likewise.
* stdlib/strtod_l.c (round_and_return): Likewise.
(____STRTOF_INTERNAL): Likewise.
* stdlib/tst-strfrom.h (TEST_STRFROM): Likewise.
* string/strcspn.c (STRCSPN): Likewise.
* string/test-memmem.c (simple_memmem): Likewise.
* termios/tcsetattr.c (tcsetattr): Likewise.
* time/alt_digit.c (_nl_parse_alt_digit): Likewise.
* time/asctime.c (asctime_internal): Likewise.
* time/strptime_l.c (__strptime_internal): Likewise.
* time/sys/time.h (timercmp): Likewise.
* time/tzfile.c (__tzfile_compute): Likewise.
2019-02-22 01:32:36 +00:00
|
|
|
&& doretry == FS_RETRY_NORMAL)
|
2001-06-17 21:09:28 +00:00
|
|
|
{
|
|
|
|
if (flags & O_NOFOLLOW)
|
|
|
|
{
|
|
|
|
/* In Linux, O_NOFOLLOW means to reject symlinks. If we
|
|
|
|
did an O_NOLINK lookup above and io_stat here to check
|
2018-03-18 18:39:29 +00:00
|
|
|
for S_IFLNK only, a translator like firmlink could easily
|
2001-06-17 21:09:28 +00:00
|
|
|
spoof this check by not showing S_IFLNK, but in fact
|
|
|
|
redirecting the lookup to some other name
|
|
|
|
(i.e. opening the very same holes a symlink would).
|
|
|
|
|
|
|
|
Instead we do an O_NOTRANS lookup above, and stat the
|
|
|
|
underlying node: if it has a translator set, and its
|
|
|
|
owner is not root (st_uid 0) then we reject it.
|
|
|
|
Since the motivation for this feature is security, and
|
|
|
|
that security presumes we trust the containing
|
|
|
|
directory, this check approximates the security of
|
|
|
|
refusing symlinks while accepting mount points.
|
|
|
|
Note that we actually permit something Linux doesn't:
|
|
|
|
we follow root-owned symlinks; if that is deemed
|
|
|
|
undesireable, we can add a final check for that
|
|
|
|
one exception to our general translator-based rule. */
|
2002-06-11 23:04:51 +00:00
|
|
|
struct stat64 st;
|
2001-06-17 21:09:28 +00:00
|
|
|
err = __io_stat (*result, &st);
|
2018-03-18 18:39:29 +00:00
|
|
|
if (!err)
|
2001-06-17 21:09:28 +00:00
|
|
|
{
|
2018-03-18 18:43:04 +00:00
|
|
|
if (flags & O_DIRECTORY && !S_ISDIR (st.st_mode))
|
|
|
|
err = ENOTDIR;
|
2018-03-18 18:39:29 +00:00
|
|
|
if (S_ISLNK (st.st_mode))
|
|
|
|
err = ELOOP;
|
|
|
|
else if (st.st_mode & (S_IPTRANS|S_IATRANS))
|
2001-06-17 21:09:28 +00:00
|
|
|
{
|
2018-03-18 18:39:29 +00:00
|
|
|
if (st.st_uid != 0)
|
|
|
|
err = ELOOP;
|
|
|
|
else if (st.st_mode & S_IPTRANS)
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
char *trans = buf;
|
|
|
|
size_t translen = sizeof buf;
|
|
|
|
err = __file_get_translator (*result,
|
|
|
|
&trans, &translen);
|
|
|
|
if (!err
|
|
|
|
&& translen > sizeof _HURD_SYMLINK
|
|
|
|
&& !memcmp (trans,
|
|
|
|
_HURD_SYMLINK, sizeof _HURD_SYMLINK))
|
|
|
|
err = ELOOP;
|
|
|
|
}
|
2001-06-17 21:09:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We got a successful translation. Now apply any open-time
|
|
|
|
action flags we were passed. */
|
|
|
|
|
2020-03-29 17:42:55 +00:00
|
|
|
if (!err && (flags & O_TRUNC))
|
|
|
|
{
|
|
|
|
/* Asked to truncate the file. */
|
|
|
|
err = __file_set_size (*result, 0);
|
|
|
|
if (!err)
|
|
|
|
{
|
|
|
|
struct timespec atime = { 0, UTIME_OMIT };
|
|
|
|
struct timespec mtime = { 0, UTIME_NOW };
|
|
|
|
__file_utimens (*result, atime, mtime);
|
|
|
|
}
|
|
|
|
}
|
2001-06-17 21:09:28 +00:00
|
|
|
|
|
|
|
if (err)
|
|
|
|
__mach_port_deallocate (__mach_task_self (), *result);
|
2018-12-28 21:31:01 +00:00
|
|
|
goto out;
|
2001-06-17 21:09:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
startdir = *result;
|
|
|
|
file_name = retryname;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FS_RETRY_MAGICAL:
|
|
|
|
switch (retryname[0])
|
|
|
|
{
|
|
|
|
case '/':
|
|
|
|
dirport = INIT_PORT_CRDIR;
|
|
|
|
if (*result != MACH_PORT_NULL)
|
|
|
|
__mach_port_deallocate (__mach_task_self (), *result);
|
2012-08-01 17:33:11 +00:00
|
|
|
if (nloops++ >= __eloop_threshold ())
|
2018-12-28 21:31:01 +00:00
|
|
|
{
|
|
|
|
err = ELOOP;
|
|
|
|
goto out;
|
|
|
|
}
|
2001-06-17 21:09:28 +00:00
|
|
|
file_name = &retryname[1];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
if (retryname[1] == 'd' && retryname[2] == '/')
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
char *end;
|
|
|
|
int save = errno;
|
|
|
|
errno = 0;
|
2012-05-10 22:37:23 +00:00
|
|
|
fd = (int) __strtoul_internal (&retryname[3], &end, 10, 0);
|
2019-02-25 13:19:19 +00:00
|
|
|
if (end == NULL || errno /* Malformed number. */
|
2001-06-17 21:09:28 +00:00
|
|
|
/* Check for excess text after the number. A slash
|
|
|
|
is valid; it ends the component. Anything else
|
|
|
|
does not name a numeric file descriptor. */
|
2019-02-25 13:19:19 +00:00
|
|
|
|| (*end != '/' && *end != '\0'))
|
2001-06-17 21:09:28 +00:00
|
|
|
{
|
|
|
|
errno = save;
|
2018-12-28 21:31:01 +00:00
|
|
|
err = ENOENT;
|
|
|
|
goto out;
|
2001-06-17 21:09:28 +00:00
|
|
|
}
|
|
|
|
if (! get_dtable_port)
|
|
|
|
err = EGRATUITOUS;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*result = (*get_dtable_port) (fd);
|
|
|
|
if (*result == MACH_PORT_NULL)
|
|
|
|
{
|
|
|
|
/* If the name was a proper number, but the file
|
|
|
|
descriptor does not exist, we return EBADF instead
|
|
|
|
of ENOENT. */
|
|
|
|
err = errno;
|
|
|
|
errno = save;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
errno = save;
|
|
|
|
if (err)
|
2018-12-28 21:31:01 +00:00
|
|
|
goto out;
|
2001-06-17 21:09:28 +00:00
|
|
|
if (*end == '\0')
|
2018-12-28 21:31:01 +00:00
|
|
|
{
|
|
|
|
err = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2001-06-17 21:09:28 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Do a normal retry on the remaining components. */
|
|
|
|
startdir = *result;
|
|
|
|
file_name = end + 1; /* Skip the slash. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto bad_magic;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'm':
|
Break some lines before not after operators.
The GNU Coding Standards specify that line breaks in expressions
should go before an operator, not after one. This patch fixes various
code to do this. It only changes code that appears to be mostly
following GNU style anyway, not files and directories with
substantially different formatting. It is not exhaustive even for
files using GNU style (for example, changes to sysdeps files are
deferred for subsequent cleanups). Some files changed are shared with
gnulib, but most are specific to glibc. Changes were made manually,
with places to change found by grep (so some cases, e.g. where the
operator was followed by a comment at end of line, are particularly
liable to have been missed by grep, but I did include cases where the
operator was followed by backslash-newline).
This patch generally does not attempt to address other coding style
issues in the expressions changed (for example, missing spaces before
'(', or lack of parentheses to ensure indentation of continuation
lines properly reflects operator precedence).
Tested for x86_64, and with build-many-glibcs.py.
* benchtests/bench-memmem.c (simple_memmem): Break lines before
rather than after operators.
* benchtests/bench-skeleton.c (TIMESPEC_AFTER): Likewise.
* crypt/md5.c (md5_finish_ctx): Likewise.
* crypt/sha256.c (__sha256_finish_ctx): Likewise.
* crypt/sha512.c (__sha512_finish_ctx): Likewise.
* elf/cache.c (load_aux_cache): Likewise.
* elf/dl-load.c (open_verify): Likewise.
* elf/get-dynamic-info.h (elf_get_dynamic_info): Likewise.
* elf/readelflib.c (process_elf_file): Likewise.
* elf/rtld.c (dl_main): Likewise.
* elf/sprof.c (generate_call_graph): Likewise.
* hurd/ctty-input.c (_hurd_ctty_input): Likewise.
* hurd/ctty-output.c (_hurd_ctty_output): Likewise.
* hurd/dtable.c (reauth_dtable): Likewise.
* hurd/getdport.c (__getdport): Likewise.
* hurd/hurd/signal.h (_hurd_interrupted_rpc_timeout): Likewise.
* hurd/hurd/sigpreempt.h (HURD_PREEMPT_SIGNAL_P): Likewise.
* hurd/hurdfault.c (_hurdsig_fault_catch_exception_raise):
Likewise.
* hurd/hurdioctl.c (fioctl): Likewise.
* hurd/hurdselect.c (_hurd_select): Likewise.
* hurd/hurdsig.c (_hurdsig_abort_rpcs): Likewise.
(STOPSIGS): Likewise.
* hurd/hurdstartup.c (_hurd_startup): Likewise.
* hurd/intr-msg.c (_hurd_intr_rpc_mach_msg): Likewise.
* hurd/lookup-retry.c (__hurd_file_name_lookup_retry): Likewise.
* hurd/msgportdemux.c (msgport_server): Likewise.
* hurd/setauth.c (_hurd_setauth): Likewise.
* include/features.h (__GLIBC_USE_DEPRECATED_SCANF): Likewise.
* libio/libioP.h [IO_DEBUG] (CHECK_FILE): Likewise.
* locale/programs/ld-ctype.c (set_class_defaults): Likewise.
* localedata/tests-mbwc/tst_swscanf.c (tst_swscanf): Likewise.
* login/tst-utmp.c (do_check): Likewise.
(simulate_login): Likewise.
* mach/lowlevellock.h (lll_lock): Likewise.
(lll_trylock): Likewise.
* math/test-fenv.c (ALL_EXC): Likewise.
* math/test-fenvinline.c (ALL_EXC): Likewise.
* misc/sys/cdefs.h (__attribute_deprecated_msg__): Likewise.
* nis/nis_call.c (__do_niscall3): Likewise.
* nis/nis_callback.c (cb_prog_1): Likewise.
* nis/nis_defaults.c (searchaccess): Likewise.
* nis/nis_findserv.c (__nis_findfastest_with_timeout): Likewise.
* nis/nis_ismember.c (internal_ismember): Likewise.
* nis/nis_local_names.c (nis_local_principal): Likewise.
* nis/nss_nis/nis-rpc.c (_nss_nis_getrpcbyname_r): Likewise.
* nis/nss_nisplus/nisplus-netgrp.c (_nss_nisplus_getnetgrent_r):
Likewise.
* nis/ypclnt.c (yp_match): Likewise.
(yp_first): Likewise.
(yp_next): Likewise.
(yp_master): Likewise.
(yp_order): Likewise.
* nscd/hstcache.c (cache_addhst): Likewise.
* nscd/initgrcache.c (addinitgroupsX): Likewise.
* nss/nss_compat/compat-pwd.c (copy_pwd_changes): Likewise.
(internal_getpwuid_r): Likewise.
* nss/nss_compat/compat-spwd.c (copy_spwd_changes): Likewise.
* posix/glob.h (__GLOB_FLAGS): Likewise.
* posix/regcomp.c (peek_token): Likewise.
(peek_token_bracket): Likewise.
(parse_expression): Likewise.
* posix/regexec.c (sift_states_iter_mb): Likewise.
(check_node_accept_bytes): Likewise.
* posix/tst-spawn3.c (do_test): Likewise.
* posix/wordexp-test.c (testit): Likewise.
* posix/wordexp.c (parse_tilde): Likewise.
(exec_comm): Likewise.
* posix/wordexp.h (__WRDE_FLAGS): Likewise.
* resource/vtimes.c (TIMEVAL_TO_VTIMES): Likewise.
* setjmp/sigjmp.c (__sigjmp_save): Likewise.
* stdio-common/printf_fp.c (__printf_fp_l): Likewise.
* stdio-common/tst-fileno.c (do_test): Likewise.
* stdio-common/vfprintf-internal.c (vfprintf): Likewise.
* stdlib/strfmon_l.c (__vstrfmon_l_internal): Likewise.
* stdlib/strtod_l.c (round_and_return): Likewise.
(____STRTOF_INTERNAL): Likewise.
* stdlib/tst-strfrom.h (TEST_STRFROM): Likewise.
* string/strcspn.c (STRCSPN): Likewise.
* string/test-memmem.c (simple_memmem): Likewise.
* termios/tcsetattr.c (tcsetattr): Likewise.
* time/alt_digit.c (_nl_parse_alt_digit): Likewise.
* time/asctime.c (asctime_internal): Likewise.
* time/strptime_l.c (__strptime_internal): Likewise.
* time/sys/time.h (timercmp): Likewise.
* time/tzfile.c (__tzfile_compute): Likewise.
2019-02-22 01:32:36 +00:00
|
|
|
if (retryname[1] == 'a' && retryname[2] == 'c'
|
|
|
|
&& retryname[3] == 'h' && retryname[4] == 't'
|
|
|
|
&& retryname[5] == 'y' && retryname[6] == 'p'
|
|
|
|
&& retryname[7] == 'e')
|
2001-06-17 21:09:28 +00:00
|
|
|
{
|
|
|
|
error_t err;
|
|
|
|
struct host_basic_info hostinfo;
|
|
|
|
mach_msg_type_number_t hostinfocnt = HOST_BASIC_INFO_COUNT;
|
|
|
|
char *p;
|
|
|
|
/* XXX want client's host */
|
|
|
|
if (err = __host_info (__mach_host_self (), HOST_BASIC_INFO,
|
2005-12-29 10:38:16 +00:00
|
|
|
(integer_t *) &hostinfo,
|
2001-06-17 21:09:28 +00:00
|
|
|
&hostinfocnt))
|
2018-12-28 21:31:01 +00:00
|
|
|
goto out;
|
2001-06-17 21:09:28 +00:00
|
|
|
if (hostinfocnt != HOST_BASIC_INFO_COUNT)
|
2018-12-28 21:31:01 +00:00
|
|
|
{
|
|
|
|
err = EGRATUITOUS;
|
|
|
|
goto out;
|
|
|
|
}
|
2001-06-17 21:09:28 +00:00
|
|
|
p = _itoa (hostinfo.cpu_subtype, &retryname[8], 10, 0);
|
|
|
|
*--p = '/';
|
|
|
|
p = _itoa (hostinfo.cpu_type, &retryname[8], 10, 0);
|
|
|
|
if (p < retryname)
|
|
|
|
abort (); /* XXX write this right if this ever happens */
|
|
|
|
if (p > retryname)
|
2020-11-22 23:15:36 +00:00
|
|
|
memmove (retryname, p, strlen(p) + 1);
|
2001-06-17 21:09:28 +00:00
|
|
|
startdir = *result;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto bad_magic;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 't':
|
|
|
|
if (retryname[1] == 't' && retryname[2] == 'y')
|
|
|
|
switch (retryname[3])
|
|
|
|
{
|
|
|
|
error_t opentty (file_t *result)
|
|
|
|
{
|
|
|
|
error_t err;
|
|
|
|
error_t ctty_open (file_t port)
|
|
|
|
{
|
|
|
|
if (port == MACH_PORT_NULL)
|
|
|
|
return ENXIO; /* No controlling terminal. */
|
|
|
|
return __termctty_open_terminal (port,
|
|
|
|
flags,
|
|
|
|
result);
|
|
|
|
}
|
|
|
|
err = (*use_init_port) (INIT_PORT_CTTYID, &ctty_open);
|
|
|
|
if (! err)
|
|
|
|
err = reauthenticate (*result);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
case '\0':
|
2018-12-28 21:31:01 +00:00
|
|
|
err = opentty (result);
|
|
|
|
goto out;
|
2001-06-17 21:09:28 +00:00
|
|
|
case '/':
|
|
|
|
if (err = opentty (&startdir))
|
2018-12-28 21:31:01 +00:00
|
|
|
goto out;
|
2020-11-22 23:15:36 +00:00
|
|
|
memmove (retryname, &retryname[4], strlen(retryname + 4) + 1);
|
2001-06-17 21:09:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto bad_magic;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto bad_magic;
|
|
|
|
break;
|
|
|
|
|
2018-12-28 21:31:01 +00:00
|
|
|
case 'p':
|
2019-02-25 13:19:19 +00:00
|
|
|
if (retryname[1] == 'i' && retryname[2] == 'd'
|
|
|
|
&& (retryname[3] == '/' || retryname[3] == 0))
|
2018-12-28 21:31:01 +00:00
|
|
|
{
|
|
|
|
char *p, buf[1024]; /* XXX */
|
|
|
|
size_t len;
|
|
|
|
p = _itoa (__getpid (), &buf[sizeof buf], 10, 0);
|
|
|
|
len = &buf[sizeof buf] - p;
|
|
|
|
memcpy (buf, p, len);
|
2020-11-22 23:15:36 +00:00
|
|
|
strncpy (buf + len, &retryname[3], sizeof buf - len - 1);
|
|
|
|
buf[sizeof buf - 1] = '\0';
|
2018-12-28 21:31:01 +00:00
|
|
|
strcpy (retryname, buf);
|
|
|
|
|
|
|
|
/* Do a normal retry on the remaining components. */
|
|
|
|
__mach_port_mod_refs (__mach_task_self (), lastdir,
|
|
|
|
MACH_PORT_RIGHT_SEND, 1);
|
|
|
|
startdir = lastdir;
|
|
|
|
file_name = retryname;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto bad_magic;
|
|
|
|
break;
|
|
|
|
|
2001-06-17 21:09:28 +00:00
|
|
|
default:
|
|
|
|
bad_magic:
|
2018-12-28 21:31:01 +00:00
|
|
|
err = EGRATUITOUS;
|
|
|
|
goto out;
|
2001-06-17 21:09:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2018-12-28 21:31:01 +00:00
|
|
|
err = EGRATUITOUS;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MACH_PORT_VALID (*result) && *result != lastdir)
|
|
|
|
{
|
|
|
|
if (MACH_PORT_VALID (lastdir))
|
|
|
|
__mach_port_deallocate (__mach_task_self (), lastdir);
|
|
|
|
|
|
|
|
lastdir = *result;
|
|
|
|
__mach_port_mod_refs (__mach_task_self (), lastdir,
|
|
|
|
MACH_PORT_RIGHT_SEND, 1);
|
2001-06-17 21:09:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (startdir != MACH_PORT_NULL)
|
|
|
|
{
|
|
|
|
err = lookup_op (startdir);
|
|
|
|
__mach_port_deallocate (__mach_task_self (), startdir);
|
|
|
|
startdir = MACH_PORT_NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
err = (*use_init_port) (dirport, &lookup_op);
|
|
|
|
} while (! err);
|
|
|
|
|
2018-12-28 21:31:01 +00:00
|
|
|
out:
|
|
|
|
if (MACH_PORT_VALID (lastdir))
|
|
|
|
__mach_port_deallocate (__mach_task_self (), lastdir);
|
|
|
|
|
2001-06-17 21:09:28 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
weak_alias (__hurd_file_name_lookup_retry, hurd_file_name_lookup_retry)
|