]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/vpick.h
cryptenroll: allow to use a public key on a token
[thirdparty/systemd.git] / src / shared / vpick.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <sys/types.h>
5
6 #include "architecture.h"
7
8 typedef enum PickFlags {
9 PICK_ARCHITECTURE = 1 << 0, /* Look for an architecture suffix */
10 PICK_TRIES = 1 << 1, /* Look for tries left/tries done counters */
11 PICK_RESOLVE = 1 << 2, /* Return the fully resolved (chased) path, rather than the path to the entry */
12 } PickFlags;
13
14 typedef struct PickFilter {
15 uint32_t type_mask; /* A mask of 1U << DT_REG, 1U << DT_DIR, … */
16 const char *basename; /* Can be overridden by search pattern */
17 const char *version;
18 Architecture architecture;
19 const char *suffix; /* Can be overridden by search pattern */
20 } PickFilter;
21
22 typedef struct PickResult {
23 char *path;
24 int fd; /* O_PATH */
25 struct stat st;
26 char *version;
27 Architecture architecture;
28 unsigned tries_left;
29 unsigned tries_done;
30 } PickResult;
31
32 #define PICK_RESULT_NULL \
33 (const PickResult) { \
34 .fd = -EBADF, \
35 .st.st_mode = MODE_INVALID, \
36 .architecture = _ARCHITECTURE_INVALID, \
37 .tries_left = UINT_MAX, \
38 .tries_done = UINT_MAX, \
39 }
40
41 #define TAKE_PICK_RESULT(pick) TAKE_GENERIC(pick, PickResult, PICK_RESULT_NULL)
42
43 void pick_result_done(PickResult *p);
44
45 int path_pick(const char *toplevel_path,
46 int toplevel_fd,
47 const char *path,
48 const PickFilter *filter,
49 PickFlags flags,
50 PickResult *ret);
51
52 int path_pick_update_warn(
53 char **path,
54 const PickFilter *filter,
55 PickFlags flags,
56 PickResult *ret);
57
58 extern const PickFilter pick_filter_image_raw;
59 extern const PickFilter pick_filter_image_dir;