Env class bug?

R

ruby

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

ts

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
 
A

Adriano Ferreira

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

ruby

ts said:
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.
 
R

ruby

Adriano said:
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.
 
Z

Zach Dennis

Adriano said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Class instance method 2
bug in IPAddr eql? (stndard library) 2
1.9 bug? 3
convert date 5
is it bug? 3
iconv transfer code 13
Regular expression: Is this a bug or feature? 3
Array#slice! bug? 0

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,458
Latest member
Chris#

Latest Threads

Top