I'm writing a library which accesses the parallel port to output data to an external device. To do this, I use ioperm(). However, ioperm() needs root privileges and thus programs using the library must be run as root.
How can the library be used by a normal user. Is there a function in C++ which allows me to code the library in a way that it get the access by itself without the need to start the program that uses the library as root?
I've tried setting it with setregid() and setuid(), but this doesn't work (error "Operation not permitted"):
Code:
uid_t uid = 0;
gid_t gid = 0;
setregid( gid, gid );
if (getgid() != 0) {
perror("Could not get GID root");
return false;
}
setuid( 0 );
if (getuid() != 0 ) {
perror("Could not get UID root");
return false;
}
On the other hand, this does not work for obvious security related reasons.
Or how to solve this problem using a other approach? I'm not interrested in having root privileges, just direct access to the parallel port. So if there's another way, I'd be happy to hear it.