]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/basic/chase-symlinks.h
Merge pull request #24412 from keszybz/man-similarly
[thirdparty/systemd.git] / src / basic / chase-symlinks.h
CommitLineData
f4351959
LP
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2#pragma once
3
4#include <dirent.h>
5#include <stdio.h>
6
7#include "stat-util.h"
8
8f47f880 9typedef enum ChaseSymlinksFlags {
f4351959
LP
10 CHASE_PREFIX_ROOT = 1 << 0, /* The specified path will be prefixed by the specified root before beginning the iteration */
11 CHASE_NONEXISTENT = 1 << 1, /* It's OK if the path doesn't actually exist. */
12 CHASE_NO_AUTOFS = 1 << 2, /* Return -EREMOTE if autofs mount point found */
13 CHASE_SAFE = 1 << 3, /* Return -EPERM if we ever traverse from unprivileged to privileged files or directories */
14 CHASE_TRAIL_SLASH = 1 << 4, /* Any trailing slash will be preserved */
15 CHASE_STEP = 1 << 5, /* Just execute a single step of the normalization */
16 CHASE_NOFOLLOW = 1 << 6, /* Do not follow the path's right-most component. With ret_fd, when the path's
17 * right-most component refers to symlink, return O_PATH fd of the symlink. */
18 CHASE_WARN = 1 << 7, /* Emit an appropriate warning when an error is encountered */
8f47f880 19} ChaseSymlinksFlags;
f4351959
LP
20
21bool unsafe_transition(const struct stat *a, const struct stat *b);
22
23/* How many iterations to execute before returning -ELOOP */
24#define CHASE_SYMLINKS_MAX 32
25
8f47f880 26int chase_symlinks(const char *path_with_prefix, const char *root, ChaseSymlinksFlags chase_flags, char **ret_path, int *ret_fd);
f4351959 27
8f47f880
LP
28int chase_symlinks_and_open(const char *path, const char *root, ChaseSymlinksFlags chase_flags, int open_flags, char **ret_path);
29int chase_symlinks_and_opendir(const char *path, const char *root, ChaseSymlinksFlags chase_flags, char **ret_path, DIR **ret_dir);
30int chase_symlinks_and_stat(const char *path, const char *root, ChaseSymlinksFlags chase_flags, char **ret_path, struct stat *ret_stat, int *ret_fd);
2b2caea2 31int chase_symlinks_and_access(const char *path, const char *root, ChaseSymlinksFlags chase_flags, int access_mode, char **ret_path, int *ret_fd);
8f47f880 32int chase_symlinks_and_fopen_unlocked(const char *path, const char *root, ChaseSymlinksFlags chase_flags, const char *open_flags, char **ret_path, FILE **ret_file);