Date: Thu, 9 Aug 2001 00:13:45 -0500 From: Mike Meyer <mwm@mired.org> To: BinarySoul <binary@binary.ath.cx> Cc: questions@freebsd.org Subject: Re: finding user of su Message-ID: <15218.7177.143011.457023@guru.mired.org> In-Reply-To: <122679418@toto.iv>
next in thread | previous in thread | raw e-mail | index | archive | help
[Format recovered from top posting.]
BinarySoul <binary@binary.ath.cx> types:
> Eric Anderson wrote:
> > Is there a tool (or how would I write one) that can tell me the original
> > user after an su? Basically, if I su to root, how can I tell who I su'd
> > from?
> There are a lot of ways you can do that :)
> Really...
> You can just look at you environment:
> Things like:
> id -p | grep login
Very nice. I didn't know id would do that.
> ...
> Well, I said, there are a lot of ways...
> Even:
> cat << lol > buh.c
> #include <stdio.h>
> #include <sys/param.h>
> int main(void){
> printf("%s\n",getlogin());
> return 0;
> }
> lol
>
> must work
getlogin is what "id -p" uses, so the two solutions are pretty much
the same. Like all the other cases, it only works if the user doesn't
reset it. For getlogin, that needs something like this:
#include <stdio.h>
#include <sys/param.h>
int
main(int argc, char **argv) {
if (argc != 2) {
fprintf(stderr, "usage: %s <name>\n", argv[0]) ;
return 1 ;
}
if (setlogin(argv[1]) != 0) {
perror("olo") ;
return 1 ;
}
return 0;
}
<mike
--
Mike Meyer <mwm@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?15218.7177.143011.457023>
