LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-10-2011, 11:47 AM   #1
r_jr
Member
 
Registered: Feb 2006
Distribution: Ubuntu
Posts: 66

Rep: Reputation: 0
Question SUID question


I have a python script that needs to run as a normal user, but do to the fact that it is accessing digital IO ports I need root access. I tried setting the SUID
Code:
chmod 4755 file
and then tried running it as a normal user, but I still get a need to root error. Is there anyway around this problem?

 
Old 08-10-2011, 12:07 PM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
Hello,

Depending on what you are doing, you could always change the individual permission for the block device that you are using; In this case, a digital IO port. What exactly are you working on anyway? Just curious so I can help out...

Cheers,

Josh
 
Old 08-10-2011, 12:45 PM   #3
r_jr
Member
 
Registered: Feb 2006
Distribution: Ubuntu
Posts: 66

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by corp769 View Post
Hello,

Depending on what you are doing, you could always change the individual permission for the block device that you are using; In this case, a digital IO port. What exactly are you working on anyway? Just curious so I can help out...

Cheers,

Josh
I am using the python portio library to toggle a shutdown line to an external device. The code below works, but like I said I need to be root to execute it and I eventually need to do it as a normal user as part of an application. Either that or I need to add a new group to the sudoer list. I did that for a startup script that I need to run but I read that I could set the SUID to allow a normal user to run a script, but I have been unsuccessful so far.


Code:
import sys, time, os
import portio

# check for root privileges
if os.getuid():
  print 'You need to be root! Exiting.'
  sys.exit()

# acquire permission for I/O on lp0
#status = portio.ioperm(0x480, 1, 1)
status = portio.iopl(3)
if status:
  print 'iopl:',os.strerror(status)
  sys.exit()

#init the chipset
RetVal = 0

RetVal = portio.inb(0x4B0)
RetVal=RetVal|0x02
portio.outb(RetVal,0x4B0) 

RetVal = portio.inb(0x481)
RetVal=RetVal|0xF0
portio.outb(RetVal,0x481) 

RetVal = portio.inb(0x480)
RetVal=RetVal|0xC0
portio.outb(RetVal,0x480) 

RetVal = portio.inb(0x4B4)
RetVal=RetVal|0x01
portio.outb(RetVal,0x4B4) 

RetVal = portio.inb(0x485)
RetVal=RetVal&0x0F
portio.outb(RetVal,0x485) 

RetVal = portio.inb(0x485)
RetVal=RetVal|0x02
portio.outb(RetVal,0x485) 

RetVal = portio.inb(0x484)
RetVal=RetVal|0xC0
portio.outb(RetVal,0x484) 


#reset the output pins to zero
RetVal = portio.inb(0x48d)
RetVal=RetVal&0x0F
portio.outb(RetVal,0x48d) 
   

for i in range(1,10):
  print ("LED ON!, \n",i)
  #Set all DO0 to 1
  portio.outb(0x10,0x48d) #DO0 is bit 4
	     		  #DO1 is bit 5
		  	  #DO2 is bit 6
		  	  #DO3 is bit 7
  time.sleep(1)
  print ("LED OFF!, \n",i)
  #Set all output to 0
  portio.outb(0x00,0x48d)
  time.sleep(1)

print ("Hello World!, \n")

#### END
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
A question on SUID (Set User ID) saagar Linux - Newbie 3 12-10-2009 12:51 PM
Question about suid detail... redbot Linux - Security 6 10-01-2007 09:59 AM
SUID question ddaas Linux - General 3 02-08-2007 05:28 AM
suid/sgid question plan9 Linux - Security 1 07-08-2004 07:15 AM
SUID file drops suid bit on append? c_coder Programming 1 03-12-2004 07:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:36 AM.

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