~tomleb/alpine-mkinitfs

8a9ab098c7d3a6d6d5cc09729a0fca9b1fa66eaf — Tom Lebreux 10 months ago ff62924 master
Send a response to cryptprompt
1 files changed, 30 insertions(+), 11 deletions(-)

M nlplug-findfs/nlplug-findfs.c
M nlplug-findfs/nlplug-findfs.c => nlplug-findfs/nlplug-findfs.c +30 -11
@@ 607,11 607,12 @@ static void *cryptsetup_thread(void *data)
	}

	if (!stat(c->crypt.data.prompt, &st)) {
		int fd[2];
		int fd_from[2];
		int fd_to[2];
		pid_t pid;
		char pass[1024];

		if (pipe(fd) == -1) {
		if (pipe(fd_from) == -1 || pipe(fd_to) == -1) {
			warn("pipe");
			goto free_out;
		}


@@ 623,18 624,22 @@ static void *cryptsetup_thread(void *data)
		}

		if (pid == 0) {
			close(fd[0]);
			dup2(fd[1], 3);
			close(fd[1]);
			close(fd_from[0]);
			close(fd_to[1]);
			// The prompt will use:
			// - fd 3 to write the LUKS key and
			// - fd 4 to read the result
			dup2(fd_from[1], 3);
			dup2(fd_to[0], 4);
			close(fd_from[1]);
			close(fd_to[0]);
			execlp(c->crypt.data.prompt, c->crypt.data.prompt, c->crypt.data.devnode, NULL);
			warn("executing prompt %s", c->crypt.data.prompt);
		}
		close(fd_from[1]);
		close(fd_to[0]);

		close(fd[1]);
		read(fd[0], pass, sizeof(pass));

		wait(NULL);
		close(fd[0]);
		read(fd_from[0], pass, sizeof(pass));

		pthread_mutex_lock(&c->crypt.mutex);
		r = crypt_activate_by_passphrase(cd, c->crypt.data.name,


@@ 644,7 649,21 @@ static void *cryptsetup_thread(void *data)
		pthread_mutex_unlock(&c->crypt.mutex);
		memset(pass, 0, sizeof(pass)); /* wipe pass after use */

		if (r >= 0)
		int res = 0;
		if (r >= 0) {
			res = 1;
			char *success = "success\n";
			write(fd_to[1], success, strlen(success));
		} else {
			char *failure = "failure\n";
			write(fd_to[1], failure, strlen(failure));
		}

		wait(NULL);
		close(fd_from[0]);
		close(fd_to[1]);

		if (res > 0)
			goto free_out;
	}