Skip to content
Snippets Groups Projects
Commit d29bed15 authored by Thiago Abdo's avatar Thiago Abdo
Browse files

[add user] Adds function that removes_user from passwd and group(need testing)


Signed-off-by: default avatarThiago Abdo <tja14@inf.ufpr.br>
parent d8fcb0fb
No related branches found
No related tags found
No related merge requests found
...@@ -93,6 +93,28 @@ add (){ ...@@ -93,6 +93,28 @@ add (){
fi fi
} }
remove_user(){
userDetail=$1
userName=$( echo $userDetail | cut -d':' -f1 );
echo $0": Removendo usuário "$userName" do passwd e shadow"
#remove from passwd
temp=mktemp;
sed "/^$userDetail:/d" /etc/passwd > $temp
cp $temp /etc/passwd
chown root:root /etc/passwd
chmod 644 /etc/passwd
rm $temp
#remove from shadow
temp=mktemp;
sed "/^$userName:/d" /etc/shadow > $temp
cp $temp /etc/shadow
chown root:shadow /etc/shadow
chmod 640 /etc/shadow
rm $temp
}
#This script can only be executed by a root/sudoer user #This script can only be executed by a root/sudoer user
if [ "$(/usr/bin/id -r -u)" != "0" ]; then if [ "$(/usr/bin/id -r -u)" != "0" ]; then
...@@ -157,12 +179,14 @@ fi ...@@ -157,12 +179,14 @@ fi
checkName=$( cat /etc/passwd | cut -d':' -f1-3 | grep -e "^$username:" ) checkName=$( cat /etc/passwd | cut -d':' -f1-3 | grep -e "^$username:" )
if [ -z "$checkName" ]; then if [ -z "$checkName" ]; then
#remove "$checkName" #remove "$checkName"
remove_user "$checkName"
echo $0": encontrei outro usuario local com o mesmo nome, devo remove-lo" echo $0": encontrei outro usuario local com o mesmo nome, devo remove-lo"
fi fi
checkID=$( cat /etc/passwd | cut -d':' -f1-3 | grep -e ":$uID$" ) checkID=$( cat /etc/passwd | cut -d':' -f1-3 | grep -e ":$uID$" )
if [ -z "$checkID" ]; then if [ -z "$checkID" ]; then
#remove "$checkID" #remove "$checkID"
remove_user "$checkID"
echo $0": encontrei outro usuario local com o mesmo id, devo remove-lo" echo $0": encontrei outro usuario local com o mesmo id, devo remove-lo"
fi fi
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment