Getuid

(Leslie Viljoen) #1

Hello everyone!

I am struggling to detect in a script whether the current user is root or
not. Etc.getlogin seems to return my unpriveleged username even after
I have done an 'su' or run the script with 'sudo' to become root.

All I really need is:

if Etc.getuid != 0
    puts "You are not root"
    exit
end

···

--
ruby -e "puts 'Just another fickle programmer'"

Leslie Viljoen [leslie@camary.co.za]
Camary Consulting [http://www.camary.co.za]
Cellphone [083-6186100]
Personal web [http://mobeus.homelinux.org]

(Bruce Woodward) #2

irb(main):004:0> if Process.euid != 0
irb(main):005:1> puts "you are not root"
irb(main):006:1> end
you are not root
=> nil

···

On 8/25/05, Leslie Viljoen <leslie@camary.co.za> wrote:

Hello everyone!

I am struggling to detect in a script whether the current user is root or
not. Etc.getlogin seems to return my unpriveleged username even after
I have done an 'su' or run the script with 'sudo' to become root.

All I really need is:

if Etc.getuid != 0
    puts "You are not root"
    exit
end

(Park Ji-In) #3

2005-08-25 (목), 18:32 +0900, Leslie Viljoen 쓰시길:

All I really need is:

if Etc.getuid != 0
    puts "You are not root"
    exit
end

How about this?

$ cat uid.rb
puts Process.uid
$ ruby uid.rb
1000
$ sudo ruby uid.rb
0

(Leslie Viljoen) #4

Bruce Woodward wrote:

irb(main):004:0> if Process.euid != 0
irb(main):005:1> puts "you are not root"
irb(main):006:1> end
you are not root
=> nil

Thanks!

What is the difference between effective user id and user id?

···

On 8/25/05, Leslie Viljoen <leslie@camary.co.za> wrote:

Hello everyone!

I am struggling to detect in a script whether the current user is root or
not. Etc.getlogin seems to return my unpriveleged username even after
I have done an 'su' or run the script with 'sudo' to become root.

All I really need is:

if Etc.getuid != 0
   puts "You are not root"
   exit
end

--
ruby -e "puts 'Just another fickle programmer'"

Leslie Viljoen [leslie@camary.co.za]
Camary Consulting [http://www.camary.co.za]
Cellphone [083-6186100]
Personal web [http://mobeus.homelinux.org]

(Andrew S. Townley) #5

Hi Leslie.

What is the difference between effective user id and user id?

Userid is always who you logged in as; effective user id is who you
appear to be at the moment. This is why setuid/setgid is important
under UNIX so that if you have a process started as root, it can do a
setuid to a non-privileged user on startup to minimize potential system
security risks.

They might be hard to find now, but if you really want to know more (and
have a better/longer explanation than mine), check out any of the
Richard W. Stevens books like UNIX Network Programming or Advanced
Programming in the UNIX environment. Both are well worth reading if
you're doing system-level programming.

Hope this helps,

ast

···

On Thu, 2005-08-25 at 11:46, Leslie Viljoen wrote:

***************************************************************************************************
The information in this email is confidential and may be legally privileged. Access to this email by anyone other than the intended addressee is unauthorized. If you are not the intended recipient of this message, any review, disclosure, copying, distribution, retention, or any action taken or omitted to be taken in reliance on it is prohibited and may be unlawful. If you are not the intended recipient, please reply to or forward a copy of this message to the sender and delete the message, any attachments, and any copies thereof from your system.
***************************************************************************************************