简体   繁体   中英

Decrypt and mount an eCryptFS encrypted directory using an external C++ script in Linux

I want to decrypt and mount the default eCryptfs private directory by executing the "ecryptfs-mount-private" terminal command in C++ and providing the passphrase/password from the same C++ script.

I have tried forking then exec the shell (/bin/sh) and opening pipes for I/O with sh but when I try to write through the pipe I get the following error:

stty: standard input: Inappropriate ioctl for device

I guess this is because ecryptfs-mount-private only accepts input for a passphrase from the keyboard.

How can I achieve this type of decrypt and mount mechanism? Possible ways of doing this or any workarounds will be helpful.

PS. Security concern of storing the passphrase in the C++ code is not a problem in my scenario.

Thanks!

ecryptfs-mount-private是一个/bin/sh shell脚本(相对较短,只有65行,没有注释),因此您可以尝试将其中的一些“转换”为C ++和/或将其余的shell命令行一次运行。与system()时间。

ecrypt-mountfs-private expects to be attached to a terminal. One solution is to use forkpty (2) instead of fork , which will ensure the child process has access to a pty (pseudo-tty). You can then write to and read from the master file descriptor to provide input resp. read output from the child process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM