-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__lstat50.c
76 lines (61 loc) · 1.49 KB
/
__lstat50.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Copyright 2024 Gaël PORTAY
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#ifdef __NetBSD__
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <limits.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "iamroot.h"
static int (*sym)(const char *, struct stat *);
hidden int next___lstat50(const char *path, struct stat *statbuf)
{
if (!sym)
sym = dlsym(RTLD_NEXT, "__lstat50");
if (!sym)
return __dl_set_errno_and_perror(ENOSYS, -1);
return sym(path, statbuf);
}
int __lstat50(const char *path, struct stat *statbuf)
{
char buf[PATH_MAX];
int ret = -1;
ssize_t siz;
uid_t uid;
gid_t gid;
/*
* According to symlink(7):
*
* Various system calls do not follow links in the basename component
* of a pathname, and operate on the symbolic link itself. They are:
* lchown(2), lgetxattr(2), llistxattr(2), lremovexattr(2),
* lsetxattr(2), lstat(2), readlink(2), rename(2), rmdir(2), and
* unlink(2).
*/
siz = path_resolution2(AT_FDCWD, path, buf, sizeof(buf),
AT_SYMLINK_NOFOLLOW,
PATH_RESOLUTION_NOWALKALONG);
if (siz == -1)
goto exit;
ret = next___lstat50(buf, statbuf);
if (ret == -1)
goto exit;
uid = __get_uid(buf);
if (uid == (uid_t)-1)
statbuf->st_uid = 0;
gid = __get_gid(buf);
if (gid == (gid_t)-1)
statbuf->st_gid = 0;
__st_mode(buf, statbuf);
__st_uid(buf, statbuf);
__st_gid(buf, statbuf);
exit:
__debug("%s(path: '%s' -> '%s', ...) -> %i\n", __func__, path, buf, ret);
return ret;
}
#endif