Re: How to get original user (linux 2.4.20 kernel)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, May 05, 2006 at 01:45:37PM +0530, Linux Dang wrote:
> Hi,
>    I am looking for some way to extract original user for a given
> process. For example,
> A user types following command
> 
> i   ) guest log's in as "aaa"
> ii  ) su - "bbb"
> iii ) su - "ccc"
> iv ) ./a.out
> 
> I want to find the actual user i.e. "aaa". Can this be acheived on Linux 2.4.20?
> I am thinking of following solution but don't know whether this will
> work in all the cases or is there is any better way to achieve this.
> 
> struct task_struct {
> ...
> pid_t session;  /* Stores login session pid */
> ...
> 
> }
> 
> This "session" is the pid of login session process. Using this pid we
> can traverse task_struct and get "uid" associated with this pid and
> hence original user.
> 
> Thanks in advance.
> 
> Regards,
> Linux Dang
> 

Hi,

don't touch the kernel :)

You can already find the user logged initially. You just have to find
the user which owns the actual pty (pseudo terminal)
You can find this information in the /var/run/utmp file (maybe somewhere
else with you distribution).

This file is not a plain text. I don't exactly how to read it but you
should download the source of the who command (coreutils package). You
will see that this file is used and the file is read (it's read with the
help of the readutmp(...) function).

Or you can just launch the 'who' command from your C program but it's
not advised.

-- 
tyler
tyler@xxxxxxxx


	

	
		
___________________________________________________________________________ 
Faites de Yahoo! votre page d'accueil sur le web pour retrouver directement vos services préférés : vérifiez vos nouveaux mails, lancez vos recherches et suivez l'actualité en temps réel. 
Rendez-vous sur http://fr.yahoo.com/set


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux