summaryrefslogtreecommitdiff
path: root/src/cryptsetup
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-11-03 13:59:20 -0600
committerGitHub <noreply@github.com>2016-11-03 13:59:20 -0600
commit493fd52f1ada36bfe63301d4bb50f7fd2b38c670 (patch)
tree19864f5568a2fe48181c1b3f33c46b4db36dd768 /src/cryptsetup
parenta1e2ef7ec912902d8142e7cb5830cbfb47dba86c (diff)
parent9aa2169eaeb20994fb2b0196c051cff52f57a93d (diff)
Merge pull request #4510 from keszybz/tree-wide-cleanups
Tree wide cleanups
Diffstat (limited to 'src/cryptsetup')
-rw-r--r--src/cryptsetup/cryptsetup-generator.c12
-rw-r--r--src/cryptsetup/cryptsetup.c105
2 files changed, 57 insertions, 60 deletions
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
index e2dc4327fe..68029865a0 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -86,7 +86,7 @@ static int create_disk(
if (r < 0)
return log_error_errno(r, "Failed to generate unit name: %m");
- p = strjoin(arg_dest, "/", n, NULL);
+ p = strjoin(arg_dest, "/", n);
if (!p)
return log_oom();
@@ -188,7 +188,7 @@ static int create_disk(
if (!noauto) {
- to = strjoin(arg_dest, "/", d, ".wants/", n, NULL);
+ to = strjoin(arg_dest, "/", d, ".wants/", n);
if (!to)
return log_oom();
@@ -198,9 +198,9 @@ static int create_disk(
free(to);
if (!nofail)
- to = strjoin(arg_dest, "/cryptsetup.target.requires/", n, NULL);
+ to = strjoin(arg_dest, "/cryptsetup.target.requires/", n);
else
- to = strjoin(arg_dest, "/cryptsetup.target.wants/", n, NULL);
+ to = strjoin(arg_dest, "/cryptsetup.target.wants/", n);
if (!to)
return log_oom();
@@ -210,7 +210,7 @@ static int create_disk(
}
free(to);
- to = strjoin(arg_dest, "/dev-mapper-", e, ".device.requires/", n, NULL);
+ to = strjoin(arg_dest, "/dev-mapper-", e, ".device.requires/", n);
if (!to)
return log_oom();
@@ -220,7 +220,7 @@ static int create_disk(
if (!noauto && !nofail) {
_cleanup_free_ char *dmname;
- dmname = strjoin("dev-mapper-", e, ".device", NULL);
+ dmname = strjoin("dev-mapper-", e, ".device");
if (!dmname)
return log_oom();
diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c
index ff5a3f36fb..01e7ee9973 100644
--- a/src/cryptsetup/cryptsetup.c
+++ b/src/cryptsetup/cryptsetup.c
@@ -69,26 +69,25 @@ static usec_t arg_timeout = 0;
*/
static int parse_one_option(const char *option) {
+ const char *val;
+ int r;
+
assert(option);
/* Handled outside of this tool */
if (STR_IN_SET(option, "noauto", "auto", "nofail", "fail"))
return 0;
- if (startswith(option, "cipher=")) {
- char *t;
-
- t = strdup(option+7);
- if (!t)
+ if ((val = startswith(option, "cipher="))) {
+ r = free_and_strdup(&arg_cipher, val);
+ if (r < 0)
return log_oom();
- free(arg_cipher);
- arg_cipher = t;
-
- } else if (startswith(option, "size=")) {
+ } else if ((val = startswith(option, "size="))) {
- if (safe_atou(option+5, &arg_key_size) < 0) {
- log_error("size= parse failure, ignoring.");
+ r = safe_atou(val, &arg_key_size);
+ if (r < 0) {
+ log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
return 0;
}
@@ -99,68 +98,67 @@ static int parse_one_option(const char *option) {
arg_key_size /= 8;
- } else if (startswith(option, "key-slot=")) {
+ } else if ((val = startswith(option, "key-slot="))) {
arg_type = CRYPT_LUKS1;
- if (safe_atoi(option+9, &arg_key_slot) < 0) {
- log_error("key-slot= parse failure, ignoring.");
+ r = safe_atoi(val, &arg_key_slot);
+ if (r < 0) {
+ log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
return 0;
}
- } else if (startswith(option, "tcrypt-keyfile=")) {
+ } else if ((val = startswith(option, "tcrypt-keyfile="))) {
arg_type = CRYPT_TCRYPT;
- if (path_is_absolute(option+15)) {
- if (strv_extend(&arg_tcrypt_keyfiles, option + 15) < 0)
+ if (path_is_absolute(val)) {
+ if (strv_extend(&arg_tcrypt_keyfiles, val) < 0)
return log_oom();
} else
- log_error("Key file path '%s' is not absolute. Ignoring.", option+15);
+ log_error("Key file path \"%s\" is not absolute. Ignoring.", val);
- } else if (startswith(option, "keyfile-size=")) {
+ } else if ((val = startswith(option, "keyfile-size="))) {
- if (safe_atou(option+13, &arg_keyfile_size) < 0) {
- log_error("keyfile-size= parse failure, ignoring.");
+ r = safe_atou(val, &arg_keyfile_size);
+ if (r < 0) {
+ log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
return 0;
}
- } else if (startswith(option, "keyfile-offset=")) {
+ } else if ((val = startswith(option, "keyfile-offset="))) {
- if (safe_atou(option+15, &arg_keyfile_offset) < 0) {
- log_error("keyfile-offset= parse failure, ignoring.");
+ r = safe_atou(val, &arg_keyfile_offset);
+ if (r < 0) {
+ log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
return 0;
}
- } else if (startswith(option, "hash=")) {
- char *t;
-
- t = strdup(option+5);
- if (!t)
+ } else if ((val = startswith(option, "hash="))) {
+ r = free_and_strdup(&arg_hash, val);
+ if (r < 0)
return log_oom();
- free(arg_hash);
- arg_hash = t;
-
- } else if (startswith(option, "header=")) {
+ } else if ((val = startswith(option, "header="))) {
arg_type = CRYPT_LUKS1;
- if (!path_is_absolute(option+7)) {
- log_error("Header path '%s' is not absolute, refusing.", option+7);
+ if (!path_is_absolute(val)) {
+ log_error("Header path \"%s\" is not absolute, refusing.", val);
return -EINVAL;
}
if (arg_header) {
- log_error("Duplicate header= options, refusing.");
+ log_error("Duplicate header= option, refusing.");
return -EINVAL;
}
- arg_header = strdup(option+7);
+ arg_header = strdup(val);
if (!arg_header)
return log_oom();
- } else if (startswith(option, "tries=")) {
+ } else if ((val = startswith(option, "tries="))) {
- if (safe_atou(option+6, &arg_tries) < 0) {
- log_error("tries= parse failure, ignoring.");
+ r = safe_atou(val, &arg_tries);
+ if (r < 0) {
+ log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
return 0;
}
@@ -190,29 +188,28 @@ static int parse_one_option(const char *option) {
#endif
} else if (STR_IN_SET(option, "plain", "swap", "tmp"))
arg_type = CRYPT_PLAIN;
- else if (startswith(option, "timeout=")) {
+ else if ((val = startswith(option, "timeout="))) {
- if (parse_sec(option+8, &arg_timeout) < 0) {
- log_error("timeout= parse failure, ignoring.");
+ r = parse_sec(val, &arg_timeout);
+ if (r < 0) {
+ log_error_errno(r, "Failed to parse %s, ignoring: %m", option);
return 0;
}
- } else if (startswith(option, "offset=")) {
+ } else if ((val = startswith(option, "offset="))) {
- if (safe_atou64(option+7, &arg_offset) < 0) {
- log_error("offset= parse failure, refusing.");
- return -EINVAL;
- }
+ r = safe_atou64(val, &arg_offset);
+ if (r < 0)
+ return log_error_errno(r, "Failed to parse %s: %m", option);
- } else if (startswith(option, "skip=")) {
+ } else if ((val = startswith(option, "skip="))) {
- if (safe_atou64(option+5, &arg_skip) < 0) {
- log_error("skip= parse failure, refusing.");
- return -EINVAL;
- }
+ r = safe_atou64(val, &arg_skip);
+ if (r < 0)
+ return log_error_errno(r, "Failed to parse %s: %m", option);
} else if (!streq(option, "none"))
- log_error("Encountered unknown /etc/crypttab option '%s', ignoring.", option);
+ log_warning("Encountered unknown /etc/crypttab option '%s', ignoring.", option);
return 0;
}