get effective and real user names in a setuid program in linux

This is a discussion on get effective and real user names in a setuid program in linux within the Linux General forums, part of the Linux Forums category; Hi, I have to write a setuid program which is going to check for accesslogs based on the real user ...


Go Back   Usenet Forums > Linux Forums > Linux General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-31-2003
vimala
 
Posts: n/a
Default get effective and real user names in a setuid program in linux

Hi,
I have to write a setuid program which is going to check for
accesslogs based on the real user who had invoked the executable.

I need to get the real and effective user-ids of the system
and based on the real user-id i need to filter logs only for that
user and give it for further activity. My idea was to get the real
userid, groupid and search for a pattern x:userid:groupid in the
/etc/password file. But again that involves fork, exec, write the
result to some file etc.....

Instead of doing all that is there any other way of getting
all this done???

-kellogy
Reply With Quote
  #2 (permalink)  
Old 07-31-2003
Lew Pitcher
 
Posts: n/a
Default Re: get effective and real user names in a setuid program in linux

On 31 Jul 2003 04:42:12 -0700, vimala@ncb.ernet.in (vimala) wrote:

>Hi,
> I have to write a setuid program which is going to check for
>accesslogs based on the real user who had invoked the executable.
>
> I need to get the real and effective user-ids of the system
>and based on the real user-id i need to filter logs only for that
>user and give it for further activity. My idea was to get the real
>userid, groupid and search for a pattern x:userid:groupid in the
>/etc/password file.


getuid(2), getgid(2) to get the real uid and real gid
geteuid(2), getegid(2) to get the effective uid and the effective gid
getpwuid(3) to get the password entry (broken out by field)
use the ->pw_name for your user name
getgruid(3) to get the group entry (broken out by field)
use the ->gr_name field for your group name

> But again that involves fork, exec, write the
>result to some file etc.....


Not really, how about
#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
{
printf("Your real username is \"%s\"\n",
getpwuid(getuid())->pw_name);
printf("Your real groupname is \"%s\"\n",
getgruid(getgid())->gr_name);
printf("Your effective username is \"%s\"\n",
getpwuid(geteuid())->pw_name);
printf("Your effective groupname is \"%s\"\n",
getgruid(getegid())->gr_name);
}

>
> Instead of doing all that is there any other way of getting
>all this done???
>
>-kellogy


--
Lew Pitcher
IT Consultant, Enterprise Technology Solutions
Toronto Dominion Bank Financial Group

(Opinions expressed are my own, not my employers')
Reply With Quote
  #3 (permalink)  
Old 07-31-2003
Lew Pitcher
 
Posts: n/a
Default Re: get effective and real user names in a setuid program in linux

SIGTYPO caught; corrections below

On Thu, 31 Jul 2003 12:14:13 GMT, Lew.Pitcher@td.com (Lew Pitcher) wrote:

>On 31 Jul 2003 04:42:12 -0700, vimala@ncb.ernet.in (vimala) wrote:
>
>>Hi,
>> I have to write a setuid program which is going to check for
>>accesslogs based on the real user who had invoked the executable.
>>
>> I need to get the real and effective user-ids of the system
>>and based on the real user-id i need to filter logs only for that
>>user and give it for further activity. My idea was to get the real
>>userid, groupid and search for a pattern x:userid:groupid in the
>>/etc/password file.

>
>getuid(2), getgid(2) to get the real uid and real gid
>geteuid(2), getegid(2) to get the effective uid and the effective gid
>getpwuid(3) to get the password entry (broken out by field)
> use the ->pw_name for your user name
>getgruid(3) to get the group entry (broken out by field)

Make that getgrgid(3)

> use the ->gr_name field for your group name
>
>> But again that involves fork, exec, write the
>>result to some file etc.....

>
>Not really, how about
> #include <unistd.h>
> #include <sys/types.h>
> #include <pwd.h>
> #include <grp.h>
> {
> printf("Your real username is \"%s\"\n",
> getpwuid(getuid())->pw_name);
> printf("Your real groupname is \"%s\"\n",
> getgruid(getgid())->gr_name);

getgrgid(getgid())->gr_name);

> printf("Your effective username is \"%s\"\n",
> getpwuid(geteuid())->pw_name);
> printf("Your effective groupname is \"%s\"\n",
> getgruid(getegid())->gr_name);

getgrgid(getegid())->gr_name);

> }
>
>>
>> Instead of doing all that is there any other way of getting
>>all this done???
>>
>>-kellogy

>
>--
>Lew Pitcher
>IT Consultant, Enterprise Technology Solutions
>Toronto Dominion Bank Financial Group
>
>(Opinions expressed are my own, not my employers')


--
Lew Pitcher
IT Consultant, Enterprise Technology Solutions
Toronto Dominion Bank Financial Group

(Opinions expressed are my own, not my employers')
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:25 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0