Reading from a block device without permission



Hi there,

I am currently writing an application that I want to run as
unprivileged user, but I want to read raw data from a block device
such as /dev/sda (the usual block device for USB memory sticks).

The problem is that users do not have privileges to read from
/dev/sda. So I will need my application to gain root privileges to
read from this device. My initial idea is to create a pipe, fork my
application, close stdout and replace it with the pipe and run `gksudo
"cat /dev/sda"` from the child process, and close stdin and replace it
with the pipe in the parent process, and read raw data from the device
through stdin.

Another idea of mine was to write a little program to open a file
specified as a parameter, and send the file descriptor to stdout. I
would create a pipe and fork in my original program as above, and use
gksudo to run this second program as root, and pass the file
descriptor back to my original program through the pipe.

Has anyone done anything like this before? Has anyone got any better
ideas of a way to gain privileges to read from a block device in this
way? Can someone comment on the security implication of the above
approaches?

Any help would be much appreciated,

--
Marc O'Morain
http://marcomorain.com


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]