Skip to content
Advertisement

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!

Advertisement

Answer

ecryptfs-mount-private is a /bin/sh shell script (and relatively short, only about 65 lines without comments) so you could try running “converting” some of it into C++ and/or running the remaining shell command lines one at a time with system().

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement