LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-01-2005, 08:14 AM   #1
Zotty
LQ Newbie
 
Registered: Sep 2004
Location: Netherlands
Distribution: Debian testing
Posts: 25

Rep: Reputation: 15
Getting hardware access as normal user


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.
 
Old 02-01-2005, 10:44 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
setuid()
 
Old 02-01-2005, 11:13 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
On my (debian) computer I get:
Code:
ls -l /dev/lp0
crw-rw----  1 root lp 6, 0 Mar 14  2002 /dev/lp0
As you can see group permissions are "rw". And the group of the parallel port device file (/dev/lp0) is "lp".

Now say you want user "hko" to be able to access this device, so he can run your program. To do this, you make "hko" a member of group "lp" with this (as root):
Code:
adduser hko lp
When "hko" logs in again after this he will be able to acces the parallel ports.

If this is not what you were looking for, try reading about the "sudo" program.

Or, make you executable SUID root (not recommended, security issues).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
normal user access folders jwijesundra Linux - Newbie 3 01-16-2005 10:46 AM
can to get access to mysql from a normal user chinaundead Linux - Software 4 04-09-2004 07:56 PM
getting access denied , when trying to access camera as normal user bennythepitbull Linux - Hardware 2 11-04-2003 02:30 AM
normal user access devices N|ghtwo|f Linux - Software 4 07-22-2003 05:16 AM
cdrom normal user access N|ghtwo|f Linux - Software 1 07-08-2003 07:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration