15 #define MBUF_LENGTH 1024
17 int xdev_allow(const char *pathname
)
19 char realpathname
[PATH_MAX
];
20 FILE* proc_mounts
= NULL
;
21 char mbuf
[MBUF_LENGTH
+1];
28 warnx("xdev? %s", pathname
);
30 proc_mounts
= fopen("/proc/mounts", "r");
31 if(proc_mounts
== NULL
)
33 err(1, "/proc/mounts: open");
36 if(realpath(pathname
, realpathname
) != NULL
)
38 while(fgets(mbuf
, MBUF_LENGTH
, proc_mounts
) != NULL
)
41 space
= strchr(mbuf
, ' ');
46 space
= strchr(mntpnt
, ' ');
51 space
= strchr(mntype
, ' ');
56 space
= strchr(mntopt
, ' ');
60 if(strncmp(realpathname
, mntpnt
, strlen(mntpnt
)) == 0)
62 /* It's a mountpoint, or under a mountpoint */
64 /* Deny if it is likely a network device */
65 if(strncmp(mntdev
, "//", 2) == 0 || strchr(mntdev
, ':') != NULL
)
90 int __lxstat64(int ver
, const char *path
, struct stat64
*buf
)
92 int (*real___lxstat64
)(int, const char *, struct stat64
*) = dlsym(RTLD_NEXT
, "__lxstat64");
93 if(xdev_allow(path
)) return real___lxstat64(ver
, path
, buf
);
97 int __openat_2(int fd
, const char *path
, int oflag
, mode_t mode
)
99 int (*real___openat_2
)(int, const char*, int, mode_t
) = dlsym(RTLD_NEXT
, "__openat_2");
100 if(xdev_allow(path
)) return real___openat_2(fd
, path
, oflag
, mode
);
104 DIR* opendir(const char *pathname
)
106 DIR* (*real_opendir
)(const char *) = dlsym(RTLD_NEXT
, "opendir");
107 if(xdev_allow(pathname
)) return real_opendir(pathname
);
111 int xdev_ftw_cb(const char *fpath
, const struct stat
*sb
, int typeflag
, struct FTW
*ftwbuf
112 // ,int (*real_cb)(const char*, const struct stat*, int, struct FTW*)
115 // if(xdev_allow(fpath)) return real_cb(fpath, sb, typeflag, ftwbuf);
120 int nftw64(const char *dirpath
,
121 // int (*fgv)(const char*, const struct stat*, int, struct FTW*),
123 int nopenfd
, int flags
)
125 int (*real_nftw64
)(const char *, int (*)(const char*, const struct stat
*, int, struct FTW
*), int, int) = dlsym(RTLD_NEXT
, "nftw64");
126 return real_nftw64(dirpath
, xdev_ftw_cb
, nopenfd
, flags
);