From 6bd102382341d268d2e99349abd4c21546a5993e Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 12 Nov 2009 21:45:20 -0700 Subject: [PATCH] lchown: detect Solaris and FreeBSD bug Solaris 9 and FreeBSD 7.2 lchown("link-to-file/",uid,gid) mistakenly changes ownership of "file". * lib/lchown.c (rpl_lchown): Work around bug. * m4/lchown.m4 (gl_FUNC_LCHOWN): Check for trailing slash bugs. * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Add witness. * modules/unistd (Makefile.am): Populate it. * lib/unistd.in.h (lchown): Update declaration. * doc/posix-functions/lchown.texi (lchown): Document the bug. * modules/lchown-tests: New file. * tests/test-lchown.h (test_lchown): Likewise. * tests/test-lchown.c (main): Likewise. Signed-off-by: Eric Blake --- ChangeLog | 11 ++ doc/posix-functions/lchown.texi | 8 +- lib/lchown.c | 35 +++-- lib/unistd.in.h | 5 +- m4/lchown.m4 | 12 +- m4/unistd_h.m4 | 3 +- modules/lchown | 2 +- modules/lchown-tests | 19 +++ modules/unistd | 1 + tests/test-lchown.c | 56 ++++++++ tests/test-lchown.h | 311 ++++++++++++++++++++++++++++++++++++++++ 11 files changed, 448 insertions(+), 15 deletions(-) create mode 100644 modules/lchown-tests create mode 100644 tests/test-lchown.c create mode 100644 tests/test-lchown.h diff --git a/ChangeLog b/ChangeLog index 8ca5ad6b6..f0e2a18df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2009-11-14 Eric Blake + lchown: detect Solaris and FreeBSD bug + * lib/lchown.c (rpl_lchown): Work around bug. + * m4/lchown.m4 (gl_FUNC_LCHOWN): Check for trailing slash bugs. + * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Add witness. + * modules/unistd (Makefile.am): Populate it. + * lib/unistd.in.h (lchown): Update declaration. + * doc/posix-functions/lchown.texi (lchown): Document the bug. + * modules/lchown-tests: New file. + * tests/test-lchown.h (test_lchown): Likewise. + * tests/test-lchown.c (main): Likewise. + chown: detect Solaris and FreeBSD bug * lib/chown.c (rpl_chown): Work around bug. * m4/chown.m4 (gl_FUNC_CHOWN): Check for trailing slash bugs. diff --git a/doc/posix-functions/lchown.texi b/doc/posix-functions/lchown.texi index e40be3fda..0686bf391 100644 --- a/doc/posix-functions/lchown.texi +++ b/doc/posix-functions/lchown.texi @@ -9,7 +9,13 @@ Gnulib module: lchown Portability problems fixed by Gnulib: @itemize @item -This function is missing on some platforms: +Some platforms fail to detect trailing slash on non-directories, as in +@code{lchown("link-to-file/",uid,gid)}: +FreeBSD 7.2, Solaris 9. +@item +This function is missing on some platforms; however, the replacement +fails on symlinks if @code{chown} is supported, and fails altogether +with @code{ENOSYS} otherwise: MacOS X 10.3, mingw, BeOS. @end itemize diff --git a/lib/lchown.c b/lib/lchown.c index 65434b45c..265c2f72e 100644 --- a/lib/lchown.c +++ b/lib/lchown.c @@ -23,13 +23,16 @@ #include #include +#include #include +#if !HAVE_LCHOWN + /* If the system chown does not follow symlinks, we don't want it replaced by gnulib's chown, which does follow symlinks. */ -#if CHOWN_MODIFIES_SYMLINK -# undef chown -#endif +# if CHOWN_MODIFIES_SYMLINK +# undef chown +# endif /* Work just like chown, except when FILE is a symbolic link. In that case, set errno to EOPNOTSUPP and return -1. @@ -39,8 +42,8 @@ int lchown (const char *file, uid_t uid, gid_t gid) { -#if HAVE_CHOWN -# if ! CHOWN_MODIFIES_SYMLINK +# if HAVE_CHOWN +# if ! CHOWN_MODIFIES_SYMLINK struct stat stats; if (lstat (file, &stats) == 0 && S_ISLNK (stats.st_mode)) @@ -48,12 +51,28 @@ lchown (const char *file, uid_t uid, gid_t gid) errno = EOPNOTSUPP; return -1; } -# endif +# endif return chown (file, uid, gid); -#else /* !HAVE_CHOWN */ +# else /* !HAVE_CHOWN */ errno = ENOSYS; return -1; -#endif +# endif } + +#else /* HAVE_LCHOWN */ + +# undef lchown + +/* Work around trailing slash bugs in lchown. */ +int +rpl_lchown (const char *file, uid_t uid, gid_t gid) +{ + size_t len = strlen (file); + if (len && file[len - 1] == '/') + return chown (file, uid, gid); + return lchown (file, uid, gid); +} + +#endif /* HAVE_LCHOWN */ diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 6b0513bdd..c026b7178 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -565,12 +565,15 @@ extern void endusershell (void); #if @GNULIB_LCHOWN@ # if @REPLACE_LCHOWN@ +# undef lchown +# define lchown rpl_lchown +# endif +# if !@HAVE_LCHOWN@ || @REPLACE_LCHOWN@ /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE to GID (if GID is not -1). Do not follow symbolic links. Return 0 if successful, otherwise -1 and errno set. See the POSIX:2001 specification . */ -# define lchown rpl_lchown extern int lchown (char const *file, uid_t owner, gid_t group); # endif #elif defined GNULIB_POSIXCHECK diff --git a/m4/lchown.m4 b/m4/lchown.m4 index f509fde04..e40c43762 100644 --- a/m4/lchown.m4 +++ b/m4/lchown.m4 @@ -1,14 +1,16 @@ -# serial 13 +# serial 14 # Determine whether we need the lchown wrapper. -dnl Copyright (C) 1998, 2001, 2003-2007, 2009 Free Software Foundation, Inc. +dnl Copyright (C) 1998, 2001, 2003-2007, 2009 Free Software +dnl Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. dnl From Jim Meyering. -dnl Provide lchown on systems that lack it. +dnl Provide lchown on systems that lack it, and work around trailing +dnl slash bugs on systems that have it. AC_DEFUN([gl_FUNC_LCHOWN], [ @@ -16,6 +18,10 @@ AC_DEFUN([gl_FUNC_LCHOWN], AC_REQUIRE([gl_FUNC_CHOWN]) AC_REPLACE_FUNCS([lchown]) if test $ac_cv_func_lchown = no; then + HAVE_LCHOWN=0 + elif test "$gl_cv_func_chown_slash_works" != yes; then + dnl Trailing slash bugs in chown also occur in lchown. + AC_LIBOBJ([lchown]) REPLACE_LCHOWN=1 fi ]) diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 index bd368c614..88e60a053 100644 --- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -1,4 +1,4 @@ -# unistd_h.m4 serial 33 +# unistd_h.m4 serial 34 dnl Copyright (C) 2006-2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -82,6 +82,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], HAVE_GETHOSTNAME=1; AC_SUBST([HAVE_GETHOSTNAME]) HAVE_GETPAGESIZE=1; AC_SUBST([HAVE_GETPAGESIZE]) HAVE_GETUSERSHELL=1; AC_SUBST([HAVE_GETUSERSHELL]) + HAVE_LCHOWN=1; AC_SUBST([HAVE_LCHOWN]) HAVE_LINK=1; AC_SUBST([HAVE_LINK]) HAVE_LINKAT=1; AC_SUBST([HAVE_LINKAT]) HAVE_PIPE2=1; AC_SUBST([HAVE_PIPE2]) diff --git a/modules/lchown b/modules/lchown index c50537aac..233e33479 100644 --- a/modules/lchown +++ b/modules/lchown @@ -25,4 +25,4 @@ License: GPL Maintainer: -Jim Meyering +Jim Meyering, Eric Blake diff --git a/modules/lchown-tests b/modules/lchown-tests new file mode 100644 index 000000000..c33103a6b --- /dev/null +++ b/modules/lchown-tests @@ -0,0 +1,19 @@ +Files: +tests/test-lchown.h +tests/test-lchown.c + +Depends-on: +mgetgroups +progname +sleep +stat-time +stdbool +symlink + +configure.ac: +AC_CHECK_FUNCS_ONCE([getegid usleep]) + +Makefile.am: +TESTS += test-lchown +check_PROGRAMS += test-lchown +test_lchown_LDADD = $(LDADD) @LIBINTL@ diff --git a/modules/unistd b/modules/unistd index 031d7076e..1cb3b0b62 100644 --- a/modules/unistd +++ b/modules/unistd @@ -74,6 +74,7 @@ unistd.h: unistd.in.h -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \ -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \ -e 's|@''HAVE_GETUSERSHELL''@|$(HAVE_GETUSERSHELL)|g' \ + -e 's|@''HAVE_LCHOWN''@|$(HAVE_LCHOWN)|g' \ -e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \ -e 's|@''HAVE_LINKAT''@|$(HAVE_LINKAT)|g' \ -e 's|@''HAVE_PIPE2''@|$(HAVE_PIPE2)|g' \ diff --git a/tests/test-lchown.c b/tests/test-lchown.c new file mode 100644 index 000000000..78c294081 --- /dev/null +++ b/tests/test-lchown.c @@ -0,0 +1,56 @@ +/* Tests of lchown. + Copyright (C) 2009 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 . */ + +/* Written by Eric Blake , 2009. */ + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include "mgetgroups.h" +#include "stat-time.h" + +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ + while (0) + +#define BASE "test-lchown.t" + +#include "test-lchown.h" + +int +main (void) +{ + /* Remove any leftovers from a previous partial run. */ + ASSERT (system ("rm -rf " BASE "*") == 0); + + return test_lchown (lchown, true); +} diff --git a/tests/test-lchown.h b/tests/test-lchown.h new file mode 100644 index 000000000..b0987c51c --- /dev/null +++ b/tests/test-lchown.h @@ -0,0 +1,311 @@ +/* Tests of lchown. + Copyright (C) 2009 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 . */ + +/* Written by Eric Blake , 2009. */ + +#ifndef TEST_CHOWN_NAP +/* Sleep long enough to notice a timestamp difference on the file + system in the current directory. */ +static void +nap (void) +{ +# if !HAVE_USLEEP + /* Assume the worst case file system of FAT, which has a granularity + of 2 seconds. */ + sleep (2); +# else /* HAVE_USLEEP */ + static long delay; + if (!delay) + { + /* Initialize only once, by sleeping for 20 milliseconds (needed + since xfs has a quantization of about 10 milliseconds, even + though it has a granularity of 1 nanosecond, and since NTFS + has a default quantization of 15.25 milliseconds, even though + it has a granularity of 100 nanoseconds). If the seconds + differ, repeat the test one more time (in case we crossed a + quantization boundary on a file system with 1 second + resolution). If we can't observe a difference in only the + nanoseconds, then fall back to 2 seconds. However, note that + usleep (2000000) is allowed to fail with EINVAL. */ + struct stat st1; + struct stat st2; + ASSERT (close (creat (BASE "tmp", 0600)) == 0); + ASSERT (stat (BASE "tmp", &st1) == 0); + ASSERT (unlink (BASE "tmp") == 0); + delay = 20000; + usleep (delay); + ASSERT (close (creat (BASE "tmp", 0600)) == 0); + ASSERT (stat (BASE "tmp", &st2) == 0); + ASSERT (unlink (BASE "tmp") == 0); + if (st1.st_mtime != st2.st_mtime) + { + /* Seconds differ, give it one more shot. */ + st1 = st2; + usleep (delay); + ASSERT (close (creat (BASE "tmp", 0600)) == 0); + ASSERT (stat (BASE "tmp", &st2) == 0); + ASSERT (unlink (BASE "tmp") == 0); + } + if (! (st1.st_mtime == st2.st_mtime + && get_stat_mtime_ns (&st1) < get_stat_mtime_ns (&st2))) + delay = 2000000; + } + if (delay == 2000000) + sleep (2); + else + usleep (delay); +# endif /* HAVE_USLEEP */ +} +#endif /* !TEST_CHOWN_NAP */ + +#if !HAVE_GETEGID +# define getegid() (-1) +#endif + +/* This file is designed to test lchown(n,o,g) and + chownat(AT_FDCWD,n,o,g,AT_SYMLINK_NOFOLLOW). FUNC is the function + to test. Assumes that BASE and ASSERT are already defined, and + that appropriate headers are already included. If PRINT, warn + before skipping symlink tests with status 77. */ + +static int +test_lchown (int (*func) (char const *, uid_t, gid_t), bool print) +{ + struct stat st1; + struct stat st2; + gid_t *gids = NULL; + int gids_count; + int result; + + /* Solaris 8 is interesting - if the current process belongs to + multiple groups, the current directory is owned by a a group that + the current process belongs to but different than getegid(), and + the current directory does not have the S_ISGID bit, then regular + files created in the directory belong to the directory's group, + but symlinks belong to the current effective group id. If + S_ISGID is set, then both files and symlinks belong to the + directory's group. However, it is possible to run the testsuite + from within a directory owned by a group we don't belong to, in + which case all things that we create belong to the current + effective gid. So, work around the issues by creating a + subdirectory (we are guaranteed that the subdirectory will be + owned by one of our current groups), change ownership of that + directory to the current effective gid (which will thus succeed), + then create all other files within that directory (eliminating + questions on whether inheritance or current id triumphs, since + the two methods resolve to the same gid). */ + ASSERT (mkdir (BASE "dir", 0700) == 0); + ASSERT (stat (BASE "dir", &st1) == 0); + + /* Filter out mingw, which has no concept of groups. */ + result = func (BASE "dir", st1.st_uid, getegid ()); + if (result == -1 && errno == ENOSYS) + { + ASSERT (rmdir (BASE "dir") == 0); + if (print) + fputs ("skipping test: no support for ownership\n", stderr); + return 77; + } + ASSERT (result == 0); + + ASSERT (close (creat (BASE "dir/file", 0600)) == 0); + ASSERT (stat (BASE "dir/file", &st1) == 0); + ASSERT (st1.st_uid != -1); + ASSERT (st1.st_gid != -1); + ASSERT (st1.st_gid == getegid ()); + + /* Sanity check of error cases. */ + errno = 0; + ASSERT (func ("", -1, -1) == -1); + ASSERT (errno == ENOENT); + errno = 0; + ASSERT (func ("no_such", -1, -1) == -1); + ASSERT (errno == ENOENT); + errno = 0; + ASSERT (func ("no_such/", -1, -1) == -1); + ASSERT (errno == ENOENT); + errno = 0; + ASSERT (func (BASE "dir/file/", -1, -1) == -1); + ASSERT (errno == ENOTDIR); + + /* Check that -1 does not alter ownership. */ + ASSERT (func (BASE "dir/file", -1, st1.st_gid) == 0); + ASSERT (func (BASE "dir/file", st1.st_uid, -1) == 0); + ASSERT (stat (BASE "dir/file", &st2) == 0); + ASSERT (st1.st_uid == st2.st_uid); + ASSERT (st1.st_gid == st2.st_gid); + + /* Even if the values aren't changing, ctime is required to change + if at least one argument is not -1. */ + nap (); + ASSERT (func (BASE "dir/file", st1.st_uid, st1.st_gid) == 0); + ASSERT (stat (BASE "dir/file", &st2) == 0); + ASSERT (st1.st_ctime < st2.st_ctime + || (st1.st_ctime == st2.st_ctime + && get_stat_ctime_ns (&st1) < get_stat_ctime_ns (&st2))); + + /* Test symlink behavior. */ + if (symlink ("link", BASE "dir/link2")) + { + ASSERT (unlink (BASE "dir/file") == 0); + ASSERT (rmdir (BASE "dir") == 0); + if (print) + fputs ("skipping test: symlinks not supported on this file system\n", + stderr); + return 77; + } + result = func (BASE "dir/link2", -1, -1); + if (result == -1 && errno == ENOSYS) + { + ASSERT (unlink (BASE "dir/file") == 0); + ASSERT (unlink (BASE "dir/link2") == 0); + ASSERT (rmdir (BASE "dir") == 0); + if (print) + fputs ("skipping test: symlink ownership not supported\n", stderr); + return 77; + } + ASSERT (result == 0); + errno = 0; + ASSERT (func (BASE "dir/link2/", st1.st_uid, st1.st_gid) == -1); + ASSERT (errno == ENOENT); + ASSERT (symlink ("file", BASE "dir/link") == 0); + ASSERT (mkdir (BASE "dir/sub", 0700) == 0); + ASSERT (symlink ("sub", BASE "dir/link3") == 0); + + /* For non-privileged users, lchown can only portably succeed at + changing group ownership of a file we own. If we belong to at + least two groups, then verifying the correct change is simple. + But if we belong to only one group, then we fall back on the + other observable effect of lchown: the ctime must be updated. + Be careful of duplicates returned by getgroups. */ + gids_count = mgetgroups (NULL, -1, &gids); + if (2 <= gids_count && gids[0] == gids[1] && 2 < gids_count--) + gids[1] = gids[2]; + if (1 < gids_count || (gids_count == 1 && gids[0] != st1.st_gid)) + { + if (gids[0] == st1.st_gid) + { + ASSERT (1 < gids_count); + ASSERT (gids[0] != gids[1]); + gids[0] = gids[1]; + } + ASSERT (gids[0] != st1.st_gid); + ASSERT (gids[0] != -1); + ASSERT (lstat (BASE "dir/link", &st2) == 0); + ASSERT (st1.st_uid == st2.st_uid); + ASSERT (st1.st_gid == st2.st_gid); + ASSERT (lstat (BASE "dir/link2", &st2) == 0); + ASSERT (st1.st_uid == st2.st_uid); + ASSERT (st1.st_gid == st2.st_gid); + + errno = 0; + ASSERT (func (BASE "dir/link2/", -1, gids[0]) == -1); + ASSERT (errno == ENOTDIR); + ASSERT (stat (BASE "dir/file", &st2) == 0); + ASSERT (st1.st_uid == st2.st_uid); + ASSERT (st1.st_gid == st2.st_gid); + ASSERT (lstat (BASE "dir/link", &st2) == 0); + ASSERT (st1.st_uid == st2.st_uid); + ASSERT (st1.st_gid == st2.st_gid); + ASSERT (lstat (BASE "dir/link2", &st2) == 0); + ASSERT (st1.st_uid == st2.st_uid); + ASSERT (st1.st_gid == st2.st_gid); + + ASSERT (func (BASE "dir/link2", -1, gids[0]) == 0); + ASSERT (stat (BASE "dir/file", &st2) == 0); + ASSERT (st1.st_uid == st2.st_uid); + ASSERT (st1.st_gid == st2.st_gid); + ASSERT (lstat (BASE "dir/link", &st2) == 0); + ASSERT (st1.st_uid == st2.st_uid); + ASSERT (st1.st_gid == st2.st_gid); + ASSERT (lstat (BASE "dir/link2", &st2) == 0); + ASSERT (st1.st_uid == st2.st_uid); + ASSERT (gids[0] == st2.st_gid); + + /* Trailing slash follows through to directory. */ + ASSERT (lstat (BASE "dir/link3", &st2) == 0); + ASSERT (st1.st_uid == st2.st_uid); + ASSERT (st1.st_gid == st2.st_gid); + ASSERT (lstat (BASE "dir/sub", &st2) == 0); + ASSERT (st1.st_uid == st2.st_uid); + ASSERT (st1.st_gid == st2.st_gid); + + ASSERT (func (BASE "dir/link3/", -1, gids[0]) == 0); + ASSERT (lstat (BASE "dir/link3", &st2) == 0); + ASSERT (st1.st_uid == st2.st_uid); + ASSERT (st1.st_gid == st2.st_gid); + ASSERT (lstat (BASE "dir/sub", &st2) == 0); + ASSERT (st1.st_uid == st2.st_uid); + ASSERT (gids[0] == st2.st_gid); + } + else + { + struct stat l1; + struct stat l2; + ASSERT (stat (BASE "dir/file", &st1) == 0); + ASSERT (lstat (BASE "dir/link", &l1) == 0); + ASSERT (lstat (BASE "dir/link2", &l2) == 0); + + nap (); + errno = 0; + ASSERT (func (BASE "dir/link2/", -1, st1.st_gid) == -1); + ASSERT (errno == ENOTDIR); + ASSERT (stat (BASE "dir/file", &st2) == 0); + ASSERT (st1.st_ctime == st2.st_ctime); + ASSERT (get_stat_ctime_ns (&st1) == get_stat_ctime_ns (&st2)); + ASSERT (lstat (BASE "dir/link", &st2) == 0); + ASSERT (l1.st_ctime == st2.st_ctime); + ASSERT (get_stat_ctime_ns (&l1) == get_stat_ctime_ns (&st2)); + ASSERT (lstat (BASE "dir/link2", &st2) == 0); + ASSERT (l2.st_ctime == st2.st_ctime); + ASSERT (get_stat_ctime_ns (&l2) == get_stat_ctime_ns (&st2)); + + ASSERT (func (BASE "dir/link2", -1, gids[0]) == 0); + ASSERT (stat (BASE "dir/file", &st2) == 0); + ASSERT (st1.st_ctime == st2.st_ctime); + ASSERT (get_stat_ctime_ns (&st1) == get_stat_ctime_ns (&st2)); + ASSERT (lstat (BASE "dir/link", &st2) == 0); + ASSERT (l1.st_ctime == st2.st_ctime); + ASSERT (get_stat_ctime_ns (&l1) == get_stat_ctime_ns (&st2)); + ASSERT (lstat (BASE "dir/link2", &st2) == 0); + ASSERT (l2.st_ctime < st2.st_ctime + || (l2.st_ctime == st2.st_ctime + && get_stat_ctime_ns (&l2) < get_stat_ctime_ns (&st2))); + + /* Trailing slash follows through to directory. */ + ASSERT (lstat (BASE "dir/sub", &st1) == 0); + ASSERT (lstat (BASE "dir/link3", &l1) == 0); + nap (); + ASSERT (func (BASE "dir/link3/", -1, gids[0]) == 0); + ASSERT (lstat (BASE "dir/link3", &st2) == 0); + ASSERT (l1.st_ctime == st2.st_ctime); + ASSERT (get_stat_ctime_ns (&l1) == get_stat_ctime_ns (&st2)); + ASSERT (lstat (BASE "dir/sub", &st2) == 0); + ASSERT (st1.st_ctime < st2.st_ctime + || (st1.st_ctime == st2.st_ctime + && get_stat_ctime_ns (&st1) < get_stat_ctime_ns (&st2))); + } + + /* Cleanup. */ + free (gids); + ASSERT (unlink (BASE "dir/file") == 0); + ASSERT (unlink (BASE "dir/link") == 0); + ASSERT (unlink (BASE "dir/link2") == 0); + ASSERT (unlink (BASE "dir/link3") == 0); + ASSERT (rmdir (BASE "dir/sub") == 0); + ASSERT (rmdir (BASE "dir") == 0); + return 0; +} -- 2.11.0