How to diff between 2 users with uid 0?


 
Thread Tools Search this Thread
Special Forums Cybersecurity How to diff between 2 users with uid 0?
# 8  
Old 03-24-2013
When a user logs into a UNIX system, the login name used is saved in a system database and in the environment variable LOGNAME. The file(s) containing the database where it is stored varies from system to system, but is likely to be in a file named something like utmp or utmpx in a directory like /var/run, /var/adm, or /etc. The name stored there should be used by who (not the 1st name in the user database [AKA the passwd file] with a matching UID). The name stored in the login database should also be used by the logname() function and the logname utility (both of which are explicitly NOT allowed to use $LOGNAME since any user can alter the value of $LOGNAME in the current shell execution environment). None of these should care how many different login names are associated with a given user ID.

None of this makes it a good idea to allow multiple user names for any user ID with extended privileges. But, I don't understand why the who or whoami utilities should be unable to determine what login name was used as long as the login session is still active. (They might fail if file descriptors 0, 1, and 2 have been disconnected from the controlling terminal, but they shouldn't make up a login name just based on the UID of the calling process.)
These 2 Users Gave Thanks to Don Cragun For This Post:
# 9  
Old 03-24-2013
Quote:
Originally Posted by urip
"whoami" command return "root" for both users.
That's by design. "whoami" uses geteuid which retrieves the user identity from the numerical id.
You should use who am I instead which retrieves the user identity from the utmpx/wtmpx or similar source:
Code:
# id
uid=0(root) gid=0(root)
# whoami
root
# who am I
toor       pts/5        Mar 24 23:57   (localhost)

This User Gave Thanks to jlliagre For This Post:
# 10  
Old 03-24-2013
geteuid, means who the current process is "pretending" to be. getuid is the id the process logged in as. If a process executes seteuid to become root, it still retains the original process uid.

geteuid is the effective current uid, not necessarily the origianal id of the user at login time.
# 11  
Old 03-27-2013
Thanks for the replays.
"who am I" will do the work.
Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Display info about users (UID GID processes terminal)

I would like to get an opinion for my solution for this task and get feedback about better approach or mistakes I have made. 1. The problem statement, all variables and given/known data: The task is to create a script which prints information about users whose names are specified in the... (2 Replies)
Discussion started by: kornfan
2 Replies

2. Shell Programming and Scripting

Find users with root UID or GID or root home

I need to list users in /etc/passwd with root's GID or UID or /root as home directory If we have these entries in /etc/passwd root:x:0:0:root:/root:/bin/bash rootgooduser1:x:100:100::/home/gooduser1:/bin/bash baduser1:x:0:300::/home/baduser1:/bin/bash... (6 Replies)
Discussion started by: anil510
6 Replies

3. UNIX for Advanced & Expert Users

How to diff between 2 users with uid 0?

Hello, I created a new user "rootNew" After creation I manually change the file /etc/passwd and gave the new user "rootNew" uid 0. Now I have 2 users with uid 0 (root,rootNew) how can I know which user is log in the system? "whoami" command return "root" for both users. Thanks, Uri No... (0 Replies)
Discussion started by: urip
0 Replies

4. Solaris

Can we create multiple users with same UID?

* Can we create multiple users with same UID? * Can we give root permissions to normal user like admin.s ? If YES give me full details (syntax of sudo/RBAC) (14 Replies)
Discussion started by: Navkreddy
14 Replies

5. Shell Programming and Scripting

serach diff filename in diff location using shell scripting

Hi, I am new to shell scripting. please help me to find out the solution. I need a script where we need to read the text file(consists of all file names) and get the file names one by one and append the date suffix for each file name as 'yyyymmdd' . Then search each file if exists... (1 Reply)
Discussion started by: Lucky123
1 Replies

6. OS X (Apple)

When to use /Users/m/bin instead of /usr/local/bin (& whats the diff?)?

Q1. I understand that /usr/local/bin means I can install/uninstall stuff in here and have any chance of messing up my original system files or effecting any other users. I created this directory myself. But what about the directory I didn't create, namely /Users/m/bin? How is that directory... (1 Reply)
Discussion started by: michellepace
1 Replies

7. Shell Programming and Scripting

.procmailrc and uudeview (put attachments from diff senders to diff folders)

Moderator, please, delete this topic (1 Reply)
Discussion started by: optik77
1 Replies

8. AIX

Finding a specific UID on a site with hundreads of users.

Hello, I am not the AIX guru.. This might seem simple for a lot but I am not sure where to start.. So here is my question: I have a unix account on a remote site. My UID is 999999. Now I need to create my account at my main site, with the same UID. So i have to make sure the UID 999999 is... (1 Reply)
Discussion started by: maxalarie
1 Replies

9. AIX

Locking a file when using VI to prevent multiple-edit sessions by diff users

At the office, we often have to edit one file with VI. We are 4-6 workers doing it and sometimes can be done at the same time. We have found a problem and want to prevent it with a file lock. Is it possible and how ? problem : Worker-a starts edit VI session on File-A at 1PM Worker-b... (14 Replies)
Discussion started by: Browser_ice
14 Replies

10. Shell Programming and Scripting

diff 2 files; output diff's to 3rd file

Hello, I want to compare two files. All records in file 2 that are not in file 1 should be output to file 3. For example: file 1 123 1234 123456 file 2 123 2345 23456 file 3 should have 2345 23456 I have looked at diff, bdiff, cmp, comm, diff3 without any luck! (2 Replies)
Discussion started by: blt123
2 Replies
Login or Register to Ask a Question