[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Env class bug?

ruby@eq.cz

3/3/2005 12:24:00 PM

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.


5 Answers

ts

3/3/2005 12:39:00 PM

0

>>>>> "r" == ruby@eq cz <ruby@eq.cz> writes:

r> Is this expected behaviour?

yes,

r> Seems like a bug to me.

the bug is to connect as root :-)

r> Am I missing something?

try

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

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


Guy Decoux





Adriano Ferreira

3/3/2005 12:56:00 PM

0

> 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.


ruby@eq.cz

3/3/2005 12:58:00 PM

0

ts wrote:
> the bug is to connect as root :-)

:-)

> 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.


ruby@eq.cz

3/3/2005 3:29:00 PM

0

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.


Zach Dennis

3/3/2005 4:10:00 PM

0

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