Skip to content

Commit bce334a

Browse files
committed
core: add ConditionSecurity=tpm2 support
1 parent 7509c7f commit bce334a

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

man/systemd.unit.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,9 +1257,9 @@
12571257
<listitem><para><varname>ConditionSecurity=</varname> may be used to check whether the given
12581258
security technology is enabled on the system. Currently, the recognized values are
12591259
<literal>selinux</literal>, <literal>apparmor</literal>, <literal>tomoyo</literal>,
1260-
<literal>ima</literal>, <literal>smack</literal>, <literal>audit</literal> and
1261-
<literal>uefi-secureboot</literal>. The test may be negated by prepending an exclamation
1262-
mark.</para>
1260+
<literal>ima</literal>, <literal>smack</literal>, <literal>audit</literal>,
1261+
<literal>uefi-secureboot</literal> and <literal>tpm2</literal>. The test may be negated by prepending
1262+
an exclamation mark.</para>
12631263
</listitem>
12641264
</varlistentry>
12651265

src/shared/condition.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,21 @@ static int condition_test_ac_power(Condition *c, char **env) {
480480
return (on_ac_power() != 0) == !!r;
481481
}
482482

483+
static int has_tpm2(void) {
484+
int r;
485+
486+
/* Checks whether the system has at least one TPM2 resource manager device, i.e. at least one "tpmrm"
487+
* class device */
488+
489+
r = dir_is_empty("/sys/class/tpmrm");
490+
if (r == -ENOENT)
491+
return false;
492+
if (r < 0)
493+
return log_debug_errno(r, "Failed to determine whether system has TPM2 support: %m");
494+
495+
return !r;
496+
}
497+
483498
static int condition_test_security(Condition *c, char **env) {
484499
assert(c);
485500
assert(c->parameter);
@@ -499,6 +514,8 @@ static int condition_test_security(Condition *c, char **env) {
499514
return mac_tomoyo_use();
500515
if (streq(c->parameter, "uefi-secureboot"))
501516
return is_efi_secure_boot();
517+
if (streq(c->parameter, "tpm2"))
518+
return has_tpm2();
502519

503520
return false;
504521
}

0 commit comments

Comments
 (0)