su & effective uid/gid

When I log in as non-root and run ‘su’ to temporarilly have root
privleges, the system does not seem to remember my “real” id.
This can be demonstrated by:
$ su
password: [enter the new password]

pidin -Ppidin user

shows 0 for all id’s, real and effective

And by the way

id -r

doesn’t return anything.

I believe that this represents a bug in both ‘su’ and ‘id’.
If I’m wrong, please point me to documentation to indicate
the purpose of the “real” ids.

What I want to accomplish is to have shell scipts that su when
necessary, but can figure out who they were before they su’ed.

Can this be done?

Yes, I know that the shell script can save that information in a
shell variable, but I’d rather not do that.

Bill Caroselli wrote:

When I log in as non-root and run ‘su’ to temporarilly have root
privleges, the system does not seem to remember my “real” id.
This can be demonstrated by:
$ su
password: [enter the new password]

pidin -Ppidin user

shows 0 for all id’s, real and effective

And by the way

id -r

doesn’t return anything.

I believe that this represents a bug in both ‘su’ and ‘id’.
If I’m wrong, please point me to documentation to indicate
the purpose of the “real” ids.

What I want to accomplish is to have shell scipts that su when
necessary, but can figure out who they were before they su’ed.

Can this be done?

Yes, I know that the shell script can save that information in a
shell variable, but I’d rather not do that.

Bill,

The real and effective uids [gids] come into play when the setuid
[setgid] bit[s] of an executable is[are] set. If I have:

rwsr-x–x root testuid

and run that as userid 101, then my real uid will be 101
and my effective uid will be 0.

su changes both, as you have observed. What does remain
constant is the login name of the user, which you can
access via the posix ‘logname’ function. Curiously, this
function seems to be missing from QNX6, though it is
a trivial wrapper around the getlogin() function.

-Norton