/* Can't setns to your own userns, since then you could escalate from non-root to root in
* your own namespace, so check if namespaces are equal before attempting to enter. */
- r = files_same(FORMAT_PROC_FD_PATH(userns_fd), "/proc/self/ns/user", 0);
+ r = inode_same(FORMAT_PROC_FD_PATH(userns_fd), "/proc/self/ns/user", 0);
if (r < 0)
return r;
if (r)
}
}
-bool path_equal_or_files_same(const char *a, const char *b, int flags) {
- return path_equal(a, b) || files_same(a, b, flags) > 0;
+bool path_equal_or_inode_same(const char *a, const char *b, int flags) {
+ return path_equal(a, b) || inode_same(a, b, flags) > 0;
}
int path_compare_filename(const char *a, const char *b) {
return path_compare_filename(a, b) == 0;
}
-bool path_equal_or_files_same(const char *a, const char *b, int flags);
+bool path_equal_or_inode_same(const char *a, const char *b, int flags);
char* path_extend_internal(char **x, ...);
#define path_extend(x, ...) path_extend_internal(x, __VA_ARGS__, POINTER_MAX)
root = procfs_file_alloca(pid, "root");
- return files_same(root, "/proc/1/root", 0);
+ return inode_same(root, "/proc/1/root", 0);
}
bool is_main_thread(void) {
return false;
if (a->sockaddr.un.sun_path[0]) {
- if (!path_equal_or_files_same(a->sockaddr.un.sun_path, b->sockaddr.un.sun_path, 0))
+ if (!path_equal_or_inode_same(a->sockaddr.un.sun_path, b->sockaddr.un.sun_path, 0))
return false;
} else {
if (a->size != b->size)
return fd_is_read_only_fs(fd);
}
-int files_same_at(int fda, const char *filea, int fdb, const char *fileb, int flags) {
+int inode_same_at(int fda, const char *filea, int fdb, const char *fileb, int flags) {
struct stat a, b;
assert(fda >= 0 || fda == AT_FDCWD);
int path_is_read_only_fs(const char *path);
-int files_same_at(int fda, const char *filea, int fdb, const char *fileb, int flags);
+int inode_same_at(int fda, const char *filea, int fdb, const char *fileb, int flags);
-static inline int files_same(const char *filea, const char *fileb, int flags) {
- return files_same_at(AT_FDCWD, filea, AT_FDCWD, fileb, flags);
+static inline int inode_same(const char *filea, const char *fileb, int flags) {
+ return inode_same_at(AT_FDCWD, filea, AT_FDCWD, fileb, flags);
}
/* The .f_type field of struct statfs is really weird defined on
if (getpid_cached() == 1)
return false; /* We're PID 1, we can't be in a chroot. */
- r = files_same("/proc/1/root", "/", 0);
+ r = inode_same("/proc/1/root", "/", 0);
if (r == -ENOENT) {
r = proc_mounted();
if (r == 0) {
LIST_FOREACH(port, p, s->ports)
if (p->fd < 0 &&
p->type == SOCKET_FIFO &&
- path_equal_or_files_same(p->path, value, 0)) {
+ path_equal_or_inode_same(p->path, value, 0)) {
p->fd = fdset_remove(fds, fd);
found = true;
break;
LIST_FOREACH(port, p, s->ports)
if (p->fd < 0 &&
p->type == SOCKET_SPECIAL &&
- path_equal_or_files_same(p->path, value, 0)) {
+ path_equal_or_inode_same(p->path, value, 0)) {
p->fd = fdset_remove(fds, fd);
found = true;
break;
LIST_FOREACH(port, p, s->ports)
if (p->fd < 0 &&
p->type == SOCKET_USB_FUNCTION &&
- path_equal_or_files_same(p->path, value, 0)) {
+ path_equal_or_inode_same(p->path, value, 0)) {
p->fd = fdset_remove(fds, fd);
found = true;
break;
continue;
}
- if (files_same(s, backing_file, 0) <= 0)
+ if (inode_same(s, backing_file, 0) <= 0)
continue;
*ret = sd_device_ref(dev);
if (!a || !b)
return log_oom();
- r = path_equal_or_files_same(a, b, 0);
+ r = path_equal_or_inode_same(a, b, 0);
if (r != 0)
return r;
/* We refuse to clean the root file system with this call. This is extra paranoia to never cause a
* really seriously broken system. */
- if (path_equal_or_files_same(path, "/", AT_SYMLINK_NOFOLLOW))
+ if (path_equal_or_inode_same(path, "/", AT_SYMLINK_NOFOLLOW))
return log_error_errno(SYNTHETIC_ERRNO(EPERM),
"Attempted to remove entire root file system (\"%s\"), and we can't allow that.",
path);
if (new_root_fd < 0)
return log_error_errno(errno, "Failed to open target directory '%s': %m", new_root);
- r = files_same_at(old_root_fd, "", new_root_fd, "", AT_EMPTY_PATH);
+ r = inode_same_at(old_root_fd, "", new_root_fd, "", AT_EMPTY_PATH);
if (r < 0)
return log_error_errno(r, "Failed to determine if old and new root directory are the same: %m");
if (r > 0) {
/* Make sure that files_same works as expected. */
- assert_se(files_same("/", "/", 0) > 0);
- assert_se(files_same("/", "/", AT_SYMLINK_NOFOLLOW) > 0);
- assert_se(files_same("/", "//", 0) > 0);
- assert_se(files_same("/", "//", AT_SYMLINK_NOFOLLOW) > 0);
+ assert_se(inode_same("/", "/", 0) > 0);
+ assert_se(inode_same("/", "/", AT_SYMLINK_NOFOLLOW) > 0);
+ assert_se(inode_same("/", "//", 0) > 0);
+ assert_se(inode_same("/", "//", AT_SYMLINK_NOFOLLOW) > 0);
- assert_se(files_same("/", "/./", 0) > 0);
- assert_se(files_same("/", "/./", AT_SYMLINK_NOFOLLOW) > 0);
- assert_se(files_same("/", "/../", 0) > 0);
- assert_se(files_same("/", "/../", AT_SYMLINK_NOFOLLOW) > 0);
+ assert_se(inode_same("/", "/./", 0) > 0);
+ assert_se(inode_same("/", "/./", AT_SYMLINK_NOFOLLOW) > 0);
+ assert_se(inode_same("/", "/../", 0) > 0);
+ assert_se(inode_same("/", "/../", AT_SYMLINK_NOFOLLOW) > 0);
- assert_se(files_same("/", "/.../", 0) == -ENOENT);
- assert_se(files_same("/", "/.../", AT_SYMLINK_NOFOLLOW) == -ENOENT);
+ assert_se(inode_same("/", "/.../", 0) == -ENOENT);
+ assert_se(inode_same("/", "/.../", AT_SYMLINK_NOFOLLOW) == -ENOENT);
/* The same for path_equal_or_files_same. */
- assert_se(path_equal_or_files_same("/", "/", 0));
- assert_se(path_equal_or_files_same("/", "/", AT_SYMLINK_NOFOLLOW));
- assert_se(path_equal_or_files_same("/", "//", 0));
- assert_se(path_equal_or_files_same("/", "//", AT_SYMLINK_NOFOLLOW));
+ assert_se(path_equal_or_inode_same("/", "/", 0));
+ assert_se(path_equal_or_inode_same("/", "/", AT_SYMLINK_NOFOLLOW));
+ assert_se(path_equal_or_inode_same("/", "//", 0));
+ assert_se(path_equal_or_inode_same("/", "//", AT_SYMLINK_NOFOLLOW));
- assert_se(path_equal_or_files_same("/", "/./", 0));
- assert_se(path_equal_or_files_same("/", "/./", AT_SYMLINK_NOFOLLOW));
- assert_se(path_equal_or_files_same("/", "/../", 0));
- assert_se(path_equal_or_files_same("/", "/../", AT_SYMLINK_NOFOLLOW));
+ assert_se(path_equal_or_inode_same("/", "/./", 0));
+ assert_se(path_equal_or_inode_same("/", "/./", AT_SYMLINK_NOFOLLOW));
+ assert_se(path_equal_or_inode_same("/", "/../", 0));
+ assert_se(path_equal_or_inode_same("/", "/../", AT_SYMLINK_NOFOLLOW));
- assert_se(!path_equal_or_files_same("/", "/.../", 0));
- assert_se(!path_equal_or_files_same("/", "/.../", AT_SYMLINK_NOFOLLOW));
+ assert_se(!path_equal_or_inode_same("/", "/.../", 0));
+ assert_se(!path_equal_or_inode_same("/", "/.../", AT_SYMLINK_NOFOLLOW));
}
TEST(find_executable_full) {
puts(strnull(w));
/* /dev/initctl should normally be a symlink to /run/initctl */
- if (files_same("/dev/initctl", "/run/initctl", 0) > 0)
+ if (inode_same("/dev/initctl", "/run/initctl", 0) > 0)
assert_se(streq(w, "p=/dev/initctl y=/run/initctl Y=/run w=/dev/tty W=/dev"));
}
assert_se(null_or_empty_path_with_root("/foobar/barbar/dev/null", "/foobar/barbar/") == 1);
}
-TEST(files_same) {
+TEST(inode_same) {
_cleanup_close_ int fd = -EBADF;
_cleanup_(unlink_tempfilep) char name[] = "/tmp/test-files_same.XXXXXX";
_cleanup_(unlink_tempfilep) char name_alias[] = "/tmp/test-files_same.alias";
assert_se(fd >= 0);
assert_se(symlink(name, name_alias) >= 0);
- assert_se(files_same(name, name, 0));
- assert_se(files_same(name, name, AT_SYMLINK_NOFOLLOW));
- assert_se(files_same(name, name_alias, 0));
- assert_se(!files_same(name, name_alias, AT_SYMLINK_NOFOLLOW));
+ assert_se(inode_same(name, name, 0));
+ assert_se(inode_same(name, name, AT_SYMLINK_NOFOLLOW));
+ assert_se(inode_same(name, name_alias, 0));
+ assert_se(!inode_same(name, name_alias, AT_SYMLINK_NOFOLLOW));
}
TEST(is_symlink) {