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 11-18-2003, 04:20 AM   #1
P_Shep
LQ Newbie
 
Registered: Jun 2003
Location: Reading, UK
Distribution: RH 7.2
Posts: 26

Rep: Reputation: 15
Raw sockets root user work around


I had to write as part of a program the ability to ping other machines for some kind of diagnosics.

Disseminating the ping code and using it mine, I managed to get the ping working how i wanted, but only under root access, which i really didn't want to permanently use.

Searching the net I saw something about capabilities and CAP_NET_RAW, but couldn't find anywhere which explained what the hell they were or how to use it. I also could find anywhere else which had a workaround for it.

Then i though a bit laterally... if ping could why can't my program?
simple, copy the ping properties over using chmod

chmod --reference=/bin/ping <your exec>

Bingo! worked a charm
 
Old 11-18-2003, 05:53 AM   #2
P_Shep
LQ Newbie
 
Registered: Jun 2003
Location: Reading, UK
Distribution: RH 7.2
Posts: 26

Original Poster
Rep: Reputation: 15
or you could just set up a socket which doesn't need root access:

s = socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP);

doh!
 
Old 11-18-2003, 11:35 AM   #3
LogicG8
Member
 
Registered: Jun 2003
Location: Long Island, NY
Distribution: Gentoo Unstable (what a misnomer)
Posts: 380

Rep: Reputation: 30
What you are doing is setting the program to be setuid
you can do this with chmod +s. Just remember to be
very careful with setuid programs because whoever
uses that program effectovely *is* root for the
duration of the program so if there are any bugs bad
things can happen.
 
  


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
Can We Run Raw Sockets With User Permissions fpfernando Programming 2 10-27-2005 06:03 AM
Pblm in Raw Sockets fpfernando Linux - Software 1 10-08-2005 01:04 AM
raw sockets and C wrongman Programming 3 05-04-2004 02:17 PM
can I use mmap with raw sockets? kanth Programming 2 02-28-2004 12:42 PM
raw sockets BashTin Programming 1 06-07-2003 06:34 AM

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

All times are GMT -5. The time now is 06:45 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