🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #150

Summary: getlogin() problem

#150
From: Don Costello
Date: Mon, 27 Jul 1992 11:38
41 lines
1616 bytes
Thanks to the following people, the getlogin() problem (which is really
not a problem) is finally solved:

leo@ine.philips.nl
graham@castle.edinburgh.ac.uk
Matt Schroth
cjc@ulysses.att.com
David A. Wagner
John Eric Fosler
David Myers
cjc@ulysses.att.com

It seems that, according to the man page, (which I obviously didn't
read too thoroughly :-) getlogin reads /etc/utmp, returning the ID of
the owner of whatever tty the user is on.  When doing an su to another login, 
there is no utmp entry for the new login, only the original one.

The following is the solution:

#include <all-the-normal-stuff>
#include <pwd.h>

char     *username;
struct   passwd *userinfo;

userinfo=getpwuid(getuid());
username=userinfo->pw_name;

"username" now points to the name of the current (su'd) login id
(userinfo->pw_name), not the original.

Thanks again to all who have helped.

  ==- dcc-==

-- 
+------------------------------------+---------------------------+
| Don Costello, DASC-ZSC             |  It's hard to cram this   |
| DLA Cameron Station, VA            |  signature into just 4    |
| TEL: (703) 274-7215  AV: 284-7215  |  lines!!!                 | 
Technical Details
Message-ID: <833@hq.dla.mil>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!udecc.engr.udayton.edu!blackbird.afit.af.mil!dsacg3.dsac.dla.mil!dsac.dla.mil!hq.dla.mil!fazc016

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!udecc.engr.udayton.edu!blackbird.afit.af.mil!dsacg3.dsac.dla.mil!dsac.dla.mil!hq.dla.mil!fazc016
From: fazc016@hq.dla.mil (Don Costello)
Newsgroups: comp.unix.programmer
Subject: Summary: getlogin() problem
Message-ID: <833@hq.dla.mil>
Date: 27 Jul 92 11:38:29 GMT
Organization: HQ Defense Logistics Agency/DASC, Cameron Station, VA
Lines: 41
X-Newsreader: Tin 1.1 PL4