home *** CD-ROM | disk | FTP | other *** search
/ ftp.jcu.edu.au / 2014.06.ftp.jcu.edu.au.tar / ftp.jcu.edu.au / v6.3.2b / SWBD63 / fabos-6.3.2b-10.ppc.rpm / fabos-6.3.2b.10.cpio.gz / fabos-6.3.2b.10.cpio / fabos / libexec / usrlogout < prev    next >
Text File  |  2010-11-10  |  3KB  |  123 lines

  1. #!/bin/sh
  2. #
  3. #    Copyright (c) 2002-2007 Brocade Communications Systems, Inc.
  4. #    All rights reserved.
  5. #
  6. #    File name:   logout
  7. #    Module name: fabos/src/security/utils.c
  8. #
  9. #    This script will logout all sessions of specified particular users.
  10. #    It's called by the in a number of situtaions in secure mode
  11. #    by the FABOS code such as when passwords change or FCS role
  12. #    change.
  13. #
  14. PATH=/fabos/sbin:/fabos/bin:/bin:/usr/bin:/sbin
  15.  
  16.  
  17. if [ $# -ge 1 ]; then
  18.  
  19. # Logout Multiple Users
  20. if [ $# -ge 2 ]; then
  21. # Information for User
  22. #echo Will logout user: $1
  23. line="$*"
  24. sw=`echo $line | cut -d' ' -f 1`
  25. accts=`echo $line | cut -d' ' -f 2-`
  26.  
  27. msg="Security Policy, Password or Account Attribute Change: "
  28. msg=$msg$accts" will be logged out"
  29. chassis_info=`getchassisconfig`
  30. num_switches=`echo $chassis_info | \
  31.     sed -n -e 's/Number of switches: //gp' | \
  32.     sed -n -e 's/ .*//gp'`
  33.  
  34. wall "$msg"
  35. fi
  36.  
  37. if [ $# -eq 1 ]; then
  38.  
  39. # Logout Invalid Users
  40. if [ $1 == "-invalid" ]; then
  41. echo "Finding invalid users" >> /var/log/user.log
  42. for logged_user in `who | cut -d' ' -f1`
  43. do
  44. echo "*logged_user - $logged_user* " >> /var/log/user.log
  45.     kill_user=1
  46.     # Check if the user is valid by searching the /etc/passwd file
  47.     for valid_user in `grep "$logged_user" < /etc/passwd | cut -d':' -f1`
  48.     do
  49.         if [ "$logged_user" == "$valid_user" ]
  50.         then
  51.             kill_user=0
  52.             break
  53.         fi
  54.     done
  55.     # If user is invalid, add it to the list of accounts
  56.     if [ $kill_user -eq 1 ]
  57.     then
  58.         accts="$logged_user $accts"
  59.     fi
  60. done
  61. if [ "$accts" != "" ]; then
  62.     wall "Active CP : Invalid users \"$accts\" will be logged out."
  63. fi
  64. accts=`echo $accts | cut -d' ' -f1-`
  65. else
  66.     echo "Invalid Arguments/Options for usrlogout"
  67. fi
  68.  
  69. fi
  70.  
  71. echo "logged_users : $accts" >> /var/log/user.log
  72. echo "" >> /var/log/user.log
  73. echo "looping through all accounts" >> /var/log/user.log
  74. # Loop through all accounts
  75. for name in $accts; do
  76. echo "$name" >> /var/log/user.log
  77. # Loop through all TTYs of user using 'who' command
  78. for tty in `who | grep "$name " | sed -e 's/   / /g' | sed -e 's/  / /g' \
  79.             | sed -e 's/  / /g' | cut -d' ' -f2`
  80. do
  81. echo "*tty - $tty* " >> /var/log/user.log
  82.     pid=`fuser /dev/$tty | sed -e "s,^/dev/[[:alnum:]/]*:[[:space:]]*,,g"`
  83. echo "*pid - $pid*" >> /var/log/user.log
  84.     if [ "$pid" != "" ]
  85.     then
  86.         kill -9 $pid 2> /dev/null
  87.     fi
  88.  
  89. done
  90. done
  91.  
  92.  
  93. # no argument, logout all
  94. elif [ $# -eq 0 ]; then
  95.  
  96. msg="AAA Server Configuration Change: all accounts will be logged out"
  97. mytty=`tty|sed  -e 's/\/dev\///g'`
  98.  
  99. wall "$msg"
  100.  
  101. for tty in `who | sed -e 's/   / /g' | sed -e 's/  / /g' | sed -e 's/  / /g' \
  102.             | cut -d' ' -f2`
  103. do
  104.     echo "*aaa tty - $tty*" >> /var/log/user.log
  105. #kill all other shells first
  106.     if [ "$tty" != "$mytty" ]; then
  107.         pid=`fuser /dev/$tty | sed -e "s,^/dev/[[:alnum:]/]*:[[:space:]]*,,g"`
  108.  
  109. #    echo Killing PID $pid
  110.         if [ "$pid" != "" ]; then
  111.             kill -9 $pid 2> /dev/null
  112.         fi
  113.     fi
  114. done
  115. #kill my own shell
  116.     pid=`fuser /dev/$mytty | sed -e "s,^/dev/[[:alnum:]/]*:[[:space:]]*,,g"`
  117.  
  118. #    echo Killing PID $pid
  119.     if [ "$pid" != "" ]; then
  120.         kill -9 $pid 2> /dev/null
  121.     fi
  122. fi
  123.