LinuxQuestions.org
Visit Jeremy's Blog.
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 04-01-2012, 01:49 PM   #1
alphisb0t
Member
 
Registered: Jun 2004
Distribution: gentoo 2008.desktop
Posts: 110

Rep: Reputation: 15
running as root and changing to user nobody programmatically


Hey all.

I'm writing a program that requires being run as root (for interfacing with network card) but during runtime it no longer requires it.

I'd like to setuid and setgid to the nobody user/group but don't know how to programmatically determine the UID/GID of the corresponding nobody user/group. I'm trying to avoid having the user enter the UID/GID as an additional parameter or adding it to a conf file (as it would be the only thing in the conf file).

Is there a way to determine a uid/gid for nobody without asking the user for it?

Thanks for any input on this!
 
Old 04-01-2012, 06:15 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Have a look at the source of getent, maybe?
$ getent passwd nobody
nobody:x:65534:65534:nobody:/nonexistent:/bin/sh



Cheers,
Tink
 
Old 04-01-2012, 06:25 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
man getpwent
 
Old 04-01-2012, 08:14 PM   #4
alphisb0t
Member
 
Registered: Jun 2004
Distribution: gentoo 2008.desktop
Posts: 110

Original Poster
Rep: Reputation: 15
Wow getpwent is precisely what I needed! Thanks much guys. I hadn't even heard of this function before.
 
Old 04-01-2012, 08:44 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by alphisb0t View Post
Wow getpwent is precisely what I needed! Thanks much guys. I hadn't even heard of this function before.

Neither - that's why I looked at getent's source ;}
 
Old 04-02-2012, 07:11 PM   #6
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
I use getpwnam and getgrnam.
Kevin Barry
 
  


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
changing user to root user in obuntu 10.04lts kato.jacob Linux - Newbie 6 06-28-2011 07:28 AM
How to change a process running in root-user to non-root user ???????????????????? narendra1310 Linux - Software 4 10-29-2009 02:11 AM
Changing Windows Password Programmatically kamransoomro84 Programming 9 05-28-2006 12:35 PM
changing user, root, password! itz2000 Linux - Newbie 3 11-19-2005 03:31 AM
Changing proxy server programmatically irfanhab Programming 1 10-19-2004 02:18 AM

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

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