Env class bug?

Hi,

trying to implement something like:

cd ~

using

Dir.chdir( Etc.getpwnam( Etc.getlogin ).dir )

(I thought this should be quite safe path) I faced this behaviour:

root@machine:~# su - everyuser
everyuser@machine:~$ irb
irb(main):001:0> require 'etc'
=> true
irb(main):002:0> Etc.getlogin
=> "root"
irb(main):003:0>

Is this expected behaviour? Seems like a bug to me. Am I missing something?

Regards,

r.

Is this expected behaviour?

yes,

Seems like a bug to me.

the bug is to connect as root :slight_smile:

Am I missing something?

  try

Etc.getpwuid(Process::Sys.geteuid)[:dir]

Etc.getpwuid(Process::Sys.getuid)[:dir]

Guy Decoux

irb(main):002:0> Etc.getlogin
=> "root"
Is this expected behaviour? Seems like a bug to me. Am I missing something?

Etc.getlogin likely "implements the C library function of the
same name, which on most systems returns the current login
from /etc/utmp, if any".

With a 'su' you changed the real user user id and getlogin() returns
the name associated with the current login activity. So as Guy Decoux
said it is the expected behaviour and
        Etc.getpwuid(Process::Sys.geteuid)[:dir]
is what you want.

ts wrote:

the bug is to connect as root :slight_smile:

:slight_smile:

  try

Etc.getpwuid(Process::Sys.geteuid)[:dir]

Etc.getpwuid(Process::Sys.getuid)[:dir]

root@machine:~# su - everyuser
everyuser@machine:~$ irb
irb(main):001:0> Process::Sys.geteuid
=> 1001
irb(main):002:0> Process::Sys.getuid
=> 1001
irb(main):003:0> require 'etc'
=> true
irb(main):004:0> Etc.getlogin
=> "root"
irb(main):005:0>

r.

Adriano Ferreira wrote:

Etc.getlogin likely "implements the C library function of the
same name, which on most systems returns the current login
from /etc/utmp, if any".

With a 'su' you changed the real user user id and getlogin() returns
the name associated with the current login activity. So as Guy Decoux
said it is the expected behaviour and
        Etc.getpwuid(Process::Sys.geteuid)[:dir]
is what you want.

Ok, now I see. 'su -', according to man page, should ``Simulate a full login.''. On the other hand, 'getlogin', according to 'Linux Programmer's Manual', ``returns a pointer to a string containing the name of the user logged in on the controlling terminal of the process''.

'NetBSD System Calls Manual' is explicit about this behaviour:
``The name is normally associated with a login shell at the time a session is created, and is inherited by all processes descended from the login shell. (This is true even if some of those processes assume another user ID, for example when su(1) is used.)''

Thanks for your help, guys, and sorry for the noise.

r.

ruby@eq.cz wrote:

Adriano Ferreira wrote:

Etc.getlogin likely "implements the C library function of the
same name, which on most systems returns the current login
from /etc/utmp, if any".
With a 'su' you changed the real user user id and getlogin() returns
the name associated with the current login activity. So as Guy Decoux
said it is the expected behaviour and
        Etc.getpwuid(Process::Sys.geteuid)[:dir]
is what you want.

Ok, now I see. 'su -', according to man page, should ``Simulate a full login.''. On the other hand, 'getlogin', according to 'Linux Programmer's Manual', ``returns a pointer to a string containing the name of the user logged in on the controlling terminal of the process''.

'NetBSD System Calls Manual' is explicit about this behaviour:
``The name is normally associated with a login shell at the time a session is created, and is inherited by all processes descended from the login shell. (This is true even if some of those processes assume another user ID, for example when su(1) is used.)''

Thanks for your help, guys, and sorry for the noise.

Not noise, I learned from this. Thanks for posting this to the list so I could share in reading the replies and reasoning!

Zach