Operating System - Linux
1752679 Members
5766 Online
108789 Solutions
New Discussion юеВ

Re: Alternatives to "getlogin"?

 
SOLVED
Go to solution
OldSchool
Honored Contributor

Alternatives to "getlogin"?

Let me be upfront with this: I'm not a programmer / developer, so forgive if this sounds more than slightly ignorant. I'm trying to assist a developer who doesn't have a *nix background.

We have an HP-UX 11.0 box running IBM's UniVerse database version 10.1. The database application runs some locally written C code to do some remote data access. This is, in Universe-speak, GCI (generalized call interface?) code.

The issue at hand is this:

Currently, the application is accessed via telnet. Part of the C code does a "getlogin" to grab the username which is then used throughout the remainder of the C stuff. That all works properly

The problem: part of the application is being relocated to a windows server. The remaing portion, including the 'gci' c code will remain on the server previously described and will be accessed via universe's uvrpc daemon. When this happens, the getlogin does not return a userid, only "". My surmise is that that uvrpcd is not placing info in utmp.

The question, given the circumstances, does anyone know of a method that the userid information can be obtained.

FWIW: An issue has been raised w/ Universe support as well

Thx....scott
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor
Solution

Re: Alternatives to "getlogin"?

Hi Scott:

See if 'getpwuid' otherwise known by 'getpwent' works.

http://docs.hp.com/en/B2355-60105/getpwent.3C.html

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: Alternatives to "getlogin"?

Anyone who uses getlogin() in C or in Perl always does a backup plan -- and this is a direct quote from the getlogin man page:

"The recommended procedure to obtain the user name associated with the real user ID of the calling process is to call getlogin(), and if that fails, to call getpwuid(geteuid))."

Yoiur code should at least make that modification (and indeed it should have always been in place).

However, this may not yield the result intended (though is will almost certainly result in a non-NULL user name). The problem is depending upon the protocol and the daemon that the effective uid is probably that of the daemon on the UNIX box. It would be possible for the daemon to fork() and exec() a new process and then set the uid but that entirely depends upon the applications design and I know (or care) nearly nothing about Universe.
If it ain't broke, I can fix that.
OldSchool
Honored Contributor

Re: Alternatives to "getlogin"?

James,

Doesn't that rely on getlogin_r to correctly identify the login id?

OldSchool
Honored Contributor

Re: Alternatives to "getlogin"?

James,
I didn't read that reply carefully enough before responding.

I'm going to get w/ the developer this afternoon and see if we can't get that to work.

Clay..you are correct re: the backup plan. the coder that wrote this is no longer w/ the company and we are finding a variety of issues like this. I have hopes that this will work properly as I can "see" the correct user attached to the process when doing a "ps".

Thanks to both. I'll update this when I have some results one way or the other....

scott
OldSchool
Honored Contributor

Re: Alternatives to "getlogin"?

getpwuid(getuid()) returned the result that we wanted

thanks to both of you, and have a good holiday.