Maintain health of passwd file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Maintain health of passwd file
# 1  
Old 08-16-2012
Maintain health of passwd file

Hello guys

I am about to write a script that is based on "The Linux Administration Handbook" The exercise is as follows:

Write a shell script to help monitor the health of the /etc/passwd file.
  1. Find entries that have UID0
  2. Find entries that have no password (needs /etc/shadow)
  3. Find any sets of entries that have duplicate UID's
  4. Find entries that have duplicate login names
  5. find entries that have no expiration date (needs /etc/shadow)
I finished point 1,3, and 4. What I am not able to figure out is how to access the shadow file without being root. I thought maybe by exec su | sh, and then access the file. But the user shouldn't have to interact with the script. Here is what I have so far


Code:
#!/usr/bin/sh
#
# SCRIPT:    lab5
# AUTHOR:    
# DATE:        8/15/2012
# REV:        1.0A
# PLATFORM:    Linux
# PURPOSE:    Maintain Health of the /etc/passwd file by checking for 
#        duplicate UID's, root ID, duplicate login names,
#        expiration date, entries with no password.
#
#
# REV LIST:
#    DATE:    8/16/2012
#    BY:    
#    MDIFICATION:    add awk for duplicate UID and login name check.
#
#
#
###############################################################################
##################### DEFINE FILES AND VARIABLES HERE #########################
###############################################################################

#    NO VARIABLES


###############################################################################
######################### DEFINE FUNCTIONS HERE ###############################
###############################################################################


#    NO FUNCTIONS


###############################################################################
######################### BEGINNING OF MAIN ###################################
###############################################################################

# This line checks for the root ID. It notifies the user if the root ID 
# exists or not.
echo "Check for root uid..."
awk -F: '$1 = ~/root/ {print "Found Root ID"} ' /etc/passwd        

# Check for duplicate UID by reading the records into an awk array
# and compare the predecessor with the successor. If the comparison 
# result is greater as 1 print the duplicate value.
echo "Check for duplicate UID's..."
awk -F:  'uname[$3]++ && uname[$3]>1 {print "duplicate user:", $1} ' /etc/passwd
echo "Duplicate UID check done"


# Check for duplicate UID by reading the records into an awk array
# and compare the predecessor with the successor. If the comparison 
# result is greater as 1 print the duplicate value.
echo "Check for duplicate user names..."
awk -F:  'uid[$3]++ && uid[$3]>1 {print "duplicate uid:", $3}' /etc/passwd
echo "Duplicate user name check done."

echo "Check for passwords..."

# I am not sure about that one !
#`exec su | sh | awk -F: '$2 ~/$\d$/ {print "User $1 has password}' /etc/shadow |  exit` 
exit 0


# End of Script

Any ideas, hints, advice etc. is greatly appreciated. Thank you.

-Daniel
# 2  
Old 08-17-2012
Thread reopened - accidentally closed as homework.
# 3  
Old 08-18-2012
To access or modify the /etc/shadow file your script is going to have to have an EUID of 0. That is by design. And scripts generally cannot be setuid!. Have a look at the pwck command.
# 4  
Old 08-18-2012
This thread shouldn't have been reopened. There is another active thread with the same title submitted by the same user in the "The UNIX and Linux Forums > Homework and Emergencies > Homework & Coursework Questions" forum. I believe discussion on this topic should happen there.
# 5  
Old 08-19-2012
Just noticed it that OP can provide a teacher etc. while stating in a PM he can't, etc... Not nice kidding me - you get a long time warning and a note on your account.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Removing special chars from file and maintain field separator

Running SunOs 5.6. Solaris. I've been able to remove all special characters from a fixed length file which appear in the first column but as a result all subsequent columns have shifted to the left by the amount of characters deleted. It is a space separated file. Line 1 in input file is... (6 Replies)
Discussion started by: iffy290
6 Replies

2. UNIX for Advanced & Expert Users

How to maintain a personal password file 'safely'?

Hi all, As time progresses, the number of servers that I have to login to has grown to the hundreds. Some of the servers has NIS so I can use one single password for this group of servers. The hard part comes to when you have 20+ other servers that now require different passwords and... (4 Replies)
Discussion started by: newbie_01
4 Replies

3. Homework & Coursework Questions

Maintain health of passwd file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hello guys I am about to write a script that is based on "The Linux Administration Handbook" The exercise is... (6 Replies)
Discussion started by: Learn4Life
6 Replies

4. AIX

When did AIX start using /etc/security/passwd instead of /etc/passwd to store encrypted passwords?

Does anyone know when AIX started using /etc/security/passwd instead of /etc/passwd to store encrypted passwords? (1 Reply)
Discussion started by: Anne Neville
1 Replies

5. Shell Programming and Scripting

Script to maintain file versions

I am developing a script to maintain 'n' number of versions of a file. The script will take a filename as a parameter and the number of versions to maintain. This basically does something like a FIFO. Here is what I developed. But something is not right. I have attached the script. Can u pls help... (2 Replies)
Discussion started by: vskr72
2 Replies

6. UNIX for Dummies Questions & Answers

help with passwd file

Not an unix expert, I read a few pages on the web about passwd files, but I didn't find the answers I need about the last 8 lines of the passwd file I'm taking a look at. I'm assuming their shortcuts to another file that may have the actual usernames of users on the system. Please, any help... (1 Reply)
Discussion started by: fusion31
1 Replies

7. Solaris

passwd cmd reenables passwd aging in shadow entry

Hi Folks, I have Solaris 10, latest release. We have passwd aging set in /etc/defalut/passwd. I have an account that passwd should never expire. Acheived by emptying associated users shadow file entries for passwd aging. When I reset the users passwd using passwd command, it re enables... (3 Replies)
Discussion started by: BG_JrAdmin
3 Replies

8. UNIX for Dummies Questions & Answers

sed a file and maintain date stamp and permissions

I need to alter a file. I'm using sed then passing output to temp file then using touch -r to maintain the date but the permissions do not get preserved How can I sed a file and maintain date and permissions currently it's preserving the date but the permissions revert back to the... (3 Replies)
Discussion started by: andyatit
3 Replies

9. Shell Programming and Scripting

help in /etc/passwd file

Hi all, As all of us know that in /etc/passwd file the first field correspond to username could any one tell me what is bin , damoen etc in the first field, and r they in user field , what is nologin in the last column ? root:x:0:0:root:/root:/bin/bash ... (4 Replies)
Discussion started by: useless79
4 Replies

10. Cybersecurity

/etc/passwd file

hi Does anyone anyone know what the last line of a unix user passwd file signifes? Mine shows "+:::::" best (4 Replies)
Discussion started by: s_mad010
4 Replies
Login or Register to Ask a Question