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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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') |
|
|||
|
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') |