| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "shared-forward.h" |
| 5 |
|
| 6 |
typedef int (*SpecifierCallback)(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 7 |
|
| 8 |
typedef struct Specifier { |
| 9 |
const char specifier; |
| 10 |
const SpecifierCallback lookup; |
| 11 |
const void *data; |
| 12 |
} Specifier; |
| 13 |
|
| 14 |
int specifier_printf(const char *text, size_t max_length, const Specifier table[], const char *root, const void *userdata, char **ret); |
| 15 |
|
| 16 |
int specifier_string(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 17 |
int specifier_real_path(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 18 |
int specifier_real_directory(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 19 |
int specifier_id128(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 20 |
int specifier_uuid(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 21 |
int specifier_uint64(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 22 |
|
| 23 |
int specifier_machine_id(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 24 |
int specifier_boot_id(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 25 |
int specifier_hostname(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 26 |
int specifier_short_hostname(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 27 |
int specifier_pretty_hostname(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 28 |
int specifier_kernel_release(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 29 |
int specifier_architecture(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 30 |
int specifier_os_id(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 31 |
int specifier_os_version_id(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 32 |
int specifier_os_build_id(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 33 |
int specifier_os_variant_id(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 34 |
int specifier_os_image_id(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 35 |
int specifier_os_image_version(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 36 |
|
| 37 |
int specifier_group_name(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 38 |
int specifier_group_id(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 39 |
int specifier_user_name(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 40 |
int specifier_user_id(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 41 |
int specifier_user_home(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 42 |
int specifier_user_shell(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 43 |
|
| 44 |
int specifier_tmp_dir(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 45 |
int specifier_var_tmp_dir(char specifier, const void *data, const char *root, const void *userdata, char **ret); |
| 46 |
|
| 47 |
/* Typically, in places where one of the above specifier is to be resolved the other similar ones are to be |
| 48 |
* resolved, too. Hence let's define common macros for the relevant array entries. |
| 49 |
* |
| 50 |
* COMMON_SYSTEM_SPECIFIERS: |
| 51 |
* %a: the native userspace architecture |
| 52 |
* %A: the OS image version, according to /etc/os-release |
| 53 |
* %b: the boot ID of the running system |
| 54 |
* %B: the OS build ID, according to /etc/os-release |
| 55 |
* %H: the hostname of the running system |
| 56 |
* %l: the short hostname of the running system |
| 57 |
* %q: the 'pretty' hostname as per /etc/machine-info |
| 58 |
* %m: the machine ID of the running system |
| 59 |
* %M: the OS image ID, according to /etc/os-release |
| 60 |
* %o: the OS ID according to /etc/os-release |
| 61 |
* %v: the kernel version |
| 62 |
* %w: the OS version ID, according to /etc/os-release |
| 63 |
* %W: the OS variant ID, according to /etc/os-release |
| 64 |
* |
| 65 |
* COMMON_CREDS_SPECIFIERS: |
| 66 |
* %g: the groupname of the running user |
| 67 |
* %G: the GID of the running user |
| 68 |
* %u: the username of the running user |
| 69 |
* %U: the UID of the running user |
| 70 |
* |
| 71 |
* COMMON_TMP_SPECIFIERS: |
| 72 |
* %T: the temporary directory (e.g. /tmp, or $TMPDIR, $TEMP, $TMP) |
| 73 |
* %V: the temporary directory for large, persistent stuff (e.g. /var/tmp, or $TMPDIR, $TEMP, $TMP) |
| 74 |
*/ |
| 75 |
|
| 76 |
#define COMMON_SYSTEM_SPECIFIERS \ |
| 77 |
{ 'a', specifier_architecture, NULL }, \ |
| 78 |
{ 'A', specifier_os_image_version, NULL }, \ |
| 79 |
{ 'b', specifier_boot_id, NULL }, \ |
| 80 |
{ 'B', specifier_os_build_id, NULL }, \ |
| 81 |
{ 'H', specifier_hostname, NULL }, \ |
| 82 |
{ 'l', specifier_short_hostname, NULL }, \ |
| 83 |
{ 'q', specifier_pretty_hostname, NULL }, \ |
| 84 |
{ 'm', specifier_machine_id, NULL }, \ |
| 85 |
{ 'M', specifier_os_image_id, NULL }, \ |
| 86 |
{ 'o', specifier_os_id, NULL }, \ |
| 87 |
{ 'v', specifier_kernel_release, NULL }, \ |
| 88 |
{ 'w', specifier_os_version_id, NULL }, \ |
| 89 |
{ 'W', specifier_os_variant_id, NULL } |
| 90 |
|
| 91 |
#define COMMON_CREDS_SPECIFIERS(scope) \ |
| 92 |
{ 'g', specifier_group_name, INT_TO_PTR(scope) }, \ |
| 93 |
{ 'G', specifier_group_id, INT_TO_PTR(scope) }, \ |
| 94 |
{ 'u', specifier_user_name, INT_TO_PTR(scope) }, \ |
| 95 |
{ 'U', specifier_user_id, INT_TO_PTR(scope) } |
| 96 |
|
| 97 |
#define COMMON_TMP_SPECIFIERS \ |
| 98 |
{ 'T', specifier_tmp_dir, NULL }, \ |
| 99 |
{ 'V', specifier_var_tmp_dir, NULL } |
| 100 |
|
| 101 |
char* specifier_escape(const char *string); |
| 102 |
|
| 103 |
int specifier_escape_strv(char **l, char ***ret); |
| 104 |
|
| 105 |
/* A generic specifier table consisting of COMMON_SYSTEM_SPECIFIERS and COMMON_TMP_SPECIFIERS */ |
| 106 |
extern const Specifier system_and_tmp_specifier_table[]; |