#!/usr/bin/perl ################################################################################ # LogoutHook # # Perform necessary user cleanup & system maintenance to prepare for next # user login. # # 11/08/05, jf6b: Gutted and rebuilt for Tiger # 12/06/05, jf6b: Changed call to reboot to shutdown # require "/etc/cmu/hooks/hook-subs"; get_opts(); ################ # Create logfile # log_init("/etc/cmu/hooks/logs/LogoutHook.log", $WARNING); ################# # Check Arguments # log_abort("Script invoked with bad number of arguments") if ($#ARGV != 0); $user = $ARGV[0]; log_abort("Script invoked with a blank user-id argument") if ($user eq ''); ################## # Lookup User Info # ($name,$passwd,$uid,$gid, $quota,$comment,$gcos, $homedir,$shell,$expire) = getpwnam($user) or log_abort("User '$user' not in passwd database"); ################################################################################ # SWITCH FROM ROOT TO THE UID AND PRIMARY GID OF USER LOGGING IN # # This grants us access to the user's AFS space, # but limits what we can do to the local file system # switch_to_user($uid, $gid); ################################# # Execute individual logout hooks # run_parts("logout"); ########################################## # Remove Classic & windowserver pref files # $ethaddr = `/sbin/ifconfig en0|grep ether|cut -d' ' -f 2`; $ethaddr =~ s/[^0-9a-f]//g; $hostname = `hostname`; unlink($homedir.'/Library/Preferences/ByHost/com.apple.windowserver.'.$hostname.'.plist'); unlink($homedir.'/Library/Preferences/ByHost/com.apple.Classic.'.$hostname.'.plist'); unlink($homedir.'/Library/Preferences/ByHost/com.apple.windowserver.'.$ethaddr.'.plist'); unlink($homedir.'/Library/Preferences/ByHost/com.apple.Classic.'.$ethaddr.'.plist'); ################################### # Unlink Library to be sure nothing # more gets written back to AFS # unlink($homedir.'/Library'); #################### # Destroy AFS tokens # run_command('unlog'); ################################################################################ # SWITCH FROM THE UID AND PRIMARY GID OF USER LOGGED IN TO ROOT # switch_to_root(); ######################## # Handle delayed reboots # if ( -f "/private/etc/cmu/ctrl/INeedAReboot") { unlink("/private/etc/cmu/ctrl/INeedAReboot"); # XXX - Hack to make AFS happy system("/Library/StartupItems/OpenAFS/OpenAFS stop"); system("/sbin/shutdown -r now"); } ################ # Force a reboot # if ( -f "/private/etc/cmu/ctrl/RebootOnLogout") { # XXX - Hack to make AFS happy system("/Library/StartupItems/OpenAFS/OpenAFS stop"); system("/sbin/shutdown -r now"); } log_close(); exit 0;