diff mbox series

[2/3] e4crypt: refactor set_policy a little

Message ID 20200706194727.12979-2-flo@geekplace.eu
State Rejected
Headers show
Series [1/3] e4crypt: if salt is explicitly provided to add_key, then use it | expand

Commit Message

Florian Schmaus July 6, 2020, 7:47 p.m. UTC
Remove the superfluous 'salt' variable and simply use the functions
parameter instead.

Signed-off-by: Florian Schmaus <flo@geekplace.eu>
---
 misc/e4crypt.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Eric Biggers July 6, 2020, 10:04 p.m. UTC | #1
On Mon, Jul 06, 2020 at 09:47:26PM +0200, Florian Schmaus wrote:
> Remove the superfluous 'salt' variable and simply use the functions
> parameter instead.
> 
> Signed-off-by: Florian Schmaus <flo@geekplace.eu>
> ---
>  misc/e4crypt.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/misc/e4crypt.c b/misc/e4crypt.c
> index c82c6f8f..23980073 100644
> --- a/misc/e4crypt.c
> +++ b/misc/e4crypt.c
> @@ -344,10 +344,9 @@ static void parse_salt(char *salt_str, int flags)
>  	add_salt(salt_buf, salt_len);
>  }
>  
> -static void set_policy(struct salt *set_salt, int pad,
> +static void set_policy(struct salt *salt, int pad,
>  		       int argc, char *argv[], int path_start_index)
>  {
> -	struct salt *salt;
>  	struct ext4_encryption_policy policy;
>  	uuid_t	uu;
>  	int fd;
> @@ -366,9 +365,7 @@ static void set_policy(struct salt *set_salt, int pad,
>  			perror(argv[x]);
>  			exit(1);
>  		}
> -		if (set_salt)
> -			salt = set_salt;
> -		else {
> +		if (!salt) {
>  			if (ioctl(fd, EXT4_IOC_GET_ENCRYPTION_PWSALT,
>  				  &uu) < 0) {
>  				perror("EXT4_IOC_GET_ENCRYPTION_PWSALT");

This is wrong.  If no salt was explicitly specified, then the salt returned by
EXT4_IOC_GET_ENCRYPTION_PWSALT for the directory should be used.  There can be
multiple directories being processed.  Your patch changes the behavior so that
the default salt of the first directory is also used for all later directories.

- Eric
diff mbox series

Patch

diff --git a/misc/e4crypt.c b/misc/e4crypt.c
index c82c6f8f..23980073 100644
--- a/misc/e4crypt.c
+++ b/misc/e4crypt.c
@@ -344,10 +344,9 @@  static void parse_salt(char *salt_str, int flags)
 	add_salt(salt_buf, salt_len);
 }
 
-static void set_policy(struct salt *set_salt, int pad,
+static void set_policy(struct salt *salt, int pad,
 		       int argc, char *argv[], int path_start_index)
 {
-	struct salt *salt;
 	struct ext4_encryption_policy policy;
 	uuid_t	uu;
 	int fd;
@@ -366,9 +365,7 @@  static void set_policy(struct salt *set_salt, int pad,
 			perror(argv[x]);
 			exit(1);
 		}
-		if (set_salt)
-			salt = set_salt;
-		else {
+		if (!salt) {
 			if (ioctl(fd, EXT4_IOC_GET_ENCRYPTION_PWSALT,
 				  &uu) < 0) {
 				perror("EXT4_IOC_GET_ENCRYPTION_PWSALT");