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