diff options
-rw-r--r-- | src/creds/creds.c | 17 | ||||
-rw-r--r-- | src/cryptenroll/cryptenroll.c | 17 | ||||
-rw-r--r-- | src/cryptsetup/cryptsetup.c | 17 | ||||
-rw-r--r-- | src/partition/repart.c | 17 | ||||
-rw-r--r-- | src/shared/tpm2-util.c | 25 | ||||
-rw-r--r-- | src/shared/tpm2-util.h | 2 |
6 files changed, 36 insertions, 59 deletions
diff --git a/src/creds/creds.c b/src/creds/creds.c index e9c7c96fc5..c067c886db 100644 --- a/src/creds/creds.c +++ b/src/creds/creds.c @@ -832,25 +832,12 @@ static int parse_argv(int argc, char *argv[]) { arg_tpm2_device = streq(optarg, "auto") ? NULL : optarg; break; - case ARG_TPM2_PCRS: { - uint32_t mask; - - if (isempty(optarg)) { - arg_tpm2_pcr_mask = 0; - break; - } - - r = tpm2_parse_pcrs(optarg, &mask); + case ARG_TPM2_PCRS: + r = tpm2_parse_pcr_argument(optarg, &arg_tpm2_pcr_mask); if (r < 0) return r; - if (arg_tpm2_pcr_mask == UINT32_MAX) - arg_tpm2_pcr_mask = mask; - else - arg_tpm2_pcr_mask |= mask; - break; - } case ARG_NAME: if (isempty(optarg)) { diff --git a/src/cryptenroll/cryptenroll.c b/src/cryptenroll/cryptenroll.c index f7fc4963a8..3c2b914a43 100644 --- a/src/cryptenroll/cryptenroll.c +++ b/src/cryptenroll/cryptenroll.c @@ -315,25 +315,12 @@ static int parse_argv(int argc, char *argv[]) { break; } - case ARG_TPM2_PCRS: { - uint32_t mask; - - if (isempty(optarg)) { - arg_tpm2_pcr_mask = 0; - break; - } - - r = tpm2_parse_pcrs(optarg, &mask); + case ARG_TPM2_PCRS: + r = tpm2_parse_pcr_argument(optarg, &arg_tpm2_pcr_mask); if (r < 0) return r; - if (arg_tpm2_pcr_mask == UINT32_MAX) - arg_tpm2_pcr_mask = mask; - else - arg_tpm2_pcr_mask |= mask; - break; - } case ARG_TPM2_PIN: r = parse_boolean_argument("--tpm2-with-pin=", optarg, &arg_tpm2_pin); diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index f0130eb238..c9a55a314b 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -394,20 +394,9 @@ static int parse_one_option(const char *option) { } else if ((val = startswith(option, "tpm2-pcrs="))) { - if (isempty(val)) - arg_tpm2_pcr_mask = 0; - else { - uint32_t mask; - - r = tpm2_parse_pcrs(val, &mask); - if (r < 0) - return r; - - if (arg_tpm2_pcr_mask == UINT32_MAX) - arg_tpm2_pcr_mask = mask; - else - arg_tpm2_pcr_mask |= mask; - } + r = tpm2_parse_pcr_argument(val, &arg_tpm2_pcr_mask); + if (r < 0) + return r; } else if ((val = startswith(option, "tpm2-pin="))) { diff --git a/src/partition/repart.c b/src/partition/repart.c index 0c0c0de794..f44e239b37 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -4359,25 +4359,12 @@ static int parse_argv(int argc, char *argv[]) { break; } - case ARG_TPM2_PCRS: { - uint32_t mask; - - if (isempty(optarg)) { - arg_tpm2_pcr_mask = 0; - break; - } - - r = tpm2_parse_pcrs(optarg, &mask); + case ARG_TPM2_PCRS: + r = tpm2_parse_pcr_argument(optarg, &arg_tpm2_pcr_mask); if (r < 0) return r; - if (arg_tpm2_pcr_mask == UINT32_MAX) - arg_tpm2_pcr_mask = mask; - else - arg_tpm2_pcr_mask |= mask; - break; - } case '?': return -EINVAL; diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c index e1a5190893..db8d42b501 100644 --- a/src/shared/tpm2-util.c +++ b/src/shared/tpm2-util.c @@ -1508,3 +1508,28 @@ Tpm2Support tpm2_support(void) { return support; } + +int tpm2_parse_pcr_argument(const char *arg, uint32_t *mask) { + uint32_t m; + int r; + + assert(mask); + + /* For use in getopt_long() command line parsers: merges masks specified on the command line */ + + if (isempty(arg)) { + *mask = 0; + return 0; + } + + r = tpm2_parse_pcrs(arg, &m); + if (r < 0) + return r; + + if (*mask == UINT32_MAX) + *mask = m; + else + *mask |= m; + + return 0; +} diff --git a/src/shared/tpm2-util.h b/src/shared/tpm2-util.h index 220eb341ec..c62a0843ba 100644 --- a/src/shared/tpm2-util.h +++ b/src/shared/tpm2-util.h @@ -113,3 +113,5 @@ typedef enum Tpm2Support { } Tpm2Support; Tpm2Support tpm2_support(void); + +int tpm2_parse_pcr_argument(const char *arg, uint32_t *mask); |