1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
10 #include <sys/utsname.h>
16 #include "alloc-util.h"
17 #include "apparmor-util.h"
18 #include "architecture.h"
19 #include "audit-util.h"
20 #include "blockdev-util.h"
22 #include "cgroup-util.h"
23 #include "condition.h"
24 #include "cpu-set-util.h"
25 #include "efi-loader.h"
27 #include "extract-word.h"
31 #include "glob-util.h"
32 #include "hostname-util.h"
34 #include "limits-util.h"
37 #include "mountpoint-util.h"
38 #include "parse-util.h"
39 #include "path-util.h"
40 #include "proc-cmdline.h"
41 #include "process-util.h"
42 #include "selinux-util.h"
43 #include "smack-util.h"
44 #include "stat-util.h"
45 #include "string-table.h"
46 #include "string-util.h"
47 #include "tomoyo-util.h"
48 #include "user-record.h"
49 #include "user-util.h"
53 Condition
* condition_new(ConditionType type
, const char *parameter
, bool trigger
, bool negate
) {
57 assert(type
< _CONDITION_TYPE_MAX
);
60 c
= new(Condition
, 1);
71 c
->parameter
= strdup(parameter
);
79 Condition
* condition_free(Condition
*c
) {
86 Condition
* condition_free_list_type(Condition
*head
, ConditionType type
) {
89 LIST_FOREACH_SAFE(conditions
, c
, n
, head
)
90 if (type
< 0 || c
->type
== type
) {
91 LIST_REMOVE(conditions
, head
, c
);
95 assert(type
>= 0 || !head
);
99 static int condition_test_kernel_command_line(Condition
*c
, char **env
) {
100 _cleanup_free_
char *line
= NULL
;
106 assert(c
->parameter
);
107 assert(c
->type
== CONDITION_KERNEL_COMMAND_LINE
);
109 r
= proc_cmdline(&line
);
113 equal
= strchr(c
->parameter
, '=');
116 _cleanup_free_
char *word
= NULL
;
119 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
|EXTRACT_RELAX
);
126 found
= streq(word
, c
->parameter
);
130 f
= startswith(word
, c
->parameter
);
131 found
= f
&& IN_SET(*f
, 0, '=');
142 /* Listed in order of checking. Note that some comparators are prefixes of others, hence the longest
143 * should be listed first. */
144 ORDER_LOWER_OR_EQUAL
,
145 ORDER_GREATER_OR_EQUAL
,
151 _ORDER_INVALID
= -EINVAL
,
154 static OrderOperator
parse_order(const char **s
) {
156 static const char *const prefix
[_ORDER_MAX
] = {
157 [ORDER_LOWER_OR_EQUAL
] = "<=",
158 [ORDER_GREATER_OR_EQUAL
] = ">=",
160 [ORDER_GREATER
] = ">",
162 [ORDER_UNEQUAL
] = "!=",
167 for (i
= 0; i
< _ORDER_MAX
; i
++) {
170 e
= startswith(*s
, prefix
[i
]);
177 return _ORDER_INVALID
;
180 static bool test_order(int k
, OrderOperator p
) {
187 case ORDER_LOWER_OR_EQUAL
:
196 case ORDER_GREATER_OR_EQUAL
:
203 assert_not_reached("unknown order");
208 static int condition_test_kernel_version(Condition
*c
, char **env
) {
215 assert(c
->parameter
);
216 assert(c
->type
== CONDITION_KERNEL_VERSION
);
218 assert_se(uname(&u
) >= 0);
223 _cleanup_free_
char *word
= NULL
;
227 r
= extract_first_word(&p
, &word
, NULL
, EXTRACT_UNQUOTE
);
229 return log_debug_errno(r
, "Failed to parse condition string \"%s\": %m", p
);
234 order
= parse_order(&s
);
236 s
+= strspn(s
, WHITESPACE
);
239 /* For backwards compatibility, allow whitespace between the operator and
240 * value, without quoting, but only in the first expression. */
242 r
= extract_first_word(&p
, &word
, NULL
, 0);
244 return log_debug_errno(r
, "Failed to parse condition string \"%s\": %m", p
);
246 return log_debug_errno(SYNTHETIC_ERRNO(EINVAL
), "Unexpected end of expression: %s", p
);
249 return log_debug_errno(SYNTHETIC_ERRNO(EINVAL
), "Unexpected end of expression: %s", p
);
252 r
= test_order(strverscmp_improved(u
.release
, s
), order
);
254 /* No prefix? Then treat as glob string */
255 r
= fnmatch(s
, u
.release
, 0) == 0;
266 static int condition_test_memory(Condition
*c
, char **env
) {
273 assert(c
->parameter
);
274 assert(c
->type
== CONDITION_MEMORY
);
276 m
= physical_memory();
279 order
= parse_order(&p
);
281 order
= ORDER_GREATER_OR_EQUAL
; /* default to >= check, if nothing is specified. */
283 r
= safe_atou64(p
, &k
);
285 return log_debug_errno(r
, "Failed to parse size: %m");
287 return test_order(CMP(m
, k
), order
);
290 static int condition_test_cpus(Condition
*c
, char **env
) {
297 assert(c
->parameter
);
298 assert(c
->type
== CONDITION_CPUS
);
300 n
= cpus_in_affinity_mask();
302 return log_debug_errno(n
, "Failed to determine CPUs in affinity mask: %m");
305 order
= parse_order(&p
);
307 order
= ORDER_GREATER_OR_EQUAL
; /* default to >= check, if nothing is specified. */
309 r
= safe_atou(p
, &k
);
311 return log_debug_errno(r
, "Failed to parse number of CPUs: %m");
313 return test_order(CMP((unsigned) n
, k
), order
);
316 static int condition_test_user(Condition
*c
, char **env
) {
319 _cleanup_free_
char *username
= NULL
;
323 assert(c
->parameter
);
324 assert(c
->type
== CONDITION_USER
);
326 r
= parse_uid(c
->parameter
, &id
);
328 return id
== getuid() || id
== geteuid();
330 if (streq("@system", c
->parameter
))
331 return uid_is_system(getuid()) || uid_is_system(geteuid());
333 username
= getusername_malloc();
337 if (streq(username
, c
->parameter
))
340 if (getpid_cached() == 1)
341 return streq(c
->parameter
, "root");
344 r
= get_user_creds(&u
, &id
, NULL
, NULL
, NULL
, USER_CREDS_ALLOW_MISSING
);
348 return id
== getuid() || id
== geteuid();
351 static int condition_test_control_group_controller(Condition
*c
, char **env
) {
353 CGroupMask system_mask
, wanted_mask
= 0;
356 assert(c
->parameter
);
357 assert(c
->type
== CONDITION_CONTROL_GROUP_CONTROLLER
);
359 if (streq(c
->parameter
, "v2"))
360 return cg_all_unified();
361 if (streq(c
->parameter
, "v1")) {
362 r
= cg_all_unified();
368 r
= cg_mask_supported(&system_mask
);
370 return log_debug_errno(r
, "Failed to determine supported controllers: %m");
372 r
= cg_mask_from_string(c
->parameter
, &wanted_mask
);
373 if (r
< 0 || wanted_mask
<= 0) {
374 /* This won't catch the case that we have an unknown controller
375 * mixed in with valid ones -- these are only assessed on the
376 * validity of the valid controllers found. */
377 log_debug("Failed to parse cgroup string: %s", c
->parameter
);
381 return FLAGS_SET(system_mask
, wanted_mask
);
384 static int condition_test_group(Condition
*c
, char **env
) {
389 assert(c
->parameter
);
390 assert(c
->type
== CONDITION_GROUP
);
392 r
= parse_gid(c
->parameter
, &id
);
396 /* Avoid any NSS lookups if we are PID1 */
397 if (getpid_cached() == 1)
398 return streq(c
->parameter
, "root");
400 return in_group(c
->parameter
) > 0;
403 static int condition_test_virtualization(Condition
*c
, char **env
) {
407 assert(c
->parameter
);
408 assert(c
->type
== CONDITION_VIRTUALIZATION
);
410 if (streq(c
->parameter
, "private-users"))
411 return running_in_userns();
413 v
= detect_virtualization();
417 /* First, compare with yes/no */
418 b
= parse_boolean(c
->parameter
);
422 /* Then, compare categorization */
423 if (streq(c
->parameter
, "vm"))
424 return VIRTUALIZATION_IS_VM(v
);
426 if (streq(c
->parameter
, "container"))
427 return VIRTUALIZATION_IS_CONTAINER(v
);
429 /* Finally compare id */
430 return v
!= VIRTUALIZATION_NONE
&& streq(c
->parameter
, virtualization_to_string(v
));
433 static int condition_test_architecture(Condition
*c
, char **env
) {
437 assert(c
->parameter
);
438 assert(c
->type
== CONDITION_ARCHITECTURE
);
440 a
= uname_architecture();
444 if (streq(c
->parameter
, "native"))
445 b
= native_architecture();
447 b
= architecture_from_string(c
->parameter
);
448 if (b
< 0) /* unknown architecture? Then it's definitely not ours */
455 #define DTCOMPAT_FILE "/sys/firmware/devicetree/base/compatible"
456 static int condition_test_firmware_devicetree_compatible(const char *dtcarg
) {
458 _cleanup_free_
char *dtcompat
= NULL
;
459 _cleanup_strv_free_
char **dtcompatlist
= NULL
;
462 r
= read_full_virtual_file(DTCOMPAT_FILE
, &dtcompat
, &size
);
464 /* if the path doesn't exist it is incompatible */
466 log_debug_errno(r
, "Failed to open() '%s', assuming machine is incompatible: %m", DTCOMPAT_FILE
);
470 /* Not sure this can happen, but play safe. */
472 log_debug("%s has zero length, assuming machine is incompatible", DTCOMPAT_FILE
);
477 * /sys/firmware/devicetree/base/compatible consists of one or more
478 * strings, each ending in '\0'. So the last character in dtcompat must
481 if (dtcompat
[size
- 1] != '\0') {
482 log_debug("%s is in an unknown format, assuming machine is incompatible", DTCOMPAT_FILE
);
486 dtcompatlist
= strv_parse_nulstr(dtcompat
, size
);
490 return strv_contains(dtcompatlist
, dtcarg
);
493 static int condition_test_firmware(Condition
*c
, char **env
) {
497 assert(c
->parameter
);
498 assert(c
->type
== CONDITION_FIRMWARE
);
500 if (streq(c
->parameter
, "device-tree")) {
501 if (access("/sys/firmware/device-tree/", F_OK
) < 0) {
503 log_debug_errno(errno
, "Unexpected error when checking for /sys/firmware/device-tree/: %m");
507 } else if ((dtc
= startswith(c
->parameter
, "device-tree-compatible("))) {
508 _cleanup_free_
char *dtcarg
= NULL
;
511 end
= strchr(dtc
, ')');
512 if (!end
|| *(end
+ 1) != '\0') {
513 log_debug("Malformed Firmware condition \"%s\"", c
->parameter
);
517 dtcarg
= strndup(dtc
, end
- dtc
);
521 return condition_test_firmware_devicetree_compatible(dtcarg
);
522 } else if (streq(c
->parameter
, "uefi"))
523 return is_efi_boot();
525 log_debug("Unsupported Firmware condition \"%s\"", c
->parameter
);
530 static int condition_test_host(Condition
*c
, char **env
) {
531 _cleanup_free_
char *h
= NULL
;
536 assert(c
->parameter
);
537 assert(c
->type
== CONDITION_HOST
);
539 if (sd_id128_from_string(c
->parameter
, &x
) >= 0) {
541 r
= sd_id128_get_machine(&y
);
545 return sd_id128_equal(x
, y
);
548 h
= gethostname_malloc();
552 return fnmatch(c
->parameter
, h
, FNM_CASEFOLD
) == 0;
555 static int condition_test_ac_power(Condition
*c
, char **env
) {
559 assert(c
->parameter
);
560 assert(c
->type
== CONDITION_AC_POWER
);
562 r
= parse_boolean(c
->parameter
);
566 return (on_ac_power() != 0) == !!r
;
569 static int has_tpm2(void) {
572 /* Checks whether the system has at least one TPM2 resource manager device, i.e. at least one "tpmrm"
575 r
= dir_is_empty("/sys/class/tpmrm");
577 return true; /* nice! we have a device */
579 /* Hmm, so Linux doesn't know of the TPM2 device (or we couldn't check for it), most likely because
580 * the driver wasn't loaded yet. Let's see if the firmware knows about a TPM2 device, in this
581 * case. This way we can answer the TPM2 question already during early boot (where we most likely
586 /* OK, this didn't work either, in this case propagate the original errors */
590 return log_debug_errno(r
, "Failed to determine whether system has TPM2 support: %m");
595 static int condition_test_security(Condition
*c
, char **env
) {
597 assert(c
->parameter
);
598 assert(c
->type
== CONDITION_SECURITY
);
600 if (streq(c
->parameter
, "selinux"))
601 return mac_selinux_use();
602 if (streq(c
->parameter
, "smack"))
603 return mac_smack_use();
604 if (streq(c
->parameter
, "apparmor"))
605 return mac_apparmor_use();
606 if (streq(c
->parameter
, "audit"))
608 if (streq(c
->parameter
, "ima"))
610 if (streq(c
->parameter
, "tomoyo"))
611 return mac_tomoyo_use();
612 if (streq(c
->parameter
, "uefi-secureboot"))
613 return is_efi_secure_boot();
614 if (streq(c
->parameter
, "tpm2"))
620 static int condition_test_capability(Condition
*c
, char **env
) {
621 unsigned long long capabilities
= (unsigned long long) -1;
622 _cleanup_fclose_
FILE *f
= NULL
;
626 assert(c
->parameter
);
627 assert(c
->type
== CONDITION_CAPABILITY
);
629 /* If it's an invalid capability, we don't have it */
630 value
= capability_from_name(c
->parameter
);
634 /* If it's a valid capability we default to assume
637 f
= fopen("/proc/self/status", "re");
642 _cleanup_free_
char *line
= NULL
;
645 r
= read_line(f
, LONG_LINE_MAX
, &line
);
651 p
= startswith(line
, "CapBnd:");
653 if (sscanf(line
+7, "%llx", &capabilities
) != 1)
660 return !!(capabilities
& (1ULL << value
));
663 static int condition_test_needs_update(Condition
*c
, char **env
) {
664 struct stat usr
, other
;
670 assert(c
->parameter
);
671 assert(c
->type
== CONDITION_NEEDS_UPDATE
);
673 r
= proc_cmdline_get_bool("systemd.condition-needs-update", &b
);
675 log_debug_errno(r
, "Failed to parse systemd.condition-needs-update= kernel command line argument, ignoring: %m");
680 log_debug("We are in an initrd, not doing any updates.");
684 if (!path_is_absolute(c
->parameter
)) {
685 log_debug("Specified condition parameter '%s' is not absolute, assuming an update is needed.", c
->parameter
);
689 /* If the file system is read-only we shouldn't suggest an update */
690 r
= path_is_read_only_fs(c
->parameter
);
692 log_debug_errno(r
, "Failed to determine if '%s' is read-only, ignoring: %m", c
->parameter
);
696 /* Any other failure means we should allow the condition to be true, so that we rather invoke too
697 * many update tools than too few. */
699 p
= strjoina(c
->parameter
, "/.updated");
700 if (lstat(p
, &other
) < 0) {
702 log_debug_errno(errno
, "Failed to stat() '%s', assuming an update is needed: %m", p
);
706 if (lstat("/usr/", &usr
) < 0) {
707 log_debug_errno(errno
, "Failed to stat() /usr/, assuming an update is needed: %m");
712 * First, compare seconds as they are always accurate...
714 if (usr
.st_mtim
.tv_sec
!= other
.st_mtim
.tv_sec
)
715 return usr
.st_mtim
.tv_sec
> other
.st_mtim
.tv_sec
;
718 * ...then compare nanoseconds.
720 * A false positive is only possible when /usr's nanoseconds > 0
721 * (otherwise /usr cannot be strictly newer than the target file)
722 * AND the target file's nanoseconds == 0
723 * (otherwise the filesystem supports nsec timestamps, see stat(2)).
725 if (usr
.st_mtim
.tv_nsec
== 0 || other
.st_mtim
.tv_nsec
> 0)
726 return usr
.st_mtim
.tv_nsec
> other
.st_mtim
.tv_nsec
;
728 _cleanup_free_
char *timestamp_str
= NULL
;
729 r
= parse_env_file(NULL
, p
, "TIMESTAMP_NSEC", ×tamp_str
);
731 log_debug_errno(r
, "Failed to parse timestamp file '%s', using mtime: %m", p
);
734 log_debug("No data in timestamp file '%s', using mtime.", p
);
739 r
= safe_atou64(timestamp_str
, ×tamp
);
741 log_debug_errno(r
, "Failed to parse timestamp value '%s' in file '%s', using mtime: %m", timestamp_str
, p
);
745 return timespec_load_nsec(&usr
.st_mtim
) > timestamp
;
748 static int condition_test_first_boot(Condition
*c
, char **env
) {
753 assert(c
->parameter
);
754 assert(c
->type
== CONDITION_FIRST_BOOT
);
756 r
= proc_cmdline_get_bool("systemd.condition-first-boot", &b
);
758 log_debug_errno(r
, "Failed to parse systemd.condition-first-boot= kernel command line argument, ignoring: %m");
762 r
= parse_boolean(c
->parameter
);
766 q
= access("/run/systemd/first-boot", F_OK
);
767 if (q
< 0 && errno
!= ENOENT
)
768 log_debug_errno(errno
, "Failed to check if /run/systemd/first-boot exists, ignoring: %m");
770 return (q
>= 0) == !!r
;
773 static int condition_test_environment(Condition
*c
, char **env
) {
778 assert(c
->parameter
);
779 assert(c
->type
== CONDITION_ENVIRONMENT
);
781 equal
= strchr(c
->parameter
, '=');
783 STRV_FOREACH(i
, env
) {
787 found
= streq(c
->parameter
, *i
);
791 f
= startswith(*i
, c
->parameter
);
792 found
= f
&& IN_SET(*f
, 0, '=');
802 static int condition_test_path_exists(Condition
*c
, char **env
) {
804 assert(c
->parameter
);
805 assert(c
->type
== CONDITION_PATH_EXISTS
);
807 return access(c
->parameter
, F_OK
) >= 0;
810 static int condition_test_path_exists_glob(Condition
*c
, char **env
) {
812 assert(c
->parameter
);
813 assert(c
->type
== CONDITION_PATH_EXISTS_GLOB
);
815 return glob_exists(c
->parameter
) > 0;
818 static int condition_test_path_is_directory(Condition
*c
, char **env
) {
820 assert(c
->parameter
);
821 assert(c
->type
== CONDITION_PATH_IS_DIRECTORY
);
823 return is_dir(c
->parameter
, true) > 0;
826 static int condition_test_path_is_symbolic_link(Condition
*c
, char **env
) {
828 assert(c
->parameter
);
829 assert(c
->type
== CONDITION_PATH_IS_SYMBOLIC_LINK
);
831 return is_symlink(c
->parameter
) > 0;
834 static int condition_test_path_is_mount_point(Condition
*c
, char **env
) {
836 assert(c
->parameter
);
837 assert(c
->type
== CONDITION_PATH_IS_MOUNT_POINT
);
839 return path_is_mount_point(c
->parameter
, NULL
, AT_SYMLINK_FOLLOW
) > 0;
842 static int condition_test_path_is_read_write(Condition
*c
, char **env
) {
844 assert(c
->parameter
);
845 assert(c
->type
== CONDITION_PATH_IS_READ_WRITE
);
847 return path_is_read_only_fs(c
->parameter
) <= 0;
850 static int condition_test_cpufeature(Condition
*c
, char **env
) {
852 assert(c
->parameter
);
853 assert(c
->type
== CONDITION_CPU_FEATURE
);
855 return has_cpu_with_flag(ascii_strlower(c
->parameter
));
858 static int condition_test_path_is_encrypted(Condition
*c
, char **env
) {
862 assert(c
->parameter
);
863 assert(c
->type
== CONDITION_PATH_IS_ENCRYPTED
);
865 r
= path_is_encrypted(c
->parameter
);
866 if (r
< 0 && r
!= -ENOENT
)
867 log_debug_errno(r
, "Failed to determine if '%s' is encrypted: %m", c
->parameter
);
872 static int condition_test_directory_not_empty(Condition
*c
, char **env
) {
876 assert(c
->parameter
);
877 assert(c
->type
== CONDITION_DIRECTORY_NOT_EMPTY
);
879 r
= dir_is_empty(c
->parameter
);
880 return r
<= 0 && r
!= -ENOENT
;
883 static int condition_test_file_not_empty(Condition
*c
, char **env
) {
887 assert(c
->parameter
);
888 assert(c
->type
== CONDITION_FILE_NOT_EMPTY
);
890 return (stat(c
->parameter
, &st
) >= 0 &&
891 S_ISREG(st
.st_mode
) &&
895 static int condition_test_file_is_executable(Condition
*c
, char **env
) {
899 assert(c
->parameter
);
900 assert(c
->type
== CONDITION_FILE_IS_EXECUTABLE
);
902 return (stat(c
->parameter
, &st
) >= 0 &&
903 S_ISREG(st
.st_mode
) &&
904 (st
.st_mode
& 0111));
907 int condition_test(Condition
*c
, char **env
) {
909 static int (*const condition_tests
[_CONDITION_TYPE_MAX
])(Condition
*c
, char **env
) = {
910 [CONDITION_PATH_EXISTS
] = condition_test_path_exists
,
911 [CONDITION_PATH_EXISTS_GLOB
] = condition_test_path_exists_glob
,
912 [CONDITION_PATH_IS_DIRECTORY
] = condition_test_path_is_directory
,
913 [CONDITION_PATH_IS_SYMBOLIC_LINK
] = condition_test_path_is_symbolic_link
,
914 [CONDITION_PATH_IS_MOUNT_POINT
] = condition_test_path_is_mount_point
,
915 [CONDITION_PATH_IS_READ_WRITE
] = condition_test_path_is_read_write
,
916 [CONDITION_PATH_IS_ENCRYPTED
] = condition_test_path_is_encrypted
,
917 [CONDITION_DIRECTORY_NOT_EMPTY
] = condition_test_directory_not_empty
,
918 [CONDITION_FILE_NOT_EMPTY
] = condition_test_file_not_empty
,
919 [CONDITION_FILE_IS_EXECUTABLE
] = condition_test_file_is_executable
,
920 [CONDITION_KERNEL_COMMAND_LINE
] = condition_test_kernel_command_line
,
921 [CONDITION_KERNEL_VERSION
] = condition_test_kernel_version
,
922 [CONDITION_VIRTUALIZATION
] = condition_test_virtualization
,
923 [CONDITION_SECURITY
] = condition_test_security
,
924 [CONDITION_CAPABILITY
] = condition_test_capability
,
925 [CONDITION_HOST
] = condition_test_host
,
926 [CONDITION_AC_POWER
] = condition_test_ac_power
,
927 [CONDITION_ARCHITECTURE
] = condition_test_architecture
,
928 [CONDITION_FIRMWARE
] = condition_test_firmware
,
929 [CONDITION_NEEDS_UPDATE
] = condition_test_needs_update
,
930 [CONDITION_FIRST_BOOT
] = condition_test_first_boot
,
931 [CONDITION_USER
] = condition_test_user
,
932 [CONDITION_GROUP
] = condition_test_group
,
933 [CONDITION_CONTROL_GROUP_CONTROLLER
] = condition_test_control_group_controller
,
934 [CONDITION_CPUS
] = condition_test_cpus
,
935 [CONDITION_MEMORY
] = condition_test_memory
,
936 [CONDITION_ENVIRONMENT
] = condition_test_environment
,
937 [CONDITION_CPU_FEATURE
] = condition_test_cpufeature
,
943 assert(c
->type
>= 0);
944 assert(c
->type
< _CONDITION_TYPE_MAX
);
946 r
= condition_tests
[c
->type
](c
, env
);
948 c
->result
= CONDITION_ERROR
;
952 b
= (r
> 0) == !c
->negate
;
953 c
->result
= b
? CONDITION_SUCCEEDED
: CONDITION_FAILED
;
957 bool condition_test_list(
960 condition_to_string_t to_string
,
961 condition_test_logger_t logger
,
967 assert(!!logger
== !!to_string
);
969 /* If the condition list is empty, then it is true */
973 /* Otherwise, if all of the non-trigger conditions apply and
974 * if any of the trigger conditions apply (unless there are
975 * none) we return true */
976 LIST_FOREACH(conditions
, c
, first
) {
979 r
= condition_test(c
, env
);
983 logger(userdata
, LOG_WARNING
, r
, PROJECT_FILE
, __LINE__
, __func__
,
984 "Couldn't determine result for %s=%s%s%s, assuming failed: %m",
986 c
->trigger
? "|" : "",
987 c
->negate
? "!" : "",
990 logger(userdata
, LOG_DEBUG
, 0, PROJECT_FILE
, __LINE__
, __func__
,
993 c
->trigger
? "|" : "",
994 c
->negate
? "!" : "",
996 condition_result_to_string(c
->result
));
999 if (!c
->trigger
&& r
<= 0)
1002 if (c
->trigger
&& triggered
<= 0)
1006 return triggered
!= 0;
1009 void condition_dump(Condition
*c
, FILE *f
, const char *prefix
, condition_to_string_t to_string
) {
1014 prefix
= strempty(prefix
);
1017 "%s\t%s: %s%s%s %s\n",
1020 c
->trigger
? "|" : "",
1021 c
->negate
? "!" : "",
1023 condition_result_to_string(c
->result
));
1026 void condition_dump_list(Condition
*first
, FILE *f
, const char *prefix
, condition_to_string_t to_string
) {
1029 LIST_FOREACH(conditions
, c
, first
)
1030 condition_dump(c
, f
, prefix
, to_string
);
1033 static const char* const condition_type_table
[_CONDITION_TYPE_MAX
] = {
1034 [CONDITION_ARCHITECTURE
] = "ConditionArchitecture",
1035 [CONDITION_FIRMWARE
] = "ConditionFirmware",
1036 [CONDITION_VIRTUALIZATION
] = "ConditionVirtualization",
1037 [CONDITION_HOST
] = "ConditionHost",
1038 [CONDITION_KERNEL_COMMAND_LINE
] = "ConditionKernelCommandLine",
1039 [CONDITION_KERNEL_VERSION
] = "ConditionKernelVersion",
1040 [CONDITION_SECURITY
] = "ConditionSecurity",
1041 [CONDITION_CAPABILITY
] = "ConditionCapability",
1042 [CONDITION_AC_POWER
] = "ConditionACPower",
1043 [CONDITION_NEEDS_UPDATE
] = "ConditionNeedsUpdate",
1044 [CONDITION_FIRST_BOOT
] = "ConditionFirstBoot",
1045 [CONDITION_PATH_EXISTS
] = "ConditionPathExists",
1046 [CONDITION_PATH_EXISTS_GLOB
] = "ConditionPathExistsGlob",
1047 [CONDITION_PATH_IS_DIRECTORY
] = "ConditionPathIsDirectory",
1048 [CONDITION_PATH_IS_SYMBOLIC_LINK
] = "ConditionPathIsSymbolicLink",
1049 [CONDITION_PATH_IS_MOUNT_POINT
] = "ConditionPathIsMountPoint",
1050 [CONDITION_PATH_IS_READ_WRITE
] = "ConditionPathIsReadWrite",
1051 [CONDITION_PATH_IS_ENCRYPTED
] = "ConditionPathIsEncrypted",
1052 [CONDITION_DIRECTORY_NOT_EMPTY
] = "ConditionDirectoryNotEmpty",
1053 [CONDITION_FILE_NOT_EMPTY
] = "ConditionFileNotEmpty",
1054 [CONDITION_FILE_IS_EXECUTABLE
] = "ConditionFileIsExecutable",
1055 [CONDITION_USER
] = "ConditionUser",
1056 [CONDITION_GROUP
] = "ConditionGroup",
1057 [CONDITION_CONTROL_GROUP_CONTROLLER
] = "ConditionControlGroupController",
1058 [CONDITION_CPUS
] = "ConditionCPUs",
1059 [CONDITION_MEMORY
] = "ConditionMemory",
1060 [CONDITION_ENVIRONMENT
] = "ConditionEnvironment",
1061 [CONDITION_CPU_FEATURE
] = "ConditionCPUFeature",
1064 DEFINE_STRING_TABLE_LOOKUP(condition_type
, ConditionType
);
1066 static const char* const assert_type_table
[_CONDITION_TYPE_MAX
] = {
1067 [CONDITION_ARCHITECTURE
] = "AssertArchitecture",
1068 [CONDITION_FIRMWARE
] = "AssertFirmware",
1069 [CONDITION_VIRTUALIZATION
] = "AssertVirtualization",
1070 [CONDITION_HOST
] = "AssertHost",
1071 [CONDITION_KERNEL_COMMAND_LINE
] = "AssertKernelCommandLine",
1072 [CONDITION_KERNEL_VERSION
] = "AssertKernelVersion",
1073 [CONDITION_SECURITY
] = "AssertSecurity",
1074 [CONDITION_CAPABILITY
] = "AssertCapability",
1075 [CONDITION_AC_POWER
] = "AssertACPower",
1076 [CONDITION_NEEDS_UPDATE
] = "AssertNeedsUpdate",
1077 [CONDITION_FIRST_BOOT
] = "AssertFirstBoot",
1078 [CONDITION_PATH_EXISTS
] = "AssertPathExists",
1079 [CONDITION_PATH_EXISTS_GLOB
] = "AssertPathExistsGlob",
1080 [CONDITION_PATH_IS_DIRECTORY
] = "AssertPathIsDirectory",
1081 [CONDITION_PATH_IS_SYMBOLIC_LINK
] = "AssertPathIsSymbolicLink",
1082 [CONDITION_PATH_IS_MOUNT_POINT
] = "AssertPathIsMountPoint",
1083 [CONDITION_PATH_IS_READ_WRITE
] = "AssertPathIsReadWrite",
1084 [CONDITION_PATH_IS_ENCRYPTED
] = "AssertPathIsEncrypted",
1085 [CONDITION_DIRECTORY_NOT_EMPTY
] = "AssertDirectoryNotEmpty",
1086 [CONDITION_FILE_NOT_EMPTY
] = "AssertFileNotEmpty",
1087 [CONDITION_FILE_IS_EXECUTABLE
] = "AssertFileIsExecutable",
1088 [CONDITION_USER
] = "AssertUser",
1089 [CONDITION_GROUP
] = "AssertGroup",
1090 [CONDITION_CONTROL_GROUP_CONTROLLER
] = "AssertControlGroupController",
1091 [CONDITION_CPUS
] = "AssertCPUs",
1092 [CONDITION_MEMORY
] = "AssertMemory",
1093 [CONDITION_ENVIRONMENT
] = "AssertEnvironment",
1094 [CONDITION_CPU_FEATURE
] = "AssertCPUFeature",
1097 DEFINE_STRING_TABLE_LOOKUP(assert_type
, ConditionType
);
1099 static const char* const condition_result_table
[_CONDITION_RESULT_MAX
] = {
1100 [CONDITION_UNTESTED
] = "untested",
1101 [CONDITION_SUCCEEDED
] = "succeeded",
1102 [CONDITION_FAILED
] = "failed",
1103 [CONDITION_ERROR
] = "error",
1106 DEFINE_STRING_TABLE_LOOKUP(condition_result
, ConditionResult
);