Solved

UID/GID on Executable: Effective vs. Real UID concept

Posted on 2010-09-15
7
846 Views
Last Modified: 2012-05-10
I wrote a short C++ program that only receives an input value (basically cin >> a ;).  I enabled UID on it.  So ls -l shows:
-rwsr-xr-x 1 root root   6058 Sep 15 09:50 prog

Now I executed it as "test" user and checked the real vs. effective UID as under:
 ps -eo cmd,ruser,euser,ruid,euid,pid | grep prog | grep -v grep
./prog                      test     root       501     0 14251

Just as I expected, real userid is 501(test) and effective uid is 0(root).

So far so good.

Now I tried to do the same using a shell script.  A bash script called script which should do the same thing but it doesn't.  Why?  Is there a way to see it working in a shell script.

-rwsr-xr-x 1 root root      5 Sep 15 09:29 script

ps -eo cmd,ruser,euser,ruid,euid,pid | grep 14328
bash                        test     test       501   501 14328

Second, will the script work as root or as user test?
0
Comment
Question by:farzanj
  • 4
  • 2
7 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 450 total points
ID: 33682601
On most Unixes the "setuid on execution" flag does not work for shell scripts, only for binary executables.
Since this seems to be the case with your OS,  your script will run as user test.
wmp

 
0
 
LVL 4

Assisted Solution

by:jlar310
jlar310 earned 50 total points
ID: 33682645
bash (and other shells) ignores the setuid bit by design. It's a security thing. The setuid bit only works on compiled binary programs. In your example, the script will always run as the logged in user.
0
 
LVL 31

Author Comment

by:farzanj
ID: 33682704
I ran it on Red Hat Linux (RHEL5.5).
Second, please clarify if effective uid/gid the one that is checked for determining the access/permissions.  Does real uid/gid ever matter at all?
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 450 total points
ID: 33682870
The real userid always remains unchanged, and can be tracked by a so-designed application to find out the id of the invoking user.
The real id is used e.g. when files are being created by means of a setuid program, to set ownership to the correct id.
Besides that this real id can of course be used to possibly reject some actions otherwise allowed for the "effective" userid.
Think of /usr/bin/passwd! This executable is setuid "root" to allow for changing one's own password, but it checks the "real" id to reject changes for other users if not invoked by root.
wmp
 
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 450 total points
ID: 33682931
... and yes, RHEL does not honor setuid! It's Linux, and that functionality is built into the Linux kernel, afaik.
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 450 total points
ID: 33682950
The above should read
"...  does not honor setuid for shell scripts ..."
of course.
0
 
LVL 31

Author Closing Comment

by:farzanj
ID: 33683100
Thank you so much for your clarification and your time.  Appreciated.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now