From d29bed157125aee4ba98993a2d75c55b7df4d262 Mon Sep 17 00:00:00 2001 From: Thiago Abdo <tja14@inf.ufpr.br> Date: Mon, 18 Jan 2016 10:43:16 -0200 Subject: [PATCH] [add user] Adds function that removes_user from passwd and group(need testing) Signed-off-by: Thiago Abdo <tja14@inf.ufpr.br> --- hdd/adduser.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/hdd/adduser.sh b/hdd/adduser.sh index 0f760f4..7a4042b 100755 --- a/hdd/adduser.sh +++ b/hdd/adduser.sh @@ -93,6 +93,28 @@ add (){ 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 if [ "$(/usr/bin/id -r -u)" != "0" ]; then @@ -157,12 +179,14 @@ fi checkName=$( cat /etc/passwd | cut -d':' -f1-3 | grep -e "^$username:" ) if [ -z "$checkName" ]; then #remove "$checkName" + remove_user "$checkName" echo $0": encontrei outro usuario local com o mesmo nome, devo remove-lo" fi checkID=$( cat /etc/passwd | cut -d':' -f1-3 | grep -e ":$uID$" ) if [ -z "$checkID" ]; then #remove "$checkID" + remove_user "$checkID" echo $0": encontrei outro usuario local com o mesmo id, devo remove-lo" fi -- GitLab