Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!emory!tridom!wht From: wht@tridom.uucp (Warren Tucker) Newsgroups: alt.sources Subject: Re: euser - display the effective user name, SysV-ish Summary: try this: whoami.c Message-ID: <139@tridom.uucp> Date: 8 Jul 89 17:58:02 GMT References: <14448@bfmny0.UUCP> Organization: Tridom Corporation, Marietta GA Lines: 66 In article <14448@bfmny0.UUCP>, tneff@bfmny0.UUCP (Tom Neff) writes: > If you need a FAST way to generate the name of your current effective > user (including the effects of su(1) etc), this works. It's not fancy. > Obviously it has to read /etc/passwd. Feel free to hack and pass > around. Try this: #!/bin/sh # shar: Shell Archiver (v1.22) # # Run the following text with /bin/sh to create: # whoami.c # sed 's/^X//' << 'SHAR_EOF' > whoami.c && X/*+------------------------------------------------------------------------- X whoami.c - System V 'whoami' - prints effective user name (euid) X ...!gatech!emory!tridom!wht X XSystem V ain't got one of these goodies X--------------------------------------------------------------------------*/ X/*+:EDITS:*/ X/*:01-27-1989-17:16-wht-creation */ X X#include X#include X X/*+------------------------------------------------------------------------- X who_am_i() - return first username in /etc/passwd that matches euid X--------------------------------------------------------------------------*/ Xchar * Xwho_am_i() X{ Xstruct passwd *passwd; Xstruct passwd *getpwuid(); X X passwd = getpwuid(geteuid()); /* gotta succeed unless MUCH is wrong */ X endpwent(); X if(passwd == (struct passwd *)0) /* much wrong has been known to happen */ X return("???"); X return(passwd->pw_name); X X} /* end of who_am_i */ X X/*+------------------------------------------------------------------------- X main(argc,argv,envp) X--------------------------------------------------------------------------*/ Xmain(argc,argv,envp) Xint argc; Xchar **argv; Xchar **envp; X{ X printf("%s\n",who_am_i()); X exit(0); X} /* end of main */ X X/* vi: set tabstop=4 shiftwidth=4: */ X/* end of whoami.c */ SHAR_EOF chmod 0644 whoami.c || echo "restore of whoami.c fails" exit 0 -- ------------------------------------------------------------------- Warren Tucker, Tridom Corporation ...!gatech!emory!tridom!wht Sforzando (It., sfohr-tsahn'-doh). A direction to perform the tone or chord with special stress, or marked and sudden emphasis.