new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / debian / ossec-hids / var / ossec / active-response / bin / disable-account.sh
1 #!/bin/sh
2 # Disable an account by setting "passwd -l" or chuser
3 # Requirements: System with a passwd that supports -l and -u
4 #               or a system with chuser (AIX)
5 # Expect: username (can't be "root")
6 # Authors: Ahmet Ozturk and Daniel B. Cid
7 # Last modified: Jan 19, 2005
8
9
10 UNAME=`uname`
11 PASSWD="/usr/bin/passwd"
12 CHUSER="/usr/bin/chuser"
13 ACTION=$1
14 USER=$2
15 IP=$3
16
17 LOCAL=`dirname $0`;
18 cd $LOCAL
19 cd ../
20 PWD=`pwd`
21 echo "`date` $0 $1 $2 $3 $4 $5" >> ${PWD}/../logs/active-responses.log
22
23
24 if [ "x${USER}" = "x" ]; then
25    echo "$0: [ add | delete ] <username>" 
26    exit 1;
27 elif [ "x${USER}" = "xroot" ]; then
28    echo "$0: Invalid username."
29    exit 1;   
30 fi
31
32
33 # We should run on linux and on SunOS the passwd -u/-l
34 if [ "X${UNAME}" = "XLinux" -o "X${UNAME}" = "XSunOS" ]; then
35    # Checking if passwd is present
36    ls ${PASSWD} >> /dev/null 2>&1
37    if [ $? != 0 ]; then
38       exit 0;
39    fi    
40
41    CMD=${PASSWD}
42    if [ "x${ACTION}" = "xadd" ]; then
43        ARGS="-l"
44    elif [ "x${ACTION}" = "xdelete" ]; then
45        ARGS="-u"
46    else
47       echo "$0: invalid action: ${ACTION}"
48       exit 1;
49    fi
50
51
52 # On AIX, we run CHUSER
53 elif [ "X${UNAME}" = "XAIX" ]; then
54    # Checking if chuser is present
55    ls ${CHUSER} >> /dev/null 2>&1
56    if [ $? != 0 ]; then
57       exit 0;
58    fi    
59
60    CMD=${CHUSER}
61     
62    # Disabling an account
63    if [ "x${ACTION}" = "xadd" ]; then
64       ARGS="account_locked=true" 
65    # Unblock the account 
66    elif [ "x${ACTION}" = "xdelete" ]; then
67       ARGS="account_locked=false"
68    # Invalid action
69    else
70       echo "$0: invalid action: ${ACTION}"
71       exit 1;
72    fi
73
74
75 # We only support Linux, SunOS and AIX
76 else 
77    exit 0;
78 fi
79
80
81 # Execute the command
82 ${CMD} ${ARGS} ${USER}
83
84 exit 1;
85