1 /* Test that lstat does not follow symbolic links.
2 Copyright (C) 2024-2025 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
20 #include <support/check.h>
21 #include <support/fuse.h>
22 #include <support/support.h>
27 fuse_thread (struct support_fuse
*f
, void *closure
)
29 struct fuse_in_header
*inh
;
30 while ((inh
= support_fuse_next (f
)) != NULL
)
32 if (support_fuse_handle_mountpoint (f
)
33 || (inh
->nodeid
== 1 && support_fuse_handle_directory (f
)))
39 TEST_COMPARE (inh
->nodeid
, 1);
40 TEST_COMPARE_STRING (support_fuse_cast (LOOKUP
, inh
), "symlink");
41 struct fuse_entry_out
*out
= support_fuse_prepare_entry (f
, 2);
42 out
->attr
.mode
= S_IFLNK
| 0777;
43 out
->attr
.size
= strlen ("target");
44 support_fuse_reply_prepared (f
);
49 TEST_COMPARE (inh
->nodeid
, 2);
50 struct fuse_attr_out
*out
= support_fuse_prepare_attr (f
);
51 out
->attr
.mode
= S_IFLNK
| 0777;
52 out
->attr
.size
= strlen ("target");
53 support_fuse_reply_prepared (f
);
57 /* The lstat operation must not attempt to look at the
58 symbolic link target. */
59 FAIL ("attempt to obtain target of symblic link for node %llu",
60 (unsigned long long int) inh
->nodeid
);
63 FAIL ("unexpected event %s", support_fuse_opcode (inh
->opcode
));
72 struct support_fuse
*f
= support_fuse_mount (fuse_thread
, NULL
);
73 char *symlink_path
= xasprintf ("%s/symlink", support_fuse_mountpoint (f
));
76 struct stat st
= { 0, };
77 TEST_COMPARE (lstat (symlink_path
, &st
), 0);
78 TEST_COMPARE (st
.st_uid
, getuid ());
79 TEST_COMPARE (st
.st_gid
, getgid ());
80 TEST_COMPARE (st
.st_size
, 6);
81 TEST_COMPARE (st
.st_mode
, S_IFLNK
| 0777);
85 struct stat64 st
= { 0, };
86 TEST_COMPARE (lstat64 (symlink_path
, &st
), 0);
87 TEST_COMPARE (st
.st_uid
, getuid ());
88 TEST_COMPARE (st
.st_gid
, getgid ());
89 TEST_COMPARE (st
.st_size
, 6);
90 TEST_COMPARE (st
.st_mode
, S_IFLNK
| 0777);
94 support_fuse_unmount (f
);
98 #include <support/test-driver.c>