]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/condition.c
d1ac9de7565804368a37458da149b5924cb2783d
[thirdparty/systemd.git] / src / shared / condition.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include <errno.h>
4 #include <fcntl.h>
5 #include <fnmatch.h>
6 #include <limits.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <sys/stat.h>
10 #include <sys/types.h>
11 #include <sys/utsname.h>
12 #include <time.h>
13 #include <unistd.h>
14
15 #include "sd-id128.h"
16
17 #include "alloc-util.h"
18 #include "apparmor-util.h"
19 #include "architecture.h"
20 #include "audit-util.h"
21 #include "cap-list.h"
22 #include "cgroup-util.h"
23 #include "condition.h"
24 #include "efivars.h"
25 #include "env-file.h"
26 #include "extract-word.h"
27 #include "fd-util.h"
28 #include "fileio.h"
29 #include "glob-util.h"
30 #include "hostname-util.h"
31 #include "ima-util.h"
32 #include "limits-util.h"
33 #include "list.h"
34 #include "macro.h"
35 #include "mountpoint-util.h"
36 #include "parse-util.h"
37 #include "path-util.h"
38 #include "proc-cmdline.h"
39 #include "process-util.h"
40 #include "selinux-util.h"
41 #include "smack-util.h"
42 #include "stat-util.h"
43 #include "string-table.h"
44 #include "string-util.h"
45 #include "tomoyo-util.h"
46 #include "user-util.h"
47 #include "util.h"
48 #include "virt.h"
49
50 Condition* condition_new(ConditionType type, const char *parameter, bool trigger, bool negate) {
51 Condition *c;
52
53 assert(type >= 0);
54 assert(type < _CONDITION_TYPE_MAX);
55 assert((!parameter) == (type == CONDITION_NULL));
56
57 c = new(Condition, 1);
58 if (!c)
59 return NULL;
60
61 *c = (Condition) {
62 .type = type,
63 .trigger = trigger,
64 .negate = negate,
65 };
66
67 if (parameter) {
68 c->parameter = strdup(parameter);
69 if (!c->parameter)
70 return mfree(c);
71 }
72
73 return c;
74 }
75
76 void condition_free(Condition *c) {
77 assert(c);
78
79 free(c->parameter);
80 free(c);
81 }
82
83 Condition* condition_free_list_type(Condition *head, ConditionType type) {
84 Condition *c, *n;
85
86 LIST_FOREACH_SAFE(conditions, c, n, head)
87 if (type < 0 || c->type == type) {
88 LIST_REMOVE(conditions, head, c);
89 condition_free(c);
90 }
91
92 assert(type >= 0 || !head);
93 return head;
94 }
95
96 static int condition_test_kernel_command_line(Condition *c) {
97 _cleanup_free_ char *line = NULL;
98 const char *p;
99 bool equal;
100 int r;
101
102 assert(c);
103 assert(c->parameter);
104 assert(c->type == CONDITION_KERNEL_COMMAND_LINE);
105
106 r = proc_cmdline(&line);
107 if (r < 0)
108 return r;
109
110 equal = strchr(c->parameter, '=');
111
112 for (p = line;;) {
113 _cleanup_free_ char *word = NULL;
114 bool found;
115
116 r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES|EXTRACT_RELAX);
117 if (r < 0)
118 return r;
119 if (r == 0)
120 break;
121
122 if (equal)
123 found = streq(word, c->parameter);
124 else {
125 const char *f;
126
127 f = startswith(word, c->parameter);
128 found = f && IN_SET(*f, 0, '=');
129 }
130
131 if (found)
132 return true;
133 }
134
135 return false;
136 }
137
138 typedef enum {
139 /* Listed in order of checking. Note that some comparators are prefixes of others, hence the longest
140 * should be listed first. */
141 ORDER_LOWER_OR_EQUAL,
142 ORDER_GREATER_OR_EQUAL,
143 ORDER_LOWER,
144 ORDER_GREATER,
145 ORDER_EQUAL,
146 ORDER_UNEQUAL,
147 _ORDER_MAX,
148 _ORDER_INVALID = -1
149 } OrderOperator;
150
151 static OrderOperator parse_order(const char **s) {
152
153 static const char *const prefix[_ORDER_MAX] = {
154 [ORDER_LOWER_OR_EQUAL] = "<=",
155 [ORDER_GREATER_OR_EQUAL] = ">=",
156 [ORDER_LOWER] = "<",
157 [ORDER_GREATER] = ">",
158 [ORDER_EQUAL] = "=",
159 [ORDER_UNEQUAL] = "!=",
160 };
161
162 OrderOperator i;
163
164 for (i = 0; i < _ORDER_MAX; i++) {
165 const char *e;
166
167 e = startswith(*s, prefix[i]);
168 if (e) {
169 *s = e;
170 return i;
171 }
172 }
173
174 return _ORDER_INVALID;
175 }
176
177 static bool test_order(int k, OrderOperator p) {
178
179 switch (p) {
180
181 case ORDER_LOWER:
182 return k < 0;
183
184 case ORDER_LOWER_OR_EQUAL:
185 return k <= 0;
186
187 case ORDER_EQUAL:
188 return k == 0;
189
190 case ORDER_UNEQUAL:
191 return k != 0;
192
193 case ORDER_GREATER_OR_EQUAL:
194 return k >= 0;
195
196 case ORDER_GREATER:
197 return k > 0;
198
199 default:
200 assert_not_reached("unknown order");
201
202 }
203 }
204
205 static int condition_test_kernel_version(Condition *c) {
206 OrderOperator order;
207 struct utsname u;
208 const char *p;
209
210 assert(c);
211 assert(c->parameter);
212 assert(c->type == CONDITION_KERNEL_VERSION);
213
214 assert_se(uname(&u) >= 0);
215
216 p = c->parameter;
217 order = parse_order(&p);
218
219 /* No prefix? Then treat as glob string */
220 if (order < 0)
221 return fnmatch(skip_leading_chars(c->parameter, NULL), u.release, 0) == 0;
222
223 return test_order(str_verscmp(u.release, skip_leading_chars(p, NULL)), order);
224 }
225
226 static int condition_test_memory(Condition *c) {
227 OrderOperator order;
228 uint64_t m, k;
229 const char *p;
230 int r;
231
232 assert(c);
233 assert(c->parameter);
234 assert(c->type == CONDITION_MEMORY);
235
236 m = physical_memory();
237
238 p = c->parameter;
239 order = parse_order(&p);
240 if (order < 0)
241 order = ORDER_GREATER_OR_EQUAL; /* default to >= check, if nothing is specified. */
242
243 r = safe_atou64(p, &k);
244 if (r < 0)
245 return log_debug_errno(r, "Failed to parse size: %m");
246
247 return test_order(CMP(m, k), order);
248 }
249
250 static int condition_test_cpus(Condition *c) {
251 OrderOperator order;
252 const char *p;
253 unsigned k;
254 int r, n;
255
256 assert(c);
257 assert(c->parameter);
258 assert(c->type == CONDITION_CPUS);
259
260 n = cpus_in_affinity_mask();
261 if (n < 0)
262 return log_debug_errno(n, "Failed to determine CPUs in affinity mask: %m");
263
264 p = c->parameter;
265 order = parse_order(&p);
266 if (order < 0)
267 order = ORDER_GREATER_OR_EQUAL; /* default to >= check, if nothing is specified. */
268
269 r = safe_atou(p, &k);
270 if (r < 0)
271 return log_debug_errno(r, "Failed to parse number of CPUs: %m");
272
273 return test_order(CMP((unsigned) n, k), order);
274 }
275
276 static int condition_test_user(Condition *c) {
277 uid_t id;
278 int r;
279 _cleanup_free_ char *username = NULL;
280 const char *u;
281
282 assert(c);
283 assert(c->parameter);
284 assert(c->type == CONDITION_USER);
285
286 r = parse_uid(c->parameter, &id);
287 if (r >= 0)
288 return id == getuid() || id == geteuid();
289
290 if (streq("@system", c->parameter))
291 return uid_is_system(getuid()) || uid_is_system(geteuid());
292
293 username = getusername_malloc();
294 if (!username)
295 return -ENOMEM;
296
297 if (streq(username, c->parameter))
298 return 1;
299
300 if (getpid_cached() == 1)
301 return streq(c->parameter, "root");
302
303 u = c->parameter;
304 r = get_user_creds(&u, &id, NULL, NULL, NULL, USER_CREDS_ALLOW_MISSING);
305 if (r < 0)
306 return 0;
307
308 return id == getuid() || id == geteuid();
309 }
310
311 static int condition_test_control_group_controller(Condition *c) {
312 int r;
313 CGroupMask system_mask, wanted_mask = 0;
314
315 assert(c);
316 assert(c->parameter);
317 assert(c->type == CONDITION_CONTROL_GROUP_CONTROLLER);
318
319 r = cg_mask_supported(&system_mask);
320 if (r < 0)
321 return log_debug_errno(r, "Failed to determine supported controllers: %m");
322
323 r = cg_mask_from_string(c->parameter, &wanted_mask);
324 if (r < 0 || wanted_mask <= 0) {
325 /* This won't catch the case that we have an unknown controller
326 * mixed in with valid ones -- these are only assessed on the
327 * validity of the valid controllers found. */
328 log_debug("Failed to parse cgroup string: %s", c->parameter);
329 return 1;
330 }
331
332 return FLAGS_SET(system_mask, wanted_mask);
333 }
334
335 static int condition_test_group(Condition *c) {
336 gid_t id;
337 int r;
338
339 assert(c);
340 assert(c->parameter);
341 assert(c->type == CONDITION_GROUP);
342
343 r = parse_gid(c->parameter, &id);
344 if (r >= 0)
345 return in_gid(id);
346
347 /* Avoid any NSS lookups if we are PID1 */
348 if (getpid_cached() == 1)
349 return streq(c->parameter, "root");
350
351 return in_group(c->parameter) > 0;
352 }
353
354 static int condition_test_virtualization(Condition *c) {
355 int b, v;
356
357 assert(c);
358 assert(c->parameter);
359 assert(c->type == CONDITION_VIRTUALIZATION);
360
361 if (streq(c->parameter, "private-users"))
362 return running_in_userns();
363
364 v = detect_virtualization();
365 if (v < 0)
366 return v;
367
368 /* First, compare with yes/no */
369 b = parse_boolean(c->parameter);
370 if (b >= 0)
371 return b == !!v;
372
373 /* Then, compare categorization */
374 if (streq(c->parameter, "vm"))
375 return VIRTUALIZATION_IS_VM(v);
376
377 if (streq(c->parameter, "container"))
378 return VIRTUALIZATION_IS_CONTAINER(v);
379
380 /* Finally compare id */
381 return v != VIRTUALIZATION_NONE && streq(c->parameter, virtualization_to_string(v));
382 }
383
384 static int condition_test_architecture(Condition *c) {
385 int a, b;
386
387 assert(c);
388 assert(c->parameter);
389 assert(c->type == CONDITION_ARCHITECTURE);
390
391 a = uname_architecture();
392 if (a < 0)
393 return a;
394
395 if (streq(c->parameter, "native"))
396 b = native_architecture();
397 else {
398 b = architecture_from_string(c->parameter);
399 if (b < 0) /* unknown architecture? Then it's definitely not ours */
400 return false;
401 }
402
403 return a == b;
404 }
405
406 static int condition_test_host(Condition *c) {
407 _cleanup_free_ char *h = NULL;
408 sd_id128_t x, y;
409 int r;
410
411 assert(c);
412 assert(c->parameter);
413 assert(c->type == CONDITION_HOST);
414
415 if (sd_id128_from_string(c->parameter, &x) >= 0) {
416
417 r = sd_id128_get_machine(&y);
418 if (r < 0)
419 return r;
420
421 return sd_id128_equal(x, y);
422 }
423
424 h = gethostname_malloc();
425 if (!h)
426 return -ENOMEM;
427
428 return fnmatch(c->parameter, h, FNM_CASEFOLD) == 0;
429 }
430
431 static int condition_test_ac_power(Condition *c) {
432 int r;
433
434 assert(c);
435 assert(c->parameter);
436 assert(c->type == CONDITION_AC_POWER);
437
438 r = parse_boolean(c->parameter);
439 if (r < 0)
440 return r;
441
442 return (on_ac_power() != 0) == !!r;
443 }
444
445 static int condition_test_security(Condition *c) {
446 assert(c);
447 assert(c->parameter);
448 assert(c->type == CONDITION_SECURITY);
449
450 if (streq(c->parameter, "selinux"))
451 return mac_selinux_use();
452 if (streq(c->parameter, "smack"))
453 return mac_smack_use();
454 if (streq(c->parameter, "apparmor"))
455 return mac_apparmor_use();
456 if (streq(c->parameter, "audit"))
457 return use_audit();
458 if (streq(c->parameter, "ima"))
459 return use_ima();
460 if (streq(c->parameter, "tomoyo"))
461 return mac_tomoyo_use();
462 if (streq(c->parameter, "uefi-secureboot"))
463 return is_efi_secure_boot();
464
465 return false;
466 }
467
468 static int condition_test_capability(Condition *c) {
469 unsigned long long capabilities = (unsigned long long) -1;
470 _cleanup_fclose_ FILE *f = NULL;
471 int value, r;
472
473 assert(c);
474 assert(c->parameter);
475 assert(c->type == CONDITION_CAPABILITY);
476
477 /* If it's an invalid capability, we don't have it */
478 value = capability_from_name(c->parameter);
479 if (value < 0)
480 return -EINVAL;
481
482 /* If it's a valid capability we default to assume
483 * that we have it */
484
485 f = fopen("/proc/self/status", "re");
486 if (!f)
487 return -errno;
488
489 for (;;) {
490 _cleanup_free_ char *line = NULL;
491 const char *p;
492
493 r = read_line(f, LONG_LINE_MAX, &line);
494 if (r < 0)
495 return r;
496 if (r == 0)
497 break;
498
499 p = startswith(line, "CapBnd:");
500 if (p) {
501 if (sscanf(line+7, "%llx", &capabilities) != 1)
502 return -EIO;
503
504 break;
505 }
506 }
507
508 return !!(capabilities & (1ULL << value));
509 }
510
511 static int condition_test_needs_update(Condition *c) {
512 const char *p;
513 struct stat usr, other;
514
515 assert(c);
516 assert(c->parameter);
517 assert(c->type == CONDITION_NEEDS_UPDATE);
518
519 /* If the file system is read-only we shouldn't suggest an update */
520 if (path_is_read_only_fs(c->parameter) > 0)
521 return false;
522
523 /* Any other failure means we should allow the condition to be true,
524 * so that we rather invoke too many update tools than too
525 * few. */
526
527 if (!path_is_absolute(c->parameter))
528 return true;
529
530 p = strjoina(c->parameter, "/.updated");
531 if (lstat(p, &other) < 0)
532 return true;
533
534 if (lstat("/usr/", &usr) < 0)
535 return true;
536
537 /*
538 * First, compare seconds as they are always accurate...
539 */
540 if (usr.st_mtim.tv_sec != other.st_mtim.tv_sec)
541 return usr.st_mtim.tv_sec > other.st_mtim.tv_sec;
542
543 /*
544 * ...then compare nanoseconds.
545 *
546 * A false positive is only possible when /usr's nanoseconds > 0
547 * (otherwise /usr cannot be strictly newer than the target file)
548 * AND the target file's nanoseconds == 0
549 * (otherwise the filesystem supports nsec timestamps, see stat(2)).
550 */
551 if (usr.st_mtim.tv_nsec > 0 && other.st_mtim.tv_nsec == 0) {
552 _cleanup_free_ char *timestamp_str = NULL;
553 uint64_t timestamp;
554 int r;
555
556 r = parse_env_file(NULL, p, "TIMESTAMP_NSEC", &timestamp_str);
557 if (r < 0) {
558 log_error_errno(r, "Failed to parse timestamp file '%s', using mtime: %m", p);
559 return true;
560 } else if (r == 0) {
561 log_debug("No data in timestamp file '%s', using mtime", p);
562 return true;
563 }
564
565 r = safe_atou64(timestamp_str, &timestamp);
566 if (r < 0) {
567 log_error_errno(r, "Failed to parse timestamp value '%s' in file '%s', using mtime: %m", timestamp_str, p);
568 return true;
569 }
570
571 timespec_store(&other.st_mtim, timestamp);
572 }
573
574 return usr.st_mtim.tv_nsec > other.st_mtim.tv_nsec;
575 }
576
577 static int condition_test_first_boot(Condition *c) {
578 int r;
579
580 assert(c);
581 assert(c->parameter);
582 assert(c->type == CONDITION_FIRST_BOOT);
583
584 r = parse_boolean(c->parameter);
585 if (r < 0)
586 return r;
587
588 return (access("/run/systemd/first-boot", F_OK) >= 0) == !!r;
589 }
590
591 static int condition_test_path_exists(Condition *c) {
592 assert(c);
593 assert(c->parameter);
594 assert(c->type == CONDITION_PATH_EXISTS);
595
596 return access(c->parameter, F_OK) >= 0;
597 }
598
599 static int condition_test_path_exists_glob(Condition *c) {
600 assert(c);
601 assert(c->parameter);
602 assert(c->type == CONDITION_PATH_EXISTS_GLOB);
603
604 return glob_exists(c->parameter) > 0;
605 }
606
607 static int condition_test_path_is_directory(Condition *c) {
608 assert(c);
609 assert(c->parameter);
610 assert(c->type == CONDITION_PATH_IS_DIRECTORY);
611
612 return is_dir(c->parameter, true) > 0;
613 }
614
615 static int condition_test_path_is_symbolic_link(Condition *c) {
616 assert(c);
617 assert(c->parameter);
618 assert(c->type == CONDITION_PATH_IS_SYMBOLIC_LINK);
619
620 return is_symlink(c->parameter) > 0;
621 }
622
623 static int condition_test_path_is_mount_point(Condition *c) {
624 assert(c);
625 assert(c->parameter);
626 assert(c->type == CONDITION_PATH_IS_MOUNT_POINT);
627
628 return path_is_mount_point(c->parameter, NULL, AT_SYMLINK_FOLLOW) > 0;
629 }
630
631 static int condition_test_path_is_read_write(Condition *c) {
632 assert(c);
633 assert(c->parameter);
634 assert(c->type == CONDITION_PATH_IS_READ_WRITE);
635
636 return path_is_read_only_fs(c->parameter) <= 0;
637 }
638
639 static int condition_test_directory_not_empty(Condition *c) {
640 int r;
641
642 assert(c);
643 assert(c->parameter);
644 assert(c->type == CONDITION_DIRECTORY_NOT_EMPTY);
645
646 r = dir_is_empty(c->parameter);
647 return r <= 0 && r != -ENOENT;
648 }
649
650 static int condition_test_file_not_empty(Condition *c) {
651 struct stat st;
652
653 assert(c);
654 assert(c->parameter);
655 assert(c->type == CONDITION_FILE_NOT_EMPTY);
656
657 return (stat(c->parameter, &st) >= 0 &&
658 S_ISREG(st.st_mode) &&
659 st.st_size > 0);
660 }
661
662 static int condition_test_file_is_executable(Condition *c) {
663 struct stat st;
664
665 assert(c);
666 assert(c->parameter);
667 assert(c->type == CONDITION_FILE_IS_EXECUTABLE);
668
669 return (stat(c->parameter, &st) >= 0 &&
670 S_ISREG(st.st_mode) &&
671 (st.st_mode & 0111));
672 }
673
674 static int condition_test_null(Condition *c) {
675 assert(c);
676 assert(c->type == CONDITION_NULL);
677
678 /* Note that during parsing we already evaluate the string and
679 * store it in c->negate */
680 return true;
681 }
682
683 int condition_test(Condition *c) {
684
685 static int (*const condition_tests[_CONDITION_TYPE_MAX])(Condition *c) = {
686 [CONDITION_PATH_EXISTS] = condition_test_path_exists,
687 [CONDITION_PATH_EXISTS_GLOB] = condition_test_path_exists_glob,
688 [CONDITION_PATH_IS_DIRECTORY] = condition_test_path_is_directory,
689 [CONDITION_PATH_IS_SYMBOLIC_LINK] = condition_test_path_is_symbolic_link,
690 [CONDITION_PATH_IS_MOUNT_POINT] = condition_test_path_is_mount_point,
691 [CONDITION_PATH_IS_READ_WRITE] = condition_test_path_is_read_write,
692 [CONDITION_DIRECTORY_NOT_EMPTY] = condition_test_directory_not_empty,
693 [CONDITION_FILE_NOT_EMPTY] = condition_test_file_not_empty,
694 [CONDITION_FILE_IS_EXECUTABLE] = condition_test_file_is_executable,
695 [CONDITION_KERNEL_COMMAND_LINE] = condition_test_kernel_command_line,
696 [CONDITION_KERNEL_VERSION] = condition_test_kernel_version,
697 [CONDITION_VIRTUALIZATION] = condition_test_virtualization,
698 [CONDITION_SECURITY] = condition_test_security,
699 [CONDITION_CAPABILITY] = condition_test_capability,
700 [CONDITION_HOST] = condition_test_host,
701 [CONDITION_AC_POWER] = condition_test_ac_power,
702 [CONDITION_ARCHITECTURE] = condition_test_architecture,
703 [CONDITION_NEEDS_UPDATE] = condition_test_needs_update,
704 [CONDITION_FIRST_BOOT] = condition_test_first_boot,
705 [CONDITION_USER] = condition_test_user,
706 [CONDITION_GROUP] = condition_test_group,
707 [CONDITION_CONTROL_GROUP_CONTROLLER] = condition_test_control_group_controller,
708 [CONDITION_NULL] = condition_test_null,
709 [CONDITION_CPUS] = condition_test_cpus,
710 [CONDITION_MEMORY] = condition_test_memory,
711 };
712
713 int r, b;
714
715 assert(c);
716 assert(c->type >= 0);
717 assert(c->type < _CONDITION_TYPE_MAX);
718
719 r = condition_tests[c->type](c);
720 if (r < 0) {
721 c->result = CONDITION_ERROR;
722 return r;
723 }
724
725 b = (r > 0) == !c->negate;
726 c->result = b ? CONDITION_SUCCEEDED : CONDITION_FAILED;
727 return b;
728 }
729
730 bool condition_test_list(Condition *first, const char *(*to_string)(ConditionType t), condition_test_logger_t logger, void *userdata) {
731 Condition *c;
732 int triggered = -1;
733
734 assert(!!logger == !!to_string);
735
736 /* If the condition list is empty, then it is true */
737 if (!first)
738 return true;
739
740 /* Otherwise, if all of the non-trigger conditions apply and
741 * if any of the trigger conditions apply (unless there are
742 * none) we return true */
743 LIST_FOREACH(conditions, c, first) {
744 int r;
745
746 r = condition_test(c);
747
748 if (logger) {
749 if (r < 0)
750 logger(userdata, LOG_WARNING, r, __FILE__, __LINE__, __func__,
751 "Couldn't determine result for %s=%s%s%s, assuming failed: %m",
752 to_string(c->type),
753 c->trigger ? "|" : "",
754 c->negate ? "!" : "",
755 c->parameter);
756 else
757 logger(userdata, LOG_DEBUG, 0, __FILE__, __LINE__, __func__,
758 "%s=%s%s%s %s.",
759 to_string(c->type),
760 c->trigger ? "|" : "",
761 c->negate ? "!" : "",
762 c->parameter,
763 condition_result_to_string(c->result));
764 }
765
766 if (!c->trigger && r <= 0)
767 return false;
768
769 if (c->trigger && triggered <= 0)
770 triggered = r > 0;
771 }
772
773 return triggered != 0;
774 }
775
776 void condition_dump(Condition *c, FILE *f, const char *prefix, const char *(*to_string)(ConditionType t)) {
777 assert(c);
778 assert(f);
779
780 prefix = strempty(prefix);
781
782 fprintf(f,
783 "%s\t%s: %s%s%s %s\n",
784 prefix,
785 to_string(c->type),
786 c->trigger ? "|" : "",
787 c->negate ? "!" : "",
788 c->parameter,
789 condition_result_to_string(c->result));
790 }
791
792 void condition_dump_list(Condition *first, FILE *f, const char *prefix, const char *(*to_string)(ConditionType t)) {
793 Condition *c;
794
795 LIST_FOREACH(conditions, c, first)
796 condition_dump(c, f, prefix, to_string);
797 }
798
799 static const char* const condition_type_table[_CONDITION_TYPE_MAX] = {
800 [CONDITION_ARCHITECTURE] = "ConditionArchitecture",
801 [CONDITION_VIRTUALIZATION] = "ConditionVirtualization",
802 [CONDITION_HOST] = "ConditionHost",
803 [CONDITION_KERNEL_COMMAND_LINE] = "ConditionKernelCommandLine",
804 [CONDITION_KERNEL_VERSION] = "ConditionKernelVersion",
805 [CONDITION_SECURITY] = "ConditionSecurity",
806 [CONDITION_CAPABILITY] = "ConditionCapability",
807 [CONDITION_AC_POWER] = "ConditionACPower",
808 [CONDITION_NEEDS_UPDATE] = "ConditionNeedsUpdate",
809 [CONDITION_FIRST_BOOT] = "ConditionFirstBoot",
810 [CONDITION_PATH_EXISTS] = "ConditionPathExists",
811 [CONDITION_PATH_EXISTS_GLOB] = "ConditionPathExistsGlob",
812 [CONDITION_PATH_IS_DIRECTORY] = "ConditionPathIsDirectory",
813 [CONDITION_PATH_IS_SYMBOLIC_LINK] = "ConditionPathIsSymbolicLink",
814 [CONDITION_PATH_IS_MOUNT_POINT] = "ConditionPathIsMountPoint",
815 [CONDITION_PATH_IS_READ_WRITE] = "ConditionPathIsReadWrite",
816 [CONDITION_DIRECTORY_NOT_EMPTY] = "ConditionDirectoryNotEmpty",
817 [CONDITION_FILE_NOT_EMPTY] = "ConditionFileNotEmpty",
818 [CONDITION_FILE_IS_EXECUTABLE] = "ConditionFileIsExecutable",
819 [CONDITION_USER] = "ConditionUser",
820 [CONDITION_GROUP] = "ConditionGroup",
821 [CONDITION_CONTROL_GROUP_CONTROLLER] = "ConditionControlGroupController",
822 [CONDITION_NULL] = "ConditionNull",
823 [CONDITION_CPUS] = "ConditionCPUs",
824 [CONDITION_MEMORY] = "ConditionMemory",
825 };
826
827 DEFINE_STRING_TABLE_LOOKUP(condition_type, ConditionType);
828
829 static const char* const assert_type_table[_CONDITION_TYPE_MAX] = {
830 [CONDITION_ARCHITECTURE] = "AssertArchitecture",
831 [CONDITION_VIRTUALIZATION] = "AssertVirtualization",
832 [CONDITION_HOST] = "AssertHost",
833 [CONDITION_KERNEL_COMMAND_LINE] = "AssertKernelCommandLine",
834 [CONDITION_KERNEL_VERSION] = "AssertKernelVersion",
835 [CONDITION_SECURITY] = "AssertSecurity",
836 [CONDITION_CAPABILITY] = "AssertCapability",
837 [CONDITION_AC_POWER] = "AssertACPower",
838 [CONDITION_NEEDS_UPDATE] = "AssertNeedsUpdate",
839 [CONDITION_FIRST_BOOT] = "AssertFirstBoot",
840 [CONDITION_PATH_EXISTS] = "AssertPathExists",
841 [CONDITION_PATH_EXISTS_GLOB] = "AssertPathExistsGlob",
842 [CONDITION_PATH_IS_DIRECTORY] = "AssertPathIsDirectory",
843 [CONDITION_PATH_IS_SYMBOLIC_LINK] = "AssertPathIsSymbolicLink",
844 [CONDITION_PATH_IS_MOUNT_POINT] = "AssertPathIsMountPoint",
845 [CONDITION_PATH_IS_READ_WRITE] = "AssertPathIsReadWrite",
846 [CONDITION_DIRECTORY_NOT_EMPTY] = "AssertDirectoryNotEmpty",
847 [CONDITION_FILE_NOT_EMPTY] = "AssertFileNotEmpty",
848 [CONDITION_FILE_IS_EXECUTABLE] = "AssertFileIsExecutable",
849 [CONDITION_USER] = "AssertUser",
850 [CONDITION_GROUP] = "AssertGroup",
851 [CONDITION_CONTROL_GROUP_CONTROLLER] = "AssertControlGroupController",
852 [CONDITION_NULL] = "AssertNull",
853 [CONDITION_CPUS] = "AssertCPUs",
854 [CONDITION_MEMORY] = "AssertMemory",
855 };
856
857 DEFINE_STRING_TABLE_LOOKUP(assert_type, ConditionType);
858
859 static const char* const condition_result_table[_CONDITION_RESULT_MAX] = {
860 [CONDITION_UNTESTED] = "untested",
861 [CONDITION_SUCCEEDED] = "succeeded",
862 [CONDITION_FAILED] = "failed",
863 [CONDITION_ERROR] = "error",
864 };
865
866 DEFINE_STRING_TABLE_LOOKUP(condition_result, ConditionResult);